revisions 0.0.0 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +1 -11
- data/VERSION +1 -1
- data/lib/revisions.rb +12 -16
- data/revisions.gemspec +2 -2
- data/test/test_revisions.rb +3 -2
- metadata +3 -3
data/README.rdoc
CHANGED
@@ -47,8 +47,7 @@ pending_revisions:
|
|
47
47
|
* returns true if there are revisions with a more recent updated_at than the model.
|
48
48
|
|
49
49
|
save_revision:
|
50
|
-
*
|
51
|
-
* If your model is published, it saves a revision (does not modify the core model)
|
50
|
+
* Saves a copy of your model (a revision) in the same table
|
52
51
|
* OG model doesn't change, so all associations are intact
|
53
52
|
* Behaves like standard ActiveRecord save (ie. returns true/false if it saves succesfully and creates an errors array if not)
|
54
53
|
* can be called with bang (save_revision!) to throw an exception if it doesn't save.
|
@@ -80,15 +79,6 @@ apply_revision will affect the original response
|
|
80
79
|
response.apply_revision # => true
|
81
80
|
response.title # => 'monkey'
|
82
81
|
|
83
|
-
|
84
|
-
|
85
|
-
==Final Suggestion
|
86
|
-
|
87
|
-
Since revisions all live within the same table, you probably want to setup a default scope on your model so you don't access revisions directly.
|
88
|
-
|
89
|
-
default_scope :conditions => "status <> 'revision'"
|
90
|
-
|
91
|
-
|
92
82
|
== LIMITATIONS
|
93
83
|
|
94
84
|
There are a few things on the to-do list, among them:
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.1.0
|
data/lib/revisions.rb
CHANGED
@@ -37,23 +37,19 @@ module Revisions
|
|
37
37
|
end
|
38
38
|
|
39
39
|
def save_revision
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
true
|
50
|
-
else
|
51
|
-
new_copy.errors.each {|attribute,message| self.errors.add(attribute,message)}
|
52
|
-
false
|
53
|
-
end
|
40
|
+
new_copy = self.clone
|
41
|
+
attributes_to_nil = {}
|
42
|
+
self.unrevised_attributes.each {|a| attributes_to_nil[a] = nil }
|
43
|
+
new_copy.attributes=attributes_to_nil
|
44
|
+
new_copy.created_at = new_copy.updated_at = Time.zone.now
|
45
|
+
new_copy.status = 'revision'
|
46
|
+
new_copy.revision_of = self.id
|
47
|
+
if new_copy.save
|
48
|
+
true
|
54
49
|
else
|
55
|
-
|
56
|
-
|
50
|
+
new_copy.errors.each {|attribute,message| self.errors.add(attribute,message)}
|
51
|
+
false
|
52
|
+
end
|
57
53
|
end
|
58
54
|
|
59
55
|
def save_revision!
|
data/revisions.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{revisions}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.1.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Brian Hamman"]
|
12
|
-
s.date = %q{2010-
|
12
|
+
s.date = %q{2010-05-20}
|
13
13
|
s.description = %q{Save and apply revisions to a model, while keeping track of old revisiions}
|
14
14
|
s.email = %q{hamman@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
data/test/test_revisions.rb
CHANGED
@@ -26,11 +26,12 @@ class TestRevisions < Test::Unit::TestCase
|
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
29
|
-
should "
|
29
|
+
should "save a revision even in draft mode" do
|
30
30
|
@response.revisions.delete_all
|
31
31
|
@response.status = 'draft'
|
32
32
|
assert @response.save_revision
|
33
|
-
|
33
|
+
@response.reload
|
34
|
+
assert_equal 1, @response.revisions.size
|
34
35
|
end
|
35
36
|
|
36
37
|
should "save a revision that copies all fields" do
|
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 0
|
7
|
+
- 1
|
7
8
|
- 0
|
8
|
-
|
9
|
-
version: 0.0.0
|
9
|
+
version: 0.1.0
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Brian Hamman
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-
|
17
|
+
date: 2010-05-20 00:00:00 -04:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|