mongo_mapper-unstable 2009.10.11 → 2009.10.12
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/mongo_mapper/dirty.rb +6 -0
- data/mongo_mapper.gemspec +1 -1
- data/test/functional/test_dirty.rb +21 -0
- metadata +2 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2009.10.
|
1
|
+
2009.10.12
|
data/lib/mongo_mapper/dirty.rb
CHANGED
@@ -3,6 +3,7 @@ module MongoMapper
|
|
3
3
|
DIRTY_SUFFIXES = ['_changed?', '_change', '_will_change!', '_was']
|
4
4
|
|
5
5
|
def self.included(base)
|
6
|
+
base.alias_method_chain :initialize, :dirty
|
6
7
|
base.alias_method_chain :write_attribute, :dirty
|
7
8
|
base.alias_method_chain :save, :dirty
|
8
9
|
base.alias_method_chain :save!, :dirty
|
@@ -52,6 +53,11 @@ module MongoMapper
|
|
52
53
|
changed.inject({}) { |h, attribute| h[attribute] = key_change(attribute); h }
|
53
54
|
end
|
54
55
|
|
56
|
+
def initialize_with_dirty(attrs={})
|
57
|
+
initialize_without_dirty(attrs)
|
58
|
+
changed_keys.clear unless new?
|
59
|
+
end
|
60
|
+
|
55
61
|
# Attempts to +save+ the record and clears changed keys if successful.
|
56
62
|
def save_with_dirty(*args) #:nodoc:
|
57
63
|
if status = save_without_dirty(*args)
|
data/mongo_mapper.gemspec
CHANGED
@@ -29,6 +29,11 @@ class DirtyTest < Test::Unit::TestCase
|
|
29
29
|
doc.phrase_change.should == [nil, 'Golly Gee Willikers Batman']
|
30
30
|
end
|
31
31
|
|
32
|
+
should "happen when initializing" do
|
33
|
+
doc = @document.new(:phrase => 'Foo')
|
34
|
+
doc.changed?.should be_true
|
35
|
+
end
|
36
|
+
|
32
37
|
should "clear changes on save" do
|
33
38
|
doc = @document.new
|
34
39
|
doc.phrase = 'Golly Gee Willikers Batman'
|
@@ -46,6 +51,22 @@ class DirtyTest < Test::Unit::TestCase
|
|
46
51
|
doc.phrase_changed?.should_not be_true
|
47
52
|
doc.phrase_change.should be_nil
|
48
53
|
end
|
54
|
+
|
55
|
+
should "not happen when loading from database" do
|
56
|
+
doc = @document.create(:phrase => 'Foo')
|
57
|
+
|
58
|
+
from_db = @document.find(doc.id)
|
59
|
+
from_db.changed?.should be_false
|
60
|
+
end
|
61
|
+
|
62
|
+
should "happen if changed after loading from database" do
|
63
|
+
doc = @document.create(:phrase => 'Foo')
|
64
|
+
|
65
|
+
from_db = @document.find(doc.id)
|
66
|
+
from_db.changed?.should be_false
|
67
|
+
from_db.phrase = 'Bar'
|
68
|
+
from_db.changed?.should be_true
|
69
|
+
end
|
49
70
|
end
|
50
71
|
|
51
72
|
context "blank new value and type integer" do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mongo_mapper-unstable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2009.10.
|
4
|
+
version: 2009.10.12
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Nunemaker
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-10-
|
12
|
+
date: 2009-10-12 00:00:00 -05:00
|
13
13
|
default_executable: mmconsole
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|