formtastic 3.1.1 → 4.0.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (130) hide show
  1. checksums.yaml +7 -0
  2. data/.gitattributes +1 -0
  3. data/.gitignore +3 -2
  4. data/.travis.yml +29 -24
  5. data/CHANGELOG.md +49 -0
  6. data/DEPRECATIONS +4 -1
  7. data/Gemfile.lock +104 -0
  8. data/{README.textile → README.md} +178 -166
  9. data/Rakefile +20 -1
  10. data/app/assets/stylesheets/formtastic.css +1 -1
  11. data/bin/appraisal +8 -0
  12. data/formtastic.gemspec +9 -15
  13. data/gemfiles/rails_5.2/Gemfile +5 -0
  14. data/gemfiles/rails_6.0/Gemfile +5 -0
  15. data/gemfiles/rails_edge/Gemfile +13 -0
  16. data/lib/formtastic.rb +9 -11
  17. data/lib/formtastic/actions.rb +6 -3
  18. data/lib/formtastic/deprecation.rb +1 -38
  19. data/lib/formtastic/engine.rb +3 -1
  20. data/lib/formtastic/form_builder.rb +11 -24
  21. data/lib/formtastic/helpers.rb +1 -1
  22. data/lib/formtastic/helpers/action_helper.rb +1 -48
  23. data/lib/formtastic/helpers/enum.rb +13 -0
  24. data/lib/formtastic/helpers/errors_helper.rb +2 -2
  25. data/lib/formtastic/helpers/fieldset_wrapper.rb +13 -9
  26. data/lib/formtastic/helpers/form_helper.rb +1 -1
  27. data/lib/formtastic/helpers/input_helper.rb +23 -77
  28. data/lib/formtastic/helpers/inputs_helper.rb +27 -22
  29. data/lib/formtastic/i18n.rb +1 -1
  30. data/lib/formtastic/inputs.rb +32 -29
  31. data/lib/formtastic/inputs/base/choices.rb +1 -1
  32. data/lib/formtastic/inputs/base/collections.rb +43 -10
  33. data/lib/formtastic/inputs/base/database.rb +7 -2
  34. data/lib/formtastic/inputs/base/errors.rb +4 -4
  35. data/lib/formtastic/inputs/base/hints.rb +1 -1
  36. data/lib/formtastic/inputs/base/html.rb +7 -6
  37. data/lib/formtastic/inputs/base/naming.rb +4 -4
  38. data/lib/formtastic/inputs/base/options.rb +2 -3
  39. data/lib/formtastic/inputs/base/timeish.rb +5 -1
  40. data/lib/formtastic/inputs/base/validations.rb +38 -12
  41. data/lib/formtastic/inputs/check_boxes_input.rb +13 -5
  42. data/lib/formtastic/inputs/color_input.rb +0 -1
  43. data/lib/formtastic/inputs/country_input.rb +3 -1
  44. data/lib/formtastic/inputs/radio_input.rb +20 -0
  45. data/lib/formtastic/inputs/select_input.rb +29 -1
  46. data/lib/formtastic/inputs/time_zone_input.rb +16 -6
  47. data/lib/formtastic/localizer.rb +20 -22
  48. data/lib/formtastic/namespaced_class_finder.rb +1 -1
  49. data/lib/formtastic/version.rb +1 -1
  50. data/lib/generators/formtastic/form/form_generator.rb +1 -1
  51. data/lib/generators/formtastic/input/input_generator.rb +46 -0
  52. data/lib/generators/templates/formtastic.rb +14 -13
  53. data/lib/generators/templates/input.rb +19 -0
  54. data/script/integration-template.rb +71 -0
  55. data/script/integration.sh +19 -0
  56. data/spec/action_class_finder_spec.rb +1 -1
  57. data/spec/actions/button_action_spec.rb +8 -8
  58. data/spec/actions/generic_action_spec.rb +60 -60
  59. data/spec/actions/input_action_spec.rb +7 -7
  60. data/spec/actions/link_action_spec.rb +10 -10
  61. data/spec/builder/custom_builder_spec.rb +36 -20
  62. data/spec/builder/error_proc_spec.rb +4 -4
  63. data/spec/builder/semantic_fields_for_spec.rb +27 -27
  64. data/spec/fast_spec_helper.rb +12 -0
  65. data/spec/generators/formtastic/form/form_generator_spec.rb +25 -25
  66. data/spec/generators/formtastic/input/input_generator_spec.rb +124 -0
  67. data/spec/generators/formtastic/install/install_generator_spec.rb +9 -9
  68. data/spec/helpers/action_helper_spec.rb +328 -10
  69. data/spec/helpers/actions_helper_spec.rb +17 -17
  70. data/spec/helpers/form_helper_spec.rb +37 -37
  71. data/spec/helpers/input_helper_spec.rb +975 -2
  72. data/spec/helpers/inputs_helper_spec.rb +120 -105
  73. data/spec/helpers/reflection_helper_spec.rb +3 -3
  74. data/spec/helpers/semantic_errors_helper_spec.rb +22 -22
  75. data/spec/i18n_spec.rb +26 -26
  76. data/spec/input_class_finder_spec.rb +1 -1
  77. data/spec/inputs/base/collections_spec.rb +76 -0
  78. data/spec/inputs/base/validations_spec.rb +480 -0
  79. data/spec/inputs/boolean_input_spec.rb +55 -55
  80. data/spec/inputs/check_boxes_input_spec.rb +155 -108
  81. data/spec/inputs/color_input_spec.rb +51 -63
  82. data/spec/inputs/country_input_spec.rb +20 -20
  83. data/spec/inputs/custom_input_spec.rb +2 -6
  84. data/spec/inputs/datalist_input_spec.rb +1 -1
  85. data/spec/inputs/date_picker_input_spec.rb +42 -42
  86. data/spec/inputs/date_select_input_spec.rb +51 -37
  87. data/spec/inputs/datetime_picker_input_spec.rb +46 -46
  88. data/spec/inputs/datetime_select_input_spec.rb +53 -37
  89. data/spec/inputs/email_input_spec.rb +5 -5
  90. data/spec/inputs/file_input_spec.rb +6 -6
  91. data/spec/inputs/hidden_input_spec.rb +18 -18
  92. data/spec/inputs/include_blank_spec.rb +8 -8
  93. data/spec/inputs/label_spec.rb +20 -20
  94. data/spec/inputs/number_input_spec.rb +112 -112
  95. data/spec/inputs/password_input_spec.rb +5 -5
  96. data/spec/inputs/phone_input_spec.rb +5 -5
  97. data/spec/inputs/placeholder_spec.rb +5 -5
  98. data/spec/inputs/radio_input_spec.rb +84 -58
  99. data/spec/inputs/range_input_spec.rb +66 -66
  100. data/spec/inputs/readonly_spec.rb +50 -0
  101. data/spec/inputs/search_input_spec.rb +5 -5
  102. data/spec/inputs/select_input_spec.rb +149 -93
  103. data/spec/inputs/string_input_spec.rb +23 -23
  104. data/spec/inputs/text_input_spec.rb +16 -16
  105. data/spec/inputs/time_picker_input_spec.rb +43 -43
  106. data/spec/inputs/time_select_input_spec.rb +67 -54
  107. data/spec/inputs/time_zone_input_spec.rb +54 -28
  108. data/spec/inputs/url_input_spec.rb +5 -5
  109. data/spec/inputs/with_options_spec.rb +7 -7
  110. data/spec/localizer_spec.rb +17 -17
  111. data/spec/namespaced_class_finder_spec.rb +2 -2
  112. data/spec/schema.rb +21 -0
  113. data/spec/spec_helper.rb +165 -253
  114. data/spec/support/custom_macros.rb +72 -75
  115. data/spec/support/shared_examples.rb +0 -1232
  116. data/spec/support/test_environment.rb +23 -9
  117. metadata +67 -174
  118. data/Appraisals +0 -29
  119. data/CHANGELOG +0 -31
  120. data/gemfiles/rails_3.2.gemfile +0 -7
  121. data/gemfiles/rails_4.0.4.gemfile +0 -7
  122. data/gemfiles/rails_4.1.gemfile +0 -7
  123. data/gemfiles/rails_4.2.gemfile +0 -7
  124. data/gemfiles/rails_4.gemfile +0 -7
  125. data/gemfiles/rails_edge.gemfile +0 -10
  126. data/lib/formtastic/util.rb +0 -53
  127. data/spec/helpers/namespaced_action_helper_spec.rb +0 -43
  128. data/spec/helpers/namespaced_input_helper_spec.rb +0 -36
  129. data/spec/support/deferred_garbage_collection.rb +0 -21
  130. data/spec/util_spec.rb +0 -66
