formtastic 0.9.7 → 0.9.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.textile +69 -12
- data/Rakefile +1 -1
- data/generators/form/templates/view__form.html.erb +2 -2
- data/generators/form/templates/view__form.html.haml +2 -2
- data/generators/formtastic/templates/formtastic.css +58 -50
- data/generators/formtastic/templates/formtastic.rb +3 -0
- data/generators/formtastic/templates/formtastic_changes.css +5 -1
- data/lib/formtastic.rb +108 -37
- data/lib/formtastic/layout_helper.rb +10 -0
- data/rails/init.rb +2 -0
- data/spec/commit_button_spec.rb +26 -4
- data/spec/custom_macros.rb +0 -101
- data/spec/form_helper_spec.rb +6 -0
- data/spec/input_spec.rb +34 -0
- data/spec/inputs/boolean_input_spec.rb +9 -5
- data/spec/inputs/check_boxes_input_spec.rb +33 -10
- data/spec/inputs/date_input_spec.rb +137 -25
- data/spec/inputs/datetime_input_spec.rb +177 -54
- data/spec/inputs/hidden_input_spec.rb +9 -0
- data/spec/inputs/radio_input_spec.rb +15 -9
- data/spec/inputs/select_input_spec.rb +113 -83
- data/spec/inputs/time_input_spec.rb +151 -25
- data/spec/inputs/time_zone_input_spec.rb +4 -2
- data/spec/layout_helper_spec.rb +29 -0
- data/spec/semantic_errors_spec.rb +98 -0
- data/spec/spec_helper.rb +26 -18
- metadata +50 -22
| @@ -13,68 +13,76 @@ describe 'datetime input' do | |
| 13 13 | 
             
                @new_post.should_receive(:created_at=).any_number_of_times
         | 
| 14 14 | 
             
                @bob.should_receive(:created_at=).any_number_of_times
         | 
| 15 15 | 
             
                @new_post.should_receive(:title=).any_number_of_times # Macro stuff forces this.
         | 
| 16 | 
            -
                
         | 
| 17 | 
            -
                semantic_form_for(@new_post) do |builder|
         | 
| 18 | 
            -
                  concat(builder.input(:publish_at, :as => :datetime))
         | 
| 19 | 
            -
                end
         | 
| 20 16 | 
             
              end
         | 
| 21 | 
            -
             
         | 
| 22 | 
            -
              it_should_have_input_wrapper_with_class("datetime")
         | 
| 23 | 
            -
              it_should_have_input_wrapper_with_id("post_publish_at_input")
         | 
| 24 | 
            -
              it_should_have_a_nested_fieldset
         | 
| 25 | 
            -
              it_should_apply_error_logic_for_input_type(:datetime)
         | 
| 26 17 |  | 
| 27 | 
            -
               | 
| 28 | 
            -
                 | 
| 29 | 
            -
             | 
| 30 | 
            -
             | 
| 31 | 
            -
             | 
| 32 | 
            -
             | 
| 33 | 
            -
                output_buffer.should have_tag('form li.datetime fieldset ol li', :count => 5)
         | 
| 34 | 
            -
              end
         | 
| 35 | 
            -
             | 
| 36 | 
            -
              it 'should have five labels for year, month, day, hour and minute' do
         | 
| 37 | 
            -
                output_buffer.should have_tag('form li.datetime fieldset ol li label', :count => 5)
         | 
| 38 | 
            -
                output_buffer.should have_tag('form li.datetime fieldset ol li label', /year/i)
         | 
| 39 | 
            -
                output_buffer.should have_tag('form li.datetime fieldset ol li label', /month/i)
         | 
| 40 | 
            -
                output_buffer.should have_tag('form li.datetime fieldset ol li label', /day/i)
         | 
| 41 | 
            -
                output_buffer.should have_tag('form li.datetime fieldset ol li label', /hour/i)
         | 
| 42 | 
            -
                output_buffer.should have_tag('form li.datetime fieldset ol li label', /minute/i)
         | 
| 43 | 
            -
              end
         | 
| 44 | 
            -
             | 
| 45 | 
            -
              it 'should have five selects for year, month, day, hour and minute' do
         | 
| 46 | 
            -
                output_buffer.should have_tag('form li.datetime fieldset ol li select', :count => 5)
         | 
| 47 | 
            -
              end
         | 
| 48 | 
            -
             | 
| 49 | 
            -
              it 'should generate a sanitized label and matching ids for attribute' do
         | 
| 50 | 
            -
                semantic_form_for(@new_post) do |builder|
         | 
| 51 | 
            -
                  builder.semantic_fields_for(@bob, :index => 10) do |bob_builder|
         | 
| 52 | 
            -
                    concat(bob_builder.input(:created_at, :as => :datetime))
         | 
| 18 | 
            +
              describe "general" do
         | 
| 19 | 
            +
                
         | 
| 20 | 
            +
                before do
         | 
| 21 | 
            +
                  output_buffer.replace ''
         | 
| 22 | 
            +
                  semantic_form_for(@new_post) do |builder|
         | 
| 23 | 
            +
                    concat(builder.input(:publish_at, :as => :datetime))
         | 
| 53 24 | 
             
                  end
         | 
| 54 25 | 
             
                end
         | 
| 55 | 
            -
             | 
| 56 | 
            -
                 | 
| 57 | 
            -
             | 
| 58 | 
            -
             | 
| 26 | 
            +
             
         | 
| 27 | 
            +
                it_should_have_input_wrapper_with_class("datetime")
         | 
| 28 | 
            +
                it_should_have_input_wrapper_with_id("post_publish_at_input")
         | 
| 29 | 
            +
                it_should_have_a_nested_fieldset
         | 
| 30 | 
            +
                it_should_apply_error_logic_for_input_type(:datetime)
         | 
| 31 | 
            +
                
         | 
| 32 | 
            +
                it 'should have a legend and label with the label text inside the fieldset' do
         | 
