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,16 @@
1
+ module FormtasticBootstrap
2
+ module Inputs
3
+ class DateInput < Formtastic::Inputs::DateInput
4
+ include Base
5
+ include Base::Stringish
6
+ include Base::Timeish
7
+
8
+ def to_html
9
+ generic_input_wrapping do
10
+ date_input_html
11
+ end
12
+ end
13
+
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,19 @@
1
+ module FormtasticBootstrap
2
+ module Inputs
3
+ class DatetimeInput < Formtastic::Inputs::DatetimeInput
4
+ include Base
5
+ include Base::Stringish
6
+ include Base::Timeish
7
+
8
+ def to_html
9
+ generic_input_wrapping do
10
+ inline_inputs_div_wrapping do
11
+ # This newline matters.
12
+ date_input_html << "\n".html_safe << time_input_html
13
+ end
14
+ end
15
+ end
16
+
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,15 @@
1
+ module FormtasticBootstrap
2
+ module Inputs
3
+ class EmailInput < Formtastic::Inputs::EmailInput
4
+ include Base
5
+ include Base::Stringish
6
+
7
+ def to_html
8
+ generic_input_wrapping do
9
+ builder.email_field(method, input_html_options)
10
+ end
11
+ end
12
+
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,14 @@
1
+ module FormtasticBootstrap
2
+ module Inputs
3
+ class FileInput < Formtastic::Inputs::FileInput
4
+ include Base
5
+
6
+ def to_html
7
+ generic_input_wrapping do
8
+ builder.file_field(method, input_html_options)
9
+ end
10
+ end
11
+
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,14 @@
1
+ module FormtasticBootstrap
2
+ module Inputs
3
+ class HiddenInput < Formtastic::Inputs::HiddenInput
4
+ include Base
5
+ def to_html
6
+ control_group_div_wrapping do
7
+ input_div_wrapping do
8
+ builder.hidden_field(method, input_html_options)
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,15 @@
1
+ module FormtasticBootstrap
2
+ module Inputs
3
+ class NumberInput < Formtastic::Inputs::NumberInput
4
+ include Base
5
+ include Base::Numeric
6
+
7
+ def to_html
8
+ generic_input_wrapping do
9
+ builder.number_field(method, input_html_options)
10
+ end
11
+ end
12
+
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ module FormtasticBootstrap
2
+ module Inputs
3
+ class PasswordInput < Formtastic::Inputs::PasswordInput
4
+ include Base
5
+ include Base::Stringish
6
+
7
+ def to_html
8
+ generic_input_wrapping do
9
+ builder.password_field(method, input_html_options)
10
+ end
11
+ end
12
+
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ module FormtasticBootstrap
2
+ module Inputs
3
+ class PhoneInput < Formtastic::Inputs::PhoneInput
4
+ include Base
5
+ include Base::Stringish
6
+
7
+ def to_html
8
+ generic_input_wrapping do
9
+ builder.phone_field(method, input_html_options)
10
+ end
11
+ end
12
+
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,33 @@
1
+ module FormtasticBootstrap
2
+ module Inputs
3
+ class RadioInput < Formtastic::Inputs::RadioInput
4
+ include Base
5
+ include Base::Choices
6
+
7
+ def to_html
8
+ control_group_div_wrapping do
9
+ legend_html <<
10
+ input_div_wrapping do
11
+ collection.map { |choice|
12
+ choice_html(choice)
13
+ }.join("\n").html_safe
14
+ end
15
+ end
16
+ end
17
+
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)) <<
21
+
22
+ choice_label(choice)
23
+ end
24
+ end
25
+
26
+ def choice_wrapping_html_options(choice)
27
+ new_class = [super[:class], 'radio'].join(' ')
28
+ super.merge(:class => new_class)
29
+ end
30
+
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,15 @@
1
+ module FormtasticBootstrap
2
+ module Inputs
3
+ class RangeInput < Formtastic::Inputs::RangeInput
4
+ include Base
5
+ include Base::Numeric
6
+
7
+ def to_html
8
+ generic_input_wrapping do
9
+ builder.range_field(method, input_html_options)
10
+ end
11
+ end
12
+
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ module FormtasticBootstrap
2
+ module Inputs
3
+ class SearchInput < Formtastic::Inputs::SearchInput
4
+ include Base
5
+ include Base::Stringish
6
+
7
+ def to_html
8
+ generic_input_wrapping do
9
+ builder.search_field(method, input_html_options)
10
+ end
11
+ end
12
+
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,14 @@
1
+ module FormtasticBootstrap
2
+ module Inputs
3
+ class SelectInput < Formtastic::Inputs::SelectInput
4
+ include Base
5
+
6
+ def to_html
7
+ generic_input_wrapping do
8
+ options[:group_by] ? grouped_select_html : select_html
9
+ end
10
+ end
11
+
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,15 @@
1
+ module FormtasticBootstrap
2
+ module Inputs
3
+ class StringInput < Formtastic::Inputs::StringInput
4
+ include Base
5
+ include Base::Stringish
6
+
7
+ def to_html
8
+ generic_input_wrapping do
9
+ builder.text_field(method, input_html_options)
10
+ end
11
+ end
12
+
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,14 @@
1
+ module FormtasticBootstrap
2
+ module Inputs
3
+ class TextInput < Formtastic::Inputs::TextInput
4
+ include Base
5
+
6
+ def to_html
7
+ generic_input_wrapping do
8
+ builder.text_area(method, input_html_options)
9
+ end
10
+ end
11
+
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,16 @@
1
+ module FormtasticBootstrap
2
+ module Inputs
3
+ class TimeInput < Formtastic::Inputs::TimeInput
4
+ include Base
5
+ include Base::Stringish
6
+ include Base::Timeish
7
+
8
+ def to_html
9
+ generic_input_wrapping do
10
+ time_input_html
11
+ end
12
+ end
13
+
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,14 @@
1
+ module FormtasticBootstrap
2
+ module Inputs
3
+ class TimeZoneInput < Formtastic::Inputs::TimeZoneInput
4
+ include Base
5
+
6
+ def to_html
7
+ generic_input_wrapping do
8
+ builder.time_zone_select(method, priority_zones, input_options, input_html_options)
9
+ end
10
+ end
11
+
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,14 @@
1
+ module FormtasticBootstrap
2
+ module Inputs
3
+ class UrlInput < Formtastic::Inputs::UrlInput
4
+ include Base
5
+ include Base::Stringish
6
+
7
+ def to_html
8
+ generic_input_wrapping do
9
+ builder.url_field(method, input_html_options)
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,68 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+ describe 'ButtonAction', '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 => :button))
15
+ end)
16
+ end
17
+
18
+ it 'should render a submit type of button' do
19
+ output_buffer.should have_tag('button[@type="submit"].action.button_action.btn.btn-primary')
20
+ end
21
+
22
+ end
23
+
24
+ describe 'ButtonAction', '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 => :button))
34
+ end)
35
+ end
36
+
37
+ it 'should render a reset type of button' do
38
+ output_buffer.should have_tag('button[@type="reset"].action.button_action.btn', :text => "Reset Post")
39
+ end
40
+
41
+ it 'should not be primary' do
42
+ output_buffer.should_not have_tag('button[@type="reset"].action.button_action.btn.btn-primary', :text => "Reset Post")
43
+ end
44
+
45
+ it 'should not render a value attribute' do
46
+ output_buffer.should_not have_tag('button[@value].action.button_action')
47
+ end
48
+
49
+ end
50
+
51
+ describe 'InputAction', 'when cancelling' do
52
+
53
+ include FormtasticSpecHelper
54
+
55
+ before do
56
+ @output_buffer = ''
57
+ mock_everything
58
+ end
59
+
60
+ it 'should raise an error' do
61
+ lambda {
62
+ concat(semantic_form_for(@new_post) do |builder|
63
+ concat(builder.action(:cancel, :as => :button))
64
+ end)
65
+ }.should raise_error(Formtastic::UnsupportedMethodForAction)
66
+ end
67
+
68
+ end
@@ -0,0 +1,486 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+ describe 'InputAction::Base' do
5
+
6
+ # Most basic Action class to test Base
7
+ class ::GenericAction
8
+ include ::Formtastic::Actions::Base
9
+
10
+ def supported_methods
11
+ [:submit, :reset, :cancel]
12
+ end
13
+
14
+ def to_html
15
+ wrapper do
16
+ builder.submit(text, button_html)
17
+ end
18
+ end
19
+ end
20
+
21
+ include FormtasticSpecHelper
22
+
23
+ before do
24
+ @output_buffer = ''
25
+ mock_everything
26
+ Formtastic::Helpers::FormHelper.builder = FormtasticBootstrap::FormBuilder
27
+ end
28
+
29
+ describe 'wrapping HTML' do
30
+
31
+ before do
32
+ concat(semantic_form_for(@new_post) do |builder|
33
+ concat(builder.action(:submit, :as => :generic,
34
+ :wrapper_html => { :foo => 'bah' }
35
+ ))
36
+ end)
37
+ end
38
+
39
+ it 'should add the #foo id to the li' do
40
+ output_buffer.should have_tag('li#post_submit_action')
41
+ end
42
+
43
+ it 'should add the .action and .generic_action classes to the li' do
44
+ output_buffer.should have_tag('li.action.generic_action')
45
+ end
46
+
47
+ it 'should pass :wrapper_html HTML attributes to the wrapper' do
48
+ output_buffer.should have_tag('li.action.generic_action[@foo="bah"]')
49
+ end
50
+
51
+ context "when a custom :id is provided" do
52
+
53
+ before do
54
+ concat(semantic_form_for(@new_post) do |builder|
55
+ concat(builder.action(:submit, :as => :generic,
56
+ :wrapper_html => { :id => 'foo_bah_bing' }
57
+ ))
58
+ end)
59
+ end
60
+
61
+ it "should use the custom id" do
62
+ output_buffer.should have_tag('li#foo_bah_bing')
63
+ end
64
+
65
+ end
66
+
67
+ context "when a custom class is provided as a string" do
68
+
69
+ before do
70
+ concat(semantic_form_for(@new_post) do |builder|
71
+ concat(builder.action(:submit, :as => :generic,
72
+ :wrapper_html => { :class => 'foo_bah_bing' }
73
+ ))
74
+ end)
75
+ end
76
+
77
+ it "should add the custom class strng to the existing classes" do
78
+ output_buffer.should have_tag('li.action.generic_action.foo_bah_bing')
79
+ end
80
+
81
+ end
82
+
83
+ context "when a custom class is provided as an array" do
84
+
85
+ before do
86
+ concat(semantic_form_for(@new_post) do |builder|
87
+ concat(builder.action(:submit, :as => :generic,
88
+ :wrapper_html => { :class => ['foo_bah_bing', 'zing_boo'] }
89
+ ))
90
+ end)
91
+ end
92
+
93
+ it "should add the custom class strng to the existing classes" do
94
+ output_buffer.should have_tag('li.action.generic_action.foo_bah_bing.zing_boo')
95
+ end
96
+
97
+ end
98
+
99
+ end
100
+
101
+ describe 'button HTML' do
102
+
103
+ before do
104
+ concat(semantic_form_for(@new_post) do |builder|
105
+ concat(builder.action(:submit, :as => :generic,
106
+ :button_html => { :foo => 'bah' }
107
+ ))
108
+ end)
109
+ end
110
+
111
+ it 'should pass :button_html HTML attributes to the button' do
112
+ output_buffer.should have_tag('li.action.generic_action input[@foo="bah"]')
113
+ end
114
+
115
+ it 'should respect a default_commit_button_accesskey configuration with nil' do
116
+ with_config :default_commit_button_accesskey, nil do
117
+ concat(semantic_form_for(@new_post) do |builder|
118
+ concat(builder.action(:submit, :as => :generic))
119
+ end)
120
+ output_buffer.should_not have_tag('li.action input[@accesskey]')
121
+ end
122
+ end
123
+
124
+ it 'should respect a default_commit_button_accesskey configuration with a String' do
125
+ with_config :default_commit_button_accesskey, 's' do
126
+ concat(semantic_form_for(@new_post) do |builder|
127
+ concat(builder.action(:submit, :as => :generic))
128
+ end)
129
+ output_buffer.should have_tag('li.action input[@accesskey="s"]')
130
+ end
131
+ end
132
+
133
+ it 'should respect an accesskey through options over configration' do
134
+ with_config :default_commit_button_accesskey, 's' do
135
+ concat(semantic_form_for(@new_post) do |builder|
136
+ concat(builder.action(:submit, :as => :generic, :accesskey => 'o'))
137
+ end)
138
+ output_buffer.should_not have_tag('li.action input[@accesskey="s"]')
139
+ output_buffer.should have_tag('li.action input[@accesskey="o"]')
140
+ end
141
+ end
142
+
143
+ end
144
+
145
+ describe 'labelling' do
146
+
147
+ describe 'when used without object' do
148
+
149
+ describe 'when explicit label is provided' do
150
+ it 'should render an input with the explicitly specified label' do
151
+ concat(semantic_form_for(:post, :url => 'http://example.com') do |builder|
152
+ concat(builder.action(:submit, :as => :generic, :label => "Click!"))
153
+ concat(builder.action(:reset, :as => :generic, :label => "Reset!"))
154
+ concat(builder.action(:cancel, :as => :generic, :label => "Cancel!"))
155
+ end)
156
+ output_buffer.should have_tag('li.generic_action input[@value="Click!"]')
157
+ output_buffer.should have_tag('li.generic_action input[@value="Reset!"]')
158
+ output_buffer.should have_tag('li.generic_action input[@value="Cancel!"]')
159
+ end
160
+ end
161
+
162
+ describe 'when no explicit label is provided' do
163
+ describe 'when no I18n-localized label is provided' do
164
+ before do
165
+ ::I18n.backend.store_translations :en, :formtastic => {
166
+ :submit => 'Submit %{model}',
167
+ :reset => 'Reset %{model}',
168
+ :cancel => 'Cancel %{model}'
169
+ }
170
+ end
171
+
172
+ after do
173
+ ::I18n.backend.reload!
174
+ end
175
+
176
+ it 'should render an input with default I18n-localized label (fallback)' do
177
+ concat(semantic_form_for(:post, :url => 'http://example.com') do |builder|
178
+ concat(builder.action(:submit, :as => :generic))
179
+ concat(builder.action(:reset, :as => :generic))
180
+ concat(builder.action(:cancel, :as => :generic))
181
+ end)
182
+ output_buffer.should have_tag('li.generic_action input[@value="Submit Post"]')
183
+ output_buffer.should have_tag('li.generic_action input[@value="Cancel Post"]')
184
+ output_buffer.should have_tag('li.generic_action input[@value="Reset Post"]')
185
+ end
186
+ end
187
+
188
+ describe 'when I18n-localized label is provided' do
189
+
190
+ before do
191
+ ::I18n.backend.store_translations :en,
192
+ :formtastic => {
193
+ :actions => {
194
+ :submit => 'Custom Submit',
195
+ :reset => 'Custom Reset',
196
+ :cancel => 'Custom Cancel'
197
+ }
198
+ }
199
+ end
200
+
201
+ after do
202
+ ::I18n.backend.reload!
203
+ end
204
+
205
+ it 'should render an input with localized label (I18n)' do
206
+ with_config :i18n_lookups_by_default, true do
207
+ ::I18n.backend.store_translations :en,
208
+ :formtastic => {
209
+ :actions => {
210
+ :post => {
211
+ :submit => 'Custom Submit %{model}',
212
+ :reset => 'Custom Reset %{model}',
213
+ :cancel => 'Custom Cancel %{model}'
214
+ }
215
+ }
216
+ }
217
+
218
+ concat(semantic_form_for(:post, :url => 'http://example.com') do |builder|
219
+ concat(builder.action(:submit, :as => :generic))
220
+ concat(builder.action(:reset, :as => :generic))
221
+ concat(builder.action(:cancel, :as => :generic))
222
+ end)
223
+ output_buffer.should have_tag(%Q{li.generic_action input[@value="Custom Submit Post"]})
224
+ output_buffer.should have_tag(%Q{li.generic_action input[@value="Custom Reset Post"]})
225
+ output_buffer.should have_tag(%Q{li.generic_action input[@value="Custom Cancel Post"]})
226
+ end
227
+ end
228
+
229
+ it 'should render an input with anoptional localized label (I18n) - if first is not set' do
230
+ with_config :i18n_lookups_by_default, true do
231
+ concat(semantic_form_for(:post, :url => 'http://example.com') do |builder|
232
+ concat(builder.action(:submit, :as => :generic))
233
+ concat(builder.action(:reset, :as => :generic))
234
+ concat(builder.action(:cancel, :as => :generic))
235
+ end)
236
+ output_buffer.should have_tag(%Q{li.generic_action input[@value="Custom Submit"]})
237
+ output_buffer.should have_tag(%Q{li.generic_action input[@value="Custom Reset"]})
238
+ output_buffer.should have_tag(%Q{li.generic_action input[@value="Custom Cancel"]})
239
+ end
240
+ end
241
+
242
+ end
243
+ end
244
+ end
245
+
246
+ describe 'when used on a new record' do
247
+ before do
248
+ @new_post.stub!(:new_record?).and_return(true)
249
+ end
250
+
251
+ describe 'when explicit label is provided' do
252
+ it 'should render an input with the explicitly specified label' do
253
+ concat(semantic_form_for(@new_post) do |builder|
254
+ concat(builder.action(:submit, :as => :generic, :label => "Click!"))
255
+ concat(builder.action(:reset, :as => :generic, :label => "Reset!"))
256
+ concat(builder.action(:cancel, :as => :generic, :label => "Cancel!"))
257
+ end)
258
+ output_buffer.should have_tag('li.generic_action input[@value="Click!"]')
259
+ output_buffer.should have_tag('li.generic_action input[@value="Reset!"]')
260
+ output_buffer.should have_tag('li.generic_action input[@value="Cancel!"]')
261
+ end
262
+ end
263
+
264
+ describe 'when no explicit label is provided' do
265
+ describe 'when no I18n-localized label is provided' do
266
+ before do
267
+ ::I18n.backend.store_translations :en, :formtastic => {
268
+ :create => 'Create %{model}',
269
+ :reset => 'Reset %{model}',
270
+ :cancel => 'Cancel %{model}'
271
+ }
272
+ end
273
+
274
+ after do
275
+ ::I18n.backend.reload!
276
+ end
277
+
278
+ it 'should render an input with default I18n-localized label (fallback)' do
279
+ concat(semantic_form_for(@new_post) do |builder|
280
+ concat(builder.action(:submit, :as => :generic))
281
+ concat(builder.action(:reset, :as => :generic))
282
+ concat(builder.action(:cancel, :as => :generic))
283
+ end)
284
+ output_buffer.should have_tag('li.generic_action input[@value="Create Post"]')
285
+ output_buffer.should have_tag('li.generic_action input[@value="Reset Post"]')
286
+ output_buffer.should have_tag('li.generic_action input[@value="Cancel Post"]')
287
+ end
288
+ end
289
+
290
+ describe 'when I18n-localized label is provided' do
291
+ before do
292
+ ::I18n.backend.store_translations :en,
293
+ :formtastic => {
294
+ :actions => {
295
+ :create => 'Custom Create',
296
+ :reset => 'Custom Reset',
297
+ :cancel => 'Custom Cancel'
298
+ }
299
+ }
300
+ end
301
+
302
+ after do
303
+ ::I18n.backend.reload!
304
+ end
305
+
306
+ it 'should render an input with localized label (I18n)' do
307
+ with_config :i18n_lookups_by_default, true do
308
+ ::I18n.backend.store_translations :en,
309
+ :formtastic => {
310
+ :actions => {
311
+ :post => {
312
+ :create => 'Custom Create %{model}',
313
+ :reset => 'Custom Reset %{model}',
314
+ :cancel => 'Custom Cancel %{model}'
315
+ }
316
+ }
317
+ }
318
+ concat(semantic_form_for(@new_post) do |builder|
319
+ concat(builder.action(:submit, :as => :generic))
320
+ concat(builder.action(:reset, :as => :generic))
321
+ concat(builder.action(:cancel, :as => :generic))
322
+ end)
323
+ output_buffer.should have_tag(%Q{li.generic_action input[@value="Custom Create Post"]})
324
+ output_buffer.should have_tag(%Q{li.generic_action input[@value="Custom Reset Post"]})
325
+ output_buffer.should have_tag(%Q{li.generic_action input[@value="Custom Cancel Post"]})
326
+ end
327
+ end
328
+
329
+ it 'should render an input with anoptional localized label (I18n) - if first is not set' do
330
+ with_config :i18n_lookups_by_default, true do
331
+ concat(semantic_form_for(@new_post) do |builder|
332
+ concat(builder.action(:submit, :as => :generic))
333
+ concat(builder.action(:reset, :as => :generic))
334
+ concat(builder.action(:cancel, :as => :generic))
335
+ end)
336
+ output_buffer.should have_tag(%Q{li.generic_action input[@value="Custom Create"]})
337
+ output_buffer.should have_tag(%Q{li.generic_action input[@value="Custom Reset"]})
338
+ output_buffer.should have_tag(%Q{li.generic_action input[@value="Custom Cancel"]})
339
+ end
340
+ end
341
+
342
+ end
343
+ end
344
+ end
345
+
346
+ describe 'when used on an existing record' do
347
+ before do
348
+ @new_post.stub!(:persisted?).and_return(true)
349
+ end
350
+
351
+ describe 'when explicit label is provided' do
352
+ it 'should render an input with the explicitly specified label' do
353
+ concat(semantic_form_for(@new_post) do |builder|
354
+ concat(builder.action(:submit, :as => :generic, :label => "Click!"))
355
+ concat(builder.action(:reset, :as => :generic, :label => "Reset!"))
356
+ concat(builder.action(:cancel, :as => :generic, :label => "Cancel!"))
357
+ end)
358
+ output_buffer.should have_tag('li.generic_action input[@value="Click!"]')
359
+ output_buffer.should have_tag('li.generic_action input[@value="Reset!"]')
360
+ output_buffer.should have_tag('li.generic_action input[@value="Cancel!"]')
361
+ end
362
+ end
363
+
364
+ describe 'when no explicit label is provided' do
365
+ describe 'when no I18n-localized label is provided' do
366
+ before do
367
+ ::I18n.backend.store_translations :en, :formtastic => {
368
+ :update => 'Save %{model}',
369
+ :reset => 'Reset %{model}',
370
+ :cancel => 'Cancel %{model}'
371
+ }
372
+ end
373
+
374
+ after do
375
+ ::I18n.backend.reload!
376
+ end
377
+
378
+ it 'should render an input with default I18n-localized label (fallback)' do
379
+ concat(semantic_form_for(@new_post) do |builder|
380
+ concat(builder.action(:submit, :as => :generic))
381
+ concat(builder.action(:reset, :as => :generic))
382
+ concat(builder.action(:cancel, :as => :generic))
383
+ end)
384
+ output_buffer.should have_tag('li.generic_action input[@value="Save Post"]')
385
+ output_buffer.should have_tag('li.generic_action input[@value="Reset Post"]')
386
+ output_buffer.should have_tag('li.generic_action input[@value="Cancel Post"]')
387
+ end
388
+ end
389
+
390
+ describe 'when I18n-localized label is provided' do
391
+ before do
392
+ ::I18n.backend.reload!
393
+ ::I18n.backend.store_translations :en,
394
+ :formtastic => {
395
+ :actions => {
396
+ :update => 'Custom Save',
397
+ :reset => 'Custom Reset',
398
+ :cancel => 'Custom Cancel'
399
+ }
400
+ }
401
+ end
402
+
403
+ after do
404
+ ::I18n.backend.reload!
405
+ end
406
+
407
+ it 'should render an input with localized label (I18n)' do
408
+ with_config :i18n_lookups_by_default, true do
409
+ ::I18n.backend.store_translations :en,
410
+ :formtastic => {
411
+ :actions => {
412
+ :post => {
413
+ :update => 'Custom Save %{model}',
414
+ :reset => 'Custom Reset %{model}',
415
+ :cancel => 'Custom Cancel %{model}'
416
+ }
417
+ }
418
+ }
419
+ concat(semantic_form_for(@new_post) do |builder|
420
+ concat(builder.action(:submit, :as => :generic))
421
+ concat(builder.action(:reset, :as => :generic))
422
+ concat(builder.action(:cancel, :as => :generic))
423
+ end)
424
+ output_buffer.should have_tag(%Q{li.generic_action input[@value="Custom Save Post"]})
425
+ output_buffer.should have_tag(%Q{li.generic_action input[@value="Custom Reset Post"]})
426
+ output_buffer.should have_tag(%Q{li.generic_action input[@value="Custom Cancel Post"]})
427
+ end
428
+ end
429
+
430
+ it 'should render an input with anoptional localized label (I18n) - if first is not set' do
431
+ with_config :i18n_lookups_by_default, true do
432
+ concat(semantic_form_for(@new_post) do |builder|
433
+ concat(builder.action(:submit, :as => :generic))
434
+ concat(builder.action(:reset, :as => :generic))
435
+ concat(builder.action(:cancel, :as => :generic))
436
+ end)
437
+ output_buffer.should have_tag(%Q{li.generic_action input[@value="Custom Save"]})
438
+ output_buffer.should have_tag(%Q{li.generic_action input[@value="Custom Reset"]})
439
+ output_buffer.should have_tag(%Q{li.generic_action input[@value="Custom Cancel"]})
440
+ ::I18n.backend.store_translations :en, :formtastic => {}
441
+ end
442
+ end
443
+
444
+ end
445
+ end
446
+ end
447
+ end
448
+
449
+ describe 'when the model is two words' do
450
+
451
+ before do
452
+ output_buffer = ''
453
+ class ::UserPost
454
+ extend ActiveModel::Naming if defined?(ActiveModel::Naming)
455
+ include ActiveModel::Conversion if defined?(ActiveModel::Conversion)
456
+
457
+ def id
458
+ end
459
+
460
+ def persisted?
461
+ end
462
+
463
+ # Rails does crappy human_name
464
+ def self.human_name
465
+ "User post"
466
+ end
467
+ end
468
+ @new_user_post = ::UserPost.new
469
+
470
+ @new_user_post.stub!(:new_record?).and_return(true)
471
+ concat(semantic_form_for(@new_user_post, :url => '') do |builder|
472
+ concat(builder.action(:submit, :as => :generic))
473
+ concat(builder.action(:reset, :as => :generic))
474
+ concat(builder.action(:cancel, :as => :generic))
475
+ end)
476
+ end
477
+
478
+ it "should render the string as the value of the button" do
479
+ output_buffer.should have_tag('li input[@value="Create User post"]')
480
+ output_buffer.should have_tag('li input[@value="Reset User post"]')
481
+ output_buffer.should have_tag('li input[@value="Cancel User post"]')
482
+ end
483
+
484
+ end
485
+
486
+ end