mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-22 22:06:50 +00:00
Remove assert_template from Test::SerializerTest
Rails 5 removed this assertion after considering it not a good testing practice. https://github.com/rails/rails/issues/18950 Rather that add a gem to our Rails 5 matrix to support it, the assertion is made that the template is rendering using active support notifications. Also, to clarify that the action 'render_template' is unrelated to the event name '!render_template.action_view', I renamed the actions so that would not look like event names.
This commit is contained in:
parent
f59431439d
commit
a43cff4ae3
1
Gemfile
1
Gemfile
@ -12,7 +12,6 @@ version = ENV['RAILS_VERSION'] || '4.2'
|
|||||||
if version == 'master'
|
if version == 'master'
|
||||||
gem 'rack', github: 'rack/rack'
|
gem 'rack', github: 'rack/rack'
|
||||||
gem 'arel', github: 'rails/arel'
|
gem 'arel', github: 'rails/arel'
|
||||||
gem 'rails-controller-testing', github: 'rails/rails-controller-testing'
|
|
||||||
git 'https://github.com/rails/rails.git' do
|
git 'https://github.com/rails/rails.git' do
|
||||||
gem 'railties'
|
gem 'railties'
|
||||||
gem 'activesupport'
|
gem 'activesupport'
|
||||||
|
|||||||
@ -1,5 +1,4 @@
|
|||||||
require 'test_helper'
|
require 'test_helper'
|
||||||
require 'rails-controller-testing' if Rails::VERSION::MAJOR >= 5
|
|
||||||
|
|
||||||
module ActiveModelSerializers
|
module ActiveModelSerializers
|
||||||
module Test
|
module Test
|
||||||
@ -7,17 +6,19 @@ module ActiveModelSerializers
|
|||||||
include ActiveModelSerializers::Test::Serializer
|
include ActiveModelSerializers::Test::Serializer
|
||||||
|
|
||||||
class MyController < ActionController::Base
|
class MyController < ActionController::Base
|
||||||
|
TEMPLATE_NAME = 'template'
|
||||||
def render_using_serializer
|
def render_using_serializer
|
||||||
render json: Profile.new(name: 'Name 1', description: 'Description 1', comments: 'Comments 1')
|
render json: Profile.new(name: 'Name 1', description: 'Description 1', comments: 'Comments 1')
|
||||||
end
|
end
|
||||||
|
|
||||||
def render_text
|
# For Rails4.0
|
||||||
render text: 'ok'
|
def render_some_text
|
||||||
|
Rails.version > '4.1' ? render(plain: 'ok') : render(text: 'ok')
|
||||||
end
|
end
|
||||||
|
|
||||||
def render_template
|
def render_a_template
|
||||||
prepend_view_path './test/fixtures'
|
prepend_view_path './test/fixtures'
|
||||||
render template: 'template'
|
render template: TEMPLATE_NAME
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -44,7 +45,7 @@ module ActiveModelSerializers
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_supports_specifying_serializers_with_a_nil
|
def test_supports_specifying_serializers_with_a_nil
|
||||||
get :render_text
|
get :render_some_text
|
||||||
assert_serializer nil
|
assert_serializer nil
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -65,8 +66,20 @@ module ActiveModelSerializers
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_does_not_overwrite_notification_subscriptions
|
def test_does_not_overwrite_notification_subscriptions
|
||||||
get :render_template
|
payloads = []
|
||||||
assert_template 'template'
|
event_name = '!render_template.action_view'
|
||||||
|
ActiveSupport::Notifications.subscribe(event_name) do |_name, _start, _finish, _id, payload|
|
||||||
|
payloads << payload
|
||||||
|
end
|
||||||
|
|
||||||
|
get :render_a_template
|
||||||
|
|
||||||
|
assert_equal 1, payloads.size, 'Only expected one template rendering to be registered'
|
||||||
|
payload = payloads.first
|
||||||
|
assert_equal MyController::TEMPLATE_NAME, payload[:virtual_path]
|
||||||
|
assert_match %r{test/fixtures/#{MyController::TEMPLATE_NAME}.html.erb}, payload[:identifier]
|
||||||
|
ensure
|
||||||
|
ActiveSupport::Notifications.unsubscribe(event_name)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user