public
Rubygem
Description: RSpec extension library for Ruby on Rails
Homepage:
Clone URL: git://github.com/dchelimsky/rspec-rails.git
Added mock_model#as_new_record functionality
zdennis (author)
Thu Aug 07 08:03:55 -0700 2008
David Chelimsky (committer)
Mon Aug 11 04:37:59 -0700 2008
commit  3c59e0c75e1eaf6660a14654a56e1a419f5c5c85
tree    75917c760669fedc56b73b3cba72f5b53d56c316
parent  7a9d2ce1b3c1f1ac314433f925a46b7bbfa05851
...
18
19
20
 
 
 
 
 
 
21
22
23
...
18
19
20
21
22
23
24
25
26
27
28
29
0
@@ -18,6 +18,12 @@ module Spec
0
         })
0
         m = mock("#{model_class.name}_#{id}", options_and_stubs)
0
         m.send(:__mock_proxy).instance_eval <<-CODE
0
+          def @target.as_new_record
0
+            self.stub!(:id).and_return nil
0
+            self.stub!(:to_param).and_return nil
0
+            self.stub!(:new_record?).and_return true
0
+            self
0
+          end
0
           def @target.is_a?(other)
0
             #{model_class}.ancestors.include?(other)
0
           end
...
65
66
67
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
...
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
0
@@ -65,3 +65,18 @@ describe "mock_model as association", :type => :view do
0
       @real.mockable_model.should == @mock_model
0
   end
0
 end
0
+
0
+describe "mock_model #as_new_record" do
0
+  it "should say it is a new record" do
0
+    mock_model(MockableModel).as_new_record.should be_new_record
0
+  end
0
+
0
+  it "should have a nil id" do
0
+    mock_model(MockableModel).as_new_record.id.should be(nil)
0
+  end
0
+
0
+  it "should have a nil to_param" do
0
+    mock_model(MockableModel).as_new_record.to_param.should be(nil)
0
+  end
0
+end
0
+

Comments