formtastic 1.0.1 → 1.1.0.beta
Sign up to get free protection for your applications and to get access to all the features.
- data/README.textile +2 -2
- data/Rakefile +33 -8
- data/generators/formtastic/templates/formtastic.css +3 -18
- data/init.rb +5 -0
- data/lib/formtastic.rb +180 -82
- data/lib/formtastic/i18n.rb +8 -9
- data/lib/formtastic/layout_helper.rb +0 -1
- data/lib/formtastic/railtie.rb +12 -0
- data/lib/formtastic/util.rb +7 -0
- data/lib/generators/formtastic/form/form_generator.rb +86 -0
- data/lib/generators/formtastic/install/install_generator.rb +24 -0
- data/rails/init.rb +1 -6
- data/spec/buttons_spec.rb +25 -8
- data/spec/commit_button_spec.rb +67 -29
- data/spec/custom_builder_spec.rb +40 -4
- data/spec/defaults_spec.rb +1 -1
- data/spec/error_proc_spec.rb +1 -1
- data/spec/errors_spec.rb +3 -2
- data/spec/form_helper_spec.rb +33 -17
- data/spec/helpers/layout_helper_spec.rb +21 -0
- data/spec/i18n_spec.rb +13 -9
- data/spec/include_blank_spec.rb +9 -5
- data/spec/input_spec.rb +188 -48
- data/spec/inputs/boolean_input_spec.rb +14 -7
- data/spec/inputs/check_boxes_input_spec.rb +150 -20
- data/spec/inputs/country_input_spec.rb +9 -5
- data/spec/inputs/date_input_spec.rb +21 -9
- data/spec/inputs/datetime_input_spec.rb +33 -14
- data/spec/inputs/file_input_spec.rb +4 -3
- data/spec/inputs/hidden_input_spec.rb +11 -4
- 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 +29 -10
- data/spec/inputs/select_input_spec.rb +66 -26
- data/spec/inputs/string_input_spec.rb +5 -4
- data/spec/inputs/text_input_spec.rb +4 -3
- data/spec/inputs/time_input_spec.rb +26 -10
- data/spec/inputs/time_zone_input_spec.rb +11 -5
- data/spec/inputs_spec.rb +103 -39
- data/spec/label_spec.rb +5 -3
- data/spec/semantic_errors_spec.rb +7 -7
- data/spec/semantic_fields_for_spec.rb +5 -4
- data/spec/spec_helper.rb +86 -38
- data/spec/{custom_macros.rb → support/custom_macros.rb} +69 -35
- data/spec/support/output_buffer.rb +4 -0
- data/spec/support/test_environment.rb +45 -0
- metadata +26 -28
- data/spec/layout_helper_spec.rb +0 -29
@@ -1,5 +1,5 @@
|
|
1
1
|
# coding: utf-8
|
2
|
-
require
|
2
|
+
require 'spec_helper'
|
3
3
|
|
4
4
|
describe 'string input' do
|
5
5
|
|
@@ -12,7 +12,7 @@ describe 'string input' do
|
|
12
12
|
|
13
13
|
describe "when object is provided" do
|
14
14
|
before do
|
15
|
-
semantic_form_for(@new_post) do |builder|
|
15
|
+
@form = semantic_form_for(@new_post) do |builder|
|
16
16
|
concat(builder.input(:title, :as => :string))
|
17
17
|
end
|
18
18
|
end
|
@@ -35,7 +35,7 @@ describe 'string input' do
|
|
35
35
|
|
36
36
|
describe "when no object is provided" do
|
37
37
|
before do
|
38
|
-
semantic_form_for(:project, :url => 'http://test.host/') do |builder|
|
38
|
+
@form = semantic_form_for(:project, :url => 'http://test.host/') do |builder|
|
39
39
|
concat(builder.input(:title, :as => :string))
|
40
40
|
end
|
41
41
|
end
|
@@ -49,12 +49,13 @@ describe 'string input' do
|
|
49
49
|
|
50
50
|
describe "when size is nil" do
|
51
51
|
before do
|
52
|
-
semantic_form_for(:project, :url => 'http://test.host/') do |builder|
|
52
|
+
@form = semantic_form_for(:project, :url => 'http://test.host/') do |builder|
|
53
53
|
concat(builder.input(:title, :as => :string, :input_html => {:size => nil}))
|
54
54
|
end
|
55
55
|
end
|
56
56
|
|
57
57
|
it "should have no size attribute" do
|
58
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
58
59
|
output_buffer.should_not have_tag("input[@size]")
|
59
60
|
end
|
60
61
|
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
# coding: utf-8
|
2
|
-
require
|
2
|
+
require 'spec_helper'
|
3
3
|
|
4
4
|
describe 'text input' do
|
5
5
|
|
@@ -9,7 +9,7 @@ describe 'text input' do
|
|
9
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(:body, :as => :text))
|
14
14
|
end
|
15
15
|
end
|
@@ -23,9 +23,10 @@ describe 'text input' do
|
|
23
23
|
it_should_apply_error_logic_for_input_type(:numeric)
|
24
24
|
|
25
25
|
it 'should use input_html to style inputs' do
|
26
|
-
semantic_form_for(@new_post) do |builder|
|
26
|
+
form = semantic_form_for(@new_post) do |builder|
|
27
27
|
concat(builder.input(:title, :as => :text, :input_html => { :class => 'myclass' }))
|
28
28
|
end
|
29
|
+
output_buffer.concat(form) if Formtastic::Util.rails3?
|
29
30
|
output_buffer.should have_tag("form li textarea.myclass")
|
30
31
|
end
|
31
32
|
|
@@ -1,5 +1,5 @@
|
|
1
1
|
# coding: utf-8
|
2
|
-
require
|
2
|
+
require 'spec_helper'
|
3
3
|
|
4
4
|
describe 'time input' do
|
5
5
|
|
@@ -18,18 +18,20 @@ describe 'time input' do
|
|
18
18
|
|
19
19
|
describe "with :ignore_date" do
|
20
20
|
before do
|
21
|
-
semantic_form_for(@new_post) do |builder|
|
21
|
+
@form = semantic_form_for(@new_post) do |builder|
|
22
22
|
concat(builder.input(:publish_at, :as => :time, :ignore_date => true))
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
26
26
|
it 'should not have an input for day, month and year' do
|
27
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
27
28
|
output_buffer.should_not have_tag('#post_publish_at_1i')
|
28
29
|
output_buffer.should_not have_tag('#post_publish_at_2i')
|
29
30
|
output_buffer.should_not have_tag('#post_publish_at_3i')
|
30
31
|
end
|
31
32
|
|
32
33
|
it 'should have an input for hour and minute' do
|
34
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
33
35
|
output_buffer.should have_tag('#post_publish_at_4i')
|
34
36
|
output_buffer.should have_tag('#post_publish_at_5i')
|
35
37
|
end
|
@@ -38,7 +40,7 @@ describe 'time input' do
|
|
38
40
|
|
39
41
|
describe "without seconds" do
|
40
42
|
before do
|
41
|
-
semantic_form_for(@new_post) do |builder|
|
43
|
+
@form = semantic_form_for(@new_post) do |builder|
|
42
44
|
concat(builder.input(:publish_at, :as => :time))
|
43
45
|
end
|
44
46
|
end
|
@@ -49,37 +51,43 @@ describe 'time input' do
|
|
49
51
|
it_should_apply_error_logic_for_input_type(:time)
|
50
52
|
|
51
53
|
it 'should have a legend and label with the label text inside the fieldset' do
|
54
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
52
55
|
output_buffer.should have_tag('form li.time fieldset legend.label label', /Publish at/)
|
53
56
|
end
|
54
57
|
|
55
58
|
it 'should associate the legend label with the first select' do
|
59
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
56
60
|
output_buffer.should have_tag('form li.time fieldset legend.label label[@for="post_publish_at_1i"]')
|
57
61
|
end
|
58
62
|
|
59
63
|
it 'should have an ordered list of two items inside the fieldset' do
|
64
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
60
65
|
output_buffer.should have_tag('form li.time fieldset ol')
|
61
66
|
output_buffer.should have_tag('form li.time fieldset ol li', :count => 2)
|
62
67
|
end
|
63
68
|
|
64
69
|
it 'should have five labels for hour and minute' do
|
70
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
65
71
|
output_buffer.should have_tag('form li.time fieldset ol li label', :count => 2)
|
66
72
|
output_buffer.should have_tag('form li.time fieldset ol li label', /hour/i)
|
67
73
|
output_buffer.should have_tag('form li.time fieldset ol li label', /minute/i)
|
68
74
|
end
|
69
75
|
|
70
76
|
it 'should have two selects for hour and minute' do
|
77
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
71
78
|
output_buffer.should have_tag('form li.time fieldset ol li', :count => 2)
|
72
79
|
end
|
73
80
|
end
|
74
81
|
|
75
82
|
describe "with seconds" do
|
76
83
|
before do
|
77
|
-
semantic_form_for(@new_post) do |builder|
|
84
|
+
@form = semantic_form_for(@new_post) do |builder|
|
78
85
|
concat(builder.input(:publish_at, :as => :time, :include_seconds => true))
|
79
86
|
end
|
80
87
|
end
|
81
88
|
|
82
89
|
it 'should have five labels for hour and minute' do
|
90
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
83
91
|
output_buffer.should have_tag('form li.time fieldset ol li label', :count => 3)
|
84
92
|
output_buffer.should have_tag('form li.time fieldset ol li label', /hour/i)
|
85
93
|
output_buffer.should have_tag('form li.time fieldset ol li label', /minute/i)
|
@@ -87,10 +95,12 @@ describe 'time input' do
|
|
87
95
|
end
|
88
96
|
|
89
97
|
it 'should have three selects for hour, minute and seconds' do
|
98
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
90
99
|
output_buffer.should have_tag('form li.time fieldset ol li', :count => 3)
|
91
100
|
end
|
92
101
|
|
93
102
|
it 'should generate a sanitized label and matching ids for attribute' do
|
103
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
94
104
|
4.upto(6) do |i|
|
95
105
|
output_buffer.should have_tag("form li fieldset ol li label[@for='post_publish_at_#{i}i']")
|
96
106
|
output_buffer.should have_tag("form li fieldset ol li #post_publish_at_#{i}i")
|
@@ -106,10 +116,11 @@ describe 'time input' do
|
|
106
116
|
output_buffer.replace ''
|
107
117
|
@new_post.stub!(:created_at => Time.mktime(2012, 11, 30, 21, 45))
|
108
118
|
with_deprecation_silenced do
|
109
|
-
semantic_form_for(@new_post) do |builder|
|
119
|
+
@form = semantic_form_for(@new_post) do |builder|
|
110
120
|
concat(builder.input(:created_at, :as => :time, :selected => Time.mktime(1999, 12, 31, 22, 59)))
|
111
121
|
end
|
112
122
|
end
|
123
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
113
124
|
output_buffer.should have_tag("form li ol li select#post_created_at_4i option[@selected]", :count => 1)
|
114
125
|
output_buffer.should have_tag("form li ol li select#post_created_at_4i option[@value='21'][@selected]", :count => 1)
|
115
126
|
end
|
@@ -120,10 +131,11 @@ describe 'time input' do
|
|
120
131
|
output_buffer.replace ''
|
121
132
|
@new_post.stub!(:created_at => nil)
|
122
133
|
with_deprecation_silenced do
|
123
|
-
semantic_form_for(@new_post) do |builder|
|
134
|
+
@form = semantic_form_for(@new_post) do |builder|
|
124
135
|
concat(builder.input(:created_at, :as => :time, :selected => Time.mktime(1999, 12, 31, 22, 59)))
|
125
136
|
end
|
126
137
|
end
|
138
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
127
139
|
output_buffer.should have_tag("form li ol li select#post_created_at_4i option[@selected]", :count => 1)
|
128
140
|
output_buffer.should have_tag("form li ol li select#post_created_at_4i option[@value='22'][@selected]", :count => 1)
|
129
141
|
end
|
@@ -132,19 +144,21 @@ describe 'time input' do
|
|
132
144
|
output_buffer.replace ''
|
133
145
|
@new_post.stub!(:created_at => nil)
|
134
146
|
with_deprecation_silenced do
|
135
|
-
semantic_form_for(@new_post) do |builder|
|
147
|
+
@form = semantic_form_for(@new_post) do |builder|
|
136
148
|
concat(builder.input(:created_at, :as => :time, :selected => nil))
|
137
149
|
end
|
138
150
|
end
|
151
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
139
152
|
output_buffer.should_not have_tag("form li ol li select#post_created_at_4i option[@selected]")
|
140
153
|
end
|
141
154
|
|
142
155
|
it "should select nothing if a :selected is not provided" do
|
143
156
|
output_buffer.replace ''
|
144
157
|
@new_post.stub!(:created_at => nil)
|
145
|
-
semantic_form_for(@new_post) do |builder|
|
158
|
+
form = semantic_form_for(@new_post) do |builder|
|
146
159
|
concat(builder.input(:created_at, :as => :time))
|
147
160
|
end
|
161
|
+
output_buffer.concat(form) if Formtastic::Util.rails3?
|
148
162
|
output_buffer.should_not have_tag("form li ol li select option[@selected]")
|
149
163
|
end
|
150
164
|
end
|
@@ -156,9 +170,10 @@ describe 'time input' do
|
|
156
170
|
fields.each do |field|
|
157
171
|
it "should replace the #{field} label with the specified text if :labels[:#{field}] is set" do
|
158
172
|
output_buffer.replace ''
|
159
|
-
semantic_form_for(@new_post) do |builder|
|
173
|
+
form = semantic_form_for(@new_post) do |builder|
|
160
174
|
concat(builder.input(:created_at, :as => :time, :include_seconds => true, :labels => { field => "another #{field} label" }))
|
161
175
|
end
|
176
|
+
output_buffer.concat(form) if Formtastic::Util.rails3?
|
162
177
|
output_buffer.should have_tag('form li.time fieldset ol li label', :count => fields.length)
|
163
178
|
fields.each do |f|
|
164
179
|
output_buffer.should have_tag('form li.time fieldset ol li label', f == field ? /another #{f} label/i : /#{f}/i)
|
@@ -167,9 +182,10 @@ describe 'time input' do
|
|
167
182
|
|
168
183
|
it "should not display the label for the #{field} field when :labels[:#{field}] is blank" do
|
169
184
|
output_buffer.replace ''
|
170
|
-
semantic_form_for(@new_post) do |builder|
|
185
|
+
form = semantic_form_for(@new_post) do |builder|
|
171
186
|
concat(builder.input(:created_at, :as => :time, :include_seconds => true, :labels => { field => "" }))
|
172
187
|
end
|
188
|
+
output_buffer.concat(form) if Formtastic::Util.rails3?
|
173
189
|
output_buffer.should have_tag('form li.time fieldset ol li label', :count => fields.length-1)
|
174
190
|
fields.each do |f|
|
175
191
|
output_buffer.should have_tag('form li.time fieldset ol li label', /#{f}/i) unless field == f
|
@@ -1,5 +1,5 @@
|
|
1
1
|
# coding: utf-8
|
2
|
-
require
|
2
|
+
require 'spec_helper'
|
3
3
|
|
4
4
|
describe 'time_zone input' do
|
5
5
|
|
@@ -9,7 +9,7 @@ describe 'time_zone input' do
|
|
9
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(:time_zone))
|
14
14
|
end
|
15
15
|
end
|
@@ -19,38 +19,43 @@ describe 'time_zone input' do
|
|
19
19
|
it_should_apply_error_logic_for_input_type(:time_zone)
|
20
20
|
|
21
21
|
it 'should generate a label for the input' do
|
22
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
22
23
|
output_buffer.should have_tag('form li label')
|
23
24
|
output_buffer.should have_tag('form li label[@for="post_time_zone"]')
|
24
25
|
output_buffer.should have_tag('form li label', /Time zone/)
|
25
26
|
end
|
26
27
|
|
27
28
|
it "should generate a select" do
|
29
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
28
30
|
output_buffer.should have_tag("form li select")
|
29
31
|
output_buffer.should have_tag("form li select#post_time_zone")
|
30
32
|
output_buffer.should have_tag("form li select[@name=\"post[time_zone]\"]")
|
31
33
|
end
|
32
34
|
|
33
35
|
it 'should use input_html to style inputs' do
|
34
|
-
semantic_form_for(@new_post) do |builder|
|
36
|
+
form = semantic_form_for(@new_post) do |builder|
|
35
37
|
concat(builder.input(:time_zone, :input_html => { :class => 'myclass' }))
|
36
38
|
end
|
39
|
+
output_buffer.concat(form) if Formtastic::Util.rails3?
|
37
40
|
output_buffer.should have_tag("form li select.myclass")
|
38
41
|
end
|
39
42
|
|
40
43
|
describe 'when no object is given' do
|
41
44
|
before(:each) do
|
42
|
-
semantic_form_for(:project, :url => 'http://test.host/') do |builder|
|
45
|
+
@form = semantic_form_for(:project, :url => 'http://test.host/') do |builder|
|
43
46
|
concat(builder.input(:time_zone, :as => :time_zone))
|
44
47
|
end
|
45
48
|
end
|
46
49
|
|
47
50
|
it 'should generate labels' do
|
51
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
48
52
|
output_buffer.should have_tag('form li label')
|
49
53
|
output_buffer.should have_tag('form li label[@for="project_time_zone"]')
|
50
54
|
output_buffer.should have_tag('form li label', /Time zone/)
|
51
55
|
end
|
52
56
|
|
53
57
|
it 'should generate select inputs' do
|
58
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
54
59
|
output_buffer.should have_tag("form li select")
|
55
60
|
output_buffer.should have_tag("form li select#project_time_zone")
|
56
61
|
output_buffer.should have_tag("form li select[@name=\"project[time_zone]\"]")
|
@@ -86,13 +91,14 @@ describe 'time_zone input' do
|
|
86
91
|
@new_post.stub!(:time_zone).and_return(nil)
|
87
92
|
|
88
93
|
with_deprecation_silenced do
|
89
|
-
semantic_form_for(@new_post) do |builder|
|
94
|
+
@form = semantic_form_for(@new_post) do |builder|
|
90
95
|
concat(builder.input(:time_zone, :as => :time_zone, :selected => 'Melbourne'))
|
91
96
|
end
|
92
97
|
end
|
93
98
|
end
|
94
99
|
|
95
100
|
it 'should have a selected item; the specified one' do
|
101
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
96
102
|
output_buffer.should have_tag("form li select option[@selected='selected']", :count => 1)
|
97
103
|
output_buffer.should have_tag("form li select option[@selected='selected']", /Melbourne/i)
|
98
104
|
output_buffer.should have_tag("form li select option[@selected='selected'][@value='Melbourne']")
|
data/spec/inputs_spec.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# coding: utf-8
|
2
|
-
require
|
2
|
+
require 'spec_helper'
|
3
3
|
|
4
4
|
describe 'SemanticFormBuilder#inputs' do
|
5
5
|
|
@@ -15,7 +15,7 @@ describe 'SemanticFormBuilder#inputs' do
|
|
15
15
|
describe 'when no options are provided' do
|
16
16
|
before do
|
17
17
|
output_buffer.replace 'before_builder' # clear the output buffer and sets before_builder
|
18
|
-
semantic_form_for(@new_post) do |builder|
|
18
|
+
@form = semantic_form_for(@new_post) do |builder|
|
19
19
|
@inputs_output = builder.inputs do
|
20
20
|
concat('hello')
|
21
21
|
end
|
@@ -23,33 +23,39 @@ describe 'SemanticFormBuilder#inputs' do
|
|
23
23
|
end
|
24
24
|
|
25
25
|
it 'should output just the content wrapped in inputs, not the whole template' do
|
26
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
26
27
|
output_buffer.should =~ /before_builder/
|
27
28
|
@inputs_output.should_not =~ /before_builder/
|
28
29
|
end
|
29
30
|
|
30
31
|
it 'should render a fieldset inside the form, with a class of "inputs"' do
|
32
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
31
33
|
output_buffer.should have_tag("form fieldset.inputs")
|
32
34
|
end
|
33
35
|
|
34
36
|
it 'should render an ol inside the fieldset' do
|
37
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
35
38
|
output_buffer.should have_tag("form fieldset.inputs ol")
|
36
39
|
end
|
37
40
|
|
38
41
|
it 'should render the contents of the block inside the ol' do
|
42
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
39
43
|
output_buffer.should have_tag("form fieldset.inputs ol", /hello/)
|
40
44
|
end
|
41
45
|
|
42
46
|
it 'should not render a legend inside the fieldset' do
|
47
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
43
48
|
output_buffer.should_not have_tag("form fieldset.inputs legend")
|
44
49
|
end
|
45
50
|
|
46
51
|
it 'should render a fieldset even if no object is given' do
|
47
|
-
semantic_form_for(:project, :url => 'http://test.host/') do |builder|
|
52
|
+
form = semantic_form_for(:project, :url => 'http://test.host/') do |builder|
|
48
53
|
@inputs_output = builder.inputs do
|
49
54
|
concat('bye')
|
50
55
|
end
|
51
56
|
end
|
52
57
|
|
58
|
+
output_buffer.concat(form) if Formtastic::Util.rails3?
|
53
59
|
output_buffer.should have_tag("form fieldset.inputs ol", /bye/)
|
54
60
|
end
|
55
61
|
end
|
@@ -64,25 +70,45 @@ describe 'SemanticFormBuilder#inputs' do
|
|
64
70
|
it 'should render nested inputs' do
|
65
71
|
@bob.stub!(:column_for_attribute).and_return(mock('column', :type => :string, :limit => 255))
|
66
72
|
|
67
|
-
semantic_form_for(@new_post) do |builder|
|
73
|
+
form = semantic_form_for(@new_post) do |builder|
|
74
|
+
inputs = builder.inputs :for => [:author, @bob] do |bob_builder|
|
75
|
+
concat(bob_builder.input(:login))
|
76
|
+
end
|
77
|
+
concat(inputs)
|
78
|
+
end
|
79
|
+
|
80
|
+
output_buffer.concat(form) if Formtastic::Util.rails3?
|
81
|
+
output_buffer.should have_tag("form fieldset.inputs #post_author_attributes_login")
|
82
|
+
output_buffer.should_not have_tag("form fieldset.inputs #author_login")
|
83
|
+
|
84
|
+
end
|
85
|
+
|
86
|
+
it 'should concat rendered nested inputs to the template under rails3' do
|
87
|
+
@bob.stub!(:column_for_attribute).and_return(mock('column', :type => :string, :limit => 255))
|
88
|
+
::Formtastic::Util.stub!(:rails3?).and_return(true)
|
89
|
+
|
90
|
+
form = semantic_form_for(@new_post) do |builder|
|
68
91
|
builder.inputs :for => [:author, @bob] do |bob_builder|
|
69
92
|
concat(bob_builder.input(:login))
|
70
93
|
end
|
71
94
|
end
|
72
95
|
|
96
|
+
output_buffer.concat(form) if Formtastic::Util.rails3?
|
73
97
|
output_buffer.should have_tag("form fieldset.inputs #post_author_attributes_login")
|
74
98
|
output_buffer.should_not have_tag("form fieldset.inputs #author_login")
|
75
99
|
|
76
100
|
end
|
77
|
-
|
101
|
+
|
78
102
|
describe "as a symbol representing the association name" do
|
79
103
|
|
80
104
|
it 'should nest the inputs with an _attributes suffix on the association name' do
|
81
|
-
semantic_form_for(@new_post) do |post|
|
82
|
-
post.inputs :for => :author do |author|
|
105
|
+
form = semantic_form_for(@new_post) do |post|
|
106
|
+
inputs = post.inputs :for => :author do |author|
|
83
107
|
concat(author.input(:login))
|
84
108
|
end
|
109
|
+
concat(inputs)
|
85
110
|
end
|
111
|
+
output_buffer.concat(form) if Formtastic::Util.rails3?
|
86
112
|
output_buffer.should have_tag("form input[@name='post[author_attributes][login]']")
|
87
113
|
end
|
88
114
|
|
@@ -95,12 +121,13 @@ describe 'SemanticFormBuilder#inputs' do
|
|
95
121
|
end
|
96
122
|
|
97
123
|
it 'should nest the inputs with a name input for each item' do
|
98
|
-
semantic_form_for(@new_post) do |post|
|
124
|
+
form = semantic_form_for(@new_post) do |post|
|
99
125
|
post.inputs :for => :authors do |author|
|
100
126
|
concat(author.input(:login))
|
101
127
|
end
|
102
128
|
end
|
103
129
|
|
130
|
+
output_buffer.concat(form) if Formtastic::Util.rails3?
|
104
131
|
output_buffer.should have_tag("form input[@name='post[authors_attributes][0][login]']")
|
105
132
|
output_buffer.should have_tag("form input[@name='post[authors_attributes][1][login]']")
|
106
133
|
end
|
@@ -109,11 +136,13 @@ describe 'SemanticFormBuilder#inputs' do
|
|
109
136
|
describe 'as an array containing the a symbole for the association name and the associated object' do
|
110
137
|
|
111
138
|
it 'should nest the inputs with an _attributes suffix on the association name' do
|
112
|
-
semantic_form_for(@new_post) do |post|
|
113
|
-
post.inputs :for => [:author, @new_post.author] do |author|
|
139
|
+
form = semantic_form_for(@new_post) do |post|
|
140
|
+
inputs = post.inputs :for => [:author, @new_post.author] do |author|
|
114
141
|
concat(author.input(:login))
|
115
142
|
end
|
143
|
+
concat(inputs)
|
116
144
|
end
|
145
|
+
output_buffer.concat(form) if Formtastic::Util.rails3?
|
117
146
|
output_buffer.should have_tag("form input[@name='post[author_attributes][login]']")
|
118
147
|
end
|
119
148
|
|
@@ -122,11 +151,13 @@ describe 'SemanticFormBuilder#inputs' do
|
|
122
151
|
describe 'as an associated object' do
|
123
152
|
|
124
153
|
it 'should not nest the inputs with an _attributes suffix' do
|
125
|
-
semantic_form_for(@new_post) do |post|
|
126
|
-
post.inputs :for => @new_post.author do |author|
|
154
|
+
form = semantic_form_for(@new_post) do |post|
|
155
|
+
inputs = post.inputs :for => @new_post.author do |author|
|
127
156
|
concat(author.input(:login))
|
128
157
|
end
|
158
|
+
concat(inputs)
|
129
159
|
end
|
160
|
+
output_buffer.concat(form) if Formtastic::Util.rails3?
|
130
161
|
output_buffer.should have_tag("form input[@name='post[author][login]']")
|
131
162
|
end
|
132
163
|
|
@@ -146,44 +177,52 @@ describe 'SemanticFormBuilder#inputs' do
|
|
146
177
|
it 'should pass options down to semantic_fields_for' do
|
147
178
|
@bob.stub!(:column_for_attribute).and_return(mock('column', :type => :string, :limit => 255))
|
148
179
|
|
149
|
-
semantic_form_for(@new_post) do |builder|
|
150
|
-
builder.inputs :for => [:author, @bob], :for_options => { :index => 10 } do |bob_builder|
|
180
|
+
form = semantic_form_for(@new_post) do |builder|
|
181
|
+
inputs = builder.inputs :for => [:author, @bob], :for_options => { :index => 10 } do |bob_builder|
|
151
182
|
concat(bob_builder.input(:login))
|
152
183
|
end
|
184
|
+
concat(inputs)
|
153
185
|
end
|
154
186
|
|
187
|
+
output_buffer.concat(form) if Formtastic::Util.rails3?
|
155
188
|
output_buffer.should have_tag('form fieldset ol li #post_author_attributes_10_login')
|
156
189
|
end
|
157
190
|
|
158
191
|
it 'should not add builder as a fieldset attribute tag' do
|
159
|
-
semantic_form_for(@new_post) do |builder|
|
160
|
-
builder.inputs :for => [:author, @bob], :for_options => { :index => 10 } do |bob_builder|
|
192
|
+
form = semantic_form_for(@new_post) do |builder|
|
193
|
+
inputs = builder.inputs :for => [:author, @bob], :for_options => { :index => 10 } do |bob_builder|
|
161
194
|
concat('input')
|
162
195
|
end
|
196
|
+
concat(inputs)
|
163
197
|
end
|
164
198
|
|
199
|
+
output_buffer.concat(form) if Formtastic::Util.rails3?
|
165
200
|
output_buffer.should_not have_tag('fieldset[@builder="Formtastic::SemanticFormHelper"]')
|
166
201
|
end
|
167
202
|
|
168
203
|
it 'should send parent_builder as an option to allow child index interpolation' do
|
169
|
-
semantic_form_for(@new_post) do |builder|
|
204
|
+
form = semantic_form_for(@new_post) do |builder|
|
170
205
|
builder.instance_variable_set('@nested_child_index', 0)
|
171
|
-
builder.inputs :for => [:author, @bob], :name => 'Author #%i' do |bob_builder|
|
206
|
+
inputs = builder.inputs :for => [:author, @bob], :name => 'Author #%i' do |bob_builder|
|
172
207
|
concat('input')
|
173
208
|
end
|
209
|
+
concat(inputs)
|
174
210
|
end
|
175
211
|
|
212
|
+
output_buffer.concat(form) if Formtastic::Util.rails3?
|
176
213
|
output_buffer.should have_tag('fieldset legend', 'Author #1')
|
177
214
|
end
|
178
215
|
|
179
216
|
it 'should also provide child index interpolation when nested child index is a hash' do
|
180
|
-
semantic_form_for(@new_post) do |builder|
|
217
|
+
form = semantic_form_for(@new_post) do |builder|
|
181
218
|
builder.instance_variable_set('@nested_child_index', :author => 10)
|
182
|
-
builder.inputs :for => [:author, @bob], :name => 'Author #%i' do |bob_builder|
|
219
|
+
inputs = builder.inputs :for => [:author, @bob], :name => 'Author #%i' do |bob_builder|
|
183
220
|
concat('input')
|
184
221
|
end
|
222
|
+
concat(inputs)
|
185
223
|
end
|
186
224
|
|
225
|
+
output_buffer.concat(form) if Formtastic::Util.rails3?
|
187
226
|
output_buffer.should have_tag('fieldset legend', 'Author #11')
|
188
227
|
end
|
189
228
|
end
|
@@ -195,19 +234,24 @@ describe 'SemanticFormBuilder#inputs' do
|
|
195
234
|
@legend_text_using_name = "Advanced options 2"
|
196
235
|
@legend_text_using_title = "Advanced options 3"
|
197
236
|
@nested_forms_legend_text = "This is a nested form title"
|
198
|
-
semantic_form_for(@new_post) do |builder|
|
199
|
-
builder.inputs @legend_text do
|
237
|
+
@form = semantic_form_for(@new_post) do |builder|
|
238
|
+
inputs = builder.inputs @legend_text do
|
200
239
|
end
|
201
|
-
|
240
|
+
concat(inputs)
|
241
|
+
inputs = builder.inputs :name => @legend_text_using_name do
|
202
242
|
end
|
203
|
-
|
243
|
+
concat(inputs)
|
244
|
+
inputs = builder.inputs :title => @legend_text_using_title do
|
204
245
|
end
|
205
|
-
|
246
|
+
concat(inputs)
|
247
|
+
inputs = builder.inputs @nested_forms_legend_text, :for => :authors do |nf|
|
206
248
|
end
|
249
|
+
concat(inputs)
|
207
250
|
end
|
208
251
|
end
|
209
252
|
|
210
253
|
it 'should render a fieldset with a legend inside the form' do
|
254
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
211
255
|
output_buffer.should have_tag("form fieldset legend", /^#{@legend_text}$/)
|
212
256
|
output_buffer.should have_tag("form fieldset legend", /^#{@legend_text_using_name}$/)
|
213
257
|
output_buffer.should have_tag("form fieldset legend", /^#{@legend_text_using_title}$/)
|
@@ -231,19 +275,24 @@ describe 'SemanticFormBuilder#inputs' do
|
|
231
275
|
}
|
232
276
|
}
|
233
277
|
}
|
234
|
-
semantic_form_for(@new_post) do |builder|
|
235
|
-
builder.inputs :advanced_options do
|
278
|
+
@form = semantic_form_for(@new_post) do |builder|
|
279
|
+
inputs = builder.inputs :advanced_options do
|
236
280
|
end
|
237
|
-
|
281
|
+
concat(inputs)
|
282
|
+
inputs =builder.inputs :name => :advanced_options_using_name do
|
238
283
|
end
|
239
|
-
|
284
|
+
concat(inputs)
|
285
|
+
inputs = builder.inputs :title => :advanced_options_using_title do
|
240
286
|
end
|
241
|
-
|
287
|
+
concat(inputs)
|
288
|
+
inputs = builder.inputs :nested_forms_title, :for => :authors do |nf|
|
242
289
|
end
|
290
|
+
concat(inputs)
|
243
291
|
end
|
244
292
|
end
|
245
293
|
|
246
294
|
it 'should render a fieldset with a localized legend inside the form' do
|
295
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
247
296
|
output_buffer.should have_tag("form fieldset legend", /^#{@localized_legend_text}$/)
|
248
297
|
output_buffer.should have_tag("form fieldset legend", /^#{@localized_legend_text_using_name}$/)
|
249
298
|
output_buffer.should have_tag("form fieldset legend", /^#{@localized_legend_text_using_title}$/)
|
@@ -257,13 +306,14 @@ describe 'SemanticFormBuilder#inputs' do
|
|
257
306
|
@id_option = 'advanced'
|
258
307
|
@class_option = 'wide'
|
259
308
|
|
260
|
-
semantic_form_for(@new_post) do |builder|
|
309
|
+
@form = semantic_form_for(@new_post) do |builder|
|
261
310
|
builder.inputs :id => @id_option, :class => @class_option do
|
262
311
|
end
|
263
312
|
end
|
264
313
|
end
|
265
314
|
|
266
315
|
it 'should pass the options into the fieldset tag as attributes' do
|
316
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
267
317
|
output_buffer.should have_tag("form fieldset##{@id_option}")
|
268
318
|
output_buffer.should have_tag("form fieldset.#{@class_option}")
|
269
319
|
end
|
@@ -290,46 +340,55 @@ describe 'SemanticFormBuilder#inputs' do
|
|
290
340
|
|
291
341
|
describe 'with no args' do
|
292
342
|
before do
|
293
|
-
semantic_form_for(@new_post) do |builder|
|
343
|
+
@form = semantic_form_for(@new_post) do |builder|
|
294
344
|
concat(builder.inputs)
|
295
345
|
end
|
296
346
|
end
|
297
347
|
|
298
348
|
it 'should render a form' do
|
349
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
299
350
|
output_buffer.should have_tag('form')
|
300
351
|
end
|
301
352
|
|
302
353
|
it 'should render a fieldset inside the form' do
|
354
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
303
355
|
output_buffer.should have_tag('form > fieldset.inputs')
|
304
356
|
end
|
305
357
|
|
306
358
|
it 'should not render a legend in the fieldset' do
|
359
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
307
360
|
output_buffer.should_not have_tag('form > fieldset.inputs > legend')
|
308
361
|
end
|
309
362
|
|
310
363
|
it 'should render an ol in the fieldset' do
|
364
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
311
365
|
output_buffer.should have_tag('form > fieldset.inputs > ol')
|
312
366
|
end
|
313
367
|
|
314
368
|
it 'should render a list item in the ol for each column and reflection' do
|
315
369
|
# Remove the :has_many macro and :created_at column
|
316
370
|
count = ::Post.content_columns.size + ::Post.reflections.size - 2
|
371
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
317
372
|
output_buffer.should have_tag('form > fieldset.inputs > ol > li', :count => count)
|
318
373
|
end
|
319
374
|
|
320
375
|
it 'should render a string list item for title' do
|
376
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
321
377
|
output_buffer.should have_tag('form > fieldset.inputs > ol > li.string')
|
322
378
|
end
|
323
379
|
|
324
380
|
it 'should render a text list item for body' do
|
381
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
325
382
|
output_buffer.should have_tag('form > fieldset.inputs > ol > li.text')
|
326
383
|
end
|
327
384
|
|
328
385
|
it 'should render a select list item for author_id' do
|
386
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
329
387
|
output_buffer.should have_tag('form > fieldset.inputs > ol > li.select', :count => 1)
|
330
388
|
end
|
331
389
|
|
332
390
|
it 'should not render timestamps inputs by default' do
|
391
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
333
392
|
output_buffer.should_not have_tag('form > fieldset.inputs > ol > li.datetime')
|
334
393
|
end
|
335
394
|
end
|
@@ -337,10 +396,11 @@ describe 'SemanticFormBuilder#inputs' do
|
|
337
396
|
describe 'with column names as args' do
|
338
397
|
describe 'and an object is given' do
|
339
398
|
it 'should render a form with a fieldset containing two list items' do
|
340
|
-
semantic_form_for(@new_post) do |builder|
|
399
|
+
form = semantic_form_for(@new_post) do |builder|
|
341
400
|
concat(builder.inputs(:title, :body))
|
342
401
|
end
|
343
402
|
|
403
|
+
output_buffer.concat(form) if Formtastic::Util.rails3?
|
344
404
|
output_buffer.should have_tag('form > fieldset.inputs > ol > li', :count => 2)
|
345
405
|
output_buffer.should have_tag('form > fieldset.inputs > ol > li.string')
|
346
406
|
output_buffer.should have_tag('form > fieldset.inputs > ol > li.text')
|
@@ -349,10 +409,11 @@ describe 'SemanticFormBuilder#inputs' do
|
|
349
409
|
|
350
410
|
describe 'and no object is given' do
|
351
411
|
it 'should render a form with a fieldset containing two list items' do
|
352
|
-
semantic_form_for(:project, :url => 'http://test.host') do |builder|
|
412
|
+
form = semantic_form_for(:project, :url => 'http://test.host') do |builder|
|
353
413
|
concat(builder.inputs(:title, :body))
|
354
414
|
end
|
355
415
|
|
416
|
+
output_buffer.concat(form) if Formtastic::Util.rails3?
|
356
417
|
output_buffer.should have_tag('form > fieldset.inputs > ol > li.string', :count => 2)
|
357
418
|
end
|
358
419
|
end
|
@@ -362,11 +423,11 @@ describe 'SemanticFormBuilder#inputs' do
|
|
362
423
|
describe 'and an object is given' do
|
363
424
|
it 'should render nested inputs' do
|
364
425
|
@bob.stub!(:column_for_attribute).and_return(mock('column', :type => :string, :limit => 255))
|
365
|
-
|
366
|
-
semantic_form_for(@new_post) do |builder|
|
426
|
+
form = semantic_form_for(@new_post) do |builder|
|
367
427
|
concat(builder.inputs(:login, :for => @bob))
|
368
428
|
end
|
369
429
|
|
430
|
+
output_buffer.concat(form) if Formtastic::Util.rails3?
|
370
431
|
output_buffer.should have_tag("form fieldset.inputs #post_author_login")
|
371
432
|
output_buffer.should_not have_tag("form fieldset.inputs #author_login")
|
372
433
|
end
|
@@ -374,10 +435,10 @@ describe 'SemanticFormBuilder#inputs' do
|
|
374
435
|
|
375
436
|
describe 'and no object is given' do
|
376
437
|
it 'should render nested inputs' do
|
377
|
-
semantic_form_for(:project, :url => 'http://test.host/') do |builder|
|
438
|
+
form = semantic_form_for(:project, :url => 'http://test.host/') do |builder|
|
378
439
|
concat(builder.inputs(:login, :for => @bob))
|
379
440
|
end
|
380
|
-
|
441
|
+
output_buffer.concat(form) if Formtastic::Util.rails3?
|
381
442
|
output_buffer.should have_tag("form fieldset.inputs #project_author_login")
|
382
443
|
output_buffer.should_not have_tag("form fieldset.inputs #project_login")
|
383
444
|
end
|
@@ -386,7 +447,7 @@ describe 'SemanticFormBuilder#inputs' do
|
|
386
447
|
|
387
448
|
describe 'with column names and an options hash as args' do
|
388
449
|
before do
|
389
|
-
semantic_form_for(@new_post) do |builder|
|
450
|
+
@form = semantic_form_for(@new_post) do |builder|
|
390
451
|
@legend_text_using_option = "Legendary Legend Text"
|
391
452
|
@legend_text_using_arg = "Legendary Legend Text 2"
|
392
453
|
concat(builder.inputs(:title, :body, :name => @legend_text_using_option, :id => "my-id"))
|
@@ -395,14 +456,17 @@ describe 'SemanticFormBuilder#inputs' do
|
|
395
456
|
end
|
396
457
|
|
397
458
|
it 'should render a form with a fieldset containing two list items' do
|
459
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
398
460
|
output_buffer.should have_tag('form > fieldset.inputs > ol > li', :count => 4)
|
399
461
|
end
|
400
462
|
|
401
463
|
it 'should pass the options down to the fieldset' do
|
464
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
402
465
|
output_buffer.should have_tag('form > fieldset#my-id.inputs')
|
403
466
|
end
|
404
467
|
|
405
468
|
it 'should use the special :name option as a text for the legend tag' do
|
469
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
406
470
|
output_buffer.should have_tag('form > fieldset#my-id.inputs > legend', /^#{@legend_text_using_option}$/)
|
407
471
|
output_buffer.should have_tag('form > fieldset#my-id-2.inputs > legend', /^#{@legend_text_using_arg}$/)
|
408
472
|
end
|