techthumb-formtastic 1.rails3.sha
Sign up to get free protection for your applications and to get access to all the features.
- data/MIT-LICENSE +20 -0
- data/README.textile +584 -0
- data/Rakefile +127 -0
- data/generators/form/USAGE +16 -0
- data/generators/form/form_generator.rb +120 -0
- data/generators/form/templates/view__form.html.erb +5 -0
- data/generators/form/templates/view__form.html.haml +4 -0
- data/generators/formtastic/formtastic_generator.rb +24 -0
- data/generators/formtastic/templates/formtastic.css +131 -0
- data/generators/formtastic/templates/formtastic.rb +54 -0
- data/generators/formtastic/templates/formtastic_changes.css +14 -0
- data/generators/formtastic_stylesheets/formtastic_stylesheets_generator.rb +16 -0
- data/init.rb +5 -0
- data/lib/formtastic/i18n.rb +35 -0
- data/lib/formtastic/layout_helper.rb +10 -0
- data/lib/formtastic/railtie.rb +12 -0
- data/lib/formtastic/util.rb +36 -0
- data/lib/formtastic.rb +1870 -0
- data/lib/generators/formtastic/form/form_generator.rb +86 -0
- data/lib/generators/formtastic/install/install_generator.rb +24 -0
- data/lib/locale/en.yml +8 -0
- data/rails/init.rb +2 -0
- data/spec/buttons_spec.rb +166 -0
- data/spec/commit_button_spec.rb +401 -0
- data/spec/custom_builder_spec.rb +98 -0
- data/spec/defaults_spec.rb +20 -0
- data/spec/error_proc_spec.rb +27 -0
- data/spec/errors_spec.rb +105 -0
- data/spec/form_helper_spec.rb +142 -0
- data/spec/helpers/layout_helper_spec.rb +21 -0
- data/spec/i18n_spec.rb +152 -0
- data/spec/include_blank_spec.rb +74 -0
- data/spec/input_spec.rb +786 -0
- data/spec/inputs/boolean_input_spec.rb +104 -0
- data/spec/inputs/check_boxes_input_spec.rb +426 -0
- data/spec/inputs/country_input_spec.rb +118 -0
- data/spec/inputs/date_input_spec.rb +168 -0
- data/spec/inputs/datetime_input_spec.rb +310 -0
- data/spec/inputs/file_input_spec.rb +34 -0
- data/spec/inputs/hidden_input_spec.rb +78 -0
- data/spec/inputs/numeric_input_spec.rb +44 -0
- data/spec/inputs/password_input_spec.rb +46 -0
- data/spec/inputs/radio_input_spec.rb +243 -0
- data/spec/inputs/select_input_spec.rb +546 -0
- data/spec/inputs/string_input_spec.rb +64 -0
- data/spec/inputs/text_input_spec.rb +34 -0
- data/spec/inputs/time_input_spec.rb +206 -0
- data/spec/inputs/time_zone_input_spec.rb +110 -0
- data/spec/inputs_spec.rb +476 -0
- data/spec/label_spec.rb +89 -0
- data/spec/semantic_errors_spec.rb +98 -0
- data/spec/semantic_fields_for_spec.rb +45 -0
- data/spec/spec.opts +2 -0
- data/spec/spec_helper.rb +289 -0
- data/spec/support/custom_macros.rb +494 -0
- data/spec/support/output_buffer.rb +4 -0
- data/spec/support/test_environment.rb +45 -0
- metadata +235 -0
@@ -0,0 +1,168 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe 'date input' do
|
5
|
+
|
6
|
+
include FormtasticSpecHelper
|
7
|
+
|
8
|
+
before do
|
9
|
+
@output_buffer = ''
|
10
|
+
mock_everything
|
11
|
+
end
|
12
|
+
|
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
|
21
|
+
|
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
|
58
|
+
end
|
59
|
+
|
60
|
+
describe ':selected option' do
|
61
|
+
|
62
|
+
describe "when the object has a value" do
|
63
|
+
it "should select the object value (ignoring :selected)" do
|
64
|
+
output_buffer.replace ''
|
65
|
+
@new_post.stub!(:created_at => Time.mktime(2012))
|
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
|
70
|
+
end
|
71
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
72
|
+
output_buffer.should have_tag("form li ol li select#post_created_at_1i option[@selected]", :count => 1)
|
73
|
+
output_buffer.should have_tag("form li ol li select#post_created_at_1i option[@value='2012'][@selected]", :count => 1)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
describe 'when the object has no value (nil)' do
|
78
|
+
it "should select the :selected if provided as a Date" do
|
79
|
+
output_buffer.replace ''
|
80
|
+
@new_post.stub!(:created_at => nil)
|
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
|
85
|
+
end
|
86
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
87
|
+
output_buffer.should have_tag("form li ol li select#post_created_at_1i option[@selected]", :count => 1)
|
88
|
+
output_buffer.should have_tag("form li ol li select#post_created_at_1i option[@value='1999'][@selected]", :count => 1)
|
89
|
+
end
|
90
|
+
|
91
|
+
it "should select the :selected if provided as a Time" do
|
92
|
+
output_buffer.replace ''
|
93
|
+
@new_post.stub!(:created_at => nil)
|
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
|
98
|
+
end
|
99
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
100
|
+
output_buffer.should have_tag("form li ol li select#post_created_at_1i option[@selected]", :count => 1)
|
101
|
+
output_buffer.should have_tag("form li ol li select#post_created_at_1i option[@value='1999'][@selected]", :count => 1)
|
102
|
+
end
|
103
|
+
|
104
|
+
it "should not select an option if the :selected is provided as nil" do
|
105
|
+
output_buffer.replace ''
|
106
|
+
@new_post.stub!(:created_at => nil)
|
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
|
111
|
+
end
|
112
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
113
|
+
output_buffer.should_not have_tag("form li ol li select#post_created_at_1i option[@selected]")
|
114
|
+
end
|
115
|
+
|
116
|
+
it "should select nothing if a :selected is not provided" do
|
117
|
+
output_buffer.replace ''
|
118
|
+
@new_post.stub!(:created_at => nil)
|
119
|
+
form = semantic_form_for(@new_post) do |builder|
|
120
|
+
concat(builder.input(:created_at, :as => :date))
|
121
|
+
end
|
122
|
+
output_buffer.concat(form) if Formtastic::Util.rails3?
|
123
|
+
output_buffer.should_not have_tag("form li ol li select option[@selected]")
|
124
|
+
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
end
|
129
|
+
|
130
|
+
describe ':labels option' do
|
131
|
+
fields = [:year, :month, :day]
|
132
|
+
fields.each do |field|
|
133
|
+
it "should replace the #{field} label with the specified text if :labels[:#{field}] is set" do
|
134
|
+
output_buffer.replace ''
|
135
|
+
form = semantic_form_for(@new_post) do |builder|
|
136
|
+
concat(builder.input(:created_at, :as => :date, :labels => { field => "another #{field} label" }))
|
137
|
+
end
|
138
|
+
output_buffer.concat(form) if Formtastic::Util.rails3?
|
139
|
+
output_buffer.should have_tag('form li.date fieldset ol li label', :count => fields.length)
|
140
|
+
fields.each do |f|
|
141
|
+
output_buffer.should have_tag('form li.date fieldset ol li label', f == field ? /another #{f} label/i : /#{f}/i)
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
it "should not display the label for the #{field} field when :labels[:#{field}] is blank" do
|
146
|
+
output_buffer.replace ''
|
147
|
+
form = semantic_form_for(@new_post) do |builder|
|
148
|
+
concat(builder.input(:created_at, :as => :date, :labels => { field => "" }))
|
149
|
+
end
|
150
|
+
output_buffer.concat(form) if Formtastic::Util.rails3?
|
151
|
+
output_buffer.should have_tag('form li.date fieldset ol li label', :count => fields.length-1)
|
152
|
+
fields.each do |f|
|
153
|
+
output_buffer.should have_tag('form li.date fieldset ol li label', /#{f}/i) unless field == f
|
154
|
+
end
|
155
|
+
end
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
it 'should warn about :selected deprecation' do
|
160
|
+
with_deprecation_silenced do
|
161
|
+
::ActiveSupport::Deprecation.should_receive(:warn).any_number_of_times
|
162
|
+
semantic_form_for(@new_post) do |builder|
|
163
|
+
concat(builder.input(:created_at, :as => :date, :selected => Date.new(1999)))
|
164
|
+
end
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
end
|
@@ -0,0 +1,310 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe 'datetime input' do
|
5
|
+
|
6
|
+
include FormtasticSpecHelper
|
7
|
+
|
8
|
+
before do
|
9
|
+
@output_buffer = ''
|
10
|
+
mock_everything
|
11
|
+
|
12
|
+
@new_post.should_receive(:publish_at=).any_number_of_times
|
13
|
+
@new_post.should_receive(:created_at=).any_number_of_times
|
14
|
+
@bob.should_receive(:created_at=).any_number_of_times
|
15
|
+
@new_post.should_receive(:title=).any_number_of_times # Macro stuff forces this.
|
16
|
+
end
|
17
|
+
|
18
|
+
describe "general" do
|
19
|
+
|
20
|
+
before do
|
21
|
+
output_buffer.replace ''
|
22
|
+
@form = semantic_form_for(@new_post) do |builder|
|
23
|
+
concat(builder.input(:publish_at, :as => :datetime))
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
it_should_have_input_wrapper_with_class("datetime")
|
28
|
+
it_should_have_input_wrapper_with_id("post_publish_at_input")
|
29
|
+
it_should_have_a_nested_fieldset
|
30
|
+
it_should_apply_error_logic_for_input_type(:datetime)
|
31
|
+
|
32
|
+
it 'should have a legend and label with the label text inside the fieldset' do
|
33
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
34
|
+
output_buffer.should have_tag('form li.datetime fieldset legend.label label', /Publish at/)
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'should associate the legend label with the first select' do
|
38
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
39
|
+
output_buffer.should have_tag('form li.datetime fieldset legend.label label[@for="post_publish_at_1i"]')
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'should have an ordered list of five items inside the fieldset' do
|
43
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
44
|
+
output_buffer.should have_tag('form li.datetime fieldset ol')
|
45
|
+
output_buffer.should have_tag('form li.datetime fieldset ol li', :count => 5)
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'should have five labels for year, month, day, hour and minute' do
|
49
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
50
|
+
output_buffer.should have_tag('form li.datetime fieldset ol li label', :count => 5)
|
51
|
+
output_buffer.should have_tag('form li.datetime fieldset ol li label', /year/i)
|
52
|
+
output_buffer.should have_tag('form li.datetime fieldset ol li label', /month/i)
|
53
|
+
output_buffer.should have_tag('form li.datetime fieldset ol li label', /day/i)
|
54
|
+
output_buffer.should have_tag('form li.datetime fieldset ol li label', /hour/i)
|
55
|
+
output_buffer.should have_tag('form li.datetime fieldset ol li label', /minute/i)
|
56
|
+
end
|
57
|
+
|
58
|
+
it 'should have five selects for year, month, day, hour and minute' do
|
59
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
60
|
+
output_buffer.should have_tag('form li.datetime fieldset ol li select', :count => 5)
|
61
|
+
end
|
62
|
+
|
63
|
+
it 'should generate a sanitized label and matching ids for attribute' do
|
64
|
+
form = semantic_form_for(@new_post) do |builder|
|
65
|
+
fields = builder.semantic_fields_for(@bob, :index => 10) do |bob_builder|
|
66
|
+
concat(bob_builder.input(:created_at, :as => :datetime))
|
67
|
+
end
|
68
|
+
concat(fields)
|
69
|
+
end
|
70
|
+
output_buffer.concat(form) if Formtastic::Util.rails3?
|
71
|
+
|
72
|
+
1.upto(5) do |i|
|
73
|
+
output_buffer.should have_tag("form li fieldset ol li label[@for='post_author_10_created_at_#{i}i']")
|
74
|
+
output_buffer.should have_tag("form li fieldset ol li #post_author_10_created_at_#{i}i")
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
describe 'when :discard_input => true is set' do
|
80
|
+
it 'should use default attribute value when it is not nil' do
|
81
|
+
@new_post.stub!(:publish_at).and_return(Date.new(2007,12,27))
|
82
|
+
form = semantic_form_for(@new_post) do |builder|
|
83
|
+
concat(builder.input(:publish_at, :as => :datetime, :discard_day => true))
|
84
|
+
end
|
85
|
+
|
86
|
+
output_buffer.concat(form) if Formtastic::Util.rails3?
|
87
|
+
output_buffer.should have_tag("form li input[@type='hidden'][@value='27']")
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
describe 'inputs order' do
|
92
|
+
it 'should have a default' do
|
93
|
+
output_buffer.replace ''
|
94
|
+
semantic_form_for(@new_post) do |builder|
|
95
|
+
self.should_receive(:select_year).once.ordered.and_return('')
|
96
|
+
self.should_receive(:select_month).once.ordered.and_return('')
|
97
|
+
self.should_receive(:select_day).once.ordered.and_return('')
|
98
|
+
builder.input(:publish_at, :as => :datetime)
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
it 'should be specified with :order option' do
|
103
|
+
::I18n.backend.store_translations 'en', :date => { :order => [:month, :year, :day] }
|
104
|
+
output_buffer.replace ''
|
105
|
+
semantic_form_for(@new_post) do |builder|
|
106
|
+
self.should_receive(:select_month).once.ordered.and_return('')
|
107
|
+
self.should_receive(:select_year).once.ordered.and_return('')
|
108
|
+
self.should_receive(:select_day).once.ordered.and_return('')
|
109
|
+
builder.input(:publish_at, :as => :datetime)
|
110
|
+
::I18n.backend.store_translations 'en', :date => nil
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
it 'should be changed through I18n' do
|
115
|
+
output_buffer.replace ''
|
116
|
+
semantic_form_for(@new_post) do |builder|
|
117
|
+
self.should_receive(:select_day).once.ordered.and_return('')
|
118
|
+
self.should_receive(:select_month).once.ordered.and_return('')
|
119
|
+
self.should_receive(:select_year).once.ordered.and_return('')
|
120
|
+
builder.input(:publish_at, :as => :datetime, :order => [:day, :month, :year])
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
describe 'when the locale changes the label text' do
|
126
|
+
before do
|
127
|
+
::I18n.backend.store_translations 'en', :datetime => {:prompts => {
|
128
|
+
:year => 'The Year', :month => 'The Month', :day => 'The Day',
|
129
|
+
:hour => 'The Hour', :minute => 'The Minute'
|
130
|
+
}}
|
131
|
+
output_buffer.replace ''
|
132
|
+
@form = semantic_form_for(@new_post) do |builder|
|
133
|
+
concat(builder.input(:publish_at, :as => :datetime))
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
after do
|
138
|
+
::I18n.backend.store_translations 'en', :formtastic => {
|
139
|
+
:year => nil, :month => nil, :day => nil,
|
140
|
+
:hour => nil, :minute => nil
|
141
|
+
}
|
142
|
+
end
|
143
|
+
|
144
|
+
it 'should have translated labels for year, month, day, hour and minute' do
|
145
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
146
|
+
output_buffer.should have_tag('form li.datetime fieldset ol li label', /The Year/)
|
147
|
+
output_buffer.should have_tag('form li.datetime fieldset ol li label', /The Month/)
|
148
|
+
output_buffer.should have_tag('form li.datetime fieldset ol li label', /The Day/)
|
149
|
+
output_buffer.should have_tag('form li.datetime fieldset ol li label', /The Hour/)
|
150
|
+
output_buffer.should have_tag('form li.datetime fieldset ol li label', /The Minute/)
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
describe 'when no object is given' do
|
155
|
+
before(:each) do
|
156
|
+
output_buffer.replace ''
|
157
|
+
@form = semantic_form_for(:project, :url => 'http://test.host') do |builder|
|
158
|
+
concat(builder.input(:publish_at, :as => :datetime))
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
it 'should have fieldset with legend - classified as a label' do
|
163
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
164
|
+
output_buffer.should have_tag('form li.datetime fieldset legend.label', /Publish at/)
|
165
|
+
end
|
166
|
+
|
167
|
+
it 'should have labels for each input' do
|
168
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
169
|
+
output_buffer.should have_tag('form li.datetime fieldset ol li label', :count => 5)
|
170
|
+
end
|
171
|
+
|
172
|
+
it 'should have selects for each inputs' do
|
173
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
174
|
+
output_buffer.should have_tag('form li.datetime fieldset ol li select', :count => 5)
|
175
|
+
end
|
176
|
+
end
|
177
|
+
|
178
|
+
#describe 'when an object is given and the attribute value is nil' do
|
179
|
+
# before(:each) do
|
180
|
+
# @new_post.stub!(:publish_at).and_return(nil)
|
181
|
+
# output_buffer.replace ''
|
182
|
+
# semantic_form_for(@new_post) do |builder|
|
183
|
+
# concat(builder.input(:publish_at, :as => :datetime))
|
184
|
+
# end
|
185
|
+
# end
|
186
|
+
#
|
187
|
+
# it 'should not select a value' do
|
188
|
+
# output_buffer.should_not have_tag('form li.datetime option[@selected]')
|
189
|
+
# end
|
190
|
+
#
|
191
|
+
#end
|
192
|
+
|
193
|
+
describe ':selected option' do
|
194
|
+
|
195
|
+
describe "when the object has a value" do
|
196
|
+
it "should select the object value (ignoring :selected)" do
|
197
|
+
output_buffer.replace ''
|
198
|
+
@new_post.stub!(:created_at => Time.mktime(2012))
|
199
|
+
with_deprecation_silenced do
|
200
|
+
@form = semantic_form_for(@new_post) do |builder|
|
201
|
+
concat(builder.input(:created_at, :as => :datetime, :selected => Time.mktime(1999)))
|
202
|
+
end
|
203
|
+
end
|
204
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
205
|
+
output_buffer.should have_tag("form li ol li select#post_created_at_1i option[@selected]", :count => 1)
|
206
|
+
output_buffer.should have_tag("form li ol li select#post_created_at_1i option[@value='2012'][@selected]", :count => 1)
|
207
|
+
end
|
208
|
+
end
|
209
|
+
|
210
|
+
describe 'when the object has no value' do
|
211
|
+
it "should select the :selected if provided as a Date" do
|
212
|
+
output_buffer.replace ''
|
213
|
+
@new_post.stub!(:created_at => nil)
|
214
|
+
with_deprecation_silenced do
|
215
|
+
@form = semantic_form_for(@new_post) do |builder|
|
216
|
+
concat(builder.input(:created_at, :as => :datetime, :selected => Date.new(1999)))
|
217
|
+
end
|
218
|
+
end
|
219
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
220
|
+
output_buffer.should have_tag("form li ol li select#post_created_at_1i option[@selected]", :count => 1)
|
221
|
+
output_buffer.should have_tag("form li ol li select#post_created_at_1i option[@value='1999'][@selected]", :count => 1)
|
222
|
+
end
|
223
|
+
|
224
|
+
it "should select the :selected if provided as a Time" do
|
225
|
+
output_buffer.replace ''
|
226
|
+
@new_post.stub!(:created_at => nil)
|
227
|
+
with_deprecation_silenced do
|
228
|
+
@form = semantic_form_for(@new_post) do |builder|
|
229
|
+
concat(builder.input(:created_at, :as => :datetime, :selected => Time.mktime(1999)))
|
230
|
+
end
|
231
|
+
end
|
232
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
233
|
+
output_buffer.should have_tag("form li ol li select#post_created_at_1i option[@selected]", :count => 1)
|
234
|
+
output_buffer.should have_tag("form li ol li select#post_created_at_1i option[@value='1999'][@selected]", :count => 1)
|
235
|
+
end
|
236
|
+
|
237
|
+
it "should not select an option if the :selected is provided as nil" do
|
238
|
+
output_buffer.replace ''
|
239
|
+
@new_post.stub!(:created_at => nil)
|
240
|
+
with_deprecation_silenced do
|
241
|
+
@form = semantic_form_for(@new_post) do |builder|
|
242
|
+
concat(builder.input(:created_at, :as => :datetime, :selected => nil))
|
243
|
+
end
|
244
|
+
end
|
245
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
246
|
+
output_buffer.should_not have_tag("form li ol li select#post_created_at_1i option[@selected]")
|
247
|
+
end
|
248
|
+
|
249
|
+
it "should select nothing if a :selected is not provided" do
|
250
|
+
output_buffer.replace ''
|
251
|
+
@new_post.stub!(:created_at => nil)
|
252
|
+
form = semantic_form_for(@new_post) do |builder|
|
253
|
+
concat(builder.input(:created_at, :as => :datetime))
|
254
|
+
end
|
255
|
+
output_buffer.concat(form) if Formtastic::Util.rails3?
|
256
|
+
output_buffer.should_not have_tag("form li ol li select option[@selected]")
|
257
|
+
end
|
258
|
+
end
|
259
|
+
|
260
|
+
it 'should warn about :selected deprecation' do
|
261
|
+
with_deprecation_silenced do
|
262
|
+
::ActiveSupport::Deprecation.should_receive(:warn).any_number_of_times
|
263
|
+
semantic_form_for(@new_post) do |builder|
|
264
|
+
concat(builder.input(:created_at, :as => :date, :selected => Time.mktime(1999)))
|
265
|
+
end
|
266
|
+
end
|
267
|
+
end
|
268
|
+
|
269
|
+
end
|
270
|
+
|
271
|
+
describe ':labels option' do
|
272
|
+
fields = [:year, :month, :day, :hour, :minute]
|
273
|
+
fields.each do |field|
|
274
|
+
it "should replace the #{field} label with the specified text if :labels[:#{field}] is set" do
|
275
|
+
output_buffer.replace ''
|
276
|
+
form = semantic_form_for(@new_post) do |builder|
|
277
|
+
concat(builder.input(:created_at, :as => :datetime, :labels => { field => "another #{field} label" }))
|
278
|
+
end
|
279
|
+
output_buffer.concat(form) if Formtastic::Util.rails3?
|
280
|
+
output_buffer.should have_tag('form li.datetime fieldset ol li label', :count => fields.length)
|
281
|
+
fields.each do |f|
|
282
|
+
output_buffer.should have_tag('form li.datetime fieldset ol li label', f == field ? /another #{f} label/i : /#{f}/i)
|
283
|
+
end
|
284
|
+
end
|
285
|
+
|
286
|
+
it "should not display the label for the #{field} field when :labels[:#{field}] is blank" do
|
287
|
+
output_buffer.replace ''
|
288
|
+
form = semantic_form_for(@new_post) do |builder|
|
289
|
+
concat(builder.input(:created_at, :as => :datetime, :labels => { field => "" }))
|
290
|
+
end
|
291
|
+
output_buffer.concat(form) if Formtastic::Util.rails3?
|
292
|
+
output_buffer.should have_tag('form li.datetime fieldset ol li label', :count => fields.length-1)
|
293
|
+
fields.each do |f|
|
294
|
+
output_buffer.should have_tag('form li.datetime fieldset ol li label', /#{f}/i) unless field == f
|
295
|
+
end
|
296
|
+
end
|
297
|
+
end
|
298
|
+
end
|
299
|
+
|
300
|
+
it 'should warn about :selected deprecation' do
|
301
|
+
with_deprecation_silenced do
|
302
|
+
::ActiveSupport::Deprecation.should_receive(:warn).any_number_of_times
|
303
|
+
semantic_form_for(@new_post) do |builder|
|
304
|
+
concat(builder.input(:created_at, :as => :datetime, :selected => Time.mktime(1999)))
|
305
|
+
end
|
306
|
+
end
|
307
|
+
end
|
308
|
+
|
309
|
+
end
|
310
|
+
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe 'file input' do
|
5
|
+
|
6
|
+
include FormtasticSpecHelper
|
7
|
+
|
8
|
+
before do
|
9
|
+
@output_buffer = ''
|
10
|
+
mock_everything
|
11
|
+
|
12
|
+
@form = semantic_form_for(@new_post) do |builder|
|
13
|
+
concat(builder.input(:body, :as => :file))
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
it_should_have_input_wrapper_with_class("file")
|
18
|
+
it_should_have_input_wrapper_with_id("post_body_input")
|
19
|
+
it_should_have_label_with_text(/Body/)
|
20
|
+
it_should_have_label_for("post_body")
|
21
|
+
it_should_have_input_with_id("post_body")
|
22
|
+
it_should_have_input_with_name("post[body]")
|
23
|
+
it_should_apply_error_logic_for_input_type(:file)
|
24
|
+
|
25
|
+
it 'should use input_html to style inputs' do
|
26
|
+
form = semantic_form_for(@new_post) do |builder|
|
27
|
+
concat(builder.input(:title, :as => :file, :input_html => { :class => 'myclass' }))
|
28
|
+
end
|
29
|
+
output_buffer.concat(form) if Formtastic::Util.rails3?
|
30
|
+
output_buffer.should have_tag("form li input.myclass")
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
|
@@ -0,0 +1,78 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe 'hidden input' do
|
5
|
+
|
6
|
+
include FormtasticSpecHelper
|
7
|
+
|
8
|
+
before do
|
9
|
+
@output_buffer = ''
|
10
|
+
mock_everything
|
11
|
+
|
12
|
+
@form = semantic_form_for(@new_post) do |builder|
|
13
|
+
concat(builder.input(:secret, :as => :hidden))
|
14
|
+
concat(builder.input(:author_id, :as => :hidden, :value => 99))
|
15
|
+
concat(builder.input(:published, :as => :hidden, :input_html => {:value => true}))
|
16
|
+
concat(builder.input(:reviewer, :as => :hidden, :input_html => {:class => 'new_post_reviewer', :id => 'new_post_reviewer'}))
|
17
|
+
concat(builder.input(:author, :as => :hidden, :value => 'direct_value', :input_html => {:value => "formtastic_value"}))
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
it_should_have_input_wrapper_with_class("hidden")
|
22
|
+
it_should_have_input_wrapper_with_id("post_secret_input")
|
23
|
+
it_should_not_have_a_label
|
24
|
+
|
25
|
+
it "should generate a input field" do
|
26
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
27
|
+
output_buffer.should have_tag("form li input#post_secret")
|
28
|
+
output_buffer.should have_tag("form li input#post_secret[@type=\"hidden\"]")
|
29
|
+
output_buffer.should have_tag("form li input#post_secret[@name=\"post[secret]\"]")
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should pass any explicitly specified value - using :value" do
|
33
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
34
|
+
output_buffer.should have_tag("form li input#post_author_id[@type=\"hidden\"][@value=\"99\"]")
|
35
|
+
end
|
36
|
+
|
37
|
+
# Handle Formtastic :input_html options for consistency.
|
38
|
+
it "should pass any explicitly specified value - using :input_html options" do
|
39
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
40
|
+
output_buffer.should have_tag("form li input#post_published[@type=\"hidden\"][@value=\"true\"]")
|
41
|
+
end
|
42
|
+
|
43
|
+
it "should pass any option specified using :input_html" do
|
44
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
45
|
+
output_buffer.should have_tag("form li input#new_post_reviewer[@type=\"hidden\"][@class=\"new_post_reviewer\"]")
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should prefer :input_html over directly supplied options" do
|
49
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
50
|
+
output_buffer.should have_tag("form li input#post_author[@type=\"hidden\"][@value=\"formtastic_value\"]")
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should not render inline errors" do
|
54
|
+
@errors = mock('errors')
|
55
|
+
@errors.stub!(:[]).with(:secret).and_return(["foo", "bah"])
|
56
|
+
@new_post.stub!(:errors).and_return(@errors)
|
57
|
+
|
58
|
+
form = semantic_form_for(@new_post) do |builder|
|
59
|
+
concat(builder.input(:secret, :as => :hidden))
|
60
|
+
end
|
61
|
+
|
62
|
+
output_buffer.concat(form) if Formtastic::Util.rails3?
|
63
|
+
output_buffer.should_not have_tag("form li p.inline-errors")
|
64
|
+
output_buffer.should_not have_tag("form li ul.errors")
|
65
|
+
end
|
66
|
+
|
67
|
+
it "should not render inline hints" do
|
68
|
+
form = semantic_form_for(@new_post) do |builder|
|
69
|
+
concat(builder.input(:secret, :as => :hidden, :hint => "all your base are belong to use"))
|
70
|
+
end
|
71
|
+
|
72
|
+
output_buffer.concat(form) if Formtastic::Util.rails3?
|
73
|
+
output_buffer.should_not have_tag("form li p.inline-hints")
|
74
|
+
output_buffer.should_not have_tag("form li ul.hints")
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
78
|
+
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe 'numeric input' do
|
5
|
+
|
6
|
+
include FormtasticSpecHelper
|
7
|
+
|
8
|
+
before do
|
9
|
+
@output_buffer = ''
|
10
|
+
mock_everything
|
11
|
+
|
12
|
+
@form = semantic_form_for(@new_post) do |builder|
|
13
|
+
concat(builder.input(:title, :as => :numeric))
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
it_should_have_input_wrapper_with_class(:numeric)
|
18
|
+
it_should_have_input_wrapper_with_id("post_title_input")
|
19
|
+
it_should_have_label_with_text(/Title/)
|
20
|
+
it_should_have_label_for("post_title")
|
21
|
+
it_should_have_input_with_id("post_title")
|
22
|
+
it_should_have_input_with_type(:text)
|
23
|
+
it_should_have_input_with_name("post[title]")
|
24
|
+
it_should_use_default_text_field_size_when_method_has_no_database_column(:string)
|
25
|
+
it_should_apply_custom_input_attributes_when_input_html_provided(:string)
|
26
|
+
it_should_apply_custom_for_to_label_when_input_html_id_provided(:string)
|
27
|
+
it_should_apply_error_logic_for_input_type(:numeric)
|
28
|
+
|
29
|
+
describe "when no object is provided" do
|
30
|
+
before do
|
31
|
+
@form = semantic_form_for(:project, :url => 'http://test.host/') do |builder|
|
32
|
+
concat(builder.input(:title, :as => :numeric))
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
it_should_have_label_with_text(/Title/)
|
37
|
+
it_should_have_label_for("project_title")
|
38
|
+
it_should_have_input_with_id("project_title")
|
39
|
+
it_should_have_input_with_type(:text)
|
40
|
+
it_should_have_input_with_name("project[title]")
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe 'password input' do
|
5
|
+
|
6
|
+
include FormtasticSpecHelper
|
7
|
+
|
8
|
+
before do
|
9
|
+
@output_buffer = ''
|
10
|
+
mock_everything
|
11
|
+
|
12
|
+
@form = semantic_form_for(@new_post) do |builder|
|
13
|
+
concat(builder.input(:title, :as => :password))
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
it_should_have_input_wrapper_with_class(:password)
|
18
|
+
it_should_have_input_wrapper_with_id("post_title_input")
|
19
|
+
it_should_have_label_with_text(/Title/)
|
20
|
+
it_should_have_label_for("post_title")
|
21
|
+
it_should_have_input_with_id("post_title")
|
22
|
+
it_should_have_input_with_type(:password)
|
23
|
+
it_should_have_input_with_name("post[title]")
|
24
|
+
it_should_have_maxlength_matching_column_limit
|
25
|
+
it_should_use_default_text_field_size_for_columns_longer_than_default_text_field_size(:string)
|
26
|
+
it_should_use_column_size_for_columns_shorter_than_default_text_field_size(:string)
|
27
|
+
it_should_use_default_text_field_size_when_method_has_no_database_column(:string)
|
28
|
+
it_should_apply_custom_input_attributes_when_input_html_provided(:string)
|
29
|
+
it_should_apply_custom_for_to_label_when_input_html_id_provided(:string)
|
30
|
+
it_should_apply_error_logic_for_input_type(:password)
|
31
|
+
|
32
|
+
describe "when no object is provided" do
|
33
|
+
before do
|
34
|
+
@form = semantic_form_for(:project, :url => 'http://test.host/') do |builder|
|
35
|
+
concat(builder.input(:title, :as => :password))
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
it_should_have_label_with_text(/Title/)
|
40
|
+
it_should_have_label_for("project_title")
|
41
|
+
it_should_have_input_with_id("project_title")
|
42
|
+
it_should_have_input_with_type(:password)
|
43
|
+
it_should_have_input_with_name("project[title]")
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|