| 33 | 
            +
                  output_buffer.should have_tag('form li.datetime fieldset legend.label label', /Publish at/)
         | 
| 34 | 
            +
                end
         | 
| 35 | 
            +
                
         | 
| 36 | 
            +
                it 'should associate the legend label with the first select' do
         | 
| 37 | 
            +
                  output_buffer.should have_tag('form li.datetime fieldset legend.label label[@for="post_publish_at_1i"]')
         | 
| 38 | 
            +
                end
         | 
| 39 | 
            +
                
         | 
| 40 | 
            +
                it 'should have an ordered list of five items inside the fieldset' do
         | 
| 41 | 
            +
                  output_buffer.should have_tag('form li.datetime fieldset ol')
         | 
| 42 | 
            +
                  output_buffer.should have_tag('form li.datetime fieldset ol li', :count => 5)
         | 
| 43 | 
            +
                end
         | 
| 44 | 
            +
                
         | 
| 45 | 
            +
                it 'should have five labels for year, month, day, hour and minute' do
         | 
| 46 | 
            +
                  output_buffer.should have_tag('form li.datetime fieldset ol li label', :count => 5)
         | 
| 47 | 
            +
                  output_buffer.should have_tag('form li.datetime fieldset ol li label', /year/i)
         | 
| 48 | 
            +
                  output_buffer.should have_tag('form li.datetime fieldset ol li label', /month/i)
         | 
| 49 | 
            +
                  output_buffer.should have_tag('form li.datetime fieldset ol li label', /day/i)
         | 
| 50 | 
            +
                  output_buffer.should have_tag('form li.datetime fieldset ol li label', /hour/i)
         | 
| 51 | 
            +
                  output_buffer.should have_tag('form li.datetime fieldset ol li label', /minute/i)
         | 
| 52 | 
            +
                end
         | 
| 53 | 
            +
                
         | 
| 54 | 
            +
                it 'should have five selects for year, month, day, hour and minute' do
         | 
| 55 | 
            +
                  output_buffer.should have_tag('form li.datetime fieldset ol li select', :count => 5)
         | 
| 56 | 
            +
                end
         | 
| 57 | 
            +
                
         | 
| 58 | 
            +
                it 'should generate a sanitized label and matching ids for attribute' do
         | 
| 59 | 
            +
                  semantic_form_for(@new_post) do |builder|
         | 
| 60 | 
            +
                    builder.semantic_fields_for(@bob, :index => 10) do |bob_builder|
         | 
| 61 | 
            +
                      concat(bob_builder.input(:created_at, :as => :datetime))
         | 
| 62 | 
            +
                    end
         | 
| 63 | 
            +
                  end
         | 
| 64 | 
            +
                
         | 
| 65 | 
            +
                  1.upto(5) do |i|
         | 
| 66 | 
            +
                    output_buffer.should have_tag("form li fieldset ol li label[@for='post_author_10_created_at_#{i}i']")
         | 
| 67 | 
            +
                    output_buffer.should have_tag("form li fieldset ol li #post_author_10_created_at_#{i}i")
         | 
| 68 | 
            +
                  end
         | 
| 59 69 | 
             
                end
         | 
| 60 70 | 
             
              end
         | 
| 61 71 |  | 
| 62 | 
            -
              it_should_select_existing_datetime_else_current(:year, :month, :day, :hour, :minute, :second)
         | 
| 63 | 
            -
              it_should_select_explicit_default_value_if_set(:year, :month, :day, :hour, :minute, :second)
         | 
| 64 | 
            -
             | 
| 65 72 | 
             
              describe 'when :discard_input => true is set' do
         | 
| 66 73 | 
             
                it 'should use default attribute value when it is not nil' do
         | 
| 67 74 | 
             
                  @new_post.stub!(:publish_at).and_return(Date.new(2007,12,27))
         | 
| 68 75 | 
             
                  semantic_form_for(@new_post) do |builder|
         | 
| 69 76 | 
             
                    concat(builder.input(:publish_at, :as => :datetime, :discard_day => true))
         | 
| 70 77 | 
             
                  end
         | 
| 71 | 
            -
             | 
| 78 | 
            +
              
         | 
| 72 79 | 
             
                  output_buffer.should have_tag("form li input[@type='hidden'][@value='27']")
         | 
| 73 80 | 
             
                end
         | 
| 74 81 | 
             
              end
         | 
| 75 | 
            -
             | 
| 82 | 
            +
              
         | 
| 76 83 | 
             
              describe 'inputs order' do
         | 
| 77 84 | 
             
                it 'should have a default' do
         | 
| 85 | 
            +
                  output_buffer.replace ''
         | 
| 78 86 | 
             
                  semantic_form_for(@new_post) do |builder|
         | 
| 79 87 | 
             
                    self.should_receive(:select_year).once.ordered.and_return('')
         | 
| 80 88 | 
             
                    self.should_receive(:select_month).once.ordered.and_return('')
         | 
| @@ -82,18 +90,21 @@ describe 'datetime input' do | |
| 82 90 | 
             
                    builder.input(:publish_at, :as => :datetime)
         | 
| 83 91 | 
             
                  end
         | 
| 84 92 | 
             
                end
         | 
| 85 | 
            -
             | 
| 93 | 
            +
              
         | 
| 86 94 | 
             
                it 'should be specified with :order option' do
         | 
| 87 95 | 
             
                  ::I18n.backend.store_translations 'en', :date => { :order => [:month, :year, :day] }
         | 
| 96 | 
            +
                  output_buffer.replace ''
         | 
| 88 97 | 
             
                  semantic_form_for(@new_post) do |builder|
         | 
| 89 98 | 
             
                    self.should_receive(:select_month).once.ordered.and_return('')
         | 
| 90 99 | 
             
                    self.should_receive(:select_year).once.ordered.and_return('')
         | 
| 91 100 | 
             
                    self.should_receive(:select_day).once.ordered.and_return('')
         | 
| 92 101 | 
             
                    builder.input(:publish_at, :as => :datetime)
         | 