@@ -1,7 +1,7 @@
1
1
  # encoding: utf-8
2
2
  require 'spec_helper'
3
3
 
4
- describe 'boolean input' do
4
+ RSpec.describe 'boolean input' do
5
5
 
6
6
  include FormtasticSpecHelper
7
7
 
@@ -23,31 +23,31 @@ describe 'boolean input' do
23
23
  it_should_apply_error_logic_for_input_type(:boolean)
24
24
 
25
25
  it 'should generate a label containing the input' do
26
- output_buffer.should_not have_tag('label.label')
27
- output_buffer.should have_tag('form li label', :count => 1)
28
- output_buffer.should have_tag('form li label[@for="post_allow_comments"]')
29
- output_buffer.should have_tag('form li label', /Allow comments/)
30
- output_buffer.should have_tag('form li label input[@type="checkbox"]', :count => 1)
31
- output_buffer.should have_tag('form li input[@type="hidden"]', :count => 1)
32
- output_buffer.should_not have_tag('form li label input[@type="hidden"]', :count => 1) # invalid HTML5
26
+ expect(output_buffer).not_to have_tag('label.label')
27
+ expect(output_buffer).to have_tag('form li label', :count => 1)
28
+ expect(output_buffer).to have_tag('form li label[@for="post_allow_comments"]')
29
+ expect(output_buffer).to have_tag('form li label', :text => /Allow comments/)
30
+ expect(output_buffer).to have_tag('form li label input[@type="checkbox"]', :count => 1)
31
+ expect(output_buffer).to have_tag('form li input[@type="hidden"]', :count => 1)
32
+ expect(output_buffer).not_to have_tag('form li label input[@type="hidden"]', :count => 1) # invalid HTML5
33
33
  end
34
34
 
35
35
  it 'should not add a "name" attribute to the label' do
36
- output_buffer.should_not have_tag('form li label[@name]')
36
+ expect(output_buffer).not_to have_tag('form li label[@name]')
37
37
  end
38
38
 
39
39
  it 'should generate a checkbox input' do
40
- output_buffer.should have_tag('form li label input')
41
- output_buffer.should have_tag('form li label input#post_allow_comments')
42
- output_buffer.should have_tag('form li label input[@type="checkbox"]')
43
- output_buffer.should have_tag('form li label input[@name="post[allow_comments]"]')
44
- output_buffer.should have_tag('form li label input[@type="checkbox"][@value="1"]')
40
+ expect(output_buffer).to have_tag('form li label input')
41
+ expect(output_buffer).to have_tag('form li label input#post_allow_comments')
42
+ expect(output_buffer).to have_tag('form li label input[@type="checkbox"]')
43
+ expect(output_buffer).to have_tag('form li label input[@name="post[allow_comments]"]')
44
+ expect(output_buffer).to have_tag('form li label input[@type="checkbox"][@value="1"]')
45
45
  end
46
46
 
47
47
  it 'should generate a checked input if object.method returns true' do
48
- output_buffer.should have_tag('form li label input[@checked="checked"]')
49
- output_buffer.should have_tag('form li input[@name="post[allow_comments]"]', :count => 2)
50
- output_buffer.should have_tag('form li input#post_allow_comments', :count => 1)
48
+ expect(output_buffer).to have_tag('form li label input[@checked="checked"]')
49
+ expect(output_buffer).to have_tag('form li input[@name="post[allow_comments]"]', :count => 2)
50
+ expect(output_buffer).to have_tag('form li input#post_allow_comments', :count => 1)
51
51
  end
52
52
  end
53
53
 
@@ -55,7 +55,7 @@ describe 'boolean input' do
55
55
  concat(semantic_form_for(@new_post) do |builder|
56
56
  concat(builder.input(:answer_comments, :as => :boolean, :input_html => {:checked => 'checked'}))
57
57
  end)
58
- output_buffer.should have_tag('form li label input[@checked="checked"]')
58
+ expect(output_buffer).to have_tag('form li label input[@checked="checked"]')
59
59
  end
60
60
 
61
61
  it 'should name the hidden input with the :name html_option' do
@@ -63,8 +63,8 @@ describe 'boolean input' do
63
63
  concat(builder.input(:answer_comments, :as => :boolean, :input_html => { :name => "foo" }))
64
64
  end)
65
65
 
66
- output_buffer.should have_tag('form li input[@type="checkbox"][@name="foo"]', :count => 1)
67
- output_buffer.should have_tag('form li input[@type="hidden"][@name="foo"]', :count => 1)
66
+ expect(output_buffer).to have_tag('form li input[@type="checkbox"][@name="foo"]', :count => 1)
67
+ expect(output_buffer).to have_tag('form li input[@type="hidden"][@name="foo"]', :count => 1)
68
68
  end
69
69
 
70
70
  it 'should name the hidden input with the :name html_option' do
@@ -72,93 +72,93 @@ describe 'boolean input' do
72
72
  concat(builder.input(:answer_comments, :as => :boolean, :input_html => { :name => "foo" }))
73
73
  end)
74
74
 
