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,243 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe 'radio input' do
|
5
|
+
|
6
|
+
include FormtasticSpecHelper
|
7
|
+
|
8
|
+
before do
|
9
|
+
@output_buffer = ''
|
10
|
+
mock_everything
|
11
|
+
end
|
12
|
+
|
13
|
+
describe 'for belongs_to association' do
|
14
|
+
before do
|
15
|
+
@form = semantic_form_for(@new_post) do |builder|
|
16
|
+
concat(builder.input(:author, :as => :radio, :value_as_class => true))
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
it_should_have_input_wrapper_with_class("radio")
|
21
|
+
it_should_have_input_wrapper_with_id("post_author_input")
|
22
|
+
it_should_have_a_nested_fieldset
|
23
|
+
it_should_apply_error_logic_for_input_type(:radio)
|
24
|
+
it_should_use_the_collection_when_provided(:radio, 'input')
|
25
|
+
|
26
|
+
it 'should generate a legend containing a label with text for the input' do
|
27
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
28
|
+
output_buffer.should have_tag('form li fieldset legend.label label')
|
29
|
+
output_buffer.should have_tag('form li fieldset legend.label label', /Author/)
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'should not link the label within the legend to any input' do
|
33
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
34
|
+
output_buffer.should_not have_tag('form li fieldset legend label[@for]')
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'should generate an ordered list with a list item for each choice' do
|
38
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
39
|
+
output_buffer.should have_tag('form li fieldset ol')
|
40
|
+
output_buffer.should have_tag('form li fieldset ol li', :count => ::Author.find(:all).size)
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'should have one option with a "checked" attribute' do
|
44
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
45
|
+
output_buffer.should have_tag('form li input[@checked]', :count => 1)
|
46
|
+
end
|
47
|
+
|
48
|
+
describe "each choice" do
|
49
|
+
|
50
|
+
it 'should contain a label for the radio input with a nested input and label text' do
|
51
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
52
|
+
::Author.find(:all).each do |author|
|
53
|
+
output_buffer.should have_tag('form li fieldset ol li label', /#{author.to_label}/)
|
54
|
+
output_buffer.should have_tag("form li fieldset ol li label[@for='post_author_id_#{author.id}']")
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
it 'should use values as li.class when value_as_class is true' do
|
59
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
60
|
+
::Author.find(:all).each do |author|
|
61
|
+
output_buffer.should have_tag("form li fieldset ol li.author_#{author.id} label")
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
it "should have a radio input" do
|
66
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
67
|
+
::Author.find(:all).each do |author|
|
68
|
+
output_buffer.should have_tag("form li fieldset ol li label input#post_author_id_#{author.id}")
|
69
|
+
output_buffer.should have_tag("form li fieldset ol li label input[@type='radio']")
|
70
|
+
output_buffer.should have_tag("form li fieldset ol li label input[@value='#{author.id}']")
|
71
|
+
output_buffer.should have_tag("form li fieldset ol li label input[@name='post[author_id]']")
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
it "should mark input as checked if it's the the existing choice" do
|
76
|
+
@new_post.author_id.should == @bob.id
|
77
|
+
@new_post.author.id.should == @bob.id
|
78
|
+
@new_post.author.should == @bob
|
79
|
+
|
80
|
+
form = semantic_form_for(@new_post) do |builder|
|
81
|
+
concat(builder.input(:author, :as => :radio))
|
82
|
+
end
|
83
|
+
|
84
|
+
output_buffer.concat(form) if Formtastic::Util.rails3?
|
85
|
+
output_buffer.should have_tag("form li fieldset ol li label input[@checked='checked']")
|
86
|
+
end
|
87
|
+
|
88
|
+
it "should not contain invalid HTML attributes" do
|
89
|
+
|
90
|
+
form = semantic_form_for(@new_post) do |builder|
|
91
|
+
concat(builder.input(:author, :as => :radio))
|
92
|
+
end
|
93
|
+
|
94
|
+
output_buffer.concat(form) if Formtastic::Util.rails3?
|
95
|
+
output_buffer.should_not have_tag("form li fieldset ol li input[@find_options]")
|
96
|
+
end
|
97
|
+
|
98
|
+
end
|
99
|
+
|
100
|
+
describe 'and no object is given' do
|
101
|
+
before(:each) do
|
102
|
+
output_buffer.replace ''
|
103
|
+
@form = semantic_form_for(:project, :url => 'http://test.host') do |builder|
|
104
|
+
concat(builder.input(:author_id, :as => :radio, :collection => ::Author.find(:all)))
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
it 'should generate a fieldset with legend' do
|
109
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
110
|
+
output_buffer.should have_tag('form li fieldset legend', /Author/)
|
111
|
+
end
|
112
|
+
|
113
|
+
it 'should generate an li tag for each item in the collection' do
|
114
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
115
|
+
output_buffer.should have_tag('form li fieldset ol li', :count => ::Author.find(:all).size)
|
116
|
+
end
|
117
|
+
|
118
|
+
it 'should generate labels for each item' do
|
119
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
120
|
+
::Author.find(:all).each do |author|
|
121
|
+
output_buffer.should have_tag('form li fieldset ol li label', /#{author.to_label}/)
|
122
|
+
output_buffer.should have_tag("form li fieldset ol li label[@for='project_author_id_#{author.id}']")
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
it 'should html escape the label string' do
|
127
|
+
output_buffer.replace ''
|
128
|
+
form = semantic_form_for(:project, :url => 'http://test.host') do |builder|
|
129
|
+
concat(builder.input(:author_id, :as => :radio, :collection => [["<b>Item 1</b>", 1], ["<b>Item 2</b>", 2]]))
|
130
|
+
end
|
131
|
+
output_buffer.concat(form) if Formtastic::Util.rails3?
|
132
|
+
output_buffer.should have_tag('form li fieldset ol li label') do |label|
|
133
|
+
label.body.should match /<b>Item [12]<\/b>$/
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
it 'should generate inputs for each item' do
|
138
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
139
|
+
::Author.find(:all).each do |author|
|
140
|
+
output_buffer.should have_tag("form li fieldset ol li label input#project_author_id_#{author.id}")
|
141
|
+
output_buffer.should have_tag("form li fieldset ol li label input[@type='radio']")
|
142
|
+
output_buffer.should have_tag("form li fieldset ol li label input[@value='#{author.id}']")
|
143
|
+
output_buffer.should have_tag("form li fieldset ol li label input[@name='project[author_id]']")
|
144
|
+
end
|
145
|
+
end
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
describe 'when :selected is set' do
|
150
|
+
before do
|
151
|
+
@output_buffer = ''
|
152
|
+
end
|
153
|
+
|
154
|
+
describe "no selected items" do
|
155
|
+
before do
|
156
|
+
@new_post.stub!(:author_ids).and_return(nil)
|
157
|
+
|
158
|
+
with_deprecation_silenced do
|
159
|
+
@form = semantic_form_for(@new_post) do |builder|
|
160
|
+
concat(builder.input(:authors, :as => :radio, :selected => nil))
|
161
|
+
end
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
it 'should not have any selected item(s)' do
|
166
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
167
|
+
output_buffer.should_not have_tag("form li fieldset ol li label input[@checked='checked']")
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
describe "single selected item" do
|
172
|
+
before do
|
173
|
+
@new_post.stub!(:author_ids).and_return(nil)
|
174
|
+
with_deprecation_silenced do
|
175
|
+
@form = semantic_form_for(@new_post) do |builder|
|
176
|
+
concat(builder.input(:authors, :as => :radio, :selected => @fred.id))
|
177
|
+
end
|
178
|
+
end
|
179
|
+
end
|
180
|
+
|
181
|
+
it "should have one item selected; the specified one" do
|
182
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
183
|
+
output_buffer.should have_tag("form li fieldset ol li label input[@type='radio'][@checked='checked']", :count => 1)
|
184
|
+
output_buffer.should have_tag("form li fieldset ol li label[@for='post_author_ids_#{@fred.id}']", /fred/i)
|
185
|
+
output_buffer.should have_tag("form li fieldset ol li label input[@type='radio'][@checked='checked'][@value='#{@fred.id}']")
|
186
|
+
end
|
187
|
+
end
|
188
|
+
|
189
|
+
end
|
190
|
+
|
191
|
+
describe "with i18n of the legend label" do
|
192
|
+
|
193
|
+
before do
|
194
|
+
::I18n.backend.store_translations :en, :formtastic => { :labels => { :post => { :authors => "Translated!" }}}
|
195
|
+
|
196
|
+
Formtastic::SemanticFormBuilder.i18n_lookups_by_default = true
|
197
|
+
@new_post.stub!(:author_ids).and_return(nil)
|
198
|
+
@form = semantic_form_for(@new_post) do |builder|
|
199
|
+
concat(builder.input(:authors, :as => :radio))
|
200
|
+
end
|
201
|
+
end
|
202
|
+
|
203
|
+
after do
|
204
|
+
::I18n.backend.reload!
|
205
|
+
Formtastic::SemanticFormBuilder.i18n_lookups_by_default = false
|
206
|
+
end
|
207
|
+
|
208
|
+
it "should do foo" do
|
209
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
210
|
+
output_buffer.should have_tag("legend.label label", /Translated/)
|
211
|
+
end
|
212
|
+
|
213
|
+
end
|
214
|
+
|
215
|
+
describe "when :label option is set" do
|
216
|
+
before do
|
217
|
+
@new_post.stub!(:author_ids).and_return(nil)
|
218
|
+
@form = semantic_form_for(@new_post) do |builder|
|
219
|
+
concat(builder.input(:authors, :as => :radio, :label => 'The authors'))
|
220
|
+
end
|
221
|
+
end
|
222
|
+
|
223
|
+
it "should output the correct label title" do
|
224
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
225
|
+
output_buffer.should have_tag("legend.label label", /The authors/)
|
226
|
+
end
|
227
|
+
end
|
228
|
+
|
229
|
+
describe "when :label option is false" do
|
230
|
+
before do
|
231
|
+
@output_buffer = ''
|
232
|
+
@new_post.stub!(:author_ids).and_return(nil)
|
233
|
+
@form = semantic_form_for(@new_post) do |builder|
|
234
|
+
concat(builder.input(:authors, :as => :radio, :label => false))
|
235
|
+
end
|
236
|
+
end
|
237
|
+
|
238
|
+
it "should not output the legend" do
|
239
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
240
|
+
output_buffer.should_not have_tag("legend.label")
|
241
|
+
end
|
242
|
+
end
|
243
|
+
end
|