formtastic 0.9.2 → 0.9.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README.textile +35 -4
- data/Rakefile +47 -22
- data/generators/formtastic/templates/formtastic.css +1 -0
- data/lib/formtastic/i18n.rb +27 -0
- data/lib/formtastic.rb +151 -81
- data/lib/locale/en.yml +2 -2
- data/spec/commit_button_spec.rb +5 -5
- data/spec/custom_builder_spec.rb +8 -8
- data/spec/custom_macros.rb +3 -3
- data/spec/errors_spec.rb +6 -6
- data/spec/form_helper_spec.rb +4 -4
- data/spec/i18n_spec.rb +83 -0
- data/spec/input_spec.rb +22 -21
- data/spec/inputs/check_boxes_input_spec.rb +3 -3
- data/spec/inputs/country_input_spec.rb +1 -1
- data/spec/inputs/date_input_spec.rb +2 -2
- data/spec/inputs/datetime_input_spec.rb +5 -5
- data/spec/inputs/hidden_input_spec.rb +13 -2
- data/spec/inputs/radio_input_spec.rb +3 -3
- data/spec/inputs/select_input_spec.rb +83 -4
- data/spec/inputs/time_input_spec.rb +2 -2
- data/spec/inputs_spec.rb +28 -16
- data/spec/label_spec.rb +0 -6
- data/spec/semantic_fields_for_spec.rb +1 -1
- data/spec/spec_helper.rb +4 -2
- metadata +58 -6
data/spec/custom_macros.rb
CHANGED
@@ -157,7 +157,7 @@ module CustomMacros
|
|
157
157
|
end
|
158
158
|
|
159
159
|
it 'should render a paragraph for the errors' do
|
160
|
-
Formtastic::SemanticFormBuilder.inline_errors = :sentence
|
160
|
+
::Formtastic::SemanticFormBuilder.inline_errors = :sentence
|
161
161
|
semantic_form_for(@new_post) do |builder|
|
162
162
|
concat(builder.input(:title, :as => type))
|
163
163
|
end
|
@@ -165,7 +165,7 @@ module CustomMacros
|
|
165
165
|
end
|
166
166
|
|
167
167
|
it 'should not display an error list' do
|
168
|
-
Formtastic::SemanticFormBuilder.inline_errors = :list
|
168
|
+
::Formtastic::SemanticFormBuilder.inline_errors = :list
|
169
169
|
semantic_form_for(@new_post) do |builder|
|
170
170
|
concat(builder.input(:title, :as => type))
|
171
171
|
end
|
@@ -399,7 +399,7 @@ module CustomMacros
|
|
399
399
|
end
|
400
400
|
|
401
401
|
describe 'when the :label_method option is not provided' do
|
402
|
-
Formtastic::SemanticFormBuilder.collection_label_methods.each do |label_method|
|
402
|
+
::Formtastic::SemanticFormBuilder.collection_label_methods.each do |label_method|
|
403
403
|
|
404
404
|
describe "when the collection objects respond to #{label_method}" do
|
405
405
|
before do
|
data/spec/errors_spec.rb
CHANGED
@@ -19,14 +19,14 @@ describe 'SemanticFormBuilder#errors_on' do
|
|
19
19
|
end
|
20
20
|
|
21
21
|
it 'should render a paragraph with the errors joined into a sentence when inline_errors config is :sentence' do
|
22
|
-
Formtastic::SemanticFormBuilder.inline_errors = :sentence
|
22
|
+
::Formtastic::SemanticFormBuilder.inline_errors = :sentence
|
23
23
|
semantic_form_for(@new_post) do |builder|
|
24
24
|
builder.errors_on(:title).should have_tag('p.inline-errors', @title_errors.to_sentence)
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
28
28
|
it 'should render an unordered list with the class errors when inline_errors config is :list' do
|
29
|
-
Formtastic::SemanticFormBuilder.inline_errors = :list
|
29
|
+
::Formtastic::SemanticFormBuilder.inline_errors = :list
|
30
30
|
semantic_form_for(@new_post) do |builder|
|
31
31
|
builder.errors_on(:title).should have_tag('ul.errors')
|
32
32
|
@title_errors.each do |error|
|
@@ -36,14 +36,14 @@ describe 'SemanticFormBuilder#errors_on' do
|
|
36
36
|
end
|
37
37
|
|
38
38
|
it 'should render a paragraph with the first error when inline_errors config is :first' do
|
39
|
-
Formtastic::SemanticFormBuilder.inline_errors = :first
|
39
|
+
::Formtastic::SemanticFormBuilder.inline_errors = :first
|
40
40
|
semantic_form_for(@new_post) do |builder|
|
41
41
|
builder.errors_on(:title).should have_tag('p.inline-errors', @title_errors.first)
|
42
42
|
end
|
43
43
|
end
|
44
44
|
|
45
45
|
it 'should return nil when inline_errors config is :none' do
|
46
|
-
Formtastic::SemanticFormBuilder.inline_errors = :none
|
46
|
+
::Formtastic::SemanticFormBuilder.inline_errors = :none
|
47
47
|
semantic_form_for(@new_post) do |builder|
|
48
48
|
builder.errors_on(:title).should be_nil
|
49
49
|
end
|
@@ -58,7 +58,7 @@ describe 'SemanticFormBuilder#errors_on' do
|
|
58
58
|
|
59
59
|
it 'should return nil when inline_errors config is :sentence, :list or :none' do
|
60
60
|
[:sentence, :list, :none].each do |config|
|
61
|
-
Formtastic::SemanticFormBuilder.inline_errors = config
|
61
|
+
::Formtastic::SemanticFormBuilder.inline_errors = config
|
62
62
|
semantic_form_for(@new_post) do |builder|
|
63
63
|
builder.errors_on(:title).should be_nil
|
64
64
|
end
|
@@ -73,7 +73,7 @@ describe 'SemanticFormBuilder#errors_on' do
|
|
73
73
|
|
74
74
|
it 'should return nil when inline_errors config is :sentence, :list or :none' do
|
75
75
|
[:sentence, :list, :none].each do |config|
|
76
|
-
Formtastic::SemanticFormBuilder.inline_errors = config
|
76
|
+
::Formtastic::SemanticFormBuilder.inline_errors = config
|
77
77
|
semantic_form_for(@new_post) do |builder|
|
78
78
|
builder.errors_on(:title).should be_nil
|
79
79
|
end
|
data/spec/form_helper_spec.rb
CHANGED
@@ -14,7 +14,7 @@ describe 'SemanticFormHelper' do
|
|
14
14
|
|
15
15
|
it 'yields an instance of SemanticFormBuilder' do
|
16
16
|
semantic_form_for(:post, ::Post.new, :url => '/hello') do |builder|
|
17
|
-
builder.class.should == Formtastic::SemanticFormBuilder
|
17
|
+
builder.class.should == ::Formtastic::SemanticFormBuilder
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
@@ -85,7 +85,7 @@ describe 'SemanticFormHelper' do
|
|
85
85
|
describe '#semantic_fields_for' do
|
86
86
|
it 'yields an instance of SemanticFormBuilder' do
|
87
87
|
semantic_fields_for(:post, ::Post.new, :url => '/hello') do |builder|
|
88
|
-
builder.class.should == Formtastic::SemanticFormBuilder
|
88
|
+
builder.class.should == ::Formtastic::SemanticFormBuilder
|
89
89
|
end
|
90
90
|
end
|
91
91
|
end
|
@@ -93,7 +93,7 @@ describe 'SemanticFormHelper' do
|
|
93
93
|
describe '#semantic_form_remote_for' do
|
94
94
|
it 'yields an instance of SemanticFormBuilder' do
|
95
95
|
semantic_form_remote_for(:post, ::Post.new, :url => '/hello') do |builder|
|
96
|
-
builder.class.should == Formtastic::SemanticFormBuilder
|
96
|
+
builder.class.should == ::Formtastic::SemanticFormBuilder
|
97
97
|
end
|
98
98
|
end
|
99
99
|
end
|
@@ -101,7 +101,7 @@ describe 'SemanticFormHelper' do
|
|
101
101
|
describe '#semantic_form_for_remote' do
|
102
102
|
it 'yields an instance of SemanticFormBuilder' do
|
103
103
|
semantic_remote_form_for(:post, ::Post.new, :url => '/hello') do |builder|
|
104
|
-
builder.class.should == Formtastic::SemanticFormBuilder
|
104
|
+
builder.class.should == ::Formtastic::SemanticFormBuilder
|
105
105
|
end
|
106
106
|
end
|
107
107
|
end
|
data/spec/i18n_spec.rb
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
require File.join(File.dirname(__FILE__), *%w[spec_helper])
|
3
|
+
|
4
|
+
describe 'Formtastic::I18n' do
|
5
|
+
|
6
|
+
FORMTASTIC_KEYS = [:required, :yes, :no, :create, :update].freeze
|
7
|
+
|
8
|
+
it "should be defined" do
|
9
|
+
lambda { ::Formtastic::I18n }.should_not raise_error(::NameError)
|
10
|
+
end
|
11
|
+
|
12
|
+
describe "default translations" do
|
13
|
+
it "should be defined" do
|
14
|
+
lambda { ::Formtastic::I18n::DEFAULT_VALUES }.should_not raise_error(::NameError)
|
15
|
+
::Formtastic::I18n::DEFAULT_VALUES.is_a?(::Hash).should == true
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should exists for the core I18n lookup keys" do
|
19
|
+
(::Formtastic::I18n::DEFAULT_VALUES.keys & FORMTASTIC_KEYS).size.should == FORMTASTIC_KEYS.size
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe "when I18n locales are available" do
|
24
|
+
|
25
|
+
before do
|
26
|
+
@formtastic_strings = {
|
27
|
+
:required => 'Default Required',
|
28
|
+
:yes => 'Default Yes',
|
29
|
+
:no => 'Default No',
|
30
|
+
:create => 'Default Create {{model}}',
|
31
|
+
:update => 'Default Update {{model}}',
|
32
|
+
:custom_scope => {
|
33
|
+
:duck => 'Duck',
|
34
|
+
:duck_pond => '{{ducks}} ducks in a pond'
|
35
|
+
}
|
36
|
+
}
|
37
|
+
::I18n.backend.store_translations :en, :formtastic => @formtastic_strings
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should translate core strings correctly" do
|
41
|
+
::Formtastic::I18n.t(:required).should == "Default Required"
|
42
|
+
::Formtastic::I18n.t(:yes).should == "Default Yes"
|
43
|
+
::Formtastic::I18n.t(:no).should == "Default No"
|
44
|
+
::Formtastic::I18n.t(:create, :model => 'Post').should == "Default Create Post"
|
45
|
+
::Formtastic::I18n.t(:update, :model => 'Post').should == "Default Update Post"
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should all belong to scope 'formtastic'" do
|
49
|
+
::Formtastic::I18n.t(:duck, :scope => [:custom_scope]).should == 'Duck'
|
50
|
+
end
|
51
|
+
|
52
|
+
it "should override default I18n lookup args if these are specified" do
|
53
|
+
::Formtastic::I18n.t(:duck_pond, :scope => [:custom_scope], :ducks => 15).should == '15 ducks in a pond'
|
54
|
+
end
|
55
|
+
|
56
|
+
it "should be possible to override default values" do
|
57
|
+
::I18n.backend.store_translations :en, {:formtastic => {:required => nil}}
|
58
|
+
::Formtastic::I18n.t(:required, :default => 'Nothing found!').should == 'Nothing found!'
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
|
63
|
+
describe "when no I18n locales are available" do
|
64
|
+
|
65
|
+
before do
|
66
|
+
::I18n.backend.store_translations :en, :formtastic => {
|
67
|
+
:required => nil,
|
68
|
+
:yes => nil,
|
69
|
+
:no => nil,
|
70
|
+
:create => nil,
|
71
|
+
:update => nil
|
72
|
+
}
|
73
|
+
end
|
74
|
+
|
75
|
+
it "should use default strings" do
|
76
|
+
(::Formtastic::I18n::DEFAULT_VALUES.keys).each do |key|
|
77
|
+
::Formtastic::I18n.t(key, :model => '{{model}}').should == ::Formtastic::I18n::DEFAULT_VALUES[key]
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
82
|
+
|
83
|
+
end
|
data/spec/input_spec.rb
CHANGED
@@ -12,7 +12,7 @@ describe 'SemanticFormBuilder#input' do
|
|
12
12
|
|
13
13
|
describe 'with inline order customization' do
|
14
14
|
it 'should allow input, hints, errors as order' do
|
15
|
-
Formtastic::SemanticFormBuilder.inline_order = [:input, :hints, :errors]
|
15
|
+
::Formtastic::SemanticFormBuilder.inline_order = [:input, :hints, :errors]
|
16
16
|
|
17
17
|
semantic_form_for(@new_post) do |builder|
|
18
18
|
builder.should_receive(:inline_input_for).once.ordered
|
@@ -23,7 +23,7 @@ describe 'SemanticFormBuilder#input' do
|
|
23
23
|
end
|
24
24
|
|
25
25
|
it 'should allow hints, input, errors as order' do
|
26
|
-
Formtastic::SemanticFormBuilder.inline_order = [:hints, :input, :errors]
|
26
|
+
::Formtastic::SemanticFormBuilder.inline_order = [:hints, :input, :errors]
|
27
27
|
|
28
28
|
semantic_form_for(@new_post) do |builder|
|
29
29
|
builder.should_receive(:inline_hints_for).once.ordered
|
@@ -49,12 +49,13 @@ describe 'SemanticFormBuilder#input' do
|
|
49
49
|
describe 'when true' do
|
50
50
|
|
51
51
|
before do
|
52
|
-
@
|
52
|
+
@old_string = ::Formtastic::SemanticFormBuilder.required_string
|
53
|
+
@new_string = ::Formtastic::SemanticFormBuilder.required_string = " required yo!" # ensure there's something in the string
|
53
54
|
@new_post.class.should_not_receive(:reflect_on_all_validations)
|
54
55
|
end
|
55
56
|
|
56
57
|
after do
|
57
|
-
Formtastic::SemanticFormBuilder.required_string =
|
58
|
+
::Formtastic::SemanticFormBuilder.required_string = @old_string
|
58
59
|
end
|
59
60
|
|
60
61
|
it 'should set a "required" class' do
|
@@ -69,7 +70,7 @@ describe 'SemanticFormBuilder#input' do
|
|
69
70
|
semantic_form_for(@new_post) do |builder|
|
70
71
|
concat(builder.input(:title, :required => true))
|
71
72
|
end
|
72
|
-
output_buffer.should have_tag('form li.required label', /#{@
|
73
|
+
output_buffer.should have_tag('form li.required label', /#{@new_string}$/)
|
73
74
|
end
|
74
75
|
|
75
76
|
end
|
@@ -77,12 +78,12 @@ describe 'SemanticFormBuilder#input' do
|
|
77
78
|
describe 'when false' do
|
78
79
|
|
79
80
|
before do
|
80
|
-
@string = Formtastic::SemanticFormBuilder.optional_string = " optional yo!" # ensure there's something in the string
|
81
|
+
@string = ::Formtastic::SemanticFormBuilder.optional_string = " optional yo!" # ensure there's something in the string
|
81
82
|
@new_post.class.should_not_receive(:reflect_on_all_validations)
|
82
83
|
end
|
83
84
|
|
84
85
|
after do
|
85
|
-
Formtastic::SemanticFormBuilder.optional_string = ''
|
86
|
+
::Formtastic::SemanticFormBuilder.optional_string = ''
|
86
87
|
end
|
87
88
|
|
88
89
|
it 'should set an "optional" class' do
|
@@ -107,8 +108,8 @@ describe 'SemanticFormBuilder#input' do
|
|
107
108
|
describe 'and an object was not given' do
|
108
109
|
|
109
110
|
it 'should use the default value' do
|
110
|
-
Formtastic::SemanticFormBuilder.all_fields_required_by_default.should == true
|
111
|
-
Formtastic::SemanticFormBuilder.all_fields_required_by_default = false
|
111
|
+
::Formtastic::SemanticFormBuilder.all_fields_required_by_default.should == true
|
112
|
+
::Formtastic::SemanticFormBuilder.all_fields_required_by_default = false
|
112
113
|
|
113
114
|
semantic_form_for(:project, :url => 'http://test.host/') do |builder|
|
114
115
|
concat(builder.input(:title))
|
@@ -116,7 +117,7 @@ describe 'SemanticFormBuilder#input' do
|
|
116
117
|
output_buffer.should_not have_tag('form li.required')
|
117
118
|
output_buffer.should have_tag('form li.optional')
|
118
119
|
|
119
|
-
Formtastic::SemanticFormBuilder.all_fields_required_by_default = true
|
120
|
+
::Formtastic::SemanticFormBuilder.all_fields_required_by_default = true
|
120
121
|
end
|
121
122
|
|
122
123
|
end
|
@@ -225,8 +226,8 @@ describe 'SemanticFormBuilder#input' do
|
|
225
226
|
describe 'and the validation reflection plugin is not available' do
|
226
227
|
|
227
228
|
it 'should use the default value' do
|
228
|
-
Formtastic::SemanticFormBuilder.all_fields_required_by_default.should == true
|
229
|
-
Formtastic::SemanticFormBuilder.all_fields_required_by_default = false
|
229
|
+
::Formtastic::SemanticFormBuilder.all_fields_required_by_default.should == true
|
230
|
+
::Formtastic::SemanticFormBuilder.all_fields_required_by_default = false
|
230
231
|
|
231
232
|
semantic_form_for(@new_post) do |builder|
|
232
233
|
concat(builder.input(:title))
|
@@ -234,7 +235,7 @@ describe 'SemanticFormBuilder#input' do
|
|
234
235
|
output_buffer.should_not have_tag('form li.required')
|
235
236
|
output_buffer.should have_tag('form li.optional')
|
236
237
|
|
237
|
-
Formtastic::SemanticFormBuilder.all_fields_required_by_default = true
|
238
|
+
::Formtastic::SemanticFormBuilder.all_fields_required_by_default = true
|
238
239
|
end
|
239
240
|
|
240
241
|
end
|
@@ -330,12 +331,12 @@ describe 'SemanticFormBuilder#input' do
|
|
330
331
|
end
|
331
332
|
|
332
333
|
describe 'defaulting to file column' do
|
333
|
-
Formtastic::SemanticFormBuilder.file_methods.each do |method|
|
334
|
+
::Formtastic::SemanticFormBuilder.file_methods.each do |method|
|
334
335
|
it "should default to :file for attributes that respond to ##{method}" do
|
335
336
|
@new_post.stub!(:column_for_attribute).and_return(nil)
|
336
337
|
column = mock('column')
|
337
338
|
|
338
|
-
Formtastic::SemanticFormBuilder.file_methods.each do |test|
|
339
|
+
::Formtastic::SemanticFormBuilder.file_methods.each do |test|
|
339
340
|
column.stub!(:respond_to?).with(test).and_return(method == test)
|
340
341
|
end
|
341
342
|
|
@@ -401,25 +402,25 @@ describe 'SemanticFormBuilder#input' do
|
|
401
402
|
describe 'when localized label is NOT provided' do
|
402
403
|
describe 'and object is not given' do
|
403
404
|
it 'should default the humanized method name, passing it down to the label tag' do
|
404
|
-
Formtastic::SemanticFormBuilder.label_str_method = :humanize
|
405
|
-
|
405
|
+
::Formtastic::SemanticFormBuilder.label_str_method = :humanize
|
406
|
+
|
406
407
|
semantic_form_for(:project, :url => 'http://test.host') do |builder|
|
407
408
|
concat(builder.input(:meta_description))
|
408
409
|
end
|
409
|
-
|
410
|
+
|
410
411
|
output_buffer.should have_tag("form li label", /#{'meta_description'.humanize}/)
|
411
412
|
end
|
412
413
|
end
|
413
|
-
|
414
|
+
|
414
415
|
describe 'and object is given' do
|
415
416
|
it 'should delegate the label logic to class human attribute name and pass it down to the label tag' do
|
416
417
|
@new_post.stub!(:meta_description) # a two word method name
|
417
418
|
@new_post.class.should_receive(:human_attribute_name).with('meta_description').and_return('meta_description'.humanize)
|
418
|
-
|
419
|
+
|
419
420
|
semantic_form_for(@new_post) do |builder|
|
420
421
|
concat(builder.input(:meta_description))
|
421
422
|
end
|
422
|
-
|
423
|
+
|
423
424
|
output_buffer.should have_tag("form li label", /#{'meta_description'.humanize}/)
|
424
425
|
end
|
425
426
|
end
|
@@ -22,9 +22,9 @@ describe 'check_boxes input' do
|
|
22
22
|
it_should_call_find_on_association_class_when_no_collection_is_provided(:check_boxes)
|
23
23
|
it_should_use_the_collection_when_provided(:check_boxes, 'input[@type="checkbox"]')
|
24
24
|
|
25
|
-
it 'should generate a legend containing label text for the input' do
|
26
|
-
output_buffer.should have_tag('form li fieldset legend')
|
27
|
-
output_buffer.should have_tag('form li fieldset legend', /Posts/)
|
25
|
+
it 'should generate a legend - classified as a label - containing label text for the input' do
|
26
|
+
output_buffer.should have_tag('form li fieldset legend.label')
|
27
|
+
output_buffer.should have_tag('form li fieldset legend.label', /Posts/)
|
28
28
|
end
|
29
29
|
|
30
30
|
it 'should generate an ordered list with a list item for each choice' do
|
@@ -62,7 +62,7 @@ describe 'country input' do
|
|
62
62
|
end
|
63
63
|
|
64
64
|
it "should default to the @@priority_countries config when absent" do
|
65
|
-
priority_countries = Formtastic::SemanticFormBuilder.priority_countries
|
65
|
+
priority_countries = ::Formtastic::SemanticFormBuilder.priority_countries
|
66
66
|
priority_countries.should_not be_empty
|
67
67
|
priority_countries.should_not be_nil
|
68
68
|
|
@@ -19,8 +19,8 @@ describe 'date input' do
|
|
19
19
|
it_should_have_a_nested_fieldset
|
20
20
|
it_should_apply_error_logic_for_input_type(:date)
|
21
21
|
|
22
|
-
it 'should have a legend containing the label text inside the fieldset' do
|
23
|
-
output_buffer.should have_tag('form li.date fieldset legend', /Publish at/)
|
22
|
+
it 'should have a legend - classified as a label - containing the label text inside the fieldset' do
|
23
|
+
output_buffer.should have_tag('form li.date fieldset legend.label', /Publish at/)
|
24
24
|
end
|
25
25
|
|
26
26
|
it 'should have an ordered list of three items inside the fieldset' do
|
@@ -84,7 +84,7 @@ describe 'datetime input' do
|
|
84
84
|
end
|
85
85
|
|
86
86
|
it 'should be specified with :order option' do
|
87
|
-
I18n.backend.store_translations 'en', :date => { :order => [:month, :year, :day] }
|
87
|
+
::I18n.backend.store_translations 'en', :date => { :order => [:month, :year, :day] }
|
88
88
|
semantic_form_for(@new_post) do |builder|
|
89
89
|
self.should_receive(:select_month).once.ordered.and_return('')
|
90
90
|
self.should_receive(:select_year).once.ordered.and_return('')
|
@@ -105,7 +105,7 @@ describe 'datetime input' do
|
|
105
105
|
|
106
106
|
describe 'when the locale changes the label text' do
|
107
107
|
before do
|
108
|
-
I18n.backend.store_translations 'en', :datetime => {:prompts => {
|
108
|
+
::I18n.backend.store_translations 'en', :datetime => {:prompts => {
|
109
109
|
:year => 'The Year', :month => 'The Month', :day => 'The Day',
|
110
110
|
:hour => 'The Hour', :minute => 'The Minute'
|
111
111
|
}}
|
@@ -115,7 +115,7 @@ describe 'datetime input' do
|
|
115
115
|
end
|
116
116
|
|
117
117
|
after do
|
118
|
-
I18n.backend.store_translations 'en', :formtastic => {
|
118
|
+
::I18n.backend.store_translations 'en', :formtastic => {
|
119
119
|
:year => nil, :month => nil, :day => nil,
|
120
120
|
:hour => nil, :minute => nil
|
121
121
|
}
|
@@ -138,8 +138,8 @@ describe 'datetime input' do
|
|
138
138
|
end
|
139
139
|
end
|
140
140
|
|
141
|
-
it 'should have fieldset with legend' do
|
142
|
-
output_buffer.should have_tag('form li.datetime fieldset legend', /Publish at/)
|
141
|
+
it 'should have fieldset with legend - classified as a label' do
|
142
|
+
output_buffer.should have_tag('form li.datetime fieldset legend.label', /Publish at/)
|
143
143
|
end
|
144
144
|
|
145
145
|
it 'should have labels for each input' do
|
@@ -11,6 +11,8 @@ describe 'hidden input' do
|
|
11
11
|
|
12
12
|
semantic_form_for(@new_post) do |builder|
|
13
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}))
|
14
16
|
end
|
15
17
|
end
|
16
18
|
|
@@ -20,8 +22,17 @@ describe 'hidden input' do
|
|
20
22
|
|
21
23
|
it "should generate a input field" do
|
22
24
|
output_buffer.should have_tag("form li input#post_secret")
|
23
|
-
output_buffer.should have_tag("form li input[@type=\"hidden\"]")
|
24
|
-
output_buffer.should have_tag("form li input[@name=\"post[secret]\"]")
|
25
|
+
output_buffer.should have_tag("form li input#post_secret[@type=\"hidden\"]")
|
26
|
+
output_buffer.should have_tag("form li input#post_secret[@name=\"post[secret]\"]")
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should pass any explicitly specified value - using :value" do
|
30
|
+
output_buffer.should have_tag("form li input#post_author_id[@type=\"hidden\"][@value=\"99\"]")
|
31
|
+
end
|
32
|
+
|
33
|
+
# Handle Formtastic :input_html options for consistency.
|
34
|
+
it "should pass any explicitly specified value - using :input_html options" do
|
35
|
+
output_buffer.should have_tag("form li input#post_published[@type=\"hidden\"][@value=\"true\"]")
|
25
36
|
end
|
26
37
|
|
27
38
|
it "should not render inline errors" do
|
@@ -24,9 +24,9 @@ describe 'radio input' do
|
|
24
24
|
it_should_use_the_collection_when_provided(:radio, 'input')
|
25
25
|
|
26
26
|
|
27
|
-
it 'should generate a legend containing label text for the input' do
|
28
|
-
output_buffer.should have_tag('form li fieldset legend')
|
29
|
-
output_buffer.should have_tag('form li fieldset legend', /Author/)
|
27
|
+
it 'should generate a legend - classified as a label - containing label text for the input' do
|
28
|
+
output_buffer.should have_tag('form li fieldset legend.label')
|
29
|
+
output_buffer.should have_tag('form li fieldset legend.label', /Author/)
|
30
30
|
end
|
31
31
|
|
32
32
|
it 'should generate an ordered list with a list item for each choice' do
|
@@ -2,14 +2,51 @@
|
|
2
2
|
require File.dirname(__FILE__) + '/../spec_helper'
|
3
3
|
|
4
4
|
describe 'select input' do
|
5
|
-
|
5
|
+
|
6
6
|
include FormtasticSpecHelper
|
7
|
-
|
7
|
+
|
8
8
|
before do
|
9
9
|
@output_buffer = ''
|
10
10
|
mock_everything
|
11
11
|
end
|
12
|
-
|
12
|
+
|
13
|
+
describe 'explicit values' do
|
14
|
+
describe 'using an array of values' do
|
15
|
+
before do
|
16
|
+
@array_with_values = ["Title A", "Title B", "Title C"]
|
17
|
+
@array_with_keys_and_values = [["Title D", 1], ["Title E", 2], ["Title F", 3]]
|
18
|
+
semantic_form_for(@new_post) do |builder|
|
19
|
+
concat(builder.input(:title, :as => :select, :collection => @array_with_values))
|
20
|
+
concat(builder.input(:title, :as => :select, :collection => @array_with_keys_and_values))
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'should have a option for each key and/or value' do
|
25
|
+
@array_with_values.each do |v|
|
26
|
+
output_buffer.should have_tag("form li select option[@value='#{v}']", /^#{v}$/)
|
27
|
+
end
|
28
|
+
@array_with_keys_and_values.each do |v|
|
29
|
+
output_buffer.should have_tag("form li select option[@value='#{v.second}']", /^#{v.first}$/)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe 'using a range' do
|
35
|
+
before do
|
36
|
+
@range_with_values = 1..5
|
37
|
+
semantic_form_for(@new_post) do |builder|
|
38
|
+
concat(builder.input(:title, :as => :select, :collection => @range_with_values))
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'should have an option for each value' do
|
43
|
+
@range_with_values.each do |v|
|
44
|
+
output_buffer.should have_tag("form li select option[@value='#{v}']", /^#{v}$/)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
13
50
|
describe 'for a belongs_to association' do
|
14
51
|
before do
|
15
52
|
semantic_form_for(@new_post) do |builder|
|
@@ -259,5 +296,47 @@ describe 'select input' do
|
|
259
296
|
|
260
297
|
end
|
261
298
|
|
262
|
-
|
299
|
+
describe 'boolean select' do
|
300
|
+
describe 'default formtastic locale' do
|
301
|
+
before do
|
302
|
+
# Note: Works, but something like Formtastic.root.join(...) would probably be "safer".
|
303
|
+
::I18n.load_path = [File.join(File.dirname(__FILE__), *%w[.. .. lib locale en.yml])]
|
304
|
+
::I18n.backend.send(:init_translations)
|
305
|
+
|
306
|
+
semantic_form_for(@new_post) do |builder|
|
307
|
+
concat(builder.input(:published, :as => :select))
|
308
|
+
end
|
309
|
+
end
|
310
|
+
|
311
|
+
after do
|
312
|
+
::I18n.backend.store_translations :en, {}
|
313
|
+
end
|
263
314
|
|
315
|
+
it 'should render a select with at least options: true/false' do
|
316
|
+
output_buffer.should have_tag("form li select option[@value='true']", /^Yes$/)
|
317
|
+
output_buffer.should have_tag("form li select option[@value='false']", /^No$/)
|
318
|
+
end
|
319
|
+
end
|
320
|
+
|
321
|
+
describe 'custom locale' do
|
322
|
+
before do
|
323
|
+
@boolean_select_labels = {:yes => 'Yep', :no => 'Nope'}
|
324
|
+
::I18n.backend.store_translations :en, :formtastic => @boolean_select_labels
|
325
|
+
|
326
|
+
semantic_form_for(@new_post) do |builder|
|
327
|
+
concat(builder.input(:published, :as => :select))
|
328
|
+
end
|
329
|
+
end
|
330
|
+
|
331
|
+
after do
|
332
|
+
::I18n.backend.store_translations :en, {}
|
333
|
+
end
|
334
|
+
|
335
|
+
it 'should render a select with at least options: true/false' do
|
336
|
+
output_buffer.should have_tag("form li select option[@value='true']", /#{@boolean_select_labels[:yes]}/)
|
337
|
+
output_buffer.should have_tag("form li select option[@value='false']", /#{@boolean_select_labels[:no]}/)
|
338
|
+
end
|
339
|
+
end
|
340
|
+
end
|
341
|
+
|
342
|
+
end
|
@@ -19,8 +19,8 @@ describe 'time input' do
|
|
19
19
|
it_should_have_a_nested_fieldset
|
20
20
|
it_should_apply_error_logic_for_input_type(:time)
|
21
21
|
|
22
|
-
it 'should have a legend containing the label text inside the fieldset' do
|
23
|
-
output_buffer.should have_tag('form li.time fieldset legend', /Publish at/)
|
22
|
+
it 'should have a legend - classified as a label - containing the label text inside the fieldset' do
|
23
|
+
output_buffer.should have_tag('form li.time fieldset legend.label', /Publish at/)
|
24
24
|
end
|
25
25
|
|
26
26
|
it 'should have an ordered list of two items inside the fieldset' do
|