formtastic 3.1.2 → 4.0.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.
- checksums.yaml +7 -0
- data/.gitattributes +1 -0
- data/.github/workflows/test.yml +61 -0
- data/.gitignore +3 -2
- data/CHANGELOG.md +52 -0
- data/Gemfile.lock +105 -0
- data/MIT-LICENSE +1 -1
- data/{README.textile → README.md} +178 -167
- data/RELEASE_PROCESS +3 -1
- data/Rakefile +20 -1
- data/app/assets/stylesheets/formtastic.css +1 -1
- data/bin/appraisal +8 -0
- data/formtastic.gemspec +10 -16
- data/gemfiles/rails_5.2/Gemfile +5 -0
- data/gemfiles/rails_6.0/Gemfile +5 -0
- data/gemfiles/rails_6.1/Gemfile +5 -0
- data/gemfiles/rails_edge/Gemfile +13 -0
- data/lib/formtastic.rb +9 -11
- data/lib/formtastic/actions.rb +6 -3
- data/lib/formtastic/deprecation.rb +1 -38
- data/lib/formtastic/engine.rb +3 -1
- data/lib/formtastic/form_builder.rb +11 -24
- data/lib/formtastic/helpers.rb +1 -1
- data/lib/formtastic/helpers/action_helper.rb +1 -48
- data/lib/formtastic/helpers/enum.rb +13 -0
- data/lib/formtastic/helpers/errors_helper.rb +2 -2
- data/lib/formtastic/helpers/fieldset_wrapper.rb +13 -9
- data/lib/formtastic/helpers/form_helper.rb +1 -1
- data/lib/formtastic/helpers/input_helper.rb +23 -77
- data/lib/formtastic/helpers/inputs_helper.rb +27 -22
- data/lib/formtastic/i18n.rb +1 -1
- data/lib/formtastic/inputs.rb +32 -29
- data/lib/formtastic/inputs/base/choices.rb +1 -1
- data/lib/formtastic/inputs/base/collections.rb +43 -10
- data/lib/formtastic/inputs/base/database.rb +7 -2
- data/lib/formtastic/inputs/base/errors.rb +4 -4
- data/lib/formtastic/inputs/base/hints.rb +1 -1
- data/lib/formtastic/inputs/base/html.rb +7 -6
- data/lib/formtastic/inputs/base/naming.rb +4 -4
- data/lib/formtastic/inputs/base/options.rb +2 -3
- data/lib/formtastic/inputs/base/timeish.rb +5 -1
- data/lib/formtastic/inputs/base/validations.rb +38 -12
- data/lib/formtastic/inputs/check_boxes_input.rb +13 -5
- data/lib/formtastic/inputs/color_input.rb +0 -1
- data/lib/formtastic/inputs/country_input.rb +3 -1
- data/lib/formtastic/inputs/radio_input.rb +20 -0
- data/lib/formtastic/inputs/select_input.rb +29 -1
- data/lib/formtastic/inputs/time_zone_input.rb +16 -6
- data/lib/formtastic/localizer.rb +20 -22
- data/lib/formtastic/namespaced_class_finder.rb +1 -1
- data/lib/formtastic/version.rb +1 -1
- data/lib/generators/formtastic/form/form_generator.rb +1 -1
- data/lib/generators/formtastic/input/input_generator.rb +46 -0
- data/lib/generators/templates/formtastic.rb +14 -13
- data/lib/generators/templates/input.rb +19 -0
- data/sample/basic_inputs.html +1 -1
- data/script/integration-template.rb +74 -0
- data/script/integration.sh +19 -0
- data/spec/action_class_finder_spec.rb +1 -1
- data/spec/actions/button_action_spec.rb +8 -8
- data/spec/actions/generic_action_spec.rb +60 -60
- data/spec/actions/input_action_spec.rb +7 -7
- data/spec/actions/link_action_spec.rb +10 -10
- data/spec/builder/custom_builder_spec.rb +37 -21
- data/spec/builder/error_proc_spec.rb +4 -4
- data/spec/builder/semantic_fields_for_spec.rb +27 -27
- data/spec/fast_spec_helper.rb +12 -0
- data/spec/generators/formtastic/form/form_generator_spec.rb +25 -25
- data/spec/generators/formtastic/input/input_generator_spec.rb +124 -0
- data/spec/generators/formtastic/install/install_generator_spec.rb +9 -9
- data/spec/helpers/action_helper_spec.rb +328 -10
- data/spec/helpers/actions_helper_spec.rb +17 -17
- data/spec/helpers/form_helper_spec.rb +37 -37
- data/spec/helpers/input_helper_spec.rb +975 -2
- data/spec/helpers/inputs_helper_spec.rb +120 -105
- data/spec/helpers/reflection_helper_spec.rb +3 -3
- data/spec/helpers/semantic_errors_helper_spec.rb +22 -22
- data/spec/i18n_spec.rb +26 -26
- data/spec/input_class_finder_spec.rb +1 -1
- data/spec/inputs/base/collections_spec.rb +76 -0
- data/spec/inputs/base/validations_spec.rb +480 -0
- data/spec/inputs/boolean_input_spec.rb +55 -55
- data/spec/inputs/check_boxes_input_spec.rb +155 -108
- data/spec/inputs/color_input_spec.rb +51 -63
- data/spec/inputs/country_input_spec.rb +20 -20
- data/spec/inputs/custom_input_spec.rb +2 -6
- data/spec/inputs/datalist_input_spec.rb +1 -1
- data/spec/inputs/date_picker_input_spec.rb +42 -42
- data/spec/inputs/date_select_input_spec.rb +51 -37
- data/spec/inputs/datetime_picker_input_spec.rb +46 -46
- data/spec/inputs/datetime_select_input_spec.rb +53 -37
- data/spec/inputs/email_input_spec.rb +5 -5
- data/spec/inputs/file_input_spec.rb +6 -6
- data/spec/inputs/hidden_input_spec.rb +18 -18
- data/spec/inputs/include_blank_spec.rb +8 -8
- data/spec/inputs/label_spec.rb +20 -20
- data/spec/inputs/number_input_spec.rb +112 -112
- data/spec/inputs/password_input_spec.rb +5 -5
- data/spec/inputs/phone_input_spec.rb +5 -5
- data/spec/inputs/placeholder_spec.rb +5 -5
- data/spec/inputs/radio_input_spec.rb +84 -58
- data/spec/inputs/range_input_spec.rb +66 -66
- data/spec/inputs/readonly_spec.rb +50 -0
- data/spec/inputs/search_input_spec.rb +5 -5
- data/spec/inputs/select_input_spec.rb +149 -93
- data/spec/inputs/string_input_spec.rb +23 -23
- data/spec/inputs/text_input_spec.rb +16 -16
- data/spec/inputs/time_picker_input_spec.rb +43 -43
- data/spec/inputs/time_select_input_spec.rb +67 -54
- data/spec/inputs/time_zone_input_spec.rb +54 -28
- data/spec/inputs/url_input_spec.rb +5 -5
- data/spec/inputs/with_options_spec.rb +7 -7
- data/spec/localizer_spec.rb +17 -17
- data/spec/namespaced_class_finder_spec.rb +2 -2
- data/spec/schema.rb +21 -0
- data/spec/spec_helper.rb +165 -253
- data/spec/support/custom_macros.rb +72 -75
- data/spec/support/shared_examples.rb +0 -1232
- data/spec/support/test_environment.rb +23 -9
- metadata +69 -176
- data/.travis.yml +0 -29
- data/Appraisals +0 -29
- data/CHANGELOG +0 -31
- data/DEPRECATIONS +0 -49
- data/gemfiles/rails_3.2.gemfile +0 -7
- data/gemfiles/rails_4.0.4.gemfile +0 -7
- data/gemfiles/rails_4.1.gemfile +0 -7
- data/gemfiles/rails_4.2.gemfile +0 -7
- data/gemfiles/rails_4.gemfile +0 -7
- data/gemfiles/rails_edge.gemfile +0 -10
- data/lib/formtastic/util.rb +0 -57
- data/spec/helpers/namespaced_action_helper_spec.rb +0 -43
- data/spec/helpers/namespaced_input_helper_spec.rb +0 -36
- data/spec/support/deferred_garbage_collection.rb +0 -21
- data/spec/util_spec.rb +0 -66
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
require 'spec_helper'
|
|
3
|
+
|
|
4
|
+
RSpec.describe 'readonly option' do
|
|
5
|
+
|
|
6
|
+
include FormtasticSpecHelper
|
|
7
|
+
|
|
8
|
+
before do
|
|
9
|
+
@output_buffer = ''
|
|
10
|
+
mock_everything
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
describe "placeholder text" do
|
|
14
|
+
[:email, :number, :password, :phone, :search, :string, :url, :text, :date_picker, :time_picker, :datetime_picker].each do |type|
|
|
15
|
+
|
|
16
|
+
describe "for #{type} inputs" do
|
|
17
|
+
|
|
18
|
+
describe "when readonly is found in input_html" do
|
|
19
|
+
it "sets readonly attribute" do
|
|
20
|
+
concat(semantic_form_for(@new_post) do |builder|
|
|
21
|
+
concat(builder.input(:title, :as => type, input_html: {readonly: true}))
|
|
22
|
+
end)
|
|
23
|
+
expect(output_buffer).to have_tag((type == :text ? 'textarea' : 'input') + '[@readonly]')
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
describe "when readonly not found in input_html" do
|
|
28
|
+
describe "when column is not readonly attribute" do
|
|
29
|
+
it "doesn't set readonly attribute" do
|
|
30
|
+
concat(semantic_form_for(@new_post) do |builder|
|
|
31
|
+
concat(builder.input(:title, :as => type))
|
|
32
|
+
end)
|
|
33
|
+
expect(output_buffer).not_to have_tag((type == :text ? 'textarea' : 'input') + '[@readonly]')
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
describe "when column is readonly attribute" do
|
|
37
|
+
it "sets readonly attribute" do
|
|
38
|
+
input_class = "Formtastic::Inputs::#{type.to_s.camelize}Input".constantize
|
|
39
|
+
expect_any_instance_of(input_class).to receive(:readonly_attribute?).at_least(1).and_return(true)
|
|
40
|
+
concat(semantic_form_for(@new_post) do |builder|
|
|
41
|
+
concat(builder.input(:title, :as => type))
|
|
42
|
+
end)
|
|
43
|
+
expect(output_buffer).to have_tag((type == :text ? 'textarea' : 'input') + '[@readonly]')
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# encoding: utf-8
|
|
2
2
|
require 'spec_helper'
|
|
3
3
|
|
|
4
|
-
describe 'search input' do
|
|
4
|
+
RSpec.describe 'search input' do
|
|
5
5
|
|
|
6
6
|
include FormtasticSpecHelper
|
|
7
7
|
|
|
@@ -56,15 +56,15 @@ describe 'search input' do
|
|
|
56
56
|
end
|
|
57
57
|
|
|
58
58
|
it 'should index the id of the wrapper' do
|
|
59
|
-
output_buffer.
|
|
59
|
+
expect(output_buffer).to have_tag("li#post_author_attributes_3_name_input")
|
|
60
60
|
end
|
|
61
61
|
|
|
62
62
|
it 'should index the id of the select tag' do
|
|
63
|
-
output_buffer.
|
|
63
|
+
expect(output_buffer).to have_tag("input#post_author_attributes_3_name")
|
|
64
64
|
end
|
|
65
65
|
|
|
66
66
|
it 'should index the name of the select tag' do
|
|
67
|
-
output_buffer.
|
|
67
|
+
expect(output_buffer).to have_tag("input[@name='post[author_attributes][3][name]']")
|
|
68
68
|
end
|
|
69
69
|
|
|
70
70
|
end
|
|
@@ -75,7 +75,7 @@ describe 'search input' do
|
|
|
75
75
|
concat(semantic_form_for(@new_post) do |builder|
|
|
76
76
|
concat(builder.input(:title, :as => :search, :required => true))
|
|
77
77
|
end)
|
|
78
|
-
output_buffer.
|
|
78
|
+
expect(output_buffer).to have_tag("input[@required]")
|
|
79
79
|
end
|
|
80
80
|
end
|
|
81
81
|
end
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# encoding: utf-8
|
|
2
2
|
require 'spec_helper'
|
|
3
3
|
|
|
4
|
-
describe 'select input' do
|
|
4
|
+
RSpec.describe 'select input' do
|
|
5
5
|
|
|
6
6
|
include FormtasticSpecHelper
|
|
7
7
|
|
|
@@ -23,10 +23,10 @@ describe 'select input' do
|
|
|
23
23
|
|
|
24
24
|
it 'should have a option for each key and/or value' do
|
|
25
25
|
@array_with_values.each do |v|
|
|
26
|
-
output_buffer.
|
|
26
|
+
expect(output_buffer).to have_tag("form li select option[@value='#{v}']", :text => /^#{v}$/)
|
|
27
27
|
end
|
|
28
28
|
@array_with_keys_and_values.each do |v|
|
|
29
|
-
output_buffer.
|
|
29
|
+
expect(output_buffer).to have_tag("form li select option[@value='#{v.second}']", :text => /^#{v.first}$/)
|
|
30
30
|
end
|
|
31
31
|
end
|
|
32
32
|
end
|
|
@@ -43,26 +43,26 @@ describe 'select input' do
|
|
|
43
43
|
|
|
44
44
|
it 'should have a option for each key and/or value' do
|
|
45
45
|
@set_with_values.each do |v|
|
|
46
|
-
output_buffer.
|
|
46
|
+
expect(output_buffer).to have_tag("form li select option[@value='#{v}']", :text => /^#{v}$/)
|
|
47
47
|
end
|
|
48
48
|
@set_with_keys_and_values.each do |v|
|
|
49
|
-
output_buffer.
|
|
49
|
+
expect(output_buffer).to have_tag("form li select option[@value='#{v.second}']", :text => /^#{v.first}$/)
|
|
50
50
|
end
|
|
51
51
|
end
|
|
52
52
|
end
|
|
53
53
|
|
|
54
54
|
describe "using a related model without reflection's options (Mongoid Document)" do
|
|
55
55
|
before do
|
|
56
|
-
@new_post.
|
|
56
|
+
allow(@new_post).to receive(:mongoid_reviewer)
|
|
57
57
|
concat(semantic_form_for(@new_post) do |builder|
|
|
58
58
|
concat(builder.input(:mongoid_reviewer, :as => :select))
|
|
59
59
|
end)
|
|
60
60
|
end
|
|
61
61
|
|
|
62
62
|
it 'should draw select options' do
|
|
63
|
-
output_buffer.
|
|
64
|
-
output_buffer.
|
|
65
|
-
output_buffer.
|
|
63
|
+
expect(output_buffer).to have_tag('form li select')
|
|
64
|
+
expect(output_buffer).to have_tag('form li select#post_reviewer_id')
|
|
65
|
+
expect(output_buffer).not_to have_tag('form li select#post_mongoid_reviewer_id')
|
|
66
66
|
end
|
|
67
67
|
end
|
|
68
68
|
|
|
@@ -76,7 +76,7 @@ describe 'select input' do
|
|
|
76
76
|
|
|
77
77
|
it 'should have an option for each value' do
|
|
78
78
|
@range_with_values.each do |v|
|
|
79
|
-
output_buffer.
|
|
79
|
+
expect(output_buffer).to have_tag("form li select option[@value='#{v}']", :text => /^#{v}$/)
|
|
80
80
|
end
|
|
81
81
|
end
|
|
82
82
|
end
|
|
@@ -91,7 +91,7 @@ describe 'select input' do
|
|
|
91
91
|
|
|
92
92
|
it 'should render select options using provided HTML string' do
|
|
93
93
|
2.times do |v|
|
|
94
|
-
output_buffer.
|
|
94
|
+
expect(output_buffer).to have_tag("form li select option[@value='#{v}']", :text => /^#{v}$/)
|
|
95
95
|
end
|
|
96
96
|
end
|
|
97
97
|
end
|
|
@@ -125,8 +125,8 @@ describe 'select input' do
|
|
|
125
125
|
end
|
|
126
126
|
|
|
127
127
|
it 'should render a select with at least options: true/false' do
|
|
128
|
-
output_buffer.
|
|
129
|
-
output_buffer.
|
|
128
|
+
expect(output_buffer).to have_tag("form li select option[@value='true']", :text => /^Yes$/)
|
|
129
|
+
expect(output_buffer).to have_tag("form li select option[@value='false']", :text => /^No$/)
|
|
130
130
|
end
|
|
131
131
|
end
|
|
132
132
|
|
|
@@ -145,8 +145,79 @@ describe 'select input' do
|
|
|
145
145
|
end
|
|
146
146
|
|
|
147
147
|
it 'should render a select with at least options: true/false' do
|
|
148
|
-
output_buffer.
|
|
149
|
-
output_buffer.
|
|
148
|
+
expect(output_buffer).to have_tag("form li select option[@value='true']", :text => /#{@boolean_select_labels[:yes]}/)
|
|
149
|
+
expect(output_buffer).to have_tag("form li select option[@value='false']", :text => /#{@boolean_select_labels[:no]}/)
|
|
150
|
+
end
|
|
151
|
+
end
|
|
152
|
+
end
|
|
153
|
+
|
|
154
|
+
describe 'for a enum column' do
|
|
155
|
+
before do
|
|
156
|
+
allow(@new_post).to receive(:status) { 'inactive' }
|
|
157
|
+
statuses = ActiveSupport::HashWithIndifferentAccess.new("active"=>0, "inactive"=>1)
|
|
158
|
+
allow(@new_post.class).to receive(:statuses) { statuses }
|
|
159
|
+
allow(@new_post).to receive(:defined_enums) { { "status" => statuses } }
|
|
160
|
+
end
|
|
161
|
+
|
|
162
|
+
context 'single choice' do
|
|
163
|
+
before do
|
|
164
|
+
concat(semantic_form_for(@new_post) do |builder|
|
|
165
|
+
concat(builder.input(:status, :as => :select))
|
|
166
|
+
end)
|
|
167
|
+
end
|
|
168
|
+
|
|
169
|
+
it_should_have_input_wrapper_with_class("select")
|
|
170
|
+
it_should_have_input_wrapper_with_class(:input)
|
|
171
|
+
it_should_have_input_wrapper_with_id("post_status_input")
|
|
172
|
+
it_should_have_label_with_text(/Status/)
|
|
173
|
+
it_should_have_label_for('post_status')
|
|
174
|
+
it_should_apply_error_logic_for_input_type(:select)
|
|
175
|
+
|
|
176
|
+
it 'should have a select inside the wrapper' do
|
|
177
|
+
expect(output_buffer).to have_tag('form li select')
|
|
178
|
+
expect(output_buffer).to have_tag('form li select#post_status')
|
|
179
|
+
end
|
|
180
|
+
|
|
181
|
+
it 'should have a valid name' do
|
|
182
|
+
expect(output_buffer).to have_tag("form li select[@name='post[status]']")
|
|
183
|
+
expect(output_buffer).not_to have_tag("form li select[@name='post[status][]']")
|
|
184
|
+
end
|
|
185
|
+
|
|
186
|
+
it 'should not create a multi-select' do
|
|
187
|
+
expect(output_buffer).not_to have_tag('form li select[@multiple]')
|
|
188
|
+
end
|
|
189
|
+
|
|
190
|
+
it 'should not add a hidden input' do
|
|
191
|
+
expect(output_buffer).not_to have_tag('form li input[@type="hidden"]')
|
|
192
|
+
end
|
|
193
|
+
|
|
194
|
+
it 'should create a select without size' do
|
|
195
|
+
expect(output_buffer).not_to have_tag('form li select[@size]')
|
|
196
|
+
end
|
|
197
|
+
|
|
198
|
+
it 'should have a blank option' do
|
|
199
|
+
expect(output_buffer).to have_tag("form li select option[@value='']")
|
|
200
|
+
end
|
|
201
|
+
|
|
202
|
+
it 'should have a select option for each defined enum status' do
|
|
203
|
+
expect(output_buffer).to have_tag("form li select[@name='post[status]'] option", :count => @new_post.class.statuses.count + 1)
|
|
204
|
+
@new_post.class.statuses.each do |label, value|
|
|
205
|
+
expect(output_buffer).to have_tag("form li select option[@value='#{label}']", :text => /#{label.humanize}/)
|
|
206
|
+
end
|
|
207
|
+
end
|
|
208
|
+
|
|
209
|
+
it 'should have one option with a "selected" attribute (TODO)' do
|
|
210
|
+
expect(output_buffer).to have_tag("form li select[@name='post[status]'] option[@selected]", :count => 1)
|
|
211
|
+
end
|
|
212
|
+
end
|
|
213
|
+
|
|
214
|
+
context 'multiple choice' do
|
|
215
|
+
it 'raises an error' do
|
|
216
|
+
expect {
|
|
217
|
+
concat(semantic_form_for(@new_post) do |builder|
|
|
218
|
+
concat(builder.input(:status, :as => :select, :multiple => true))
|
|
219
|
+
end)
|
|
220
|
+
}.to raise_error Formtastic::UnsupportedEnumCollection
|
|
150
221
|
end
|
|
151
222
|
end
|
|
152
223
|
end
|
|
@@ -169,88 +240,73 @@ describe 'select input' do
|
|
|
169
240
|
it_should_use_the_collection_when_provided(:select, 'option')
|
|
170
241
|
|
|
171
242
|
it 'should have a select inside the wrapper' do
|
|
172
|
-
output_buffer.
|
|
173
|
-
output_buffer.
|
|
174
|
-
output_buffer.
|
|
243
|
+
expect(output_buffer).to have_tag('form li select')
|
|
244
|
+
expect(output_buffer).to have_tag('form li select#post_author_id')
|
|
245
|
+
expect(output_buffer).to have_tag('form li select#post_reviewer_id')
|
|
175
246
|
end
|
|
176
247
|
|
|
177
248
|
it 'should have a valid name' do
|
|
178
|
-
output_buffer.
|
|
179
|
-
output_buffer.
|
|
180
|
-
output_buffer.
|
|
249
|
+
expect(output_buffer).to have_tag("form li select[@name='post[author_id]']")
|
|
250
|
+
expect(output_buffer).not_to have_tag("form li select[@name='post[author_id][]']")
|
|
251
|
+
expect(output_buffer).not_to have_tag("form li select[@name='post[reviewer_id][]']")
|
|
181
252
|
end
|
|
182
253
|
|
|
183
254
|
it 'should not create a multi-select' do
|
|
184
|
-
output_buffer.
|
|
255
|
+
expect(output_buffer).not_to have_tag('form li select[@multiple]')
|
|
185
256
|
end
|
|
186
257
|
|
|
187
258
|
it 'should not add a hidden input' do
|
|
188
|
-
output_buffer.
|
|
259
|
+
expect(output_buffer).not_to have_tag('form li input[@type="hidden"]')
|
|
189
260
|
end
|
|
190
261
|
|
|
191
262
|
it 'should create a select without size' do
|
|
192
|
-
output_buffer.
|
|
263
|
+
expect(output_buffer).not_to have_tag('form li select[@size]')
|
|
193
264
|
end
|
|
194
265
|
|
|
195
266
|
it 'should have a blank option' do
|
|
196
|
-
output_buffer.
|
|
267
|
+
expect(output_buffer).to have_tag("form li select option[@value='']")
|
|
197
268
|
end
|
|
198
269
|
|
|
199
270
|
it 'should have a select option for each Author' do
|
|
200
|
-
output_buffer.
|
|
271
|
+
expect(output_buffer).to have_tag("form li select[@name='post[author_id]'] option", :count => ::Author.all.size + 1)
|
|
201
272
|
::Author.all.each do |author|
|
|
202
|
-
output_buffer.
|
|
273
|
+
expect(output_buffer).to have_tag("form li select option[@value='#{author.id}']", :text => /#{author.to_label}/)
|
|
203
274
|
end
|
|
204
275
|
end
|
|
205
276
|
|
|
206
277
|
it 'should have one option with a "selected" attribute (bob)' do
|
|
207
|
-
output_buffer.
|
|
278
|
+
expect(output_buffer).to have_tag("form li select[@name='post[author_id]'] option[@selected]", :count => 1)
|
|
208
279
|
end
|
|
209
280
|
|
|
210
281
|
it 'should not singularize the association name' do
|
|
211
|
-
@new_post.
|
|
212
|
-
@new_post.
|
|
213
|
-
@new_post.
|
|
282
|
+
allow(@new_post).to receive(:author_status).and_return(@bob)
|
|
283
|
+
allow(@new_post).to receive(:author_status_id).and_return(@bob.id)
|
|
284
|
+
allow(@new_post).to receive(:column_for_attribute).and_return(double('column', :type => :integer, :limit => 255))
|
|
214
285
|
|
|
215
286
|
concat(semantic_form_for(@new_post) do |builder|
|
|
216
287
|
concat(builder.input(:author_status, :as => :select))
|
|
217
288
|
end)
|
|
218
289
|
|
|
219
|
-
output_buffer.
|
|
290
|
+
expect(output_buffer).to have_tag('form li select#post_author_status_id')
|
|
220
291
|
end
|
|
221
292
|
end
|
|
222
293
|
|
|
223
294
|
describe "for a belongs_to association with :conditions" do
|
|
224
295
|
before do
|
|
225
|
-
::Post.
|
|
296
|
+
allow(::Post).to receive(:reflect_on_association).with(:author) do
|
|
226
297
|
mock = double('reflection', :options => {:conditions => {:active => true}}, :klass => ::Author, :macro => :belongs_to)
|
|
227
|
-
mock.
|
|
298
|
+
allow(mock).to receive(:[]).with(:class_name).and_return("Author")
|
|
228
299
|
mock
|
|
229
300
|
end
|
|
230
301
|
end
|
|
231
302
|
|
|
232
303
|
it "should call author.(scoped|where) with association conditions" do
|
|
233
|
-
|
|
234
|
-
::Author.should_receive(:scoped).with(:conditions => {:active => true})
|
|
235
|
-
else
|
|
236
|
-
::Author.should_receive(:where).with({:active => true})
|
|
237
|
-
end
|
|
304
|
+
expect(::Author).to receive(:where).with({:active => true})
|
|
238
305
|
|
|
239
306
|
semantic_form_for(@new_post) do |builder|
|
|
240
307
|
concat(builder.input(:author, :as => :select))
|
|
241
308
|
end
|
|
242
309
|
end
|
|
243
|
-
|
|
244
|
-
it "should call author.(scoped|where) with association conditions" do
|
|
245
|
-
if Formtastic::Util.rails3?
|
|
246
|
-
::Author.should_receive(:scoped).with(:conditions => {:active => true})
|
|
247
|
-
else
|
|
248
|
-
::Author.should_receive(:where).with({:active => true})
|
|
249
|
-
end
|
|
250
|
-
semantic_form_for(@new_post) do |builder|
|
|
251
|
-
concat(builder.input(:author, :as => :select))
|
|
252
|
-
end
|
|
253
|
-
end
|
|
254
310
|
end
|
|
255
311
|
|
|
256
312
|
describe 'for a has_many association' do
|
|
@@ -269,31 +325,31 @@ describe 'select input' do
|
|
|
269
325
|
it_should_use_the_collection_when_provided(:select, 'option')
|
|
270
326
|
|
|
271
327
|
it 'should have a select inside the wrapper' do
|
|
272
|
-
output_buffer.
|
|
273
|
-
output_buffer.
|
|
328
|
+
expect(output_buffer).to have_tag('form li select')
|
|
329
|
+
expect(output_buffer).to have_tag('form li select#author_post_ids')
|
|
274
330
|
end
|
|
275
331
|
|
|
276
332
|
it 'should have a multi-select select' do
|
|
277
|
-
output_buffer.
|
|
333
|
+
expect(output_buffer).to have_tag('form li select[@multiple="multiple"]')
|
|
278
334
|
end
|
|
279
335
|
|
|
280
336
|
it 'should append [] to the name attribute for multiple select' do
|
|
281
|
-
output_buffer.
|
|
337
|
+
expect(output_buffer).to have_tag('form li select[@multiple="multiple"][@name="author[post_ids][]"]')
|
|
282
338
|
end
|
|
283
339
|
|
|
284
340
|
it 'should have a hidden field' do
|
|
285
|
-
output_buffer.
|
|
341
|
+
expect(output_buffer).to have_tag('form li input[@type="hidden"][@name="author[post_ids][]"]', :count => 1)
|
|
286
342
|
end
|
|
287
343
|
|
|
288
344
|
it 'should have a select option for each Post' do
|
|
289
|
-
output_buffer.
|
|
345
|
+
expect(output_buffer).to have_tag('form li select option', :count => ::Post.all.size)
|
|
290
346
|
::Post.all.each do |post|
|
|
291
|
-
output_buffer.
|
|
347
|
+
expect(output_buffer).to have_tag("form li select option[@value='#{post.id}']", :text => /#{post.to_label}/)
|
|
292
348
|
end
|
|
293
349
|
end
|
|
294
350
|
|
|
295
351
|
it 'should not have a blank option by default' do
|
|
296
|
-
output_buffer.
|
|
352
|
+
expect(output_buffer).not_to have_tag("form li select option[@value='']")
|
|
297
353
|
end
|
|
298
354
|
|
|
299
355
|
it 'should respect the :include_blank option for single selects' do
|
|
@@ -301,7 +357,7 @@ describe 'select input' do
|
|
|
301
357
|
concat(builder.input(:posts, :as => :select, :multiple => false, :include_blank => true))
|
|
302
358
|
end)
|
|
303
359
|
|
|
304
|
-
output_buffer.
|
|
360
|
+
expect(output_buffer).to have_tag("form li select option[@value='']")
|
|
305
361
|
end
|
|
306
362
|
|
|
307
363
|
it 'should respect the :include_blank option for multiple selects' do
|
|
@@ -309,11 +365,11 @@ describe 'select input' do
|
|
|
309
365
|
concat(builder.input(:posts, :as => :select, :multiple => true, :include_blank => true))
|
|
310
366
|
end)
|
|
311
367
|
|
|
312
|
-
output_buffer.
|
|
368
|
+
expect(output_buffer).to have_tag("form li select option[@value='']")
|
|
313
369
|
end
|
|
314
370
|
|
|
315
371
|
it 'should have one option with a "selected" attribute' do
|
|
316
|
-
output_buffer.
|
|
372
|
+
expect(output_buffer).to have_tag('form li select option[@selected]', :count => 1)
|
|
317
373
|
end
|
|
318
374
|
end
|
|
319
375
|
|
|
@@ -333,23 +389,23 @@ describe 'select input' do
|
|
|
333
389
|
it_should_use_the_collection_when_provided(:select, 'option')
|
|
334
390
|
|
|
335
391
|
it 'should have a select inside the wrapper' do
|
|
336
|
-
output_buffer.
|
|
337
|
-
output_buffer.
|
|
392
|
+
expect(output_buffer).to have_tag('form li select')
|
|
393
|
+
expect(output_buffer).to have_tag('form li select#post_author_ids')
|
|
338
394
|
end
|
|
339
395
|
|
|
340
396
|
it 'should have a multi-select select' do
|
|
341
|
-
output_buffer.
|
|
397
|
+
expect(output_buffer).to have_tag('form li select[@multiple="multiple"]')
|
|
342
398
|
end
|
|
343
399
|
|
|
344
400
|
it 'should have a select option for each Author' do
|
|
345
|
-
output_buffer.
|
|
401
|
+
expect(output_buffer).to have_tag('form li select option', :count => ::Author.all.size)
|
|
346
402
|
::Author.all.each do |author|
|
|
347
|
-
output_buffer.
|
|
403
|
+
expect(output_buffer).to have_tag("form li select option[@value='#{author.id}']", :text => /#{author.to_label}/)
|
|
348
404
|
end
|
|
349
405
|
end
|
|
350
406
|
|
|
351
407
|
it 'should not have a blank option by default' do
|
|
352
|
-
output_buffer.
|
|
408
|
+
expect(output_buffer).not_to have_tag("form li select option[@value='']")
|
|
353
409
|
end
|
|
354
410
|
|
|
355
411
|
it 'should respect the :include_blank option for single selects' do
|
|
@@ -357,7 +413,7 @@ describe 'select input' do
|
|
|
357
413
|
concat(builder.input(:authors, :as => :select, :multiple => false, :include_blank => true))
|
|
358
414
|
end)
|
|
359
415
|
|
|
360
|
-
output_buffer.
|
|
416
|
+
expect(output_buffer).to have_tag("form li select option[@value='']")
|
|
361
417
|
end
|
|
362
418
|
|
|
363
419
|
it 'should respect the :include_blank option for multiple selects' do
|
|
@@ -365,51 +421,51 @@ describe 'select input' do
|
|
|
365
421
|
concat(builder.input(:authors, :as => :select, :multiple => true, :include_blank => true))
|
|
366
422
|
end)
|
|
367
423
|
|
|
368
|
-
output_buffer.
|
|
424
|
+
expect(output_buffer).to have_tag("form li select option[@value='']")
|
|
369
425
|
end
|
|
370
426
|
|
|
371
427
|
it 'should have one option with a "selected" attribute' do
|
|
372
|
-
output_buffer.
|
|
428
|
+
expect(output_buffer).to have_tag('form li select option[@selected]', :count => 1)
|
|
373
429
|
end
|
|
374
430
|
end
|
|
375
431
|
|
|
376
432
|
describe 'when :prompt => "choose something" is set' do
|
|
377
433
|
before do
|
|
378
|
-
@new_post.
|
|
434
|
+
allow(@new_post).to receive(:author_id).and_return(nil)
|
|
379
435
|
concat(semantic_form_for(@new_post) do |builder|
|
|
380
436
|
concat(builder.input(:author, :as => :select, :prompt => "choose author"))
|
|
381
437
|
end)
|
|
382
438
|
end
|
|
383
439
|
|
|
384
440
|
it 'should have a select with prompt' do
|
|
385
|
-
output_buffer.
|
|
441
|
+
expect(output_buffer).to have_tag("form li select option[@value='']", :text => /choose author/, :count => 1)
|
|
386
442
|
end
|
|
387
443
|
|
|
388
444
|
it 'should not have a second blank select option' do
|
|
389
|
-
output_buffer.
|
|
445
|
+
expect(output_buffer).to have_tag("form li select option[@value='']", :count => 1)
|
|
390
446
|
end
|
|
391
447
|
end
|
|
392
448
|
|
|
393
449
|
describe 'when no object is given' do
|
|
394
|
-
before(:
|
|
450
|
+
before(:example) do
|
|
395
451
|
concat(semantic_form_for(:project, :url => 'http://test.host') do |builder|
|
|
396
452
|
concat(builder.input(:author, :as => :select, :collection => ::Author.all))
|
|
397
453
|
end)
|
|
398
454
|
end
|
|
399
455
|
|
|
400
456
|
it 'should generate label' do
|
|
401
|
-
output_buffer.
|
|
402
|
-
output_buffer.
|
|
457
|
+
expect(output_buffer).to have_tag('form li label', :text => /Author/)
|
|
458
|
+
expect(output_buffer).to have_tag("form li label[@for='project_author']")
|
|
403
459
|
end
|
|
404
460
|
|
|
405
461
|
it 'should generate select inputs' do
|
|
406
|
-
output_buffer.
|
|
407
|
-
output_buffer.
|
|
462
|
+
expect(output_buffer).to have_tag('form li select#project_author')
|
|
463
|
+
expect(output_buffer).to have_tag('form li select option', :count => ::Author.all.size + 1)
|
|
408
464
|
end
|
|
409
465
|
|
|
410
466
|
it 'should generate an option to each item' do
|
|
411
467
|
::Author.all.each do |author|
|
|
412
|
-
output_buffer.
|
|
468
|
+
expect(output_buffer).to have_tag("form li select option[@value='#{author.id}']", :text => /#{author.to_label}/)
|
|
413
469
|
end
|
|
414
470
|
end
|
|
415
471
|
end
|
|
@@ -420,7 +476,7 @@ describe 'select input' do
|
|
|
420
476
|
concat(semantic_form_for(:project, :url => 'http://test.host') do |builder|
|
|
421
477
|
concat(builder.input(:author_name, :as => :select, :collection => ::Author.all))
|
|
422
478
|
end)
|
|
423
|
-
output_buffer.
|
|
479
|
+
expect(output_buffer).to have_tag("form li select[@name='project[author_name]']")
|
|
424
480
|
end
|
|
425
481
|
|
|
426
482
|
describe 'and :multiple is set to true through :input_html' do
|
|
@@ -428,7 +484,7 @@ describe 'select input' do
|
|
|
428
484
|
concat(semantic_form_for(:project, :url => 'http://test.host') do |builder|
|
|
429
485
|
concat(builder.input(:author_name, :as => :select, :input_html => {:multiple => true} ))
|
|
430
486
|
end)
|
|
431
|
-
output_buffer.
|
|
487
|
+
expect(output_buffer).to have_tag("form li select[@multiple]")
|
|
432
488
|
end
|
|
433
489
|
end
|
|
434
490
|
|
|
@@ -437,14 +493,14 @@ describe 'select input' do
|
|
|
437
493
|
concat(semantic_form_for(:project, :url => 'http://test.host') do |builder|
|
|
438
494
|
concat(builder.input(:author_name, :as => :select, :multiple => true, :collection => ["Fred", "Bob"]))
|
|
439
495
|
end)
|
|
440
|
-
output_buffer.
|
|
496
|
+
expect(output_buffer).to have_tag("form li select[@multiple]")
|
|
441
497
|
end
|
|
442
498
|
end
|
|
443
499
|
|
|
444
500
|
end
|
|
445
501
|
|
|
446
502
|
describe 'when a grouped collection collection is given' do
|
|
447
|
-
before(:
|
|
503
|
+
before(:example) do
|
|
448
504
|
concat(semantic_form_for(:project, :url => 'http://test.host') do |builder|
|
|
449
505
|
@grouped_opts = [['one', ['pencil', 'crayon', 'pen']],
|
|
450
506
|
['two', ['eyes', 'hands', 'feet']],
|
|
@@ -455,12 +511,12 @@ describe 'select input' do
|
|
|
455
511
|
|
|
456
512
|
it 'should generate an option to each item' do
|
|
457
513
|
@grouped_opts.each do |opt_pair|
|
|
458
|
-
output_buffer.
|
|
514
|
+
expect(output_buffer).to have_tag("form li select optgroup[@label='#{opt_pair[0]}']")
|
|
459
515
|
opt_pair[1].each do |v|
|
|
460
|
-
output_buffer.
|
|
516
|
+
expect(output_buffer).to have_tag("form li select optgroup[@label='#{opt_pair[0]}'] option[@value='#{v}']")
|
|
461
517
|
end
|
|
462
518
|
end
|
|
463
|
-
output_buffer.
|
|
519
|
+
expect(output_buffer).to have_tag("form li select optgroup option[@selected]","hands")
|
|
464
520
|
end
|
|
465
521
|
end
|
|
466
522
|
|
|
@@ -468,7 +524,7 @@ describe 'select input' do
|
|
|
468
524
|
before do
|
|
469
525
|
@output_buffer = ''
|
|
470
526
|
@some_meta_descriptions = ["One", "Two", "Three"]
|
|
471
|
-
@new_post.
|
|
527
|
+
allow(@new_post).to receive(:meta_description).at_least(:once)
|
|
472
528
|
end
|
|
473
529
|
|
|
474
530
|
describe ":as is not set" do
|
|
@@ -482,7 +538,7 @@ describe 'select input' do
|
|
|
482
538
|
end
|
|
483
539
|
|
|
484
540
|
it "should render a select field" do
|
|
485
|
-
output_buffer.
|
|
541
|
+
expect(output_buffer).to have_tag("form li select", :count => 2)
|
|
486
542
|
end
|
|
487
543
|
end
|
|
488
544
|
|
|
@@ -498,7 +554,7 @@ describe 'select input' do
|
|
|
498
554
|
end
|
|
499
555
|
|
|
500
556
|
it "should render a text field" do
|
|
501
|
-
output_buffer.
|
|
557
|
+
expect(output_buffer).to have_tag("form li input[@type='text']", :count => 2)
|
|
502
558
|
end
|
|
503
559
|
end
|
|
504
560
|
end
|
|
@@ -528,15 +584,15 @@ describe 'select input' do
|
|
|
528
584
|
end
|
|
529
585
|
|
|
530
586
|
it 'should index the id of the wrapper' do
|
|
531
|
-
output_buffer.
|
|
587
|
+
expect(output_buffer).to have_tag("li#post_author_attributes_3_name_input")
|
|
532
588
|
end
|
|
533
589
|
|
|
534
590
|
it 'should index the id of the select tag' do
|
|
535
|
-
output_buffer.
|
|
591
|
+
expect(output_buffer).to have_tag("select#post_author_attributes_3_name")
|
|
536
592
|
end
|
|
537
593
|
|
|
538
594
|
it 'should index the name of the select' do
|
|
539
|
-
output_buffer.
|
|
595
|
+
expect(output_buffer).to have_tag("select[@name='post[author_attributes][3][name]']")
|
|
540
596
|
end
|
|
541
597
|
|
|
542
598
|
end
|
|
@@ -547,7 +603,7 @@ describe 'select input' do
|
|
|
547
603
|
concat(semantic_form_for(@new_post) do |builder|
|
|
548
604
|
concat(builder.input(:author, :as => :select, :required => true))
|
|
549
605
|
end)
|
|
550
|
-
output_buffer.
|
|
606
|
+
expect(output_buffer).to have_tag("select[@required]")
|
|
551
607
|
end
|
|
552
608
|
end
|
|
553
609
|
end
|