diff --git a/spec/active_enum/form_helpers/formtastic2_spec.rb b/spec/active_enum/form_helpers/formtastic2_spec.rb index 7ef3b79..7373b6f 100644 --- a/spec/active_enum/form_helpers/formtastic2_spec.rb +++ b/spec/active_enum/form_helpers/formtastic2_spec.rb @@ -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) diff --git a/spec/active_enum/form_helpers/simple_form_spec.rb b/spec/active_enum/form_helpers/simple_form_spec.rb index fd19fb4..eb988fd 100644 --- a/spec/active_enum/form_helpers/simple_form_spec.rb +++ b/spec/active_enum/form_helpers/simple_form_spec.rb @@ -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)