Skip to content

Commit

Permalink
Add tests to make sure that form helpers work with symbol ids
Browse files Browse the repository at this point in the history
  • Loading branch information
hackling authored and parameme committed Jun 4, 2014
1 parent 3e09cb9 commit d1d2f47
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
29 changes: 29 additions & 0 deletions spec/active_enum/form_helpers/formtastic2_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,35 @@
output.should have_xpath('//option[@value=2]', :content => 'Female')
end

context 'with ids as symbols' do
before do
reset_class Person do
enumerate :sex do
value :id => :m, :name => 'Male'
value :id => :f, :name => 'Female'
end
end
end

it "should use enum input type for enumerated attribute" do
output = semantic_form_for(Person.new, :url => people_path) do |f|
concat f.input(:sex)
end
output.should have_selector('select#person_sex')
output.should have_xpath("//option[@value='m']", :content => 'Male')
output.should have_xpath("//option[@value='f']", :content => 'Female')
end

it "should use explicit :enum input type" do
output = semantic_form_for(Person.new, :url => people_path) do |f|
concat f.input(:sex, :as => :enum)
end
output.should have_selector('select#person_sex')
output.should have_xpath("//option[@value='m']", :content => 'Male')
output.should have_xpath("//option[@value='f']", :content => 'Female')
end
end

it "should not use enum input type if :as option indicates other type" do
output = semantic_form_for(Person.new, :url => people_path) do |f|
concat f.input(:sex, :as => :string)
Expand Down
30 changes: 30 additions & 0 deletions spec/active_enum/form_helpers/simple_form_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,36 @@
output.should have_xpath('//option[@value=2]', :content => 'Female')
end

context 'with ids as symbols' do
before do
controller.stub!(:action_name).and_return('new')
reset_class Person do
enumerate :sex do
value :id => :m, :name => 'Male'
value :id => :f, :name => 'Female'
end
end
end

it "should use enum input type for enumerated attribute" do
output = simple_form_for(Person.new, :url => people_path) do |f|
concat f.input(:sex)
end
output.should have_selector('select#person_sex')
output.should have_xpath("//option[@value='m']", :content => 'Male')
output.should have_xpath("//option[@value='f']", :content => 'Female')
end

it "should use explicit :enum input type" do
output = simple_form_for(Person.new, :url => people_path) do |f|
concat f.input(:sex, :as => :enum)
end
output.should have_selector('select#person_sex')
output.should have_xpath("//option[@value='m']", :content => 'Male')
output.should have_xpath("//option[@value='f']", :content => 'Female')
end
end

it "should not use enum input type if :as option indicates other type" do
output = simple_form_for(Person.new, :url => people_path) do |f|
concat f.input(:sex, :as => :string)
Expand Down

0 comments on commit d1d2f47

Please sign in to comment.