speedo-formstrap 1.2.2 → 1.2.3
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +0 -1
- data/README.md +4 -4
- data/Rakefile +1 -1
- data/VERSION +1 -1
- data/lib/speedo-formstrap/form_builder.rb +7 -5
- data/lib/speedo-formstrap/helpers.rb +3 -1
- data/lib/speedo-formstrap/helpers/buttons_helper.rb +13 -9
- data/lib/speedo-formstrap/helpers/fieldset_wrapper.rb +11 -6
- data/lib/speedo-formstrap/helpers/inputs_helper.rb +4 -4
- data/lib/speedo-formstrap/inputs/base.rb +2 -1
- data/lib/speedo-formstrap/inputs/base/choices.rb +12 -23
- data/lib/speedo-formstrap/inputs/base/labelling.rb +16 -6
- data/lib/speedo-formstrap/inputs/base/timeish.rb +5 -12
- data/lib/speedo-formstrap/inputs/base/wrapping.rb +32 -14
- data/lib/speedo-formstrap/inputs/number_input.rb +2 -2
- data/lib/speedo-formstrap/inputs/radio_input.rb +13 -12
- data/lib/speedo-formstrap/inputs/range_input.rb +2 -2
- data/spec/builder/semantic_fields_for_spec.rb +16 -16
- data/spec/helpers/buttons_helper_spec.rb +56 -46
- data/spec/helpers/input_helper_spec.rb +209 -209
- data/spec/helpers/inputs_helper_spec.rb +117 -103
- data/spec/inputs/boolean_input_spec.rb +74 -46
- data/spec/inputs/check_boxes_input_spec.rb +110 -82
- data/spec/inputs/date_input_spec.rb +81 -15
- data/spec/inputs/datetime_input_spec.rb +13 -13
- data/spec/inputs/email_input_spec.rb +34 -6
- data/spec/inputs/file_input_spec.rb +34 -6
- data/spec/inputs/hidden_input_spec.rb +41 -13
- data/spec/inputs/number_input_spec.rb +127 -97
- data/spec/inputs/password_input_spec.rb +34 -6
- data/spec/inputs/phone_input_spec.rb +34 -6
- data/spec/inputs/radio_input_spec.rb +73 -45
- data/spec/inputs/range_input_spec.rb +94 -66
- data/spec/inputs/search_input_spec.rb +33 -6
- data/spec/inputs/select_input_spec.rb +124 -78
- data/spec/inputs/string_input_spec.rb +67 -22
- data/spec/inputs/text_input_spec.rb +42 -15
- data/spec/inputs/time_input_spec.rb +23 -23
- data/spec/inputs/time_zone_input_spec.rb +20 -20
- data/spec/inputs/url_input_spec.rb +34 -6
- data/spec/support/custom_macros.rb +67 -196
- data/spec/support/formtastic_spec_helper.rb +22 -6
- data/speedo-formstrap.gemspec +2 -2
- metadata +17 -17
@@ -2,7 +2,7 @@ module SpeedoFormstrap
|
|
2
2
|
module Inputs
|
3
3
|
class NumberInput < Formtastic::Inputs::NumberInput
|
4
4
|
include Base
|
5
|
-
include Base::
|
5
|
+
include Base::Numeric
|
6
6
|
|
7
7
|
def to_html
|
8
8
|
generic_input_wrapping do
|
@@ -12,4 +12,4 @@ module SpeedoFormstrap
|
|
12
12
|
|
13
13
|
end
|
14
14
|
end
|
15
|
-
end
|
15
|
+
end
|
@@ -5,28 +5,29 @@ module SpeedoFormstrap
|
|
5
5
|
include Base::Choices
|
6
6
|
|
7
7
|
def to_html
|
8
|
-
|
8
|
+
control_group_div_wrapping do
|
9
9
|
legend_html <<
|
10
10
|
input_div_wrapping do
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
choice_html(choice)
|
15
|
-
end
|
16
|
-
}.join("\n").html_safe
|
17
|
-
end
|
11
|
+
collection.map { |choice|
|
12
|
+
choice_html(choice)
|
13
|
+
}.join("\n").html_safe
|
18
14
|
end
|
19
15
|
end
|
20
16
|
end
|
21
17
|
|
22
|
-
def choice_html(choice)
|
23
|
-
template.content_tag(:label, label_html_options.merge(:for => choice_input_dom_id(choice)
|
24
|
-
builder.radio_button(input_name, choice_value(choice), input_html_options.merge(choice_html_options(choice)).merge(:required => false)) <<
|
18
|
+
def choice_html(choice)
|
19
|
+
template.content_tag(:label, label_html_options.merge(:for => choice_input_dom_id(choice)).merge(choice_wrapping_html_options(choice))) do
|
20
|
+
builder.radio_button(input_name, choice_value(choice), input_html_options.merge(choice_html_options(choice)).merge(:required => false)) <<
|
25
21
|
|
26
22
|
choice_label(choice)
|
27
23
|
end
|
28
24
|
end
|
29
25
|
|
26
|
+
def choice_wrapping_html_options(choice)
|
27
|
+
new_class = [super[:class], 'radio'].join(' ')
|
28
|
+
super.merge(:class => new_class)
|
29
|
+
end
|
30
|
+
|
30
31
|
end
|
31
32
|
end
|
32
|
-
end
|
33
|
+
end
|
@@ -2,7 +2,7 @@ module SpeedoFormstrap
|
|
2
2
|
module Inputs
|
3
3
|
class RangeInput < Formtastic::Inputs::RangeInput
|
4
4
|
include Base
|
5
|
-
include Base::
|
5
|
+
include Base::Numeric
|
6
6
|
|
7
7
|
def to_html
|
8
8
|
generic_input_wrapping do
|
@@ -12,4 +12,4 @@ module SpeedoFormstrap
|
|
12
12
|
|
13
13
|
end
|
14
14
|
end
|
15
|
-
end
|
15
|
+
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe '
|
3
|
+
describe 'FormtasticBootstrap::FormBuilder#fields_for' do
|
4
4
|
|
5
5
|
include FormtasticSpecHelper
|
6
6
|
|
@@ -9,7 +9,7 @@ describe 'SpeedoFormstrap::FormBuilder#fields_for' do
|
|
9
9
|
mock_everything
|
10
10
|
@new_post.stub!(:author).and_return(::Author.new)
|
11
11
|
|
12
|
-
Formtastic::Helpers::FormHelper.builder =
|
12
|
+
Formtastic::Helpers::FormHelper.builder = FormtasticBootstrap::FormBuilder
|
13
13
|
end
|
14
14
|
|
15
15
|
context 'outside a form_for block' do
|
@@ -27,7 +27,7 @@ describe 'SpeedoFormstrap::FormBuilder#fields_for' do
|
|
27
27
|
nested_builder.class.should == Formtastic::Helpers::FormHelper.builder
|
28
28
|
end
|
29
29
|
end
|
30
|
-
|
30
|
+
|
31
31
|
it 'should respond to input' do
|
32
32
|
semantic_fields_for(@new_post) do |nested_builder|
|
33
33
|
nested_builder.respond_to?(:input).should be_true
|
@@ -43,7 +43,7 @@ describe 'SpeedoFormstrap::FormBuilder#fields_for' do
|
|
43
43
|
end
|
44
44
|
end
|
45
45
|
end
|
46
|
-
|
46
|
+
|
47
47
|
context 'within a form_for block' do
|
48
48
|
it 'yields an instance of FormHelper.builder' do
|
49
49
|
semantic_form_for(@new_post) do |builder|
|
@@ -52,7 +52,7 @@ describe 'SpeedoFormstrap::FormBuilder#fields_for' do
|
|
52
52
|
end
|
53
53
|
end
|
54
54
|
end
|
55
|
-
|
55
|
+
|
56
56
|
it 'yields an instance of FormHelper.builder with hash-like model' do
|
57
57
|
semantic_form_for(:user) do |builder|
|
58
58
|
builder.semantic_fields_for(:author, @hash_backed_author) do |nested_builder|
|
@@ -60,7 +60,7 @@ describe 'SpeedoFormstrap::FormBuilder#fields_for' do
|
|
60
60
|
end
|
61
61
|
end
|
62
62
|
end
|
63
|
-
|
63
|
+
|
64
64
|
it 'nests the object name' do
|
65
65
|
semantic_form_for(@new_post) do |builder|
|
66
66
|
builder.semantic_fields_for(@bob) do |nested_builder|
|
@@ -68,7 +68,7 @@ describe 'SpeedoFormstrap::FormBuilder#fields_for' do
|
|
68
68
|
end
|
69
69
|
end
|
70
70
|
end
|
71
|
-
|
71
|
+
|
72
72
|
it 'supports passing collection as second parameter' do
|
73
73
|
semantic_form_for(@new_post) do |builder|
|
74
74
|
builder.semantic_fields_for(:author, [@fred,@bob]) do |nested_builder|
|
@@ -76,7 +76,7 @@ describe 'SpeedoFormstrap::FormBuilder#fields_for' do
|
|
76
76
|
end
|
77
77
|
end
|
78
78
|
end
|
79
|
-
|
79
|
+
|
80
80
|
it 'should sanitize html id for li tag' do
|
81
81
|
@bob.stub!(:column_for_attribute).and_return(mock('column', :type => :string, :limit => 255))
|
82
82
|
concat(semantic_form_for(@new_post) do |builder|
|
@@ -89,7 +89,7 @@ describe 'SpeedoFormstrap::FormBuilder#fields_for' do
|
|
89
89
|
output_buffer.should_not =~ /id="post\[author\]_1_login_input"/
|
90
90
|
# <=> output_buffer.should_not have_tag('form fieldset.inputs #post[author]_1_login_input')
|
91
91
|
end
|
92
|
-
|
92
|
+
|
93
93
|
it 'should use namespace provided in nested fields' do
|
94
94
|
@bob.stub!(:column_for_attribute).and_return(mock('column', :type => :string, :limit => 255))
|
95
95
|
concat(semantic_form_for(@new_post, :namespace => 'context2') do |builder|
|
@@ -100,12 +100,12 @@ describe 'SpeedoFormstrap::FormBuilder#fields_for' do
|
|
100
100
|
output_buffer.should have_tag('form fieldset.inputs #context2_post_author_1_login_input')
|
101
101
|
end
|
102
102
|
end
|
103
|
-
|
104
|
-
context "when I rendered my own hidden id input" do
|
105
|
-
|
103
|
+
|
104
|
+
context "when I rendered my own hidden id input" do
|
105
|
+
|
106
106
|
before do
|
107
107
|
output_buffer.replace ''
|
108
|
-
|
108
|
+
|
109
109
|
@fred.posts.size.should == 1
|
110
110
|
@fred.posts.first.stub!(:persisted?).and_return(true)
|
111
111
|
@fred.stub!(:posts_attributes=)
|
@@ -117,13 +117,13 @@ describe 'SpeedoFormstrap::FormBuilder#fields_for' do
|
|
117
117
|
end)
|
118
118
|
end)
|
119
119
|
end
|
120
|
-
|
120
|
+
|
121
121
|
it "should only render one hidden input (my one)" do
|
122
122
|
output_buffer.should have_tag 'input#author_posts_attributes_0_id', :count => 1
|
123
123
|
end
|
124
124
|
|
125
|
-
it "should render the hidden input inside an div.hidden" do
|
126
|
-
output_buffer.should have_tag 'div.hidden div.
|
125
|
+
it "should render the hidden input inside an div.hidden-wrapper" do
|
126
|
+
output_buffer.should have_tag 'div.hidden-wrapper div.controls input#author_posts_attributes_0_id'
|
127
127
|
end
|
128
128
|
end
|
129
129
|
|
@@ -8,34 +8,36 @@ describe 'Formtastic::FormBuilder#buttons' do
|
|
8
8
|
before do
|
9
9
|
@output_buffer = ''
|
10
10
|
mock_everything
|
11
|
-
Formtastic::Helpers::FormHelper.builder =
|
11
|
+
Formtastic::Helpers::FormHelper.builder = FormtasticBootstrap::FormBuilder
|
12
12
|
end
|
13
13
|
|
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
|
-
|
17
|
+
with_deprecation_silenced do
|
18
|
+
concat(semantic_form_for(@new_post) do |builder|
|
19
|
+
buttons = builder.buttons do
|
20
|
+
concat('hello')
|
21
|
+
end
|
22
|
+
concat(buttons)
|
23
|
+
end)
|
24
|
+
end
|
23
25
|
end
|
24
26
|
|
25
|
-
it 'should render a div inside the form, with a class of "actions"' do
|
26
|
-
output_buffer.should have_tag("form div.actions")
|
27
|
+
it 'should render a div inside the form, with a class of "form-actions"' do
|
28
|
+
output_buffer.should have_tag("form div.form-actions")
|
27
29
|
end
|
28
30
|
|
29
31
|
it 'should not render an ol inside the div' do
|
30
|
-
output_buffer.should_not have_tag("form div.actions ol")
|
32
|
+
output_buffer.should_not have_tag("form div.form-actions ol")
|
31
33
|
end
|
32
34
|
|
33
35
|
it 'should render the contents of the block inside the input' do
|
34
|
-
output_buffer.should have_tag("form div.actions", /hello/)
|
36
|
+
output_buffer.should have_tag("form div.form-actions", /hello/)
|
35
37
|
end
|
36
38
|
|
37
39
|
it 'should not render a legend inside the div' do
|
38
|
-
output_buffer.should_not have_tag("form div.actions legend")
|
40
|
+
output_buffer.should_not have_tag("form div.form-actions legend")
|
39
41
|
end
|
40
42
|
end
|
41
43
|
|
@@ -44,10 +46,12 @@ describe 'Formtastic::FormBuilder#buttons' do
|
|
44
46
|
@id_option = 'advanced'
|
45
47
|
@class_option = 'wide'
|
46
48
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
49
|
+
with_deprecation_silenced do
|
50
|
+
concat(semantic_form_for(@new_post) do |builder|
|
51
|
+
builder.buttons :id => @id_option, :class => @class_option do
|
52
|
+
end
|
53
|
+
end)
|
54
|
+
end
|
51
55
|
end
|
52
56
|
it 'should pass the options into the div tag as attributes' do
|
53
57
|
output_buffer.should have_tag("form div##{@id_option}")
|
@@ -62,29 +66,31 @@ describe 'Formtastic::FormBuilder#buttons' do
|
|
62
66
|
describe 'with no args (default buttons)' do
|
63
67
|
|
64
68
|
before do
|
65
|
-
|
66
|
-
concat(builder
|
67
|
-
|
69
|
+
with_deprecation_silenced do
|
70
|
+
concat(semantic_form_for(@new_post) do |builder|
|
71
|
+
concat(builder.buttons)
|
72
|
+
end)
|
73
|
+
end
|
68
74
|
end
|
69
75
|
|
70
76
|
it 'should render a form' do
|
71
77
|
output_buffer.should have_tag('form')
|
72
78
|
end
|
73
79
|
|
74
|
-
it 'should render a "actions" div inside the form' do
|
75
|
-
output_buffer.should have_tag('form div.actions')
|
80
|
+
it 'should render a "form-actions" div inside the form' do
|
81
|
+
output_buffer.should have_tag('form div.form-actions')
|
76
82
|
end
|
77
83
|
|
78
84
|
it 'should not render a legend in the div' do
|
79
|
-
output_buffer.should_not have_tag('form div.actions legend')
|
85
|
+
output_buffer.should_not have_tag('form div.form-actions legend')
|
80
86
|
end
|
81
87
|
|
82
88
|
it 'should render an button item in the ol for each default button' do
|
83
|
-
output_buffer.should have_tag('form div.actions input.btn', :count => 1)
|
89
|
+
output_buffer.should have_tag('form div.form-actions input.btn', :count => 1)
|
84
90
|
end
|
85
91
|
|
86
92
|
it 'should render a commit list item for the commit button' do
|
87
|
-
output_buffer.should have_tag('form div.actions input.commit')
|
93
|
+
output_buffer.should have_tag('form div.form-actions input.commit')
|
88
94
|
end
|
89
95
|
|
90
96
|
end
|
@@ -92,22 +98,24 @@ describe 'Formtastic::FormBuilder#buttons' do
|
|
92
98
|
describe 'with button names as args' do
|
93
99
|
|
94
100
|
before do
|
95
|
-
|
96
|
-
concat(
|
97
|
-
|
101
|
+
with_deprecation_silenced do
|
102
|
+
concat(semantic_form_for(@new_post) do |builder|
|
103
|
+
concat(builder.buttons(:commit))
|
104
|
+
end)
|
105
|
+
end
|
98
106
|
end
|
99
107
|
|
100
108
|
it 'should render a form with a div containing an input for each button arg' do
|
101
|
-
output_buffer.should have_tag('form > div.actions > input', :count => 1)
|
102
|
-
output_buffer.should have_tag('form > div.actions > input.commit')
|
109
|
+
output_buffer.should have_tag('form > div.form-actions > input', :count => 1)
|
110
|
+
output_buffer.should have_tag('form > div.form-actions > input.commit')
|
103
111
|
end
|
104
112
|
|
105
113
|
end
|
106
114
|
|
107
115
|
describe 'with :names' do
|
108
|
-
|
116
|
+
|
109
117
|
before do
|
110
|
-
ActiveSupport::Deprecation.should_receive(:warn)
|
118
|
+
ActiveSupport::Deprecation.should_receive(:warn).exactly(3).times
|
111
119
|
concat(
|
112
120
|
semantic_form_for(@new_post) do |builder|
|
113
121
|
concat(builder.buttons(:commit, :name => "Now click a button"))
|
@@ -120,29 +128,31 @@ describe 'Formtastic::FormBuilder#buttons' do
|
|
120
128
|
end
|
121
129
|
|
122
130
|
end
|
123
|
-
|
124
|
-
|
131
|
+
|
132
|
+
|
125
133
|
describe 'with button names and an options hash' do
|
126
|
-
|
134
|
+
|
127
135
|
before do
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
136
|
+
with_deprecation_silenced do
|
137
|
+
concat(
|
138
|
+
semantic_form_for(@new_post) do |builder|
|
139
|
+
concat(builder.buttons(:commit, :id => "my-id"))
|
140
|
+
end
|
141
|
+
)
|
142
|
+
end
|
133
143
|
end
|
134
|
-
|
144
|
+
|
135
145
|
it 'should render a form with a div containing a input for each button arg' do
|
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)
|
146
|
+
output_buffer.should have_tag('form > div.form-actions > input', :count => 1)
|
147
|
+
output_buffer.should have_tag('form > div.form-actions > input.commit', :count => 1)
|
138
148
|
end
|
139
|
-
|
149
|
+
|
140
150
|
it 'should pass the options down to the div' do
|
141
|
-
output_buffer.should have_tag('form > div#my-id.actions')
|
151
|
+
output_buffer.should have_tag('form > div#my-id.form-actions')
|
142
152
|
end
|
143
|
-
|
153
|
+
|
144
154
|
end
|
145
|
-
|
155
|
+
|
146
156
|
end
|
147
157
|
|
148
158
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
require 'spec_helper'
|
3
3
|
|
4
|
-
describe '
|
4
|
+
describe 'FormtasticBootstrap::FormBuilder#input' do
|
5
5
|
|
6
6
|
include FormtasticSpecHelper
|
7
7
|
|
@@ -9,7 +9,7 @@ describe 'SpeedoFormstrap::FormBuilder#input' do
|
|
9
9
|
@output_buffer = ''
|
10
10
|
mock_everything
|
11
11
|
|
12
|
-
Formtastic::Helpers::FormHelper.builder =
|
12
|
+
Formtastic::Helpers::FormHelper.builder = FormtasticBootstrap::FormBuilder
|
13
13
|
|
14
14
|
@errors = mock('errors')
|
15
15
|
@errors.stub!(:[]).and_return([])
|
@@ -31,49 +31,49 @@ describe 'SpeedoFormstrap::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.control-group.optional')
|
43
|
+
output_buffer.should have_tag('form div.control-group.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.control-group.required label.control-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
|
-
@orig_optional_string =
|
61
|
-
@string =
|
60
|
+
@orig_optional_string = FormtasticBootstrap::FormBuilder.optional_string
|
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.control-group.required')
|
74
|
+
output_buffer.should have_tag('form div.control-group.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 'SpeedoFormstrap::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.control-group.required')
|
85
|
+
output_buffer.should have_tag('form div.control-group.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.control-group.optional label.control-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
|
-
@orig_all_fields_required =
|
102
|
+
@orig_all_fields_required = FormtasticBootstrap::FormBuilder.all_fields_required_by_default
|
103
103
|
end
|
104
|
-
|
104
|
+
|
105
105
|
after(:each) do
|
106
|
-
|
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
|
-
|
111
|
-
|
112
|
-
|
110
|
+
FormtasticBootstrap::FormBuilder.all_fields_required_by_default.should == true
|
111
|
+
FormtasticBootstrap::FormBuilder.all_fields_required_by_default = false
|
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.control-group.required')
|
117
|
+
output_buffer.should have_tag('form div.control-group.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.control-group.required')
|
147
|
+
output_buffer.should_not have_tag('form div.control-group.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 'SpeedoFormstrap::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.control-group.required')
|
159
|
+
output_buffer.should_not have_tag('form div.control-group.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 'SpeedoFormstrap::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.control-group.required')
|
172
|
+
output_buffer.should_not have_tag('form div.control-group.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 'SpeedoFormstrap::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.control-group.required')
|
185
|
+
output_buffer.should_not have_tag('form div.control-group.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 'SpeedoFormstrap::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.control-group.required')
|
197
|
+
output_buffer.should have_tag('form div.control-group.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 'SpeedoFormstrap::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.control-group.required')
|
208
|
+
output_buffer.should have_tag('form div.control-group.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 'SpeedoFormstrap::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 'SpeedoFormstrap::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.control-group.optional')
|
314
|
+
output_buffer.should have_tag('form div.control-group.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.control-group.optional')
|
317
|
+
output_buffer.should_not have_tag('form div.control-group.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.control-group.required')
|
342
|
+
output_buffer.should have_tag('form div.control-group.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
|
-
@orig_all_fields_required =
|
351
|
+
@orig_all_fields_required = FormtasticBootstrap::FormBuilder.all_fields_required_by_default
|
352
352
|
end
|
353
|
-
|
353
|
+
|
354
354
|
after(:each) do
|
355
|
-
|
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
|
-
|
360
|
-
|
361
|
-
|
359
|
+
FormtasticBootstrap::FormBuilder.all_fields_required_by_default.should == true
|
360
|
+
FormtasticBootstrap::FormBuilder.all_fields_required_by_default = false
|
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.control-group.required')
|
366
|
+
output_buffer.should have_tag('form div.control-group.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.control-group.string-wrapper')
|
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.control-group.password-wrapper', :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
|
-
|
496
|
-
|
495
|
+
|
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.
|
@@ -519,43 +519,43 @@ describe 'SpeedoFormstrap::FormBuilder#input' do
|
|
519
519
|
semantic_form_for(@new_post) do |builder|
|
520
520
|
input_instance = mock('Input instance')
|
521
521
|
input_class = "#{input_style.to_s}_input".classify
|
522
|
-
input_constant = "
|
523
|
-
|
522
|
+
input_constant = "FormtasticBootstrap::Inputs::#{input_class}".constantize
|
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.control-group label.control-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.control-group label.control-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.control-group label.control-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 'SpeedoFormstrap::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.control-group label.control-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 'SpeedoFormstrap::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.control-group label.control-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.control-group label.control-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.control-group label.control-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 'SpeedoFormstrap::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.control-group label.control-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,24 +662,24 @@ describe 'SpeedoFormstrap::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.control-group label.control-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
|
-
@orig_hint_class =
|
678
|
+
@orig_hint_class = FormtasticBootstrap::FormBuilder.default_inline_hint_class
|
679
679
|
end
|
680
680
|
|
681
681
|
after(:each) do
|
682
|
-
|
682
|
+
FormtasticBootstrap::FormBuilder.default_inline_hint_class = @orig_hint_class
|
683
683
|
end
|
684
684
|
|
685
685
|
it 'should be passed down to the paragraph tag' do
|
@@ -687,7 +687,7 @@ describe 'SpeedoFormstrap::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.control-group 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,17 +695,17 @@ describe 'SpeedoFormstrap::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.control-group 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
|
702
702
|
hint_text = "this is the title of the post"
|
703
|
-
#
|
704
|
-
|
703
|
+
# FormtasticBootstrap::FormBuilder.default_hint_class = "custom-hint-class"
|
704
|
+
FormtasticBootstrap::FormBuilder.default_inline_hint_class = "custom-hint-class"
|
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.control-group div span.custom-hint-class", hint_text)
|
709
709
|
end
|
710
710
|
end
|
711
711
|
|
@@ -740,7 +740,7 @@ describe 'SpeedoFormstrap::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.control-group div span.help-inline', @localized_hint_text)
|
744
744
|
end
|
745
745
|
end
|
746
746
|
|
@@ -757,7 +757,7 @@ describe 'SpeedoFormstrap::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.control-group div span.custom-hint-class', @localized_hint_text)
|
761
761
|
end
|
762
762
|
end
|
763
763
|
|
@@ -766,7 +766,7 @@ describe 'SpeedoFormstrap::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.control-group div span.help-inline', @default_localized_hint_text)
|
770
770
|
end
|
771
771
|
end
|
772
772
|
end
|
@@ -777,7 +777,7 @@ describe 'SpeedoFormstrap::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.control-group div span.help-inline', @localized_hint_text)
|
781
781
|
end
|
782
782
|
end
|
783
783
|
end
|
@@ -797,7 +797,7 @@ describe 'SpeedoFormstrap::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.control-group div span.help-inline', @localized_hint_text)
|
801
801
|
end
|
802
802
|
end
|
803
803
|
end
|
@@ -808,7 +808,7 @@ describe 'SpeedoFormstrap::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.control-group div span.help-inline')
|
812
812
|
end
|
813
813
|
end
|
814
814
|
end
|
@@ -817,7 +817,7 @@ describe 'SpeedoFormstrap::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 'SpeedoFormstrap::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.control-group.string-wrapper")
|
834
|
+
output_buffer.should have_tag("form div.control-group.required")
|
835
|
+
output_buffer.should have_tag("form div.control-group.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.control-group.string-wrapper")
|
843
|
+
output_buffer.should have_tag("form div.control-group.my_class")
|
844
|
+
output_buffer.should have_tag("form div.control-group.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.control-group.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 'SpeedoFormstrap::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.control-group.string-wrapper', :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,36 +909,36 @@ describe 'SpeedoFormstrap::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)
|
918
918
|
concat(semantic_form_for(@new_post) do |builder|
|
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
|
-
class ::StringInput <
|
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 'SpeedoFormstrap::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
|