require 'abstract_notifier/testing/minitest'
class EventsNotifierTestCase < Minitest::Test
include AbstractNotifier::TestHelper
test 'canceled' do
assert_notifications_sent 1, identify: "123", body: "Alarma!" do
EventsNotifier.with(profile: profile).canceled(event).notify_now
end
assert_notifications_enqueued 1, identify: "123", body: "Alarma!" do
EventsNotifier.with(profile: profile).canceled(event).notify_later
end
end
end
class User
after_create UserCallbacks.new
end
class UserCallbacks
def after_save(user)
# do something
end
end
@user.save
こう書き換えられます。
# app/models/sign_up_notifier.rb
class SignUpNotifier
def call(payload)
# do something
end
end
# config/initializers/newspaper.rb
Newspaper.subscribe(:user_create, SignUpNotifier.new)
# app/controllers/users_controller.rb
Newspaper.publish(:user_create, payload)