formtastic-bootstrap 2.0.0 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
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,118 +0,0 @@
1
- # encoding: utf-8
2
- require 'spec_helper'
3
-
4
- describe 'time_zone input' 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.input(:time_zone))
14
- end)
15
- end
16
-
17
- it_should_have_bootstrap_horizontal_wrapping
18
- it_should_have_input_wrapper_with_class("time_zone")
19
- it_should_have_input_wrapper_with_class(:input)
20
- it_should_have_input_wrapper_with_id("post_time_zone_input")
21
- it_should_apply_error_logic_for_input_type(:time_zone)
22
-
23
- it 'should generate a label for the input' do
24
- output_buffer.should have_tag('form div.control-group label.control-label')
25
- output_buffer.should have_tag('form div.control-group label.control-label[@for="post_time_zone"]')
26
- output_buffer.should have_tag('form div.control-group label.control-label', /Time zone/)
27
- end
28
-
29
- it "should generate a select" do
30
- output_buffer.should have_tag("form div.control-group div.controls select")
31
- output_buffer.should have_tag("form div.control-group div.controls select#post_time_zone")
32
- output_buffer.should have_tag("form div.control-group div.controls select[@name=\"post[time_zone]\"]")
33
- end
34
-
35
- it 'should use input_html to style inputs' do
36
- concat(semantic_form_for(@new_post) do |builder|
37
- concat(builder.input(:time_zone, :input_html => { :class => 'myclass' }))
38
- end)
39
- output_buffer.should have_tag("form div.control-group div.controls select.myclass")
40
- end
41
-
42
- describe "when namespace is provided" do
43
-
44
- before do
45
- @output_buffer = ''
46
- mock_everything
47
-
48
- concat(semantic_form_for(@new_post, :namespace => 'context2') do |builder|
49
- concat(builder.input(:time_zone))
50
- end)
51
- end
52
-
53
- it_should_have_input_wrapper_with_id("context2_post_time_zone_input")
54
- it_should_have_select_with_id("context2_post_time_zone")
55
- it_should_have_label_for("context2_post_time_zone")
56
-
57
- end
58
-
59
- describe "when index is provided" do
60
-
61
- before do
62
- @output_buffer = ''
63
- mock_everything
64
-
65
- concat(semantic_form_for(@new_post) do |builder|
66
- concat(builder.fields_for(:author, :index => 3) do |author|
67
- concat(author.input(:name, :as => :time_zone))
68
- end)
69
- end)
70
- end
71
-
72
- it 'should index the id of the control group' do
73
- output_buffer.should have_tag("div.control-group#post_author_attributes_3_name_input")
74
- end
75
-
76
- it 'should index the id of the select tag' do
77
- output_buffer.should have_tag("select#post_author_attributes_3_name")
78
- end
79
-
80
- it 'should index the name of the select tag' do
81
- output_buffer.should have_tag("select[@name='post[author_attributes][3][name]']")
82
- end
83
-
84
- end
85
-
86
-
87
- describe 'when no object is given' do
88
- before(:each) do
89
- concat(semantic_form_for(:project, :url => 'http://test.host/') do |builder|
90
- concat(builder.input(:time_zone, :as => :time_zone))
91
- end)
92
- end
93
-
94
- it 'should generate labels' do
95
- output_buffer.should have_tag('form div.control-group label.control-label')
96
- output_buffer.should have_tag('form div.control-group label.control-label[@for="project_time_zone"]')
97
- output_buffer.should have_tag('form div.control-group label.control-label', /Time zone/)
98
- end
99
-
100
- it 'should generate select inputs' do
101
- output_buffer.should have_tag("form div.control-group div.controls select")
102
- output_buffer.should have_tag("form div.control-group div.controls select#project_time_zone")
103
- output_buffer.should have_tag("form div.control-group div.controls select[@name=\"project[time_zone]\"]")
104
- end
105
- end
106
-
107
- context "when required" do
108
- it "should add the required attribute to the input's html options" do
109
- with_config :use_required_attribute, true do
110
- concat(semantic_form_for(@new_post) do |builder|
111
- concat(builder.input(:title, :as => :time_zone, :required => true))
112
- end)
113
- output_buffer.should have_tag("select[@required]")
114
- end
115
- end
116
- end
117
-
118
- end
@@ -1,86 +0,0 @@
1
- # encoding: utf-8
2
- require 'spec_helper'
3
-
4
- describe 'url input' do
5
-
6
- include FormtasticSpecHelper
7
-
8
- before do
9
- @output_buffer = ''
10
- mock_everything
11
- end
12
-
13
- describe "when object is provided" do
14
- before do
15
- concat(semantic_form_for(@new_post) do |builder|
16
- concat(builder.input(:url))
17
- end)
18
- end
19
-
20
- it_should_have_bootstrap_horizontal_wrapping
21
- it_should_have_input_wrapper_with_class(:url)
22
- it_should_have_input_wrapper_with_class(:input)
23
- it_should_have_input_wrapper_with_class(:stringish)
24
- it_should_have_input_wrapper_with_id("post_url_input")
25
- it_should_have_label_with_text(/Url/)
26
- it_should_have_label_for("post_url")
27
- it_should_have_input_with_id("post_url")
28
- it_should_have_input_with_type(:url)
29
- it_should_have_input_with_name("post[url]")
30
-
31
- end
32
-
33
- describe "when namespace is provided" do
34
-
35
- before do
36
- concat(semantic_form_for(@new_post, :namespace => "context2") do |builder|
37
- concat(builder.input(:url))
38
- end)
39
- end
40
-
41
- it_should_have_input_wrapper_with_id("context2_post_url_input")
42
- it_should_have_label_and_input_with_id("context2_post_url")
43
-
44
- end
45
-
46
- describe "when index is provided" do
47
-
48
- before do
49
- @output_buffer = ''
50
- mock_everything
51
-
52
- concat(semantic_form_for(@new_post) do |builder|
53
- concat(builder.fields_for(:author, :index => 3) do |author|
54
- concat(author.input(:name, :as => :url))
55
- end)
56
- end)
57
- end
58
-
59
- it 'should index the id of the control-group' do
60
- output_buffer.should have_tag("div.control-group#post_author_attributes_3_name_input")
61
- end
62
-
63
- it 'should index the id of the select tag' do
64
- output_buffer.should have_tag("input#post_author_attributes_3_name")
65
- end
66
-
67
- it 'should index the name of the select tag' do
68
- output_buffer.should have_tag("input[@name='post[author_attributes][3][name]']")
69
- end
70
-
71
- end
72
-
73
-
74
- describe "when required" do
75
- it "should add the required attribute to the input's html options" do
76
- with_config :use_required_attribute, true do
77
- concat(semantic_form_for(@new_post) do |builder|
78
- concat(builder.input(:title, :as => :url, :required => true))
79
- end)
80
- output_buffer.should have_tag("input[@required]")
81
- end
82
- end
83
- end
84
-
85
- end
86
-
@@ -1,30 +0,0 @@
1
- require 'bundler/setup'
2
-
3
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
4
- $LOAD_PATH.unshift(File.dirname(__FILE__))
5
-
6
- # require 'rspec'
7
- # require 'rspec_tag_matchers'
8
- # require 'rubygems'
9
-
10
- # Find Formtastic and grab its testing support first.
11
- formtastic_full_gem_path = Bundler.load.specs.find{|s| s.name == "formtastic" }.full_gem_path
12
- require File.join(formtastic_full_gem_path, 'spec', 'spec_helper.rb')
13
-
14
- # Now add in ours.
15
- require 'formtastic-bootstrap'
16
- require File.join(File.dirname(__FILE__), "support", "custom_macros.rb")
17
- require File.join(File.dirname(__FILE__), "support", "fb_custom_macros.rb")
18
-
19
-
20
- RSpec.configure do |config|
21
- config.before(:suite) do
22
- Formtastic::Helpers::FormHelper.builder = FormtasticBootstrap::FormBuilder
23
- end
24
- config.include FbCustomMacros
25
- end
26
-
27
- # RSpec.configure do |config|
28
- # config.include RspecTagMatchers
29
- # config.include CustomMacros
30
- # end
@@ -1,537 +0,0 @@
1
- # encoding: utf-8
2
-
3
- module CustomMacros
4
-
5
- def self.included(base)
6
- base.extend(ClassMethods)
7
- end
8
-
9
- module ClassMethods
10
-
11
- def it_should_have_input_wrapper_with_class(class_name)
12
- it "should have input wrapper with class '#{class_name}'" do
13
- output_buffer.should have_tag("form div.#{class_name}")
14
- end
15
- end
16
-
17
- def it_should_have_input_wrapper_with_id(id_string)
18
- it "should have input wrapper with id '#{id_string}'" do
19
- output_buffer.should have_tag("form div##{id_string}")
20
- end
21
- end
22
-
23
- def it_should_not_have_a_label
24
- it "should not have a label" do
25
- output_buffer.should_not have_tag("form li label")
26
- end
27
- end
28
-
29
- def it_should_have_a_nested_fieldset
30
- it "should have a nested_fieldset" do
31
- output_buffer.should have_tag("form li fieldset")
32
- end
33
- end
34
-
35
- def it_should_have_a_nested_fieldset_with_class(klass)
36
- it "should have a nested_fieldset with class #{klass}" do
37
- output_buffer.should have_tag("form li fieldset.#{klass}")
38
- end
39
- end
40
-
41
- def it_should_have_a_nested_ordered_list_with_class(klass)
42
- it "should have a nested fieldset with class #{klass}" do
43
- output_buffer.should have_tag("form li ol.#{klass}")
44
- end
45
- end
46
-
47
- def it_should_have_label_with_text(string_or_regex)
48
- it "should have a label with text '#{string_or_regex}'" do
49
- output_buffer.should have_tag("form div.control-group label.control-label", string_or_regex)
50
- end
51
- end
52
-
53
- def it_should_have_label_for(element_id)
54
- it "should have a label for ##{element_id}" do
55
- output_buffer.should have_tag("form div.control-group label.control-label[@for='#{element_id}']")
56
- end
57
- end
58
-
59
- def it_should_have_an_inline_label_for(element_id)
60
- it "should have a label for ##{element_id}" do
61
- output_buffer.should have_tag("form div.control-group div.controls label[@for='#{element_id}']")
62
- end
63
- end
64
-
65
- def it_should_have_input_with_id(element_id)
66
- it "should have an input with id '#{element_id}'" do
67
- output_buffer.should have_tag("form div.control-group div.controls input[@id=\"#{element_id}\"]")
68
- end
69
- end
70
-
71
- def it_should_have_select_with_id(element_id)
72
- it "should have a select box with id '#{element_id}'" do
73
- output_buffer.should have_tag("form div.control-group div.controls select##{element_id}")
74
- end
75
- end
76
-
77
- def it_should_have_input_with_type(input_type)
78
- it "should have a #{input_type} input" do
79
- output_buffer.should have_tag("form div.control-group div.controls input[@type=\"#{input_type}\"]")
80
- end
81
- end
82
-
83
- def it_should_have_input_with_name(name)
84
- it "should have an input named #{name}" do
85
- output_buffer.should have_tag("form div.control-group div.controls input[@name=\"#{name}\"]")
86
- end
87
- end
88
-
89
- def it_should_have_select_with_name(name)
90
- it "should have an input named #{name}" do
91
- output_buffer.should have_tag("form div.control-group div.controls select[@name=\"#{name}\"]")
92
- end
93
- end
94
-
95
- def it_should_have_textarea_with_name(name)
96
- it "should have an input named #{name}" do
97
- output_buffer.should have_tag("form div.control-group div.controls textarea[@name=\"#{name}\"]")
98
- end
99
- end
100
-
101
- def it_should_have_textarea_with_id(element_id)
102
- it "should have an input with id '#{element_id}'" do
103
- output_buffer.should have_tag("form div.control-group div.controls textarea##{element_id}")
104
- end
105
- end
106
-
107
- def it_should_have_label_and_input_with_id(element_id)
108
- it "should have an input with id '#{element_id}'" do
109
- output_buffer.should have_tag("form div.control-group div.controls input##{element_id}")
110
- output_buffer.should have_tag("form div.control-group label.control-label[@for='#{element_id}']")
111
- end
112
- end
113
-
114
- def it_should_use_default_text_field_size_when_not_nil(as)
115
- it 'should use default_text_field_size when not nil' do
116
- with_config :default_text_field_size, 30 do
117
- concat(semantic_form_for(@new_post) do |builder|
118
- concat(builder.input(:title, :as => as))
119
- end)
120
- output_buffer.should have_tag("form div.control-group div.controls input[@size='#{Formtastic::FormBuilder.default_text_field_size}']")
121
- end
122
- end
123
- end
124
-
125
- def it_should_not_use_default_text_field_size_when_nil(as)
126
- it 'should not use default_text_field_size when nil' do
127
- with_config :default_text_field_size, nil do
128
- concat(semantic_form_for(@new_post) do |builder|
129
- concat(builder.input(:title, :as => as))
130
- end)
131
- output_buffer.should have_tag("form div.control-group div.controls input")
132
- output_buffer.should_not have_tag("form div.control-group div.controls input[@size]")
133
- end
134
- end
135
- end
136
-
137
- def it_should_apply_custom_input_attributes_when_input_html_provided(as)
138
- it 'it should apply custom input attributes when input_html provided' do
139
- concat(semantic_form_for(@new_post) do |builder|
140
- concat(builder.input(:title, :as => as, :input_html => { :class => 'myclass' }))
141
- end)
142
- output_buffer.should have_tag("form div.control-group div.controls input.myclass")
143
- end
144
- end
145
-
146
- def it_should_apply_custom_for_to_label_when_input_html_id_provided(as)
147
- it 'it should apply custom for to label when input_html :id provided' do
148
- concat(semantic_form_for(@new_post) do |builder|
149
- concat(builder.input(:title, :as => as, :input_html => { :id => 'myid' }))
150
- end)
151
- output_buffer.should have_tag('form div.control-group label.control-label[@for="myid"]')
152
- end
153
- end
154
-
155
- def it_should_have_maxlength_matching_column_limit
156
- it 'should have a maxlength matching column limit' do
157
- @new_post.column_for_attribute(:title).limit.should == 50
158
- output_buffer.should have_tag("form div.control-group div.controls input[@maxlength='50']")
159
- end
160
- end
161
-
162
- def it_should_use_column_size_for_columns_shorter_than_default_text_field_size(as)
163
- it 'should use the column size for columns shorter than default_text_field_size' do
164
- column_limit_shorted_than_default = 1
165
- @new_post.stub!(:column_for_attribute).and_return(mock('column', :type => as, :limit => column_limit_shorted_than_default))
166
-
167
- concat(semantic_form_for(@new_post) do |builder|
168
- concat(builder.input(:title, :as => as))
169
- end)
170
-
171
- output_buffer.should have_tag("form li input[@size='#{column_limit_shorted_than_default}']")
172
- end
173
- end
174
-
175
- def it_should_apply_error_logic_for_input_type(type, inline_or_block = :inline)
176
- describe 'when there are errors on the object for this method' do
177
- before do
178
- @title_errors = ['must not be blank', 'must be longer than 10 characters', 'must be awesome']
179
- @errors = mock('errors')
180
- @errors.stub!(:[]).with(errors_matcher(:title)).and_return(@title_errors)
181
- Formtastic::FormBuilder.file_metadata_suffixes.each do |suffix|
182
- @errors.stub!(:[]).with(errors_matcher("title_#{suffix}".to_sym)).and_return(nil)
183
- end
184
- @new_post.stub!(:errors).and_return(@errors)
185
- end
186
-
187
- it 'should apply an errors class to the list item' do
188
- concat(semantic_form_for(@new_post) do |builder|
189
- concat(builder.input(:title, :as => type))
190
- end)
191
- output_buffer.should have_tag('form div.error')
192
- end
193
-
194
- it 'should not wrap the input with the Rails default error wrapping' do
195
- concat(semantic_form_for(@new_post) do |builder|
196
- concat(builder.input(:title, :as => type))
197
- end)
198
- output_buffer.should_not have_tag('div.fieldWithErrors')
199
- end
200
-
201
- it 'should render a paragraph for the errors' do
202
- FormtasticBootstrap::FormBuilder.inline_errors = :sentence
203
- concat(semantic_form_for(@new_post) do |builder|
204
- concat(builder.input(:title, :as => type))
205
- end)
206
- # output_buffer.should have_tag('form div.error p.inline-errors')
207
- if inline_or_block == :inline
208
- output_buffer.should have_tag('form div.error span.help-inline')
209
- else
210
- output_buffer.should have_tag('form div.error span.help-block')
211
- end
212
- end
213
-
214
- it 'should not display an error list' do
215
- FormtasticBootstrap::FormBuilder.inline_errors = :list
216
- concat(semantic_form_for(@new_post) do |builder|
217
- concat(builder.input(:title, :as => type))
218
- end)
219
- output_buffer.should have_tag('form div.error ul.errors')
220
- end
221
- end
222
-
223
- describe 'when there are no errors on the object for this method' do
224
- before do
225
- @form = semantic_form_for(@new_post) do |builder|
226
- concat(builder.input(:title, :as => type))
227
- end
228
- end
229
-
230
- it 'should not apply an errors class to the list item' do
231
- output_buffer.should_not have_tag('form li.error')
232
- end
233
-
234
- it 'should not render a paragraph for the errors' do
235
- output_buffer.should_not have_tag('form li.error p.inline-errors')
236
- end
237
-
238
- it 'should not display an error list' do
239
- output_buffer.should_not have_tag('form li.error ul.errors')
240
- end
241
- end
242
-
243
- describe 'when no object is provided' do
244
- before do
245
- concat(semantic_form_for(:project, :url => 'http://test.host') do |builder|
246
- concat(builder.input(:title, :as => type))
247
- end)
248
- end
249
-
250
- it 'should not apply an errors class to the list item' do
251
- output_buffer.should_not have_tag('form li.error')
252
- end
253
-
254
- it 'should not render a paragraph for the errors' do
255
- output_buffer.should_not have_tag('form li.error p.inline-errors')
256
- end
257
-
258
- it 'should not display an error list' do
259
- output_buffer.should_not have_tag('form li.error ul.errors')
260
- end
261
- end
262
- end
263
-
264
- def it_should_call_find_on_association_class_when_no_collection_is_provided(as)
265
- it "should call find on the association class when no collection is provided" do
266
- ::Author.should_receive(:where)
267
- concat(semantic_form_for(@new_post) do |builder|
268
- concat(builder.input(:author, :as => as))
269
- end)
270
- end
271
- end
272
-
273
- def it_should_use_the_collection_when_provided(as, countable)
274
-
275
- # Set control-div 'as' class.
276
- cd_as = (as == :radio) ? :radio_buttons : as
277
-
278
- describe 'when the :collection option is provided' do
279
-
280
- before do
281
- @authors = ::Author.all * 2
282
- output_buffer.replace ''
283
- end
284
-
285
- it 'should use the provided collection' do
286
- concat(semantic_form_for(@new_post) do |builder|
287
- concat(builder.input(:author, :as => as, :collection => @authors))
288
- end)
289
- output_buffer.should have_tag("form div.#{cd_as} #{countable}", :count => @authors.size + (as == :select ? 1 : 0))
290
- end
291
-
292
- describe 'and the :collection is an array of strings' do
293
- before do
294
- @categories = [ 'General', 'Design', 'Development', 'Quasi-Serious Inventions' ]
295
- end
296
-
297
- it "should use the string as the label text and value for each #{countable}" do
298
- concat(semantic_form_for(@new_post) do |builder|
299
- concat(builder.input(:category_name, :as => as, :collection => @categories))
300
- end)
301
-
302
- @categories.each do |value|
303
- output_buffer.should have_tag("form div.#{cd_as}", /#{value}/)
304
- output_buffer.should have_tag("form div.#{cd_as} #{countable}[@value='#{value}']")
305
- end
306
- end
307
-
308
- if as == :radio
309
- it 'should generate a sanitized label for attribute' do
310
- @bob.stub!(:category_name).and_return(@categories)
311
- concat(semantic_form_for(@new_post) do |builder|
312
- fields = builder.semantic_fields_for(@bob) do |bob_builder|
313
- concat(bob_builder.input(:category_name, :as => as, :collection => @categories))
314
- end
315
- concat(fields)
316
- end)
317
- output_buffer.should have_tag("form div.control-group div.controls label[@for='post_author_category_name_general']")
318
- output_buffer.should have_tag("form div.control-group div.controls label[@for='post_author_category_name_design']")
319
- output_buffer.should have_tag("form div.control-group div.controls label[@for='post_author_category_name_development']")
320
- output_buffer.should have_tag("form div.control-group div.controls label[@for='post_author_category_name_quasi-serious_inventions']")
321
- end
322
- end
323
- end
324
-
325
- describe 'and the :collection is a hash of strings' do
326
- before do
327
- @categories = { 'General' => 'gen', 'Design' => 'des','Development' => 'dev' }
328
- end
329
-
330
- it "should use the key as the label text and the hash value as the value attribute for each #{countable}" do
331
- concat(semantic_form_for(@new_post) do |builder|
332
- concat(builder.input(:category_name, :as => as, :collection => @categories))
333
- end)
334
-
335
- @categories.each do |label, value|
336
- output_buffer.should have_tag("form div.#{cd_as}", /#{label}/)
337
- output_buffer.should have_tag("form div.#{cd_as} #{countable}[@value='#{value}']")
338
- end
339
- end
340
- end
341
-
342
- describe 'and the :collection is an array of arrays' do
343
- before do
344
- @categories = { 'General' => 'gen', 'Design' => 'des', 'Development' => 'dev' }.to_a
345
- end
346
-
347
- it "should use the first value as the label text and the last value as the value attribute for #{countable}" do
348
- concat(semantic_form_for(@new_post) do |builder|
349
- concat(builder.input(:category_name, :as => as, :collection => @categories))
350
- end)
351
-
352
- @categories.each do |text, value|
353
- label = as == :select ? :option : :label
354
- output_buffer.should have_tag("form div.#{cd_as} #{label}", /#{text}/i)
355
- output_buffer.should have_tag("form div.#{cd_as} #{countable}[@value='#{value.to_s}']")
356
- output_buffer.should have_tag("form div.#{cd_as} #{countable}#post_category_name_#{value.to_s}") if as == :radio
357
- end
358
- end
359
- end
360
-
361
- if as == :radio
362
- describe 'and the :collection is an array of arrays with boolean values' do
363
- before do
364
- @choices = { 'Yeah' => true, 'Nah' => false }.to_a
365
- end
366
-
367
- it "should use the first value as the label text and the last value as the value attribute for #{countable}" do
368
- concat(semantic_form_for(@new_post) do |builder|
369
- concat(builder.input(:category_name, :as => as, :collection => @choices))
370
- end)
371
-
372
- output_buffer.should have_tag("form div.#{cd_as} #{countable}#post_category_name_true")
373
- output_buffer.should have_tag("form div.#{cd_as} #{countable}#post_category_name_false")
374
- end
375
- end
376
- end
377
-
378
- describe 'and the :collection is an array of symbols' do
379
- before do
380
- @categories = [ :General, :Design, :Development ]
381
- end
382
-
383
- it "should use the symbol as the label text and value for each #{countable}" do
384
- concat(semantic_form_for(@new_post) do |builder|
385
- concat(builder.input(:category_name, :as => as, :collection => @categories))
386
- end)
387
-
388
- @categories.each do |value|
389
- label = as == :select ? :option : :label
390
- output_buffer.should have_tag("form div.#{cd_as} #{label}", /#{value}/i)
391
- output_buffer.should have_tag("form div.#{cd_as} #{countable}[@value='#{value.to_s}']")
392
- end
393
- end
394
- end
395
-
396
- describe 'and the :collection is an OrderedHash of strings' do
397
- before do
398
- @categories = ActiveSupport::OrderedHash.new('General' => 'gen', 'Design' => 'des','Development' => 'dev')
399
- end
400
-
401
- it "should use the key as the label text and the hash value as the value attribute for each #{countable}" do
402
- concat(semantic_form_for(@new_post) do |builder|
403
- concat(builder.input(:category_name, :as => as, :collection => @categories))
404
- end)
405
-
406
- @categories.each do |label, value|
407
- output_buffer.should have_tag("form div.#{cd_as}", /#{label}/)
408
- output_buffer.should have_tag("form div.#{cd_as} #{countable}[@value='#{value}']")
409
- end
410
- end
411
-
412
- end
413
-
414
- describe 'when the :member_label option is provided' do
415
-
416
- describe 'as a symbol' do
417
- before do
418
- concat(semantic_form_for(@new_post) do |builder|
419
- concat(builder.input(:author, :as => as, :member_label => :login))
420
- end)
421
- end
422
-
423
- it 'should have options with text content from the specified method' do
424
- ::Author.all.each do |author|
425
- output_buffer.should have_tag("form div.#{cd_as}", /#{author.login}/)
426
- end
427
- end
428
- end
429
-
430
- describe 'as a proc' do
431
- before do
432
- concat(semantic_form_for(@new_post) do |builder|
433
- concat(builder.input(:author, :as => as, :member_label => Proc.new {|a| a.login.reverse }))
434
- end)
435
- end
436
-
437
- it 'should have options with the proc applied to each' do
438
- ::Author.all.each do |author|
439
- output_buffer.should have_tag("form div.#{cd_as}", /#{author.login.reverse}/)
440
- end
441
- end
442
- end
443
-
444
- describe 'as a method object' do
445
- before do
446
- def reverse_login(a)
447
- a.login.reverse
448
- end
449
- concat(semantic_form_for(@new_post) do |builder|
450
- concat(builder.input(:author, :as => as, :member_label => method(:reverse_login)))
451
- end)
452
- end
453
-
454
- it 'should have options with the proc applied to each' do
455
- ::Author.all.each do |author|
456
- output_buffer.should have_tag("form div.#{cd_as}", /#{author.login.reverse}/)
457
- end
458
- end
459
- end
460
- end
461
-
462
- describe 'when the :member_label option is not provided' do
463
- Formtastic::FormBuilder.collection_label_methods.each do |label_method|
464
-
465
- describe "when the collection objects respond to #{label_method}" do
466
- before do
467
- @fred.stub!(:respond_to?).and_return { |m| m.to_s == label_method || m.to_s == 'id' }
468
- ::Author.all.each { |a| a.stub!(label_method).and_return('The Label Text') }
469
-
470
- concat(semantic_form_for(@new_post) do |builder|
471
- concat(builder.input(:author, :as => as))
472
- end)
473
- end
474
-
475
- it "should render the options with #{label_method} as the label" do
476
- ::Author.all.each do |author|
477
- output_buffer.should have_tag("form div.#{cd_as}", /The Label Text/)
478
- end
479
- end
480
- end
481
-
482
- end
483
- end
484
-
485
- describe 'when the :member_value option is provided' do
486
-
487
- describe 'as a symbol' do
488
- before do
489
- concat(semantic_form_for(@new_post) do |builder|
490
- concat(builder.input(:author, :as => as, :member_value => :login))
491
- end)
492
- end
493
-
494
- it 'should have options with values from specified method' do
495
- ::Author.all.each do |author|
496
- output_buffer.should have_tag("form div.#{cd_as} #{countable}[@value='#{author.login}']")
497
- end
498
- end
499
- end
500
-
501
- describe 'as a proc' do
502
- before do
503
- concat(semantic_form_for(@new_post) do |builder|
504
- concat(builder.input(:author, :as => as, :member_value => Proc.new {|a| a.login.reverse }))
505
- end)
506
- end
507
-
508
- it 'should have options with the proc applied to each value' do
509
- ::Author.all.each do |author|
510
- output_buffer.should have_tag("form div.#{cd_as} #{countable}[@value='#{author.login.reverse}']")
511
- end
512
- end
513
- end
514
-
515
- describe 'as a method object' do
516
- before do
517
- def reverse_login(a)
518
- a.login.reverse
519
- end
520
- concat(semantic_form_for(@new_post) do |builder|
521
- concat(builder.input(:author, :as => as, :member_value => method(:reverse_login)))
522
- end)
523
- end
524
-
525
- it 'should have options with the proc applied to each value' do
526
- ::Author.all.each do |author|
527
- output_buffer.should have_tag("form div.#{cd_as} #{countable}[@value='#{author.login.reverse}']")
528
- end
529
- end
530
- end
531
- end
532
-
533
- end
534
- end
535
-
536
- end
537
- end