formtastic 2.3.0.rc2 → 2.3.0.rc3
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.
- data/.travis.yml +27 -1
- data/Appraisals +5 -0
- data/CHANGELOG +1 -0
- data/README.textile +19 -26
- data/formtastic.gemspec +4 -3
- data/gemfiles/rails_3.0.gemfile +1 -1
- data/gemfiles/rails_3.1.gemfile +1 -1
- data/gemfiles/rails_3.2.gemfile +1 -1
- data/gemfiles/rails_4.0.4.gemfile +7 -0
- data/gemfiles/rails_4.gemfile +1 -1
- data/lib/formtastic/form_builder.rb +9 -1
- data/lib/formtastic/helpers/form_helper.rb +11 -6
- data/lib/formtastic/helpers/inputs_helper.rb +6 -1
- data/lib/formtastic/inputs/base/collections.rb +1 -1
- data/lib/formtastic/inputs/base/validations.rb +1 -1
- data/lib/formtastic/inputs/boolean_input.rb +4 -14
- data/lib/formtastic/inputs/check_boxes_input.rb +7 -1
- data/lib/formtastic/inputs/radio_input.rb +2 -0
- data/lib/formtastic/util.rb +13 -1
- data/lib/formtastic/version.rb +1 -1
- data/lib/generators/templates/_form.html.slim +2 -2
- data/lib/generators/templates/formtastic.rb +15 -1
- data/spec/actions/generic_action_spec.rb +3 -3
- data/spec/builder/custom_builder_spec.rb +7 -7
- data/spec/builder/semantic_fields_for_spec.rb +8 -8
- data/spec/generators/formtastic/form/form_generator_spec.rb +6 -6
- data/spec/helpers/action_helper_spec.rb +11 -11
- data/spec/helpers/form_helper_spec.rb +22 -11
- data/spec/helpers/input_helper_spec.rb +44 -44
- data/spec/helpers/inputs_helper_spec.rb +64 -31
- data/spec/helpers/semantic_errors_helper_spec.rb +12 -12
- data/spec/i18n_spec.rb +5 -5
- data/spec/inputs/boolean_input_spec.rb +6 -5
- data/spec/inputs/check_boxes_input_spec.rb +27 -9
- data/spec/inputs/country_input_spec.rb +5 -5
- data/spec/inputs/custom_input_spec.rb +1 -1
- data/spec/inputs/date_picker_input_spec.rb +4 -4
- data/spec/inputs/datetime_picker_input_spec.rb +4 -4
- data/spec/inputs/hidden_input_spec.rb +3 -3
- data/spec/inputs/include_blank_spec.rb +2 -2
- data/spec/inputs/number_input_spec.rb +36 -36
- data/spec/inputs/radio_input_spec.rb +23 -5
- data/spec/inputs/range_input_spec.rb +19 -19
- data/spec/inputs/select_input_spec.rb +40 -20
- data/spec/inputs/string_input_spec.rb +2 -2
- data/spec/inputs/time_picker_input_spec.rb +4 -4
- data/spec/localizer_spec.rb +1 -1
- data/spec/spec_helper.rb +203 -188
- data/spec/support/custom_macros.rb +8 -8
- metadata +15 -13
@@ -73,7 +73,7 @@ describe 'range input' do
|
|
73
73
|
|
74
74
|
describe "when validations require a minimum value (:greater_than)" do
|
75
75
|
before do
|
76
|
-
@new_post.class.stub
|
76
|
+
@new_post.class.stub(:validators_on).with(:title).and_return([
|
77
77
|
active_model_numericality_validator([:title], {:only_integer=>false, :allow_nil=>false, :greater_than=>2})
|
78
78
|
])
|
79
79
|
end
|
@@ -108,7 +108,7 @@ describe 'range input' do
|
|
108
108
|
|
109
109
|
describe "and the column is an integer" do
|
110
110
|
before do
|
111
|
-
@new_post.stub
|
111
|
+
@new_post.stub(:column_for_attribute).with(:title).and_return(double('column', :type => :integer))
|
112
112
|
end
|
113
113
|
|
114
114
|
it "should add a min attribute to the input one greater than the validation" do
|
@@ -121,7 +121,7 @@ describe 'range input' do
|
|
121
121
|
|
122
122
|
describe "and the column is a float" do
|
123
123
|
before do
|
124
|
-
@new_post.stub
|
124
|
+
@new_post.stub(:column_for_attribute).with(:title).and_return(double('column', :type => :float))
|
125
125
|
end
|
126
126
|
|
127
127
|
it "should raise an error" do
|
@@ -135,7 +135,7 @@ describe 'range input' do
|
|
135
135
|
|
136
136
|
describe "and the column is a big decimal" do
|
137
137
|
before do
|
138
|
-
@new_post.stub
|
138
|
+
@new_post.stub(:column_for_attribute).with(:title).and_return(double('column', :type => :decimal))
|
139
139
|
end
|
140
140
|
|
141
141
|
it "should raise an error" do
|
@@ -151,7 +151,7 @@ describe 'range input' do
|
|
151
151
|
|
152
152
|
describe "when validations require a minimum value (:greater_than_or_equal_to)" do
|
153
153
|
before do
|
154
|
-
@new_post.class.stub
|
154
|
+
@new_post.class.stub(:validators_on).with(:title).and_return([
|
155
155
|
active_model_numericality_validator([:title], {:only_integer=>false, :allow_nil=>false, :greater_than_or_equal_to=>2})
|
156
156
|
])
|
157
157
|
end
|
@@ -188,7 +188,7 @@ describe 'range input' do
|
|
188
188
|
[:integer, :decimal, :float].each do |column_type|
|
189
189
|
describe "and the column is a #{column_type}" do
|
190
190
|
before do
|
191
|
-
@new_post.stub
|
191
|
+
@new_post.stub(:column_for_attribute).with(:title).and_return(double('column', :type => column_type))
|
192
192
|
end
|
193
193
|
|
194
194
|
it "should add a max attribute to the input equal to the validation" do
|
@@ -202,7 +202,7 @@ describe 'range input' do
|
|
202
202
|
|
203
203
|
describe "and there is no column" do
|
204
204
|
before do
|
205
|
-
@new_post.stub
|
205
|
+
@new_post.stub(:column_for_attribute).with(:title).and_return(nil)
|
206
206
|
end
|
207
207
|
|
208
208
|
it "should add a max attribute to the input equal to the validation" do
|
@@ -227,7 +227,7 @@ describe 'range input' do
|
|
227
227
|
|
228
228
|
describe "when validations require a maximum value (:less_than)" do
|
229
229
|
before do
|
230
|
-
@new_post.class.stub
|
230
|
+
@new_post.class.stub(:validators_on).with(:title).and_return([
|
231
231
|
active_model_numericality_validator([:title], {:only_integer=>false, :allow_nil=>false, :less_than=>20})
|
232
232
|
])
|
233
233
|
end
|
@@ -262,7 +262,7 @@ describe 'range input' do
|
|
262
262
|
|
263
263
|
describe "and the column is an integer" do
|
264
264
|
before do
|
265
|
-
@new_post.stub
|
265
|
+
@new_post.stub(:column_for_attribute).with(:title).and_return(double('column', :type => :integer))
|
266
266
|
end
|
267
267
|
|
268
268
|
it "should add a max attribute to the input one greater than the validation" do
|
@@ -275,7 +275,7 @@ describe 'range input' do
|
|
275
275
|
|
276
276
|
describe "and the column is a float" do
|
277
277
|
before do
|
278
|
-
@new_post.stub
|
278
|
+
@new_post.stub(:column_for_attribute).with(:title).and_return(double('column', :type => :float))
|
279
279
|
end
|
280
280
|
|
281
281
|
it "should raise an error" do
|
@@ -289,7 +289,7 @@ describe 'range input' do
|
|
289
289
|
|
290
290
|
describe "and the column is a big decimal" do
|
291
291
|
before do
|
292
|
-
@new_post.stub
|
292
|
+
@new_post.stub(:column_for_attribute).with(:title).and_return(double('column', :type => :decimal))
|
293
293
|
end
|
294
294
|
|
295
295
|
it "should raise an error" do
|
@@ -305,7 +305,7 @@ describe 'range input' do
|
|
305
305
|
|
306
306
|
describe "when validations require a maximum value (:less_than_or_equal_to)" do
|
307
307
|
before do
|
308
|
-
@new_post.class.stub
|
308
|
+
@new_post.class.stub(:validators_on).with(:title).and_return([
|
309
309
|
active_model_numericality_validator([:title], {:only_integer=>false, :allow_nil=>false, :less_than_or_equal_to=>20})
|
310
310
|
])
|
311
311
|
end
|
@@ -341,7 +341,7 @@ describe 'range input' do
|
|
341
341
|
[:integer, :decimal, :float].each do |column_type|
|
342
342
|
describe "and the column is a #{column_type}" do
|
343
343
|
before do
|
344
|
-
@new_post.stub
|
344
|
+
@new_post.stub(:column_for_attribute).with(:title).and_return(double('column', :type => column_type))
|
345
345
|
end
|
346
346
|
|
347
347
|
it "should add a max attribute to the input equal to the validation" do
|
@@ -355,7 +355,7 @@ describe 'range input' do
|
|
355
355
|
|
356
356
|
describe "and there is no column" do
|
357
357
|
before do
|
358
|
-
@new_post.stub
|
358
|
+
@new_post.stub(:column_for_attribute).with(:title).and_return(nil)
|
359
359
|
end
|
360
360
|
|
361
361
|
it "should add a max attribute to the input equal to the validation" do
|
@@ -380,7 +380,7 @@ describe 'range input' do
|
|
380
380
|
|
381
381
|
describe "when validations require conflicting minimum values (:greater_than, :greater_than_or_equal_to)" do
|
382
382
|
before do
|
383
|
-
@new_post.class.stub
|
383
|
+
@new_post.class.stub(:validators_on).with(:title).and_return([
|
384
384
|
active_model_numericality_validator([:title], {:only_integer=>false, :allow_nil=>false, :greater_than => 20, :greater_than_or_equal_to=>2})
|
385
385
|
])
|
386
386
|
end
|
@@ -395,7 +395,7 @@ describe 'range input' do
|
|
395
395
|
|
396
396
|
describe "when validations require conflicting maximum values (:less_than, :less_than_or_equal_to)" do
|
397
397
|
before do
|
398
|
-
@new_post.class.stub
|
398
|
+
@new_post.class.stub(:validators_on).with(:title).and_return([
|
399
399
|
active_model_numericality_validator([:title], {:only_integer=>false, :allow_nil=>false, :less_than => 20, :less_than_or_equal_to=>2})
|
400
400
|
])
|
401
401
|
end
|
@@ -411,7 +411,7 @@ describe 'range input' do
|
|
411
411
|
describe "when validations require only an integer (:only_integer)" do
|
412
412
|
|
413
413
|
before do
|
414
|
-
@new_post.class.stub
|
414
|
+
@new_post.class.stub(:validators_on).with(:title).and_return([
|
415
415
|
active_model_numericality_validator([:title], {:allow_nil=>false, :only_integer=>true})
|
416
416
|
])
|
417
417
|
end
|
@@ -442,7 +442,7 @@ describe 'range input' do
|
|
442
442
|
describe "when validations require a :step (non standard)" do
|
443
443
|
|
444
444
|
before do
|
445
|
-
@new_post.class.stub
|
445
|
+
@new_post.class.stub(:validators_on).with(:title).and_return([
|
446
446
|
active_model_numericality_validator([:title], {:allow_nil=>false, :only_integer=>true, :step=>2})
|
447
447
|
])
|
448
448
|
end
|
@@ -473,7 +473,7 @@ describe 'range input' do
|
|
473
473
|
describe "when validations do not specify :step (non standard) or :only_integer" do
|
474
474
|
|
475
475
|
before do
|
476
|
-
@new_post.class.stub
|
476
|
+
@new_post.class.stub(:validators_on).with(:title).and_return([
|
477
477
|
active_model_numericality_validator([:title], {:allow_nil=>false})
|
478
478
|
])
|
479
479
|
end
|
@@ -30,10 +30,30 @@ describe 'select input' do
|
|
30
30
|
end
|
31
31
|
end
|
32
32
|
end
|
33
|
+
|
34
|
+
describe 'using a set of values' do
|
35
|
+
before do
|
36
|
+
@set_with_values = Set.new(["Title A", "Title B", "Title C"])
|
37
|
+
@set_with_keys_and_values = [["Title D", :d], ["Title E", :e], ["Title F", :f]]
|
38
|
+
concat(semantic_form_for(@new_post) do |builder|
|
39
|
+
concat(builder.input(:title, :as => :select, :collection => @set_with_values))
|
40
|
+
concat(builder.input(:title, :as => :select, :collection => @set_with_keys_and_values))
|
41
|
+
end)
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'should have a option for each key and/or value' do
|
45
|
+
@set_with_values.each do |v|
|
46
|
+
output_buffer.should have_tag("form li select option[@value='#{v}']", /^#{v}$/)
|
47
|
+
end
|
48
|
+
@set_with_keys_and_values.each do |v|
|
49
|
+
output_buffer.should have_tag("form li select option[@value='#{v.second}']", /^#{v.first}$/)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
33
53
|
|
34
54
|
describe "using a related model without reflection's options (Mongoid Document)" do
|
35
55
|
before do
|
36
|
-
@new_post.stub
|
56
|
+
@new_post.stub(:mongoid_reviewer)
|
37
57
|
concat(semantic_form_for(@new_post) do |builder|
|
38
58
|
concat(builder.input(:mongoid_reviewer, :as => :select))
|
39
59
|
end)
|
@@ -188,9 +208,9 @@ describe 'select input' do
|
|
188
208
|
end
|
189
209
|
|
190
210
|
it 'should not singularize the association name' do
|
191
|
-
@new_post.stub
|
192
|
-
@new_post.stub
|
193
|
-
@new_post.stub
|
211
|
+
@new_post.stub(:author_status).and_return(@bob)
|
212
|
+
@new_post.stub(:author_status_id).and_return(@bob.id)
|
213
|
+
@new_post.stub(:column_for_attribute).and_return(double('column', :type => :integer, :limit => 255))
|
194
214
|
|
195
215
|
concat(semantic_form_for(@new_post) do |builder|
|
196
216
|
concat(builder.input(:author_status, :as => :select))
|
@@ -202,9 +222,9 @@ describe 'select input' do
|
|
202
222
|
|
203
223
|
describe "for a belongs_to association with :group_by => :author" do
|
204
224
|
it "should call author.posts" do
|
205
|
-
::Author.stub
|
225
|
+
::Author.stub(:reflect_on_all_associations).and_return { |macro| macro == :has_many ? [double('reflection', :klass => Post, :name => :posts)] : []}
|
206
226
|
|
207
|
-
[@freds_post].each { |post| post.stub
|
227
|
+
[@freds_post].each { |post| post.stub(:to_label).and_return("Post - #{post.id}") }
|
208
228
|
@fred.should_receive(:posts)
|
209
229
|
|
210
230
|
with_deprecation_silenced do
|
@@ -217,9 +237,9 @@ describe 'select input' do
|
|
217
237
|
|
218
238
|
describe "for a belongs_to association with :conditions" do
|
219
239
|
before do
|
220
|
-
::Post.stub
|
221
|
-
mock =
|
222
|
-
mock.stub
|
240
|
+
::Post.stub(:reflect_on_association).with(:author).and_return do
|
241
|
+
mock = double('reflection', :options => {:conditions => {:active => true}}, :klass => ::Author, :macro => :belongs_to)
|
242
|
+
mock.stub(:[]).with(:class_name).and_return("Author")
|
223
243
|
mock
|
224
244
|
end
|
225
245
|
end
|
@@ -241,7 +261,7 @@ describe 'select input' do
|
|
241
261
|
::Author.should_receive(:scoped).with(:conditions => {:active => true})
|
242
262
|
::Author.should_receive(:where).with({:publisher => true})
|
243
263
|
else
|
244
|
-
proxy =
|
264
|
+
proxy = double
|
245
265
|
::Author.should_receive(:where).with({:active => true}).and_return(proxy)
|
246
266
|
proxy.should_receive(:where).with({:publisher => true})
|
247
267
|
end
|
@@ -258,19 +278,19 @@ describe 'select input' do
|
|
258
278
|
describe 'for a belongs_to association with :group_by => :continent' do
|
259
279
|
before do
|
260
280
|
@authors = [@bob, @fred, @fred, @fred]
|
261
|
-
::Author.stub
|
281
|
+
::Author.stub(:find).and_return(@authors)
|
262
282
|
@continent_names = %w(Europe Africa)
|
263
|
-
@continents = (0..1).map { |i| c = ::Continent.new; c.stub
|
264
|
-
@authors[0..1].each_with_index { |author, i| author.stub
|
283
|
+
@continents = (0..1).map { |i| c = ::Continent.new; c.stub(:id).and_return(100 - i);c }
|
284
|
+
@authors[0..1].each_with_index { |author, i| author.stub(:continent).and_return(@continents[i]) }
|
265
285
|
|
266
|
-
::Continent.stub
|
267
|
-
::Continent.stub
|
268
|
-
::Author.stub
|
286
|
+
::Continent.stub(:reflect_on_all_associations).and_return { |macro| macro == :has_many ? [double('reflection', :klass => Author, :name => :authors)] : [] }
|
287
|
+
::Continent.stub(:reflect_on_association).and_return {|column_name| double('reflection', :klass => Author) if column_name == :authors}
|
288
|
+
::Author.stub(:reflect_on_association).and_return { |column_name| double('reflection', :options => {}, :klass => Continent, :macro => :belongs_to) if column_name == :continent }
|
269
289
|
|
270
290
|
|
271
291
|
@continents.each_with_index do |continent, i|
|
272
|
-
continent.stub
|
273
|
-
continent.stub
|
292
|
+
continent.stub(:to_label).and_return(@continent_names[i])
|
293
|
+
continent.stub(:authors).and_return([@authors[i]])
|
274
294
|
end
|
275
295
|
|
276
296
|
with_deprecation_silenced do
|
@@ -456,7 +476,7 @@ describe 'select input' do
|
|
456
476
|
|
457
477
|
describe 'when :prompt => "choose something" is set' do
|
458
478
|
before do
|
459
|
-
@new_post.stub
|
479
|
+
@new_post.stub(:author_id).and_return(nil)
|
460
480
|
concat(semantic_form_for(@new_post) do |builder|
|
461
481
|
concat(builder.input(:author, :as => :select, :prompt => "choose author"))
|
462
482
|
end)
|
@@ -549,7 +569,7 @@ describe 'select input' do
|
|
549
569
|
before do
|
550
570
|
@output_buffer = ''
|
551
571
|
@some_meta_descriptions = ["One", "Two", "Three"]
|
552
|
-
@new_post.stub
|
572
|
+
@new_post.stub(:meta_description).at_least(:once)
|
553
573
|
end
|
554
574
|
|
555
575
|
describe ":as is not set" do
|
@@ -44,11 +44,11 @@ describe 'string input' do
|
|
44
44
|
let(:default_maxlength) { 50 }
|
45
45
|
|
46
46
|
before do
|
47
|
-
@new_post.stub
|
47
|
+
@new_post.stub(:class).and_return(::PostModel)
|
48
48
|
end
|
49
49
|
|
50
50
|
after do
|
51
|
-
@new_post.stub
|
51
|
+
@new_post.stub(:class).and_return(::Post)
|
52
52
|
end
|
53
53
|
|
54
54
|
describe 'and validates_length_of was called for the method' do
|
@@ -122,7 +122,7 @@ describe 'time_picker input' do
|
|
122
122
|
|
123
123
|
before do
|
124
124
|
@date = Date.new(2000, 11, 11)
|
125
|
-
@new_post.stub
|
125
|
+
@new_post.stub(:publish_at).and_return(@date)
|
126
126
|
end
|
127
127
|
|
128
128
|
it "renders 00:00" do
|
@@ -149,7 +149,7 @@ describe 'time_picker input' do
|
|
149
149
|
|
150
150
|
before do
|
151
151
|
@time = Time.utc(2000,11,11,11,11,11)
|
152
|
-
@new_post.stub
|
152
|
+
@new_post.stub(:publish_at).and_return(@time)
|
153
153
|
end
|
154
154
|
|
155
155
|
it "renders the time as a HH:MM" do
|
@@ -175,7 +175,7 @@ describe 'time_picker input' do
|
|
175
175
|
context "when method returns an empty String" do
|
176
176
|
|
177
177
|
before do
|
178
|
-
@new_post.stub
|
178
|
+
@new_post.stub(:publish_at).and_return("")
|
179
179
|
end
|
180
180
|
|
181
181
|
it "will be empty" do
|
@@ -201,7 +201,7 @@ describe 'time_picker input' do
|
|
201
201
|
context "when method returns a String" do
|
202
202
|
|
203
203
|
before do
|
204
|
-
@new_post.stub
|
204
|
+
@new_post.stub(:publish_at).and_return("yeah")
|
205
205
|
end
|
206
206
|
|
207
207
|
it "will be the string" do
|
data/spec/localizer_spec.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -10,19 +10,28 @@ require 'action_dispatch'
|
|
10
10
|
require File.expand_path(File.join(File.dirname(__FILE__), '../lib/formtastic/util'))
|
11
11
|
require File.expand_path(File.join(File.dirname(__FILE__), '../lib/formtastic'))
|
12
12
|
|
13
|
+
#rspec-rails 2-14 assumes a full rails install
|
14
|
+
module Rails
|
15
|
+
module VERSION
|
16
|
+
include ActionPack::VERSION
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
13
20
|
require 'ammeter/init'
|
14
21
|
|
15
22
|
# Requires supporting files with custom matchers and macros, etc,
|
16
23
|
# in ./support/ and its subdirectories in alphabetic order.
|
17
24
|
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].sort.each {|f| require f}
|
18
25
|
|
26
|
+
I18n.enforce_available_locales = false if I18n.respond_to?(:enforce_available_locales)
|
27
|
+
|
19
28
|
module FakeHelpersModule
|
20
29
|
end
|
21
30
|
|
22
31
|
module FormtasticSpecHelper
|
23
32
|
include ActionPack
|
24
33
|
include ActionView::Context if defined?(ActionView::Context)
|
25
|
-
include ActionController::RecordIdentifier
|
34
|
+
include ActionController::RecordIdentifier if defined?(ActionController::RecordIdentifier)
|
26
35
|
include ActionView::Helpers::FormHelper
|
27
36
|
include ActionView::Helpers::FormTagHelper
|
28
37
|
include ActionView::Helpers::FormOptionsHelper
|
@@ -43,8 +52,8 @@ module FormtasticSpecHelper
|
|
43
52
|
include Formtastic::Helpers::FormHelper
|
44
53
|
|
45
54
|
def default_input_type(column_type, column_name = :generic_column_name)
|
46
|
-
@new_post.stub
|
47
|
-
@new_post.stub
|
55
|
+
@new_post.stub(column_name)
|
56
|
+
@new_post.stub(:column_for_attribute).and_return(double('column', :type => column_type)) unless column_type.nil?
|
48
57
|
|
49
58
|
semantic_form_for(@new_post) do |builder|
|
50
59
|
@default_type = builder.send(:default_input_type, column_name)
|
@@ -54,8 +63,8 @@ module FormtasticSpecHelper
|
|
54
63
|
end
|
55
64
|
|
56
65
|
def active_model_validator(kind, attributes, options = {})
|
57
|
-
validator =
|
58
|
-
validator.stub
|
66
|
+
validator = double("ActiveModel::Validations::#{kind.to_s.titlecase}Validator", :attributes => attributes, :options => options)
|
67
|
+
validator.stub(:kind).and_return(kind)
|
59
68
|
validator
|
60
69
|
end
|
61
70
|
|
@@ -201,22 +210,22 @@ module FormtasticSpecHelper
|
|
201
210
|
end
|
202
211
|
|
203
212
|
def _routes
|
204
|
-
url_helpers =
|
205
|
-
url_helpers.stub
|
206
|
-
url_helpers.stub
|
207
|
-
url_helpers.stub
|
208
|
-
url_helpers.stub
|
213
|
+
url_helpers = double('url_helpers')
|
214
|
+
url_helpers.stub(:hash_for_posts_path).and_return({})
|
215
|
+
url_helpers.stub(:hash_for_post_path).and_return({})
|
216
|
+
url_helpers.stub(:hash_for_post_models_path).and_return({})
|
217
|
+
url_helpers.stub(:hash_for_authors_path).and_return({})
|
209
218
|
|
210
|
-
|
219
|
+
double('_routes',
|
211
220
|
:url_helpers => url_helpers,
|
212
221
|
:url_for => "/mock/path"
|
213
222
|
)
|
214
223
|
end
|
215
224
|
|
216
225
|
def controller
|
217
|
-
env =
|
218
|
-
request =
|
219
|
-
|
226
|
+
env = double('env', :[] => nil)
|
227
|
+
request = double('request', :env => env)
|
228
|
+
double('controller', :controller_path= => '', :params => {}, :request => request)
|
220
229
|
end
|
221
230
|
|
222
231
|
def default_url_options
|
@@ -248,207 +257,209 @@ module FormtasticSpecHelper
|
|
248
257
|
end
|
249
258
|
|
250
259
|
@fred = ::Author.new
|
251
|
-
@fred.stub
|
252
|
-
@fred.stub
|
253
|
-
@fred.stub
|
254
|
-
@fred.stub
|
255
|
-
@fred.stub
|
256
|
-
@fred.stub
|
257
|
-
@fred.stub
|
258
|
-
@fred.stub
|
259
|
-
@fred.stub
|
260
|
-
@fred.stub
|
260
|
+
@fred.stub(:class).and_return(::Author)
|
261
|
+
@fred.stub(:to_label).and_return('Fred Smith')
|
262
|
+
@fred.stub(:login).and_return('fred_smith')
|
263
|
+
@fred.stub(:age).and_return(27)
|
264
|
+
@fred.stub(:id).and_return(37)
|
265
|
+
@fred.stub(:new_record?).and_return(false)
|
266
|
+
@fred.stub(:errors).and_return(double('errors', :[] => nil))
|
267
|
+
@fred.stub(:to_key).and_return(nil)
|
268
|
+
@fred.stub(:persisted?).and_return(nil)
|
269
|
+
@fred.stub(:name).and_return('Fred')
|
261
270
|
|
262
271
|
@bob = ::Author.new
|
263
|
-
@bob.stub
|
264
|
-
@bob.stub
|
265
|
-
@bob.stub
|
266
|
-
@bob.stub
|
267
|
-
@bob.stub
|
268
|
-
@bob.stub
|
269
|
-
@bob.stub
|
270
|
-
@bob.stub
|
271
|
-
@bob.stub
|
272
|
-
@bob.stub
|
273
|
-
@bob.stub
|
274
|
-
@bob.stub
|
272
|
+
@bob.stub(:to_label).and_return('Bob Rock')
|
273
|
+
@bob.stub(:login).and_return('bob')
|
274
|
+
@bob.stub(:age).and_return(43)
|
275
|
+
@bob.stub(:created_at)
|
276
|
+
@bob.stub(:id).and_return(42)
|
277
|
+
@bob.stub(:posts).and_return([])
|
278
|
+
@bob.stub(:post_ids).and_return([])
|
279
|
+
@bob.stub(:new_record?).and_return(false)
|
280
|
+
@bob.stub(:errors).and_return(double('errors', :[] => nil))
|
281
|
+
@bob.stub(:to_key).and_return(nil)
|
282
|
+
@bob.stub(:persisted?).and_return(nil)
|
283
|
+
@bob.stub(:name).and_return('Bob')
|
275
284
|
|
276
285
|
@james = ::Author.new
|
277
|
-
@james.stub
|
278
|
-
@james.stub
|
279
|
-
@james.stub
|
280
|
-
@james.stub
|
281
|
-
@james.stub
|
282
|
-
@james.stub
|
283
|
-
@james.stub
|
284
|
-
@james.stub
|
285
|
-
@james.stub
|
286
|
-
@james.stub
|
287
|
-
@james.stub
|
288
|
-
|
289
|
-
|
290
|
-
::Author.stub
|
291
|
-
::Author.stub
|
292
|
-
::Author.stub
|
293
|
-
::Author.stub
|
294
|
-
::Author.stub
|
295
|
-
::Author.stub
|
296
|
-
::Author.stub
|
297
|
-
::Author.stub
|
298
|
-
::Author.stub
|
299
|
-
::Author.stub
|
286
|
+
@james.stub(:to_label).and_return('James Shock')
|
287
|
+
@james.stub(:login).and_return('james')
|
288
|
+
@james.stub(:age).and_return(38)
|
289
|
+
@james.stub(:id).and_return(75)
|
290
|
+
@james.stub(:posts).and_return([])
|
291
|
+
@james.stub(:post_ids).and_return([])
|
292
|
+
@james.stub(:new_record?).and_return(false)
|
293
|
+
@james.stub(:errors).and_return(double('errors', :[] => nil))
|
294
|
+
@james.stub(:to_key).and_return(nil)
|
295
|
+
@james.stub(:persisted?).and_return(nil)
|
296
|
+
@james.stub(:name).and_return('James')
|
297
|
+
|
298
|
+
|
299
|
+
::Author.stub(:scoped).and_return(::Author)
|
300
|
+
::Author.stub(:find).and_return(author_array_or_scope)
|
301
|
+
::Author.stub(:all).and_return(author_array_or_scope)
|
302
|
+
::Author.stub(:where).and_return(author_array_or_scope)
|
303
|
+
::Author.stub(:human_attribute_name).and_return { |column_name| column_name.humanize }
|
304
|
+
::Author.stub(:human_name).and_return('::Author')
|
305
|
+
::Author.stub(:reflect_on_association).and_return { |column_name| double('reflection', :options => {}, :klass => Post, :macro => :has_many) if column_name == :posts }
|
306
|
+
::Author.stub(:content_columns).and_return([double('column', :name => 'login'), double('column', :name => 'created_at')])
|
307
|
+
::Author.stub(:to_key).and_return(nil)
|
308
|
+
::Author.stub(:persisted?).and_return(nil)
|
300
309
|
|
301
310
|
@hash_backed_author = HashBackedAuthor.new
|
302
311
|
|
303
312
|
# Sometimes we need a mock @post object and some Authors for belongs_to
|
304
|
-
@new_post =
|
305
|
-
@new_post.stub
|
306
|
-
@new_post.stub
|
307
|
-
@new_post.stub
|
308
|
-
@new_post.stub
|
309
|
-
@new_post.stub
|
310
|
-
@new_post.stub
|
311
|
-
@new_post.stub
|
312
|
-
@new_post.stub
|
313
|
-
@new_post.stub
|
314
|
-
@new_post.stub
|
315
|
-
@new_post.stub
|
316
|
-
@new_post.stub
|
317
|
-
@new_post.stub
|
318
|
-
@new_post.stub
|
319
|
-
|
320
|
-
@freds_post =
|
321
|
-
@freds_post.stub
|
322
|
-
@freds_post.stub
|
323
|
-
@freds_post.stub
|
324
|
-
@freds_post.stub
|
325
|
-
@freds_post.stub
|
326
|
-
@freds_post.stub
|
327
|
-
@freds_post.stub
|
328
|
-
@freds_post.stub
|
329
|
-
@freds_post.stub
|
330
|
-
@freds_post.stub
|
331
|
-
@freds_post.stub
|
332
|
-
@freds_post.stub
|
333
|
-
@freds_post.stub
|
334
|
-
@fred.stub
|
335
|
-
@fred.stub
|
336
|
-
|
337
|
-
::Post.stub
|
338
|
-
::Post.stub
|
339
|
-
::Post.stub
|
340
|
-
::Post.stub
|
341
|
-
::Post.stub
|
342
|
-
::Post.stub
|
343
|
-
::Post.stub
|
313
|
+
@new_post = double('post')
|
314
|
+
@new_post.stub(:class).and_return(::Post)
|
315
|
+
@new_post.stub(:id).and_return(nil)
|
316
|
+
@new_post.stub(:new_record?).and_return(true)
|
317
|
+
@new_post.stub(:errors).and_return(double('errors', :[] => nil))
|
318
|
+
@new_post.stub(:author).and_return(nil)
|
319
|
+
@new_post.stub(:author_attributes=).and_return(nil)
|
320
|
+
@new_post.stub(:authors).and_return(author_array_or_scope([@fred]))
|
321
|
+
@new_post.stub(:authors_attributes=)
|
322
|
+
@new_post.stub(:reviewer).and_return(nil)
|
323
|
+
@new_post.stub(:main_post).and_return(nil)
|
324
|
+
@new_post.stub(:sub_posts).and_return([]) #TODO should be a mock with methods for adding sub posts
|
325
|
+
@new_post.stub(:to_key).and_return(nil)
|
326
|
+
@new_post.stub(:to_model).and_return(@new_post)
|
327
|
+
@new_post.stub(:persisted?).and_return(nil)
|
328
|
+
|
329
|
+
@freds_post = double('post')
|
330
|
+
@freds_post.stub(:to_ary)
|
331
|
+
@freds_post.stub(:class).and_return(::Post)
|
332
|
+
@freds_post.stub(:to_label).and_return('Fred Smith')
|
333
|
+
@freds_post.stub(:id).and_return(19)
|
334
|
+
@freds_post.stub(:title).and_return("Hello World")
|
335
|
+
@freds_post.stub(:author).and_return(@fred)
|
336
|
+
@freds_post.stub(:author_id).and_return(@fred.id)
|
337
|
+
@freds_post.stub(:authors).and_return([@fred])
|
338
|
+
@freds_post.stub(:author_ids).and_return([@fred.id])
|
339
|
+
@freds_post.stub(:new_record?).and_return(false)
|
340
|
+
@freds_post.stub(:errors).and_return(double('errors', :[] => nil))
|
341
|
+
@freds_post.stub(:to_key).and_return(nil)
|
342
|
+
@freds_post.stub(:persisted?).and_return(nil)
|
343
|
+
@fred.stub(:posts).and_return(author_array_or_scope([@freds_post]))
|
344
|
+
@fred.stub(:post_ids).and_return([@freds_post.id])
|
345
|
+
|
346
|
+
::Post.stub(:scoped).and_return(::Post)
|
347
|
+
::Post.stub(:human_attribute_name).and_return { |column_name| column_name.humanize }
|
348
|
+
::Post.stub(:human_name).and_return('Post')
|
349
|
+
::Post.stub(:reflect_on_all_validations).and_return([])
|
350
|
+
::Post.stub(:reflect_on_validations_for).and_return([])
|
351
|
+
::Post.stub(:reflections).and_return({})
|
352
|
+
::Post.stub(:reflect_on_association).and_return do |column_name|
|
344
353
|
case column_name
|
345
354
|
when :author, :author_status
|
346
|
-
mock =
|
347
|
-
mock.stub
|
355
|
+
mock = double('reflection', :options => {}, :klass => ::Author, :macro => :belongs_to)
|
356
|
+
mock.stub(:[]).with(:class_name).and_return("Author")
|
348
357
|
mock
|
349
358
|
when :reviewer
|
350
|
-
mock =
|
351
|
-
mock.stub
|
359
|
+
mock = double('reflection', :options => {:class_name => 'Author'}, :klass => ::Author, :macro => :belongs_to)
|
360
|
+
mock.stub(:[]).with(:class_name).and_return("Author")
|
352
361
|
mock
|
353
362
|
when :authors
|
354
|
-
|
363
|
+
double('reflection', :options => {}, :klass => ::Author, :macro => :has_and_belongs_to_many)
|
355
364
|
when :sub_posts
|
356
|
-
|
365
|
+
double('reflection', :options => {}, :klass => ::Post, :macro => :has_many)
|
357
366
|
when :main_post
|
358
|
-
|
367
|
+
double('reflection', :options => {}, :klass => ::Post, :macro => :belongs_to)
|
359
368
|
when :mongoid_reviewer
|
360
369
|
::MongoidReflectionMock.new('reflection',
|
361
370
|
:options => Proc.new { raise NoMethodError, "Mongoid has no reflection.options" },
|
362
371
|
:klass => ::Author, :macro => :referenced_in, :foreign_key => "reviewer_id") # custom id
|
363
372
|
end
|
364
373
|
end
|
365
|
-
::Post.stub
|
366
|
-
::Post.stub
|
367
|
-
::Post.stub
|
368
|
-
::Post.stub
|
369
|
-
::Post.stub
|
370
|
-
::Post.stub
|
371
|
-
::Post.stub
|
372
|
-
|
373
|
-
::MongoPost.stub
|
374
|
-
::MongoPost.stub
|
375
|
-
::MongoPost.stub
|
376
|
-
:sub_posts =>
|
374
|
+
::Post.stub(:find).and_return(author_array_or_scope([@freds_post]))
|
375
|
+
::Post.stub(:all).and_return(author_array_or_scope([@freds_post]))
|
376
|
+
::Post.stub(:where).and_return(author_array_or_scope([@freds_post]))
|
377
|
+
::Post.stub(:content_columns).and_return([double('column', :name => 'title'), double('column', :name => 'body'), double('column', :name => 'created_at')])
|
378
|
+
::Post.stub(:to_key).and_return(nil)
|
379
|
+
::Post.stub(:persisted?).and_return(nil)
|
380
|
+
::Post.stub(:to_ary)
|
381
|
+
|
382
|
+
::MongoPost.stub(:human_attribute_name).and_return { |column_name| column_name.humanize }
|
383
|
+
::MongoPost.stub(:human_name).and_return('MongoPost')
|
384
|
+
::MongoPost.stub(:associations).and_return({
|
385
|
+
:sub_posts => double('reflection', :options => {:polymorphic => true}, :klass => ::MongoPost, :macro => :has_many),
|
377
386
|
:options => []
|
378
387
|
})
|
379
|
-
::MongoPost.stub
|
380
|
-
::MongoPost.stub
|
381
|
-
::MongoPost.stub
|
382
|
-
::MongoPost.stub
|
383
|
-
::MongoPost.stub
|
384
|
-
::MongoPost.stub
|
385
|
-
::MongoPost.stub
|
386
|
-
|
387
|
-
@new_mm_post =
|
388
|
-
@new_mm_post.stub
|
389
|
-
@new_mm_post.stub
|
390
|
-
@new_mm_post.stub
|
391
|
-
@new_mm_post.stub
|
392
|
-
@new_mm_post.stub
|
393
|
-
@new_mm_post.stub
|
394
|
-
@new_mm_post.stub
|
395
|
-
@new_mm_post.stub
|
396
|
-
@new_mm_post.stub
|
397
|
-
|
398
|
-
@mock_file =
|
388
|
+
::MongoPost.stub(:find).and_return(author_array_or_scope([@freds_post]))
|
389
|
+
::MongoPost.stub(:all).and_return(author_array_or_scope([@freds_post]))
|
390
|
+
::MongoPost.stub(:where).and_return(author_array_or_scope([@freds_post]))
|
391
|
+
::MongoPost.stub(:to_key).and_return(nil)
|
392
|
+
::MongoPost.stub(:persisted?).and_return(nil)
|
393
|
+
::MongoPost.stub(:to_ary)
|
394
|
+
::MongoPost.stub(:model_name).and_return( double(:model_name_mock, :singular => "post", :plural => "posts", :param_key => "post", :route_key => "posts") )
|
395
|
+
|
396
|
+
@new_mm_post = double('mm_post')
|
397
|
+
@new_mm_post.stub(:class).and_return(::MongoPost)
|
398
|
+
@new_mm_post.stub(:id).and_return(nil)
|
399
|
+
@new_mm_post.stub(:new_record?).and_return(true)
|
400
|
+
@new_mm_post.stub(:errors).and_return(double('errors', :[] => nil))
|
401
|
+
@new_mm_post.stub(:title).and_return("Hello World")
|
402
|
+
@new_mm_post.stub(:sub_posts).and_return([]) #TODO should be a mock with methods for adding sub posts
|
403
|
+
@new_mm_post.stub(:to_key).and_return(nil)
|
404
|
+
@new_mm_post.stub(:to_model).and_return(@new_mm_post)
|
405
|
+
@new_mm_post.stub(:persisted?).and_return(nil)
|
406
|
+
|
407
|
+
@mock_file = double('file')
|
399
408
|
Formtastic::FormBuilder.file_methods.each do |method|
|
400
|
-
@mock_file.stub
|
409
|
+
@mock_file.stub(method).and_return(true)
|
401
410
|
end
|
402
411
|
|
403
|
-
@new_post.stub
|
404
|
-
@new_post.stub
|
405
|
-
@new_post.stub
|
406
|
-
@new_post.stub
|
407
|
-
@new_post.stub
|
408
|
-
@new_post.stub
|
409
|
-
@new_post.stub
|
410
|
-
@new_post.stub
|
411
|
-
@new_post.stub
|
412
|
-
@new_post.stub
|
413
|
-
@new_post.stub
|
414
|
-
@new_post.stub
|
415
|
-
@new_post.stub
|
416
|
-
@new_post.stub
|
417
|
-
@new_post.stub
|
418
|
-
@new_post.stub
|
419
|
-
@new_post.stub
|
420
|
-
@new_post.stub
|
421
|
-
@new_post.stub
|
422
|
-
@new_post.stub
|
423
|
-
@new_post.stub
|
424
|
-
@new_post.stub
|
425
|
-
@new_post.stub
|
426
|
-
@new_post.stub
|
427
|
-
@new_post.stub
|
428
|
-
@new_post.stub
|
429
|
-
@new_post.stub
|
430
|
-
@new_post.stub
|
431
|
-
@new_post.stub
|
432
|
-
@new_post.stub
|
433
|
-
@new_post.stub
|
434
|
-
@new_post.stub
|
435
|
-
@new_post.stub
|
436
|
-
@new_post.stub
|
437
|
-
@new_post.stub
|
438
|
-
@new_post.stub
|
439
|
-
@new_post.stub
|
440
|
-
@new_post.stub
|
441
|
-
@new_post.stub
|
442
|
-
|
443
|
-
@new_post.stub
|
444
|
-
@new_post.stub
|
445
|
-
|
446
|
-
@new_post.stub
|
447
|
-
@new_post.stub
|
448
|
-
|
449
|
-
@new_post.should_receive(:publish_at=).
|
450
|
-
@new_post.
|
451
|
-
@new_post.
|
412
|
+
@new_post.stub(:title)
|
413
|
+
@new_post.stub(:email)
|
414
|
+
@new_post.stub(:url)
|
415
|
+
@new_post.stub(:phone)
|
416
|
+
@new_post.stub(:search)
|
417
|
+
@new_post.stub(:to_ary)
|
418
|
+
@new_post.stub(:body)
|
419
|
+
@new_post.stub(:published)
|
420
|
+
@new_post.stub(:publish_at)
|
421
|
+
@new_post.stub(:created_at)
|
422
|
+
@new_post.stub(:secret).and_return(1)
|
423
|
+
@new_post.stub(:url)
|
424
|
+
@new_post.stub(:email)
|
425
|
+
@new_post.stub(:search)
|
426
|
+
@new_post.stub(:phone)
|
427
|
+
@new_post.stub(:time_zone)
|
428
|
+
@new_post.stub(:category_name)
|
429
|
+
@new_post.stub(:allow_comments).and_return(true)
|
430
|
+
@new_post.stub(:answer_comments)
|
431
|
+
@new_post.stub(:country)
|
432
|
+
@new_post.stub(:country_subdivision)
|
433
|
+
@new_post.stub(:country_code)
|
434
|
+
@new_post.stub(:document).and_return(@mock_file)
|
435
|
+
@new_post.stub(:column_for_attribute).with(:meta_description).and_return(double('column', :type => :string, :limit => 255))
|
436
|
+
@new_post.stub(:column_for_attribute).with(:title).and_return(double('column', :type => :string, :limit => 50))
|
437
|
+
@new_post.stub(:column_for_attribute).with(:body).and_return(double('column', :type => :text))
|
438
|
+
@new_post.stub(:column_for_attribute).with(:published).and_return(double('column', :type => :boolean))
|
439
|
+
@new_post.stub(:column_for_attribute).with(:publish_at).and_return(double('column', :type => :date))
|
440
|
+
@new_post.stub(:column_for_attribute).with(:time_zone).and_return(double('column', :type => :string))
|
441
|
+
@new_post.stub(:column_for_attribute).with(:allow_comments).and_return(double('column', :type => :boolean))
|
442
|
+
@new_post.stub(:column_for_attribute).with(:author).and_return(double('column', :type => :integer))
|
443
|
+
@new_post.stub(:column_for_attribute).with(:country).and_return(double('column', :type => :string, :limit => 255))
|
444
|
+
@new_post.stub(:column_for_attribute).with(:country_subdivision).and_return(double('column', :type => :string, :limit => 255))
|
445
|
+
@new_post.stub(:column_for_attribute).with(:country_code).and_return(double('column', :type => :string, :limit => 255))
|
446
|
+
@new_post.stub(:column_for_attribute).with(:email).and_return(double('column', :type => :string, :limit => 255))
|
447
|
+
@new_post.stub(:column_for_attribute).with(:url).and_return(double('column', :type => :string, :limit => 255))
|
448
|
+
@new_post.stub(:column_for_attribute).with(:phone).and_return(double('column', :type => :string, :limit => 255))
|
449
|
+
@new_post.stub(:column_for_attribute).with(:search).and_return(double('column', :type => :string, :limit => 255))
|
450
|
+
@new_post.stub(:column_for_attribute).with(:document).and_return(nil)
|
451
|
+
|
452
|
+
@new_post.stub(:author).and_return(@bob)
|
453
|
+
@new_post.stub(:author_id).and_return(@bob.id)
|
454
|
+
|
455
|
+
@new_post.stub(:reviewer).and_return(@fred)
|
456
|
+
@new_post.stub(:reviewer_id).and_return(@fred.id)
|
457
|
+
|
458
|
+
# @new_post.should_receive(:publish_at=).at_least(:once)
|
459
|
+
@new_post.stub(:publish_at=)
|
460
|
+
# @new_post.should_receive(:title=).at_least(:once)
|
461
|
+
@new_post.stub(:title=)
|
462
|
+
@new_post.stub(:main_post_id).and_return(nil)
|
452
463
|
|
453
464
|
end
|
454
465
|
|
@@ -501,6 +512,10 @@ module FormtasticSpecHelper
|
|
501
512
|
end
|
502
513
|
end
|
503
514
|
|
515
|
+
class ::ActionView::Base
|
516
|
+
include Formtastic::Helpers::FormHelper
|
517
|
+
end
|
518
|
+
|
504
519
|
::ActiveSupport::Deprecation.silenced = false
|
505
520
|
|
506
521
|
RSpec.configure do |config|
|