revisions 0.0.0 → 0.1.0

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/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
- * If your model is a draft, it simply saves the model.
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.0.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
- if self.published?
41
- new_copy = self.clone
42
- attributes_to_nil = {}
43
- self.unrevised_attributes.each {|a| attributes_to_nil[a] = nil }
44
- new_copy.attributes=attributes_to_nil
45
- new_copy.created_at = new_copy.updated_at = Time.zone.now
46
- new_copy.status = 'revision'
47
- new_copy.revision_of = self.id
48
- if new_copy.save
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
- save
56
- end
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.0.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-04-29}
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 = [
@@ -26,11 +26,12 @@ class TestRevisions < Test::Unit::TestCase
26
26
  end
27
27
  end
28
28
 
29
- should "just save to the same record when in draft mode" do
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
- assert_equal 0, @response.revisions.size
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
- - 0
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-04-29 00:00:00 -04:00
17
+ date: 2010-05-20 00:00:00 -04:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency