formtastic-bootstrap 2.0.0 → 2.1.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/README.md +11 -2
  2. data/VERSION +1 -1
  3. data/vendor/assets/stylesheets/formtastic-bootstrap.css +4 -0
  4. metadata +51 -154
  5. data/.rspec +0 -1
  6. data/Gemfile +0 -14
  7. data/Gemfile.lock +0 -131
  8. data/Rakefile +0 -49
  9. data/formtastic-bootstrap.gemspec +0 -166
  10. data/lib/action_view/helpers/text_field_date_helper.rb +0 -166
  11. data/lib/formtastic-bootstrap/actions.rb +0 -10
  12. data/lib/formtastic-bootstrap/actions/base.rb +0 -22
  13. data/lib/formtastic-bootstrap/actions/button_action.rb +0 -13
  14. data/lib/formtastic-bootstrap/actions/input_action.rb +0 -13
  15. data/lib/formtastic-bootstrap/actions/link_action.rb +0 -12
  16. data/lib/formtastic-bootstrap/engine.rb +0 -4
  17. data/lib/formtastic-bootstrap/form_builder.rb +0 -40
  18. data/lib/formtastic-bootstrap/helpers.rb +0 -17
  19. data/lib/formtastic-bootstrap/helpers/action_helper.rb +0 -12
  20. data/lib/formtastic-bootstrap/helpers/actions_helper.rb +0 -24
  21. data/lib/formtastic-bootstrap/helpers/fieldset_wrapper.rb +0 -35
  22. data/lib/formtastic-bootstrap/helpers/input_helper.rb +0 -12
  23. data/lib/formtastic-bootstrap/helpers/inputs_helper.rb +0 -34
  24. data/lib/formtastic-bootstrap/inputs.rb +0 -36
  25. data/lib/formtastic-bootstrap/inputs/base.rb +0 -45
  26. data/lib/formtastic-bootstrap/inputs/base/choices.rb +0 -20
  27. data/lib/formtastic-bootstrap/inputs/base/collections.rb +0 -9
  28. data/lib/formtastic-bootstrap/inputs/base/errors.rb +0 -48
  29. data/lib/formtastic-bootstrap/inputs/base/grouped_collections.rb +0 -9
  30. data/lib/formtastic-bootstrap/inputs/base/hints.rb +0 -27
  31. data/lib/formtastic-bootstrap/inputs/base/html.rb +0 -21
  32. data/lib/formtastic-bootstrap/inputs/base/labelling.rb +0 -29
  33. data/lib/formtastic-bootstrap/inputs/base/numeric.rb +0 -9
  34. data/lib/formtastic-bootstrap/inputs/base/stringish.rb +0 -17
  35. data/lib/formtastic-bootstrap/inputs/base/timeish.rb +0 -55
  36. data/lib/formtastic-bootstrap/inputs/base/wrapping.rb +0 -55
  37. data/lib/formtastic-bootstrap/inputs/boolean_input.rb +0 -29
  38. data/lib/formtastic-bootstrap/inputs/check_boxes_input.rb +0 -40
  39. data/lib/formtastic-bootstrap/inputs/date_input.rb +0 -10
  40. data/lib/formtastic-bootstrap/inputs/date_select_input.rb +0 -8
  41. data/lib/formtastic-bootstrap/inputs/datetime_input.rb +0 -10
  42. data/lib/formtastic-bootstrap/inputs/datetime_select_input.rb +0 -8
  43. data/lib/formtastic-bootstrap/inputs/email_input.rb +0 -15
  44. data/lib/formtastic-bootstrap/inputs/file_input.rb +0 -14
  45. data/lib/formtastic-bootstrap/inputs/hidden_input.rb +0 -12
  46. data/lib/formtastic-bootstrap/inputs/number_input.rb +0 -15
  47. data/lib/formtastic-bootstrap/inputs/password_input.rb +0 -15
  48. data/lib/formtastic-bootstrap/inputs/phone_input.rb +0 -15
  49. data/lib/formtastic-bootstrap/inputs/radio_input.rb +0 -46
  50. data/lib/formtastic-bootstrap/inputs/range_input.rb +0 -15
  51. data/lib/formtastic-bootstrap/inputs/search_input.rb +0 -15
  52. data/lib/formtastic-bootstrap/inputs/select_input.rb +0 -16
  53. data/lib/formtastic-bootstrap/inputs/string_input.rb +0 -8
  54. data/lib/formtastic-bootstrap/inputs/text_input.rb +0 -14
  55. data/lib/formtastic-bootstrap/inputs/time_input.rb +0 -10
  56. data/lib/formtastic-bootstrap/inputs/time_select_input.rb +0 -8
  57. data/lib/formtastic-bootstrap/inputs/time_zone_input.rb +0 -14
  58. data/lib/formtastic-bootstrap/inputs/url_input.rb +0 -14
  59. data/spec/actions/button_action_spec.rb +0 -63
  60. data/spec/actions/input_action_spec.rb +0 -59
  61. data/spec/actions/link_action_spec.rb +0 -92
  62. data/spec/builder/semantic_fields_for_spec.rb +0 -130
  63. data/spec/helpers/action_helper_spec.rb +0 -368
  64. data/spec/helpers/actions_helper_spec.rb +0 -147
  65. data/spec/helpers/input_helper_spec.rb +0 -935
  66. data/spec/helpers/inputs_helper_spec.rb +0 -636
  67. data/spec/inputs/boolean_input_spec.rb +0 -226
  68. data/spec/inputs/check_boxes_input_spec.rb +0 -454
  69. data/spec/inputs/date_select_input_spec.rb +0 -164
  70. data/spec/inputs/datetime_select_input_spec.rb +0 -112
  71. data/spec/inputs/deprecated_time_date_datetime_inputs_spec.rb +0 -48
  72. data/spec/inputs/email_input_spec.rb +0 -86
  73. data/spec/inputs/file_input_spec.rb +0 -90
  74. data/spec/inputs/hidden_input_spec.rb +0 -153
  75. data/spec/inputs/number_input_spec.rb +0 -816
  76. data/spec/inputs/password_input_spec.rb +0 -100
  77. data/spec/inputs/phone_input_spec.rb +0 -86
  78. data/spec/inputs/radio_input_spec.rb +0 -267
  79. data/spec/inputs/range_input_spec.rb +0 -506
  80. data/spec/inputs/search_input_spec.rb +0 -85
  81. data/spec/inputs/select_input_spec.rb +0 -624
  82. data/spec/inputs/string_input_spec.rb +0 -210
  83. data/spec/inputs/text_input_spec.rb +0 -188
  84. data/spec/inputs/time_select_input_spec.rb +0 -191
  85. data/spec/inputs/time_zone_input_spec.rb +0 -118
  86. data/spec/inputs/url_input_spec.rb +0 -86
  87. data/spec/spec_helper.rb +0 -30
  88. data/spec/support/custom_macros.rb +0 -537
  89. data/spec/support/fb_custom_macros.rb +0 -23
@@ -1,8 +0,0 @@
1
- module FormtasticBootstrap
2
- module Inputs
3
- class StringInput < Formtastic::Inputs::StringInput
4
- include Base
5
- include Base::Stringish
6
- end
7
- end
8
- end
@@ -1,14 +0,0 @@
1
- module FormtasticBootstrap
2
- module Inputs
3
- class TextInput < Formtastic::Inputs::TextInput
4
- include Base
5
-
6
- def to_html
7
- bootstrap_wrapping do
8
- builder.text_area(method, input_html_options)
9
- end
10
- end
11
-
12
- end
13
- end
14
- end
@@ -1,10 +0,0 @@
1
- module FormtasticBootstrap
2
- module Inputs
3
- class TimeInput < FormtasticBootstrap::Inputs::TimeSelectInput
4
- def to_html
5
- ::ActiveSupport::Deprecation.warn("TimeInput (:as => :time) has been renamed to TimeSelectInput (:as => :time_select) and will be removed or changed in the next version of Formtastic, please update your forms.", caller(2))
6
- super
7
- end
8
- end
9
- end
10
- end
@@ -1,8 +0,0 @@
1
- module FormtasticBootstrap
2
- module Inputs
3
- class TimeSelectInput < Formtastic::Inputs::TimeSelectInput
4
- include Base
5
- include Base::Timeish
6
- end
7
- end
8
- end
@@ -1,14 +0,0 @@
1
- module FormtasticBootstrap
2
- module Inputs
3
- class TimeZoneInput < Formtastic::Inputs::TimeZoneInput
4
- include Base
5
-
6
- def to_html
7
- bootstrap_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
@@ -1,14 +0,0 @@
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
- bootstrap_wrapping do
9
- builder.url_field(method, input_html_options)
10
- end
11
- end
12
- end
13
- end
14
- end
@@ -1,63 +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
-
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
@@ -1,59 +0,0 @@
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
@@ -1,92 +0,0 @@
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
@@ -1,130 +0,0 @@
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" do
126
- output_buffer.should have_tag 'div.hidden div.input input#author_posts_attributes_0_id'
127
- end
128
- end
129
-
130
- end
@@ -1,368 +0,0 @@
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