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,206 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe 'time input' do
|
5
|
+
|
6
|
+
include FormtasticSpecHelper
|
7
|
+
|
8
|
+
before do
|
9
|
+
@output_buffer = ''
|
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 "with :ignore_date" do
|
20
|
+
before do
|
21
|
+
@form = semantic_form_for(@new_post) do |builder|
|
22
|
+
concat(builder.input(:publish_at, :as => :time, :ignore_date => true))
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'should not have an input for day, month and year' do
|
27
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
28
|
+
output_buffer.should_not have_tag('#post_publish_at_1i')
|
29
|
+
output_buffer.should_not have_tag('#post_publish_at_2i')
|
30
|
+
output_buffer.should_not have_tag('#post_publish_at_3i')
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'should have an input for hour and minute' do
|
34
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
35
|
+
output_buffer.should have_tag('#post_publish_at_4i')
|
36
|
+
output_buffer.should have_tag('#post_publish_at_5i')
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
describe "without seconds" do
|
42
|
+
before do
|
43
|
+
@form = semantic_form_for(@new_post) do |builder|
|
44
|
+
concat(builder.input(:publish_at, :as => :time))
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
it_should_have_input_wrapper_with_class("time")
|
49
|
+
it_should_have_input_wrapper_with_id("post_publish_at_input")
|
50
|
+
it_should_have_a_nested_fieldset
|
51
|
+
it_should_apply_error_logic_for_input_type(:time)
|
52
|
+
|
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?
|
55
|
+
output_buffer.should have_tag('form li.time fieldset legend.label label', /Publish at/)
|
56
|
+
end
|
57
|
+
|
58
|
+
it 'should associate the legend label with the first select' do
|
59
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
60
|
+
output_buffer.should have_tag('form li.time fieldset legend.label label[@for="post_publish_at_1i"]')
|
61
|
+
end
|
62
|
+
|
63
|
+
it 'should have an ordered list of two items inside the fieldset' do
|
64
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
65
|
+
output_buffer.should have_tag('form li.time fieldset ol')
|
66
|
+
output_buffer.should have_tag('form li.time fieldset ol li', :count => 2)
|
67
|
+
end
|
68
|
+
|
69
|
+
it 'should have five labels for hour and minute' do
|
70
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
71
|
+
output_buffer.should have_tag('form li.time fieldset ol li label', :count => 2)
|
72
|
+
output_buffer.should have_tag('form li.time fieldset ol li label', /hour/i)
|
73
|
+
output_buffer.should have_tag('form li.time fieldset ol li label', /minute/i)
|
74
|
+
end
|
75
|
+
|
76
|
+
it 'should have two selects for hour and minute' do
|
77
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
78
|
+
output_buffer.should have_tag('form li.time fieldset ol li', :count => 2)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
describe "with seconds" do
|
83
|
+
before do
|
84
|
+
@form = semantic_form_for(@new_post) do |builder|
|
85
|
+
concat(builder.input(:publish_at, :as => :time, :include_seconds => true))
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
it 'should have five labels for hour and minute' do
|
90
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
91
|
+
output_buffer.should have_tag('form li.time fieldset ol li label', :count => 3)
|
92
|
+
output_buffer.should have_tag('form li.time fieldset ol li label', /hour/i)
|
93
|
+
output_buffer.should have_tag('form li.time fieldset ol li label', /minute/i)
|
94
|
+
output_buffer.should have_tag('form li.time fieldset ol li label', /second/i)
|
95
|
+
end
|
96
|
+
|
97
|
+
it 'should have three selects for hour, minute and seconds' do
|
98
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
99
|
+
output_buffer.should have_tag('form li.time fieldset ol li', :count => 3)
|
100
|
+
end
|
101
|
+
|
102
|
+
it 'should generate a sanitized label and matching ids for attribute' do
|
103
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
104
|
+
4.upto(6) do |i|
|
105
|
+
output_buffer.should have_tag("form li fieldset ol li label[@for='post_publish_at_#{i}i']")
|
106
|
+
output_buffer.should have_tag("form li fieldset ol li #post_publish_at_#{i}i")
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
describe ':selected option' do
|
113
|
+
|
114
|
+
describe "when the object has a value" do
|
115
|
+
it "should select the object value (ignoring :selected)" do
|
116
|
+
output_buffer.replace ''
|
117
|
+
@new_post.stub!(:created_at => Time.mktime(2012, 11, 30, 21, 45))
|
118
|
+
with_deprecation_silenced do
|
119
|
+
@form = semantic_form_for(@new_post) do |builder|
|
120
|
+
concat(builder.input(:created_at, :as => :time, :selected => Time.mktime(1999, 12, 31, 22, 59)))
|
121
|
+
end
|
122
|
+
end
|
123
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
124
|
+
output_buffer.should have_tag("form li ol li select#post_created_at_4i option[@selected]", :count => 1)
|
125
|
+
output_buffer.should have_tag("form li ol li select#post_created_at_4i option[@value='21'][@selected]", :count => 1)
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
describe 'when the object has no value (nil)' do
|
130
|
+
it "should select the :selected if provided as a Time" do
|
131
|
+
output_buffer.replace ''
|
132
|
+
@new_post.stub!(:created_at => nil)
|
133
|
+
with_deprecation_silenced do
|
134
|
+
@form = semantic_form_for(@new_post) do |builder|
|
135
|
+
concat(builder.input(:created_at, :as => :time, :selected => Time.mktime(1999, 12, 31, 22, 59)))
|
136
|
+
end
|
137
|
+
end
|
138
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
139
|
+
output_buffer.should have_tag("form li ol li select#post_created_at_4i option[@selected]", :count => 1)
|
140
|
+
output_buffer.should have_tag("form li ol li select#post_created_at_4i option[@value='22'][@selected]", :count => 1)
|
141
|
+
end
|
142
|
+
|
143
|
+
it "should not select an option if the :selected is provided as nil" do
|
144
|
+
output_buffer.replace ''
|
145
|
+
@new_post.stub!(:created_at => nil)
|
146
|
+
with_deprecation_silenced do
|
147
|
+
@form = semantic_form_for(@new_post) do |builder|
|
148
|
+
concat(builder.input(:created_at, :as => :time, :selected => nil))
|
149
|
+
end
|
150
|
+
end
|
151
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
152
|
+
output_buffer.should_not have_tag("form li ol li select#post_created_at_4i option[@selected]")
|
153
|
+
end
|
154
|
+
|
155
|
+
it "should select nothing if a :selected is not provided" do
|
156
|
+
output_buffer.replace ''
|
157
|
+
@new_post.stub!(:created_at => nil)
|
158
|
+
form = semantic_form_for(@new_post) do |builder|
|
159
|
+
concat(builder.input(:created_at, :as => :time))
|
160
|
+
end
|
161
|
+
output_buffer.concat(form) if Formtastic::Util.rails3?
|
162
|
+
output_buffer.should_not have_tag("form li ol li select option[@selected]")
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
end
|
167
|
+
|
168
|
+
describe ':labels option' do
|
169
|
+
fields = [:hour, :minute, :second]
|
170
|
+
fields.each do |field|
|
171
|
+
it "should replace the #{field} label with the specified text if :labels[:#{field}] is set" do
|
172
|
+
output_buffer.replace ''
|
173
|
+
form = semantic_form_for(@new_post) do |builder|
|
174
|
+
concat(builder.input(:created_at, :as => :time, :include_seconds => true, :labels => { field => "another #{field} label" }))
|
175
|
+
end
|
176
|
+
output_buffer.concat(form) if Formtastic::Util.rails3?
|
177
|
+
output_buffer.should have_tag('form li.time fieldset ol li label', :count => fields.length)
|
178
|
+
fields.each do |f|
|
179
|
+
output_buffer.should have_tag('form li.time fieldset ol li label', f == field ? /another #{f} label/i : /#{f}/i)
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
183
|
+
it "should not display the label for the #{field} field when :labels[:#{field}] is blank" do
|
184
|
+
output_buffer.replace ''
|
185
|
+
form = semantic_form_for(@new_post) do |builder|
|
186
|
+
concat(builder.input(:created_at, :as => :time, :include_seconds => true, :labels => { field => "" }))
|
187
|
+
end
|
188
|
+
output_buffer.concat(form) if Formtastic::Util.rails3?
|
189
|
+
output_buffer.should have_tag('form li.time fieldset ol li label', :count => fields.length-1)
|
190
|
+
fields.each do |f|
|
191
|
+
output_buffer.should have_tag('form li.time fieldset ol li label', /#{f}/i) unless field == f
|
192
|
+
end
|
193
|
+
end
|
194
|
+
end
|
195
|
+
end
|
196
|
+
|
197
|
+
it 'should warn about :selected deprecation' do
|
198
|
+
with_deprecation_silenced do
|
199
|
+
::ActiveSupport::Deprecation.should_receive(:warn).any_number_of_times
|
200
|
+
semantic_form_for(@new_post) do |builder|
|
201
|
+
concat(builder.input(:created_at, :as => :time, :selected => Time.mktime(1999)))
|
202
|
+
end
|
203
|
+
end
|
204
|
+
end
|
205
|
+
|
206
|
+
end
|
@@ -0,0 +1,110 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe 'time_zone 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(:time_zone))
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
it_should_have_input_wrapper_with_class("time_zone")
|
18
|
+
it_should_have_input_wrapper_with_id("post_time_zone_input")
|
19
|
+
it_should_apply_error_logic_for_input_type(:time_zone)
|
20
|
+
|
21
|
+
it 'should generate a label for the input' do
|
22
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
23
|
+
output_buffer.should have_tag('form li label')
|
24
|
+
output_buffer.should have_tag('form li label[@for="post_time_zone"]')
|
25
|
+
output_buffer.should have_tag('form li label', /Time zone/)
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should generate a select" do
|
29
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
30
|
+
output_buffer.should have_tag("form li select")
|
31
|
+
output_buffer.should have_tag("form li select#post_time_zone")
|
32
|
+
output_buffer.should have_tag("form li select[@name=\"post[time_zone]\"]")
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'should use input_html to style inputs' do
|
36
|
+
form = semantic_form_for(@new_post) do |builder|
|
37
|
+
concat(builder.input(:time_zone, :input_html => { :class => 'myclass' }))
|
38
|
+
end
|
39
|
+
output_buffer.concat(form) if Formtastic::Util.rails3?
|
40
|
+
output_buffer.should have_tag("form li select.myclass")
|
41
|
+
end
|
42
|
+
|
43
|
+
describe 'when no object is given' do
|
44
|
+
before(:each) do
|
45
|
+
@form = semantic_form_for(:project, :url => 'http://test.host/') do |builder|
|
46
|
+
concat(builder.input(:time_zone, :as => :time_zone))
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'should generate labels' do
|
51
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
52
|
+
output_buffer.should have_tag('form li label')
|
53
|
+
output_buffer.should have_tag('form li label[@for="project_time_zone"]')
|
54
|
+
output_buffer.should have_tag('form li label', /Time zone/)
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'should generate select inputs' do
|
58
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
59
|
+
output_buffer.should have_tag("form li select")
|
60
|
+
output_buffer.should have_tag("form li select#project_time_zone")
|
61
|
+
output_buffer.should have_tag("form li select[@name=\"project[time_zone]\"]")
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
describe 'when :selected is set' do
|
66
|
+
before do
|
67
|
+
@output_buffer = ''
|
68
|
+
end
|
69
|
+
|
70
|
+
# Note: Not possible to override default selected value for time_zone input
|
71
|
+
# without overriding Rails time_zone_select. This Rails helper works "a bit different". =/
|
72
|
+
#
|
73
|
+
# describe "no selected items" do
|
74
|
+
# before do
|
75
|
+
# @new_post.stub!(:time_zone).and_return('Stockholm')
|
76
|
+
#
|
77
|
+
# semantic_form_for(@new_post) do |builder|
|
78
|
+
# concat(builder.input(:time_zone, :as => :time_zone, :selected => nil))
|
79
|
+
# end
|
80
|
+
# end
|
81
|
+
#
|
82
|
+
# it 'should not have any selected item(s)' do
|
83
|
+
# output_buffer.should_not have_tag("form li select option[@selected='selected']")
|
84
|
+
# end
|
85
|
+
# end
|
86
|
+
|
87
|
+
describe "single selected item" do
|
88
|
+
before do
|
89
|
+
# Note: See above...only works for the "attribute is nil" case.
|
90
|
+
# @new_post.stub!(:time_zone).and_return('Stockholm')
|
91
|
+
@new_post.stub!(:time_zone).and_return(nil)
|
92
|
+
|
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
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
it 'should have a selected item; the specified one' do
|
101
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
102
|
+
output_buffer.should have_tag("form li select option[@selected='selected']", :count => 1)
|
103
|
+
output_buffer.should have_tag("form li select option[@selected='selected']", /Melbourne/i)
|
104
|
+
output_buffer.should have_tag("form li select option[@selected='selected'][@value='Melbourne']")
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
end
|
109
|
+
|
110
|
+
end
|