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,10 +6,10 @@ describe 'string 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(:title, :as => :string))
|
14
14
|
end
|
15
15
|
end
|
@@ -31,7 +31,7 @@ describe 'string input' do
|
|
31
31
|
|
32
32
|
describe "when no object is provided" do
|
33
33
|
before do
|
34
|
-
semantic_form_for(:project, :url => 'http://test.host/') do |builder|
|
34
|
+
@form = semantic_form_for(:project, :url => 'http://test.host/') do |builder|
|
35
35
|
concat(builder.input(:title, :as => :string))
|
36
36
|
end
|
37
37
|
end
|
@@ -6,10 +6,10 @@ describe 'text 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(: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
|
|
@@ -6,108 +6,164 @@ describe 'time input' do
|
|
6
6
|
include FormtasticSpecHelper
|
7
7
|
|
8
8
|
before do
|
9
|
-
@output_buffer =
|
9
|
+
@output_buffer = ''
|
10
10
|
mock_everything
|
11
|
+
end
|
12
|
+
|
13
|
+
describe "general" do
|
14
|
+
before do
|
15
|
+
::I18n.backend.reload!
|
16
|
+
output_buffer.replace ''
|
17
|
+
end
|
18
|
+
|
19
|
+
describe "without seconds" do
|
20
|
+
before do
|
21
|
+
@form = semantic_form_for(@new_post) do |builder|
|
22
|
+
concat(builder.input(:publish_at, :as => :time))
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
it_should_have_input_wrapper_with_class("time")
|
27
|
+
it_should_have_input_wrapper_with_id("post_publish_at_input")
|
28
|
+
it_should_have_a_nested_fieldset
|
29
|
+
it_should_apply_error_logic_for_input_type(:time)
|
30
|
+
|
31
|
+
it 'should have a legend and label with the label text inside the fieldset' do
|
32
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
33
|
+
output_buffer.should have_tag('form li.time fieldset legend.label label', /Publish at/)
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'should associate the legend label with the first select' do
|
37
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
38
|
+
output_buffer.should have_tag('form li.time fieldset legend.label label[@for="post_publish_at_1i"]')
|
39
|
+
end
|
11
40
|
|
12
|
-
|
13
|
-
|
41
|
+
it 'should have an ordered list of two items inside the fieldset' do
|
42
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
43
|
+
output_buffer.should have_tag('form li.time fieldset ol')
|
44
|
+
output_buffer.should have_tag('form li.time fieldset ol li', :count => 2)
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'should have five labels for hour and minute' do
|
48
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
49
|
+
output_buffer.should have_tag('form li.time fieldset ol li label', :count => 2)
|
50
|
+
output_buffer.should have_tag('form li.time fieldset ol li label', /hour/i)
|
51
|
+
output_buffer.should have_tag('form li.time fieldset ol li label', /minute/i)
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'should have two selects for hour and minute' do
|
55
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
56
|
+
output_buffer.should have_tag('form li.time fieldset ol li', :count => 2)
|
57
|
+
end
|
14
58
|
end
|
15
|
-
end
|
16
|
-
|
17
|
-
it_should_have_input_wrapper_with_class("time")
|
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(:time)
|
21
59
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
60
|
+
describe "with seconds" do
|
61
|
+
before do
|
62
|
+
@form = semantic_form_for(@new_post) do |builder|
|
63
|
+
concat(builder.input(:publish_at, :as => :time, :include_seconds => true))
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
it 'should have five labels for hour and minute' do
|
68
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
69
|
+
output_buffer.should have_tag('form li.time fieldset ol li label', :count => 3)
|
70
|
+
output_buffer.should have_tag('form li.time fieldset ol li label', /hour/i)
|
71
|
+
output_buffer.should have_tag('form li.time fieldset ol li label', /minute/i)
|
72
|
+
output_buffer.should have_tag('form li.time fieldset ol li label', /second/i)
|
73
|
+
end
|
29
74
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
75
|
+
it 'should have three selects for hour, minute and seconds' do
|
76
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
77
|
+
output_buffer.should have_tag('form li.time fieldset ol li', :count => 3)
|
78
|
+
end
|
34
79
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
80
|
+
it 'should generate a sanitized label and matching ids for attribute' do
|
81
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
82
|
+
4.upto(6) do |i|
|
83
|
+
output_buffer.should have_tag("form li fieldset ol li label[@for='post_publish_at_#{i}i']")
|
84
|
+
output_buffer.should have_tag("form li fieldset ol li #post_publish_at_#{i}i")
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
39
88
|
end
|
40
89
|
|
41
|
-
|
42
|
-
output_buffer.should have_tag('form li.time fieldset ol li', :count => 2)
|
43
|
-
end
|
44
|
-
|
45
|
-
describe ':default option' do
|
90
|
+
describe ':selected option' do
|
46
91
|
|
47
92
|
describe "when the object has a value" do
|
48
|
-
it "should select the object value (ignoring :
|
93
|
+
it "should select the object value (ignoring :selected)" do
|
49
94
|
output_buffer.replace ''
|
50
95
|
@new_post.stub!(:created_at => Time.mktime(2012, 11, 30, 21, 45))
|
51
|
-
|
52
|
-
|
96
|
+
with_deprecation_silenced do
|
97
|
+
@form = semantic_form_for(@new_post) do |builder|
|
98
|
+
concat(builder.input(:created_at, :as => :time, :selected => Time.mktime(1999, 12, 31, 22, 59)))
|
99
|
+
end
|
53
100
|
end
|
101
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
54
102
|
output_buffer.should have_tag("form li ol li select#post_created_at_4i option[@selected]", :count => 1)
|
55
103
|
output_buffer.should have_tag("form li ol li select#post_created_at_4i option[@value='21'][@selected]", :count => 1)
|
56
104
|
end
|
57
105
|
end
|
58
106
|
|
59
|
-
describe 'when the object has no value' do
|
60
|
-
it "should select the :
|
107
|
+
describe 'when the object has no value (nil)' do
|
108
|
+
it "should select the :selected if provided as a Time" do
|
61
109
|
output_buffer.replace ''
|
62
110
|
@new_post.stub!(:created_at => nil)
|
63
|
-
|
64
|
-
|
111
|
+
with_deprecation_silenced do
|
112
|
+
@form = semantic_form_for(@new_post) do |builder|
|
113
|
+
concat(builder.input(:created_at, :as => :time, :selected => Time.mktime(1999, 12, 31, 22, 59)))
|
114
|
+
end
|
65
115
|
end
|
116
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
66
117
|
output_buffer.should have_tag("form li ol li select#post_created_at_4i option[@selected]", :count => 1)
|
67
118
|
output_buffer.should have_tag("form li ol li select#post_created_at_4i option[@value='22'][@selected]", :count => 1)
|
68
119
|
end
|
69
120
|
|
70
|
-
it "should not select an option if the :
|
121
|
+
it "should not select an option if the :selected is provided as nil" do
|
71
122
|
output_buffer.replace ''
|
72
123
|
@new_post.stub!(:created_at => nil)
|
73
|
-
|
74
|
-
|
124
|
+
with_deprecation_silenced do
|
125
|
+
@form = semantic_form_for(@new_post) do |builder|
|
126
|
+
concat(builder.input(:created_at, :as => :time, :selected => nil))
|
127
|
+
end
|
75
128
|
end
|
129
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
76
130
|
output_buffer.should_not have_tag("form li ol li select#post_created_at_4i option[@selected]")
|
77
131
|
end
|
78
132
|
|
79
|
-
it "should select
|
133
|
+
it "should select nothing if a :selected is not provided" do
|
80
134
|
output_buffer.replace ''
|
81
135
|
@new_post.stub!(:created_at => nil)
|
82
|
-
semantic_form_for(@new_post) do |builder|
|
136
|
+
form = semantic_form_for(@new_post) do |builder|
|
83
137
|
concat(builder.input(:created_at, :as => :time))
|
84
138
|
end
|
85
|
-
output_buffer.
|
86
|
-
output_buffer.
|
139
|
+
output_buffer.concat(form) if Formtastic::Util.rails3?
|
140
|
+
output_buffer.should_not have_tag("form li ol li select option[@selected]")
|
87
141
|
end
|
88
142
|
end
|
89
143
|
|
90
144
|
end
|
91
|
-
|
145
|
+
|
92
146
|
describe ':labels option' do
|
93
|
-
fields = [:hour, :minute]
|
147
|
+
fields = [:hour, :minute, :second]
|
94
148
|
fields.each do |field|
|
95
149
|
it "should replace the #{field} label with the specified text if :labels[:#{field}] is set" do
|
96
150
|
output_buffer.replace ''
|
97
|
-
semantic_form_for(@new_post) do |builder|
|
98
|
-
concat(builder.input(:created_at, :as => :time, :labels => { field => "another #{field} label" }))
|
151
|
+
form = semantic_form_for(@new_post) do |builder|
|
152
|
+
concat(builder.input(:created_at, :as => :time, :include_seconds => true, :labels => { field => "another #{field} label" }))
|
99
153
|
end
|
154
|
+
output_buffer.concat(form) if Formtastic::Util.rails3?
|
100
155
|
output_buffer.should have_tag('form li.time fieldset ol li label', :count => fields.length)
|
101
156
|
fields.each do |f|
|
102
157
|
output_buffer.should have_tag('form li.time fieldset ol li label', f == field ? /another #{f} label/i : /#{f}/i)
|
103
158
|
end
|
104
159
|
end
|
105
|
-
|
160
|
+
|
106
161
|
it "should not display the label for the #{field} field when :labels[:#{field}] is blank" do
|
107
162
|
output_buffer.replace ''
|
108
|
-
semantic_form_for(@new_post) do |builder|
|
109
|
-
concat(builder.input(:created_at, :as => :time, :labels => { field => "" }))
|
163
|
+
form = semantic_form_for(@new_post) do |builder|
|
164
|
+
concat(builder.input(:created_at, :as => :time, :include_seconds => true, :labels => { field => "" }))
|
110
165
|
end
|
166
|
+
output_buffer.concat(form) if Formtastic::Util.rails3?
|
111
167
|
output_buffer.should have_tag('form li.time fieldset ol li label', :count => fields.length-1)
|
112
168
|
fields.each do |f|
|
113
169
|
output_buffer.should have_tag('form li.time fieldset ol li label', /#{f}/i) unless field == f
|
@@ -115,14 +171,14 @@ describe 'time input' do
|
|
115
171
|
end
|
116
172
|
end
|
117
173
|
end
|
118
|
-
|
174
|
+
|
119
175
|
it 'should warn about :selected deprecation' do
|
120
176
|
with_deprecation_silenced do
|
121
|
-
::ActiveSupport::Deprecation.should_receive(:warn)
|
177
|
+
::ActiveSupport::Deprecation.should_receive(:warn).any_number_of_times
|
122
178
|
semantic_form_for(@new_post) do |builder|
|
123
179
|
concat(builder.input(:created_at, :as => :time, :selected => Time.mktime(1999)))
|
124
180
|
end
|
125
181
|
end
|
126
182
|
end
|
127
|
-
|
183
|
+
|
128
184
|
end
|
@@ -6,10 +6,10 @@ describe 'time_zone 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(: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]\"]")
|
@@ -59,7 +64,7 @@ describe 'time_zone input' do
|
|
59
64
|
|
60
65
|
describe 'when :selected is set' do
|
61
66
|
before do
|
62
|
-
@output_buffer =
|
67
|
+
@output_buffer = ''
|
63
68
|
end
|
64
69
|
|
65
70
|
# Note: Not possible to override default selected value for time_zone input
|
@@ -85,12 +90,15 @@ describe 'time_zone input' do
|
|
85
90
|
# @new_post.stub!(:time_zone).and_return('Stockholm')
|
86
91
|
@new_post.stub!(:time_zone).and_return(nil)
|
87
92
|
|
88
|
-
|
89
|
-
|
93
|
+
with_deprecation_silenced do
|
94
|
+
@form = semantic_form_for(@new_post) do |builder|
|
95
|
+
concat(builder.input(:time_zone, :as => :time_zone, :selected => 'Melbourne'))
|
96
|
+
end
|
90
97
|
end
|
91
98
|
end
|
92
99
|
|
93
100
|
it 'should have a selected item; the specified one' do
|
101
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
94
102
|
output_buffer.should have_tag("form li select option[@selected='selected']", :count => 1)
|
95
103
|
output_buffer.should have_tag("form li select option[@selected='selected']", /Melbourne/i)
|
96
104
|
output_buffer.should have_tag("form li select option[@selected='selected'][@value='Melbourne']")
|
data/spec/inputs_spec.rb
CHANGED
@@ -6,7 +6,7 @@ describe 'SemanticFormBuilder#inputs' 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
|
|
@@ -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,12 +70,14 @@ 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|
|
68
|
-
builder.inputs :for => [:author, @bob] do |bob_builder|
|
73
|
+
form = semantic_form_for(@new_post) do |builder|
|
74
|
+
inputs = builder.inputs :for => [:author, @bob] do |bob_builder|
|
69
75
|
concat(bob_builder.input(:login))
|
70
76
|
end
|
77
|
+
concat(inputs)
|
71
78
|
end
|
72
79
|
|
80
|
+
output_buffer.concat(form) if Formtastic::Util.rails3?
|
73
81
|
output_buffer.should have_tag("form fieldset.inputs #post_author_attributes_login")
|
74
82
|
output_buffer.should_not have_tag("form fieldset.inputs #author_login")
|
75
83
|
|
@@ -78,11 +86,13 @@ describe 'SemanticFormBuilder#inputs' do
|
|
78
86
|
describe "as a symbol representing the association name" do
|
79
87
|
|
80
88
|
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|
|
89
|
+
form = semantic_form_for(@new_post) do |post|
|
90
|
+
inputs = post.inputs :for => :author do |author|
|
83
91
|
concat(author.input(:login))
|
84
92
|
end
|
93
|
+
concat(inputs)
|
85
94
|
end
|
95
|
+
output_buffer.concat(form) if Formtastic::Util.rails3?
|
86
96
|
output_buffer.should have_tag("form input[@name='post[author_attributes][login]']")
|
87
97
|
end
|
88
98
|
|
@@ -91,11 +101,13 @@ describe 'SemanticFormBuilder#inputs' do
|
|
91
101
|
describe 'as an array containing the a symbole for the association name and the associated object' do
|
92
102
|
|
93
103
|
it 'should nest the inputs with an _attributes suffix on the association name' do
|
94
|
-
semantic_form_for(@new_post) do |post|
|
95
|
-
post.inputs :for => [:author, @new_post.author] do |author|
|
104
|
+
form = semantic_form_for(@new_post) do |post|
|
105
|
+
inputs = post.inputs :for => [:author, @new_post.author] do |author|
|
96
106
|
concat(author.input(:login))
|
97
107
|
end
|
108
|
+
concat(inputs)
|
98
109
|
end
|
110
|
+
output_buffer.concat(form) if Formtastic::Util.rails3?
|
99
111
|
output_buffer.should have_tag("form input[@name='post[author_attributes][login]']")
|
100
112
|
end
|
101
113
|
|
@@ -104,11 +116,13 @@ describe 'SemanticFormBuilder#inputs' do
|
|
104
116
|
describe 'as an associated object' do
|
105
117
|
|
106
118
|
it 'should not nest the inputs with an _attributes suffix' do
|
107
|
-
semantic_form_for(@new_post) do |post|
|
108
|
-
post.inputs :for => @new_post.author do |author|
|
119
|
+
form = semantic_form_for(@new_post) do |post|
|
120
|
+
inputs = post.inputs :for => @new_post.author do |author|
|
109
121
|
concat(author.input(:login))
|
110
122
|
end
|
123
|
+
concat(inputs)
|
111
124
|
end
|
125
|
+
output_buffer.concat(form) if Formtastic::Util.rails3?
|
112
126
|
output_buffer.should have_tag("form input[@name='post[author][login]']")
|
113
127
|
end
|
114
128
|
|
@@ -128,44 +142,52 @@ describe 'SemanticFormBuilder#inputs' do
|
|
128
142
|
it 'should pass options down to semantic_fields_for' do
|
129
143
|
@bob.stub!(:column_for_attribute).and_return(mock('column', :type => :string, :limit => 255))
|
130
144
|
|
131
|
-
semantic_form_for(@new_post) do |builder|
|
132
|
-
builder.inputs :for => [:author, @bob], :for_options => { :index => 10 } do |bob_builder|
|
145
|
+
form = semantic_form_for(@new_post) do |builder|
|
146
|
+
inputs = builder.inputs :for => [:author, @bob], :for_options => { :index => 10 } do |bob_builder|
|
133
147
|
concat(bob_builder.input(:login))
|
134
148
|
end
|
149
|
+
concat(inputs)
|
135
150
|
end
|
136
151
|
|
152
|
+
output_buffer.concat(form) if Formtastic::Util.rails3?
|
137
153
|
output_buffer.should have_tag('form fieldset ol li #post_author_attributes_10_login')
|
138
154
|
end
|
139
155
|
|
140
156
|
it 'should not add builder as a fieldset attribute tag' do
|
141
|
-
semantic_form_for(@new_post) do |builder|
|
142
|
-
builder.inputs :for => [:author, @bob], :for_options => { :index => 10 } do |bob_builder|
|
157
|
+
form = semantic_form_for(@new_post) do |builder|
|
158
|
+
inputs = builder.inputs :for => [:author, @bob], :for_options => { :index => 10 } do |bob_builder|
|
143
159
|
concat('input')
|
144
160
|
end
|
161
|
+
concat(inputs)
|
145
162
|
end
|
146
163
|
|
164
|
+
output_buffer.concat(form) if Formtastic::Util.rails3?
|
147
165
|
output_buffer.should_not have_tag('fieldset[@builder="Formtastic::SemanticFormHelper"]')
|
148
166
|
end
|
149
167
|
|
150
168
|
it 'should send parent_builder as an option to allow child index interpolation' do
|
151
|
-
semantic_form_for(@new_post) do |builder|
|
169
|
+
form = semantic_form_for(@new_post) do |builder|
|
152
170
|
builder.instance_variable_set('@nested_child_index', 0)
|
153
|
-
builder.inputs :for => [:author, @bob], :name => 'Author #%i' do |bob_builder|
|
171
|
+
inputs = builder.inputs :for => [:author, @bob], :name => 'Author #%i' do |bob_builder|
|
154
172
|
concat('input')
|
155
173
|
end
|
174
|
+
concat(inputs)
|
156
175
|
end
|
157
176
|
|
177
|
+
output_buffer.concat(form) if Formtastic::Util.rails3?
|
158
178
|
output_buffer.should have_tag('fieldset legend', 'Author #1')
|
159
179
|
end
|
160
180
|
|
161
181
|
it 'should also provide child index interpolation when nested child index is a hash' do
|
162
|
-
semantic_form_for(@new_post) do |builder|
|
182
|
+
form = semantic_form_for(@new_post) do |builder|
|
163
183
|
builder.instance_variable_set('@nested_child_index', :author => 10)
|
164
|
-
builder.inputs :for => [:author, @bob], :name => 'Author #%i' do |bob_builder|
|
184
|
+
inputs = builder.inputs :for => [:author, @bob], :name => 'Author #%i' do |bob_builder|
|
165
185
|
concat('input')
|
166
186
|
end
|
187
|
+
concat(inputs)
|
167
188
|
end
|
168
189
|
|
190
|
+
output_buffer.concat(form) if Formtastic::Util.rails3?
|
169
191
|
output_buffer.should have_tag('fieldset legend', 'Author #11')
|
170
192
|
end
|
171
193
|
end
|
@@ -177,19 +199,24 @@ describe 'SemanticFormBuilder#inputs' do
|
|
177
199
|
@legend_text_using_name = "Advanced options 2"
|
178
200
|
@legend_text_using_title = "Advanced options 3"
|
179
201
|
@nested_forms_legend_text = "This is a nested form title"
|
180
|
-
semantic_form_for(@new_post) do |builder|
|
181
|
-
builder.inputs @legend_text do
|
202
|
+
@form = semantic_form_for(@new_post) do |builder|
|
203
|
+
inputs = builder.inputs @legend_text do
|
182
204
|
end
|
183
|
-
|
205
|
+
concat(inputs)
|
206
|
+
inputs = builder.inputs :name => @legend_text_using_name do
|
184
207
|
end
|
185
|
-
|
208
|
+
concat(inputs)
|
209
|
+
inputs = builder.inputs :title => @legend_text_using_title do
|
186
210
|
end
|
187
|
-
|
211
|
+
concat(inputs)
|
212
|
+
inputs = builder.inputs @nested_forms_legend_text, :for => :authors do |nf|
|
188
213
|
end
|
214
|
+
concat(inputs)
|
189
215
|
end
|
190
216
|
end
|
191
217
|
|
192
218
|
it 'should render a fieldset with a legend inside the form' do
|
219
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
193
220
|
output_buffer.should have_tag("form fieldset legend", /^#{@legend_text}$/)
|
194
221
|
output_buffer.should have_tag("form fieldset legend", /^#{@legend_text_using_name}$/)
|
195
222
|
output_buffer.should have_tag("form fieldset legend", /^#{@legend_text_using_title}$/)
|
@@ -213,19 +240,24 @@ describe 'SemanticFormBuilder#inputs' do
|
|
213
240
|
}
|
214
241
|
}
|
215
242
|
}
|
216
|
-
semantic_form_for(@new_post) do |builder|
|
217
|
-
builder.inputs :advanced_options do
|
243
|
+
@form = semantic_form_for(@new_post) do |builder|
|
244
|
+
inputs = builder.inputs :advanced_options do
|
218
245
|
end
|
219
|
-
|
246
|
+
concat(inputs)
|
247
|
+
inputs =builder.inputs :name => :advanced_options_using_name do
|
220
248
|
end
|
221
|
-
|
249
|
+
concat(inputs)
|
250
|
+
inputs = builder.inputs :title => :advanced_options_using_title do
|
222
251
|
end
|
223
|
-
|
252
|
+
concat(inputs)
|
253
|
+
inputs = builder.inputs :nested_forms_title, :for => :authors do |nf|
|
224
254
|
end
|
255
|
+
concat(inputs)
|
225
256
|
end
|
226
257
|
end
|
227
258
|
|
228
259
|
it 'should render a fieldset with a localized legend inside the form' do
|
260
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
229
261
|
output_buffer.should have_tag("form fieldset legend", /^#{@localized_legend_text}$/)
|
230
262
|
output_buffer.should have_tag("form fieldset legend", /^#{@localized_legend_text_using_name}$/)
|
231
263
|
output_buffer.should have_tag("form fieldset legend", /^#{@localized_legend_text_using_title}$/)
|
@@ -239,13 +271,14 @@ describe 'SemanticFormBuilder#inputs' do
|
|
239
271
|
@id_option = 'advanced'
|
240
272
|
@class_option = 'wide'
|
241
273
|
|
242
|
-
semantic_form_for(@new_post) do |builder|
|
274
|
+
@form = semantic_form_for(@new_post) do |builder|
|
243
275
|
builder.inputs :id => @id_option, :class => @class_option do
|
244
276
|
end
|
245
277
|
end
|
246
278
|
end
|
247
279
|
|
248
280
|
it 'should pass the options into the fieldset tag as attributes' do
|
281
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
249
282
|
output_buffer.should have_tag("form fieldset##{@id_option}")
|
250
283
|
output_buffer.should have_tag("form fieldset.#{@class_option}")
|
251
284
|
end
|
@@ -272,46 +305,55 @@ describe 'SemanticFormBuilder#inputs' do
|
|
272
305
|
|
273
306
|
describe 'with no args' do
|
274
307
|
before do
|
275
|
-
semantic_form_for(@new_post) do |builder|
|
308
|
+
@form = semantic_form_for(@new_post) do |builder|
|
276
309
|
concat(builder.inputs)
|
277
310
|
end
|
278
311
|
end
|
279
312
|
|
280
313
|
it 'should render a form' do
|
314
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
281
315
|
output_buffer.should have_tag('form')
|
282
316
|
end
|
283
317
|
|
284
318
|
it 'should render a fieldset inside the form' do
|
319
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
285
320
|
output_buffer.should have_tag('form > fieldset.inputs')
|
286
321
|
end
|
287
322
|
|
288
323
|
it 'should not render a legend in the fieldset' do
|
324
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
289
325
|
output_buffer.should_not have_tag('form > fieldset.inputs > legend')
|
290
326
|
end
|
291
327
|
|
292
328
|
it 'should render an ol in the fieldset' do
|
329
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
293
330
|
output_buffer.should have_tag('form > fieldset.inputs > ol')
|
294
331
|
end
|
295
332
|
|
296
333
|
it 'should render a list item in the ol for each column and reflection' do
|
297
334
|
# Remove the :has_many macro and :created_at column
|
298
335
|
count = ::Post.content_columns.size + ::Post.reflections.size - 2
|
336
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
299
337
|
output_buffer.should have_tag('form > fieldset.inputs > ol > li', :count => count)
|
300
338
|
end
|
301
339
|
|
302
340
|
it 'should render a string list item for title' do
|
341
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
303
342
|
output_buffer.should have_tag('form > fieldset.inputs > ol > li.string')
|
304
343
|
end
|
305
344
|
|
306
345
|
it 'should render a text list item for body' do
|
346
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
307
347
|
output_buffer.should have_tag('form > fieldset.inputs > ol > li.text')
|
308
348
|
end
|
309
349
|
|
310
350
|
it 'should render a select list item for author_id' do
|
351
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
311
352
|
output_buffer.should have_tag('form > fieldset.inputs > ol > li.select', :count => 1)
|
312
353
|
end
|
313
354
|
|
314
355
|
it 'should not render timestamps inputs by default' do
|
356
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
315
357
|
output_buffer.should_not have_tag('form > fieldset.inputs > ol > li.datetime')
|
316
358
|
end
|
317
359
|
end
|
@@ -319,10 +361,11 @@ describe 'SemanticFormBuilder#inputs' do
|
|
319
361
|
describe 'with column names as args' do
|
320
362
|
describe 'and an object is given' do
|
321
363
|
it 'should render a form with a fieldset containing two list items' do
|
322
|
-
semantic_form_for(@new_post) do |builder|
|
364
|
+
form = semantic_form_for(@new_post) do |builder|
|
323
365
|
concat(builder.inputs(:title, :body))
|
324
366
|
end
|
325
367
|
|
368
|
+
output_buffer.concat(form) if Formtastic::Util.rails3?
|
326
369
|
output_buffer.should have_tag('form > fieldset.inputs > ol > li', :count => 2)
|
327
370
|
output_buffer.should have_tag('form > fieldset.inputs > ol > li.string')
|
328
371
|
output_buffer.should have_tag('form > fieldset.inputs > ol > li.text')
|
@@ -331,10 +374,11 @@ describe 'SemanticFormBuilder#inputs' do
|
|
331
374
|
|
332
375
|
describe 'and no object is given' do
|
333
376
|
it 'should render a form with a fieldset containing two list items' do
|
334
|
-
semantic_form_for(:project, :url => 'http://test.host') do |builder|
|
377
|
+
form = semantic_form_for(:project, :url => 'http://test.host') do |builder|
|
335
378
|
concat(builder.inputs(:title, :body))
|
336
379
|
end
|
337
380
|
|
381
|
+
output_buffer.concat(form) if Formtastic::Util.rails3?
|
338
382
|
output_buffer.should have_tag('form > fieldset.inputs > ol > li.string', :count => 2)
|
339
383
|
end
|
340
384
|
end
|
@@ -344,11 +388,11 @@ describe 'SemanticFormBuilder#inputs' do
|
|
344
388
|
describe 'and an object is given' do
|
345
389
|
it 'should render nested inputs' do
|
346
390
|
@bob.stub!(:column_for_attribute).and_return(mock('column', :type => :string, :limit => 255))
|
347
|
-
|
348
|
-
semantic_form_for(@new_post) do |builder|
|
391
|
+
form = semantic_form_for(@new_post) do |builder|
|
349
392
|
concat(builder.inputs(:login, :for => @bob))
|
350
393
|
end
|
351
394
|
|
395
|
+
output_buffer.concat(form) if Formtastic::Util.rails3?
|
352
396
|
output_buffer.should have_tag("form fieldset.inputs #post_author_login")
|
353
397
|
output_buffer.should_not have_tag("form fieldset.inputs #author_login")
|
354
398
|
end
|
@@ -356,10 +400,10 @@ describe 'SemanticFormBuilder#inputs' do
|
|
356
400
|
|
357
401
|
describe 'and no object is given' do
|
358
402
|
it 'should render nested inputs' do
|
359
|
-
semantic_form_for(:project, :url => 'http://test.host/') do |builder|
|
403
|
+
form = semantic_form_for(:project, :url => 'http://test.host/') do |builder|
|
360
404
|
concat(builder.inputs(:login, :for => @bob))
|
361
405
|
end
|
362
|
-
|
406
|
+
output_buffer.concat(form) if Formtastic::Util.rails3?
|
363
407
|
output_buffer.should have_tag("form fieldset.inputs #project_author_login")
|
364
408
|
output_buffer.should_not have_tag("form fieldset.inputs #project_login")
|
365
409
|
end
|
@@ -368,7 +412,7 @@ describe 'SemanticFormBuilder#inputs' do
|
|
368
412
|
|
369
413
|
describe 'with column names and an options hash as args' do
|
370
414
|
before do
|
371
|
-
semantic_form_for(@new_post) do |builder|
|
415
|
+
@form = semantic_form_for(@new_post) do |builder|
|
372
416
|
@legend_text_using_option = "Legendary Legend Text"
|
373
417
|
@legend_text_using_arg = "Legendary Legend Text 2"
|
374
418
|
concat(builder.inputs(:title, :body, :name => @legend_text_using_option, :id => "my-id"))
|
@@ -377,19 +421,21 @@ describe 'SemanticFormBuilder#inputs' do
|
|
377
421
|
end
|
378
422
|
|
379
423
|
it 'should render a form with a fieldset containing two list items' do
|
424
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
380
425
|
output_buffer.should have_tag('form > fieldset.inputs > ol > li', :count => 4)
|
381
426
|
end
|
382
427
|
|
383
428
|
it 'should pass the options down to the fieldset' do
|
429
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
384
430
|
output_buffer.should have_tag('form > fieldset#my-id.inputs')
|
385
431
|
end
|
386
432
|
|
387
433
|
it 'should use the special :name option as a text for the legend tag' do
|
434
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
388
435
|
output_buffer.should have_tag('form > fieldset#my-id.inputs > legend', /^#{@legend_text_using_option}$/)
|
389
436
|
output_buffer.should have_tag('form > fieldset#my-id-2.inputs > legend', /^#{@legend_text_using_arg}$/)
|
390
437
|
end
|
391
438
|
end
|
392
439
|
|
393
440
|
end
|
394
|
-
|
395
441
|
end
|