Skip to content

Commit

Permalink
Remove all warnings of invalid CSS selector
Browse files Browse the repository at this point in the history
  • Loading branch information
Rafael Mendonça França committed Sep 8, 2014
1 parent 56f3c0c commit 12e6d89
Show file tree
Hide file tree
Showing 13 changed files with 142 additions and 142 deletions.
62 changes: 31 additions & 31 deletions test/action_view_extensions/builder_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -263,15 +263,15 @@ def with_collection_check_boxes(object, attribute, collection, value_method, tex
collection = [Tag.new(1, 'Tag 1'), Tag.new(2, 'Tag 2')]
with_collection_check_boxes @user, :tag_ids, collection, :id, :name

assert_select 'form input#user_tag_ids_1[type=checkbox][value=1]'
assert_select 'form input#user_tag_ids_2[type=checkbox][value=2]'
assert_select 'form input#user_tag_ids_1[type=checkbox][value="1"]'
assert_select 'form input#user_tag_ids_2[type=checkbox][value="2"]'
end

test "collection check box generates only one hidden field for the entire collection, to ensure something will be sent back to the server when posting an empty collection" do
collection = [Tag.new(1, 'Tag 1'), Tag.new(2, 'Tag 2')]
with_collection_check_boxes @user, :tag_ids, collection, :id, :name

assert_select "form input[type=hidden][name='user[tag_ids][]'][value=]", count: 1
assert_select 'form input[type=hidden][name="user[tag_ids][]"][value=""]', count: 1
end

test "collection check box accepts a collection and generate a serie of checkboxes with labels for label method" do
Expand Down Expand Up @@ -301,81 +301,81 @@ def with_collection_check_boxes(object, attribute, collection, value_method, tex

with_collection_check_boxes user, :tag_ids, collection, :first, :last

assert_select 'form input[type=checkbox][value=1][checked=checked]'
assert_select 'form input[type=checkbox][value=3][checked=checked]'
assert_no_select 'form input[type=checkbox][value=2][checked=checked]'
assert_select 'form input[type=checkbox][value="1"][checked=checked]'
assert_select 'form input[type=checkbox][value="3"][checked=checked]'
assert_no_select 'form input[type=checkbox][value="2"][checked=checked]'
end

test "collection check box accepts selected values as :checked option" do
collection = (1..3).map { |i| [i, "Tag #{i}"] }
with_collection_check_boxes @user, :tag_ids, collection, :first, :last, checked: [1, 3]

assert_select 'form input[type=checkbox][value=1][checked=checked]'
assert_select 'form input[type=checkbox][value=3][checked=checked]'
assert_no_select 'form input[type=checkbox][value=2][checked=checked]'
assert_select 'form input[type=checkbox][value="1"][checked=checked]'
assert_select 'form input[type=checkbox][value="3"][checked=checked]'
assert_no_select 'form input[type=checkbox][value="2"][checked=checked]'
end

test "collection check boxes accepts selected string values as :checked option" do
collection = (1..3).map { |i| [i, "Category #{i}"] }
with_collection_check_boxes :user, :category_ids, collection, :first, :last, checked: ['1', '3']

assert_select 'input[type=checkbox][value=1][checked=checked]'
assert_select 'input[type=checkbox][value=3][checked=checked]'
assert_no_select 'input[type=checkbox][value=2][checked=checked]'
assert_select 'input[type=checkbox][value="1"][checked=checked]'
assert_select 'input[type=checkbox][value="3"][checked=checked]'
assert_no_select 'input[type=checkbox][value="2"][checked=checked]'
end

test "collection check box accepts a single checked value" do
collection = (1..3).map { |i| [i, "Tag #{i}"] }
with_collection_check_boxes @user, :tag_ids, collection, :first, :last, checked: 3

assert_select 'form input[type=checkbox][value=3][checked=checked]'
assert_no_select 'form input[type=checkbox][value=1][checked=checked]'
assert_no_select 'form input[type=checkbox][value=2][checked=checked]'
assert_select 'form input[type=checkbox][value="3"][checked=checked]'
assert_no_select 'form input[type=checkbox][value="1"][checked=checked]'
assert_no_select 'form input[type=checkbox][value="2"][checked=checked]'
end

test "collection check box accepts selected values as :checked option and override the model values" do
collection = (1..3).map { |i| [i, "Tag #{i}"] }
@user.tag_ids = [2]
with_collection_check_boxes @user, :tag_ids, collection, :first, :last, checked: [1, 3]

assert_select 'form input[type=checkbox][value=1][checked=checked]'
assert_select 'form input[type=checkbox][value=3][checked=checked]'
assert_no_select 'form input[type=checkbox][value=2][checked=checked]'
assert_select 'form input[type=checkbox][value="1"][checked=checked]'
assert_select 'form input[type=checkbox][value="3"][checked=checked]'
assert_no_select 'form input[type=checkbox][value="2"][checked=checked]'
end

test "collection check box accepts multiple disabled items" do
collection = (1..3).map { |i| [i, "Tag #{i}"] }
with_collection_check_boxes @user, :tag_ids, collection, :first, :last, disabled: [1, 3]

assert_select 'form input[type=checkbox][value=1][disabled=disabled]'
assert_select 'form input[type=checkbox][value=3][disabled=disabled]'
assert_no_select 'form input[type=checkbox][value=2][disabled=disabled]'
assert_select 'form input[type=checkbox][value="1"][disabled=disabled]'
assert_select 'form input[type=checkbox][value="3"][disabled=disabled]'
assert_no_select 'form input[type=checkbox][value="2"][disabled=disabled]'
end

test "collection check box accepts single disable item" do
collection = (1..3).map { |i| [i, "Tag #{i}"] }
with_collection_check_boxes @user, :tag_ids, collection, :first, :last, disabled: 1

assert_select 'form input[type=checkbox][value=1][disabled=disabled]'
assert_no_select 'form input[type=checkbox][value=3][disabled=disabled]'
assert_no_select 'form input[type=checkbox][value=2][disabled=disabled]'
assert_select 'form input[type=checkbox][value="1"][disabled=disabled]'
assert_no_select 'form input[type=checkbox][value="3"][disabled=disabled]'
assert_no_select 'form input[type=checkbox][value="2"][disabled=disabled]'
end

test "collection check box accepts a proc to disabled items" do
collection = (1..3).map { |i| [i, "Tag #{i}"] }
with_collection_check_boxes @user, :tag_ids, collection, :first, :last, disabled: proc { |i| i.first == 1 }

assert_select 'form input[type=checkbox][value=1][disabled=disabled]'
assert_no_select 'form input[type=checkbox][value=3][disabled=disabled]'
assert_no_select 'form input[type=checkbox][value=2][disabled=disabled]'
assert_select 'form input[type=checkbox][value="1"][disabled=disabled]'
assert_no_select 'form input[type=checkbox][value="3"][disabled=disabled]'
assert_no_select 'form input[type=checkbox][value="2"][disabled=disabled]'
end

test "collection check box accepts html options" do
collection = [[1, 'Tag 1'], [2, 'Tag 2']]
with_collection_check_boxes @user, :tag_ids, collection, :first, :last, {}, class: 'check'

assert_select 'form input.check[type=checkbox][value=1]'
assert_select 'form input.check[type=checkbox][value=2]'
assert_select 'form input.check[type=checkbox][value="1"]'
assert_select 'form input.check[type=checkbox][value="2"]'
end

test "collection check box with fields for" do
Expand All @@ -386,8 +386,8 @@ def with_collection_check_boxes(object, attribute, collection, value_method, tex
end
end

assert_select 'form input#user_post_tag_ids_1[type=checkbox][value=1]'
assert_select 'form input#user_post_tag_ids_2[type=checkbox][value=2]'
assert_select 'form input#user_post_tag_ids_1[type=checkbox][value="1"]'
assert_select 'form input#user_post_tag_ids_2[type=checkbox][value="2"]'

assert_select 'form label.collection_check_boxes[for=user_post_tag_ids_1]', 'Tag 1'
assert_select 'form label.collection_check_boxes[for=user_post_tag_ids_2]', 'Tag 2'
Expand Down
2 changes: 1 addition & 1 deletion test/action_view_extensions/form_helper_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ class FormHelperTest < ActionView::TestCase
test 'passes options to SimpleForm' do
with_concat_form_for(:user, url: '/account', html: { id: 'my_form' })
assert_select 'form#my_form'
assert_select 'form[action=/account]'
assert_select 'form[action="/account"]'
end

test 'form_for yields an instance of FormBuilder' do
Expand Down
2 changes: 1 addition & 1 deletion test/components/label_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ def @controller.action_name; nil; end
test 'label uses i18n to find required text' do
store_translations(:en, simple_form: { required: { text: 'campo requerido' } }) do
with_label_for @user, :name, :string
assert_select 'form label abbr[title=campo requerido]', '*'
assert_select 'form label abbr[title="campo requerido"]', '*'
end
end

Expand Down
74 changes: 37 additions & 37 deletions test/form_builder/association_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ def with_association_for(object, *args)

with_association_for @user, :tags
assert_select 'form select.select#user_tag_ids'
assert_select 'form select option[value=1]', 'Tag 1'
assert_select 'form select option[value=2]', 'Tag 2'
assert_select 'form select option[value=3]', 'Tag 3'
assert_select 'form select option[value="1"]', 'Tag 1'
assert_select 'form select option[value="2"]', 'Tag 2'
assert_select 'form select option[value="3"]', 'Tag 3'

value.verify
end
Expand All @@ -59,9 +59,9 @@ def with_association_for(object, *args)

with_association_for @user, :tags, preload: false
assert_select 'form select.select#user_tag_ids'
assert_select 'form select option[value=1]', 'Tag 1'
assert_select 'form select option[value=2]', 'Tag 2'
assert_select 'form select option[value=3]', 'Tag 3'
assert_select 'form select option[value="1"]', 'Tag 1'
assert_select 'form select option[value="2"]', 'Tag 2'
assert_select 'form select option[value="3"]', 'Tag 3'

assert_raises MockExpectationError do
value.verify
Expand All @@ -74,9 +74,9 @@ def with_association_for(object, *args)

with_association_for @user, :company
assert_select 'form select.select#user_company_id'
assert_select 'form select option[value=1]', 'Company 1'
assert_select 'form select option[value=2]', 'Company 2'
assert_select 'form select option[value=3]', 'Company 3'
assert_select 'form select option[value="1"]', 'Company 1'
assert_select 'form select option[value="2"]', 'Company 2'
assert_select 'form select option[value="3"]', 'Company 3'

assert_raises MockExpectationError do
value.verify
Expand All @@ -87,15 +87,15 @@ def with_association_for(object, *args)
test 'builder creates a select for belongs_to associations' do
with_association_for @user, :company
assert_select 'form select.select#user_company_id'
assert_select 'form select option[value=1]', 'Company 1'
assert_select 'form select option[value=2]', 'Company 2'
assert_select 'form select option[value=3]', 'Company 3'
assert_select 'form select option[value="1"]', 'Company 1'
assert_select 'form select option[value="2"]', 'Company 2'
assert_select 'form select option[value="3"]', 'Company 3'
end

test 'builder creates blank select if collection is nil' do
with_association_for @user, :company, collection: nil
assert_select 'form select.select#user_company_id'
assert_no_select 'form select option[value=1]', 'Company 1'
assert_no_select 'form select option[value="1"]', 'Company 1'
end

test 'builder allows collection radio for belongs_to associations' do
Expand All @@ -108,17 +108,17 @@ def with_association_for(object, *args)
test 'builder allows collection to have a proc as a condition' do
with_association_for @user, :extra_special_company
assert_select 'form select.select#user_extra_special_company_id'
assert_select 'form select option[value=1]'
assert_no_select 'form select option[value=2]'
assert_no_select 'form select option[value=3]'
assert_select 'form select option[value="1"]'
assert_no_select 'form select option[value="2"]'
assert_no_select 'form select option[value="3"]'
end

test 'builder allows collection to have a scope' do
with_association_for @user, :special_pictures
assert_select 'form select.select#user_special_picture_ids'
assert_select 'form select option[value=3]', '3'
assert_no_select 'form select option[value=1]'
assert_no_select 'form select option[value=2]'
assert_select 'form select option[value="3"]', '3'
assert_no_select 'form select option[value="1"]'
assert_no_select 'form select option[value="2"]'
end

test 'builder marks the record which already belongs to the user' do
Expand All @@ -133,17 +133,17 @@ def with_association_for(object, *args)
test 'builder uses reflection conditions to find collection' do
with_association_for @user, :special_company
assert_select 'form select.select#user_special_company_id'
assert_select 'form select option[value=1]'
assert_no_select 'form select option[value=2]'
assert_no_select 'form select option[value=3]'
assert_select 'form select option[value="1"]'
assert_no_select 'form select option[value="2"]'
assert_no_select 'form select option[value="3"]'
end

test 'builder allows overriding collection to association input' do
with_association_for @user, :company, include_blank: false,
collection: [Company.new(999, 'Teste')]
assert_select 'form select.select#user_company_id'
assert_no_select 'form select option[value=1]'
assert_select 'form select option[value=999]', 'Teste'
assert_no_select 'form select option[value="1"]'
assert_select 'form select option[value="999"]', 'Teste'
assert_select 'form select option', count: 1
end

Expand All @@ -158,31 +158,31 @@ def with_association_for(object, *args)
with_association_for @user, :pictures
assert_select 'form select.select#user_picture_ids'
assert_select 'form select[multiple=multiple]'
assert_select 'form select option[value=1]', 'Picture 1'
assert_select 'form select option[value=2]', 'Picture 2'
assert_select 'form select option[value=3]', 'Picture 3'
assert_select 'form select option[value="1"]', 'Picture 1'
assert_select 'form select option[value="2"]', 'Picture 2'
assert_select 'form select option[value="3"]', 'Picture 3'
end

test 'builder creates a select with multiple options for collection associations' do
with_association_for @user, :tags
assert_select 'form select.select#user_tag_ids'
assert_select 'form select[multiple=multiple]'
assert_select 'form select option[value=1]', 'Tag 1'
assert_select 'form select option[value=2]', 'Tag 2'
assert_select 'form select option[value=3]', 'Tag 3'
assert_select 'form select option[value="1"]', 'Tag 1'
assert_select 'form select option[value="2"]', 'Tag 2'
assert_select 'form select option[value="3"]', 'Tag 3'
end

test 'builder allows size to be overwritten for collection associations' do
with_association_for @user, :tags, input_html: { size: 10 }
assert_select 'form select[multiple=multiple][size=10]'
assert_select 'form select[multiple=multiple][size="10"]'
end

test 'builder marks all selected records which already belongs to user' do
@user.tag_ids = [1, 2]
with_association_for @user, :tags
assert_select 'form select option[value=1][selected=selected]'
assert_select 'form select option[value=2][selected=selected]'
assert_no_select 'form select option[value=3][selected=selected]'
assert_select 'form select option[value="1"][selected=selected]'
assert_select 'form select option[value="2"][selected=selected]'
assert_no_select 'form select option[value="3"][selected=selected]'
end

test 'builder allows a collection of check boxes for collection associations' do
Expand All @@ -196,9 +196,9 @@ def with_association_for(object, *args)
test 'builder marks all selected records for collection boxes' do
@user.tag_ids = [1, 2]
with_association_for @user, :tags, as: :check_boxes
assert_select 'form input[type=checkbox][value=1][checked=checked]'
assert_select 'form input[type=checkbox][value=2][checked=checked]'
assert_no_select 'form input[type=checkbox][value=3][checked=checked]'
assert_select 'form input[type=checkbox][value="1"][checked=checked]'
assert_select 'form input[type=checkbox][value="2"][checked=checked]'
assert_no_select 'form input[type=checkbox][value="3"][checked=checked]'
end

test 'builder with collection support giving collection and item wrapper tags' do
Expand Down
10 changes: 5 additions & 5 deletions test/form_builder/button_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,31 +10,31 @@ def with_button_for(object, *args)

test 'builder creates buttons' do
with_button_for :post, :submit
assert_select 'form input.button[type=submit][value=Save Post]'
assert_select 'form input.button[type=submit][value="Save Post"]'
end

test 'builder creates buttons with options' do
with_button_for :post, :submit, class: 'my_button'
assert_select 'form input.button.my_button[type=submit][value=Save Post]'
assert_select 'form input.button.my_button[type=submit][value="Save Post"]'
end

test 'builder does not modify the options hash' do
options = { class: 'my_button' }
with_button_for :post, :submit, options
assert_select 'form input.button.my_button[type=submit][value=Save Post]'
assert_select 'form input.button.my_button[type=submit][value="Save Post"]'
assert_equal({ class: 'my_button' }, options)
end

test 'builder creates buttons for records' do
@user.new_record!
with_button_for @user, :submit
assert_select 'form input.button[type=submit][value=Create User]'
assert_select 'form input.button[type=submit][value="Create User"]'
end

test "builder uses the default class from the configuration" do
swap SimpleForm, button_class: 'btn' do
with_button_for :post, :submit
assert_select 'form input.btn[type=submit][value=Save Post]'
assert_select 'form input.btn[type=submit][value="Save Post"]'
end
end

Expand Down
6 changes: 3 additions & 3 deletions test/form_builder/input_field_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class InputFieldTest < ActionView::TestCase
f.input_field :name
end

assert_select 'input.string[placeholder=Name goes here]'
assert_select 'input.string[placeholder="Name goes here"]'
end
end

Expand All @@ -85,7 +85,7 @@ class InputFieldTest < ActionView::TestCase
f.input_field :age, as: :integer
end

assert_select 'input[min=18]'
assert_select 'input[min="18"]'
end

test 'builder input_field does not use pattern component by default' do
Expand Down Expand Up @@ -125,7 +125,7 @@ class InputFieldTest < ActionView::TestCase
f.input_field :name, as: :string
end

assert_select 'input.string[maxlength=25]'
assert_select 'input.string[maxlength="25"]'
end

test 'builder collection input_field generates input tag with a clean HTML' do
Expand Down
Loading

0 comments on commit 12e6d89

Please sign in to comment.