75
- output_buffer.should have_tag('form li input[@type="checkbox"][@name="foo"]', :count => 1)
76
- output_buffer.should have_tag('form li input[@type="hidden"][@name="foo"]', :count => 1)
75
+ expect(output_buffer).to have_tag('form li input[@type="checkbox"][@name="foo"]', :count => 1)
76
+ expect(output_buffer).to have_tag('form li input[@type="hidden"][@name="foo"]', :count => 1)
77
77
  end
78
78
 
79
79
  it "should generate a disabled input and hidden input if :input_html is passed :disabled => 'disabled' " do
80
80
  concat(semantic_form_for(@new_post) do |builder|
81
81
  concat(builder.input(:allow_comments, :as => :boolean, :input_html => {:disabled => 'disabled'}))
82
82
  end)
83
- output_buffer.should have_tag('form li label input[@disabled="disabled"]', :count => 1)
84
- output_buffer.should have_tag('form li input[@type="hidden"][@disabled="disabled"]', :count => 1)
83
+ expect(output_buffer).to have_tag('form li label input[@disabled="disabled"]', :count => 1)
84
+ expect(output_buffer).to have_tag('form li input[@type="hidden"][@disabled="disabled"]', :count => 1)
85
85
  end
86
86
 
87
87
  it 'should generate an input[id] with matching label[for] when id passed in :input_html' do
88
88
  concat(semantic_form_for(@new_post) do |builder|
89
89
  concat(builder.input(:allow_comments, :as => :boolean, :input_html => {:id => 'custom_id'}))
90
90
  end)
91
- output_buffer.should have_tag('form li label input[@id="custom_id"]')
92
- output_buffer.should have_tag('form li label[@for="custom_id"]')
91
+ expect(output_buffer).to have_tag('form li label input[@id="custom_id"]')
92
+ expect(output_buffer).to have_tag('form li label[@for="custom_id"]')
93
93
  end
94
94
 
95
95
  it 'should allow checked and unchecked values to be sent' do
96
96
  concat(semantic_form_for(@new_post) do |builder|
97
97
  concat(builder.input(:allow_comments, :as => :boolean, :checked_value => 'checked', :unchecked_value => 'unchecked'))
98
98
  end)
99
- output_buffer.should have_tag('form li label input[@type="checkbox"][@value="checked"]:not([@unchecked_value][@checked_value])')
100
- output_buffer.should have_tag('form li input[@type="hidden"][@value="unchecked"]')
101
- output_buffer.should_not have_tag('form li label input[@type="hidden"]') # invalid HTML5
99
+ expect(output_buffer).to have_tag('form li label input[@type="checkbox"][@value="checked"]:not([@unchecked_value][@checked_value])')
100
+ expect(output_buffer).to have_tag('form li input[@type="hidden"][@value="unchecked"]')
101
+ expect(output_buffer).not_to have_tag('form li label input[@type="hidden"]') # invalid HTML5
102
102
  end
103
103
 
104
104
  it 'should generate a checked input if object.method returns checked value' do
105
- @new_post.stub(:allow_comments).and_return('yes')
105
+ allow(@new_post).to receive(:allow_comments).and_return('yes')
106
106
 
107
107
  concat(semantic_form_for(@new_post) do |builder|
108
108
  concat(builder.input(:allow_comments, :as => :boolean, :checked_value => 'yes', :unchecked_value => 'no'))
109
109
  end)
110
110
 
111
- output_buffer.should have_tag('form li label input[@type="checkbox"][@value="yes"][@checked="checked"]')
111
+ expect(output_buffer).to have_tag('form li label input[@type="checkbox"][@value="yes"][@checked="checked"]')
112
112
  end
113
113
 
114
114
  it 'should not generate a checked input if object.method returns unchecked value' do
115
- @new_post.stub(:allow_comments).and_return('no')
115
+ allow(@new_post).to receive(:allow_comments).and_return('no')
116
116
 
117
117
  concat(semantic_form_for(@new_post) do |builder|
118
118
  concat(builder.input(:allow_comments, :as => :boolean, :checked_value => 'yes', :unchecked_value => 'no'))
119
119
  end)
120
120
 
121
- output_buffer.should have_tag('form li label input[@type="checkbox"][@value="yes"]:not([@checked])')
121
+ expect(output_buffer).to have_tag('form li label input[@type="checkbox"][@value="yes"]:not([@checked])')
122
122
  end
123
123
 
124
124
  it 'should generate a checked input if object.method returns checked value' do
125
- @new_post.stub(:allow_comments).and_return('yes')
125
+ allow(@new_post).to receive(:allow_comments).and_return('yes')
126
126
 
127
127
  concat(semantic_form_for(@new_post) do |builder|
128
128
  concat(builder.input(:allow_comments, :as => :boolean, :checked_value => 'yes', :unchecked_value => 'no'))
129
129
  end)
130
130
 
131
- output_buffer.should have_tag('form li label input[@type="checkbox"][@value="yes"][@checked="checked"]')
131
+ expect(output_buffer).to have_tag('form li label input[@type="checkbox"][@value="yes"][@checked="checked"]')
132
132
  end
133
133
 
134
134
  it 'should generate a checked input for boolean database values compared to string checked values' do
135
- @new_post.stub(:foo).and_return(1)
135
+ allow(@new_post).to receive(:foo).and_return(1)
136
136
 
137
137
  concat(semantic_form_for(@new_post) do |builder|
138
138
  concat(builder.input(:foo, :as => :boolean))
139
139
  end)
140
140
 
141
- output_buffer.should have_tag('form li label input[@type="checkbox"][@value="1"][@checked="checked"]')
141
+ expect(output_buffer).to have_tag('form li label input[@type="checkbox"][@value="1"][@checked="checked"]')
142
142
  end
143
143
 
144
144
  it 'should generate a checked input if object.method returns checked value when inverted' do
145
- @new_post.stub(:allow_comments).and_return(0)
145
+ allow(@new_post).to receive(:allow_comments).and_return(0)
146
146
 
147
147
  concat(semantic_form_for(@new_post) do |builder|
148
148
  concat(builder.input(:allow_comments, :as => :boolean, :checked_value => 0, :unchecked_value => 1))
149
149
  end)
150
150
 
151
- output_buffer.should have_tag('form li label input[@type="checkbox"][@value="0"][@checked="checked"]')
151
+ expect(output_buffer).to have_tag('form li label input[@type="checkbox"][@value="0"][@checked="checked"]')
152
152
  end
153
153
 
154
154
  it 'should not generate a checked input if object.method returns unchecked value' do
155
- @new_post.stub(:allow_comments).and_return('no')
155
+ allow(@new_post).to receive(:allow_comments).and_return('no')
156
156
 
157
157
  concat(semantic_form_for(@new_post) do |builder|
158
158
  concat(builder.input(:allow_comments, :as => :boolean, :checked_value => 'yes', :unchecked_value => 'no'))
159
159
  end)
160
160
 
161
- output_buffer.should have_tag('form li label input[@type="checkbox"][@value="yes"]:not([@checked])')
161
+ expect(output_buffer).to have_tag('form li label input[@type="checkbox"][@value="yes"]:not([@checked])')
162
162
  end
