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.
Files changed (50) hide show
  1. data/.travis.yml +27 -1
  2. data/Appraisals +5 -0
  3. data/CHANGELOG +1 -0
  4. data/README.textile +19 -26
  5. data/formtastic.gemspec +4 -3
  6. data/gemfiles/rails_3.0.gemfile +1 -1
  7. data/gemfiles/rails_3.1.gemfile +1 -1
  8. data/gemfiles/rails_3.2.gemfile +1 -1
  9. data/gemfiles/rails_4.0.4.gemfile +7 -0
  10. data/gemfiles/rails_4.gemfile +1 -1
  11. data/lib/formtastic/form_builder.rb +9 -1
  12. data/lib/formtastic/helpers/form_helper.rb +11 -6
  13. data/lib/formtastic/helpers/inputs_helper.rb +6 -1
  14. data/lib/formtastic/inputs/base/collections.rb +1 -1
  15. data/lib/formtastic/inputs/base/validations.rb +1 -1
  16. data/lib/formtastic/inputs/boolean_input.rb +4 -14
  17. data/lib/formtastic/inputs/check_boxes_input.rb +7 -1
  18. data/lib/formtastic/inputs/radio_input.rb +2 -0
  19. data/lib/formtastic/util.rb +13 -1
  20. data/lib/formtastic/version.rb +1 -1
  21. data/lib/generators/templates/_form.html.slim +2 -2
  22. data/lib/generators/templates/formtastic.rb +15 -1
  23. data/spec/actions/generic_action_spec.rb +3 -3
  24. data/spec/builder/custom_builder_spec.rb +7 -7
  25. data/spec/builder/semantic_fields_for_spec.rb +8 -8
  26. data/spec/generators/formtastic/form/form_generator_spec.rb +6 -6
  27. data/spec/helpers/action_helper_spec.rb +11 -11
  28. data/spec/helpers/form_helper_spec.rb +22 -11
  29. data/spec/helpers/input_helper_spec.rb +44 -44
  30. data/spec/helpers/inputs_helper_spec.rb +64 -31
  31. data/spec/helpers/semantic_errors_helper_spec.rb +12 -12
  32. data/spec/i18n_spec.rb +5 -5
  33. data/spec/inputs/boolean_input_spec.rb +6 -5
  34. data/spec/inputs/check_boxes_input_spec.rb +27 -9
  35. data/spec/inputs/country_input_spec.rb +5 -5
  36. data/spec/inputs/custom_input_spec.rb +1 -1
  37. data/spec/inputs/date_picker_input_spec.rb +4 -4
  38. data/spec/inputs/datetime_picker_input_spec.rb +4 -4
  39. data/spec/inputs/hidden_input_spec.rb +3 -3
  40. data/spec/inputs/include_blank_spec.rb +2 -2
  41. data/spec/inputs/number_input_spec.rb +36 -36
  42. data/spec/inputs/radio_input_spec.rb +23 -5
  43. data/spec/inputs/range_input_spec.rb +19 -19
  44. data/spec/inputs/select_input_spec.rb +40 -20
  45. data/spec/inputs/string_input_spec.rb +2 -2
  46. data/spec/inputs/time_picker_input_spec.rb +4 -4
  47. data/spec/localizer_spec.rb +1 -1
  48. data/spec/spec_helper.rb +203 -188
  49. data/spec/support/custom_macros.rb +8 -8
  50. 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!(:validators_on).with(:title).and_return([
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!(:column_for_attribute).with(:title).and_return(mock('column', :type => :integer))
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!(:column_for_attribute).with(:title).and_return(mock('column', :type => :float))
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!(:column_for_attribute).with(:title).and_return(mock('column', :type => :decimal))
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!(:validators_on).with(:title).and_return([
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!(:column_for_attribute).with(:title).and_return(mock('column', :type => column_type))
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!(:column_for_attribute).with(:title).and_return(nil)
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!(:validators_on).with(:title).and_return([
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!(:column_for_attribute).with(:title).and_return(mock('column', :type => :integer))
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!(:column_for_attribute).with(:title).and_return(mock('column', :type => :float))
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!(:column_for_attribute).with(:title).and_return(mock('column', :type => :decimal))
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!(:validators_on).with(:title).and_return([
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!(:column_for_attribute).with(:title).and_return(mock('column', :type => column_type))
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!(:column_for_attribute).with(:title).and_return(nil)
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!(:validators_on).with(:title).and_return([
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!(:validators_on).with(:title).and_return([
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!(:validators_on).with(:title).and_return([
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!(:validators_on).with(:title).and_return([
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!(:validators_on).with(:title).and_return([
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!(:mongoid_reviewer)
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!(:author_status).and_return(@bob)
192
- @new_post.stub!(:author_status_id).and_return(@bob.id)
193
- @new_post.stub!(:column_for_attribute).and_return(mock('column', :type => :integer, :limit => 255))
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!(:reflect_on_all_associations).and_return { |macro| macro == :has_many ? [mock('reflection', :klass => Post, :name => :posts)] : []}
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!(:to_label).and_return("Post - #{post.id}") }
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!(:reflect_on_association).with(:author).and_return do
221
- mock = mock('reflection', :options => {:conditions => {:active => true}}, :klass => ::Author, :macro => :belongs_to)
222
- mock.stub!(:[]).with(:class_name).and_return("Author")
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 = stub
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!(:find).and_return(@authors)
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!(:id).and_return(100 - i);c }
264
- @authors[0..1].each_with_index { |author, i| author.stub!(:continent).and_return(@continents[i]) }
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!(:reflect_on_all_associations).and_return { |macro| macro == :has_many ? [mock('reflection', :klass => Author, :name => :authors)] : [] }
267
- ::Continent.stub!(:reflect_on_association).and_return {|column_name| mock('reflection', :klass => Author) if column_name == :authors}
268
- ::Author.stub!(:reflect_on_association).and_return { |column_name| mock('reflection', :options => {}, :klass => Continent, :macro => :belongs_to) if column_name == :continent }
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!(:to_label).and_return(@continent_names[i])
273
- continent.stub!(:authors).and_return([@authors[i]])
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!(:author_id).and_return(nil)
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!(:meta_description).any_number_of_times
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!(:class).and_return(::PostModel)
47
+ @new_post.stub(:class).and_return(::PostModel)
48
48
  end
49
49
 
50
50
  after do
51
- @new_post.stub!(:class).and_return(::Post)
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!(:publish_at).and_return(@date)
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!(:publish_at).and_return(@time)
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!(:publish_at).and_return("")
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!(:publish_at).and_return("yeah")
204
+ @new_post.stub(:publish_at).and_return("yeah")
205
205
  end
206
206
 
207
207
  it "will be the string" do
@@ -53,7 +53,7 @@ describe 'Formtastic::Localizer' do
53
53
  end
54
54
 
55
55
  it "should be defined" do
56
- lambda { Formtastic::Localizer }.should_not raise_error(::NameError)
56
+ lambda { Formtastic::Localizer }.should_not raise_error
57
57
  end
58
58
 
59
59
  it "should have a cache" do
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!(column_name)
47
- @new_post.stub!(:column_for_attribute).and_return(mock('column', :type => column_type)) unless column_type.nil?
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 = mock("ActiveModel::Validations::#{kind.to_s.titlecase}Validator", :attributes => attributes, :options => options)
58
- validator.stub!(:kind).and_return(kind)
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 = mock('url_helpers')
205
- url_helpers.stub!(:hash_for_posts_path).and_return({})
206
- url_helpers.stub!(:hash_for_post_path).and_return({})
207
- url_helpers.stub!(:hash_for_post_models_path).and_return({})
208
- url_helpers.stub!(:hash_for_authors_path).and_return({})
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
- mock('_routes',
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 = mock('env', :[] => nil)
218
- request = mock('request', :env => env)
219
- mock('controller', :controller_path= => '', :params => {}, :request => request)
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!(:class).and_return(::Author)
252
- @fred.stub!(:to_label).and_return('Fred Smith')
253
- @fred.stub!(:login).and_return('fred_smith')
254
- @fred.stub!(:age).and_return(27)
255
- @fred.stub!(:id).and_return(37)
256
- @fred.stub!(:new_record?).and_return(false)
257
- @fred.stub!(:errors).and_return(mock('errors', :[] => nil))
258
- @fred.stub!(:to_key).and_return(nil)
259
- @fred.stub!(:persisted?).and_return(nil)
260
- @fred.stub!(:name).and_return('Fred')
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!(:to_label).and_return('Bob Rock')
264
- @bob.stub!(:login).and_return('bob')
265
- @bob.stub!(:age).and_return(43)
266
- @bob.stub!(:created_at)
267
- @bob.stub!(:id).and_return(42)
268
- @bob.stub!(:posts).and_return([])
269
- @bob.stub!(:post_ids).and_return([])
270
- @bob.stub!(:new_record?).and_return(false)
271
- @bob.stub!(:errors).and_return(mock('errors', :[] => nil))
272
- @bob.stub!(:to_key).and_return(nil)
273
- @bob.stub!(:persisted?).and_return(nil)
274
- @bob.stub!(:name).and_return('Bob')
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!(:to_label).and_return('James Shock')
278
- @james.stub!(:login).and_return('james')
279
- @james.stub!(:age).and_return(38)
280
- @james.stub!(:id).and_return(75)
281
- @james.stub!(:posts).and_return([])
282
- @james.stub!(:post_ids).and_return([])
283
- @james.stub!(:new_record?).and_return(false)
284
- @james.stub!(:errors).and_return(mock('errors', :[] => nil))
285
- @james.stub!(:to_key).and_return(nil)
286
- @james.stub!(:persisted?).and_return(nil)
287
- @james.stub!(:name).and_return('James')
288
-
289
-
290
- ::Author.stub!(:scoped).and_return(::Author)
291
- ::Author.stub!(:find).and_return(author_array_or_scope)
292
- ::Author.stub!(:all).and_return(author_array_or_scope)
293
- ::Author.stub!(:where).and_return(author_array_or_scope)
294
- ::Author.stub!(:human_attribute_name).and_return { |column_name| column_name.humanize }
295
- ::Author.stub!(:human_name).and_return('::Author')
296
- ::Author.stub!(:reflect_on_association).and_return { |column_name| mock('reflection', :options => {}, :klass => Post, :macro => :has_many) if column_name == :posts }
297
- ::Author.stub!(:content_columns).and_return([mock('column', :name => 'login'), mock('column', :name => 'created_at')])
298
- ::Author.stub!(:to_key).and_return(nil)
299
- ::Author.stub!(:persisted?).and_return(nil)
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 = mock('post')
305
- @new_post.stub!(:class).and_return(::Post)
306
- @new_post.stub!(:id).and_return(nil)
307
- @new_post.stub!(:new_record?).and_return(true)
308
- @new_post.stub!(:errors).and_return(mock('errors', :[] => nil))
309
- @new_post.stub!(:author).and_return(nil)
310
- @new_post.stub!(:author_attributes=).and_return(nil)
311
- @new_post.stub!(:authors).and_return(author_array_or_scope([@fred]))
312
- @new_post.stub!(:authors_attributes=)
313
- @new_post.stub!(:reviewer).and_return(nil)
314
- @new_post.stub!(:main_post).and_return(nil)
315
- @new_post.stub!(:sub_posts).and_return([]) #TODO should be a mock with methods for adding sub posts
316
- @new_post.stub!(:to_key).and_return(nil)
317
- @new_post.stub!(:to_model).and_return(@new_post)
318
- @new_post.stub!(:persisted?).and_return(nil)
319
-
320
- @freds_post = mock('post')
321
- @freds_post.stub!(:to_ary)
322
- @freds_post.stub!(:class).and_return(::Post)
323
- @freds_post.stub!(:to_label).and_return('Fred Smith')
324
- @freds_post.stub!(:id).and_return(19)
325
- @freds_post.stub!(:title).and_return("Hello World")
326
- @freds_post.stub!(:author).and_return(@fred)
327
- @freds_post.stub!(:author_id).and_return(@fred.id)
328
- @freds_post.stub!(:authors).and_return([@fred])
329
- @freds_post.stub!(:author_ids).and_return([@fred.id])
330
- @freds_post.stub!(:new_record?).and_return(false)
331
- @freds_post.stub!(:errors).and_return(mock('errors', :[] => nil))
332
- @freds_post.stub!(:to_key).and_return(nil)
333
- @freds_post.stub!(:persisted?).and_return(nil)
334
- @fred.stub!(:posts).and_return(author_array_or_scope([@freds_post]))
335
- @fred.stub!(:post_ids).and_return([@freds_post.id])
336
-
337
- ::Post.stub!(:scoped).and_return(::Post)
338
- ::Post.stub!(:human_attribute_name).and_return { |column_name| column_name.humanize }
339
- ::Post.stub!(:human_name).and_return('Post')
340
- ::Post.stub!(:reflect_on_all_validations).and_return([])
341
- ::Post.stub!(:reflect_on_validations_for).and_return([])
342
- ::Post.stub!(:reflections).and_return({})
343
- ::Post.stub!(:reflect_on_association).and_return do |column_name|
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 = mock('reflection', :options => {}, :klass => ::Author, :macro => :belongs_to)
347
- mock.stub!(:[]).with(:class_name).and_return("Author")
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 = mock('reflection', :options => {:class_name => 'Author'}, :klass => ::Author, :macro => :belongs_to)
351
- mock.stub!(:[]).with(:class_name).and_return("Author")
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
- mock('reflection', :options => {}, :klass => ::Author, :macro => :has_and_belongs_to_many)
363
+ double('reflection', :options => {}, :klass => ::Author, :macro => :has_and_belongs_to_many)
355
364
  when :sub_posts
356
- mock('reflection', :options => {}, :klass => ::Post, :macro => :has_many)
365
+ double('reflection', :options => {}, :klass => ::Post, :macro => :has_many)
357
366
  when :main_post
358
- mock('reflection', :options => {}, :klass => ::Post, :macro => :belongs_to)
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!(:find).and_return(author_array_or_scope([@freds_post]))
366
- ::Post.stub!(:all).and_return(author_array_or_scope([@freds_post]))
367
- ::Post.stub!(:where).and_return(author_array_or_scope([@freds_post]))
368
- ::Post.stub!(:content_columns).and_return([mock('column', :name => 'title'), mock('column', :name => 'body'), mock('column', :name => 'created_at')])
369
- ::Post.stub!(:to_key).and_return(nil)
370
- ::Post.stub!(:persisted?).and_return(nil)
371
- ::Post.stub!(:to_ary)
372
-
373
- ::MongoPost.stub!(:human_attribute_name).and_return { |column_name| column_name.humanize }
374
- ::MongoPost.stub!(:human_name).and_return('MongoPost')
375
- ::MongoPost.stub!(:associations).and_return({
376
- :sub_posts => mock('reflection', :options => {:polymorphic => true}, :klass => ::MongoPost, :macro => :has_many),
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!(:find).and_return(author_array_or_scope([@freds_post]))
380
- ::MongoPost.stub!(:all).and_return(author_array_or_scope([@freds_post]))
381
- ::MongoPost.stub!(:where).and_return(author_array_or_scope([@freds_post]))
382
- ::MongoPost.stub!(:to_key).and_return(nil)
383
- ::MongoPost.stub!(:persisted?).and_return(nil)
384
- ::MongoPost.stub!(:to_ary)
385
- ::MongoPost.stub!(:model_name).and_return( mock(:model_name_mock, :singular => "post", :plural => "posts", :param_key => "post", :route_key => "posts") )
386
-
387
- @new_mm_post = mock('mm_post')
388
- @new_mm_post.stub!(:class).and_return(::MongoPost)
389
- @new_mm_post.stub!(:id).and_return(nil)
390
- @new_mm_post.stub!(:new_record?).and_return(true)
391
- @new_mm_post.stub!(:errors).and_return(mock('errors', :[] => nil))
392
- @new_mm_post.stub!(:title).and_return("Hello World")
393
- @new_mm_post.stub!(:sub_posts).and_return([]) #TODO should be a mock with methods for adding sub posts
394
- @new_mm_post.stub!(:to_key).and_return(nil)
395
- @new_mm_post.stub!(:to_model).and_return(@new_mm_post)
396
- @new_mm_post.stub!(:persisted?).and_return(nil)
397
-
398
- @mock_file = 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!(method).and_return(true)
409
+ @mock_file.stub(method).and_return(true)
401
410
  end
402
411
 
403
- @new_post.stub!(:title)
404
- @new_post.stub!(:email)
405
- @new_post.stub!(:url)
406
- @new_post.stub!(:phone)
407
- @new_post.stub!(:search)
408
- @new_post.stub!(:to_ary)
409
- @new_post.stub!(:body)
410
- @new_post.stub!(:published)
411
- @new_post.stub!(:publish_at)
412
- @new_post.stub!(:created_at)
413
- @new_post.stub!(:secret).and_return(1)
414
- @new_post.stub!(:url)
415
- @new_post.stub!(:email)
416
- @new_post.stub!(:search)
417
- @new_post.stub!(:phone)
418
- @new_post.stub!(:time_zone)
419
- @new_post.stub!(:category_name)
420
- @new_post.stub!(:allow_comments).and_return(true)
421
- @new_post.stub!(:answer_comments)
422
- @new_post.stub!(:country)
423
- @new_post.stub!(:country_subdivision)
424
- @new_post.stub!(:country_code)
425
- @new_post.stub!(:document).and_return(@mock_file)
426
- @new_post.stub!(:column_for_attribute).with(:meta_description).and_return(mock('column', :type => :string, :limit => 255))
427
- @new_post.stub!(:column_for_attribute).with(:title).and_return(mock('column', :type => :string, :limit => 50))
428
- @new_post.stub!(:column_for_attribute).with(:body).and_return(mock('column', :type => :text))
429
- @new_post.stub!(:column_for_attribute).with(:published).and_return(mock('column', :type => :boolean))
430
- @new_post.stub!(:column_for_attribute).with(:publish_at).and_return(mock('column', :type => :date))
431
- @new_post.stub!(:column_for_attribute).with(:time_zone).and_return(mock('column', :type => :string))
432
- @new_post.stub!(:column_for_attribute).with(:allow_comments).and_return(mock('column', :type => :boolean))
433
- @new_post.stub!(:column_for_attribute).with(:author).and_return(mock('column', :type => :integer))
434
- @new_post.stub!(:column_for_attribute).with(:country).and_return(mock('column', :type => :string, :limit => 255))
435
- @new_post.stub!(:column_for_attribute).with(:country_subdivision).and_return(mock('column', :type => :string, :limit => 255))
436
- @new_post.stub!(:column_for_attribute).with(:country_code).and_return(mock('column', :type => :string, :limit => 255))
437
- @new_post.stub!(:column_for_attribute).with(:email).and_return(mock('column', :type => :string, :limit => 255))
438
- @new_post.stub!(:column_for_attribute).with(:url).and_return(mock('column', :type => :string, :limit => 255))
439
- @new_post.stub!(:column_for_attribute).with(:phone).and_return(mock('column', :type => :string, :limit => 255))
440
- @new_post.stub!(:column_for_attribute).with(:search).and_return(mock('column', :type => :string, :limit => 255))
441
- @new_post.stub!(:column_for_attribute).with(:document).and_return(nil)
442
-
443
- @new_post.stub!(:author).and_return(@bob)
444
- @new_post.stub!(:author_id).and_return(@bob.id)
445
-
446
- @new_post.stub!(:reviewer).and_return(@fred)
447
- @new_post.stub!(:reviewer_id).and_return(@fred.id)
448
-
449
- @new_post.should_receive(:publish_at=).any_number_of_times
450
- @new_post.should_receive(:title=).any_number_of_times
451
- @new_post.stub!(:main_post_id).and_return(nil)
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|