formtastic-rails3 0.9.7 → 0.9.10.0
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 +23 -7
- data/Rakefile +27 -4
- data/generators/formtastic/templates/formtastic.css +9 -7
- data/generators/formtastic/templates/formtastic.rb +1 -1
- data/generators/formtastic/templates/formtastic_changes.css +4 -0
- data/lib/formtastic.rb +190 -142
- data/lib/formtastic/i18n.rb +8 -5
- data/lib/formtastic/railtie.rb +12 -0
- data/lib/formtastic/util.rb +35 -0
- data/lib/generators/formtastic/form/form_generator.rb +4 -3
- data/lib/generators/formtastic/install/install_generator.rb +2 -1
- data/rails/init.rb +5 -0
- data/spec/buttons_spec.rb +25 -8
- data/spec/commit_button_spec.rb +88 -64
- data/spec/custom_builder_spec.rb +1 -1
- data/spec/custom_macros.rb +67 -26
- data/spec/error_proc_spec.rb +1 -1
- data/spec/errors_spec.rb +21 -1
- data/spec/form_helper_spec.rb +47 -15
- data/spec/i18n_spec.rb +40 -19
- data/spec/include_blank_spec.rb +9 -5
- data/spec/input_spec.rb +224 -76
- data/spec/inputs/boolean_input_spec.rb +22 -11
- data/spec/inputs/check_boxes_input_spec.rb +103 -11
- data/spec/inputs/country_input_spec.rb +46 -8
- data/spec/inputs/date_input_spec.rb +80 -55
- data/spec/inputs/datetime_input_spec.rb +134 -83
- data/spec/inputs/file_input_spec.rb +4 -3
- data/spec/inputs/hidden_input_spec.rb +17 -3
- data/spec/inputs/numeric_input_spec.rb +3 -3
- data/spec/inputs/password_input_spec.rb +3 -3
- data/spec/inputs/radio_input_spec.rb +28 -11
- data/spec/inputs/select_input_spec.rb +122 -46
- data/spec/inputs/string_input_spec.rb +3 -3
- data/spec/inputs/text_input_spec.rb +4 -3
- data/spec/inputs/time_input_spec.rb +109 -53
- data/spec/inputs/time_zone_input_spec.rb +15 -7
- data/spec/inputs_spec.rb +85 -39
- data/spec/label_spec.rb +1 -1
- data/spec/layout_helper_spec.rb +5 -16
- data/spec/semantic_errors_spec.rb +7 -7
- data/spec/semantic_fields_for_spec.rb +5 -4
- data/spec/spec_helper.rb +102 -36
- metadata +11 -14
- data/lib/generators/formtastic/form/templates/_form.html.erb +0 -5
- data/lib/generators/formtastic/form/templates/_form.html.haml +0 -4
- data/lib/generators/formtastic/install/templates/formtastic.css +0 -144
- data/lib/generators/formtastic/install/templates/formtastic.rb +0 -58
- data/lib/generators/formtastic/install/templates/formtastic_changes.css +0 -10
- data/spec/inputs/currency_input_spec.rb +0 -80
@@ -6,19 +6,20 @@ describe 'boolean input' do
|
|
6
6
|
include FormtasticSpecHelper
|
7
7
|
|
8
8
|
before do
|
9
|
-
@output_buffer =
|
9
|
+
@output_buffer = ''
|
10
10
|
mock_everything
|
11
11
|
|
12
|
-
semantic_form_for(@new_post) do |builder|
|
12
|
+
@form = semantic_form_for(@new_post) do |builder|
|
13
13
|
concat(builder.input(:allow_comments, :as => :boolean))
|
14
14
|
end
|
15
15
|
end
|
16
|
-
|
16
|
+
|
17
17
|
it_should_have_input_wrapper_with_class("boolean")
|
18
18
|
it_should_have_input_wrapper_with_id("post_allow_comments_input")
|
19
19
|
it_should_apply_error_logic_for_input_type(:boolean)
|
20
20
|
|
21
21
|
it 'should generate a label containing the input' do
|
22
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
22
23
|
output_buffer.should have_tag('form li label', :count => 1)
|
23
24
|
output_buffer.should have_tag('form li label[@for="post_allow_comments"]')
|
24
25
|
output_buffer.should have_tag('form li label', /Allow comments/)
|
@@ -26,6 +27,7 @@ describe 'boolean input' do
|
|
26
27
|
end
|
27
28
|
|
28
29
|
it 'should generate a checkbox input' do
|
30
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
29
31
|
output_buffer.should have_tag('form li label input')
|
30
32
|
output_buffer.should have_tag('form li label input#post_allow_comments')
|
31
33
|
output_buffer.should have_tag('form li label input[@type="checkbox"]')
|
@@ -34,19 +36,22 @@ describe 'boolean input' do
|
|
34
36
|
end
|
35
37
|
|
36
38
|
it 'should allow checked and unchecked values to be sent' do
|
37
|
-
semantic_form_for(@new_post) do |builder|
|
39
|
+
form = semantic_form_for(@new_post) do |builder|
|
38
40
|
concat(builder.input(:allow_comments, :as => :boolean, :checked_value => 'checked', :unchecked_value => 'unchecked'))
|
39
41
|
end
|
40
42
|
|
43
|
+
output_buffer.concat(form) if Formtastic::Util.rails3?
|
41
44
|
output_buffer.should have_tag('form li label input[@type="checkbox"][@value="checked"]')
|
42
45
|
output_buffer.should have_tag('form li label input[@type="hidden"][@value="unchecked"]')
|
43
46
|
end
|
44
47
|
|
45
48
|
it 'should generate a label and a checkbox even if no object is given' do
|
46
|
-
semantic_form_for(:project, :url => 'http://test.host') do |builder|
|
49
|
+
form = semantic_form_for(:project, :url => 'http://test.host') do |builder|
|
47
50
|
concat(builder.input(:allow_comments, :as => :boolean))
|
48
51
|
end
|
49
52
|
|
53
|
+
output_buffer.concat(form) if Formtastic::Util.rails3?
|
54
|
+
|
50
55
|
output_buffer.should have_tag('form li label[@for="project_allow_comments"]')
|
51
56
|
output_buffer.should have_tag('form li label', /Allow comments/)
|
52
57
|
output_buffer.should have_tag('form li label input[@type="checkbox"]')
|
@@ -58,19 +63,22 @@ describe 'boolean input' do
|
|
58
63
|
|
59
64
|
describe 'when :selected is set' do
|
60
65
|
before do
|
61
|
-
@output_buffer =
|
66
|
+
@output_buffer = ''
|
62
67
|
end
|
63
68
|
|
64
69
|
describe "not selected" do
|
65
70
|
before do
|
66
71
|
@new_post.stub!(:allow_comments).and_return(true)
|
67
72
|
|
68
|
-
|
69
|
-
|
73
|
+
with_deprecation_silenced do
|
74
|
+
@form = semantic_form_for(@new_post) do |builder|
|
75
|
+
concat(builder.input(:allow_comments, :as => :boolean, :selected => false))
|
76
|
+
end
|
70
77
|
end
|
71
78
|
end
|
72
79
|
|
73
80
|
it 'should not be selected' do
|
81
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
74
82
|
output_buffer.should_not have_tag("form li label input[@type='checkbox'][@checked='checked']")
|
75
83
|
end
|
76
84
|
end
|
@@ -78,13 +86,16 @@ describe 'boolean input' do
|
|
78
86
|
describe "selected" do
|
79
87
|
before do
|
80
88
|
@new_post.stub!(:allow_comments).and_return(false)
|
81
|
-
|
82
|
-
|
83
|
-
|
89
|
+
|
90
|
+
with_deprecation_silenced do
|
91
|
+
@form = semantic_form_for(@new_post) do |builder|
|
92
|
+
concat(builder.input(:allow_comments, :as => :boolean, :selected => true))
|
93
|
+
end
|
84
94
|
end
|
85
95
|
end
|
86
96
|
|
87
97
|
it 'should be selected' do
|
98
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
88
99
|
output_buffer.should have_tag("form li label input[@type='checkbox'][@checked='checked']")
|
89
100
|
end
|
90
101
|
end
|
@@ -7,10 +7,10 @@ describe 'check_boxes input' do
|
|
7
7
|
|
8
8
|
describe 'for a has_many association' do
|
9
9
|
before do
|
10
|
-
@output_buffer =
|
10
|
+
@output_buffer = ''
|
11
11
|
mock_everything
|
12
12
|
|
13
|
-
semantic_form_for(@fred) do |builder|
|
13
|
+
@form = semantic_form_for(@fred) do |builder|
|
14
14
|
concat(builder.input(:posts, :as => :check_boxes, :value_as_class => true))
|
15
15
|
end
|
16
16
|
end
|
@@ -23,31 +23,37 @@ describe 'check_boxes input' do
|
|
23
23
|
it_should_use_the_collection_when_provided(:check_boxes, 'input[@type="checkbox"]')
|
24
24
|
|
25
25
|
it 'should generate a legend containing a label with text for the input' do
|
26
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
26
27
|
output_buffer.should have_tag('form li fieldset legend.label label')
|
27
28
|
output_buffer.should have_tag('form li fieldset legend.label label', /Posts/)
|
28
29
|
end
|
29
30
|
|
30
31
|
it 'should not link the label within the legend to any input' do
|
32
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
31
33
|
output_buffer.should_not have_tag('form li fieldset legend label[@for^="author_post_ids_"]')
|
32
34
|
end
|
33
35
|
|
34
36
|
|
35
37
|
it 'should generate an ordered list with a list item for each choice' do
|
38
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
36
39
|
output_buffer.should have_tag('form li fieldset ol')
|
37
40
|
output_buffer.should have_tag('form li fieldset ol li', :count => ::Post.find(:all).size)
|
38
41
|
end
|
39
42
|
|
40
43
|
it 'should have one option with a "checked" attribute' do
|
44
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
41
45
|
output_buffer.should have_tag('form li input[@checked]', :count => 1)
|
42
46
|
end
|
43
47
|
|
44
48
|
it 'should generate hidden inputs with default value blank' do
|
49
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
45
50
|
output_buffer.should have_tag("form li fieldset ol li label input[@type='hidden'][@value='']", :count => ::Post.find(:all).size)
|
46
51
|
end
|
47
52
|
|
48
53
|
describe "each choice" do
|
49
54
|
|
50
55
|
it 'should contain a label for the radio input with a nested input and label text' do
|
56
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
51
57
|
::Post.find(:all).each do |post|
|
52
58
|
output_buffer.should have_tag('form li fieldset ol li label', /#{post.to_label}/)
|
53
59
|
output_buffer.should have_tag("form li fieldset ol li label[@for='author_post_ids_#{post.id}']")
|
@@ -55,12 +61,14 @@ describe 'check_boxes input' do
|
|
55
61
|
end
|
56
62
|
|
57
63
|
it 'should use values as li.class when value_as_class is true' do
|
64
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
58
65
|
::Post.find(:all).each do |post|
|
59
66
|
output_buffer.should have_tag("form li fieldset ol li.post_#{post.id} label")
|
60
67
|
end
|
61
68
|
end
|
62
69
|
|
63
70
|
it 'should have a checkbox input for each post' do
|
71
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
64
72
|
::Post.find(:all).each do |post|
|
65
73
|
output_buffer.should have_tag("form li fieldset ol li label input#author_post_ids_#{post.id}")
|
66
74
|
output_buffer.should have_tag("form li fieldset ol li label input[@name='author[post_ids][]']", :count => 2)
|
@@ -69,6 +77,7 @@ describe 'check_boxes input' do
|
|
69
77
|
|
70
78
|
it "should mark input as checked if it's the the existing choice" do
|
71
79
|
::Post.find(:all).include?(@fred.posts.first).should be_true
|
80
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
72
81
|
output_buffer.should have_tag("form li fieldset ol li label input[@checked='checked']")
|
73
82
|
end
|
74
83
|
end
|
@@ -76,20 +85,23 @@ describe 'check_boxes input' do
|
|
76
85
|
describe 'and no object is given' do
|
77
86
|
before(:each) do
|
78
87
|
output_buffer.replace ''
|
79
|
-
semantic_form_for(:project, :url => 'http://test.host') do |builder|
|
88
|
+
@form = semantic_form_for(:project, :url => 'http://test.host') do |builder|
|
80
89
|
concat(builder.input(:author_id, :as => :check_boxes, :collection => ::Author.find(:all)))
|
81
90
|
end
|
82
91
|
end
|
83
92
|
|
84
93
|
it 'should generate a fieldset with legend' do
|
94
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
85
95
|
output_buffer.should have_tag('form li fieldset legend', /Author/)
|
86
96
|
end
|
87
97
|
|
88
98
|
it 'shold generate an li tag for each item in the collection' do
|
99
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
89
100
|
output_buffer.should have_tag('form li fieldset ol li', :count => ::Author.find(:all).size)
|
90
101
|
end
|
91
102
|
|
92
103
|
it 'should generate labels for each item' do
|
104
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
93
105
|
::Author.find(:all).each do |author|
|
94
106
|
output_buffer.should have_tag('form li fieldset ol li label', /#{author.to_label}/)
|
95
107
|
output_buffer.should have_tag("form li fieldset ol li label[@for='project_author_id_#{author.id}']")
|
@@ -97,6 +109,7 @@ describe 'check_boxes input' do
|
|
97
109
|
end
|
98
110
|
|
99
111
|
it 'should generate inputs for each item' do
|
112
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
100
113
|
::Author.find(:all).each do |author|
|
101
114
|
output_buffer.should have_tag("form li fieldset ol li label input#project_author_id_#{author.id}")
|
102
115
|
output_buffer.should have_tag("form li fieldset ol li label input[@type='checkbox']")
|
@@ -108,19 +121,22 @@ describe 'check_boxes input' do
|
|
108
121
|
|
109
122
|
describe 'when :selected is set' do
|
110
123
|
before do
|
111
|
-
@output_buffer =
|
124
|
+
@output_buffer = ''
|
112
125
|
end
|
113
126
|
|
114
127
|
describe "no selected items" do
|
115
128
|
before do
|
116
129
|
@new_post.stub!(:author_ids).and_return(nil)
|
117
130
|
|
118
|
-
|
119
|
-
|
131
|
+
with_deprecation_silenced do
|
132
|
+
@form = semantic_form_for(@new_post) do |builder|
|
133
|
+
concat(builder.input(:authors, :as => :check_boxes, :selected => nil))
|
134
|
+
end
|
120
135
|
end
|
121
136
|
end
|
122
137
|
|
123
138
|
it 'should not have any selected item(s)' do
|
139
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
124
140
|
output_buffer.should_not have_tag("form li fieldset ol li label input[@checked='checked']")
|
125
141
|
end
|
126
142
|
end
|
@@ -129,12 +145,15 @@ describe 'check_boxes input' do
|
|
129
145
|
before do
|
130
146
|
@new_post.stub!(:author_ids).and_return(nil)
|
131
147
|
|
132
|
-
|
133
|
-
|
148
|
+
with_deprecation_silenced do
|
149
|
+
@form = semantic_form_for(@new_post) do |builder|
|
150
|
+
concat(builder.input(:authors, :as => :check_boxes, :selected => @fred.id))
|
151
|
+
end
|
134
152
|
end
|
135
153
|
end
|
136
154
|
|
137
155
|
it "should have one item selected; the specified one" do
|
156
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
138
157
|
output_buffer.should have_tag("form li fieldset ol li label input[@checked='checked']", :count => 1)
|
139
158
|
output_buffer.should have_tag("form li fieldset ol li label[@for='post_author_ids_#{@fred.id}']", /fred/i)
|
140
159
|
output_buffer.should have_tag("form li fieldset ol li label input[@checked='checked'][@value='#{@fred.id}']")
|
@@ -144,13 +163,16 @@ describe 'check_boxes input' do
|
|
144
163
|
describe "multiple selected items" do
|
145
164
|
before do
|
146
165
|
@new_post.stub!(:author_ids).and_return(nil)
|
147
|
-
|
148
|
-
|
149
|
-
|
166
|
+
|
167
|
+
with_deprecation_silenced do
|
168
|
+
@form = semantic_form_for(@new_post) do |builder|
|
169
|
+
concat(builder.input(:authors, :as => :check_boxes, :selected => [@bob.id, @fred.id]))
|
170
|
+
end
|
150
171
|
end
|
151
172
|
end
|
152
173
|
|
153
174
|
it "should have multiple items selected; the specified ones" do
|
175
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
154
176
|
output_buffer.should have_tag("form li fieldset ol li label input[@checked='checked']", :count => 2)
|
155
177
|
output_buffer.should have_tag("form li fieldset ol li label[@for='post_author_ids_#{@bob.id}']", /bob/i)
|
156
178
|
output_buffer.should have_tag("form li fieldset ol li label input[@checked='checked'][@value='#{@bob.id}']")
|
@@ -160,8 +182,78 @@ describe 'check_boxes input' do
|
|
160
182
|
end
|
161
183
|
|
162
184
|
end
|
185
|
+
|
186
|
+
it 'should warn about :selected deprecation' do
|
187
|
+
with_deprecation_silenced do
|
188
|
+
::ActiveSupport::Deprecation.should_receive(:warn).any_number_of_times
|
189
|
+
semantic_form_for(@new_post) do |builder|
|
190
|
+
concat(builder.input(:authors, :as => :check_boxes, :selected => @bob.id))
|
191
|
+
end
|
192
|
+
end
|
193
|
+
end
|
194
|
+
|
195
|
+
|
196
|
+
describe 'when :disabled is set' do
|
197
|
+
before do
|
198
|
+
@output_buffer = ''
|
199
|
+
end
|
200
|
+
|
201
|
+
describe "no disabled items" do
|
202
|
+
before do
|
203
|
+
@new_post.stub!(:author_ids).and_return(nil)
|
204
|
+
|
205
|
+
@form = semantic_form_for(@new_post) do |builder|
|
206
|
+
concat(builder.input(:authors, :as => :check_boxes, :disabled => nil))
|
207
|
+
end
|
208
|
+
end
|
209
|
+
|
210
|
+
it 'should not have any disabled item(s)' do
|
211
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
212
|
+
output_buffer.should_not have_tag("form li fieldset ol li label input[@disabled='disabled']")
|
213
|
+
end
|
214
|
+
end
|
215
|
+
|
216
|
+
describe "single disabled item" do
|
217
|
+
before do
|
218
|
+
@new_post.stub!(:author_ids).and_return(nil)
|
219
|
+
|
220
|
+
@form = semantic_form_for(@new_post) do |builder|
|
221
|
+
concat(builder.input(:authors, :as => :check_boxes, :disabled => @fred.id))
|
222
|
+
end
|
223
|
+
end
|
224
|
+
|
225
|
+
it "should have one item disabled; the specified one" do
|
226
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
227
|
+
output_buffer.should have_tag("form li fieldset ol li label input[@disabled='disabled']", :count => 1)
|
228
|
+
output_buffer.should have_tag("form li fieldset ol li label[@for='post_author_ids_#{@fred.id}']", /fred/i)
|
229
|
+
output_buffer.should have_tag("form li fieldset ol li label input[@disabled='disabled'][@value='#{@fred.id}']")
|
230
|
+
end
|
231
|
+
end
|
232
|
+
|
233
|
+
describe "multiple disabled items" do
|
234
|
+
before do
|
235
|
+
@new_post.stub!(:author_ids).and_return(nil)
|
236
|
+
|
237
|
+
@form = semantic_form_for(@new_post) do |builder|
|
238
|
+
concat(builder.input(:authors, :as => :check_boxes, :disabled => [@bob.id, @fred.id]))
|
239
|
+
end
|
240
|
+
end
|
241
|
+
|
242
|
+
it "should have multiple items disabled; the specified ones" do
|
243
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
244
|
+
output_buffer.should have_tag("form li fieldset ol li label input[@disabled='disabled']", :count => 2)
|
245
|
+
output_buffer.should have_tag("form li fieldset ol li label[@for='post_author_ids_#{@bob.id}']", /bob/i)
|
246
|
+
output_buffer.should have_tag("form li fieldset ol li label input[@disabled='disabled'][@value='#{@bob.id}']")
|
247
|
+
output_buffer.should have_tag("form li fieldset ol li label[@for='post_author_ids_#{@fred.id}']", /fred/i)
|
248
|
+
output_buffer.should have_tag("form li fieldset ol li label input[@disabled='disabled'][@value='#{@fred.id}']")
|
249
|
+
end
|
250
|
+
end
|
251
|
+
|
252
|
+
end
|
163
253
|
|
164
254
|
end
|
255
|
+
|
256
|
+
|
165
257
|
|
166
258
|
end
|
167
259
|
|
@@ -6,7 +6,7 @@ describe 'country input' do
|
|
6
6
|
include FormtasticSpecHelper
|
7
7
|
|
8
8
|
before do
|
9
|
-
@output_buffer =
|
9
|
+
@output_buffer = ''
|
10
10
|
mock_everything
|
11
11
|
end
|
12
12
|
|
@@ -25,8 +25,8 @@ describe 'country input' do
|
|
25
25
|
describe "when country_select is available as a helper (from a plugin)" do
|
26
26
|
|
27
27
|
before do
|
28
|
-
semantic_form_for(@new_post) do |builder|
|
29
|
-
builder.stub!(:country_select).and_return(
|
28
|
+
@form = semantic_form_for(@new_post) do |builder|
|
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
|
@@ -38,12 +38,14 @@ describe 'country input' do
|
|
38
38
|
#it_should_apply_error_logic_for_input_type(:country)
|
39
39
|
|
40
40
|
it 'should generate a label for the input' do
|
41
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
41
42
|
output_buffer.should have_tag('form li label')
|
42
43
|
output_buffer.should have_tag('form li label[@for="post_country"]')
|
43
44
|
output_buffer.should have_tag('form li label', /Country/)
|
44
45
|
end
|
45
46
|
|
46
47
|
it "should generate a select" do
|
48
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
47
49
|
output_buffer.should have_tag("form li select")
|
48
50
|
end
|
49
51
|
|
@@ -54,8 +56,8 @@ describe 'country input' do
|
|
54
56
|
it "should be passed down to the country_select helper when provided" do
|
55
57
|
priority_countries = ["Foo", "Bah"]
|
56
58
|
semantic_form_for(@new_post) do |builder|
|
57
|
-
builder.stub!(:country_select).and_return("<select><option>...</option></select>")
|
58
|
-
builder.should_receive(:country_select).with(:country, priority_countries, {}, {}).and_return("<select><option>...</option></select>")
|
59
|
+
builder.stub!(:country_select).and_return(Formtastic::Util.html_safe("<select><option>...</option></select>"))
|
60
|
+
builder.should_receive(:country_select).with(:country, priority_countries, {}, {}).and_return(Formtastic::Util.html_safe("<select><option>...</option></select>"))
|
59
61
|
|
60
62
|
concat(builder.input(:country, :as => :country, :priority_countries => priority_countries))
|
61
63
|
end
|
@@ -67,14 +69,50 @@ describe 'country input' do
|
|
67
69
|
priority_countries.should_not be_nil
|
68
70
|
|
69
71
|
semantic_form_for(@new_post) do |builder|
|
70
|
-
builder.stub!(:country_select).and_return("<select><option>...</option></select>")
|
71
|
-
builder.should_receive(:country_select).with(:country, priority_countries, {}, {}).and_return("<select><option>...</option></select>")
|
72
|
+
builder.stub!(:country_select).and_return(Formtastic::Util.html_safe("<select><option>...</option></select>"))
|
73
|
+
builder.should_receive(:country_select).with(:country, priority_countries, {}, {}).and_return(Formtastic::Util.html_safe("<select><option>...</option></select>"))
|
72
74
|
|
73
75
|
concat(builder.input(:country, :as => :country))
|
74
76
|
end
|
75
77
|
end
|
76
78
|
|
77
79
|
end
|
78
|
-
|
80
|
+
|
81
|
+
describe "matching" do
|
82
|
+
|
83
|
+
describe "when the attribute is 'country'" do
|
84
|
+
|
85
|
+
before do
|
86
|
+
@form = semantic_form_for(@new_post) do |builder|
|
87
|
+
builder.stub!(:country_select).and_return(Formtastic::Util.html_safe("<select><option>...</option></select>"))
|
88
|
+
concat(builder.input(:country))
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
it "should render a country input" do
|
93
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
94
|
+
output_buffer.should have_tag "form li.country"
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
describe "whent the attribute is 'country_something'" do
|
99
|
+
|
100
|
+
before do
|
101
|
+
@form = semantic_form_for(@new_post) do |builder|
|
102
|
+
concat(builder.input(:country_subdivision))
|
103
|
+
concat(builder.input(:country_code))
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
it "should render a country input" do
|
108
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
109
|
+
output_buffer.should_not have_tag "form li.country"
|
110
|
+
output_buffer.should have_tag "form li.string", :count => 2
|
111
|
+
end
|
112
|
+
|
113
|
+
end
|
114
|
+
|
115
|
+
end
|
116
|
+
|
79
117
|
end
|
80
118
|
|
@@ -6,98 +6,121 @@ describe 'date input' do
|
|
6
6
|
include FormtasticSpecHelper
|
7
7
|
|
8
8
|
before do
|
9
|
-
@output_buffer =
|
9
|
+
@output_buffer = ''
|
10
10
|
mock_everything
|
11
|
-
|
12
|
-
semantic_form_for(@new_post) do |builder|
|
13
|
-
concat(builder.input(:publish_at, :as => :date))
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
it_should_have_input_wrapper_with_class("date")
|
18
|
-
it_should_have_input_wrapper_with_id("post_publish_at_input")
|
19
|
-
it_should_have_a_nested_fieldset
|
20
|
-
it_should_apply_error_logic_for_input_type(:date)
|
21
|
-
|
22
|
-
it 'should have a legend and label with the label text inside the fieldset' do
|
23
|
-
output_buffer.should have_tag('form li.date fieldset legend.label label', /Publish at/)
|
24
11
|
end
|
25
12
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
output_buffer.should have_tag('form li.date fieldset ol')
|
35
|
-
output_buffer.should have_tag('form li.date fieldset ol li', :count => 3)
|
36
|
-
end
|
37
|
-
|
38
|
-
it 'should have three labels for year, month and day' do
|
39
|
-
output_buffer.should have_tag('form li.date fieldset ol li label', :count => 3)
|
40
|
-
output_buffer.should have_tag('form li.date fieldset ol li label', /year/i)
|
41
|
-
output_buffer.should have_tag('form li.date fieldset ol li label', /month/i)
|
42
|
-
output_buffer.should have_tag('form li.date fieldset ol li label', /day/i)
|
43
|
-
end
|
13
|
+
describe "general" do
|
14
|
+
|
15
|
+
before do
|
16
|
+
output_buffer.replace ''
|
17
|
+
@form = semantic_form_for(@new_post) do |builder|
|
18
|
+
concat(builder.input(:publish_at, :as => :date))
|
19
|
+
end
|
20
|
+
end
|
44
21
|
|
45
|
-
|
46
|
-
|
22
|
+
it_should_have_input_wrapper_with_class("date")
|
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(:date)
|
26
|
+
|
27
|
+
it 'should have a legend and label with the label text inside the fieldset' do
|
28
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
29
|
+
output_buffer.should have_tag('form li.date fieldset legend.label label', /Publish at/)
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'should associate the legend label with the first select' do
|
33
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
34
|
+
output_buffer.should have_tag('form li.date fieldset legend.label')
|
35
|
+
output_buffer.should have_tag('form li.date fieldset legend.label label')
|
36
|
+
output_buffer.should have_tag('form li.date fieldset legend.label label[@for]')
|
37
|
+
output_buffer.should have_tag('form li.date fieldset legend.label label[@for="post_publish_at_1i"]')
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'should have an ordered list of three items inside the fieldset' do
|
41
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
42
|
+
output_buffer.should have_tag('form li.date fieldset ol')
|
43
|
+
output_buffer.should have_tag('form li.date fieldset ol li', :count => 3)
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'should have three labels for year, month and day' do
|
47
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
48
|
+
output_buffer.should have_tag('form li.date fieldset ol li label', :count => 3)
|
49
|
+
output_buffer.should have_tag('form li.date fieldset ol li label', /year/i)
|
50
|
+
output_buffer.should have_tag('form li.date fieldset ol li label', /month/i)
|
51
|
+
output_buffer.should have_tag('form li.date fieldset ol li label', /day/i)
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'should have three selects for year, month and day' do
|
55
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
56
|
+
output_buffer.should have_tag('form li.date fieldset ol li select', :count => 3)
|
57
|
+
end
|
47
58
|
end
|
48
59
|
|
49
|
-
describe ':
|
60
|
+
describe ':selected option' do
|
50
61
|
|
51
62
|
describe "when the object has a value" do
|
52
|
-
it "should select the object value (ignoring :
|
63
|
+
it "should select the object value (ignoring :selected)" do
|
53
64
|
output_buffer.replace ''
|
54
65
|
@new_post.stub!(:created_at => Time.mktime(2012))
|
55
|
-
|
56
|
-
|
66
|
+
with_deprecation_silenced do
|
67
|
+
@form = semantic_form_for(@new_post) do |builder|
|
68
|
+
concat(builder.input(:created_at, :as => :date, :selected => Time.mktime(1999)))
|
69
|
+
end
|
57
70
|
end
|
71
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
58
72
|
output_buffer.should have_tag("form li ol li select#post_created_at_1i option[@selected]", :count => 1)
|
59
73
|
output_buffer.should have_tag("form li ol li select#post_created_at_1i option[@value='2012'][@selected]", :count => 1)
|
60
74
|
end
|
61
75
|
end
|
62
76
|
|
63
|
-
describe 'when the object has no value' do
|
64
|
-
it "should select the :
|
77
|
+
describe 'when the object has no value (nil)' do
|
78
|
+
it "should select the :selected if provided as a Date" do
|
65
79
|
output_buffer.replace ''
|
66
80
|
@new_post.stub!(:created_at => nil)
|
67
|
-
|
68
|
-
|
81
|
+
with_deprecation_silenced do
|
82
|
+
@form = semantic_form_for(@new_post) do |builder|
|
83
|
+
concat(builder.input(:created_at, :as => :date, :selected => Date.new(1999)))
|
84
|
+
end
|
69
85
|
end
|
86
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
70
87
|
output_buffer.should have_tag("form li ol li select#post_created_at_1i option[@selected]", :count => 1)
|
71
88
|
output_buffer.should have_tag("form li ol li select#post_created_at_1i option[@value='1999'][@selected]", :count => 1)
|
72
89
|
end
|
73
90
|
|
74
|
-
it "should select the :
|
91
|
+
it "should select the :selected if provided as a Time" do
|
75
92
|
output_buffer.replace ''
|
76
93
|
@new_post.stub!(:created_at => nil)
|
77
|
-
|
78
|
-
|
94
|
+
with_deprecation_silenced do
|
95
|
+
@form = semantic_form_for(@new_post) do |builder|
|
96
|
+
concat(builder.input(:created_at, :as => :date, :selected => Time.mktime(1999)))
|
97
|
+
end
|
79
98
|
end
|
99
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
80
100
|
output_buffer.should have_tag("form li ol li select#post_created_at_1i option[@selected]", :count => 1)
|
81
101
|
output_buffer.should have_tag("form li ol li select#post_created_at_1i option[@value='1999'][@selected]", :count => 1)
|
82
102
|
end
|
83
103
|
|
84
|
-
it "should not select an option if the :
|
104
|
+
it "should not select an option if the :selected is provided as nil" do
|
85
105
|
output_buffer.replace ''
|
86
106
|
@new_post.stub!(:created_at => nil)
|
87
|
-
|
88
|
-
|
107
|
+
with_deprecation_silenced do
|
108
|
+
@form = semantic_form_for(@new_post) do |builder|
|
109
|
+
concat(builder.input(:created_at, :as => :date, :selected => nil))
|
110
|
+
end
|
89
111
|
end
|
112
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
90
113
|
output_buffer.should_not have_tag("form li ol li select#post_created_at_1i option[@selected]")
|
91
114
|
end
|
92
115
|
|
93
|
-
it "should select
|
116
|
+
it "should select nothing if a :selected is not provided" do
|
94
117
|
output_buffer.replace ''
|
95
118
|
@new_post.stub!(:created_at => nil)
|
96
|
-
semantic_form_for(@new_post) do |builder|
|
119
|
+
form = semantic_form_for(@new_post) do |builder|
|
97
120
|
concat(builder.input(:created_at, :as => :date))
|
98
121
|
end
|
99
|
-
output_buffer.
|
100
|
-
output_buffer.
|
122
|
+
output_buffer.concat(form) if Formtastic::Util.rails3?
|
123
|
+
output_buffer.should_not have_tag("form li ol li select option[@selected]")
|
101
124
|
|
102
125
|
end
|
103
126
|
end
|
@@ -109,9 +132,10 @@ describe 'date input' do
|
|
109
132
|
fields.each do |field|
|
110
133
|
it "should replace the #{field} label with the specified text if :labels[:#{field}] is set" do
|
111
134
|
output_buffer.replace ''
|
112
|
-
semantic_form_for(@new_post) do |builder|
|
135
|
+
form = semantic_form_for(@new_post) do |builder|
|
113
136
|
concat(builder.input(:created_at, :as => :date, :labels => { field => "another #{field} label" }))
|
114
137
|
end
|
138
|
+
output_buffer.concat(form) if Formtastic::Util.rails3?
|
115
139
|
output_buffer.should have_tag('form li.date fieldset ol li label', :count => fields.length)
|
116
140
|
fields.each do |f|
|
117
141
|
output_buffer.should have_tag('form li.date fieldset ol li label', f == field ? /another #{f} label/i : /#{f}/i)
|
@@ -120,9 +144,10 @@ describe 'date input' do
|
|
120
144
|
|
121
145
|
it "should not display the label for the #{field} field when :labels[:#{field}] is blank" do
|
122
146
|
output_buffer.replace ''
|
123
|
-
semantic_form_for(@new_post) do |builder|
|
147
|
+
form = semantic_form_for(@new_post) do |builder|
|
124
148
|
concat(builder.input(:created_at, :as => :date, :labels => { field => "" }))
|
125
149
|
end
|
150
|
+
output_buffer.concat(form) if Formtastic::Util.rails3?
|
126
151
|
output_buffer.should have_tag('form li.date fieldset ol li label', :count => fields.length-1)
|
127
152
|
fields.each do |f|
|
128
153
|
output_buffer.should have_tag('form li.date fieldset ol li label', /#{f}/i) unless field == f
|
@@ -133,7 +158,7 @@ describe 'date input' do
|
|
133
158
|
|
134
159
|
it 'should warn about :selected deprecation' do
|
135
160
|
with_deprecation_silenced do
|
136
|
-
::ActiveSupport::Deprecation.should_receive(:warn)
|
161
|
+
::ActiveSupport::Deprecation.should_receive(:warn).any_number_of_times
|
137
162
|
semantic_form_for(@new_post) do |builder|
|
138
163
|
concat(builder.input(:created_at, :as => :date, :selected => Date.new(1999)))
|
139
164
|
end
|