formtastic 2.3.0.rc2 → 2.3.0.rc3

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.
Files changed (50) hide show
  1. data/.travis.yml +27 -1
  2. data/Appraisals +5 -0
  3. data/CHANGELOG +1 -0
  4. data/README.textile +19 -26
  5. data/formtastic.gemspec +4 -3
  6. data/gemfiles/rails_3.0.gemfile +1 -1
  7. data/gemfiles/rails_3.1.gemfile +1 -1
  8. data/gemfiles/rails_3.2.gemfile +1 -1
  9. data/gemfiles/rails_4.0.4.gemfile +7 -0
  10. data/gemfiles/rails_4.gemfile +1 -1
  11. data/lib/formtastic/form_builder.rb +9 -1
  12. data/lib/formtastic/helpers/form_helper.rb +11 -6
  13. data/lib/formtastic/helpers/inputs_helper.rb +6 -1
  14. data/lib/formtastic/inputs/base/collections.rb +1 -1
  15. data/lib/formtastic/inputs/base/validations.rb +1 -1
  16. data/lib/formtastic/inputs/boolean_input.rb +4 -14
  17. data/lib/formtastic/inputs/check_boxes_input.rb +7 -1
  18. data/lib/formtastic/inputs/radio_input.rb +2 -0
  19. data/lib/formtastic/util.rb +13 -1
  20. data/lib/formtastic/version.rb +1 -1
  21. data/lib/generators/templates/_form.html.slim +2 -2
  22. data/lib/generators/templates/formtastic.rb +15 -1
  23. data/spec/actions/generic_action_spec.rb +3 -3
  24. data/spec/builder/custom_builder_spec.rb +7 -7
  25. data/spec/builder/semantic_fields_for_spec.rb +8 -8
  26. data/spec/generators/formtastic/form/form_generator_spec.rb +6 -6
  27. data/spec/helpers/action_helper_spec.rb +11 -11
  28. data/spec/helpers/form_helper_spec.rb +22 -11
  29. data/spec/helpers/input_helper_spec.rb +44 -44
  30. data/spec/helpers/inputs_helper_spec.rb +64 -31
  31. data/spec/helpers/semantic_errors_helper_spec.rb +12 -12
  32. data/spec/i18n_spec.rb +5 -5
  33. data/spec/inputs/boolean_input_spec.rb +6 -5
  34. data/spec/inputs/check_boxes_input_spec.rb +27 -9
  35. data/spec/inputs/country_input_spec.rb +5 -5
  36. data/spec/inputs/custom_input_spec.rb +1 -1
  37. data/spec/inputs/date_picker_input_spec.rb +4 -4
  38. data/spec/inputs/datetime_picker_input_spec.rb +4 -4
  39. data/spec/inputs/hidden_input_spec.rb +3 -3
  40. data/spec/inputs/include_blank_spec.rb +2 -2
  41. data/spec/inputs/number_input_spec.rb +36 -36
  42. data/spec/inputs/radio_input_spec.rb +23 -5
  43. data/spec/inputs/range_input_spec.rb +19 -19
  44. data/spec/inputs/select_input_spec.rb +40 -20
  45. data/spec/inputs/string_input_spec.rb +2 -2
  46. data/spec/inputs/time_picker_input_spec.rb +4 -4
  47. data/spec/localizer_spec.rb +1 -1
  48. data/spec/spec_helper.rb +203 -188
  49. data/spec/support/custom_macros.rb +8 -8
  50. metadata +15 -13
@@ -56,13 +56,13 @@ describe 'Formtastic::FormBuilder#inputs' do
56
56
  describe 'when a :for option is provided' do
57
57
 
58
58
  before do
59
- @new_post.stub!(:respond_to?).and_return(true, true)
60
- @new_post.stub!(:respond_to?).with(:empty?).and_return(false)
61
- @new_post.stub!(:author).and_return(@bob)
59
+ @new_post.stub(:respond_to?).and_return(true, true)
60
+ @new_post.stub(:respond_to?).with(:empty?).and_return(false)
61
+ @new_post.stub(:author).and_return(@bob)
62
62
  end
63
63
 
64
64
  it 'should render nested inputs' do
65
- @bob.stub!(:column_for_attribute).and_return(mock('column', :type => :string, :limit => 255))
65
+ @bob.stub(:column_for_attribute).and_return(double('column', :type => :string, :limit => 255))
66
66
 