| 102 | 
            +
                    ::I18n.backend.store_translations 'en', :date => nil
         | 
| 93 103 | 
             
                  end
         | 
| 94 104 | 
             
                end
         | 
| 95 | 
            -
             | 
| 105 | 
            +
              
         | 
| 96 106 | 
             
                it 'should be changed through I18n' do
         | 
| 107 | 
            +
                  output_buffer.replace ''
         | 
| 97 108 | 
             
                  semantic_form_for(@new_post) do |builder|
         | 
| 98 109 | 
             
                    self.should_receive(:select_day).once.ordered.and_return('')
         | 
| 99 110 | 
             
                    self.should_receive(:select_month).once.ordered.and_return('')
         | 
| @@ -102,25 +113,26 @@ describe 'datetime input' do | |
| 102 113 | 
             
                  end
         | 
| 103 114 | 
             
                end
         | 
| 104 115 | 
             
              end
         | 
| 105 | 
            -
             | 
| 116 | 
            +
              
         | 
| 106 117 | 
             
              describe 'when the locale changes the label text' do
         | 
| 107 118 | 
             
                before do
         | 
| 108 119 | 
             
                  ::I18n.backend.store_translations 'en', :datetime => {:prompts => {
         | 
| 109 120 | 
             
                    :year => 'The Year', :month => 'The Month', :day => 'The Day',
         | 
| 110 121 | 
             
                    :hour => 'The Hour', :minute => 'The Minute'
         | 
| 111 122 | 
             
                  }}
         | 
| 123 | 
            +
                  output_buffer.replace ''
         | 
| 112 124 | 
             
                  semantic_form_for(@new_post) do |builder|
         | 
| 113 125 | 
             
                    concat(builder.input(:publish_at, :as => :datetime))
         | 
| 114 126 | 
             
                  end
         | 
| 115 127 | 
             
                end
         | 
| 116 | 
            -
             | 
| 128 | 
            +
              
         | 
| 117 129 | 
             
                after do
         | 
| 118 130 | 
             
                  ::I18n.backend.store_translations 'en', :formtastic => {
         | 
| 119 131 | 
             
                    :year => nil, :month => nil, :day => nil,
         | 
| 120 132 | 
             
                    :hour => nil, :minute => nil
         | 
| 121 133 | 
             
                  }
         | 
| 122 134 | 
             
                end
         | 
| 123 | 
            -
             | 
| 135 | 
            +
              
         | 
| 124 136 | 
             
                it 'should have translated labels for year, month, day, hour and minute' do
         | 
| 125 137 | 
             
                  output_buffer.should have_tag('form li.datetime fieldset ol li label', /The Year/)
         | 
| 126 138 | 
             
                  output_buffer.should have_tag('form li.datetime fieldset ol li label', /The Month/)
         | 
| @@ -129,7 +141,7 @@ describe 'datetime input' do | |
| 129 141 | 
             
                  output_buffer.should have_tag('form li.datetime fieldset ol li label', /The Minute/)
         | 
| 130 142 | 
             
                end
         | 
| 131 143 | 
             
              end
         | 
| 132 | 
            -
             | 
| 144 | 
            +
              
         | 
| 133 145 | 
             
              describe 'when no object is given' do
         | 
| 134 146 | 
             
                before(:each) do
         | 
| 135 147 | 
             
                  output_buffer.replace ''
         | 
| @@ -137,19 +149,130 @@ describe 'datetime input' do | |
| 137 149 | 
             
                    concat(builder.input(:publish_at, :as => :datetime))
         | 
| 138 150 | 
             
                  end
         | 
| 139 151 | 
             
                end
         | 
| 140 | 
            -
             | 
| 152 | 
            +
              
         | 
| 141 153 | 
             
                it 'should have fieldset with legend - classified as a label' do
         | 
| 142 154 | 
             
                  output_buffer.should have_tag('form li.datetime fieldset legend.label', /Publish at/)
         | 
| 143 155 | 
             
                end
         | 
| 144 | 
            -
             | 
| 156 | 
            +
              
         | 
| 145 157 | 
             
                it 'should have labels for each input' do
         | 
| 146 158 | 
             
                  output_buffer.should have_tag('form li.datetime fieldset ol li label', :count => 5)
         | 
| 147 159 | 
             
                end
         | 
| 148 | 
            -
             | 
| 160 | 
            +
              
         | 
| 149 161 | 
             
                it 'should have selects for each inputs' do
         | 
| 150 162 | 
             
                  output_buffer.should have_tag('form li.datetime fieldset ol li select', :count => 5)
         | 
| 151 163 | 
             
                end
         | 
| 152 164 | 
             
              end
         | 
| 153 | 
            -
             | 
| 165 | 
            +
              
         | 
| 166 | 
            +
              describe ':selected option' do
         | 
| 167 | 
            +
                
         | 
| 168 | 
            +
                describe "when the object has a value" do
         | 
| 169 | 
            +
                  it "should select the object value (ignoring :selected)" do
         | 
| 170 | 
            +
                    output_buffer.replace ''
         | 
| 171 | 
            +
                    @new_post.stub!(:created_at => Time.mktime(2012))
         | 
| 172 | 
            +
                    with_deprecation_silenced do 
         | 
| 173 | 
            +
                      semantic_form_for(@new_post) do |builder|
         | 
| 174 | 
            +
                        concat(builder.input(:created_at, :as => :datetime, :selected => Time.mktime(1999)))
         | 
| 175 | 
            +
                      end
         | 
| 176 | 
            +
                    end
         | 
| 177 | 
            +
                    output_buffer.should have_tag("form li ol li select#post_created_at_1i option[@selected]", :count => 1)
         | 
| 178 | 
            +
                    output_buffer.should have_tag("form li ol li select#post_created_at_1i option[@value='2012'][@selected]", :count => 1)
         | 
| 179 | 
            +
                  end
         | 
| 180 | 
            +
                end
         | 
| 181 | 
            +
                
         | 
| 182 | 
            +
                describe 'when the object has no value' do
         | 
