mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-22 22:06:50 +00:00
Avoid overwriting notifications for template assertions.
This commit is contained in:
parent
d5a993e193
commit
610aeb2e92
@ -3,11 +3,11 @@ module ActionController
|
|||||||
extend ActiveSupport::Concern
|
extend ActiveSupport::Concern
|
||||||
|
|
||||||
included do
|
included do
|
||||||
setup :setup_subscriptions
|
setup :setup_serialization_subscriptions
|
||||||
teardown :teardown_subscriptions
|
teardown :teardown_serialization_subscriptions
|
||||||
end
|
end
|
||||||
|
|
||||||
def setup_subscriptions
|
def setup_serialization_subscriptions
|
||||||
@serializers = Hash.new(0)
|
@serializers = Hash.new(0)
|
||||||
|
|
||||||
ActiveSupport::Notifications.subscribe("!serialize.active_model_serializers") do |name, start, finish, id, payload|
|
ActiveSupport::Notifications.subscribe("!serialize.active_model_serializers") do |name, start, finish, id, payload|
|
||||||
@ -16,7 +16,7 @@ module ActionController
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def teardown_subscriptions
|
def teardown_serialization_subscriptions
|
||||||
ActiveSupport::Notifications.unsubscribe("!serialize.active_model_serializers")
|
ActiveSupport::Notifications.unsubscribe("!serialize.active_model_serializers")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
1
test/fixtures/template.html.erb
vendored
Normal file
1
test/fixtures/template.html.erb
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
<p>Hello.</p>
|
||||||
@ -11,6 +11,11 @@ module ActionController
|
|||||||
def render_text
|
def render_text
|
||||||
render text: 'ok'
|
render text: 'ok'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def render_template
|
||||||
|
prepend_view_path "./test/fixtures"
|
||||||
|
render template: "template"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
tests MyController
|
tests MyController
|
||||||
@ -56,6 +61,11 @@ module ActionController
|
|||||||
end
|
end
|
||||||
assert_match 'assert_serializer only accepts a String, Symbol, Regexp, ActiveModel::Serializer, or nil', e.message
|
assert_match 'assert_serializer only accepts a String, Symbol, Regexp, ActiveModel::Serializer, or nil', e.message
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_does_not_overwrite_notification_subscriptions
|
||||||
|
get :render_template
|
||||||
|
assert_template "template"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user