Permalink
Browse files

Add a #new_record? method for ActiveModel compliance.

  • Loading branch information...
1 parent ae6921c commit eb304554dcc3b12aaf7342ef4b64999327381b6a @elliotcm committed Mar 27, 2010
Showing with 30 additions and 0 deletions.
  1. +4 −0 lib/document/active_model_compliance.rb
  2. +26 −0 spec/document/active_model_compliance_spec.rb
@@ -6,6 +6,10 @@ module ActiveModelCompliance
def valid?
true
end
+
+ def new_record?
+ @_id.nil?
+ end
end
end
@@ -20,4 +20,30 @@ class ActiveModelComplianceTest
@model.valid?.should be_true
end
end
+
+ describe "#new_record?" do
+ it "responds to #new_record?" do
+ @model.should respond_to(:new_record?)
+ end
+
+ context "when the object has an id" do
+ before(:each) do
+ @model.instance_variable_set(:@_id, mock(:id))
+ end
+
+ it "is false" do
+ @model.new_record?.should be_false
+ end
+ end
+
+ context "when the object has no id" do
+ before(:each) do
+ @model.instance_variable_set(:@_id, nil)
+ end
+
+ it "is true" do
+ @model.new_record?.should be_true
+ end
+ end
+ end
end

0 comments on commit eb30455

Please sign in to comment.