Permalink
Browse files

fix dirty tracking of belongs_to attributes

  • Loading branch information...
1 parent a99ce45 commit 568eb6d132c5b7c3bed3c99ddb23c00544333f11 @jweiss jweiss committed Sep 12, 2011
Showing with 43 additions and 4 deletions.
  1. +1 −1 lib/simply_stored.rb
  2. +1 −1 lib/simply_stored/couch/belongs_to.rb
  3. +2 −2 simply_stored.gemspec
  4. +39 −0 test/dirty_tracking_test.rb
View
@@ -5,7 +5,7 @@
require File.expand_path(File.dirname(__FILE__) + '/simply_stored/class_methods_base')
module SimplyStored
- VERSION = '0.7.0rc5'
+ VERSION = '0.7.0rc6'
class Error < RuntimeError; end
class RecordNotFound < RuntimeError; end
end
@@ -86,7 +86,7 @@ def initialize(owner_clazz, name, options = {})
end
define_method "#{name}_changed?" do
- self.send("#{name}_id") != self.send("#{name}_id_was")
+ self.send("#{name}_id_changed?")
end
end
end
View
@@ -5,11 +5,11 @@
Gem::Specification.new do |s|
s.name = "simply_stored"
- s.version = "0.7.0rc5"
+ s.version = "0.7.0rc6"
s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
s.authors = ["Mathias Meyer, Jonathan Weiss"]
- s.date = "2011-09-08"
+ s.date = "2011-09-12"
s.description = "Convenience layer for CouchDB on top of CouchPotato."
s.email = "info@peritor.com"
s.extra_rdoc_files = [
@@ -0,0 +1,39 @@
+require File.expand_path(File.dirname(__FILE__) + '/test_helper')
+require File.expand_path(File.dirname(__FILE__) + '/fixtures/couch')
+
+class DirtyTrackingTest < Test::Unit::TestCase
+ context "when using dirty tracking" do
+ setup do
+ CouchPotato::Config.database_name = 'simply_stored_test'
+ recreate_db
+ end
+
+ should "track normal properties" do
+ u = User.create!(:title => 'Dr.', :name => 'Bert')
+ u.name = 'Alf'
+ assert u.name_changed?
+ assert_equal 'Bert', u.name_was
+ assert u.changed?
+ end
+
+ should "track belongs_to properties" do
+ user1 = User.create!(:title => 'Dr.', :name => 'Bert')
+ user2 = User.create!(:title => 'Prof.', :name => 'Jackson')
+ post = Post.create!(:user => user1)
+ post.user = user2
+ assert post.user_changed?
+ assert post.user_id_changed?
+ assert_equal user1.id, post.user_id_was
+ assert post.changed?
+ end
+
+ should "set foreign key properties on load" do
+ user = User.create!(:title => 'Dr.', :name => 'Bert')
+ post = Post.create!(:user => user)
+ post = Post.find(post.id)
+ assert !post.user_changed?, post.user_id_was.inspect
+ assert !post.user_id_changed?
+ assert !post.changed?
+ end
+ end
+end

0 comments on commit 568eb6d

Please sign in to comment.