couch_potato 0.2.23 → 0.2.24
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGES.md +3 -0
- data/VERSION.yml +1 -1
- data/lib/couch_potato/persistence/dirty_attributes.rb +7 -1
- data/spec/unit/dirty_attributes_spec.rb +14 -0
- metadata +2 -2
data/CHANGES.md
CHANGED
@@ -1,5 +1,8 @@
|
|
1
1
|
## Changes
|
2
2
|
|
3
|
+
### 0.2.24
|
4
|
+
* persistent instances can now be marked as dirty with #is_dirty (langalex)
|
5
|
+
|
3
6
|
### 0.2.23
|
4
7
|
* Couch Potato models now conform to the ActiveModel interface when ActiveModel is installed, see http://yehudakatz.com/2010/01/10/activemodel-make-any-ruby-object-feel-like-activerecord/ (langalex)
|
5
8
|
* fixed error with dirty tracking and BigDecimals (thilo)
|
data/VERSION.yml
CHANGED
@@ -16,11 +16,16 @@ module CouchPotato
|
|
16
16
|
|
17
17
|
# returns true if a model has dirty attributes, i.e. their value has changed since the last save
|
18
18
|
def dirty?
|
19
|
-
new? || self.class.properties.inject(false) do |res, property|
|
19
|
+
new? || @forced_dirty || self.class.properties.inject(false) do |res, property|
|
20
20
|
res || property.dirty?(self)
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
24
|
+
# marks a model as dirty
|
25
|
+
def is_dirty
|
26
|
+
@forced_dirty = true
|
27
|
+
end
|
28
|
+
|
24
29
|
private
|
25
30
|
|
26
31
|
def assign_attribute_copies_for_dirty_tracking
|
@@ -30,6 +35,7 @@ module CouchPotato
|
|
30
35
|
end
|
31
36
|
|
32
37
|
def reset_dirty_attributes
|
38
|
+
@forced_dirty = nil
|
33
39
|
self.class.properties.each do |property|
|
34
40
|
instance_variable_set("@#{property.name}_was", clone_attribute(send(property.name)))
|
35
41
|
end
|
@@ -102,6 +102,11 @@ describe 'dirty attribute tracking' do
|
|
102
102
|
@plate.food_not_changed
|
103
103
|
@plate.should_not be_food_changed
|
104
104
|
end
|
105
|
+
|
106
|
+
it "should return true if forced dirty" do
|
107
|
+
@plate.is_dirty
|
108
|
+
@plate.should be_dirty
|
109
|
+
end
|
105
110
|
end
|
106
111
|
end
|
107
112
|
|
@@ -147,6 +152,15 @@ describe 'dirty attribute tracking' do
|
|
147
152
|
db.save! @plate
|
148
153
|
@plate.should_not be_food_changed
|
149
154
|
end
|
155
|
+
|
156
|
+
it "should reset a forced dirty state" do
|
157
|
+
couchrest_db = stub('database', :get => Plate.json_create({'_id' => '1', '_rev' => '2', 'food' => 'sushi', JSON.create_id => 'Plate'}), :info => nil, :save_doc => {'rev' => '3'})
|
158
|
+
db = CouchPotato::Database.new(couchrest_db)
|
159
|
+
@plate = db.load_document '1'
|
160
|
+
@plate.is_dirty
|
161
|
+
db.save! @plate
|
162
|
+
@plate.should_not be_dirty
|
163
|
+
end
|
150
164
|
end
|
151
165
|
|
152
166
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: couch_potato
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.24
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alexander Lang
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2010-02-
|
12
|
+
date: 2010-02-05 00:00:00 +01:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|