speedo-formstrap 1.2.3 → 1.2.4
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +2 -2
- data/Gemfile.lock +42 -40
- data/README.md +8 -15
- data/Rakefile +3 -3
- data/VERSION +1 -1
- data/formtastic-bootstrap.gemspec +133 -0
- data/lib/{speedo-formstrap → formtastic-bootstrap}/engine.rb +1 -1
- data/lib/{speedo-formstrap → formtastic-bootstrap}/form_builder.rb +9 -11
- data/lib/{speedo-formstrap → formtastic-bootstrap}/helpers/buttons_helper.rb +10 -14
- data/lib/{speedo-formstrap → formtastic-bootstrap}/helpers/fieldset_wrapper.rb +7 -12
- data/lib/{speedo-formstrap → formtastic-bootstrap}/helpers/input_helper.rb +2 -2
- data/lib/{speedo-formstrap → formtastic-bootstrap}/helpers/inputs_helper.rb +6 -6
- data/lib/{speedo-formstrap → formtastic-bootstrap}/helpers.rb +6 -8
- data/lib/formtastic-bootstrap/inputs/base/choices.rb +49 -0
- data/lib/{speedo-formstrap → formtastic-bootstrap}/inputs/base/errors.rb +1 -1
- data/lib/{speedo-formstrap → formtastic-bootstrap}/inputs/base/hints.rb +1 -1
- data/lib/{speedo-formstrap → formtastic-bootstrap}/inputs/base/html.rb +1 -1
- data/lib/formtastic-bootstrap/inputs/base/labelling.rb +18 -0
- data/lib/{speedo-formstrap → formtastic-bootstrap}/inputs/base/stringish.rb +1 -1
- data/lib/{speedo-formstrap → formtastic-bootstrap}/inputs/base/timeish.rb +13 -6
- data/lib/{speedo-formstrap → formtastic-bootstrap}/inputs/base/wrapping.rb +15 -33
- data/lib/formtastic-bootstrap/inputs/base.rb +22 -0
- data/lib/formtastic-bootstrap/inputs/boolean_input.rb +33 -0
- data/lib/{speedo-formstrap → formtastic-bootstrap}/inputs/check_boxes_input.rb +10 -11
- data/lib/{speedo-formstrap → formtastic-bootstrap}/inputs/date_input.rb +1 -1
- data/lib/{speedo-formstrap → formtastic-bootstrap}/inputs/datetime_input.rb +1 -1
- data/lib/{speedo-formstrap → formtastic-bootstrap}/inputs/email_input.rb +1 -1
- data/lib/{speedo-formstrap → formtastic-bootstrap}/inputs/file_input.rb +1 -1
- data/lib/formtastic-bootstrap/inputs/hidden_input.rb +12 -0
- data/lib/{speedo-formstrap → formtastic-bootstrap}/inputs/number_input.rb +3 -3
- data/lib/{speedo-formstrap → formtastic-bootstrap}/inputs/password_input.rb +1 -1
- data/lib/{speedo-formstrap → formtastic-bootstrap}/inputs/phone_input.rb +1 -1
- data/lib/{speedo-formstrap → formtastic-bootstrap}/inputs/radio_input.rb +13 -14
- data/lib/{speedo-formstrap → formtastic-bootstrap}/inputs/range_input.rb +3 -3
- data/lib/{speedo-formstrap → formtastic-bootstrap}/inputs/search_input.rb +1 -1
- data/lib/{speedo-formstrap → formtastic-bootstrap}/inputs/select_input.rb +1 -1
- data/lib/{speedo-formstrap → formtastic-bootstrap}/inputs/string_input.rb +1 -1
- data/lib/{speedo-formstrap → formtastic-bootstrap}/inputs/text_input.rb +1 -1
- data/lib/{speedo-formstrap → formtastic-bootstrap}/inputs/time_input.rb +1 -1
- data/lib/{speedo-formstrap → formtastic-bootstrap}/inputs/time_zone_input.rb +1 -1
- data/lib/{speedo-formstrap → formtastic-bootstrap}/inputs/url_input.rb +1 -1
- data/lib/formtastic-bootstrap/inputs.rb +29 -0
- data/lib/formtastic-bootstrap.rb +6 -0
- data/spec/builder/errors_spec.rb +214 -0
- data/spec/builder/semantic_fields_for_spec.rb +14 -14
- data/spec/helpers/buttons_helper_spec.rb +45 -55
- data/spec/helpers/input_helper_spec.rb +188 -188
- data/spec/helpers/inputs_helper_spec.rb +102 -116
- data/spec/inputs/boolean_input_spec.rb +44 -72
- data/spec/inputs/check_boxes_input_spec.rb +80 -108
- data/spec/inputs/date_input_spec.rb +14 -80
- data/spec/inputs/datetime_input_spec.rb +12 -12
- data/spec/inputs/email_input_spec.rb +5 -33
- data/spec/inputs/file_input_spec.rb +5 -33
- data/spec/inputs/hidden_input_spec.rb +12 -40
- data/spec/inputs/number_input_spec.rb +96 -126
- data/spec/inputs/password_input_spec.rb +5 -33
- data/spec/inputs/phone_input_spec.rb +5 -33
- data/spec/inputs/radio_input_spec.rb +44 -72
- data/spec/inputs/range_input_spec.rb +65 -93
- data/spec/inputs/search_input_spec.rb +5 -32
- data/spec/inputs/select_input_spec.rb +77 -123
- data/spec/inputs/string_input_spec.rb +21 -66
- data/spec/inputs/text_input_spec.rb +13 -40
- data/spec/inputs/time_input_spec.rb +22 -22
- data/spec/inputs/time_zone_input_spec.rb +17 -17
- data/spec/inputs/url_input_spec.rb +5 -33
- data/spec/spec_helper.rb +1 -1
- data/spec/support/custom_macros.rb +188 -59
- data/spec/support/formtastic_spec_helper.rb +3 -19
- data/vendor/assets/stylesheets/formtastic-bootstrap.css +3 -0
- metadata +62 -74
- data/lib/speedo-formstrap/actions/base.rb +0 -18
- data/lib/speedo-formstrap/actions/button_action.rb +0 -7
- data/lib/speedo-formstrap/actions/input_action.rb +0 -7
- data/lib/speedo-formstrap/actions/link_action.rb +0 -7
- data/lib/speedo-formstrap/actions.rb +0 -4
- data/lib/speedo-formstrap/helpers/action_helper.rb +0 -12
- data/lib/speedo-formstrap/helpers/actions_helper.rb +0 -23
- data/lib/speedo-formstrap/inputs/base/choices.rb +0 -38
- data/lib/speedo-formstrap/inputs/base/labelling.rb +0 -28
- data/lib/speedo-formstrap/inputs/base/numeric.rb +0 -18
- data/lib/speedo-formstrap/inputs/base.rb +0 -23
- data/lib/speedo-formstrap/inputs/boolean_input.rb +0 -29
- data/lib/speedo-formstrap/inputs/hidden_input.rb +0 -14
- data/lib/speedo-formstrap/inputs.rb +0 -29
- data/lib/speedo-formstrap.rb +0 -7
- data/spec/actions/button_action_spec.rb +0 -68
- data/spec/actions/generic_action_spec.rb +0 -486
- data/spec/actions/input_action_spec.rb +0 -64
- data/spec/actions/link_action_spec.rb +0 -93
- data/spec/helpers/action_helper_spec.rb +0 -365
- data/spec/helpers/actions_helper_spec.rb +0 -143
- data/speedo-formstrap.gemspec +0 -145
@@ -14,30 +14,28 @@ describe 'Formtastic::FormBuilder#buttons' do
|
|
14
14
|
describe 'with a block' do
|
15
15
|
describe 'when no options are provided' do
|
16
16
|
before do
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
end)
|
24
|
-
end
|
17
|
+
concat(semantic_form_for(@new_post) do |builder|
|
18
|
+
buttons = builder.buttons do
|
19
|
+
concat('hello')
|
20
|
+
end
|
21
|
+
concat(buttons)
|
22
|
+
end)
|
25
23
|
end
|
26
24
|
|
27
|
-
it 'should render a div inside the form, with a class of "
|
28
|
-
output_buffer.should have_tag("form div.
|
25
|
+
it 'should render a div inside the form, with a class of "actions"' do
|
26
|
+
output_buffer.should have_tag("form div.actions")
|
29
27
|
end
|
30
28
|
|
31
29
|
it 'should not render an ol inside the div' do
|
32
|
-
output_buffer.should_not have_tag("form div.
|
30
|
+
output_buffer.should_not have_tag("form div.actions ol")
|
33
31
|
end
|
34
32
|
|
35
33
|
it 'should render the contents of the block inside the input' do
|
36
|
-
output_buffer.should have_tag("form div.
|
34
|
+
output_buffer.should have_tag("form div.actions", /hello/)
|
37
35
|
end
|
38
36
|
|
39
37
|
it 'should not render a legend inside the div' do
|
40
|
-
output_buffer.should_not have_tag("form div.
|
38
|
+
output_buffer.should_not have_tag("form div.actions legend")
|
41
39
|
end
|
42
40
|
end
|
43
41
|
|
@@ -46,12 +44,10 @@ describe 'Formtastic::FormBuilder#buttons' do
|
|
46
44
|
@id_option = 'advanced'
|
47
45
|
@class_option = 'wide'
|
48
46
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
end)
|
54
|
-
end
|
47
|
+
concat(semantic_form_for(@new_post) do |builder|
|
48
|
+
builder.buttons :id => @id_option, :class => @class_option do
|
49
|
+
end
|
50
|
+
end)
|
55
51
|
end
|
56
52
|
it 'should pass the options into the div tag as attributes' do
|
57
53
|
output_buffer.should have_tag("form div##{@id_option}")
|
@@ -66,31 +62,29 @@ describe 'Formtastic::FormBuilder#buttons' do
|
|
66
62
|
describe 'with no args (default buttons)' do
|
67
63
|
|
68
64
|
before do
|
69
|
-
|
70
|
-
concat(
|
71
|
-
|
72
|
-
end)
|
73
|
-
end
|
65
|
+
concat(semantic_form_for(@new_post) do |builder|
|
66
|
+
concat(builder.buttons)
|
67
|
+
end)
|
74
68
|
end
|
75
69
|
|
76
70
|
it 'should render a form' do
|
77
71
|
output_buffer.should have_tag('form')
|
78
72
|
end
|
79
73
|
|
80
|
-
it 'should render a "
|
81
|
-
output_buffer.should have_tag('form div.
|
74
|
+
it 'should render a "actions" div inside the form' do
|
75
|
+
output_buffer.should have_tag('form div.actions')
|
82
76
|
end
|
83
77
|
|
84
78
|
it 'should not render a legend in the div' do
|
85
|
-
output_buffer.should_not have_tag('form div.
|
79
|
+
output_buffer.should_not have_tag('form div.actions legend')
|
86
80
|
end
|
87
81
|
|
88
82
|
it 'should render an button item in the ol for each default button' do
|
89
|
-
output_buffer.should have_tag('form div.
|
83
|
+
output_buffer.should have_tag('form div.actions input.btn', :count => 1)
|
90
84
|
end
|
91
85
|
|
92
86
|
it 'should render a commit list item for the commit button' do
|
93
|
-
output_buffer.should have_tag('form div.
|
87
|
+
output_buffer.should have_tag('form div.actions input.commit')
|
94
88
|
end
|
95
89
|
|
96
90
|
end
|
@@ -98,24 +92,22 @@ describe 'Formtastic::FormBuilder#buttons' do
|
|
98
92
|
describe 'with button names as args' do
|
99
93
|
|
100
94
|
before do
|
101
|
-
|
102
|
-
concat(
|
103
|
-
|
104
|
-
end)
|
105
|
-
end
|
95
|
+
concat(semantic_form_for(@new_post) do |builder|
|
96
|
+
concat(builder.buttons(:commit))
|
97
|
+
end)
|
106
98
|
end
|
107
99
|
|
108
100
|
it 'should render a form with a div containing an input for each button arg' do
|
109
|
-
output_buffer.should have_tag('form > div.
|
110
|
-
output_buffer.should have_tag('form > div.
|
101
|
+
output_buffer.should have_tag('form > div.actions > input', :count => 1)
|
102
|
+
output_buffer.should have_tag('form > div.actions > input.commit')
|
111
103
|
end
|
112
104
|
|
113
105
|
end
|
114
106
|
|
115
107
|
describe 'with :names' do
|
116
|
-
|
108
|
+
|
117
109
|
before do
|
118
|
-
ActiveSupport::Deprecation.should_receive(:warn)
|
110
|
+
ActiveSupport::Deprecation.should_receive(:warn)
|
119
111
|
concat(
|
120
112
|
semantic_form_for(@new_post) do |builder|
|
121
113
|
concat(builder.buttons(:commit, :name => "Now click a button"))
|
@@ -128,31 +120,29 @@ describe 'Formtastic::FormBuilder#buttons' do
|
|
128
120
|
end
|
129
121
|
|
130
122
|
end
|
131
|
-
|
132
|
-
|
123
|
+
|
124
|
+
|
133
125
|
describe 'with button names and an options hash' do
|
134
|
-
|
126
|
+
|
135
127
|
before do
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
)
|
142
|
-
end
|
128
|
+
concat(
|
129
|
+
semantic_form_for(@new_post) do |builder|
|
130
|
+
concat(builder.buttons(:commit, :id => "my-id"))
|
131
|
+
end
|
132
|
+
)
|
143
133
|
end
|
144
|
-
|
134
|
+
|
145
135
|
it 'should render a form with a div containing a input for each button arg' do
|
146
|
-
output_buffer.should have_tag('form > div.
|
147
|
-
output_buffer.should have_tag('form > div.
|
136
|
+
output_buffer.should have_tag('form > div.actions > input', :count => 1)
|
137
|
+
output_buffer.should have_tag('form > div.actions > input.commit', :count => 1)
|
148
138
|
end
|
149
|
-
|
139
|
+
|
150
140
|
it 'should pass the options down to the div' do
|
151
|
-
output_buffer.should have_tag('form > div#my-id.
|
141
|
+
output_buffer.should have_tag('form > div#my-id.actions')
|
152
142
|
end
|
153
|
-
|
143
|
+
|
154
144
|
end
|
155
|
-
|
145
|
+
|
156
146
|
end
|
157
147
|
|
158
148
|
end
|
@@ -31,49 +31,49 @@ describe 'FormtasticBootstrap::FormBuilder#input' do
|
|
31
31
|
end
|
32
32
|
|
33
33
|
describe ':required option' do
|
34
|
-
|
34
|
+
|
35
35
|
describe 'when true' do
|
36
|
-
|
36
|
+
|
37
37
|
it 'should set a "required" class' do
|
38
38
|
with_config :required_string, " required yo!" do
|
39
39
|
concat(semantic_form_for(@new_post) do |builder|
|
40
40
|
concat(builder.input(:title, :required => true))
|
41
41
|
end)
|
42
|
-
output_buffer.should_not have_tag('form div.
|
43
|
-
output_buffer.should have_tag('form div.
|
42
|
+
output_buffer.should_not have_tag('form div.clearfix.optional')
|
43
|
+
output_buffer.should have_tag('form div.clearfix.required')
|
44
44
|
end
|
45
45
|
end
|
46
|
-
|
46
|
+
|
47
47
|
it 'should append the "required" string to the label' do
|
48
48
|
with_config :required_string, " required yo!" do
|
49
49
|
concat(semantic_form_for(@new_post) do |builder|
|
50
50
|
concat(builder.input(:title, :required => true))
|
51
51
|
end)
|
52
|
-
output_buffer.should have_tag('form div.
|
52
|
+
output_buffer.should have_tag('form div.clearfix.required label', /required yo/)
|
53
53
|
end
|
54
54
|
end
|
55
55
|
end
|
56
|
-
|
56
|
+
|
57
57
|
describe 'when false' do
|
58
|
-
|
58
|
+
|
59
59
|
before(:each) do
|
60
60
|
@orig_optional_string = FormtasticBootstrap::FormBuilder.optional_string
|
61
61
|
@string = FormtasticBootstrap::FormBuilder.optional_string = " optional yo!" # ensure there's something in the string
|
62
62
|
@new_post.class.should_not_receive(:reflect_on_all_validations)
|
63
63
|
end
|
64
|
-
|
64
|
+
|
65
65
|
after(:each) do
|
66
66
|
FormtasticBootstrap::FormBuilder.optional_string = @orig_optional_string
|
67
67
|
end
|
68
|
-
|
68
|
+
|
69
69
|
it 'should set an "optional" class' do
|
70
70
|
concat(semantic_form_for(@new_post) do |builder|
|
71
71
|
concat(builder.input(:title, :required => false))
|
72
72
|
end)
|
73
|
-
output_buffer.should_not have_tag('form div.
|
74
|
-
output_buffer.should have_tag('form div.
|
73
|
+
output_buffer.should_not have_tag('form div.clearfix.required')
|
74
|
+
output_buffer.should have_tag('form div.clearfix.optional')
|
75
75
|
end
|
76
|
-
|
76
|
+
|
77
77
|
it 'should set and "optional" class also when there is presence validator' do
|
78
78
|
@new_post.class.should_receive(:validators_on).with(:title).any_number_of_times.and_return([
|
79
79
|
active_model_presence_validator([:title])
|
@@ -81,72 +81,72 @@ describe 'FormtasticBootstrap::FormBuilder#input' do
|
|
81
81
|
concat(semantic_form_for(@new_post) do |builder|
|
82
82
|
concat(builder.input(:title, :required => false))
|
83
83
|
end)
|
84
|
-
output_buffer.should_not have_tag('form div.
|
85
|
-
output_buffer.should have_tag('form div.
|
84
|
+
output_buffer.should_not have_tag('form div.clearfix.required')
|
85
|
+
output_buffer.should have_tag('form div.clearfix.optional')
|
86
86
|
end
|
87
|
-
|
87
|
+
|
88
88
|
it 'should append the "optional" string to the label' do
|
89
89
|
concat(semantic_form_for(@new_post) do |builder|
|
90
90
|
concat(builder.input(:title, :required => false))
|
91
91
|
end)
|
92
|
-
output_buffer.should have_tag('form div.
|
92
|
+
output_buffer.should have_tag('form div.clearfix.optional label', /#{@string}$/)
|
93
93
|
end
|
94
|
-
|
94
|
+
|
95
95
|
end
|
96
|
-
|
96
|
+
|
97
97
|
describe 'when not provided' do
|
98
|
-
|
98
|
+
|
99
99
|
describe 'and an object was not given' do
|
100
|
-
|
100
|
+
|
101
101
|
before(:each) do
|
102
102
|
@orig_all_fields_required = FormtasticBootstrap::FormBuilder.all_fields_required_by_default
|
103
103
|
end
|
104
|
-
|
104
|
+
|
105
105
|
after(:each) do
|
106
|
-
FormtasticBootstrap::FormBuilder.all_fields_required_by_default = @orig_all_fields_required
|
106
|
+
FormtasticBootstrap::FormBuilder.all_fields_required_by_default = @orig_all_fields_required
|
107
107
|
end
|
108
|
-
|
108
|
+
|
109
109
|
it 'should use the default value' do
|
110
110
|
FormtasticBootstrap::FormBuilder.all_fields_required_by_default.should == true
|
111
111
|
FormtasticBootstrap::FormBuilder.all_fields_required_by_default = false
|
112
|
-
|
112
|
+
|
113
113
|
concat(semantic_form_for(:project, :url => 'http://test.host/') do |builder|
|
114
114
|
concat(builder.input(:title))
|
115
115
|
end)
|
116
|
-
output_buffer.should_not have_tag('form div.
|
117
|
-
output_buffer.should have_tag('form div.
|
118
|
-
|
116
|
+
output_buffer.should_not have_tag('form div.clearfix.required')
|
117
|
+
output_buffer.should have_tag('form div.clearfix.optional')
|
118
|
+
|
119
119
|
end
|
120
|
-
|
120
|
+
|
121
121
|
end
|
122
|
-
|
122
|
+
|
123
123
|
describe 'and an object with :validators_on was given (ActiveModel, Active Resource)' do
|
124
124
|
before do
|
125
125
|
@new_post.stub!(:class).and_return(::PostModel)
|
126
126
|
end
|
127
|
-
|
127
|
+
|
128
128
|
after do
|
129
129
|
@new_post.stub!(:class).and_return(::Post)
|
130
130
|
end
|
131
131
|
describe 'and validates_presence_of was called for the method' do
|
132
132
|
it 'should be required' do
|
133
|
-
|
133
|
+
|
134
134
|
@new_post.class.should_receive(:validators_on).with(:title).any_number_of_times.and_return([
|
135
135
|
active_model_presence_validator([:title])
|
136
136
|
])
|
137
|
-
|
137
|
+
|
138
138
|
@new_post.class.should_receive(:validators_on).with(:body).any_number_of_times.and_return([
|
139
139
|
active_model_presence_validator([:body], {:if => true})
|
140
140
|
])
|
141
|
-
|
141
|
+
|
142
142
|
concat(semantic_form_for(@new_post) do |builder|
|
143
143
|
concat(builder.input(:title))
|
144
144
|
concat(builder.input(:body))
|
145
145
|
end)
|
146
|
-
output_buffer.should have_tag('form div.
|
147
|
-
output_buffer.should_not have_tag('form div.
|
146
|
+
output_buffer.should have_tag('form div.clearfix.required')
|
147
|
+
output_buffer.should_not have_tag('form div.clearfix.optional')
|
148
148
|
end
|
149
|
-
|
149
|
+
|
150
150
|
it 'should be required when there is :on => :create option on create' do
|
151
151
|
with_config :required_string, " required yo!" do
|
152
152
|
@new_post.class.should_receive(:validators_on).with(:title).any_number_of_times.and_return([
|
@@ -155,11 +155,11 @@ describe 'FormtasticBootstrap::FormBuilder#input' do
|
|
155
155
|
concat(semantic_form_for(@new_post) do |builder|
|
156
156
|
concat(builder.input(:title))
|
157
157
|
end)
|
158
|
-
output_buffer.should have_tag('form div.
|
159
|
-
output_buffer.should_not have_tag('form div.
|
158
|
+
output_buffer.should have_tag('form div.clearfix.required')
|
159
|
+
output_buffer.should_not have_tag('form div.clearfix.optional')
|
160
160
|
end
|
161
161
|
end
|
162
|
-
|
162
|
+
|
163
163
|
it 'should be required when there is :on => :save option on create' do
|
164
164
|
with_config :required_string, " required yo!" do
|
165
165
|
@new_post.class.should_receive(:validators_on).with(:title).any_number_of_times.and_return([
|
@@ -168,11 +168,11 @@ describe 'FormtasticBootstrap::FormBuilder#input' do
|
|
168
168
|
concat(semantic_form_for(@new_post) do |builder|
|
169
169
|
concat(builder.input(:title))
|
170
170
|
end)
|
171
|
-
output_buffer.should have_tag('form div.
|
172
|
-
output_buffer.should_not have_tag('form div.
|
171
|
+
output_buffer.should have_tag('form div.clearfix.required')
|
172
|
+
output_buffer.should_not have_tag('form div.clearfix.optional')
|
173
173
|
end
|
174
174
|
end
|
175
|
-
|
175
|
+
|
176
176
|
it 'should be required when there is :on => :save option on update' do
|
177
177
|
with_config :required_string, " required yo!" do
|
178
178
|
@fred.class.should_receive(:validators_on).with(:login).any_number_of_times.and_return([
|
@@ -181,11 +181,11 @@ describe 'FormtasticBootstrap::FormBuilder#input' do
|
|
181
181
|
concat(semantic_form_for(@fred) do |builder|
|
182
182
|
concat(builder.input(:login))
|
183
183
|
end)
|
184
|
-
output_buffer.should have_tag('form div.
|
185
|
-
output_buffer.should_not have_tag('form div.
|
184
|
+
output_buffer.should have_tag('form div.clearfix.required')
|
185
|
+
output_buffer.should_not have_tag('form div.clearfix.optional')
|
186
186
|
end
|
187
187
|
end
|
188
|
-
|
188
|
+
|
189
189
|
it 'should not be required when there is :on => :create option on update' do
|
190
190
|
@fred.class.should_receive(:validators_on).with(:login).any_number_of_times.and_return([
|
191
191
|
active_model_presence_validator([:login], {:on => :create})
|
@@ -193,10 +193,10 @@ describe 'FormtasticBootstrap::FormBuilder#input' do
|
|
193
193
|
concat(semantic_form_for(@fred) do |builder|
|
194
194
|
concat(builder.input(:login))
|
195
195
|
end)
|
196
|
-
output_buffer.should_not have_tag('form div.
|
197
|
-
output_buffer.should have_tag('form div.
|
196
|
+
output_buffer.should_not have_tag('form div.clearfix.required')
|
197
|
+
output_buffer.should have_tag('form div.clearfix.optional')
|
198
198
|
end
|
199
|
-
|
199
|
+
|
200
200
|
it 'should not be required when there is :on => :update option on create' do
|
201
201
|
@new_post.class.should_receive(:validators_on).with(:title).any_number_of_times.and_return([
|
202
202
|
active_model_presence_validator([:title], {:on => :update})
|
@@ -204,51 +204,51 @@ describe 'FormtasticBootstrap::FormBuilder#input' do
|
|
204
204
|
concat(semantic_form_for(@new_post) do |builder|
|
205
205
|
concat(builder.input(:title))
|
206
206
|
end)
|
207
|
-
output_buffer.should_not have_tag('form div.
|
208
|
-
output_buffer.should have_tag('form div.
|
207
|
+
output_buffer.should_not have_tag('form div.clearfix.required')
|
208
|
+
output_buffer.should have_tag('form div.clearfix.optional')
|
209
209
|
end
|
210
|
-
|
210
|
+
|
211
211
|
it 'should be not be required if the optional :if condition is not satisifed' do
|
212
212
|
presence_should_be_required(:required => false, :tag => :body, :options => { :if => false })
|
213
213
|
end
|
214
|
-
|
214
|
+
|
215
215
|
it 'should not be required if the optional :if proc evaluates to false' do
|
216
216
|
presence_should_be_required(:required => false, :tag => :body, :options => { :if => proc { |record| false } })
|
217
217
|
end
|
218
|
-
|
218
|
+
|
219
219
|
it 'should be required if the optional :if proc evaluates to true' do
|
220
220
|
presence_should_be_required(:required => true, :tag => :body, :options => { :if => proc { |record| true } })
|
221
221
|
end
|
222
|
-
|
222
|
+
|
223
223
|
it 'should not be required if the optional :unless proc evaluates to true' do
|
224
224
|
presence_should_be_required(:required => false, :tag => :body, :options => { :unless => proc { |record| true } })
|
225
225
|
end
|
226
|
-
|
226
|
+
|
227
227
|
it 'should be required if the optional :unless proc evaluates to false' do
|
228
228
|
presence_should_be_required(:required => true, :tag => :body, :options => { :unless => proc { |record| false } })
|
229
229
|
end
|
230
|
-
|
230
|
+
|
231
231
|
it 'should be required if the optional :if with a method string evaluates to true' do
|
232
232
|
@new_post.should_receive(:required_condition).and_return(true)
|
233
233
|
presence_should_be_required(:required => true, :tag => :body, :options => { :if => :required_condition })
|
234
234
|
end
|
235
|
-
|
235
|
+
|
236
236
|
it 'should be required if the optional :if with a method string evaluates to false' do
|
237
237
|
@new_post.should_receive(:required_condition).and_return(false)
|
238
238
|
presence_should_be_required(:required => false, :tag => :body, :options => { :if => :required_condition })
|
239
239
|
end
|
240
|
-
|
240
|
+
|
241
241
|
it 'should be required if the optional :unless with a method string evaluates to false' do
|
242
242
|
@new_post.should_receive(:required_condition).and_return(false)
|
243
243
|
presence_should_be_required(:required => true, :tag => :body, :options => { :unless => :required_condition })
|
244
244
|
end
|
245
|
-
|
245
|
+
|
246
246
|
it 'should not be required if the optional :unless with a method string evaluates to true' do
|
247
247
|
@new_post.should_receive(:required_condition).and_return(true)
|
248
248
|
presence_should_be_required(:required => false, :tag => :body, :options => { :unless => :required_condition })
|
249
249
|
end
|
250
250
|
end
|
251
|
-
|
251
|
+
|
252
252
|
describe 'and validates_inclusion_of was called for the method' do
|
253
253
|
it 'should be required' do
|
254
254
|
@new_post.class.should_receive(:validators_on).with(:published).any_number_of_times.and_return([
|
@@ -256,7 +256,7 @@ describe 'FormtasticBootstrap::FormBuilder#input' do
|
|
256
256
|
])
|
257
257
|
should_be_required(:tag => :published, :required => true)
|
258
258
|
end
|
259
|
-
|
259
|
+
|
260
260
|
it 'should not be required if allow_blank is true' do
|
261
261
|
@new_post.class.should_receive(:validators_on).with(:published).any_number_of_times.and_return([
|
262
262
|
active_model_inclusion_validator([:published], {:in => [false, true], :allow_blank => true})
|
@@ -264,251 +264,251 @@ describe 'FormtasticBootstrap::FormBuilder#input' do
|
|
264
264
|
should_be_required(:tag => :published, :required => false)
|
265
265
|
end
|
266
266
|
end
|
267
|
-
|
267
|
+
|
268
268
|
describe 'and validates_length_of was called for the method' do
|
269
269
|
it 'should be required if minimum is set' do
|
270
270
|
length_should_be_required(:tag => :title, :required => true, :options => {:minimum => 1})
|
271
271
|
end
|
272
|
-
|
272
|
+
|
273
273
|
it 'should be required if :within is set' do
|
274
274
|
length_should_be_required(:tag => :title, :required => true, :options => {:within => 1..5})
|
275
275
|
end
|
276
|
-
|
276
|
+
|
277
277
|
it 'should not be required if :within allows zero length' do
|
278
278
|
length_should_be_required(:tag => :title, :required => false, :options => {:within => 0..5})
|
279
279
|
end
|
280
|
-
|
280
|
+
|
281
281
|
it 'should not be required if only :minimum is zero' do
|
282
282
|
length_should_be_required(:tag => :title, :required => false, :options => {:minimum => 0})
|
283
283
|
end
|
284
|
-
|
284
|
+
|
285
285
|
it 'should not be required if only :minimum is not set' do
|
286
286
|
length_should_be_required(:tag => :title, :required => false, :options => {:maximum => 5})
|
287
287
|
end
|
288
|
-
|
288
|
+
|
289
289
|
it 'should not be required if allow_blank is true' do
|
290
290
|
length_should_be_required(:tag => :published, :required => false, :options => {:allow_blank => true})
|
291
291
|
end
|
292
292
|
end
|
293
|
-
|
293
|
+
|
294
294
|
def add_presence_validator(options)
|
295
295
|
@new_post.class.stub!(:validators_on).with(options[:tag]).and_return([
|
296
296
|
active_model_presence_validator([options[:tag]], options[:options])
|
297
297
|
])
|
298
298
|
end
|
299
|
-
|
299
|
+
|
300
300
|
def add_length_validator(options)
|
301
301
|
@new_post.class.should_receive(:validators_on).with(options[:tag]).any_number_of_times {[
|
302
302
|
active_model_length_validator([options[:tag]], options[:options])
|
303
303
|
]}
|
304
304
|
end
|
305
|
-
|
305
|
+
|
306
306
|
# TODO make a matcher for this?
|
307
307
|
def should_be_required(options)
|
308
308
|
concat(semantic_form_for(@new_post) do |builder|
|
309
309
|
concat(builder.input(options[:tag]))
|
310
310
|
end)
|
311
|
-
|
311
|
+
|
312
312
|
if options[:required]
|
313
|
-
output_buffer.should_not have_tag('form div.
|
314
|
-
output_buffer.should have_tag('form div.
|
313
|
+
output_buffer.should_not have_tag('form div.clearfix.optional')
|
314
|
+
output_buffer.should have_tag('form div.clearfix.required')
|
315
315
|
else
|
316
|
-
output_buffer.should have_tag('form div.
|
317
|
-
output_buffer.should_not have_tag('form div.
|
316
|
+
output_buffer.should have_tag('form div.clearfix.optional')
|
317
|
+
output_buffer.should_not have_tag('form div.clearfix.required')
|
318
318
|
end
|
319
319
|
end
|
320
|
-
|
320
|
+
|
321
321
|
def presence_should_be_required(options)
|
322
322
|
add_presence_validator(options)
|
323
323
|
should_be_required(options)
|
324
324
|
end
|
325
|
-
|
325
|
+
|
326
326
|
def length_should_be_required(options)
|
327
327
|
add_length_validator(options)
|
328
328
|
should_be_required(options)
|
329
329
|
end
|
330
|
-
|
330
|
+
|
331
331
|
# TODO JF reversed this during refactor, need to make sure
|
332
332
|
describe 'and there are no requirement validations on the method' do
|
333
333
|
before do
|
334
334
|
@new_post.class.should_receive(:validators_on).with(:title).and_return([])
|
335
335
|
end
|
336
|
-
|
336
|
+
|
337
337
|
it 'should not be required' do
|
338
338
|
concat(semantic_form_for(@new_post) do |builder|
|
339
339
|
concat(builder.input(:title))
|
340
340
|
end)
|
341
|
-
output_buffer.should_not have_tag('form div.
|
342
|
-
output_buffer.should have_tag('form div.
|
341
|
+
output_buffer.should_not have_tag('form div.clearfix.required')
|
342
|
+
output_buffer.should have_tag('form div.clearfix.optional')
|
343
343
|
end
|
344
344
|
end
|
345
|
-
|
345
|
+
|
346
346
|
end
|
347
|
-
|
347
|
+
|
348
348
|
describe 'and an object without :validators_on' do
|
349
|
-
|
349
|
+
|
350
350
|
before(:each) do
|
351
351
|
@orig_all_fields_required = FormtasticBootstrap::FormBuilder.all_fields_required_by_default
|
352
352
|
end
|
353
|
-
|
353
|
+
|
354
354
|
after(:each) do
|
355
|
-
FormtasticBootstrap::FormBuilder.all_fields_required_by_default = @orig_all_fields_required
|
355
|
+
FormtasticBootstrap::FormBuilder.all_fields_required_by_default = @orig_all_fields_required
|
356
356
|
end
|
357
|
-
|
357
|
+
|
358
358
|
it 'should use the default value' do
|
359
359
|
FormtasticBootstrap::FormBuilder.all_fields_required_by_default.should == true
|
360
360
|
FormtasticBootstrap::FormBuilder.all_fields_required_by_default = false
|
361
|
-
|
361
|
+
|
362
362
|
concat(semantic_form_for(@new_post) do |builder|
|
363
363
|
concat(builder.input(:title))
|
364
364
|
end)
|
365
|
-
output_buffer.should_not have_tag('form div.
|
366
|
-
output_buffer.should have_tag('form div.
|
367
|
-
|
365
|
+
output_buffer.should_not have_tag('form div.clearfix.required')
|
366
|
+
output_buffer.should have_tag('form div.clearfix.optional')
|
367
|
+
|
368
368
|
# Formtastic::FormBuilder.all_fields_required_by_default = true
|
369
369
|
end
|
370
|
-
|
370
|
+
|
371
371
|
end
|
372
|
-
|
372
|
+
|
373
373
|
end
|
374
|
-
|
374
|
+
|
375
375
|
end
|
376
376
|
|
377
377
|
describe ':as option' do
|
378
|
-
|
378
|
+
|
379
379
|
describe 'when not provided' do
|
380
|
-
|
380
|
+
|
381
381
|
it 'should default to a string for forms without objects unless column is password' do
|
382
382
|
concat(semantic_form_for(:project, :url => 'http://test.host') do |builder|
|
383
383
|
concat(builder.input(:anything))
|
384
384
|
end)
|
385
|
-
output_buffer.should have_tag('form div.
|
385
|
+
output_buffer.should have_tag('form div.clearfix.string')
|
386
386
|
end
|
387
|
-
|
387
|
+
|
388
388
|
it 'should default to password for forms without objects if column is password' do
|
389
389
|
concat(semantic_form_for(:project, :url => 'http://test.host') do |builder|
|
390
390
|
concat(builder.input(:password))
|
391
391
|
concat(builder.input(:password_confirmation))
|
392
392
|
concat(builder.input(:confirm_password))
|
393
393
|
end)
|
394
|
-
output_buffer.should have_tag('form div.
|
394
|
+
output_buffer.should have_tag('form div.clearfix.password', :count => 3)
|
395
395
|
end
|
396
|
-
|
396
|
+
|
397
397
|
it 'should default to a string for methods on objects that don\'t respond to "column_for_attribute"' do
|
398
398
|
@new_post.stub!(:method_without_a_database_column)
|
399
399
|
@new_post.stub!(:column_for_attribute).and_return(nil)
|
400
400
|
default_input_type(nil, :method_without_a_database_column).should == :string
|
401
401
|
end
|
402
|
-
|
402
|
+
|
403
403
|
it 'should default to :password for methods that don\'t have a column in the database but "password" is in the method name' do
|
404
404
|
@new_post.stub!(:password_method_without_a_database_column)
|
405
405
|
@new_post.stub!(:column_for_attribute).and_return(nil)
|
406
406
|
default_input_type(nil, :password_method_without_a_database_column).should == :password
|
407
407
|
end
|
408
|
-
|
408
|
+
|
409
409
|
it 'should default to :password for methods on objects that don\'t respond to "column_for_attribute" but "password" is in the method name' do
|
410
410
|
@new_post.stub!(:password_method_without_a_database_column)
|
411
411
|
@new_post.stub!(:column_for_attribute).and_return(nil)
|
412
412
|
default_input_type(nil, :password_method_without_a_database_column).should == :password
|
413
413
|
end
|
414
|
-
|
414
|
+
|
415
415
|
it 'should default to :number for "integer" column with name ending in "_id"' do
|
416
416
|
@new_post.stub!(:aws_instance_id)
|
417
417
|
@new_post.stub!(:column_for_attribute).with(:aws_instance_id).and_return(mock('column', :type => :integer))
|
418
418
|
default_input_type(:integer, :aws_instance_id).should == :number
|
419
419
|
end
|
420
|
-
|
420
|
+
|
421
421
|
it 'should default to :select for associations' do
|
422
422
|
@new_post.class.stub!(:reflect_on_association).with(:user_id).and_return(mock('ActiveRecord::Reflection::AssociationReflection'))
|
423
423
|
@new_post.class.stub!(:reflect_on_association).with(:section_id).and_return(mock('ActiveRecord::Reflection::AssociationReflection'))
|
424
424
|
default_input_type(:integer, :user_id).should == :select
|
425
425
|
default_input_type(:integer, :section_id).should == :select
|
426
426
|
end
|
427
|
-
|
427
|
+
|
428
428
|
it 'should default to :password for :string column types with "password" in the method name' do
|
429
429
|
default_input_type(:string, :password).should == :password
|
430
430
|
default_input_type(:string, :hashed_password).should == :password
|
431
431
|
default_input_type(:string, :password_hash).should == :password
|
432
432
|
end
|
433
|
-
|
433
|
+
|
434
434
|
it 'should default to :text for :text column types' do
|
435
435
|
default_input_type(:text).should == :text
|
436
436
|
end
|
437
|
-
|
437
|
+
|
438
438
|
it 'should default to :date for :date column types' do
|
439
439
|
default_input_type(:date).should == :date
|
440
440
|
end
|
441
|
-
|
441
|
+
|
442
442
|
it 'should default to :datetime for :datetime and :timestamp column types' do
|
443
443
|
default_input_type(:datetime).should == :datetime
|
444
444
|
default_input_type(:timestamp).should == :datetime
|
445
445
|
end
|
446
|
-
|
446
|
+
|
447
447
|
it 'should default to :time for :time column types' do
|
448
448
|
default_input_type(:time).should == :time
|
449
449
|
end
|
450
|
-
|
450
|
+
|
451
451
|
it 'should default to :boolean for :boolean column types' do
|
452
452
|
default_input_type(:boolean).should == :boolean
|
453
453
|
end
|
454
|
-
|
454
|
+
|
455
455
|
it 'should default to :string for :string column types' do
|
456
456
|
default_input_type(:string).should == :string
|
457
457
|
end
|
458
|
-
|
458
|
+
|
459
459
|
it 'should default to :number for :integer, :float and :decimal column types' do
|
460
460
|
default_input_type(:integer).should == :number
|
461
461
|
default_input_type(:float).should == :number
|
462
462
|
default_input_type(:decimal).should == :number
|
463
463
|
end
|
464
|
-
|
464
|
+
|
465
465
|
it 'should default to :country for :string columns named country' do
|
466
466
|
default_input_type(:string, :country).should == :country
|
467
467
|
end
|
468
|
-
|
468
|
+
|
469
469
|
it 'should default to :email for :string columns matching email' do
|
470
470
|
default_input_type(:string, :email).should == :email
|
471
471
|
default_input_type(:string, :customer_email).should == :email
|
472
472
|
default_input_type(:string, :email_work).should == :email
|
473
473
|
end
|
474
|
-
|
474
|
+
|
475
475
|
it 'should default to :url for :string columns named url or website' do
|
476
476
|
default_input_type(:string, :url).should == :url
|
477
477
|
default_input_type(:string, :website).should == :url
|
478
478
|
default_input_type(:string, :my_url).should == :url
|
479
479
|
default_input_type(:string, :hurl).should_not == :url
|
480
480
|
end
|
481
|
-
|
481
|
+
|
482
482
|
it 'should default to :phone for :string columns named phone or fax' do
|
483
483
|
default_input_type(:string, :phone).should == :phone
|
484
484
|
default_input_type(:string, :fax).should == :phone
|
485
485
|
end
|
486
|
-
|
486
|
+
|
487
487
|
it 'should default to :search for :string columns named search' do
|
488
488
|
default_input_type(:string, :search).should == :search
|
489
489
|
end
|
490
|
-
|
490
|
+
|
491
491
|
describe 'defaulting to file column' do
|
492
492
|
FormtasticBootstrap::FormBuilder.file_methods.each do |method|
|
493
493
|
it "should default to :file for attributes that respond to ##{method}" do
|
494
494
|
column = mock('column')
|
495
|
-
|
495
|
+
|
496
496
|
FormtasticBootstrap::FormBuilder.file_methods.each do |test|
|
497
497
|
### TODO: Check if this is ok
|
498
498
|
column.stub!(method).with(test).and_return(method == test)
|
499
499
|
end
|
500
|
-
|
500
|
+
|
501
501
|
@new_post.should_receive(method).and_return(column)
|
502
|
-
|
502
|
+
|
503
503
|
semantic_form_for(@new_post) do |builder|
|
504
504
|
builder.send(:default_input_type, method).should == :file
|
505
505
|
end
|
506
506
|
end
|
507
507
|
end
|
508
|
-
|
508
|
+
|
509
509
|
end
|
510
510
|
end
|
511
|
-
|
511
|
+
|
512
512
|
it 'should call the corresponding input class with .to_html' do
|
513
513
|
# TODO Re-activate timezone test.
|
514
514
|
# TODO Add for fancy Bootstrap types.
|
@@ -520,42 +520,42 @@ describe 'FormtasticBootstrap::FormBuilder#input' do
|
|
520
520
|
input_instance = mock('Input instance')
|
521
521
|
input_class = "#{input_style.to_s}_input".classify
|
522
522
|
input_constant = "FormtasticBootstrap::Inputs::#{input_class}".constantize
|
523
|
-
|
523
|
+
|
524
524
|
input_constant.should_receive(:new).and_return(input_instance)
|
525
525
|
input_instance.should_receive(:to_html).and_return("some HTML")
|
526
|
-
|
526
|
+
|
527
527
|
concat(builder.input(:generic_column_name, :as => input_style))
|
528
528
|
end
|
529
529
|
end
|
530
530
|
end
|
531
|
-
|
531
|
+
|
532
532
|
end
|
533
533
|
|
534
534
|
describe ':label option' do
|
535
|
-
|
535
|
+
|
536
536
|
describe 'when provided' do
|
537
537
|
it 'should be passed down to the label tag' do
|
538
538
|
concat(semantic_form_for(@new_post) do |builder|
|
539
539
|
concat(builder.input(:title, :label => "Kustom"))
|
540
540
|
end)
|
541
|
-
output_buffer.should have_tag("form div.
|
541
|
+
output_buffer.should have_tag("form div.clearfix label", /Kustom/)
|
542
542
|
end
|
543
|
-
|
543
|
+
|
544
544
|
it 'should not generate a label if false' do
|
545
545
|
concat(semantic_form_for(@new_post) do |builder|
|
546
546
|
concat(builder.input(:title, :label => false))
|
547
547
|
end)
|
548
|
-
output_buffer.should_not have_tag("form div.
|
548
|
+
output_buffer.should_not have_tag("form div.clearfix label")
|
549
549
|
end
|
550
|
-
|
550
|
+
|
551
551
|
it 'should be dupped if frozen' do
|
552
552
|
concat(semantic_form_for(@new_post) do |builder|
|
553
553
|
concat(builder.input(:title, :label => "Kustom".freeze))
|
554
554
|
end)
|
555
|
-
output_buffer.should have_tag("form div.
|
555
|
+
output_buffer.should have_tag("form div.clearfix label", /Kustom/)
|
556
556
|
end
|
557
557
|
end
|
558
|
-
|
558
|
+
|
559
559
|
describe 'when not provided' do
|
560
560
|
describe 'when localized label is provided' do
|
561
561
|
describe 'and object is given' do
|
@@ -570,17 +570,17 @@ describe 'FormtasticBootstrap::FormBuilder#input' do
|
|
570
570
|
:meta_description => @localized_label_text
|
571
571
|
}
|
572
572
|
}
|
573
|
-
|
573
|
+
|
574
574
|
concat(semantic_form_for(@new_post) do |builder|
|
575
575
|
concat(builder.input(:meta_description))
|
576
576
|
end)
|
577
|
-
output_buffer.should have_tag('form div.
|
577
|
+
output_buffer.should have_tag('form div.clearfix label', /Localized title/)
|
578
578
|
end
|
579
579
|
end
|
580
580
|
end
|
581
581
|
end
|
582
582
|
end
|
583
|
-
|
583
|
+
|
584
584
|
describe 'when localized label is NOT provided' do
|
585
585
|
describe 'and object is not given' do
|
586
586
|
it 'should default the humanized method name, passing it down to the label tag' do
|
@@ -589,37 +589,37 @@ describe 'FormtasticBootstrap::FormBuilder#input' do
|
|
589
589
|
concat(semantic_form_for(:project, :url => 'http://test.host') do |builder|
|
590
590
|
concat(builder.input(:meta_description))
|
591
591
|
end)
|
592
|
-
output_buffer.should have_tag("form div.
|
592
|
+
output_buffer.should have_tag("form div.clearfix label", /#{'meta_description'.humanize}/)
|
593
593
|
end
|
594
594
|
end
|
595
595
|
end
|
596
|
-
|
596
|
+
|
597
597
|
describe 'and object is given' do
|
598
598
|
it 'should delegate the label logic to class human attribute name and pass it down to the label tag' do
|
599
599
|
@new_post.stub!(:meta_description) # a two word method name
|
600
600
|
@new_post.class.should_receive(:human_attribute_name).with('meta_description').and_return('meta_description'.humanize)
|
601
|
-
|
601
|
+
|
602
602
|
concat(semantic_form_for(@new_post) do |builder|
|
603
603
|
concat(builder.input(:meta_description))
|
604
604
|
end)
|
605
|
-
output_buffer.should have_tag("form div.
|
605
|
+
output_buffer.should have_tag("form div.clearfix label", /#{'meta_description'.humanize}/)
|
606
606
|
end
|
607
607
|
end
|
608
|
-
|
608
|
+
|
609
609
|
describe 'and object is given with label_str_method set to :capitalize' do
|
610
610
|
it 'should capitalize method name, passing it down to the label tag' do
|
611
611
|
with_config :label_str_method, :capitalize do
|
612
612
|
@new_post.stub!(:meta_description)
|
613
|
-
|
613
|
+
|
614
614
|
concat(semantic_form_for(@new_post) do |builder|
|
615
615
|
concat(builder.input(:meta_description))
|
616
616
|
end)
|
617
|
-
output_buffer.should have_tag("form div.
|
617
|
+
output_buffer.should have_tag("form div.clearfix label", /#{'meta_description'.capitalize}/)
|
618
618
|
end
|
619
619
|
end
|
620
620
|
end
|
621
621
|
end
|
622
|
-
|
622
|
+
|
623
623
|
describe 'when localized label is provided' do
|
624
624
|
before do
|
625
625
|
@localized_label_text = 'Localized title'
|
@@ -636,17 +636,17 @@ describe 'FormtasticBootstrap::FormBuilder#input' do
|
|
636
636
|
}
|
637
637
|
}
|
638
638
|
end
|
639
|
-
|
639
|
+
|
640
640
|
it 'should render a label with localized label (I18n)' do
|
641
641
|
with_config :i18n_lookups_by_default, false do
|
642
642
|
concat(semantic_form_for(@new_post) do |builder|
|
643
643
|
concat(builder.input(:title, :label => true))
|
644
644
|
concat(builder.input(:published, :as => :boolean, :label => true))
|
645
645
|
end)
|
646
|
-
output_buffer.should have_tag('form div.
|
646
|
+
output_buffer.should have_tag('form div.clearfix label', Regexp.new('^' + @localized_label_text))
|
647
647
|
end
|
648
648
|
end
|
649
|
-
|
649
|
+
|
650
650
|
it 'should render a hint paragraph containing an optional localized label (I18n) if first is not set' do
|
651
651
|
with_config :i18n_lookups_by_default, false do
|
652
652
|
::I18n.backend.store_translations :en,
|
@@ -662,18 +662,18 @@ describe 'FormtasticBootstrap::FormBuilder#input' do
|
|
662
662
|
concat(builder.input(:title, :label => true))
|
663
663
|
concat(builder.input(:published, :as => :boolean, :label => true))
|
664
664
|
end)
|
665
|
-
output_buffer.should have_tag('form div.
|
665
|
+
output_buffer.should have_tag('form div.clearfix label', Regexp.new('^' + @default_localized_label_text))
|
666
666
|
end
|
667
667
|
end
|
668
668
|
end
|
669
669
|
end
|
670
|
-
|
670
|
+
|
671
671
|
end
|
672
672
|
|
673
673
|
describe ':hint option' do
|
674
674
|
|
675
675
|
describe 'when provided' do
|
676
|
-
|
676
|
+
|
677
677
|
before(:each) do
|
678
678
|
@orig_hint_class = FormtasticBootstrap::FormBuilder.default_inline_hint_class
|
679
679
|
end
|
@@ -687,7 +687,7 @@ describe 'FormtasticBootstrap::FormBuilder#input' do
|
|
687
687
|
concat(semantic_form_for(@new_post) do |builder|
|
688
688
|
concat(builder.input(:title, :hint => hint_text))
|
689
689
|
end)
|
690
|
-
output_buffer.should have_tag("form div.
|
690
|
+
output_buffer.should have_tag("form div.clearfix div span.help-inline", hint_text)
|
691
691
|
end
|
692
692
|
|
693
693
|
it 'should have a custom hint class if I ask for one' do
|
@@ -695,7 +695,7 @@ describe 'FormtasticBootstrap::FormBuilder#input' do
|
|
695
695
|
concat(semantic_form_for(@new_post) do |builder|
|
696
696
|
concat(builder.input(:title, :hint => hint_text, :hint_class => 'custom-hint-class'))
|
697
697
|
end)
|
698
|
-
output_buffer.should have_tag("form div.
|
698
|
+
output_buffer.should have_tag("form div.clearfix div span.custom-hint-class", hint_text)
|
699
699
|
end
|
700
700
|
|
701
701
|
it 'should have a custom hint class defaulted for all forms' do
|
@@ -705,7 +705,7 @@ describe 'FormtasticBootstrap::FormBuilder#input' do
|
|
705
705
|
concat(semantic_form_for(@new_post) do |builder|
|
706
706
|
concat(builder.input(:title, :hint => hint_text))
|
707
707
|
end)
|
708
|
-
output_buffer.should have_tag("form div.
|
708
|
+
output_buffer.should have_tag("form div.clearfix div span.custom-hint-class", hint_text)
|
709
709
|
end
|
710
710
|
end
|
711
711
|
|
@@ -740,7 +740,7 @@ describe 'FormtasticBootstrap::FormBuilder#input' do
|
|
740
740
|
concat(semantic_form_for(@new_post) do |builder|
|
741
741
|
concat(builder.input(:title, :hint => true))
|
742
742
|
end)
|
743
|
-
output_buffer.should have_tag('form div.
|
743
|
+
output_buffer.should have_tag('form div.clearfix div span.help-inline', @localized_hint_text)
|
744
744
|
end
|
745
745
|
end
|
746
746
|
|
@@ -757,7 +757,7 @@ describe 'FormtasticBootstrap::FormBuilder#input' do
|
|
757
757
|
concat(semantic_form_for(@new_post) do |builder|
|
758
758
|
concat(builder.input(:title, :hint => true, :hint_class => 'custom-hint-class'))
|
759
759
|
end)
|
760
|
-
output_buffer.should have_tag('form div.
|
760
|
+
output_buffer.should have_tag('form div.clearfix div span.custom-hint-class', @localized_hint_text)
|
761
761
|
end
|
762
762
|
end
|
763
763
|
|
@@ -766,7 +766,7 @@ describe 'FormtasticBootstrap::FormBuilder#input' do
|
|
766
766
|
concat(semantic_form_for(@new_post) do |builder|
|
767
767
|
concat(builder.input(:title, :hint => true))
|
768
768
|
end)
|
769
|
-
output_buffer.should have_tag('form div.
|
769
|
+
output_buffer.should have_tag('form div.clearfix div span.help-inline', @default_localized_hint_text)
|
770
770
|
end
|
771
771
|
end
|
772
772
|
end
|
@@ -777,7 +777,7 @@ describe 'FormtasticBootstrap::FormBuilder#input' do
|
|
777
777
|
concat(semantic_form_for(@new_post) do |builder|
|
778
778
|
concat(builder.input(:title, :hint => false))
|
779
779
|
end)
|
780
|
-
output_buffer.should_not have_tag('form div.
|
780
|
+
output_buffer.should_not have_tag('form div.clearfix div span.help-inline', @localized_hint_text)
|
781
781
|
end
|
782
782
|
end
|
783
783
|
end
|
@@ -797,7 +797,7 @@ describe 'FormtasticBootstrap::FormBuilder#input' do
|
|
797
797
|
semantic_form_for(@new_post) do |builder|
|
798
798
|
concat(builder.input(:title, :hint => true))
|
799
799
|
end
|
800
|
-
output_buffer.should_not have_tag('form div.
|
800
|
+
output_buffer.should_not have_tag('form div.clearfix div span.help-inline', @localized_hint_text)
|
801
801
|
end
|
802
802
|
end
|
803
803
|
end
|
@@ -808,7 +808,7 @@ describe 'FormtasticBootstrap::FormBuilder#input' do
|
|
808
808
|
concat(semantic_form_for(@new_post) do |builder|
|
809
809
|
concat(builder.input(:title))
|
810
810
|
end)
|
811
|
-
output_buffer.should_not have_tag('form div.
|
811
|
+
output_buffer.should_not have_tag('form div.clearfix div span.help-inline')
|
812
812
|
end
|
813
813
|
end
|
814
814
|
end
|
@@ -817,7 +817,7 @@ describe 'FormtasticBootstrap::FormBuilder#input' do
|
|
817
817
|
end
|
818
818
|
|
819
819
|
describe ':wrapper_html option' do
|
820
|
-
|
820
|
+
|
821
821
|
describe 'when provided' do
|
822
822
|
it 'should be passed down to the li tag' do
|
823
823
|
concat(semantic_form_for(@new_post) do |builder|
|
@@ -825,40 +825,40 @@ describe 'FormtasticBootstrap::FormBuilder#input' do
|
|
825
825
|
end)
|
826
826
|
output_buffer.should have_tag("form div#another_id")
|
827
827
|
end
|
828
|
-
|
828
|
+
|
829
829
|
it 'should append given classes to li default classes' do
|
830
830
|
concat(semantic_form_for(@new_post) do |builder|
|
831
831
|
concat(builder.input(:title, :wrapper_html => {:class => :another_class}, :required => true))
|
832
832
|
end)
|
833
|
-
output_buffer.should have_tag("form div.
|
834
|
-
output_buffer.should have_tag("form div.
|
835
|
-
output_buffer.should have_tag("form div.
|
833
|
+
output_buffer.should have_tag("form div.clearfix.string")
|
834
|
+
output_buffer.should have_tag("form div.clearfix.required")
|
835
|
+
output_buffer.should have_tag("form div.clearfix.another_class")
|
836
836
|
end
|
837
|
-
|
837
|
+
|
838
838
|
it 'should allow classes to be an array' do
|
839
839
|
concat(semantic_form_for(@new_post) do |builder|
|
840
840
|
concat(builder.input(:title, :wrapper_html => {:class => [ :my_class, :another_class ]}))
|
841
841
|
end)
|
842
|
-
output_buffer.should have_tag("form div.
|
843
|
-
output_buffer.should have_tag("form div.
|
844
|
-
output_buffer.should have_tag("form div.
|
842
|
+
output_buffer.should have_tag("form div.clearfix.string")
|
843
|
+
output_buffer.should have_tag("form div.clearfix.my_class")
|
844
|
+
output_buffer.should have_tag("form div.clearfix.another_class")
|
845
845
|
end
|
846
846
|
end
|
847
|
-
|
847
|
+
|
848
848
|
# describe 'when not provided' do
|
849
849
|
# it 'should use default id and class' do
|
850
850
|
# concat(semantic_form_for(@new_post) do |builder|
|
851
851
|
# concat(builder.input(:title))
|
852
852
|
# end)
|
853
853
|
# output_buffer.should have_tag("form div#post_title_input")
|
854
|
-
# output_buffer.should have_tag("form div.
|
854
|
+
# output_buffer.should have_tag("form div.clearfix.string")
|
855
855
|
# end
|
856
856
|
# end
|
857
|
-
#
|
857
|
+
#
|
858
858
|
end
|
859
859
|
|
860
860
|
describe ':collection option' do
|
861
|
-
|
861
|
+
|
862
862
|
it "should be required on polymorphic associations" do
|
863
863
|
@new_post.stub!(:commentable)
|
864
864
|
@new_post.class.stub!(:reflections).and_return({
|
@@ -878,28 +878,28 @@ describe 'FormtasticBootstrap::FormBuilder#input' do
|
|
878
878
|
end)
|
879
879
|
}.to raise_error(Formtastic::PolymorphicInputWithoutCollectionError)
|
880
880
|
end
|
881
|
-
|
881
|
+
|
882
882
|
end
|
883
883
|
|
884
884
|
end
|
885
885
|
|
886
886
|
describe 'options re-use' do
|
887
|
-
|
887
|
+
|
888
888
|
it 'should retain :as option when re-using the same options hash' do
|
889
889
|
my_options = { :as => :string }
|
890
890
|
output = ''
|
891
|
-
|
891
|
+
|
892
892
|
concat(semantic_form_for(@new_post) do |builder|
|
893
893
|
concat(builder.input(:title, my_options))
|
894
894
|
concat(builder.input(:publish_at, my_options))
|
895
895
|
end)
|
896
|
-
output_buffer.should have_tag 'div.
|
896
|
+
output_buffer.should have_tag 'div.clearfix.string', :count => 2
|
897
897
|
end
|
898
898
|
|
899
899
|
end
|
900
900
|
|
901
901
|
describe 'instantiating an input class' do
|
902
|
-
|
902
|
+
|
903
903
|
context 'when a class does not exist' do
|
904
904
|
it "should raise an error" do
|
905
905
|
lambda {
|
@@ -909,9 +909,9 @@ describe 'FormtasticBootstrap::FormBuilder#input' do
|
|
909
909
|
}.should raise_error(Formtastic::UnknownInputError)
|
910
910
|
end
|
911
911
|
end
|
912
|
-
|
912
|
+
|
913
913
|
context 'when a customized top-level class does not exist' do
|
914
|
-
|
914
|
+
|
915
915
|
it 'should instantiate the Formtastic input' do
|
916
916
|
input = mock('input', :to_html => 'some HTML')
|
917
917
|
FormtasticBootstrap::Inputs::StringInput.should_receive(:new).and_return(input)
|
@@ -919,26 +919,26 @@ describe 'FormtasticBootstrap::FormBuilder#input' do
|
|
919
919
|
builder.input(:title, :as => :string)
|
920
920
|
end)
|
921
921
|
end
|
922
|
-
|
922
|
+
|
923
923
|
end
|
924
|
-
|
924
|
+
|
925
925
|
describe 'when a top-level input class exists' do
|
926
926
|
it "should instantiate the top-level input instead of the Formtastic one" do
|
927
927
|
class ::StringInput < FormtasticBootstrap::Inputs::StringInput
|
928
928
|
end
|
929
|
-
|
929
|
+
|
930
930
|
input = mock('input', :to_html => 'some HTML')
|
931
931
|
FormtasticBootstrap::Inputs::StringInput.should_not_receive(:new).and_return(input)
|
932
932
|
::StringInput.should_receive(:new).and_return(input)
|
933
|
-
|
933
|
+
|
934
934
|
concat(semantic_form_for(@new_post) do |builder|
|
935
935
|
builder.input(:title, :as => :string)
|
936
936
|
end)
|
937
937
|
end
|
938
938
|
end
|
939
|
-
|
939
|
+
|
940
940
|
describe 'when instantiated multiple times with the same input type' do
|
941
|
-
|
941
|
+
|
942
942
|
it "should be cached (not calling the internal methods)" do
|
943
943
|
# TODO this is really tied to the underlying implementation
|
944
944
|
concat(semantic_form_for(@new_post) do |builder|
|
@@ -947,9 +947,9 @@ describe 'FormtasticBootstrap::FormBuilder#input' do
|
|
947
947
|
builder.input(:title, :as => :string)
|
948
948
|
end)
|
949
949
|
end
|
950
|
-
|
950
|
+
|
951
951
|
end
|
952
|
-
|
952
|
+
|
953
953
|
end
|
954
954
|
|
955
955
|
end
|