Browse files

Mock models should not be blank?.

  • Loading branch information...
1 parent 3b279c6 commit d33a28e4eb578c179d441e0dcba248e5c69f8b0c @r38y r38y committed with dchelimsky Feb 3, 2011
View
2 lib/rspec/rails/mocks.rb
@@ -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
@@ -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
View
6 spec/rspec/rails/mocks/mock_model_spec.rb
@@ -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'
View
5 spec/rspec/rails/mocks/stub_model_spec.rb
@@ -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

0 comments on commit d33a28e

Please sign in to comment.