speedo-formstrap 1.2.3 → 1.2.4
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +2 -2
- data/Gemfile.lock +42 -40
- data/README.md +8 -15
- data/Rakefile +3 -3
- data/VERSION +1 -1
- data/formtastic-bootstrap.gemspec +133 -0
- data/lib/{speedo-formstrap → formtastic-bootstrap}/engine.rb +1 -1
- data/lib/{speedo-formstrap → formtastic-bootstrap}/form_builder.rb +9 -11
- data/lib/{speedo-formstrap → formtastic-bootstrap}/helpers/buttons_helper.rb +10 -14
- data/lib/{speedo-formstrap → formtastic-bootstrap}/helpers/fieldset_wrapper.rb +7 -12
- data/lib/{speedo-formstrap → formtastic-bootstrap}/helpers/input_helper.rb +2 -2
- data/lib/{speedo-formstrap → formtastic-bootstrap}/helpers/inputs_helper.rb +6 -6
- data/lib/{speedo-formstrap → formtastic-bootstrap}/helpers.rb +6 -8
- data/lib/formtastic-bootstrap/inputs/base/choices.rb +49 -0
- data/lib/{speedo-formstrap → formtastic-bootstrap}/inputs/base/errors.rb +1 -1
- data/lib/{speedo-formstrap → formtastic-bootstrap}/inputs/base/hints.rb +1 -1
- data/lib/{speedo-formstrap → formtastic-bootstrap}/inputs/base/html.rb +1 -1
- data/lib/formtastic-bootstrap/inputs/base/labelling.rb +18 -0
- data/lib/{speedo-formstrap → formtastic-bootstrap}/inputs/base/stringish.rb +1 -1
- data/lib/{speedo-formstrap → formtastic-bootstrap}/inputs/base/timeish.rb +13 -6
- data/lib/{speedo-formstrap → formtastic-bootstrap}/inputs/base/wrapping.rb +15 -33
- data/lib/formtastic-bootstrap/inputs/base.rb +22 -0
- data/lib/formtastic-bootstrap/inputs/boolean_input.rb +33 -0
- data/lib/{speedo-formstrap → formtastic-bootstrap}/inputs/check_boxes_input.rb +10 -11
- data/lib/{speedo-formstrap → formtastic-bootstrap}/inputs/date_input.rb +1 -1
- data/lib/{speedo-formstrap → formtastic-bootstrap}/inputs/datetime_input.rb +1 -1
- data/lib/{speedo-formstrap → formtastic-bootstrap}/inputs/email_input.rb +1 -1
- data/lib/{speedo-formstrap → formtastic-bootstrap}/inputs/file_input.rb +1 -1
- data/lib/formtastic-bootstrap/inputs/hidden_input.rb +12 -0
- data/lib/{speedo-formstrap → formtastic-bootstrap}/inputs/number_input.rb +3 -3
- data/lib/{speedo-formstrap → formtastic-bootstrap}/inputs/password_input.rb +1 -1
- data/lib/{speedo-formstrap → formtastic-bootstrap}/inputs/phone_input.rb +1 -1
- data/lib/{speedo-formstrap → formtastic-bootstrap}/inputs/radio_input.rb +13 -14
- data/lib/{speedo-formstrap → formtastic-bootstrap}/inputs/range_input.rb +3 -3
- data/lib/{speedo-formstrap → formtastic-bootstrap}/inputs/search_input.rb +1 -1
- data/lib/{speedo-formstrap → formtastic-bootstrap}/inputs/select_input.rb +1 -1
- data/lib/{speedo-formstrap → formtastic-bootstrap}/inputs/string_input.rb +1 -1
- data/lib/{speedo-formstrap → formtastic-bootstrap}/inputs/text_input.rb +1 -1
- data/lib/{speedo-formstrap → formtastic-bootstrap}/inputs/time_input.rb +1 -1
- data/lib/{speedo-formstrap → formtastic-bootstrap}/inputs/time_zone_input.rb +1 -1
- data/lib/{speedo-formstrap → formtastic-bootstrap}/inputs/url_input.rb +1 -1
- data/lib/formtastic-bootstrap/inputs.rb +29 -0
- data/lib/formtastic-bootstrap.rb +6 -0
- data/spec/builder/errors_spec.rb +214 -0
- data/spec/builder/semantic_fields_for_spec.rb +14 -14
- data/spec/helpers/buttons_helper_spec.rb +45 -55
- data/spec/helpers/input_helper_spec.rb +188 -188
- data/spec/helpers/inputs_helper_spec.rb +102 -116
- data/spec/inputs/boolean_input_spec.rb +44 -72
- data/spec/inputs/check_boxes_input_spec.rb +80 -108
- data/spec/inputs/date_input_spec.rb +14 -80
- data/spec/inputs/datetime_input_spec.rb +12 -12
- data/spec/inputs/email_input_spec.rb +5 -33
- data/spec/inputs/file_input_spec.rb +5 -33
- data/spec/inputs/hidden_input_spec.rb +12 -40
- data/spec/inputs/number_input_spec.rb +96 -126
- data/spec/inputs/password_input_spec.rb +5 -33
- data/spec/inputs/phone_input_spec.rb +5 -33
- data/spec/inputs/radio_input_spec.rb +44 -72
- data/spec/inputs/range_input_spec.rb +65 -93
- data/spec/inputs/search_input_spec.rb +5 -32
- data/spec/inputs/select_input_spec.rb +77 -123
- data/spec/inputs/string_input_spec.rb +21 -66
- data/spec/inputs/text_input_spec.rb +13 -40
- 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 +5 -33
- data/spec/spec_helper.rb +1 -1
- data/spec/support/custom_macros.rb +188 -59
- data/spec/support/formtastic_spec_helper.rb +3 -19
- data/vendor/assets/stylesheets/formtastic-bootstrap.css +3 -0
- metadata +62 -74
- data/lib/speedo-formstrap/actions/base.rb +0 -18
- data/lib/speedo-formstrap/actions/button_action.rb +0 -7
- data/lib/speedo-formstrap/actions/input_action.rb +0 -7
- data/lib/speedo-formstrap/actions/link_action.rb +0 -7
- data/lib/speedo-formstrap/actions.rb +0 -4
- data/lib/speedo-formstrap/helpers/action_helper.rb +0 -12
- data/lib/speedo-formstrap/helpers/actions_helper.rb +0 -23
- data/lib/speedo-formstrap/inputs/base/choices.rb +0 -38
- data/lib/speedo-formstrap/inputs/base/labelling.rb +0 -28
- data/lib/speedo-formstrap/inputs/base/numeric.rb +0 -18
- data/lib/speedo-formstrap/inputs/base.rb +0 -23
- data/lib/speedo-formstrap/inputs/boolean_input.rb +0 -29
- data/lib/speedo-formstrap/inputs/hidden_input.rb +0 -14
- data/lib/speedo-formstrap/inputs.rb +0 -29
- data/lib/speedo-formstrap.rb +0 -7
- data/spec/actions/button_action_spec.rb +0 -68
- data/spec/actions/generic_action_spec.rb +0 -486
- data/spec/actions/input_action_spec.rb +0 -64
- data/spec/actions/link_action_spec.rb +0 -93
- data/spec/helpers/action_helper_spec.rb +0 -365
- data/spec/helpers/actions_helper_spec.rb +0 -143
- data/speedo-formstrap.gemspec +0 -145
@@ -1,23 +0,0 @@
|
|
1
|
-
require "speedo-formstrap/inputs/base/choices"
|
2
|
-
require "speedo-formstrap/inputs/base/errors"
|
3
|
-
require "speedo-formstrap/inputs/base/hints"
|
4
|
-
require "speedo-formstrap/inputs/base/html"
|
5
|
-
require "speedo-formstrap/inputs/base/labelling"
|
6
|
-
require "speedo-formstrap/inputs/base/numeric"
|
7
|
-
require "speedo-formstrap/inputs/base/stringish"
|
8
|
-
require "speedo-formstrap/inputs/base/timeish"
|
9
|
-
require "speedo-formstrap/inputs/base/wrapping"
|
10
|
-
|
11
|
-
module SpeedoFormstrap
|
12
|
-
module Inputs
|
13
|
-
module Base
|
14
|
-
|
15
|
-
include Errors
|
16
|
-
include Hints
|
17
|
-
include Html
|
18
|
-
include Labelling
|
19
|
-
include Wrapping
|
20
|
-
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
@@ -1,29 +0,0 @@
|
|
1
|
-
# TODO See if this can be refactored to make use of some of the Choices code.
|
2
|
-
module SpeedoFormstrap
|
3
|
-
module Inputs
|
4
|
-
class BooleanInput < Formtastic::Inputs::BooleanInput
|
5
|
-
include Base
|
6
|
-
|
7
|
-
def to_html
|
8
|
-
control_group_div_wrapping do
|
9
|
-
empty_label <<
|
10
|
-
hidden_field_html <<
|
11
|
-
input_div_wrapping(:block) do
|
12
|
-
label_with_nested_checkbox
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
def label_html_options
|
18
|
-
new_class = [super[:class], "checkbox"].compact.join(" ")
|
19
|
-
super.merge(:class => new_class)
|
20
|
-
end
|
21
|
-
|
22
|
-
# Need this for formatting to work.
|
23
|
-
def empty_label
|
24
|
-
template.content_tag(:label, '', :class => 'control-label') do end
|
25
|
-
end
|
26
|
-
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
@@ -1,14 +0,0 @@
|
|
1
|
-
module SpeedoFormstrap
|
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
|
@@ -1,29 +0,0 @@
|
|
1
|
-
require "speedo-formstrap/inputs/base"
|
2
|
-
require "speedo-formstrap/inputs/boolean_input"
|
3
|
-
require "speedo-formstrap/inputs/check_boxes_input"
|
4
|
-
require "speedo-formstrap/inputs/date_input"
|
5
|
-
require "speedo-formstrap/inputs/datetime_input"
|
6
|
-
require "speedo-formstrap/inputs/email_input"
|
7
|
-
require "speedo-formstrap/inputs/file_input"
|
8
|
-
require "speedo-formstrap/inputs/hidden_input"
|
9
|
-
require "speedo-formstrap/inputs/number_input"
|
10
|
-
require "speedo-formstrap/inputs/password_input"
|
11
|
-
require "speedo-formstrap/inputs/phone_input"
|
12
|
-
require "speedo-formstrap/inputs/radio_input"
|
13
|
-
require "speedo-formstrap/inputs/range_input"
|
14
|
-
require "speedo-formstrap/inputs/search_input"
|
15
|
-
require "speedo-formstrap/inputs/select_input"
|
16
|
-
require "speedo-formstrap/inputs/string_input"
|
17
|
-
require "speedo-formstrap/inputs/text_input"
|
18
|
-
require "speedo-formstrap/inputs/time_input"
|
19
|
-
require "speedo-formstrap/inputs/time_zone_input"
|
20
|
-
require "speedo-formstrap/inputs/url_input"
|
21
|
-
|
22
|
-
module SpeedoFormstrap
|
23
|
-
module Inputs
|
24
|
-
|
25
|
-
include Base
|
26
|
-
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
data/lib/speedo-formstrap.rb
DELETED
@@ -1,7 +0,0 @@
|
|
1
|
-
require "formtastic"
|
2
|
-
require "speedo-formstrap/engine" if defined?(::Rails) # For tests
|
3
|
-
require "speedo-formstrap/helpers"
|
4
|
-
require "speedo-formstrap/inputs"
|
5
|
-
require "speedo-formstrap/actions"
|
6
|
-
require "speedo-formstrap/form_builder"
|
7
|
-
require "action_view/helpers/text_field_date_helper"
|
@@ -1,68 +0,0 @@
|
|
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 = SpeedoFormstrap::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
|
@@ -1,486 +0,0 @@
|
|
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 = SpeedoFormstrap::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
|