163
163
 
164
164
  it 'should generate a label and a checkbox even if no object is given' do
@@ -166,21 +166,21 @@ describe 'boolean input' do
166
166
  concat(builder.input(:allow_comments, :as => :boolean))
167
167
  end)
168
168
 
169
- output_buffer.should have_tag('form li label[@for="project_allow_comments"]')
170
- output_buffer.should have_tag('form li label', /Allow comments/)
171
- output_buffer.should have_tag('form li label input[@type="checkbox"]')
169
+ expect(output_buffer).to have_tag('form li label[@for="project_allow_comments"]')
170
+ expect(output_buffer).to have_tag('form li label', :text => /Allow comments/)
171
+ expect(output_buffer).to have_tag('form li label input[@type="checkbox"]')
172
172
 
173
- output_buffer.should have_tag('form li label input#project_allow_comments')
174
- output_buffer.should have_tag('form li label input[@type="checkbox"]')
175
- output_buffer.should have_tag('form li label input[@name="project[allow_comments]"]')
173
+ expect(output_buffer).to have_tag('form li label input#project_allow_comments')
174
+ expect(output_buffer).to have_tag('form li label input[@type="checkbox"]')
175
+ expect(output_buffer).to have_tag('form li label input[@name="project[allow_comments]"]')
176
176
  end
177
177
 
178
178
  it 'should not pass input_html options down to the label html' do
179
179
  concat(semantic_form_for(@new_post) do |builder|
180
180
  builder.input(:title, :as => :boolean, :input_html => { :tabindex => 2, :x => "X" })
181
181
  end)
182
- output_buffer.should_not have_tag('label[tabindex]')
183
- output_buffer.should_not have_tag('label[x]')
182
+ expect(output_buffer).not_to have_tag('label[tabindex]')
183
+ expect(output_buffer).not_to have_tag('label[x]')
184
184
  end
185
185
 
186
186
  context "when required" do
@@ -190,7 +190,7 @@ describe 'boolean input' do
190
190
  concat(semantic_form_for(@new_post) do |builder|
191
191
  concat(builder.input(:title, :as => :boolean, :required => true))
192
192
  end)
193
- output_buffer.should have_tag("input[@required]")
193
+ expect(output_buffer).to have_tag("input[@required]")
194
194
  end
195
195
  end
196
196
 
@@ -199,7 +199,7 @@ describe 'boolean input' do
199
199
  concat(semantic_form_for(@new_post) do |builder|
200
200
  concat(builder.input(:title, :as => :boolean))
201
201
  end)
202
- output_buffer.should_not have_tag("input[@required]")
202
+ expect(output_buffer).not_to have_tag("input[@required]")
203
203
  end
204
204
  end
205
205
 
@@ -235,19 +235,19 @@ describe 'boolean input' do
235
235
  end
236
236
 
237
237
  it 'should index the id of the wrapper' do
238
- output_buffer.should have_tag("li#post_author_attributes_3_name_input")
238
+ expect(output_buffer).to have_tag("li#post_author_attributes_3_name_input")
239
239
  end
240
240
 
241
241
  it 'should index the id of the input tag' do
242
- output_buffer.should have_tag("input#post_author_attributes_3_name")
242
+ expect(output_buffer).to have_tag("input#post_author_attributes_3_name")
243
243
  end
244
244
 
245
245
  it 'should index the name of the hidden input' do
246
- output_buffer.should have_tag("input[@type='hidden'][@name='post[author_attributes][3][name]']")
246
+ expect(output_buffer).to have_tag("input[@type='hidden'][@name='post[author_attributes][3][name]']")
247
247
  end
248
248
 
249
249
  it 'should index the name of the checkbox input' do
250
- output_buffer.should have_tag("input[@type='checkbox'][@name='post[author_attributes][3][name]']")
250
+ expect(output_buffer).to have_tag("input[@type='checkbox'][@name='post[author_attributes][3][name]']")
251
251
  end
252
252
 
253
253
  end
@@ -1,10 +1,15 @@
1
1
  # encoding: utf-8
2
2
  require 'spec_helper'
3
3
 
4
- describe 'check_boxes input' do
4
+ RSpec.describe 'check_boxes input' do
5
5
 
6
6
  include FormtasticSpecHelper
7
7
 
8
+ before do
9
+ @output_buffer = ''
10
+ mock_everything
11
+ end
12
+
8
13
  describe 'for a has_many association' do
9
14
  before do
10
15
  @output_buffer = ''
@@ -26,75 +31,75 @@ describe 'check_boxes input' do
26
31
  it_should_use_the_collection_when_provided(:check_boxes, 'input[@type="checkbox"]')
27
32
 
28
33
  it 'should generate a legend containing a label with text for the input' do
29
- output_buffer.should have_tag('form li fieldset legend.label label')
30
- output_buffer.should have_tag('form li fieldset legend.label label', /Posts/)
34
+ expect(output_buffer).to have_tag('form li fieldset legend.label label')
35
+ expect(output_buffer).to have_tag('form li fieldset legend.label label', :text => /Posts/)
31
36
  end
32
37
 
33
38
  it 'should not link the label within the legend to any input' do
34
- output_buffer.should_not have_tag('form li fieldset legend label[@for^="author_post_ids_"]')
39
+ expect(output_buffer).not_to have_tag('form li fieldset legend label[@for^="author_post_ids_"]')
35
40
  end
36
41
 
37
42
  it 'should generate an ordered list with an li.choice for each choice' do
38
- output_buffer.should have_tag('form li fieldset ol')
39
- output_buffer.should have_tag('form li fieldset ol li.choice input[@type=checkbox]', :count => ::Post.all.size)
43
+ expect(output_buffer).to have_tag('form li fieldset ol')
44
+ expect(output_buffer).to have_tag('form li fieldset ol li.choice input[@type=checkbox]', :count => ::Post.all.size)
40
45
  end
41
46
 
42
47
  it 'should have one option with a "checked" attribute' do
43
- output_buffer.should have_tag('form li input[@checked]', :count => 1)
48
+ expect(output_buffer).to have_tag('form li input[@checked]', :count => 1)
44
49
  end
45
50
 
46
51
  it 'should not generate hidden inputs with default value blank' do
47
- output_buffer.should_not have_tag("form li fieldset ol li label input[@type='hidden'][@value='']")
52
+ expect(output_buffer).not_to have_tag("form li fieldset ol li label input[@type='hidden'][@value='']")
48
53
  end
49
54
 
50
55
  it 'should not render hidden inputs inside the ol' do
51
- output_buffer.should_not have_tag("form li fieldset ol li input[@type='hidden']")
56
+ expect(output_buffer).not_to have_tag("form li fieldset ol li input[@type='hidden']")
52
57
  end
53
58
 
54
59
  it 'should render one hidden input for each choice outside the ol' do
55
- output_buffer.should have_tag("form li fieldset > input[@type='hidden']", :count => 1)
60
+ expect(output_buffer).to have_tag("form li fieldset > input[@type='hidden']", :count => 1)
56
61
  end
