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