speedo-formstrap 1.2.7 → 1.2.8
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +2 -2
- data/Gemfile.lock +67 -65
- data/README.md +12 -2
- data/Rakefile +1 -1
- data/VERSION +1 -1
- data/lib/formtastic-bootstrap.rb +1 -0
- data/lib/formtastic-bootstrap/actions.rb +4 -0
- data/lib/formtastic-bootstrap/actions/base.rb +18 -0
- data/lib/formtastic-bootstrap/actions/button_action.rb +7 -0
- data/lib/formtastic-bootstrap/actions/input_action.rb +7 -0
- data/lib/formtastic-bootstrap/actions/link_action.rb +7 -0
- data/lib/formtastic-bootstrap/form_builder.rb +7 -5
- data/lib/formtastic-bootstrap/helpers.rb +3 -1
- data/lib/formtastic-bootstrap/helpers/action_helper.rb +12 -0
- data/lib/formtastic-bootstrap/helpers/actions_helper.rb +23 -0
- data/lib/formtastic-bootstrap/helpers/buttons_helper.rb +13 -9
- data/lib/formtastic-bootstrap/helpers/fieldset_wrapper.rb +11 -6
- data/lib/formtastic-bootstrap/helpers/inputs_helper.rb +4 -4
- data/lib/formtastic-bootstrap/inputs/base.rb +2 -1
- data/lib/formtastic-bootstrap/inputs/base/choices.rb +12 -23
- data/lib/formtastic-bootstrap/inputs/base/labelling.rb +16 -6
- data/lib/formtastic-bootstrap/inputs/base/numeric.rb +18 -0
- data/lib/formtastic-bootstrap/inputs/base/timeish.rb +5 -12
- data/lib/formtastic-bootstrap/inputs/base/wrapping.rb +32 -14
- data/lib/formtastic-bootstrap/inputs/boolean_input.rb +7 -11
- data/lib/formtastic-bootstrap/inputs/check_boxes_input.rb +10 -9
- data/lib/formtastic-bootstrap/inputs/hidden_input.rb +5 -3
- data/lib/formtastic-bootstrap/inputs/number_input.rb +2 -2
- data/lib/formtastic-bootstrap/inputs/radio_input.rb +13 -12
- data/lib/formtastic-bootstrap/inputs/range_input.rb +2 -2
- data/spec/actions/button_action_spec.rb +68 -0
- data/spec/actions/generic_action_spec.rb +486 -0
- data/spec/actions/input_action_spec.rb +64 -0
- data/spec/actions/link_action_spec.rb +93 -0
- data/spec/builder/semantic_fields_for_spec.rb +14 -14
- data/spec/helpers/action_helper_spec.rb +365 -0
- data/spec/helpers/actions_helper_spec.rb +143 -0
- data/spec/helpers/buttons_helper_spec.rb +55 -45
- data/spec/helpers/input_helper_spec.rb +188 -188
- data/spec/helpers/inputs_helper_spec.rb +116 -102
- data/spec/inputs/boolean_input_spec.rb +72 -44
- data/spec/inputs/check_boxes_input_spec.rb +108 -80
- data/spec/inputs/date_input_spec.rb +80 -14
- data/spec/inputs/datetime_input_spec.rb +12 -12
- data/spec/inputs/email_input_spec.rb +33 -5
- data/spec/inputs/file_input_spec.rb +33 -5
- data/spec/inputs/hidden_input_spec.rb +40 -12
- data/spec/inputs/number_input_spec.rb +126 -96
- data/spec/inputs/password_input_spec.rb +33 -5
- data/spec/inputs/phone_input_spec.rb +33 -5
- data/spec/inputs/radio_input_spec.rb +72 -44
- data/spec/inputs/range_input_spec.rb +93 -65
- data/spec/inputs/search_input_spec.rb +32 -5
- data/spec/inputs/select_input_spec.rb +123 -77
- data/spec/inputs/string_input_spec.rb +66 -21
- data/spec/inputs/text_input_spec.rb +40 -13
- 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 +33 -5
- data/spec/support/custom_macros.rb +59 -188
- data/spec/support/formtastic_spec_helper.rb +19 -3
- data/speedo-formstrap.gemspec +146 -0
- metadata +31 -16
@@ -0,0 +1,64 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe 'InputAction', 'when submitting' 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.action(:submit, :as => :input))
|
15
|
+
end)
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'should render a submit type of input' do
|
19
|
+
output_buffer.should have_tag('input[@type="submit"].action.input_action.btn.btn-primary')
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
describe 'InputAction', 'when resetting' do
|
25
|
+
|
26
|
+
include FormtasticSpecHelper
|
27
|
+
|
28
|
+
before do
|
29
|
+
@output_buffer = ''
|
30
|
+
mock_everything
|
31
|
+
|
32
|
+
concat(semantic_form_for(@new_post) do |builder|
|
33
|
+
concat(builder.action(:reset, :as => :input))
|
34
|
+
end)
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'should render a reset type of input' do
|
38
|
+
output_buffer.should have_tag('input[@type="reset"].action.input_action.btn')
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'should not be primary' do
|
42
|
+
output_buffer.should_not have_tag('input[@type="reset"].action.input_action.btn.btn-primary')
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
|
47
|
+
describe 'InputAction', 'when cancelling' do
|
48
|
+
|
49
|
+
include FormtasticSpecHelper
|
50
|
+
|
51
|
+
before do
|
52
|
+
@output_buffer = ''
|
53
|
+
mock_everything
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'should raise an error' do
|
57
|
+
lambda {
|
58
|
+
concat(semantic_form_for(@new_post) do |builder|
|
59
|
+
concat(builder.action(:cancel, :as => :input))
|
60
|
+
end)
|
61
|
+
}.should raise_error(Formtastic::UnsupportedMethodForAction)
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
@@ -0,0 +1,93 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe 'LinkAction', 'when cancelling' 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
|
+
context 'without a :url' do
|
15
|
+
before do
|
16
|
+
concat(semantic_form_for(@new_post) do |builder|
|
17
|
+
concat(builder.action(:cancel, :as => :link))
|
18
|
+
end)
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'should render a submit type of input' do
|
22
|
+
output_buffer.should have_tag('a[@href="javascript:history.back()"].action.link_action.btn')
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
context 'with a :url as String' do
|
28
|
+
|
29
|
+
before do
|
30
|
+
concat(semantic_form_for(@new_post) do |builder|
|
31
|
+
concat(builder.action(:cancel, :as => :link, :url => "http://foo.bah/baz"))
|
32
|
+
end)
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'should render a submit type of input' do
|
36
|
+
output_buffer.should have_tag('a[@href="http://foo.bah/baz"].action.link_action.btn')
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
context 'with a :url as Hash' do
|
42
|
+
|
43
|
+
before do
|
44
|
+
concat(semantic_form_for(@new_post) do |builder|
|
45
|
+
concat(builder.action(:cancel, :as => :link, :url => { :action => "foo" }))
|
46
|
+
end)
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'should render a submit type of input' do
|
50
|
+
output_buffer.should have_tag('a[@href="/mock/path"].action.link_action.btn')
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
56
|
+
|
57
|
+
describe 'LinkAction', 'when submitting' do
|
58
|
+
|
59
|
+
include FormtasticSpecHelper
|
60
|
+
|
61
|
+
before do
|
62
|
+
@output_buffer = ''
|
63
|
+
mock_everything
|
64
|
+
end
|
65
|
+
|
66
|
+
it 'should raise an error' do
|
67
|
+
lambda {
|
68
|
+
concat(semantic_form_for(@new_post) do |builder|
|
69
|
+
concat(builder.action(:submit, :as => :link))
|
70
|
+
end)
|
71
|
+
}.should raise_error(Formtastic::UnsupportedMethodForAction)
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|
75
|
+
|
76
|
+
describe 'LinkAction', 'when submitting' do
|
77
|
+
|
78
|
+
include FormtasticSpecHelper
|
79
|
+
|
80
|
+
before do
|
81
|
+
@output_buffer = ''
|
82
|
+
mock_everything
|
83
|
+
end
|
84
|
+
|
85
|
+
it 'should raise an error' do
|
86
|
+
lambda {
|
87
|
+
concat(semantic_form_for(@new_post) do |builder|
|
88
|
+
concat(builder.action(:reset, :as => :link))
|
89
|
+
end)
|
90
|
+
}.should raise_error(Formtastic::UnsupportedMethodForAction)
|
91
|
+
end
|
92
|
+
|
93
|
+
end
|
@@ -27,7 +27,7 @@ describe 'FormtasticBootstrap::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 'FormtasticBootstrap::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 'FormtasticBootstrap::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 'FormtasticBootstrap::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 'FormtasticBootstrap::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 'FormtasticBootstrap::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 'FormtasticBootstrap::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 'FormtasticBootstrap::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 'FormtasticBootstrap::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
|
|
@@ -0,0 +1,365 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe 'Formtastic::FormBuilder#action' 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
|
+
after do
|
15
|
+
::I18n.backend.reload!
|
16
|
+
end
|
17
|
+
|
18
|
+
describe 'arguments and options' do
|
19
|
+
|
20
|
+
it 'should require the first argument (the action method)' do
|
21
|
+
lambda {
|
22
|
+
concat(semantic_form_for(@new_post) do |builder|
|
23
|
+
concat(builder.action()) # no args passed in at all
|
24
|
+
end)
|
25
|
+
}.should raise_error(ArgumentError)
|
26
|
+
end
|
27
|
+
|
28
|
+
describe ':as option' do
|
29
|
+
|
30
|
+
describe 'when not provided' do
|
31
|
+
|
32
|
+
it 'should default to a commit for commit' do
|
33
|
+
concat(semantic_form_for(:project, :url => 'http://test.host') do |builder|
|
34
|
+
concat(builder.action(:submit))
|
35
|
+
end)
|
36
|
+
output_buffer.should have_tag('form input.action.input_action', :count => 1)
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'should default to a button for reset' do
|
40
|
+
concat(semantic_form_for(:project, :url => 'http://test.host') do |builder|
|
41
|
+
concat(builder.action(:reset))
|
42
|
+
end)
|
43
|
+
output_buffer.should have_tag('form input.action.input_action', :count => 1)
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'should default to a link for cancel' do
|
47
|
+
concat(semantic_form_for(:project, :url => 'http://test.host') do |builder|
|
48
|
+
concat(builder.action(:cancel))
|
49
|
+
end)
|
50
|
+
output_buffer.should have_tag('form a.action.link_action', :count => 1)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'should call the corresponding action class with .to_html' do
|
55
|
+
[:input, :button, :link].each do |action_style|
|
56
|
+
semantic_form_for(:project, :url => "http://test.host") do |builder|
|
57
|
+
action_instance = mock('Action instance')
|
58
|
+
action_class = "#{action_style.to_s}_action".classify
|
59
|
+
action_constant = "Formtastic::Actions::#{action_class}".constantize
|
60
|
+
|
61
|
+
action_constant.should_receive(:new).and_return(action_instance)
|
62
|
+
action_instance.should_receive(:to_html).and_return("some HTML")
|
63
|
+
|
64
|
+
concat(builder.action(:submit, :as => action_style))
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
70
|
+
|
71
|
+
#describe ':label option' do
|
72
|
+
#
|
73
|
+
# describe 'when provided' do
|
74
|
+
# it 'should be passed down to the label tag' do
|
75
|
+
# concat(semantic_form_for(@new_post) do |builder|
|
76
|
+
# concat(builder.input(:title, :label => "Kustom"))
|
77
|
+
# end)
|
78
|
+
# output_buffer.should have_tag("form li label", /Kustom/)
|
79
|
+
# end
|
80
|
+
#
|
81
|
+
# it 'should not generate a label if false' do
|
82
|
+
# concat(semantic_form_for(@new_post) do |builder|
|
83
|
+
# concat(builder.input(:title, :label => false))
|
84
|
+
# end)
|
85
|
+
# output_buffer.should_not have_tag("form li label")
|
86
|
+
# end
|
87
|
+
#
|
88
|
+
# it 'should be dupped if frozen' do
|
89
|
+
# concat(semantic_form_for(@new_post) do |builder|
|
90
|
+
# concat(builder.input(:title, :label => "Kustom".freeze))
|
91
|
+
# end)
|
92
|
+
# output_buffer.should have_tag("form li label", /Kustom/)
|
93
|
+
# end
|
94
|
+
# end
|
95
|
+
#
|
96
|
+
# describe 'when not provided' do
|
97
|
+
# describe 'when localized label is provided' do
|
98
|
+
# describe 'and object is given' do
|
99
|
+
# describe 'and label_str_method not :humanize' do
|
100
|
+
# it 'should render a label with localized text and not apply the label_str_method' do
|
101
|
+
# with_config :label_str_method, :reverse do
|
102
|
+
# @localized_label_text = 'Localized title'
|
103
|
+
# @new_post.stub!(:meta_description)
|
104
|
+
# ::I18n.backend.store_translations :en,
|
105
|
+
# :formtastic => {
|
106
|
+
# :labels => {
|
107
|
+
# :meta_description => @localized_label_text
|
108
|
+
# }
|
109
|
+
# }
|
110
|
+
#
|
111
|
+
# concat(semantic_form_for(@new_post) do |builder|
|
112
|
+
# concat(builder.input(:meta_description))
|
113
|
+
# end)
|
114
|
+
# output_buffer.should have_tag('form li label', /Localized title/)
|
115
|
+
# end
|
116
|
+
# end
|
117
|
+
# end
|
118
|
+
# end
|
119
|
+
# end
|
120
|
+
#
|
121
|
+
# describe 'when localized label is NOT provided' do
|
122
|
+
# describe 'and object is not given' do
|
123
|
+
# it 'should default the humanized method name, passing it down to the label tag' do
|
124
|
+
# ::I18n.backend.store_translations :en, :formtastic => {}
|
125
|
+
# with_config :label_str_method, :humanize do
|
126
|
+
# concat(semantic_form_for(:project, :url => 'http://test.host') do |builder|
|
127
|
+
# concat(builder.input(:meta_description))
|
128
|
+
# end)
|
129
|
+
# output_buffer.should have_tag("form li label", /#{'meta_description'.humanize}/)
|
130
|
+
# end
|
131
|
+
# end
|
132
|
+
# end
|
133
|
+
#
|
134
|
+
# describe 'and object is given' do
|
135
|
+
# it 'should delegate the label logic to class human attribute name and pass it down to the label tag' do
|
136
|
+
# @new_post.stub!(:meta_description) # a two word method name
|
137
|
+
# @new_post.class.should_receive(:human_attribute_name).with('meta_description').and_return('meta_description'.humanize)
|
138
|
+
#
|
139
|
+
# concat(semantic_form_for(@new_post) do |builder|
|
140
|
+
# concat(builder.input(:meta_description))
|
141
|
+
# end)
|
142
|
+
# output_buffer.should have_tag("form li label", /#{'meta_description'.humanize}/)
|
143
|
+
# end
|
144
|
+
# end
|
145
|
+
#
|
146
|
+
# describe 'and object is given with label_str_method set to :capitalize' do
|
147
|
+
# it 'should capitalize method name, passing it down to the label tag' do
|
148
|
+
# with_config :label_str_method, :capitalize do
|
149
|
+
# @new_post.stub!(:meta_description)
|
150
|
+
#
|
151
|
+
# concat(semantic_form_for(@new_post) do |builder|
|
152
|
+
# concat(builder.input(:meta_description))
|
153
|
+
# end)
|
154
|
+
# output_buffer.should have_tag("form li label", /#{'meta_description'.capitalize}/)
|
155
|
+
# end
|
156
|
+
# end
|
157
|
+
# end
|
158
|
+
# end
|
159
|
+
#
|
160
|
+
# describe 'when localized label is provided' do
|
161
|
+
# before do
|
162
|
+
# @localized_label_text = 'Localized title'
|
163
|
+
# @default_localized_label_text = 'Default localized title'
|
164
|
+
# ::I18n.backend.store_translations :en,
|
165
|
+
# :formtastic => {
|
166
|
+
# :labels => {
|
167
|
+
# :title => @default_localized_label_text,
|
168
|
+
# :published => @default_localized_label_text,
|
169
|
+
# :post => {
|
170
|
+
# :title => @localized_label_text,
|
171
|
+
# :published => @default_localized_label_text
|
172
|
+
# }
|
173
|
+
# }
|
174
|
+
# }
|
175
|
+
# end
|
176
|
+
#
|
177
|
+
# it 'should render a label with localized label (I18n)' do
|
178
|
+
# with_config :i18n_lookups_by_default, false do
|
179
|
+
# concat(semantic_form_for(@new_post) do |builder|
|
180
|
+
# concat(builder.input(:title, :label => true))
|
181
|
+
# concat(builder.input(:published, :as => :boolean, :label => true))
|
182
|
+
# end)
|
183
|
+
# output_buffer.should have_tag('form li label', Regexp.new('^' + @localized_label_text))
|
184
|
+
# end
|
185
|
+
# end
|
186
|
+
#
|
187
|
+
# it 'should render a hint paragraph containing an optional localized label (I18n) if first is not set' do
|
188
|
+
# with_config :i18n_lookups_by_default, false do
|
189
|
+
# ::I18n.backend.store_translations :en,
|
190
|
+
# :formtastic => {
|
191
|
+
# :labels => {
|
192
|
+
# :post => {
|
193
|
+
# :title => nil,
|
194
|
+
# :published => nil
|
195
|
+
# }
|
196
|
+
# }
|
197
|
+
# }
|
198
|
+
# concat(semantic_form_for(@new_post) do |builder|
|
199
|
+
# concat(builder.input(:title, :label => true))
|
200
|
+
# concat(builder.input(:published, :as => :boolean, :label => true))
|
201
|
+
# end)
|
202
|
+
# output_buffer.should have_tag('form li label', Regexp.new('^' + @default_localized_label_text))
|
203
|
+
# end
|
204
|
+
# end
|
205
|
+
# end
|
206
|
+
# end
|
207
|
+
#
|
208
|
+
#end
|
209
|
+
#
|
210
|
+
describe ':wrapper_html option' do
|
211
|
+
|
212
|
+
describe 'when provided' do
|
213
|
+
it 'should be passed down to the li tag' do
|
214
|
+
concat(semantic_form_for(@new_post) do |builder|
|
215
|
+
concat(builder.action(:submit, :wrapper_html => {:id => :another_id}))
|
216
|
+
end)
|
217
|
+
output_buffer.should have_tag("form input#another_id")
|
218
|
+
end
|
219
|
+
|
220
|
+
it 'should append given classes to li default classes' do
|
221
|
+
concat(semantic_form_for(@new_post) do |builder|
|
222
|
+
concat(builder.action(:submit, :wrapper_html => {:class => :another_class}))
|
223
|
+
end)
|
224
|
+
output_buffer.should have_tag("form input.action")
|
225
|
+
output_buffer.should have_tag("form input.input_action")
|
226
|
+
output_buffer.should have_tag("form input.another_class")
|
227
|
+
end
|
228
|
+
|
229
|
+
it 'should allow classes to be an array' do
|
230
|
+
concat(semantic_form_for(@new_post) do |builder|
|
231
|
+
concat(builder.action(:submit, :wrapper_html => {:class => [ :my_class, :another_class ]}))
|
232
|
+
end)
|
233
|
+
output_buffer.should have_tag("form input.action")
|
234
|
+
output_buffer.should have_tag("form input.input_action")
|
235
|
+
output_buffer.should have_tag("form input.my_class")
|
236
|
+
output_buffer.should have_tag("form input.another_class")
|
237
|
+
end
|
238
|
+
end
|
239
|
+
|
240
|
+
describe 'when not provided' do
|
241
|
+
it 'should use default id and class' do
|
242
|
+
concat(semantic_form_for(@new_post) do |builder|
|
243
|
+
concat(builder.action(:submit))
|
244
|
+
end)
|
245
|
+
output_buffer.should have_tag("form input#post_submit_action")
|
246
|
+
output_buffer.should have_tag("form input.action")
|
247
|
+
output_buffer.should have_tag("form input.input_action")
|
248
|
+
end
|
249
|
+
end
|
250
|
+
|
251
|
+
end
|
252
|
+
|
253
|
+
end
|
254
|
+
|
255
|
+
describe 'instantiating an action class' do
|
256
|
+
|
257
|
+
context 'when a class does not exist' do
|
258
|
+
it "should raise an error" do
|
259
|
+
lambda {
|
260
|
+
concat(semantic_form_for(@new_post) do |builder|
|
261
|
+
builder.action(:submit, :as => :non_existant)
|
262
|
+
end)
|
263
|
+
}.should raise_error(Formtastic::UnknownActionError)
|
264
|
+
end
|
265
|
+
end
|
266
|
+
|
267
|
+
context 'when a customized top-level class does not exist' do
|
268
|
+
|
269
|
+
it 'should instantiate the Formtastic action' do
|
270
|
+
action = mock('action', :to_html => 'some HTML')
|
271
|
+
Formtastic::Actions::ButtonAction.should_receive(:new).and_return(action)
|
272
|
+
concat(semantic_form_for(@new_post) do |builder|
|
273
|
+
builder.action(:commit, :as => :button)
|
274
|
+
end)
|
275
|
+
end
|
276
|
+
|
277
|
+
end
|
278
|
+
|
279
|
+
describe 'when a top-level (custom) action class exists' do
|
280
|
+
it "should instantiate the top-level action instead of the Formtastic one" do
|
281
|
+
class ::ButtonAction < Formtastic::Actions::ButtonAction
|
282
|
+
end
|
283
|
+
|
284
|
+
action = mock('action', :to_html => 'some HTML')
|
285
|
+
Formtastic::Actions::ButtonAction.should_not_receive(:new).and_return(action)
|
286
|
+
::ButtonAction.should_receive(:new).and_return(action)
|
287
|
+
|
288
|
+
concat(semantic_form_for(@new_post) do |builder|
|
289
|
+
builder.action(:commit, :as => :button)
|
290
|
+
end)
|
291
|
+
end
|
292
|
+
end
|
293
|
+
|
294
|
+
describe 'when instantiated multiple times with the same action type' do
|
295
|
+
|
296
|
+
it "should be cached (not calling the internal methods)" do
|
297
|
+
# TODO this is really tied to the underlying implementation
|
298
|
+
concat(semantic_form_for(@new_post) do |builder|
|
299
|
+
builder.should_receive(:custom_action_class_name).with(:button).once.and_return(::Formtastic::Actions::ButtonAction)
|
300
|
+
builder.action(:submit, :as => :button)
|
301
|
+
builder.action(:submit, :as => :button)
|
302
|
+
end)
|
303
|
+
end
|
304
|
+
|
305
|
+
end
|
306
|
+
|
307
|
+
describe 'support for :as on each action' do
|
308
|
+
|
309
|
+
it "should raise an error when the action does not support the :as" do
|
310
|
+
lambda {
|
311
|
+
concat(semantic_form_for(@new_post) do |builder|
|
312
|
+
concat(builder.action(:submit, :as => :link))
|
313
|
+
end)
|
314
|
+
}.should raise_error(Formtastic::UnsupportedMethodForAction)
|
315
|
+
|
316
|
+
lambda {
|
317
|
+
concat(semantic_form_for(@new_post) do |builder|
|
318
|
+
concat(builder.action(:cancel, :as => :input))
|
319
|
+
end)
|
320
|
+
}.should raise_error(Formtastic::UnsupportedMethodForAction)
|
321
|
+
|
322
|
+
lambda {
|
323
|
+
concat(semantic_form_for(@new_post) do |builder|
|
324
|
+
concat(builder.action(:cancel, :as => :button))
|
325
|
+
end)
|
326
|
+
}.should raise_error(Formtastic::UnsupportedMethodForAction)
|
327
|
+
end
|
328
|
+
|
329
|
+
it "should not raise an error when the action does not support the :as" do
|
330
|
+
lambda {
|
331
|
+
concat(semantic_form_for(@new_post) do |builder|
|
332
|
+
concat(builder.action(:cancel, :as => :link))
|
333
|
+
end)
|
334
|
+
}.should_not raise_error(Formtastic::UnsupportedMethodForAction)
|
335
|
+
|
336
|
+
lambda {
|
337
|
+
concat(semantic_form_for(@new_post) do |builder|
|
338
|
+
concat(builder.action(:submit, :as => :input))
|
339
|
+
end)
|
340
|
+
}.should_not raise_error(Formtastic::UnsupportedMethodForAction)
|
341
|
+
|
342
|
+
lambda {
|
343
|
+
concat(semantic_form_for(@new_post) do |builder|
|
344
|
+
concat(builder.action(:submit, :as => :button))
|
345
|
+
end)
|
346
|
+
}.should_not raise_error(Formtastic::UnsupportedMethodForAction)
|
347
|
+
|
348
|
+
lambda {
|
349
|
+
concat(semantic_form_for(@new_post) do |builder|
|
350
|
+
concat(builder.action(:reset, :as => :input))
|
351
|
+
end)
|
352
|
+
}.should_not raise_error(Formtastic::UnsupportedMethodForAction)
|
353
|
+
|
354
|
+
lambda {
|
355
|
+
concat(semantic_form_for(@new_post) do |builder|
|
356
|
+
concat(builder.action(:reset, :as => :button))
|
357
|
+
end)
|
358
|
+
}.should_not raise_error(Formtastic::UnsupportedMethodForAction)
|
359
|
+
end
|
360
|
+
|
361
|
+
end
|
362
|
+
|
363
|
+
end
|
364
|
+
|
365
|
+
end
|