speedo-formstrap 1.2.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.
Files changed (89) hide show
  1. data/.document +5 -0
  2. data/.rspec +1 -0
  3. data/Gemfile +13 -0
  4. data/Gemfile.lock +117 -0
  5. data/LICENSE.txt +20 -0
  6. data/README.md +192 -0
  7. data/Rakefile +49 -0
  8. data/VERSION +1 -0
  9. data/formtastic-bootstrap.gemspec +56 -0
  10. data/lib/action_view/helpers/text_field_date_helper.rb +166 -0
  11. data/lib/formtastic-bootstrap.rb +7 -0
  12. data/lib/formtastic-bootstrap/actions.rb +4 -0
  13. data/lib/formtastic-bootstrap/actions/base.rb +18 -0
  14. data/lib/formtastic-bootstrap/actions/button_action.rb +7 -0
  15. data/lib/formtastic-bootstrap/actions/input_action.rb +7 -0
  16. data/lib/formtastic-bootstrap/actions/link_action.rb +7 -0
  17. data/lib/formtastic-bootstrap/engine.rb +4 -0
  18. data/lib/formtastic-bootstrap/form_builder.rb +40 -0
  19. data/lib/formtastic-bootstrap/helpers.rb +21 -0
  20. data/lib/formtastic-bootstrap/helpers/action_helper.rb +12 -0
  21. data/lib/formtastic-bootstrap/helpers/actions_helper.rb +23 -0
  22. data/lib/formtastic-bootstrap/helpers/buttons_helper.rb +56 -0
  23. data/lib/formtastic-bootstrap/helpers/fieldset_wrapper.rb +42 -0
  24. data/lib/formtastic-bootstrap/helpers/input_helper.rb +12 -0
  25. data/lib/formtastic-bootstrap/helpers/inputs_helper.rb +36 -0
  26. data/lib/formtastic-bootstrap/inputs.rb +29 -0
  27. data/lib/formtastic-bootstrap/inputs/base.rb +23 -0
  28. data/lib/formtastic-bootstrap/inputs/base/choices.rb +38 -0
  29. data/lib/formtastic-bootstrap/inputs/base/errors.rb +48 -0
  30. data/lib/formtastic-bootstrap/inputs/base/hints.rb +27 -0
  31. data/lib/formtastic-bootstrap/inputs/base/html.rb +21 -0
  32. data/lib/formtastic-bootstrap/inputs/base/labelling.rb +28 -0
  33. data/lib/formtastic-bootstrap/inputs/base/numeric.rb +18 -0
  34. data/lib/formtastic-bootstrap/inputs/base/stringish.rb +18 -0
  35. data/lib/formtastic-bootstrap/inputs/base/timeish.rb +28 -0
  36. data/lib/formtastic-bootstrap/inputs/base/wrapping.rb +74 -0
  37. data/lib/formtastic-bootstrap/inputs/boolean_input.rb +29 -0
  38. data/lib/formtastic-bootstrap/inputs/check_boxes_input.rb +36 -0
  39. data/lib/formtastic-bootstrap/inputs/date_input.rb +16 -0
  40. data/lib/formtastic-bootstrap/inputs/datetime_input.rb +19 -0
  41. data/lib/formtastic-bootstrap/inputs/email_input.rb +15 -0
  42. data/lib/formtastic-bootstrap/inputs/file_input.rb +14 -0
  43. data/lib/formtastic-bootstrap/inputs/hidden_input.rb +14 -0
  44. data/lib/formtastic-bootstrap/inputs/number_input.rb +15 -0
  45. data/lib/formtastic-bootstrap/inputs/password_input.rb +15 -0
  46. data/lib/formtastic-bootstrap/inputs/phone_input.rb +15 -0
  47. data/lib/formtastic-bootstrap/inputs/radio_input.rb +33 -0
  48. data/lib/formtastic-bootstrap/inputs/range_input.rb +15 -0
  49. data/lib/formtastic-bootstrap/inputs/search_input.rb +15 -0
  50. data/lib/formtastic-bootstrap/inputs/select_input.rb +14 -0
  51. data/lib/formtastic-bootstrap/inputs/string_input.rb +15 -0
  52. data/lib/formtastic-bootstrap/inputs/text_input.rb +14 -0
  53. data/lib/formtastic-bootstrap/inputs/time_input.rb +16 -0
  54. data/lib/formtastic-bootstrap/inputs/time_zone_input.rb +14 -0
  55. data/lib/formtastic-bootstrap/inputs/url_input.rb +14 -0
  56. data/spec/actions/button_action_spec.rb +68 -0
  57. data/spec/actions/generic_action_spec.rb +486 -0
  58. data/spec/actions/input_action_spec.rb +64 -0
  59. data/spec/actions/link_action_spec.rb +93 -0
  60. data/spec/builder/semantic_fields_for_spec.rb +130 -0
  61. data/spec/helpers/action_helper_spec.rb +365 -0
  62. data/spec/helpers/actions_helper_spec.rb +143 -0
  63. data/spec/helpers/buttons_helper_spec.rb +159 -0
  64. data/spec/helpers/input_helper_spec.rb +956 -0
  65. data/spec/helpers/inputs_helper_spec.rb +591 -0
  66. data/spec/inputs/boolean_input_spec.rb +221 -0
  67. data/spec/inputs/check_boxes_input_spec.rb +467 -0
  68. data/spec/inputs/date_input_spec.rb +213 -0
  69. data/spec/inputs/datetime_input_spec.rb +101 -0
  70. data/spec/inputs/email_input_spec.rb +87 -0
  71. data/spec/inputs/file_input_spec.rb +91 -0
  72. data/spec/inputs/hidden_input_spec.rb +150 -0
  73. data/spec/inputs/number_input_spec.rb +817 -0
  74. data/spec/inputs/password_input_spec.rb +101 -0
  75. data/spec/inputs/phone_input_spec.rb +87 -0
  76. data/spec/inputs/radio_input_spec.rb +268 -0
  77. data/spec/inputs/range_input_spec.rb +507 -0
  78. data/spec/inputs/search_input_spec.rb +86 -0
  79. data/spec/inputs/select_input_spec.rb +613 -0
  80. data/spec/inputs/string_input_spec.rb +227 -0
  81. data/spec/inputs/text_input_spec.rb +190 -0
  82. data/spec/inputs/time_input_spec.rb +206 -0
  83. data/spec/inputs/time_zone_input_spec.rb +120 -0
  84. data/spec/inputs/url_input_spec.rb +87 -0
  85. data/spec/spec_helper.rb +24 -0
  86. data/spec/support/custom_macros.rb +575 -0
  87. data/spec/support/depracation.rb +6 -0
  88. data/spec/support/formtastic_spec_helper.rb +398 -0
  89. metadata +216 -0
