spec/toy/persistence_spec.rb in toystore-0.10.1 vs spec/toy/persistence_spec.rb in toystore-0.10.2
- old
+ new
@@ -197,48 +197,106 @@
end
context "with new record" do
before do
@doc = User.new(:name => 'John', :age => 28, :accepted_terms => true)
- @doc.save
end
it "saves to key" do
+ @doc.save
User.key?(@doc.id)
end
it "does not persist virtual attributes" do
+ @doc.save
@doc.adapter.read(@doc.id).should_not include('accepted_terms')
end
+
+ it "is persisted" do
+ @doc.save
+ @doc.persisted?.should be_true
+ end
+
+ it "returns true" do
+ @doc.save.should be_true
+ end
+
+ context "with #persist overridden" do
+ before do
+ @doc.class_eval do
+ def persist
+ end
+ end
+ end
+
+ it "is persisted" do
+ @doc.save
+ @doc.persisted?.should be_true
+ end
+
+ it "returns true" do
+ @doc.save.should be_true
+ end
+ end
end
context "with existing record" do
before do
@doc = User.create(:name => 'John', :age => 28)
@key = @doc.id
@value = User.adapter.read(@doc.id)
@doc.name = 'Bill'
@doc.accepted_terms = false
- @doc.save
end
let(:doc) { @doc }
it "does not change primary key" do
+ @doc.save
doc.id.should == @key
end
it "updates value in adapter" do
+ @doc.save
User.adapter.read(doc.id).should_not == @value
end
it "does not persist virtual attributes" do
+ @doc.save
@doc.adapter.read(@doc.id).should_not include('accepted_terms')
end
it "updates the attributes in the instance" do
+ @doc.save
doc.name.should == 'Bill'
end
+
+ it "is persisted" do
+ @doc.save
+ @doc.persisted?.should be_true
+ end
+
+ it "returns true" do
+ @doc.save.should be_true
+ end
+
+ context "with #persist overridden" do
+ before do
+ @doc.class_eval do
+ def persist
+ end
+ end
+ end
+
+ it "is persisted" do
+ @doc.save
+ doc.persisted?.should be_true
+ end
+
+ it "returns true" do
+ @doc.save.should be_true
+ end
+ end
end
end
describe "#update_attributes" do
before do
@@ -294,6 +352,6 @@
user.clone.should_not be_destroyed
user.destroy
user.clone.should_not be_destroyed
end
end
-end
\ No newline at end of file
+end