| 183 | 
            +
                  it "should select the :selected if provided as a Date" do
         | 
| 184 | 
            +
                    output_buffer.replace ''
         | 
| 185 | 
            +
                    @new_post.stub!(:created_at => nil)
         | 
| 186 | 
            +
                    with_deprecation_silenced do
         | 
| 187 | 
            +
                      semantic_form_for(@new_post) do |builder|
         | 
| 188 | 
            +
                        concat(builder.input(:created_at, :as => :datetime, :selected => Date.new(1999)))
         | 
| 189 | 
            +
                      end
         | 
| 190 | 
            +
                    end
         | 
| 191 | 
            +
                    output_buffer.should have_tag("form li ol li select#post_created_at_1i option[@selected]", :count => 1)
         | 
| 192 | 
            +
                    output_buffer.should have_tag("form li ol li select#post_created_at_1i option[@value='1999'][@selected]", :count => 1)
         | 
| 193 | 
            +
                  end
         | 
| 194 | 
            +
                  
         | 
| 195 | 
            +
                  it "should select the :selected if provided as a Time" do
         | 
| 196 | 
            +
                    output_buffer.replace ''
         | 
| 197 | 
            +
                    @new_post.stub!(:created_at => nil)
         | 
| 198 | 
            +
                    with_deprecation_silenced do
         | 
| 199 | 
            +
                      semantic_form_for(@new_post) do |builder|
         | 
| 200 | 
            +
                        concat(builder.input(:created_at, :as => :datetime, :selected => Time.mktime(1999)))
         | 
| 201 | 
            +
                      end
         | 
| 202 | 
            +
                    end
         | 
| 203 | 
            +
                    output_buffer.should have_tag("form li ol li select#post_created_at_1i option[@selected]", :count => 1)
         | 
| 204 | 
            +
                    output_buffer.should have_tag("form li ol li select#post_created_at_1i option[@value='1999'][@selected]", :count => 1)
         | 
| 205 | 
            +
                  end
         | 
| 206 | 
            +
                  
         | 
| 207 | 
            +
                  it "should not select an option if the :selected is provided as nil" do
         | 
| 208 | 
            +
                    output_buffer.replace ''
         | 
| 209 | 
            +
                    @new_post.stub!(:created_at => nil)
         | 
| 210 | 
            +
                    with_deprecation_silenced do
         | 
| 211 | 
            +
                      semantic_form_for(@new_post) do |builder|
         | 
| 212 | 
            +
                        concat(builder.input(:created_at, :as => :datetime, :selected => nil))
         | 
| 213 | 
            +
                      end
         | 
| 214 | 
            +
                    end
         | 
| 215 | 
            +
                    output_buffer.should_not have_tag("form li ol li select#post_created_at_1i option[@selected]")
         | 
| 216 | 
            +
                  end
         | 
| 217 | 
            +
                  
         | 
| 218 | 
            +
                  it "should select Time.now if a :selected is not provided" do
         | 
| 219 | 
            +
                    output_buffer.replace ''
         | 
| 220 | 
            +
                    @new_post.stub!(:created_at => nil)
         | 
| 221 | 
            +
                    semantic_form_for(@new_post) do |builder|
         | 
| 222 | 
            +
                      concat(builder.input(:created_at, :as => :datetime))
         | 
| 223 | 
            +
                    end
         | 
| 224 | 
            +
                    output_buffer.should have_tag("form li ol li select#post_created_at_1i option[@selected]", :count => 1)
         | 
| 225 | 
            +
                    output_buffer.should have_tag("form li ol li select#post_created_at_1i option[@value='#{Time.now.year}'][@selected]", :count => 1)
         | 
| 226 | 
            +
                    
         | 
| 227 | 
            +
                  end
         | 
| 228 | 
            +
                end
         | 
| 229 | 
            +
                
         | 
| 230 | 
            +
                it 'should warn about :selected deprecation' do
         | 
| 231 | 
            +
                  with_deprecation_silenced do
         | 
| 232 | 
            +
                    ::ActiveSupport::Deprecation.should_receive(:warn).any_number_of_times
         | 
| 233 | 
            +
                    semantic_form_for(@new_post) do |builder|
         | 
| 234 | 
            +
                      concat(builder.input(:created_at, :as => :date, :selected => Time.mktime(1999)))
         | 
| 235 | 
            +
                    end
         | 
| 236 | 
            +
                  end
         | 
| 237 | 
            +
                end
         | 
| 238 | 
            +
                
         | 
| 239 | 
            +
              end
         | 
| 240 | 
            +
              
         | 
| 241 | 
            +
              describe ':labels option' do
         | 
| 242 | 
            +
                fields = [:year, :month, :day, :hour, :minute]
         | 
| 243 | 
            +
                fields.each do |field|
         | 
| 244 | 
            +
                  it "should replace the #{field} label with the specified text if :labels[:#{field}] is set" do
         | 
| 245 | 
            +
                    output_buffer.replace ''
         | 
| 246 | 
            +
                    semantic_form_for(@new_post) do |builder|
         | 
| 247 | 
            +
                      concat(builder.input(:created_at, :as => :datetime, :labels => { field => "another #{field} label" }))
         | 
| 248 | 
            +
                    end
         | 
| 249 | 
            +
                    output_buffer.should have_tag('form li.datetime fieldset ol li label', :count => fields.length)
         | 
| 250 | 
            +
                    fields.each do |f|
         | 