@@ -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
@@ -0,0 +1,130 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'FormtasticBootstrap::FormBuilder#fields_for' do
4
+
5
+ include FormtasticSpecHelper
6
+
7
+ before do
8
+ @output_buffer = ''
9
+ mock_everything
10
+ @new_post.stub!(:author).and_return(::Author.new)
11
+
12
+ Formtastic::Helpers::FormHelper.builder = FormtasticBootstrap::FormBuilder
13
+ end
14
+
15
+ context 'outside a form_for block' do
16
+ it 'yields an instance of FormHelper.builder' do
17
+ semantic_fields_for(@new_post) do |nested_builder|
18
+ nested_builder.class.should == Formtastic::Helpers::FormHelper.builder
19
+ end
20
+ semantic_fields_for(@new_post.author) do |nested_builder|
21
+ nested_builder.class.should == Formtastic::Helpers::FormHelper.builder
22
+ end
23
+ semantic_fields_for(:author, @new_post.author) do |nested_builder|
24
+ nested_builder.class.should == Formtastic::Helpers::FormHelper.builder
25
+ end
26
+ semantic_fields_for(:author, @hash_backed_author) do |nested_builder|
27
+ nested_builder.class.should == Formtastic::Helpers::FormHelper.builder
28
+ end
29
+ end
30
+
31
+ it 'should respond to input' do
32
+ semantic_fields_for(@new_post) do |nested_builder|
33
+ nested_builder.respond_to?(:input).should be_true
34
+ end
35
+ semantic_fields_for(@new_post.author) do |nested_builder|
36
+ nested_builder.respond_to?(:input).should be_true
37
+ end
38
+ semantic_fields_for(:author, @new_post.author) do |nested_builder|
39
+ nested_builder.respond_to?(:input).should be_true
40
+ end
41
+ semantic_fields_for(:author, @hash_backed_author) do |nested_builder|
42
+ nested_builder.respond_to?(:input).should be_true
43
+ end
44
+ end
45
+ end
46
+
47
+ context 'within a form_for block' do
48
+ it 'yields an instance of FormHelper.builder' do
49
+ semantic_form_for(@new_post) do |builder|
50
+ builder.semantic_fields_for(:author) do |nested_builder|
51
+ nested_builder.class.should == Formtastic::Helpers::FormHelper.builder
52
+ end
53
+ end
54
+ end
55
+
56
+ it 'yields an instance of FormHelper.builder with hash-like model' do
57
+ semantic_form_for(:user) do |builder|
58
+ builder.semantic_fields_for(:author, @hash_backed_author) do |nested_builder|
59
+ nested_builder.class.should == Formtastic::Helpers::FormHelper.builder
60
+ end
61
+ end
62
+ end
63
+
64
+ it 'nests the object name' do
65
+ semantic_form_for(@new_post) do |builder|
66
+ builder.semantic_fields_for(@bob) do |nested_builder|
67
+ nested_builder.object_name.should == 'post[author]'
68
+ end
69
+ end
70
+ end
71
+
72
+ it 'supports passing collection as second parameter' do
73
+ semantic_form_for(@new_post) do |builder|
74
+ builder.semantic_fields_for(:author, [@fred,@bob]) do |nested_builder|
75
+ nested_builder.object_name.should =~ /post\[author_attributes\]\[\d+\]/
76
+ end
77
+ end
78
+ end
79
+
80
+ it 'should sanitize html id for li tag' do
81
+ @bob.stub!(:column_for_attribute).and_return(mock('column', :type => :string, :limit => 255))
82
+ concat(semantic_form_for(@new_post) do |builder|
83
+ concat(builder.semantic_fields_for(@bob, :index => 1) do |nested_builder|
84
+ concat(nested_builder.inputs(:login))
85
+ end)
86
+ end)
87
+ output_buffer.should have_tag('form fieldset.inputs #post_author_1_login_input')
88
+ # Not valid selector, so using good ol' regex
89
+ output_buffer.should_not =~ /id="post\[author\]_1_login_input"/
90
+ # <=> output_buffer.should_not have_tag('form fieldset.inputs #post[author]_1_login_input')
91
+ end
92
+
93
+ it 'should use namespace provided in nested fields' do
94
+ @bob.stub!(:column_for_attribute).and_return(mock('column', :type => :string, :limit => 255))
95
+ concat(semantic_form_for(@new_post, :namespace => 'context2') do |builder|
96
+ concat(builder.semantic_fields_for(@bob, :index => 1) do |nested_builder|
97
+ concat(nested_builder.inputs(:login))
98
+ end)
99
+ end)
100
+ output_buffer.should have_tag('form fieldset.inputs #context2_post_author_1_login_input')
101
+ end
102
+ end
103
+
104
+ context "when I rendered my own hidden id input" do
105
+
106
+ before do
107
+ output_buffer.replace ''
108
+
109
+ @fred.posts.size.should == 1
110
+ @fred.posts.first.stub!(:persisted?).and_return(true)
111
+ @fred.stub!(:posts_attributes=)
112
+
113
+ concat(semantic_form_for(@fred) do |builder|
114
+ concat(builder.semantic_fields_for(:posts) do |nested_builder|
115
+ concat(nested_builder.input(:id, :as => :hidden))
116
+ concat(nested_builder.input(:title))
117
+ end)
118
+ end)
119
+ end
120
+
121
+ it "should only render one hidden input (my one)" do
122
+ output_buffer.should have_tag 'input#author_posts_attributes_0_id', :count => 1
123
+ end
124
+
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
+ end
128
+ end
129
+
130
+ end
@@ -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