Skip to content

Commit

Permalink
when mock_model receives destroy, set its id to nil
Browse files Browse the repository at this point in the history
  • Loading branch information
dchelimsky committed Jun 27, 2010
1 parent 37f5357 commit eeb357e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/rspec/rails/mocks.rb
Expand Up @@ -22,6 +22,10 @@ def new_record?
def persisted?
!!id
end

def destroy
self.stub(:id) { nil }
end
end

# Creates a mock object instance for a +model_class+ with common
Expand Down
8 changes: 8 additions & 0 deletions spec/rspec/rails/mocks/mock_model_spec.rb
Expand Up @@ -14,6 +14,14 @@
end
end

describe "destroy" do
it "sets id to nil" do
model = mock_model(MockableModel)
model.destroy
model.id.should be_nil
end
end

describe "with params" do
it "does not mutate its parameters" do
params = {:a => 'b'}
Expand Down

0 comments on commit eeb357e

Please sign in to comment.