57
62
 
58
63
  describe "each choice" do
59
-
64
+
60
65
  it 'should not give the choice label the .label class' do
61
- output_buffer.should_not have_tag('li.choice label.label')
66
+ expect(output_buffer).not_to have_tag('li.choice label.label')
62
67
  end
63
-
68
+
64
69
  it 'should not be marked as required' do
65
- output_buffer.should_not have_tag('li.choice input[@required]')
70
+ expect(output_buffer).not_to have_tag('li.choice input[@required]')
66
71
  end
67
-
72
+
68
73
  it 'should contain a label for the radio input with a nested input and label text' do
69
74
  ::Post.all.each do |post|
70
- output_buffer.should have_tag('form li fieldset ol li label', /#{post.to_label}/)
71
- output_buffer.should have_tag("form li fieldset ol li label[@for='author_post_ids_#{post.id}']")
75
+ expect(output_buffer).to have_tag('form li fieldset ol li label', :text => /#{post.to_label}/)
76
+ expect(output_buffer).to have_tag("form li fieldset ol li label[@for='author_post_ids_#{post.id}']")
72
77
  end
73
78
  end
74
79
 
75
80
  it 'should use values as li.class when value_as_class is true' do
76
81
  ::Post.all.each do |post|
77
- output_buffer.should have_tag("form li fieldset ol li.post_#{post.id} label")
82
+ expect(output_buffer).to have_tag("form li fieldset ol li.post_#{post.id} label")
78
83
  end
79
84
  end
80
-
85
+
81
86
  it 'should have a checkbox input but no hidden field for each post' do
82
87
  ::Post.all.each do |post|
83
- output_buffer.should have_tag("form li fieldset ol li label input#author_post_ids_#{post.id}")
84
- output_buffer.should have_tag("form li fieldset ol li label input[@name='author[post_ids][]']", :count => 1)
88
+ expect(output_buffer).to have_tag("form li fieldset ol li label input#author_post_ids_#{post.id}")
89
+ expect(output_buffer).to have_tag("form li fieldset ol li label input[@name='author[post_ids][]']", :count => 1)
85
90
  end
86
91
  end
87
92
 
88
93
  it 'should have a hidden field with an empty array value for the collection to allow clearing of all checkboxes' do
89
- output_buffer.should have_tag("form li fieldset > input[@type=hidden][@name='author[post_ids][]'][@value='']", :count => 1)
94
+ expect(output_buffer).to have_tag("form li fieldset > input[@type=hidden][@name='author[post_ids][]'][@value='']", :count => 1)
90
95
  end
91
96
 
92
97
  it 'the hidden field with an empty array value should be followed by the ol' do
93
- output_buffer.should have_tag("form li fieldset > input[@type=hidden][@name='author[post_ids][]'][@value=''] + ol", :count => 1)
98
+ expect(output_buffer).to have_tag("form li fieldset > input[@type=hidden][@name='author[post_ids][]'][@value=''] + ol", :count => 1)
94
99
  end
95
100
 
96
101
  it 'should not have a hidden field with an empty string value for the collection' do
97
- output_buffer.should_not have_tag("form li fieldset > input[@type=hidden][@name='author[post_ids]'][@value='']", :count => 1)
102
+ expect(output_buffer).not_to have_tag("form li fieldset > input[@type=hidden][@name='author[post_ids]'][@value='']", :count => 1)
98
103
  end
99
104
 
100
105
  it 'should have a checkbox and a hidden field for each post with :hidden_field => true' do
@@ -105,21 +110,21 @@ describe 'check_boxes input' do
105
110
  end)
106
111
 
107
112
  ::Post.all.each do |post|
108
- output_buffer.should have_tag("form li fieldset ol li label input#author_post_ids_#{post.id}")
109
- output_buffer.should have_tag("form li fieldset ol li label input[@name='author[post_ids][]']", :count => 2)
110
- output_buffer.should have_tag('form li fieldset ol li label', /#{post.to_label}/)
113
+ expect(output_buffer).to have_tag("form li fieldset ol li label input#author_post_ids_#{post.id}")
114
+ expect(output_buffer).to have_tag("form li fieldset ol li label input[@name='author[post_ids][]']", :count => 2)
115
+ expect(output_buffer).to have_tag('form li fieldset ol li label', :text => /#{post.to_label}/)
111
116
  end
112
117
 
113
118
  end
114
119
 
115
120
  it "should mark input as checked if it's the the existing choice" do
116
- ::Post.all.include?(@fred.posts.first).should be_truthy
117
- output_buffer.should have_tag("form li fieldset ol li label input[@checked='checked']")
121
+ expect(::Post.all.include?(@fred.posts.first)).to be_truthy
122
+ expect(output_buffer).to have_tag("form li fieldset ol li label input[@checked='checked']")
118
123
  end
119
124
  end
120
125
 
121
126
  describe 'and no object is given' do
122
- before(:each) do
127
+ before(:example) do
123
128
  output_buffer.replace ''
124
129
  concat(semantic_form_for(:project, :url => 'http://test.host') do |builder|
125
130
  concat(builder.input(:author_id, :as => :check_boxes, :collection => ::Author.all))
@@ -127,26 +132,26 @@ describe 'check_boxes input' do
127
132
  end
128
133
 
129
134
  it 'should generate a fieldset with legend' do
130
- output_buffer.should have_tag('form li fieldset legend', /Author/)
135
+ expect(output_buffer).to have_tag('form li fieldset legend', :text => /Author/)
131
136
  end
132
137
 
133
138
  it 'shold generate an li tag for each item in the collection' do
134
- output_buffer.should have_tag('form li fieldset ol li input[@type=checkbox]', :count => ::Author.all.size)
139
+ expect(output_buffer).to have_tag('form li fieldset ol li input[@type=checkbox]', :count => ::Author.all.size)
135
140
  end
136
141
 
137
142
  it 'should generate labels for each item' do
138
143
  ::Author.all.each do |author|
139
- output_buffer.should have_tag('form li fieldset ol li label', /#{author.to_label}/)
140
- output_buffer.should have_tag("form li fieldset ol li label[@for='project_author_id_#{author.id}']")
144
+ expect(output_buffer).to have_tag('form li fieldset ol li label', :text => /#{author.to_label}/)
145
+ expect(output_buffer).to have_tag("form li fieldset ol li label[@for='project_author_id_#{author.id}']")
141
146
  end
142
147
  end
143
148
 
144
149
  it 'should generate inputs for each item' do
145
150
  ::Author.all.each do |author|
146
- output_buffer.should have_tag("form li fieldset ol li label input#project_author_id_#{author.id}")
147
- output_buffer.should have_tag("form li fieldset ol li label input[@type='checkbox']")
148
- output_buffer.should have_tag("form li fieldset ol li label input[@value='#{author.id}']")
149
- output_buffer.should have_tag("form li fieldset ol li label input[@name='project[author_id][]']")
151
+ expect(output_buffer).to have_tag("form li fieldset ol li label input#project_author_id_#{author.id}")
152
+ expect(output_buffer).to have_tag("form li fieldset ol li label input[@type='checkbox']")
153
+ expect(output_buffer).to have_tag("form li fieldset ol li label input[@value='#{author.id}']")
154
+ expect(output_buffer).to have_tag("form li fieldset ol li label input[@name='project[author_id][]']")
150
155
  end
151
156
  end
152
157
 
@@ -155,8 +160,9 @@ describe 'check_boxes input' do
155
160
  concat(builder.input(:author_id, :as => :check_boxes, :collection => [["<b>Item 1</b>", 1], ["<b>Item 2</b>", 2]]))
156
161
  end)
157
162
 
158
- output_buffer.should have_tag('form li fieldset ol li label') do |label|
159
- label.body.should match /&lt;b&gt;Item [12]&lt;\/b&gt;$/
163
+ expect(output_buffer).to have_tag('form li fieldset ol li label', text: %r{<b>Item [12]</b>}, count: 2) do |label|
164
+ expect(label).to have_text('<b>Item 1</b>', count: 1)
165
+ expect(label).to have_text('<b>Item 2</b>', count: 1)
160
166
  end
161
167
  end
162
168
  end
@@ -173,18 +179,18 @@ describe 'check_boxes input' do
173
179
 
174
180
  it 'should have a checkbox input for each post' do
175
181
  ::Post.all.each do |post|
176
- output_buffer.should have_tag("form li fieldset ol li label input#author_post_ids_#{post.id}")
177
- output_buffer.should have_tag("form li fieldset ol li label input[@name='author[post_ids][]']", :count => ::Post.all.length)
182
+ expect(output_buffer).to have_tag("form li fieldset ol li label input#author_post_ids_#{post.id}")
183
+ expect(output_buffer).to have_tag("form li fieldset ol li label input[@name='author[post_ids][]']", :count => ::Post.all.length)
178
184
  end
179
185
  end
180
186
 
181
187
  it "should mark input as checked if it's the the existing choice" do
182
- ::Post.all.include?(@fred.posts.first).should be_truthy
183
- output_buffer.should have_tag("form li fieldset ol li label input[@checked='checked']")
188
+ expect(::Post.all.include?(@fred.posts.first)).to be_truthy
189
+ expect(output_buffer).to have_tag("form li fieldset ol li label input[@checked='checked']")
184
190
  end
185
191
 
186
192
  it 'should not generate empty hidden inputs' do
187
- output_buffer.should_not have_tag("form li fieldset ol li label input[@type='hidden'][@value='']", :count => ::Post.all.length)
193
+ expect(output_buffer).not_to have_tag("form li fieldset ol li label input[@type='hidden'][@value='']", :count => ::Post.all.length)
188
194
  end
189
195
  end
190
196
 
@@ -195,7 +201,7 @@ describe 'check_boxes input' do
195
201
 
196
202
  describe "no disabled items" do
197
203
  before do
198
- @new_post.stub(:author_ids).and_return(nil)
204
+ allow(@new_post).to receive(:author_ids).and_return(nil)
199
205
 
200
206
  concat(semantic_form_for(@new_post) do |builder|
201
207
  concat(builder.input(:authors, :as => :check_boxes, :disabled => nil))
@@ -203,13 +209,13 @@ describe 'check_boxes input' do
203
209
  end
204
210
 
205
211
  it 'should not have any disabled item(s)' do
206
- output_buffer.should_not have_tag("form li fieldset ol li label input[@disabled='disabled']")
212
+ expect(output_buffer).not_to have_tag("form li fieldset ol li label input[@disabled='disabled']")
207
213
  end
208
214
  end
209
215
 
210
216
  describe "single disabled item" do
211
217
  before do
212
- @new_post.stub(:author_ids).and_return(nil)
218
+ allow(@new_post).to receive(:author_ids).and_return(nil)
213
219
 
214
220
  concat(semantic_form_for(@new_post) do |builder|
215
221
  concat(builder.input(:authors, :as => :check_boxes, :disabled => @fred.id))
@@ -217,15 +223,15 @@ describe 'check_boxes input' do
217
223
  end
218
224
 
219
225
  it "should have one item disabled; the specified one" do
220
- output_buffer.should have_tag("form li fieldset ol li label input[@disabled='disabled']", :count => 1)
221
- output_buffer.should have_tag("form li fieldset ol li label[@for='post_author_ids_#{@fred.id}']", /fred/i)
222
- output_buffer.should have_tag("form li fieldset ol li label input[@disabled='disabled'][@value='#{@fred.id}']")
226
+ expect(output_buffer).to have_tag("form li fieldset ol li label input[@disabled='disabled']", :count => 1)
227
+ expect(output_buffer).to have_tag("form li fieldset ol li label[@for='post_author_ids_#{@fred.id}']", :text => /fred/i)
228
+ expect(output_buffer).to have_tag("form li fieldset ol li label input[@disabled='disabled'][@value='#{@fred.id}']")
223
229
  end
224
230
  end
225
231
 
226
232
  describe "multiple disabled items" do
227
233
  before do
228
- @new_post.stub(:author_ids).and_return(nil)
234
+ allow(@new_post).to receive(:author_ids).and_return(nil)
229
235
 
230
236
  concat(semantic_form_for(@new_post) do |builder|
231
237
  concat(builder.input(:authors, :as => :check_boxes, :disabled => [@bob.id, @fred.id]))
@@ -233,11 +239,11 @@ describe 'check_boxes input' do
233
239
  end
234
240
 
235
241
  it "should have multiple items disabled; the specified ones" do
236
- output_buffer.should have_tag("form li fieldset ol li label input[@disabled='disabled']", :count => 2)
237
- output_buffer.should have_tag("form li fieldset ol li label[@for='post_author_ids_#{@bob.id}']", /bob/i)
238
- output_buffer.should have_tag("form li fieldset ol li label input[@disabled='disabled'][@value='#{@bob.id}']")
239
- output_buffer.should have_tag("form li fieldset ol li label[@for='post_author_ids_#{@fred.id}']", /fred/i)
240
- output_buffer.should have_tag("form li fieldset ol li label input[@disabled='disabled'][@value='#{@fred.id}']")
242
+ expect(output_buffer).to have_tag("form li fieldset ol li label input[@disabled='disabled']", :count => 2)
243
+ expect(output_buffer).to have_tag("form li fieldset ol li label[@for='post_author_ids_#{@bob.id}']", :text => /bob/i)
244
+ expect(output_buffer).to have_tag("form li fieldset ol li label input[@disabled='disabled'][@value='#{@bob.id}']")
245
+ expect(output_buffer).to have_tag("form li fieldset ol li label[@for='post_author_ids_#{@fred.id}']", :text => /fred/i)
246
+ expect(output_buffer).to have_tag("form li fieldset ol li label input[@disabled='disabled'][@value='#{@fred.id}']")
241
247
  end
242
248
  end
243
249
 
@@ -248,7 +254,7 @@ describe 'check_boxes input' do
248
254
  before do
249
255
  ::I18n.backend.store_translations :en, :formtastic => { :labels => { :post => { :authors => "Translated!" }}}
250
256
  with_config :i18n_lookups_by_default, true do
251
- @new_post.stub(:author_ids).and_return(nil)
257
+ allow(@new_post).to receive(:author_ids).and_return(nil)
252
258
  concat(semantic_form_for(@new_post) do |builder|
253
259
  concat(builder.input(:authors, :as => :check_boxes))
254
260
  end)
@@ -260,56 +266,72 @@ describe 'check_boxes input' do
260
266
  end
261
267
 
262
268
  it "should do foo" do
263
- output_buffer.should have_tag("legend.label label", /Translated/)
269
+ expect(output_buffer).to have_tag("legend.label label", :text => /Translated/)
264
270
  end
265
271
 
266
272
  end
267
273
 
268
274
  describe "when :label option is set" do
269
275
  before do
270
- @new_post.stub(:author_ids).and_return(nil)
276
+ allow(@new_post).to receive(:author_ids).and_return(nil)
271
277
  concat(semantic_form_for(@new_post) do |builder|
272
278
  concat(builder.input(:authors, :as => :check_boxes, :label => 'The authors'))
273
279
  end)
274
280
  end
275
281
 
276
282
  it "should output the correct label title" do
277
- output_buffer.should have_tag("legend.label label", /The authors/)
283
+ expect(output_buffer).to have_tag("legend.label label", :text => /The authors/)
278
284
  end
279
285
  end
280
286
 
281
287
  describe "when :label option is false" do
282
288
  before do
283
289
  @output_buffer = ''
284
- @new_post.stub(:author_ids).and_return(nil)
290
+ allow(@new_post).to receive(:author_ids).and_return(nil)
285
291
  concat(semantic_form_for(@new_post) do |builder|
286
292
  concat(builder.input(:authors, :as => :check_boxes, :label => false))
287
293
  end)
288
294
  end
289
295
 
290
296
  it "should not output the legend" do
291
- output_buffer.should_not have_tag("legend.label")
297
+ expect(output_buffer).not_to have_tag("legend.label")
292
298
  end
293
-
299
+
294
300
  it "should not cause escaped HTML" do
295
- output_buffer.should_not include("&gt;")
301
+ expect(output_buffer).not_to include("&gt;")
296
302
  end
297
-
303
+
298
304
  end
299
305
 
300
306
  describe "when :required option is true" do
301
307
  before do
302
- @new_post.stub(:author_ids).and_return(nil)
308
+ allow(@new_post).to receive(:author_ids).and_return(nil)
303
309
  concat(semantic_form_for(@new_post) do |builder|
304
310
  concat(builder.input(:authors, :as => :check_boxes, :required => true))
305
311
  end)
306
312
  end
307
313
 
308
314
  it "should output the correct label title" do
309
- output_buffer.should have_tag("legend.label label abbr")
315
+ expect(output_buffer).to have_tag("legend.label label abbr")
310
316
  end
311
317
  end
318
+ end
319
+
320
+ describe 'for a enum column' do
321
+ before do
322
+ allow(@new_post).to receive(:status) { 'inactive' }
323
+ statuses = ActiveSupport::HashWithIndifferentAccess.new("active"=>0, "inactive"=>1)
324
+ allow(@new_post.class).to receive(:statuses) { statuses }
325
+ allow(@new_post).to receive(:defined_enums) { { "status" => statuses } }
326
+ end
312
327
 
328
+ it 'should have a select inside the wrapper' do
329
+ expect {
330
+ concat(semantic_form_for(@new_post) do |builder|
331
+ concat(builder.input(:status, :as => :check_boxes))
332
+ end)
333
+ }.to raise_error(Formtastic::UnsupportedEnumCollection)
334
+ end
313
335
  end
314
336
 
315
337
  describe 'for a has_and_belongs_to_many association' do
@@ -325,14 +347,39 @@ describe 'check_boxes input' do
325
347
 
326
348
  it 'should render checkboxes' do
327
349
  # I'm aware these two lines test the same thing
328
- output_buffer.should have_tag('input[type="checkbox"]', :count => 2)
329
- output_buffer.should have_tag('input[type="checkbox"]', :count => ::Author.all.size)
350
+ expect(output_buffer).to have_tag('input[type="checkbox"]', :count => 2)
351
+ expect(output_buffer).to have_tag('input[type="checkbox"]', :count => ::Author.all.size)
352
+ end
353
+
354
+ it 'should only select checkboxes that are present in the association' do
355
+ # I'm aware these two lines test the same thing
356
+ expect(output_buffer).to have_tag('input[checked="checked"]', :count => 1)
357
+ expect(output_buffer).to have_tag('input[checked="checked"]', :count => @freds_post.authors.size)
358
+ end
359
+
360
+ end
361
+
362
+ describe ':collection for a has_and_belongs_to_many association' do
363
+
364
+ before do
365
+ @output_buffer = ''
366
+ mock_everything
367
+
368
+ concat(semantic_form_for(@freds_post) do |builder|
369
+ concat(builder.input(:authors, as: :check_boxes, collection: Author.all))
370
+ end)
371
+ end
372
+
373
+ it 'should render checkboxes' do
374
+ # I'm aware these two lines test the same thing
375
+ expect(output_buffer).to have_tag('input[type="checkbox"]', :count => 2)
376
+ expect(output_buffer).to have_tag('input[type="checkbox"]', :count => ::Author.all.size)
330
377
  end
331
378
 
332
379
  it 'should only select checkboxes that are present in the association' do
333
380
  # I'm aware these two lines test the same thing
334
- output_buffer.should have_tag('input[checked="checked"]', :count => 1)
335
- output_buffer.should have_tag('input[checked="checked"]', :count => @freds_post.authors.size)
381
+ expect(output_buffer).to have_tag('input[checked="checked"]', :count => 1)
382
+ expect(output_buffer).to have_tag('input[checked="checked"]', :count => @freds_post.authors.size)
336
383
  end
337
384
 
338
385
  end
@@ -346,53 +393,53 @@ describe 'check_boxes input' do
346
393
 
347
394
  it 'to set the right input value' do
348
395
  item = double('item')
349
- item.should_not_receive(:id)
350
- item.stub(:custom_value).and_return('custom_value')
351
- item.should_receive(:custom_value).exactly(3).times
352
- @new_post.author.should_receive(:custom_value).exactly(1).times
353
-
396
+ expect(item).not_to receive(:id)
397
+ allow(item).to receive(:custom_value).and_return('custom_value')
398
+ expect(item).to receive(:custom_value).exactly(3).times
399
+ expect(@new_post.author).to receive(:custom_value).exactly(1).times
400
+
354
401
  with_deprecation_silenced do
355
402
  concat(semantic_form_for(@new_post) do |builder|
356
403
  concat(builder.input(:author, :as => :check_boxes, :member_value => :custom_value, :collection => [item, item, item]))
357
404
  end)
358
405
  end
359
- output_buffer.should have_tag('input[@type=checkbox][@value="custom_value"]', :count => 3)
406
+ expect(output_buffer).to have_tag('input[@type=checkbox][@value="custom_value"]', :count => 3)
360
407
  end
361
408
  end
362
409
  end
363
-
410
+
364
411
  describe 'when :collection is provided as an array of arrays' do
365
412
  before do
366
413
  @output_buffer = ''
367
414
  mock_everything
368
- @fred.stub(:genres) { ['fiction', 'biography'] }
369
-
415
+ allow(@fred).to receive(:genres) { ['fiction', 'biography'] }
416
+
370
417
  concat(semantic_form_for(@fred) do |builder|
371
418
  concat(builder.input(:genres, :as => :check_boxes, :collection => [['Fiction', 'fiction'], ['Non-fiction', 'non_fiction'], ['Biography', 'biography']]))
372
419
  end)
373
420
  end
374
-
421
+
375
422
  it 'should check the correct checkboxes' do
376
- output_buffer.should have_tag("form li fieldset ol li label input[@value='fiction'][@checked='checked']")
377
- output_buffer.should have_tag("form li fieldset ol li label input[@value='biography'][@checked='checked']")
423
+ expect(output_buffer).to have_tag("form li fieldset ol li label input[@value='fiction'][@checked='checked']")
424
+ expect(output_buffer).to have_tag("form li fieldset ol li label input[@value='biography'][@checked='checked']")
378
425
  end
379
426
  end
380
-
427
+
381
428
  describe 'when :collection is a set' do
382
429
  before do
383
430
  @output_buffer = ''
384
431
  mock_everything
385
- @fred.stub(:roles) { Set.new([:reviewer, :admin]) }
386
-
432
+ allow(@fred).to receive(:roles) { Set.new([:reviewer, :admin]) }
433
+
387
434
  concat(semantic_form_for(@fred) do |builder|
388
435
  concat(builder.input(:roles, :as => :check_boxes, :collection => [['User', :user], ['Reviewer', :reviewer], ['Administrator', :admin]]))
389
436
  end)
390
437
  end
391
-
438
+
392
439
  it 'should check the correct checkboxes' do
393
- output_buffer.should have_tag("form li fieldset ol li label input[@value='user']")
394
- output_buffer.should have_tag("form li fieldset ol li label input[@value='admin'][@checked='checked']")
395
- output_buffer.should have_tag("form li fieldset ol li label input[@value='reviewer'][@checked='checked']")
440
+ expect(output_buffer).to have_tag("form li fieldset ol li label input[@value='user']")
441
+ expect(output_buffer).to have_tag("form li fieldset ol li label input[@value='admin'][@checked='checked']")
442
+ expect(output_buffer).to have_tag("form li fieldset ol li label input[@value='reviewer'][@checked='checked']")
396
443
  end
397
444
  end
398
445
 
@@ -406,15 +453,15 @@ describe 'check_boxes input' do
406
453
  concat(builder.input(:posts, :as => :check_boxes))
407
454
  end)
408
455
  end
409
-
456
+
410
457
  it "should have a label for #context2_author_post_ids_19" do
411
- output_buffer.should have_tag("form li label[@for='context2_author_post_ids_19']")
458
+ expect(output_buffer).to have_tag("form li label[@for='context2_author_post_ids_19']")
412
459
  end
413
460
 
414
461
  it_should_have_input_with_id('context2_author_post_ids_19')
415
462
  it_should_have_input_wrapper_with_id("context2_author_posts_input")
416
463
  end
417
-
464
+
418
465
  describe "when index is provided" do
419
466
 
420
467
  before do
@@ -427,21 +474,21 @@ describe 'check_boxes input' do
427
474
  end)
428
475
  end)
429
476
  end
430
-
477
+
431
478
  it 'should index the id of the wrapper' do
432
- output_buffer.should have_tag("li#author_post_3_authors_input")
479
+ expect(output_buffer).to have_tag("li#author_post_3_authors_input")
433
480
  end
434
-
481
+
435
482
  it 'should index the id of the input tag' do
436
- output_buffer.should have_tag("input#author_post_3_author_ids_42")
483
+ expect(output_buffer).to have_tag("input#author_post_3_author_ids_42")
437
484
  end
438
485
 
439
486
  it 'should index the name of the checkbox input' do
440
- output_buffer.should have_tag("input[@type='checkbox'][@name='author[post][3][author_ids][]']")
487
+ expect(output_buffer).to have_tag("input[@type='checkbox'][@name='author[post][3][author_ids][]']")
441
488
  end
442
-
489
+
443
490
  end
444
-
491
+
445
492
 
446
493
  describe "when collection is an array" do
447
494
  before do
@@ -456,18 +503,18 @@ describe 'check_boxes input' do
456
503
 
457
504
  it "should use array items for labels and values" do
458
505
  @_collection.each do |post|
459
- output_buffer.should have_tag('form li fieldset ol li label', /#{post.first}/)
460
- output_buffer.should have_tag("form li fieldset ol li label[@for='author_post_ids_#{post.last}']")
506
+ expect(output_buffer).to have_tag('form li fieldset ol li label', :text => /#{post.first}/)
507
+ expect(output_buffer).to have_tag("form li fieldset ol li label[@for='author_post_ids_#{post.last}']")
461
508
  end
462
509
  end
463
510
 
464
511
  it "should not check any items" do
465
- output_buffer.should have_tag('form li input[@checked]', :count => 0)
512
+ expect(output_buffer).to have_tag('form li input[@checked]', :count => 0)
466
513
  end
467
514
 
468
515
  describe "and the attribute has values" do
469
516
  before do
470
- @fred.stub(:posts) { [1] }
517
+ allow(@fred).to receive(:posts) { [1] }
471
518
 
472
519
  concat(semantic_form_for(@fred) do |builder|
473
520
  concat(builder.input(:posts, :as => :check_boxes, :collection => @_collection))
@@ -475,7 +522,7 @@ describe 'check_boxes input' do
475
522
  end
476
523
 
477
524
  it "should check the appropriate items" do
478
- output_buffer.should have_tag("form li input[@value='1'][@checked]")
525
+ expect(output_buffer).to have_tag("form li input[@value='1'][@checked]")
479
526
  end
480
527
  end
481
528
 
@@ -490,11 +537,11 @@ describe 'check_boxes input' do
490
537
 
491
538
  it "should have injected the html attributes" do
492
539
  @_collection.each do |v|
493
- output_buffer.should have_tag("form li input[@value='#{v[1]}'][@#{v[2].keys[0]}='#{v[2].values[0]}']")
540
+ expect(output_buffer).to have_tag("form li input[@value='#{v[1]}'][@#{v[2].keys[0]}='#{v[2].values[0]}']")
494
541
  end
495
542
  end
496
543
  end
497
544
  end
498
-
545
+
499
546
  end
500
547