System notice: In light of the Debian OpenSSL security issue we've regenerated the server keys. See this thread for instructions and the new key fingerprints.

Commit 09bed09fbdcafffcb0fb46403c2746d2ae8f6cdf

Added as_new_record to stub_model e.g. stub_model(Foo).as_new_record

Commit diff

rspec/CHANGES

 
55used it, and they will now break. Just replace the metaclass call with (class << self; self; end)
66and all will be well.
77
8* Added as_new_record to stub_model e.g. stub_model(Foo).as_new_record
89* Improved stub_model such that new_record? does "the right thing"
910* Patch from Pat Maddox to get integrate_views to work in nested example groups.
1011* Patch from Pat Maddox to get controller_name to work in nested example groups.
toggle raw diff

rspec_on_rails/lib/spec/rails/example/rails_example_group.rb

 
9090 def new_record?
9191 id.nil?
9292 end
93 def as_new_record
94 self.id = nil
95 self
96 end
9397 end
9498 stubs.each do |k,v|
9599 if model.has_attribute?(k)
toggle raw diff

rspec_on_rails/spec/rails/mocks/stub_model_spec.rb

 
22require File.dirname(__FILE__) + '/ar_classes'
33
44describe "stub_model" do
5 it "should have an id starting at 1000" do
6 stub_model(MockableModel).id.should be >= 1000
7 end
5 describe "defaults" do
6 it "should have an id" do
7 stub_model(MockableModel).id.should be > 0
8 end
89
9 it "should say it is not a new record by default" do
10 stub_model(MockableModel).should_not be_new_record
10 it "should say it is not a new record" do
11 stub_model(MockableModel).should_not be_new_record
12 end
1113 end
1214
1315 it "should accept a stub id" do
2020 stub_model(MockableModel, :id => nil).should be_new_record
2121 end
2222
23 it "should accept a stub anything" do
23 it "should accept any arbitrary stub" do
2424 stub_model(MockableModel, :foo => "bar").foo.should == "bar"
2525 end
2626
2828 stub_model(MockableModel, :save => false).save.should be(false)
2929 end
3030
31 describe "#as_new_record" do
32 it "should say it is a new record" do
33 stub_model(MockableModel).as_new_record.should be_new_record
34 end
35
36 it "should have a nil id" do
37 stub_model(MockableModel).as_new_record.id.should be(nil)
38 end
39 end
40
3141 it "should raise when hitting the db" do
3242 lambda do
3343 stub_model(MockableModel).save
5252
5353end
5454
55describe "stub_model as association", :type => :view do
55describe "stub_model as association" do
5656 before(:each) do
5757 @real = AssociatedModel.create!
5858 @stub_model = stub_model(MockableModel)
6868 end
6969end
7070
71describe "stub_model with a block", :type => :view do
72 it "should yield the stub" do
73 model = stub_model(MockableModel) do |model|
74 model.stub!(:foo).and_return(:bar)
71describe "stub_model with a block" do
72 it "should yield the model" do
73 model = stub_model(MockableModel) do |block_arg|
74 @block_arg = block_arg
7575 end
76 model.foo.should == :bar
76 model.should be(@block_arg)
7777 end
7878end
toggle raw diff