public
Rubygem
Description: RSpec extension library for Ruby on Rails
Homepage:
Clone URL: git://github.com/dchelimsky/rspec-rails.git
fix to_param in mock_model with stubbed id incorrectly returning autogenerated 
id
adzap (author)
Tue Jun 24 16:19:54 -0700 2008
pat-maddox (committer)
Sat Jul 12 21:33:14 -0700 2008
commit  9a1e10e7b71f7e8e4fb910a9695ee69abec63816
tree    70bf8a8f9d219ad7882054583359003c51d68536
parent  47350fb4eeabca0cfafc98ca1776772d5dbf240d
...
9
10
11
12
 
13
14
15
16
17
18
19
 
20
21
22
...
123
124
125
126
127
 
...
9
10
11
 
12
13
14
15
16
17
18
 
19
20
21
22
...
123
124
125
 
126
127
0
@@ -9,14 +9,14 @@ module Spec
0
       # methods stubbed out. Additional methods may be easily stubbed (via
0
       # add_stubs) if +stubs+ is passed.
0
       def mock_model(model_class, options_and_stubs = {})
0
-        id = next_id
0
+        id = options_and_stubs[:id] || next_id
0
         options_and_stubs.reverse_merge!({
0
           :id => id,
0
           :to_param => id.to_s,
0
           :new_record? => false,
0
           :errors => stub("errors", :count => 0)
0
         })
0
-        m = mock("#{model_class.name}_#{options_and_stubs[:id]}", options_and_stubs)
0
+        m = mock("#{model_class.name}_#{id}", options_and_stubs)
0
         m.send(:__mock_proxy).instance_eval <<-CODE
0
           def @target.is_a?(other)
0
             #{model_class}.ancestors.include?(other)
0
@@ -123,4 +123,4 @@ module Spec
0
 
0
     end
0
   end
0
-end
0
\ No newline at end of file
0
+end
...
32
33
34
 
 
 
35
36
37
...
32
33
34
35
36
37
38
39
40
0
@@ -32,6 +32,9 @@ describe "mock_model with stubbed id", :type => :view do
0
   it "should be named using the stubbed id value" do
0
     @model.instance_variable_get(:@name).should == "MockableModel_1"
0
   end
0
+  it "should return string of id value for to_param" do
0
+    @model.to_param.should == "1"
0
+  end
0
 end
0
 
0
 describe "mock_model with null_object", :type => :view do

Comments