67
67
  concat(semantic_form_for(@new_post) do |builder|
68
68
  inputs = builder.inputs :for => [:author, @bob] do |bob_builder|
@@ -75,7 +75,7 @@ describe 'Formtastic::FormBuilder#inputs' do
75
75
  end
76
76
 
77
77
  it 'should concat rendered nested inputs to the template' do
78
- @bob.stub!(:column_for_attribute).and_return(mock('column', :type => :string, :limit => 255))
78
+ @bob.stub(:column_for_attribute).and_return(double('column', :type => :string, :limit => 255))
79
79
 
80
80
  concat(semantic_form_for(@new_post) do |builder|
81
81
  builder.inputs :for => [:author, @bob] do |bob_builder|
@@ -104,8 +104,8 @@ describe 'Formtastic::FormBuilder#inputs' do
104
104
 
105
105
  describe "as a symbol representing a has_many association name" do
106
106
  before do
107
- @new_post.stub!(:authors).and_return([@bob, @fred])
108
- @new_post.stub!(:authors_attributes=)
107
+ @new_post.stub(:authors).and_return([@bob, @fred])
108
+ @new_post.stub(:authors_attributes=)
109
109
  end
110
110
 
111
111
  it 'should nest the inputs with a fieldset, legend and :name input for each item' do
@@ -177,7 +177,7 @@ describe 'Formtastic::FormBuilder#inputs' do
177
177
  end
178
178
 
179
179
  it 'should pass options down to semantic_fields_for' do
180
- @bob.stub!(:column_for_attribute).and_return(mock('column', :type => :string, :limit => 255))
180
+ @bob.stub(:column_for_attribute).and_return(double('column', :type => :string, :limit => 255))
181
181
 
182
182
  concat(semantic_form_for(@new_post) do |builder|
183
183
  inputs = builder.inputs :for => [:author, @bob], :for_options => { :index => 10 } do |bob_builder|
@@ -341,17 +341,17 @@ describe 'Formtastic::FormBuilder#inputs' do
341
341
  describe 'without a block' do
342
342
 
343
343
  before do
344
- ::Post.stub!(:reflections).and_return({:author => mock('reflection', :options => {}, :macro => :belongs_to),
345
- :comments => mock('reflection', :options => {}, :macro => :has_many) })
344
+ ::Post.stub(:reflections).and_return({:author => double('reflection', :options => {}, :macro => :belongs_to),
345
+ :comments => double('reflection', :options => {}, :macro => :has_many) })
346
346
 
347
- @new_post.stub!(:title)
348
- @new_post.stub!(:body)
349
- @new_post.stub!(:author_id)
347
+ @new_post.stub(:title)
348
+ @new_post.stub(:body)
349
+ @new_post.stub(:author_id)
350
350
 
351
- @new_post.stub!(:column_for_attribute).with(:title).and_return(mock('column', :type => :string, :limit => 255))
352
- @new_post.stub!(:column_for_attribute).with(:body).and_return(mock('column', :type => :text))
353
- @new_post.stub!(:column_for_attribute).with(:created_at).and_return(mock('column', :type => :datetime))
354
- @new_post.stub!(:column_for_attribute).with(:author).and_return(nil)
351
+ @new_post.stub(:column_for_attribute).with(:title).and_return(double('column', :type => :string, :limit => 255))
352
+ @new_post.stub(:column_for_attribute).with(:body).and_return(double('column', :type => :text))
353
+ @new_post.stub(:column_for_attribute).with(:created_at).and_return(double('column', :type => :datetime))
354
+ @new_post.stub(:column_for_attribute).with(:author).and_return(nil)
355
355
  end
356
356
 
357
357
  describe 'with no args (quick forms syntax)' do
@@ -402,12 +402,12 @@ describe 'Formtastic::FormBuilder#inputs' do
402
402
  context "with a polymorphic association" do
403
403
 
404
404
  before do
405
- @new_post.stub!(:commentable)
406
- @new_post.class.stub!(:reflections).and_return({
407
- :commentable => mock('macro_reflection', :options => { :polymorphic => true }, :macro => :belongs_to)
405
+ @new_post.stub(:commentable)
406
+ @new_post.class.stub(:reflections).and_return({
407
+ :commentable => double('macro_reflection', :options => { :polymorphic => true }, :macro => :belongs_to)
408
408
  })
409
- @new_post.stub!(:column_for_attribute).with(:commentable).and_return(
410
- mock('column', :type => :integer)
409
+ @new_post.stub(:column_for_attribute).with(:commentable).and_return(
410
+ double('column', :type => :integer)
411
411
  )
412
412
  end
413
413
 
@@ -447,15 +447,15 @@ describe 'Formtastic::FormBuilder#inputs' do
447
447
  context "with a polymorphic association" do
448
448
 
449
449
  it 'should raise an error for polymorphic associations (the collection class cannot be guessed)' do
450
- @new_post.stub!(:commentable)
451
- @new_post.class.stub!(:reflections).and_return({
452
- :commentable => mock('macro_reflection', :options => { :polymorphic => true }, :macro => :belongs_to)
450
+ @new_post.stub(:commentable)
451
+ @new_post.class.stub(:reflections).and_return({
452
+ :commentable => double('macro_reflection', :options => { :polymorphic => true }, :macro => :belongs_to)
453
453
  })
454
- @new_post.stub!(:column_for_attribute).with(:commentable).and_return(
455
- mock('column', :type => :integer)
454
+ @new_post.stub(:column_for_attribute).with(:commentable).and_return(
455
+ double('column', :type => :integer)
456
456
  )
457
- @new_post.class.stub!(:reflect_on_association).with(:commentable).and_return(
458
- mock('reflection', :macro => :belongs_to, :options => { :polymorphic => true })
457
+ @new_post.class.stub(:reflect_on_association).with(:commentable).and_return(
458
+ double('reflection', :macro => :belongs_to, :options => { :polymorphic => true })
459
459
  )
460
460
 
461
461
  expect {
@@ -472,7 +472,7 @@ describe 'Formtastic::FormBuilder#inputs' do
472
472
  describe 'when a :for option is provided' do
473
473
  describe 'and an object is given' do
474
474
  it 'should render nested inputs' do
475
- @bob.stub!(:column_for_attribute).and_return(mock('column', :type => :string, :limit => 255))
475
+ @bob.stub(:column_for_attribute).and_return(double('column', :type => :string, :limit => 255))
476
476
  concat(semantic_form_for(@new_post) do |builder|
477
477
  concat(builder.inputs(:login, :for => @bob))
478
478
  end)
@@ -516,7 +516,40 @@ describe 'Formtastic::FormBuilder#inputs' do
516
516
  output_buffer.should have_tag('form > fieldset#my-id-2.inputs > legend', /^#{@legend_text_using_arg}$/)
517
517
  end
518
518
  end
519
-
519
+
520
+ describe 'when a :except option is provided' do
521
+ describe 'and an object is given' do
522
+ it 'should render a form with a fieldset containing only string item' do
523
+ concat(semantic_form_for(@new_post) do |builder|
524
+ concat(builder.inputs :except => :body)
525
+ end)
526
+
527
+ output_buffer.should have_tag('form > fieldset.inputs > ol > li', :count => 2)
528
+ output_buffer.should have_tag('form > fieldset.inputs > ol > li.string')
529
+ output_buffer.should_not have_tag('form > fieldset.inputs > ol > li.text')
530
+ end
531
+
532
+ it 'should render a form with a fieldset containing only text item' do
533
+ concat(semantic_form_for(@new_post) do |builder|
534
+ concat(builder.inputs :except => :title)
535
+ end)
536
+
537
+ output_buffer.should have_tag('form > fieldset.inputs > ol > li', :count => 2)
538
+ output_buffer.should_not have_tag('form > fieldset.inputs > ol > li.string')
539
+ output_buffer.should have_tag('form > fieldset.inputs > ol > li.text')
540
+ end
541
+ end
542
+
543
+ describe 'and no object is given' do
544
+ it 'should render a form with a fieldset containing two list items' do
545
+ concat(semantic_form_for(:project, :url => 'http://test.host') do |builder|
546
+ concat(builder.inputs(:title, :body))
547
+ end)
548
+
549
+ output_buffer.should have_tag('form > fieldset.inputs > ol > li.string', :count => 2)
550
+ end
551
+ end
552
+ end
520
553
  end
521
554
 
522
555
  describe 'nesting' do
@@ -11,13 +11,13 @@ describe 'Formtastic::FormBuilder#semantic_errors' do
11
11
  @title_errors = ['must not be blank', 'must be awesome']
12
12
  @base_errors = ['base error message', 'nasty error']
13
13
  @base_error = 'one base error'
14
- @errors = mock('errors')
15
- @new_post.stub!(:errors).and_return(@errors)
14
+ @errors = double('errors')
15
+ @new_post.stub(:errors).and_return(@errors)
16
16
  end
17
17
 
18
18
  describe 'when there is only one error on base' do
19
19
  before do
20
- @errors.stub!(:[]).with(errors_matcher(:base)).and_return(@base_error)
20
+ @errors.stub(:[]).with(errors_matcher(:base)).and_return(@base_error)
21
21
  end
22
22
 
23
23
  it 'should render an unordered list' do
@@ -29,7 +29,7 @@ describe 'Formtastic::FormBuilder#semantic_errors' do
29
29
 
30
30
  describe 'when there is more than one error on base' do
31
31
  before do
32
- @errors.stub!(:[]).with(errors_matcher(:base)).and_return(@base_errors)
32
+ @errors.stub(:[]).with(errors_matcher(:base)).and_return(@base_errors)
33
33
  end
34
34
 
35
35
  it 'should render an unordered list' do
@@ -44,8 +44,8 @@ describe 'Formtastic::FormBuilder#semantic_errors' do
44
44
 
45
45
  describe 'when there are errors on title' do
46
46
  before do
47
- @errors.stub!(:[]).with(errors_matcher(:title)).and_return(@title_errors)
48
- @errors.stub!(:[]).with(errors_matcher(:base)).and_return([])
47
+ @errors.stub(:[]).with(errors_matcher(:title)).and_return(@title_errors)
48
+ @errors.stub(:[]).with(errors_matcher(:base)).and_return([])
49
49
  end
50
50
 
51
51
  it 'should render an unordered list' do
@@ -58,8 +58,8 @@ describe 'Formtastic::FormBuilder#semantic_errors' do
58
58
 
59
59
  describe 'when there are errors on title and base' do
60
60
  before do
61
- @errors.stub!(:[]).with(errors_matcher(:title)).and_return(@title_errors)
62
- @errors.stub!(:[]).with(errors_matcher(:base)).and_return(@base_error)
61
+ @errors.stub(:[]).with(errors_matcher(:title)).and_return(@title_errors)
62
+ @errors.stub(:[]).with(errors_matcher(:base)).and_return(@base_error)
63
63
  end
64
64
 
65
65
  it 'should render an unordered list' do
@@ -73,8 +73,8 @@ describe 'Formtastic::FormBuilder#semantic_errors' do
73
73
 
74
74
  describe 'when there are no errors' do
75
75
  before do
76
- @errors.stub!(:[]).with(errors_matcher(:title)).and_return(nil)
77
- @errors.stub!(:[]).with(errors_matcher(:base)).and_return(nil)
76
+ @errors.stub(:[]).with(errors_matcher(:title)).and_return(nil)
77
+ @errors.stub(:[]).with(errors_matcher(:base)).and_return(nil)
78
78
  end
79
79
 
80
80
  it 'should return nil' do
@@ -86,7 +86,7 @@ describe 'Formtastic::FormBuilder#semantic_errors' do
86
86
 
87
87
  describe 'when there is one error on base and options with class is passed' do
88
88
  before do
89
- @errors.stub!(:[]).with(errors_matcher(:base)).and_return(@base_error)
89
+ @errors.stub(:[]).with(errors_matcher(:base)).and_return(@base_error)
90
90
  end
91
91
 
92
92
  it 'should render an unordered list with given class' do
@@ -98,7 +98,7 @@ describe 'Formtastic::FormBuilder#semantic_errors' do
98
98
 
99
99
  describe 'when :base is passed in as an argument' do
100
100
  before do
101
- @errors.stub!(:[]).with(errors_matcher(:base)).and_return(@base_error)
101
+ @errors.stub(:[]).with(errors_matcher(:base)).and_return(@base_error)
102
102
  end
103
103
 
104
104
  it 'should ignore :base and only render base errors once' do
data/spec/i18n_spec.rb CHANGED
@@ -6,12 +6,12 @@ describe 'Formtastic::I18n' do
6
6
  FORMTASTIC_KEYS = [:required, :yes, :no, :create, :update].freeze
7
7
 
8
8
  it "should be defined" do
9
- lambda { Formtastic::I18n }.should_not raise_error(::NameError)
9
+ lambda { Formtastic::I18n }.should_not raise_error
10
10
  end
11
11
 
12
12
  describe "default translations" do
13
13
  it "should be defined" do
14
- lambda { Formtastic::I18n::DEFAULT_VALUES }.should_not raise_error(::NameError)
14
+ lambda { Formtastic::I18n::DEFAULT_VALUES }.should_not raise_error
15
15
  Formtastic::I18n::DEFAULT_VALUES.is_a?(::Hash).should == true
16
16
  end
17
17
 
@@ -98,8 +98,8 @@ describe 'Formtastic::I18n' do
98
98
  }
99
99
  }}
100
100
 
101
- @new_post.stub!(:title)
102
- @new_post.stub!(:column_for_attribute).with(:title).and_return(mock('column', :type => :string, :limit => 255))
101
+ @new_post.stub(:title)
102
+ @new_post.stub(:column_for_attribute).with(:title).and_return(double('column', :type => :string, :limit => 255))
103
103
  end
104
104
 
105
105
  after do
@@ -108,7 +108,7 @@ describe 'Formtastic::I18n' do
108
108
 
109
109
  it "lookup scopes should be defined" do
110
110
  with_config :i18n_lookups_by_default, true do
111
- lambda { Formtastic::I18n::SCOPES }.should_not raise_error(::NameError)
111
+ lambda { Formtastic::I18n::SCOPES }.should_not raise_error
112
112
  end
113
113
  end
114
114
 
@@ -98,7 +98,7 @@ describe 'boolean input' do
98
98
  end
99
99
 
100
100
  it 'should generate a checked input if object.method returns checked value' do
101
- @new_post.stub!(:allow_comments).and_return('yes')
101
+ @new_post.stub(:allow_comments).and_return('yes')
102
102
 
103
103
  concat(semantic_form_for(@new_post) do |builder|
104
104
  concat(builder.input(:allow_comments, :as => :boolean, :checked_value => 'yes', :unchecked_value => 'no'))
@@ -108,7 +108,7 @@ describe 'boolean input' do
108
108
  end
109
109
 
110
110
  it 'should not generate a checked input if object.method returns unchecked value' do
111
- @new_post.stub!(:allow_comments).and_return('no')
111
+ @new_post.stub(:allow_comments).and_return('no')
112
112
 
113
113
  concat(semantic_form_for(@new_post) do |builder|
114
114
  concat(builder.input(:allow_comments, :as => :boolean, :checked_value => 'yes', :unchecked_value => 'no'))
@@ -118,7 +118,7 @@ describe 'boolean input' do
118
118
  end
119
119
 
120
120
  it 'should generate a checked input if object.method returns checked value' do
121
- @new_post.stub!(:allow_comments).and_return('yes')
121
+ @new_post.stub(:allow_comments).and_return('yes')
122
122
 
123
123
  concat(semantic_form_for(@new_post) do |builder|
124
124
  concat(builder.input(:allow_comments, :as => :boolean, :checked_value => 'yes', :unchecked_value => 'no'))
@@ -128,7 +128,7 @@ describe 'boolean input' do
128
128
  end
129
129
 
130
130
  it 'should not generate a checked input if object.method returns unchecked value' do
131
- @new_post.stub!(:allow_comments).and_return('no')
131
+ @new_post.stub(:allow_comments).and_return('no')
132
132
 
133
133
  concat(semantic_form_for(@new_post) do |builder|
134
134
  concat(builder.input(:allow_comments, :as => :boolean, :checked_value => 'yes', :unchecked_value => 'no'))
@@ -153,9 +153,10 @@ describe 'boolean input' do
153
153
 
154
154
  it 'should not pass input_html options down to the label html' do
155
155
  concat(semantic_form_for(@new_post) do |builder|
156
- builder.input(:title, :as => :boolean, :input_html => { :tabindex => 2 })
156
+ builder.input(:title, :as => :boolean, :input_html => { :tabindex => 2, :x => "X" })
157
157
  end)
158
158
  output_buffer.should_not have_tag('label[tabindex]')
159
+ output_buffer.should_not have_tag('label[x]')
159
160
  end
160
161
 
161
162
  context "when required" do
@@ -194,7 +194,7 @@ describe 'check_boxes input' do
194
194
 
195
195
  describe "no disabled items" do
196
196
  before do
197
- @new_post.stub!(:author_ids).and_return(nil)
197
+ @new_post.stub(:author_ids).and_return(nil)
198
198
 
199
199
  concat(semantic_form_for(@new_post) do |builder|
200
200
  concat(builder.input(:authors, :as => :check_boxes, :disabled => nil))
@@ -208,7 +208,7 @@ describe 'check_boxes input' do
208
208
 
209
209
  describe "single disabled item" do
210
210
  before do
211
- @new_post.stub!(:author_ids).and_return(nil)
211
+ @new_post.stub(:author_ids).and_return(nil)
212
212
 
213
213
  concat(semantic_form_for(@new_post) do |builder|
214
214
  concat(builder.input(:authors, :as => :check_boxes, :disabled => @fred.id))
@@ -224,7 +224,7 @@ describe 'check_boxes input' do
224
224
 
225
225
  describe "multiple disabled items" do
226
226
  before do
227
- @new_post.stub!(:author_ids).and_return(nil)
227
+ @new_post.stub(:author_ids).and_return(nil)
228
228
 
229
229
  concat(semantic_form_for(@new_post) do |builder|
230
230
  concat(builder.input(:authors, :as => :check_boxes, :disabled => [@bob.id, @fred.id]))
@@ -247,7 +247,7 @@ describe 'check_boxes input' do
247
247
  before do
248
248
  ::I18n.backend.store_translations :en, :formtastic => { :labels => { :post => { :authors => "Translated!" }}}
249
249
  with_config :i18n_lookups_by_default, true do
250
- @new_post.stub!(:author_ids).and_return(nil)
250
+ @new_post.stub(:author_ids).and_return(nil)
251
251
  concat(semantic_form_for(@new_post) do |builder|
252
252
  concat(builder.input(:authors, :as => :check_boxes))
253
253
  end)
@@ -266,7 +266,7 @@ describe 'check_boxes input' do
266
266
 
267
267
  describe "when :label option is set" do
268
268
  before do
269
- @new_post.stub!(:author_ids).and_return(nil)
269
+ @new_post.stub(:author_ids).and_return(nil)
270
270
  concat(semantic_form_for(@new_post) do |builder|
271
271
  concat(builder.input(:authors, :as => :check_boxes, :label => 'The authors'))
272
272
  end)
@@ -280,7 +280,7 @@ describe 'check_boxes input' do
280
280
  describe "when :label option is false" do
281
281
  before do
282
282
  @output_buffer = ''
283
- @new_post.stub!(:author_ids).and_return(nil)
283
+ @new_post.stub(:author_ids).and_return(nil)
284
284
  concat(semantic_form_for(@new_post) do |builder|
285
285
  concat(builder.input(:authors, :as => :check_boxes, :label => false))
286
286
  end)
@@ -298,7 +298,7 @@ describe 'check_boxes input' do
298
298
 
299
299
  describe "when :required option is true" do
300
300
  before do
301
- @new_post.stub!(:author_ids).and_return(nil)
301
+ @new_post.stub(:author_ids).and_return(nil)
302
302
  concat(semantic_form_for(@new_post) do |builder|
303
303
  concat(builder.input(:authors, :as => :check_boxes, :required => true))
304
304
  end)
@@ -344,9 +344,9 @@ describe 'check_boxes input' do
344
344
  end
345
345
 
346
346
  it 'to set the right input value' do
347
- item = mock('item')
347
+ item = double('item')
348
348
  item.should_not_receive(:id)
349
- item.stub!(:custom_value).and_return('custom_value')
349
+ item.stub(:custom_value).and_return('custom_value')
350
350
  item.should_receive(:custom_value).exactly(3).times
351
351
  @new_post.author.should_receive(:custom_value).exactly(1).times
352
352
  concat(semantic_form_for(@new_post) do |builder|
@@ -373,6 +373,24 @@ describe 'check_boxes input' do
373
373
  output_buffer.should have_tag("form li fieldset ol li label input[@value='biography'][@checked='checked']")
374
374
  end
375
375
  end
376
+
377
+ describe 'when :collection is a set' do
378
+ before do
379
+ @output_buffer = ''
380
+ mock_everything
381
+ @fred.stub(:roles) { Set.new([:reviewer, :admin]) }
382
+
383
+ concat(semantic_form_for(@fred) do |builder|
384
+ concat(builder.input(:roles, :as => :check_boxes, :collection => [['User', :user], ['Reviewer', :reviewer], ['Administrator', :admin]]))
385
+ end)
386
+ end
387
+
388
+ it 'should check the correct checkboxes' do
389
+ output_buffer.should have_tag("form li fieldset ol li label input[@value='user']")
390
+ output_buffer.should have_tag("form li fieldset ol li label input[@value='admin'][@checked='checked']")
391
+ output_buffer.should have_tag("form li fieldset ol li label input[@value='reviewer'][@checked='checked']")
392
+ end
393
+ end
376
394
 
377
395
  describe "when namespace is provided" do
378
396
 
@@ -26,7 +26,7 @@ describe 'country input' do
26
26
 
27
27
  before do
28
28
  concat(semantic_form_for(@new_post) do |builder|
29
- builder.stub!(:country_select).and_return(Formtastic::Util.html_safe("<select><option>...</option></select>"))
29
+ builder.stub(:country_select).and_return(Formtastic::Util.html_safe("<select><option>...</option></select>"))
30
30
  concat(builder.input(:country, :as => :country))
31
31
  end)
32
32
  end
@@ -55,7 +55,7 @@ describe 'country input' do
55
55
  it "should be passed down to the country_select helper when provided" do
56
56
  priority_countries = ["Foo", "Bah"]
57
57
  semantic_form_for(@new_post) do |builder|
58
- builder.stub!(:country_select).and_return(Formtastic::Util.html_safe("<select><option>...</option></select>"))
58
+ builder.stub(:country_select).and_return(Formtastic::Util.html_safe("<select><option>...</option></select>"))
59
59
  builder.should_receive(:country_select).with(:country, priority_countries, {}, {:id => "post_country", :required => false, :autofocus => false}).and_return(Formtastic::Util.html_safe("<select><option>...</option></select>"))
60
60
 
61
61
  concat(builder.input(:country, :as => :country, :priority_countries => priority_countries))
@@ -68,7 +68,7 @@ describe 'country input' do
68
68
  priority_countries.should_not be_nil
69
69
 
70
70
  semantic_form_for(@new_post) do |builder|
71
- builder.stub!(:country_select).and_return(Formtastic::Util.html_safe("<select><option>...</option></select>"))
71
+ builder.stub(:country_select).and_return(Formtastic::Util.html_safe("<select><option>...</option></select>"))
72
72
  builder.should_receive(:country_select).with(:country, priority_countries, {}, {:id => "post_country", :required => false, :autofocus => false}).and_return(Formtastic::Util.html_safe("<select><option>...</option></select>"))
73
73
 
74
74
  concat(builder.input(:country, :as => :country))
@@ -84,7 +84,7 @@ describe 'country input' do
84
84
  mock_everything
85
85
 
86
86
  concat(semantic_form_for(@new_post, :namespace => 'context2') do |builder|
87
- builder.stub!(:country_select).and_return(Formtastic::Util.html_safe("<select><option>...</option></select>"))
87
+ builder.stub(:country_select).and_return(Formtastic::Util.html_safe("<select><option>...</option></select>"))
88
88
  builder.should_receive(:country_select).with(:country, [], {}, {:id => "context2_post_country", :required => false, :autofocus => false}).and_return(Formtastic::Util.html_safe("<select><option>...</option></select>"))
89
89
  concat(builder.input(:country, :priority_countries => []))
90
90
  end)
@@ -101,7 +101,7 @@ describe 'country input' do
101
101
 
102
102
  before do
103
103
  concat(semantic_form_for(@new_post) do |builder|
104
- builder.stub!(:country_select).and_return(Formtastic::Util.html_safe("<select><option>...</option></select>"))
104
+ builder.stub(:country_select).and_return(Formtastic::Util.html_safe("<select><option>...</option></select>"))
105
105
  concat(builder.input(:country))
106
106
  end)
107
107
  end