Skip to content

Commit

Permalink
Mock models should not be blank?.
Browse files Browse the repository at this point in the history
  • Loading branch information
r38y authored and dchelimsky committed Feb 5, 2011
1 parent 3b279c6 commit d33a28e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/rspec/rails/mocks.rb
Expand Up @@ -81,6 +81,7 @@ def mock_model(string_or_model_class, stubs = {})
stubs = stubs.reverse_merge(:persisted? => !!stubs[:id])
stubs = stubs.reverse_merge(:destroyed? => false)
stubs = stubs.reverse_merge(:marked_for_destruction? => false)
stubs = stubs.reverse_merge(:blank? => false)

mock("#{model_class.name}_#{stubs[:id]}", stubs).tap do |m|
m.extend ActiveModelInstanceMethods
Expand Down Expand Up @@ -192,6 +193,7 @@ def stub_model(model_class, stubs={})
stubs = stubs.reverse_merge(:id => next_id)
stubs = stubs.reverse_merge(:persisted? => !!stubs[:id])
end
stubs = stubs.reverse_merge(:blank? => false)
stubs.each do |k,v|
m.__send__("#{k}=", stubs.delete(k)) if m.respond_to?("#{k}=")
end
Expand Down
6 changes: 6 additions & 0 deletions spec/rspec/rails/mocks/mock_model_spec.rb
Expand Up @@ -260,6 +260,12 @@
end
end

describe "#blank?" do
it "is false" do
mock_model(MockableModel).should_not be_blank
end
end

describe "ActiveModel Lint tests" do
require 'test/unit/assertions'
require 'active_model/lint'
Expand Down
5 changes: 5 additions & 0 deletions spec/rspec/rails/mocks/stub_model_spec.rb
Expand Up @@ -35,6 +35,11 @@
second.to_param.to_i.should == (first.to_param.to_i + 1)
end

describe "#blank?" do
it "is false" do
stub_model(model_class).should_not be_blank
end
end
end

context "with ActiveModel (not ActiveRecord)" do
Expand Down

0 comments on commit d33a28e

Please sign in to comment.