Use different assertions for Rails 5 and 6

Rails 6 changed the way it sanitizes input values.

References:
- https://github.com/rails/rails/blob/6-0-stable/actionview/lib/action_view/helpers/tags/base.rb#L141
- https://github.com/rails/rails/blob/5-2-stable/actionview/lib/action_view/helpers/tags/base.rb#L141
This commit is contained in:
Leonardo Tegon 2019-09-20 10:53:52 -03:00
parent 6f677ec0e9
commit 13d0341bdf
1 changed files with 22 additions and 4 deletions

View File

@ -45,8 +45,17 @@ class BuilderTest < ActionView::TestCase
test "collection radio sanitizes collection values for labels correctly" do
with_collection_radio_buttons @user, :name, ['$0.99', '$1.99'], :to_s, :to_s
assert_select 'label.collection_radio_buttons[for=user_name_099]', '$0.99'
assert_select 'label.collection_radio_buttons[for=user_name_199]', '$1.99'
# Rails 6 changed the way it sanitizes the values
# https://github.com/rails/rails/blob/6-0-stable/actionview/lib/action_view/helpers/tags/base.rb#L141
# https://github.com/rails/rails/blob/5-2-stable/actionview/lib/action_view/helpers/tags/base.rb#L141
if ActionView::VERSION::MAJOR == 5
assert_select 'label.collection_radio_buttons[for=user_name_099]', '$0.99'
assert_select 'label.collection_radio_buttons[for=user_name_199]', '$1.99'
else
assert_select 'label.collection_radio_buttons[for=user_name_0_99]', '$0.99'
assert_select 'label.collection_radio_buttons[for=user_name_1_99]', '$1.99'
end
end
test "collection radio checks the correct value to local variables" do
@ -292,8 +301,17 @@ class BuilderTest < ActionView::TestCase
test "collection check box sanitizes collection values for labels correctly" do
with_collection_check_boxes @user, :name, ['$0.99', '$1.99'], :to_s, :to_s
assert_select 'label.collection_check_boxes[for=user_name_099]', '$0.99'
assert_select 'label.collection_check_boxes[for=user_name_199]', '$1.99'
# Rails 6 changed the way it sanitizes the values
# https://github.com/rails/rails/blob/6-0-stable/actionview/lib/action_view/helpers/tags/base.rb#L141
# https://github.com/rails/rails/blob/5-2-stable/actionview/lib/action_view/helpers/tags/base.rb#L141
if ActionView::VERSION::MAJOR == 5
assert_select 'label.collection_check_boxes[for=user_name_099]', '$0.99'
assert_select 'label.collection_check_boxes[for=user_name_199]', '$1.99'
else
assert_select 'label.collection_check_boxes[for=user_name_0_99]', '$0.99'
assert_select 'label.collection_check_boxes[for=user_name_1_99]', '$1.99'
end
end
test "collection check box checks the correct value to local variables" do