formtastic-bootstrap 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.document +5 -0
- data/.rspec +1 -0
- data/Gemfile +12 -0
- data/Gemfile.lock +123 -0
- data/LICENSE.txt +20 -0
- data/README.md +159 -0
- data/Rakefile +49 -0
- data/VERSION +1 -0
- data/formtastic-bootstrap.gemspec +128 -0
- data/lib/action_view/helpers/text_field_date_helper.rb +166 -0
- data/lib/formtastic-bootstrap.rb +5 -0
- data/lib/formtastic-bootstrap/form_builder.rb +38 -0
- data/lib/formtastic-bootstrap/helpers.rb +19 -0
- data/lib/formtastic-bootstrap/helpers/buttons_helper.rb +47 -0
- data/lib/formtastic-bootstrap/helpers/fieldset_wrapper.rb +37 -0
- data/lib/formtastic-bootstrap/helpers/input_helper.rb +12 -0
- data/lib/formtastic-bootstrap/helpers/inputs_helper.rb +36 -0
- data/lib/formtastic-bootstrap/inputs.rb +28 -0
- data/lib/formtastic-bootstrap/inputs/base.rb +22 -0
- data/lib/formtastic-bootstrap/inputs/base/choices.rb +49 -0
- data/lib/formtastic-bootstrap/inputs/base/errors.rb +48 -0
- data/lib/formtastic-bootstrap/inputs/base/hints.rb +27 -0
- data/lib/formtastic-bootstrap/inputs/base/html.rb +21 -0
- data/lib/formtastic-bootstrap/inputs/base/labelling.rb +18 -0
- data/lib/formtastic-bootstrap/inputs/base/stringish.rb +18 -0
- data/lib/formtastic-bootstrap/inputs/base/timeish.rb +35 -0
- data/lib/formtastic-bootstrap/inputs/base/wrapping.rb +56 -0
- data/lib/formtastic-bootstrap/inputs/boolean_input.rb +33 -0
- data/lib/formtastic-bootstrap/inputs/check_boxes_input.rb +35 -0
- data/lib/formtastic-bootstrap/inputs/date_input.rb +16 -0
- data/lib/formtastic-bootstrap/inputs/datetime_input.rb +19 -0
- data/lib/formtastic-bootstrap/inputs/email_input.rb +15 -0
- data/lib/formtastic-bootstrap/inputs/file_input.rb +14 -0
- data/lib/formtastic-bootstrap/inputs/hidden_input.rb +12 -0
- data/lib/formtastic-bootstrap/inputs/number_input.rb +15 -0
- data/lib/formtastic-bootstrap/inputs/password_input.rb +15 -0
- data/lib/formtastic-bootstrap/inputs/phone_input.rb +15 -0
- data/lib/formtastic-bootstrap/inputs/radio_input.rb +32 -0
- data/lib/formtastic-bootstrap/inputs/range_input.rb +15 -0
- data/lib/formtastic-bootstrap/inputs/search_input.rb +15 -0
- data/lib/formtastic-bootstrap/inputs/select_input.rb +14 -0
- data/lib/formtastic-bootstrap/inputs/string_input.rb +15 -0
- data/lib/formtastic-bootstrap/inputs/text_input.rb +14 -0
- data/lib/formtastic-bootstrap/inputs/time_input.rb +16 -0
- data/lib/formtastic-bootstrap/inputs/url_input.rb +14 -0
- data/spec/builder/errors_spec.rb +214 -0
- data/spec/builder/semantic_fields_for_spec.rb +130 -0
- data/spec/helpers/input_helper_spec.rb +956 -0
- data/spec/helpers/inputs_helper_spec.rb +577 -0
- data/spec/inputs/boolean_input_spec.rb +193 -0
- data/spec/inputs/check_boxes_input_spec.rb +439 -0
- data/spec/inputs/date_input_spec.rb +147 -0
- data/spec/inputs/datetime_input_spec.rb +101 -0
- data/spec/inputs/email_input_spec.rb +59 -0
- data/spec/inputs/file_input_spec.rb +63 -0
- data/spec/inputs/hidden_input_spec.rb +122 -0
- data/spec/inputs/number_input_spec.rb +787 -0
- data/spec/inputs/password_input_spec.rb +73 -0
- data/spec/inputs/phone_input_spec.rb +59 -0
- data/spec/inputs/radio_input_spec.rb +240 -0
- data/spec/inputs/range_input_spec.rb +479 -0
- data/spec/inputs/search_input_spec.rb +59 -0
- data/spec/inputs/select_input_spec.rb +567 -0
- data/spec/inputs/string_input_spec.rb +182 -0
- data/spec/inputs/text_input_spec.rb +163 -0
- data/spec/inputs/time_input_spec.rb +206 -0
- data/spec/inputs/url_input_spec.rb +59 -0
- data/spec/spec_helper.rb +24 -0
- data/spec/support/custom_macros.rb +704 -0
- data/spec/support/depracation.rb +6 -0
- data/spec/support/formtastic_spec_helper.rb +382 -0
- metadata +204 -0
@@ -0,0 +1,147 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe 'date input' do
|
5
|
+
|
6
|
+
include FormtasticSpecHelper
|
7
|
+
|
8
|
+
before do
|
9
|
+
@output_buffer = ''
|
10
|
+
mock_everything
|
11
|
+
Formtastic::Helpers::FormHelper.builder = FormtasticBootstrap::FormBuilder
|
12
|
+
end
|
13
|
+
|
14
|
+
describe "general" do
|
15
|
+
|
16
|
+
before do
|
17
|
+
output_buffer.replace ''
|
18
|
+
concat(semantic_form_for(@new_post) do |builder|
|
19
|
+
concat(builder.input(:publish_at, :as => :date, :order => [:year, :month, :day]))
|
20
|
+
end)
|
21
|
+
end
|
22
|
+
|
23
|
+
it_should_have_input_wrapper_with_class("date")
|
24
|
+
it_should_have_input_wrapper_with_class(:clearfix)
|
25
|
+
it_should_have_input_wrapper_with_class(:stringish)
|
26
|
+
it_should_have_input_class_in_the_right_place
|
27
|
+
it_should_have_input_wrapper_with_id("post_publish_at_input")
|
28
|
+
it_should_have_a_nested_div
|
29
|
+
# it_should_have_a_nested_fieldset_with_class('fragments')
|
30
|
+
# it_should_have_a_nested_ordered_list_with_class('fragments-group')
|
31
|
+
it_should_apply_error_logic_for_input_type(:date)
|
32
|
+
|
33
|
+
it 'should have a legend and label with the label text inside the fieldset' do
|
34
|
+
output_buffer.should have_tag('form div.clearfix.date label', /Publish at/)
|
35
|
+
end
|
36
|
+
|
37
|
+
# it 'should associate the legend label with the first select' do
|
38
|
+
# output_buffer.should have_tag('form li.date fieldset legend.label')
|
39
|
+
# output_buffer.should have_tag('form li.date fieldset legend.label label')
|
40
|
+
# output_buffer.should have_tag('form li.date fieldset legend.label label[@for]')
|
41
|
+
# output_buffer.should have_tag('form li.date fieldset legend.label label[@for="post_publish_at_1i"]')
|
42
|
+
# end
|
43
|
+
|
44
|
+
it 'should (sort of) associate the label with the input' do
|
45
|
+
output_buffer.should have_tag('form div.clearfix.date label[@for="post_publish_at"]')
|
46
|
+
output_buffer.should have_tag('form div.clearfix.date div.input input[@id="post_publish_at[date]"]')
|
47
|
+
end
|
48
|
+
|
49
|
+
# it 'should have an ordered list of three items inside the fieldset' do
|
50
|
+
# output_buffer.should have_tag('form li.date fieldset ol.fragments-group')
|
51
|
+
# output_buffer.should have_tag('form li.date fieldset ol li.fragment', :count => 3)
|
52
|
+
# end
|
53
|
+
|
54
|
+
# it 'should have three labels for year, month and day' do
|
55
|
+
# output_buffer.should have_tag('form li.date fieldset ol li label', :count => 3)
|
56
|
+
# output_buffer.should have_tag('form li.date fieldset ol li label', /year/i)
|
57
|
+
# output_buffer.should have_tag('form li.date fieldset ol li label', /month/i)
|
58
|
+
# output_buffer.should have_tag('form li.date fieldset ol li label', /day/i)
|
59
|
+
# end
|
60
|
+
it 'should have an text input inside the div' do
|
61
|
+
output_buffer.should have_tag('form div.clearfix.date div.input input[@type="text"]')
|
62
|
+
end
|
63
|
+
|
64
|
+
# it 'should have three selects for year, month and day' do
|
65
|
+
# output_buffer.should have_tag('form li.date fieldset ol li select', :count => 3)
|
66
|
+
# end
|
67
|
+
end
|
68
|
+
|
69
|
+
describe "when namespace is provided" do
|
70
|
+
|
71
|
+
before do
|
72
|
+
output_buffer.replace ''
|
73
|
+
concat(semantic_form_for(@new_post, :namespace => "context2") do |builder|
|
74
|
+
concat(builder.input(:publish_at, :as => :date, :order => [:year, :month, :day]))
|
75
|
+
end)
|
76
|
+
end
|
77
|
+
|
78
|
+
it_should_have_input_wrapper_with_id("context2_post_publish_at_input")
|
79
|
+
it_should_have_input_with_id("context2_post_publish_at[date]")
|
80
|
+
# it_should_have_select_with_id("context2_post_publish_at_2i")
|
81
|
+
# it_should_have_select_with_id("context2_post_publish_at_3i")
|
82
|
+
|
83
|
+
end
|
84
|
+
|
85
|
+
# We only use a single label for the entire entity.
|
86
|
+
|
87
|
+
# describe ':labels option' do
|
88
|
+
# fields = [:year, :month, :day]
|
89
|
+
# fields.each do |field|
|
90
|
+
# it "should replace the #{field} label with the specified text if :labels[:#{field}] is set" do
|
91
|
+
# output_buffer.replace ''
|
92
|
+
# concat(semantic_form_for(@new_post) do |builder|
|
93
|
+
# concat(builder.input(:created_at, :as => :date, :labels => { field => "another #{field} label" }))
|
94
|
+
# end)
|
95
|
+
# output_buffer.should have_tag('form li.date fieldset ol li label', :count => fields.length)
|
96
|
+
# fields.each do |f|
|
97
|
+
# output_buffer.should have_tag('form li.date fieldset ol li label', f == field ? /another #{f} label/i : /#{f}/i)
|
98
|
+
# end
|
99
|
+
# end
|
100
|
+
#
|
101
|
+
# it "should not display the label for the #{field} field when :labels[:#{field}] is blank" do
|
102
|
+
# output_buffer.replace ''
|
103
|
+
# concat(semantic_form_for(@new_post) do |builder|
|
104
|
+
# concat(builder.input(:created_at, :as => :date, :labels => { field => "" }))
|
105
|
+
# end)
|
106
|
+
# output_buffer.should have_tag('form li.date fieldset ol li label', :count => fields.length-1)
|
107
|
+
# fields.each do |f|
|
108
|
+
# output_buffer.should have_tag('form li.date fieldset ol li label', /#{f}/i) unless field == f
|
109
|
+
# end
|
110
|
+
# end
|
111
|
+
#
|
112
|
+
# it "should not display the label for the #{field} field when :labels[:#{field}] is false" do
|
113
|
+
# output_buffer.replace ''
|
114
|
+
# concat(semantic_form_for(@new_post) do |builder|
|
115
|
+
# concat(builder.input(:created_at, :as => :date, :labels => { field => false }))
|
116
|
+
# end)
|
117
|
+
# output_buffer.should have_tag('form li.date fieldset ol li label', :count => fields.length-1)
|
118
|
+
# fields.each do |f|
|
119
|
+
# output_buffer.should have_tag('form li.date fieldset ol li label', /#{f}/i) unless field == f
|
120
|
+
# end
|
121
|
+
# end
|
122
|
+
#
|
123
|
+
# it "should not render unsafe HTML when :labels[:#{field}] is false" do
|
124
|
+
# output_buffer.replace ''
|
125
|
+
# concat(semantic_form_for(@new_post) do |builder|
|
126
|
+
# concat(builder.input(:created_at, :as => :time, :include_seconds => true, :labels => { field => false }))
|
127
|
+
# end)
|
128
|
+
# output_buffer.should_not include(">")
|
129
|
+
# end
|
130
|
+
#
|
131
|
+
# end
|
132
|
+
# end
|
133
|
+
|
134
|
+
describe "when required" do
|
135
|
+
it "should add the required attribute to the input's html options" do
|
136
|
+
with_config :use_required_attribute, true do
|
137
|
+
concat(semantic_form_for(@new_post) do |builder|
|
138
|
+
concat(builder.input(:title, :as => :date, :required => true))
|
139
|
+
end)
|
140
|
+
# output_buffer.should have_tag("select[@required]", :count => 3)
|
141
|
+
# We only have one text field.
|
142
|
+
output_buffer.should have_tag("input[@required]", :count => 1)
|
143
|
+
end
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
end
|
@@ -0,0 +1,101 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe 'datetime input' do
|
5
|
+
|
6
|
+
include FormtasticSpecHelper
|
7
|
+
|
8
|
+
before do
|
9
|
+
@output_buffer = ''
|
10
|
+
mock_everything
|
11
|
+
Formtastic::Helpers::FormHelper.builder = FormtasticBootstrap::FormBuilder
|
12
|
+
end
|
13
|
+
|
14
|
+
describe "general" do
|
15
|
+
|
16
|
+
before do
|
17
|
+
::I18n.backend.store_translations :en, {}
|
18
|
+
output_buffer.replace ''
|
19
|
+
concat(semantic_form_for(@new_post) do |builder|
|
20
|
+
concat(builder.input(:publish_at, :as => :datetime))
|
21
|
+
end)
|
22
|
+
end
|
23
|
+
|
24
|
+
it_should_have_input_wrapper_with_class("datetime")
|
25
|
+
it_should_have_input_wrapper_with_class(:clearfix)
|
26
|
+
it_should_have_input_wrapper_with_class(:stringish) # Decide about this.
|
27
|
+
it_should_have_input_class_in_the_right_place
|
28
|
+
it_should_have_input_wrapper_with_id("post_publish_at_input")
|
29
|
+
it_should_have_a_nested_div
|
30
|
+
# it_should_have_a_nested_fieldset_with_class('fragments')
|
31
|
+
# it_should_have_a_nested_ordered_list_with_class('fragments-group')
|
32
|
+
it_should_apply_error_logic_for_input_type(:datetime)
|
33
|
+
|
34
|
+
it 'should have a legend and label with the label text inside the fieldset' do
|
35
|
+
output_buffer.should have_tag('form div.clearfix.datetime label', /Publish at/)
|
36
|
+
end
|
37
|
+
|
38
|
+
# it 'should associate the legend label with the first select' do
|
39
|
+
# output_buffer.should have_tag('form li.datetime fieldset legend.label')
|
40
|
+
# output_buffer.should have_tag('form li.datetime fieldset legend.label label')
|
41
|
+
# output_buffer.should have_tag('form li.datetime fieldset legend.label label[@for]')
|
42
|
+
# output_buffer.should have_tag('form li.datetime fieldset legend.label label[@for="post_publish_at_1i"]')
|
43
|
+
# end
|
44
|
+
|
45
|
+
# it 'should have an ordered list of five items inside the fieldset' do
|
46
|
+
# output_buffer.should have_tag('form li.datetime fieldset ol.fragments-group')
|
47
|
+
# output_buffer.should have_tag('form li.datetime fieldset ol li.fragment', :count => 5)
|
48
|
+
# end
|
49
|
+
|
50
|
+
# it 'should have five labels for year, month and day' do
|
51
|
+
# output_buffer.should have_tag('form li.datetime fieldset ol li label', :count => 5)
|
52
|
+
# output_buffer.should have_tag('form li.datetime fieldset ol li label', /year/i)
|
53
|
+
# output_buffer.should have_tag('form li.datetime fieldset ol li label', /month/i)
|
54
|
+
# output_buffer.should have_tag('form li.datetime fieldset ol li label', /day/i)
|
55
|
+
# output_buffer.should have_tag('form li.datetime fieldset ol li label', /hour/i)
|
56
|
+
# output_buffer.should have_tag('form li.datetime fieldset ol li label', /min/i)
|
57
|
+
# end
|
58
|
+
|
59
|
+
# it 'should have five selects' do
|
60
|
+
# output_buffer.should have_tag('form li.datetime fieldset ol li select', :count => 5)
|
61
|
+
# end
|
62
|
+
|
63
|
+
it 'should have two inputs' do
|
64
|
+
output_buffer.should have_tag('form div.clearfix.datetime div.input input', :count => 2)
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
68
|
+
|
69
|
+
describe "when namespace is provided" do
|
70
|
+
|
71
|
+
before do
|
72
|
+
output_buffer.replace ''
|
73
|
+
concat(semantic_form_for(@new_post, :namespace => "context2") do |builder|
|
74
|
+
concat(builder.input(:publish_at, :as => :datetime))
|
75
|
+
end)
|
76
|
+
end
|
77
|
+
|
78
|
+
it_should_have_input_wrapper_with_id("context2_post_publish_at_input")
|
79
|
+
it_should_have_input_with_id("context2_post_publish_at[date]")
|
80
|
+
it_should_have_input_with_id("context2_post_publish_at[time]")
|
81
|
+
# it_should_have_input_with_id("context2_post_publish_at_1i")
|
82
|
+
# it_should_have_select_with_id("context2_post_publish_at_2i")
|
83
|
+
# it_should_have_select_with_id("context2_post_publish_at_3i")
|
84
|
+
# it_should_have_select_with_id("context2_post_publish_at_4i")
|
85
|
+
# it_should_have_select_with_id("context2_post_publish_at_5i")
|
86
|
+
|
87
|
+
end
|
88
|
+
|
89
|
+
describe "when required" do
|
90
|
+
it "should add the required attribute to the input's html options" do
|
91
|
+
with_config :use_required_attribute, true do
|
92
|
+
concat(semantic_form_for(@new_post) do |builder|
|
93
|
+
concat(builder.input(:title, :as => :datetime, :required => true))
|
94
|
+
end)
|
95
|
+
# output_buffer.should have_tag("select[@required]", :count => 5)
|
96
|
+
output_buffer.should have_tag("input[@required]", :count => 2)
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe 'email input' do
|
5
|
+
|
6
|
+
include FormtasticSpecHelper
|
7
|
+
|
8
|
+
before do
|
9
|
+
@output_buffer = ''
|
10
|
+
mock_everything
|
11
|
+
Formtastic::Helpers::FormHelper.builder = FormtasticBootstrap::FormBuilder
|
12
|
+
end
|
13
|
+
|
14
|
+
describe "when object is provided" do
|
15
|
+
before do
|
16
|
+
concat(semantic_form_for(@new_post) do |builder|
|
17
|
+
concat(builder.input(:email))
|
18
|
+
end)
|
19
|
+
end
|
20
|
+
|
21
|
+
it_should_have_input_wrapper_with_class(:email)
|
22
|
+
it_should_have_input_wrapper_with_class(:clearfix)
|
23
|
+
it_should_have_input_wrapper_with_class(:stringish)
|
24
|
+
it_should_have_input_class_in_the_right_place
|
25
|
+
it_should_have_input_wrapper_with_id("post_email_input")
|
26
|
+
it_should_have_label_with_text(/Email/)
|
27
|
+
it_should_have_label_for("post_email")
|
28
|
+
it_should_have_input_with_id("post_email")
|
29
|
+
it_should_have_input_with_type(:email)
|
30
|
+
it_should_have_input_with_name("post[email]")
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
describe "when namespace is provided" do
|
35
|
+
|
36
|
+
before do
|
37
|
+
concat(semantic_form_for(@new_post, :namespace => 'context2') do |builder|
|
38
|
+
concat(builder.input(:email))
|
39
|
+
end)
|
40
|
+
end
|
41
|
+
|
42
|
+
it_should_have_input_wrapper_with_id("context2_post_email_input")
|
43
|
+
it_should_have_label_and_input_with_id("context2_post_email")
|
44
|
+
|
45
|
+
end
|
46
|
+
|
47
|
+
describe "when required" do
|
48
|
+
it "should add the required attribute to the input's html options" do
|
49
|
+
with_config :use_required_attribute, true do
|
50
|
+
concat(semantic_form_for(@new_post) do |builder|
|
51
|
+
concat(builder.input(:title, :as => :email, :required => true))
|
52
|
+
end)
|
53
|
+
output_buffer.should have_tag("input[@required]")
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
|
@@ -0,0 +1,63 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe 'file input' do
|
5
|
+
|
6
|
+
include FormtasticSpecHelper
|
7
|
+
|
8
|
+
before do
|
9
|
+
@output_buffer = ''
|
10
|
+
mock_everything
|
11
|
+
Formtastic::Helpers::FormHelper.builder = FormtasticBootstrap::FormBuilder
|
12
|
+
|
13
|
+
concat(semantic_form_for(@new_post) do |builder|
|
14
|
+
concat(builder.input(:body, :as => :file))
|
15
|
+
end)
|
16
|
+
end
|
17
|
+
|
18
|
+
it_should_have_input_wrapper_with_class("file")
|
19
|
+
it_should_have_input_wrapper_with_class(:clearfix)
|
20
|
+
it_should_have_input_class_in_the_right_place
|
21
|
+
it_should_have_input_wrapper_with_id("post_body_input")
|
22
|
+
it_should_have_label_with_text(/Body/)
|
23
|
+
it_should_have_label_for("post_body")
|
24
|
+
it_should_have_input_with_id("post_body")
|
25
|
+
it_should_have_input_with_name("post[body]")
|
26
|
+
it_should_apply_error_logic_for_input_type(:file)
|
27
|
+
|
28
|
+
it 'should use input_html to style inputs' do
|
29
|
+
concat(semantic_form_for(@new_post) do |builder|
|
30
|
+
concat(builder.input(:title, :as => :file, :input_html => { :class => 'myclass' }))
|
31
|
+
end)
|
32
|
+
output_buffer.should have_tag("form div.clearfix div.input input.myclass")
|
33
|
+
end
|
34
|
+
|
35
|
+
describe "when namespace is provided" do
|
36
|
+
|
37
|
+
before do
|
38
|
+
@output_buffer = ''
|
39
|
+
mock_everything
|
40
|
+
|
41
|
+
concat(semantic_form_for(@new_post, :namespace => 'context2') do |builder|
|
42
|
+
concat(builder.input(:body, :as => :file))
|
43
|
+
end)
|
44
|
+
end
|
45
|
+
|
46
|
+
it_should_have_input_wrapper_with_id("context2_post_body_input")
|
47
|
+
it_should_have_label_and_input_with_id("context2_post_body")
|
48
|
+
|
49
|
+
end
|
50
|
+
|
51
|
+
context "when required" do
|
52
|
+
it "should add the required attribute to the input's html options" do
|
53
|
+
with_config :use_required_attribute, true do
|
54
|
+
concat(semantic_form_for(@new_post) do |builder|
|
55
|
+
concat(builder.input(:title, :as => :file, :required => true))
|
56
|
+
end)
|
57
|
+
output_buffer.should have_tag("input[@required]")
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
63
|
+
|
@@ -0,0 +1,122 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe 'hidden input' do
|
5
|
+
|
6
|
+
include FormtasticSpecHelper
|
7
|
+
|
8
|
+
before do
|
9
|
+
@output_buffer = ''
|
10
|
+
mock_everything
|
11
|
+
Formtastic::Helpers::FormHelper.builder = FormtasticBootstrap::FormBuilder
|
12
|
+
|
13
|
+
concat(semantic_form_for(@new_post) do |builder|
|
14
|
+
concat(builder.input(:secret, :as => :hidden))
|
15
|
+
concat(builder.input(:author_id, :as => :hidden, :value => 99))
|
16
|
+
concat(builder.input(:published, :as => :hidden, :input_html => {:value => true}))
|
17
|
+
concat(builder.input(:reviewer, :as => :hidden, :input_html => {:class => 'new_post_reviewer', :id => 'new_post_reviewer'}))
|
18
|
+
concat(builder.input(:author, :as => :hidden, :value => 'direct_value', :input_html => {:value => "formtastic_value"}))
|
19
|
+
end)
|
20
|
+
end
|
21
|
+
|
22
|
+
it_should_have_input_wrapper_with_class("hidden")
|
23
|
+
it_should_have_input_wrapper_with_class(:clearfix)
|
24
|
+
it_should_have_input_class_in_the_right_place
|
25
|
+
it_should_have_input_wrapper_with_id("post_secret_input")
|
26
|
+
it_should_not_have_a_label
|
27
|
+
|
28
|
+
it "should generate a input field" do
|
29
|
+
output_buffer.should have_tag("form div.clearfix div.input input#post_secret")
|
30
|
+
output_buffer.should have_tag("form div.clearfix div.input input#post_secret[@type=\"hidden\"]")
|
31
|
+
output_buffer.should have_tag("form div.clearfix div.input input#post_secret[@name=\"post[secret]\"]")
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should get value from the object" do
|
35
|
+
output_buffer.should have_tag("form div.clearfix div.input input#post_secret[@type=\"hidden\"][@value=\"1\"]")
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should pass any explicitly specified value - using :value" do
|
39
|
+
output_buffer.should have_tag("form div.clearfix div.input input#post_author_id[@type=\"hidden\"][@value=\"99\"]")
|
40
|
+
end
|
41
|
+
|
42
|
+
# Handle Formtastic :input_html options for consistency.
|
43
|
+
it "should pass any explicitly specified value - using :input_html options" do
|
44
|
+
output_buffer.should have_tag("form div.clearfix div.input input#post_published[@type=\"hidden\"][@value=\"true\"]")
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should pass any option specified using :input_html" do
|
48
|
+
output_buffer.should have_tag("form div.clearfix div.input input#new_post_reviewer[@type=\"hidden\"][@class=\"new_post_reviewer\"]")
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should prefer :input_html over directly supplied options" do
|
52
|
+
output_buffer.should have_tag("form div.clearfix div.input input#post_author_id[@type=\"hidden\"][@value=\"formtastic_value\"]")
|
53
|
+
end
|
54
|
+
|
55
|
+
it "should not render inline errors" do
|
56
|
+
@errors = mock('errors')
|
57
|
+
@errors.stub!(:[]).with(:secret).and_return(["foo", "bah"])
|
58
|
+
@new_post.stub!(:errors).and_return(@errors)
|
59
|
+
|
60
|
+
concat(semantic_form_for(@new_post) do |builder|
|
61
|
+
concat(builder.input(:secret, :as => :hidden))
|
62
|
+
end)
|
63
|
+
|
64
|
+
output_buffer.should_not have_tag("form li p.inline-errors")
|
65
|
+
output_buffer.should_not have_tag("form li ul.errors")
|
66
|
+
end
|
67
|
+
|
68
|
+
it "should not render inline hints" do
|
69
|
+
concat(semantic_form_for(@new_post) do |builder|
|
70
|
+
concat(builder.input(:secret, :as => :hidden, :hint => "all your base are belong to use"))
|
71
|
+
end)
|
72
|
+
|
73
|
+
output_buffer.should_not have_tag("form li p.inline-hints")
|
74
|
+
output_buffer.should_not have_tag("form li ul.hints")
|
75
|
+
end
|
76
|
+
|
77
|
+
describe "when namespace is provided" do
|
78
|
+
|
79
|
+
before do
|
80
|
+
@output_buffer = ''
|
81
|
+
mock_everything
|
82
|
+
|
83
|
+
concat(semantic_form_for(@new_post, :namespace => 'context2') do |builder|
|
84
|
+
concat(builder.input(:secret, :as => :hidden))
|
85
|
+
concat(builder.input(:author_id, :as => :hidden, :value => 99))
|
86
|
+
concat(builder.input(:published, :as => :hidden, :input_html => {:value => true}))
|
87
|
+
concat(builder.input(:reviewer, :as => :hidden, :input_html => {:class => 'new_post_reviewer', :id => 'new_post_reviewer'}))
|
88
|
+
concat(builder.input(:author, :as => :hidden, :value => 'direct_value', :input_html => {:value => "formtastic_value"}))
|
89
|
+
end)
|
90
|
+
end
|
91
|
+
|
92
|
+
attributes_to_check = [:secret, :author_id, :published, :reviewer]
|
93
|
+
attributes_to_check.each do |a|
|
94
|
+
it_should_have_input_wrapper_with_id("context2_post_#{a}_input")
|
95
|
+
end
|
96
|
+
|
97
|
+
(attributes_to_check - [:reviewer]).each do |a|
|
98
|
+
it_should_have_input_with_id("context2_post_#{a}")
|
99
|
+
end
|
100
|
+
|
101
|
+
end
|
102
|
+
|
103
|
+
context "when required" do
|
104
|
+
it "should not add the required attribute to the input's html options" do
|
105
|
+
concat(semantic_form_for(@new_post) do |builder|
|
106
|
+
concat(builder.input(:title, :as => :hidden, :required => true))
|
107
|
+
end)
|
108
|
+
output_buffer.should_not have_tag("input[@required]")
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
context "when :autofocus is provided in :input_html" do
|
113
|
+
it "should not add the autofocus attribute to the input's html options" do
|
114
|
+
concat(semantic_form_for(@new_post) do |builder|
|
115
|
+
concat(builder.input(:title, :as => :hidden, :input_html => {:autofocus => true}))
|
116
|
+
end)
|
117
|
+
output_buffer.should_not have_tag("input[@autofocus]")
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
end
|
122
|
+
|