@@ -45,8 +45,17 @@ def with_collection_check_boxes(object, attribute, collection, value_method, tex
4545
4646 test "collection radio sanitizes collection values for labels correctly" do
4747 with_collection_radio_buttons @user , :name , [ '$0.99' , '$1.99' ] , :to_s , :to_s
48- assert_select 'label.collection_radio_buttons[for=user_name_099]' , '$0.99'
49- assert_select 'label.collection_radio_buttons[for=user_name_199]' , '$1.99'
48+
49+ # Rails 6 changed the way it sanitizes the values
50+ # https://github.com/rails/rails/blob/6-0-stable/actionview/lib/action_view/helpers/tags/base.rb#L141
51+ # https://github.com/rails/rails/blob/5-2-stable/actionview/lib/action_view/helpers/tags/base.rb#L141
52+ if ActionView ::VERSION ::MAJOR == 5
53+ assert_select 'label.collection_radio_buttons[for=user_name_099]' , '$0.99'
54+ assert_select 'label.collection_radio_buttons[for=user_name_199]' , '$1.99'
55+ else
56+ assert_select 'label.collection_radio_buttons[for=user_name_0_99]' , '$0.99'
57+ assert_select 'label.collection_radio_buttons[for=user_name_1_99]' , '$1.99'
58+ end
5059 end
5160
5261 test "collection radio checks the correct value to local variables" do
@@ -292,8 +301,17 @@ def with_collection_check_boxes(object, attribute, collection, value_method, tex
292301
293302 test "collection check box sanitizes collection values for labels correctly" do
294303 with_collection_check_boxes @user , :name , [ '$0.99' , '$1.99' ] , :to_s , :to_s
295- assert_select 'label.collection_check_boxes[for=user_name_099]' , '$0.99'
296- assert_select 'label.collection_check_boxes[for=user_name_199]' , '$1.99'
304+
305+ # Rails 6 changed the way it sanitizes the values
306+ # https://github.com/rails/rails/blob/6-0-stable/actionview/lib/action_view/helpers/tags/base.rb#L141
307+ # https://github.com/rails/rails/blob/5-2-stable/actionview/lib/action_view/helpers/tags/base.rb#L141
308+ if ActionView ::VERSION ::MAJOR == 5
309+ assert_select 'label.collection_check_boxes[for=user_name_099]' , '$0.99'
310+ assert_select 'label.collection_check_boxes[for=user_name_199]' , '$1.99'
311+ else
312+ assert_select 'label.collection_check_boxes[for=user_name_0_99]' , '$0.99'
313+ assert_select 'label.collection_check_boxes[for=user_name_1_99]' , '$1.99'
314+ end
297315 end
298316
299317 test "collection check box checks the correct value to local variables" do
0 commit comments