Skip to content

Commit

Permalink
fix dirty tracking of belongs_to attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
jweiss committed Sep 12, 2011
1 parent a99ce45 commit 568eb6d
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/simply_stored.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
require File.expand_path(File.dirname(__FILE__) + '/simply_stored/class_methods_base') require File.expand_path(File.dirname(__FILE__) + '/simply_stored/class_methods_base')


module SimplyStored module SimplyStored
VERSION = '0.7.0rc5' VERSION = '0.7.0rc6'
class Error < RuntimeError; end class Error < RuntimeError; end
class RecordNotFound < RuntimeError; end class RecordNotFound < RuntimeError; end
end end
Expand Down
2 changes: 1 addition & 1 deletion lib/simply_stored/couch/belongs_to.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def initialize(owner_clazz, name, options = {})
end end


define_method "#{name}_changed?" do define_method "#{name}_changed?" do
self.send("#{name}_id") != self.send("#{name}_id_was") self.send("#{name}_id_changed?")
end end
end end
end end
Expand Down
4 changes: 2 additions & 2 deletions simply_stored.gemspec
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@


Gem::Specification.new do |s| Gem::Specification.new do |s|
s.name = "simply_stored" 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.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
s.authors = ["Mathias Meyer, Jonathan Weiss"] 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.description = "Convenience layer for CouchDB on top of CouchPotato."
s.email = "info@peritor.com" s.email = "info@peritor.com"
s.extra_rdoc_files = [ s.extra_rdoc_files = [
Expand Down
39 changes: 39 additions & 0 deletions test/dirty_tracking_test.rb
Original file line number Original file line Diff line number Diff line change
@@ -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.