From f5be6c7679207ee2669705455bb6d5cd7c512802 Mon Sep 17 00:00:00 2001 From: Sam Lown Date: Mon, 6 Jun 2011 01:53:36 +0200 Subject: [PATCH] Fixing problem with reloading models and dirty tracking --- lib/couchrest/model/persistence.rb | 2 +- spec/couchrest/dirty_spec.rb | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/couchrest/model/persistence.rb b/lib/couchrest/model/persistence.rb index 885f726..c63b8f4 100644 --- a/lib/couchrest/model/persistence.rb +++ b/lib/couchrest/model/persistence.rb @@ -87,7 +87,7 @@ module CouchRest # # Returns self. def reload - merge!(self.class.get(id)) + prepare_all_attributes(database.get(id), :directly_set_attributes => true) self end diff --git a/spec/couchrest/dirty_spec.rb b/spec/couchrest/dirty_spec.rb index 12c4f18..8cbd7be 100644 --- a/spec/couchrest/dirty_spec.rb +++ b/spec/couchrest/dirty_spec.rb @@ -241,6 +241,14 @@ describe "Dirty" do end end + it "should report changes if an array is popped after reload" do + should_change_array do |array, obj| + obj.reload + obj.keywords.pop + end + end + + it "should report no changes if an empty array is popped" do should_not_change_array do |array, obj| array.clear