| 251 | 
            +
                      output_buffer.should have_tag('form li.datetime fieldset ol li label', f == field ? /another #{f} label/i : /#{f}/i)
         | 
| 252 | 
            +
                    end
         | 
| 253 | 
            +
                  end
         | 
| 254 | 
            +
              
         | 
| 255 | 
            +
                  it "should not display the label for the #{field} field when :labels[:#{field}] is blank" do
         | 
| 256 | 
            +
                    output_buffer.replace ''
         | 
| 257 | 
            +
                    semantic_form_for(@new_post) do |builder|
         | 
| 258 | 
            +
                      concat(builder.input(:created_at, :as => :datetime, :labels => { field => "" }))
         | 
| 259 | 
            +
                    end
         | 
| 260 | 
            +
                    output_buffer.should have_tag('form li.datetime fieldset ol li label', :count => fields.length-1)
         | 
| 261 | 
            +
                    fields.each do |f|
         | 
| 262 | 
            +
                      output_buffer.should have_tag('form li.datetime fieldset ol li label', /#{f}/i) unless field == f
         | 
| 263 | 
            +
                    end
         | 
| 264 | 
            +
                  end
         | 
| 265 | 
            +
                end
         | 
| 266 | 
            +
              end
         | 
| 267 | 
            +
              
         | 
| 268 | 
            +
              it 'should warn about :selected deprecation' do
         | 
| 269 | 
            +
                with_deprecation_silenced do
         | 
| 270 | 
            +
                  ::ActiveSupport::Deprecation.should_receive(:warn).any_number_of_times
         | 
| 271 | 
            +
                  semantic_form_for(@new_post) do |builder|
         | 
| 272 | 
            +
                    concat(builder.input(:created_at, :as => :datetime, :selected => Time.mktime(1999)))
         | 
| 273 | 
            +
                  end
         | 
| 274 | 
            +
                end
         | 
| 275 | 
            +
              end
         | 
| 276 | 
            +
              
         | 
| 154 277 | 
             
            end
         | 
| 155 278 |  | 
| @@ -47,6 +47,15 @@ describe 'hidden input' do | |
| 47 47 | 
             
                output_buffer.should_not have_tag("form li p.inline-errors")
         | 
| 48 48 | 
             
                output_buffer.should_not have_tag("form li ul.errors")
         | 
| 49 49 | 
             
              end
         | 
| 50 | 
            +
             | 
| 51 | 
            +
              it "should not render inline hints" do
         | 
| 52 | 
            +
                semantic_form_for(@new_post) do |builder|
         | 
| 53 | 
            +
                  concat(builder.input(:secret, :as => :hidden, :hint => "all your base are belong to use"))
         | 
| 54 | 
            +
                end
         | 
| 55 | 
            +
             | 
| 56 | 
            +
                output_buffer.should_not have_tag("form li p.inline-hints")
         | 
| 57 | 
            +
                output_buffer.should_not have_tag("form li ul.hints")
         | 
| 58 | 
            +
              end
         | 
| 50 59 |  | 
| 51 60 | 
             
            end
         | 
| 52 61 |  | 
| @@ -23,10 +23,13 @@ describe 'radio input' do | |
| 23 23 | 
             
                it_should_apply_error_logic_for_input_type(:radio)
         | 
| 24 24 | 
             
                it_should_use_the_collection_when_provided(:radio, 'input')
         | 
| 25 25 |  | 
| 26 | 
            +
                it 'should generate a legend containing a label with text for the input' do
         | 
| 27 | 
            +
                  output_buffer.should have_tag('form li fieldset legend.label label')
         | 
| 28 | 
            +
                  output_buffer.should have_tag('form li fieldset legend.label label', /Author/)
         | 
| 29 | 
            +
                end
         | 
| 26 30 |  | 
| 27 | 
            -
                it 'should  | 
| 28 | 
            -
                  output_buffer. | 
| 29 | 
            -
                  output_buffer.should have_tag('form li fieldset legend.label', /Author/)
         | 
| 31 | 
            +
                it 'should not link the label within the legend to any input' do
         | 
| 32 | 
            +
                  output_buffer.should_not have_tag('form li fieldset legend label[@for^="post_author_id_"]')
         | 
| 30 33 | 
             
                end
         | 
| 31 34 |  | 
| 32 35 | 
             
                it 'should generate an ordered list with a list item for each choice' do
         | 
| @@ -117,9 +120,11 @@ describe 'radio input' do | |
| 117 120 | 
             
                describe "no selected items" do
         | 
| 118 121 | 
             
                  before do
         | 
| 119 122 | 
             
                    @new_post.stub!(:author_ids).and_return(nil)
         | 
| 120 | 
            -
             | 
| 121 | 
            -
                     | 
| 122 | 
            -
                       | 
| 123 | 
            +
                    
         | 
| 124 | 
            +
                    with_deprecation_silenced do
         | 
| 125 | 
            +
                      semantic_form_for(@new_post) do |builder|
         | 
| 126 | 
            +
                        concat(builder.input(:authors, :as => :radio, :selected => nil))
         | 
| 127 | 
            +
                      end
         | 
| 123 128 | 
             
                    end
         | 
| 124 129 | 
             
                  end
         | 
| 125 130 |  | 
| @@ -131,9 +136,10 @@ describe 'radio input' do | |
| 131 136 | 
             
                describe "single selected item" do
         | 
| 132 137 | 
             
                  before do
         | 
| 133 138 | 
             
                    @new_post.stub!(:author_ids).and_return(nil)
         | 
| 134 | 
            -
             | 
| 135 | 
            -
             | 
| 136 | 
            -
             | 
| 139 | 
            +
                    with_deprecation_silenced do
         | 
| 140 | 
            +
                      semantic_form_for(@new_post) do |builder|
         | 
| 141 | 
            +
                        concat(builder.input(:authors, :as => :radio, :selected => @fred.id))
         | 
| 142 | 
            +
                      end
         | 
| 137 143 | 
             
                    end
         | 
| 138 144 | 
             
                  end
         | 
| 139 145 |  | 
| @@ -47,6 +47,49 @@ describe 'select input' do | |
| 47 47 | 
             
                end
         | 
| 48 48 | 
             
              end
         | 
| 49 49 |  | 
| 50 | 
            +
              describe 'for boolean columns' do
         | 
| 51 | 
            +
                describe 'default formtastic locale' do
         | 
| 52 | 
            +
                  before do
         | 
| 53 | 
            +
                    # Note: Works, but something like Formtastic.root.join(...) would probably be "safer".
         | 
| 54 | 
            +
                    ::I18n.load_path = [File.join(File.dirname(__FILE__), *%w[.. .. lib locale en.yml])]
         | 
| 55 | 
            +
                    ::I18n.backend.send(:init_translations)
         | 
| 56 | 
            +
             | 
| 57 | 
            +
                    semantic_form_for(@new_post) do |builder|
         | 
| 58 | 
            +
                      concat(builder.input(:published, :as => :select))
         | 
| 59 | 
            +
                    end
         | 
| 60 | 
            +
                  end
         | 
| 61 | 
            +
             | 
| 62 | 
            +
                  after do
         | 
| 63 | 
            +
                    ::I18n.backend.store_translations :en, {}
         | 
| 64 | 
            +
                  end
         | 
| 65 | 
            +
             | 
| 66 | 
            +
                  it 'should render a select with at least options: true/false' do
         | 
| 67 | 
            +
                    output_buffer.should have_tag("form li select option[@value='true']", /^Yes$/)
         | 
| 68 | 
            +
                    output_buffer.should have_tag("form li select option[@value='false']", /^No$/)
         | 
| 69 | 
            +
                  end
         | 
| 70 | 
            +
                end
         | 
| 71 | 
            +
                
         | 
| 72 | 
            +
                describe 'custom locale' do
         | 
| 73 | 
            +
                  before do
         | 
| 74 | 
            +
                    @boolean_select_labels = {:yes => 'Yep', :no => 'Nope'}
         | 
| 75 | 
            +
                    ::I18n.backend.store_translations :en, :formtastic => @boolean_select_labels
         | 
| 76 | 
            +
             | 
| 77 | 
            +
                    semantic_form_for(@new_post) do |builder|
         | 
| 78 | 
            +
                      concat(builder.input(:published, :as => :select))
         | 
| 79 | 
            +
                    end
         | 
| 80 | 
            +
                  end
         | 
| 81 | 
            +
             | 
| 82 | 
            +
                  after do
         | 
| 83 | 
            +
                    ::I18n.backend.store_translations :en, {}
         | 
| 84 | 
            +
                  end
         | 
| 85 | 
            +
             | 
| 86 | 
            +
                  it 'should render a select with at least options: true/false' do
         | 
| 87 | 
            +
                    output_buffer.should have_tag("form li select option[@value='true']", /#{@boolean_select_labels[:yes]}/)
         | 
| 88 | 
            +
                    output_buffer.should have_tag("form li select option[@value='false']", /#{@boolean_select_labels[:no]}/)
         | 
| 89 | 
            +
                  end
         | 
| 90 | 
            +
                end
         | 
| 91 | 
            +
              end
         | 
| 92 | 
            +
             | 
| 50 93 | 
             
              describe 'for a belongs_to association' do
         | 
| 51 94 | 
             
                before do
         | 
| 52 95 | 
             
                  semantic_form_for(@new_post) do |builder|
         | 
| @@ -106,6 +149,20 @@ describe 'select input' do | |
| 106 149 |  | 
| 107 150 | 
             
                  output_buffer.should have_tag('form li select#post_author_status_id')
         | 
| 108 151 | 
             
                end
         | 
| 152 | 
            +
             | 
| 153 | 
            +
                it 'should use the "class_name" option' do
         | 
| 154 | 
            +
                  @new_post.stub!(:status).and_return(@bob)
         | 
| 155 | 
            +
                  @new_post.stub!(:author_status_id).and_return(@bob.id)
         | 
| 156 | 
            +
               
         | 
| 157 | 
            +
                  ::Post.stub!(:reflect_on_association).with(:status).and_return(
         | 
| 158 | 
            +
                    mock('reflection', :options => {:class_name => 'AuthorStatus'}, :klass => ::Author, :macro => :belongs_to))
         | 
| 159 | 
            +
             | 
| 160 | 
            +
                  semantic_form_for(@new_post) do |builder|
         | 
| 161 | 
            +
                    concat(builder.input(:status, :as => :select))
         | 
| 162 | 
            +
                  end
         | 
| 163 | 
            +
             | 
| 164 | 
            +
                  output_buffer.should have_tag('form li select#post_author_status_id')
         | 
| 165 | 
            +
                end
         | 
| 109 166 | 
             
              end
         | 
| 110 167 |  | 
| 111 168 | 
             
              describe "for a belongs_to association with :group_by => :author" do
         | 
| @@ -256,7 +313,7 @@ describe 'select input' do | |
| 256 313 | 
             
                  output_buffer.should have_tag('form li select option[@selected]', :count => 1)
         | 
| 257 314 | 
             
                end
         | 
| 258 315 | 
             
              end
         | 
| 259 | 
            -
             | 
| 316 | 
            +
              
         | 
| 260 317 | 
             
              describe 'when :prompt => "choose something" is set' do
         | 
| 261 318 | 
             
                before do
         | 
| 262 319 | 
             
                  @new_post.stub!(:author_id).and_return(nil)
         | 
| @@ -297,7 +354,7 @@ describe 'select input' do | |
| 297 354 | 
             
                  end
         | 
| 298 355 | 
             
                end
         | 
| 299 356 | 
             
              end
         | 
| 300 | 
            -
             | 
| 357 | 
            +
              
         | 
| 301 358 | 
             
              describe 'when :selected is set' do
         | 
| 302 359 | 
             
                before do
         | 
| 303 360 | 
             
                  @output_buffer = ''
         | 
| @@ -306,11 +363,13 @@ describe 'select input' do | |
| 306 363 | 
             
                describe "no selected items" do
         | 
| 307 364 | 
             
                  before do
         | 
| 308 365 | 
             
                    @new_post.stub!(:author_id).and_return(nil)
         | 
| 309 | 
            -
                     | 
| 310 | 
            -
                       | 
| 366 | 
            +
                    with_deprecation_silenced do
         | 
| 367 | 
            +
                      semantic_form_for(@new_post) do |builder|
         | 
| 368 | 
            +
                        concat(builder.input(:author, :as => :select, :selected => nil))
         | 
| 369 | 
            +
                      end
         | 
| 311 370 | 
             
                    end
         | 
| 312 371 | 
             
                  end
         | 
| 313 | 
            -
             | 
| 372 | 
            +
                  
         | 
| 314 373 | 
             
                  it 'should not have any selected item(s)' do
         | 
| 315 374 | 
             
                    output_buffer.should_not have_tag("form li select option[@selected='selected']")
         | 
| 316 375 | 
             
                  end
         | 
| @@ -319,8 +378,10 @@ describe 'select input' do | |
| 319 378 | 
             
                describe "single selected item" do
         | 
| 320 379 | 
             
                  before do
         | 
| 321 380 | 
             
                    @new_post.stub!(:author_id).and_return(nil)
         | 
| 322 | 
            -
                     | 
| 323 | 
            -
                       | 
| 381 | 
            +
                    with_deprecation_silenced do
         | 
| 382 | 
            +
                      semantic_form_for(@new_post) do |builder|
         | 
| 383 | 
            +
                        concat(builder.input(:author, :as => :select, :selected => @bob.id))
         | 
| 384 | 
            +
                      end
         | 
| 324 385 | 
             
                    end
         | 
| 325 386 | 
             
                  end
         | 
| 326 387 |  | 
| @@ -337,16 +398,17 @@ describe 'select input' do | |
| 337 398 | 
             
                    before do
         | 
| 338 399 | 
             
                      @new_post.stub!(:author_ids).and_return(nil)
         | 
| 339 400 |  | 
| 340 | 
            -
                       | 
| 341 | 
            -
                         | 
| 401 | 
            +
                      with_deprecation_silenced do
         | 
| 402 | 
            +
                        semantic_form_for(@new_post) do |builder|
         | 
| 403 | 
            +
                          concat(builder.input(:authors, :as => :select, :selected => [@bob.id, @fred.id], :multiple => false))
         | 
| 404 | 
            +
                        end
         | 
| 342 405 | 
             
                      end
         | 
| 343 406 | 
             
                    end
         | 
| 344 407 |  | 
| 345 408 | 
             
                    it "should only select the first value" do
         | 
| 346 409 | 
             
                      output_buffer.should have_tag("form li select option[@selected='selected']", :count => 1)
         | 
| 347 | 
            -
                       | 
| 348 | 
            -
                       | 
| 349 | 
            -
                      # output_buffer.should have_tag("form li select:not([@multiple]) option[@selected='selected'][@value='#{@bob.id}']")
         | 
| 410 | 
            +
                      output_buffer.should have_tag("form li select:not([@multiple]) option[@selected='selected']", /bob/i)
         | 
| 411 | 
            +
                      output_buffer.should have_tag("form li select:not([@multiple]) option[@selected='selected'][@value='#{@bob.id}']")
         | 
| 350 412 | 
             
                    end
         | 
| 351 413 | 
             
                  end
         | 
| 352 414 |  | 
| @@ -354,8 +416,10 @@ describe 'select input' do | |
| 354 416 | 
             
                    before do
         | 
| 355 417 | 
             
                      @new_post.stub!(:author_ids).and_return(nil)
         | 
| 356 418 |  | 
| 357 | 
            -
                       | 
| 358 | 
            -
                         | 
| 419 | 
            +
                      with_deprecation_silenced do
         | 
| 420 | 
            +
                        semantic_form_for(@new_post) do |builder|
         | 
| 421 | 
            +
                          concat(builder.input(:authors, :as => :select, :selected => [@bob.id, @fred.id]))
         | 
| 422 | 
            +
                        end
         | 
| 359 423 | 
             
                      end
         | 
| 360 424 | 
             
                    end
         | 
| 361 425 |  | 
| @@ -371,89 +435,55 @@ describe 'select input' do | |
| 371 435 | 
             
                end
         | 
| 372 436 |  | 
| 373 437 | 
             
              end
         | 
| 374 | 
            -
             | 
| 375 | 
            -
              describe  | 
| 376 | 
            -
                 | 
| 438 | 
            +
              
         | 
| 439 | 
            +
              describe "enum" do
         | 
| 440 | 
            +
                before do
         | 
| 441 | 
            +
                  @output_buffer = ''
         | 
| 442 | 
            +
                  @some_meta_descriptions = ["One", "Two", "Three"]
         | 
| 443 | 
            +
                  @new_post.stub!(:meta_description).any_number_of_times
         | 
| 444 | 
            +
                end
         | 
| 445 | 
            +
              
         | 
| 446 | 
            +
                describe ":as is not set" do
         | 
| 377 447 | 
             
                  before do
         | 
| 378 | 
            -
                    # Note: Works, but something like Formtastic.root.join(...) would probably be "safer".
         | 
| 379 | 
            -
                    ::I18n.load_path = [File.join(File.dirname(__FILE__), *%w[.. .. lib locale en.yml])]
         | 
| 380 | 
            -
                    ::I18n.backend.send(:init_translations)
         | 
| 381 | 
            -
             | 
| 382 448 | 
             
                    semantic_form_for(@new_post) do |builder|
         | 
| 383 | 
            -
                      concat(builder.input(: | 
| 449 | 
            +
                      concat(builder.input(:meta_description, :collection => @some_meta_descriptions))
         | 
| 450 | 
            +
                    end
         | 
| 451 | 
            +
                    semantic_form_for(:project, :url => 'http://test.host') do |builder|
         | 
| 452 | 
            +
                      concat(builder.input(:meta_description, :collection => @some_meta_descriptions))
         | 
| 384 453 | 
             
                    end
         | 
| 385 454 | 
             
                  end
         | 
| 386 | 
            -
             | 
| 387 | 
            -
                   | 
| 388 | 
            -
                     | 
| 389 | 
            -
                  end
         | 
| 390 | 
            -
             | 
| 391 | 
            -
                  it 'should render a select with at least options: true/false' do
         | 
| 392 | 
            -
                    output_buffer.should have_tag("form li select option[@value='true']", /^Yes$/)
         | 
| 393 | 
            -
                    output_buffer.should have_tag("form li select option[@value='false']", /^No$/)
         | 
| 455 | 
            +
              
         | 
| 456 | 
            +
                  it "should render a select field" do
         | 
| 457 | 
            +
                    output_buffer.should have_tag("form li select", :count => 2)
         | 
| 394 458 | 
             
                  end
         | 
| 395 459 | 
             
                end
         | 
| 396 | 
            -
             | 
| 397 | 
            -
                describe  | 
| 460 | 
            +
              
         | 
| 461 | 
            +
                describe ":as is set" do
         | 
| 398 462 | 
             
                  before do
         | 
| 399 | 
            -
                     | 
| 400 | 
            -
                    ::I18n.backend.store_translations :en, :formtastic => @boolean_select_labels
         | 
| 401 | 
            -
             | 
| 463 | 
            +
                    # Should not be a case, but just checking :as got highest priority in setting input type.
         | 
| 402 464 | 
             
                    semantic_form_for(@new_post) do |builder|
         | 
| 403 | 
            -
                      concat(builder.input(: | 
| 465 | 
            +
                      concat(builder.input(:meta_description, :as => :string, :collection => @some_meta_descriptions))
         | 
| 466 | 
            +
                    end
         | 
| 467 | 
            +
                    semantic_form_for(:project, :url => 'http://test.host') do |builder|
         | 
| 468 | 
            +
                      concat(builder.input(:meta_description, :as => :string, :collection => @some_meta_descriptions))
         | 
| 404 469 | 
             
                    end
         | 
| 405 470 | 
             
                  end
         | 
| 406 | 
            -
             | 
| 407 | 
            -
                   | 
| 408 | 
            -
                     | 
| 409 | 
            -
                  end
         | 
| 410 | 
            -
             | 
| 411 | 
            -
                  it 'should render a select with at least options: true/false' do
         | 
| 412 | 
            -
                    output_buffer.should have_tag("form li select option[@value='true']", /#{@boolean_select_labels[:yes]}/)
         | 
| 413 | 
            -
                    output_buffer.should have_tag("form li select option[@value='false']", /#{@boolean_select_labels[:no]}/)
         | 
| 471 | 
            +
                  
         | 
| 472 | 
            +
                  it "should render a text field" do
         | 
| 473 | 
            +
                    output_buffer.should have_tag("form li input[@type='text']", :count => 2)
         | 
| 414 474 | 
             
                  end
         | 
| 415 475 | 
             
                end
         | 
| 416 476 | 
             
              end
         | 
| 417 | 
            -
             | 
| 418 | 
            -
               | 
| 419 | 
            -
                 | 
| 420 | 
            -
                   | 
| 421 | 
            -
             | 
| 422 | 
            -
                     | 
| 423 | 
            -
                    @new_post.stub!(:meta_description).any_number_of_times
         | 
| 424 | 
            -
                  end
         | 
| 425 | 
            -
             | 
| 426 | 
            -
                  describe ":as is not set" do
         | 
| 427 | 
            -
                    before do
         | 
| 428 | 
            -
                      semantic_form_for(@new_post) do |builder|
         | 
| 429 | 
            -
                        concat(builder.input(:meta_description, :collection => @some_meta_descriptions))
         | 
| 430 | 
            -
                      end
         | 
| 431 | 
            -
                      semantic_form_for(:project, :url => 'http://test.host') do |builder|
         | 
| 432 | 
            -
                        concat(builder.input(:meta_description, :collection => @some_meta_descriptions))
         | 
| 433 | 
            -
                      end
         | 
| 434 | 
            -
                    end
         | 
| 435 | 
            -
             | 
| 436 | 
            -
                    it "should render a select field" do
         | 
| 437 | 
            -
                      output_buffer.should have_tag("form li select", :count => 2)
         | 
| 438 | 
            -
                    end
         | 
| 439 | 
            -
                  end
         | 
| 440 | 
            -
             | 
| 441 | 
            -
                  describe ":as is set" do
         | 
| 442 | 
            -
                    before do
         | 
| 443 | 
            -
                      # Should not be a case, but just checking :as got highest priority in setting input type.
         | 
| 444 | 
            -
                      semantic_form_for(@new_post) do |builder|
         | 
| 445 | 
            -
                        concat(builder.input(:meta_description, :as => :string, :collection => @some_meta_descriptions))
         | 
| 446 | 
            -
                      end
         | 
| 447 | 
            -
                      semantic_form_for(:project, :url => 'http://test.host') do |builder|
         | 
| 448 | 
            -
                        concat(builder.input(:meta_description, :as => :string, :collection => @some_meta_descriptions))
         | 
| 449 | 
            -
                      end
         | 
| 450 | 
            -
                    end
         | 
| 451 | 
            -
                    
         | 
| 452 | 
            -
                    it "should render a text field" do
         | 
| 453 | 
            -
                      output_buffer.should have_tag("form li input[@type='text']", :count => 2)
         | 
| 454 | 
            -
                    end
         | 
| 477 | 
            +
              
         | 
| 478 | 
            +
              it 'should warn about :selected deprecation' do
         | 
| 479 | 
            +
                with_deprecation_silenced do
         | 
| 480 | 
            +
                  ::ActiveSupport::Deprecation.should_receive(:warn).any_number_of_times
         | 
| 481 | 
            +
                  semantic_form_for(@new_post) do |builder|
         | 
| 482 | 
            +
                    concat(builder.input(:author_id, :as => :select, :selected => @bob.id))
         | 
| 455 483 | 
             
                  end
         | 
| 456 484 | 
             
                end
         | 
| 457 485 | 
             
              end
         | 
| 458 | 
            -
             | 
| 486 | 
            +
              
         | 
| 487 | 
            +
              
         | 
| 488 | 
            +
              
         | 
| 459 489 | 
             
            end
         |