Skip to content

Commit

Permalink
Use different assertions for Rails 5 and 6
Browse files Browse the repository at this point in the history
  • Loading branch information
tegon committed Sep 20, 2019
1 parent 6f677ec commit 13d0341
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions test/action_view_extensions/builder_test.rb
Expand Up @@ -45,8 +45,17 @@ def with_collection_check_boxes(object, attribute, collection, value_method, tex

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
Expand Down Expand Up @@ -292,8 +301,17 @@ def with_collection_check_boxes(object, attribute, collection, value_method, tex

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
Expand Down

0 comments on commit 13d0341

Please sign in to comment.