rich-acts_as_revisable 1.0.5 → 1.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.
@@ -8,7 +8,7 @@ module WithoutScope
8
8
  end
9
9
 
10
10
  def destroy
11
- now = Time.now
11
+ now = Time.current
12
12
 
13
13
  prev = self.revisions.first
14
14
  self.revisable_deleted_at = now
@@ -77,7 +77,7 @@ module WithoutScope
77
77
  by
78
78
  when :first
79
79
  revisions.last
80
- when :previous
80
+ when :previous, :last
81
81
  revisions.first
82
82
  when Time
83
83
  revisions.find(:first, :conditions => ["? >= ? and ? <= ?", :revisable_revised_at, by, :revisable_current_at, by])
@@ -65,14 +65,13 @@ module WithoutScope
65
65
 
66
66
  # Sets some initial values for a new revision.
67
67
  def revision_setup #:nodoc:
68
- now = Time.now
68
+ now = Time.current
69
69
  prev = current_revision.revisions.first
70
70
  prev.update_attribute(:revisable_revised_at, now) if prev
71
71
  self[:revisable_current_at] = now + 1.second
72
72
  self[:revisable_is_current] = false
73
73
  self[:revisable_branched_from_id] = current_revision[:revisable_branched_from_id]
74
74
  self[:revisable_type] = current_revision[:type] || current_revision.class.name
75
- self[:revisable_number] = (self.class.maximum(:revisable_number, :conditions => {:revisable_original_id => self[:revisable_original_id]}) || 0) + 1
76
75
  end
77
76
 
78
77
  def grab_my_branches
@@ -2,8 +2,8 @@ module WithoutScope #:nodoc:
2
2
  module ActsAsRevisable
3
3
  module VERSION #:nodoc:
4
4
  MAJOR = 1
5
- MINOR = 0
6
- TINY = 5
5
+ MINOR = 1
6
+ TINY = 0
7
7
 
8
8
  STRING = [MAJOR, MINOR, TINY].join('.')
9
9
  end
data/spec/find_spec.rb CHANGED
@@ -26,5 +26,9 @@ describe WithoutScope::ActsAsRevisable do
26
26
  it "should find revisions with conditions" do
27
27
  Project.find(:all, :conditions => {:name => "Rich"}, :with_revisions => true).should == [@project1.find_revision(:previous)]
28
28
  end
29
+
30
+ it "should find last revision" do
31
+ @project1.find_revision(:last).should == @project1.find_revision(:previous)
32
+ end
29
33
  end
30
34
  end
data/spec/general_spec.rb CHANGED
@@ -70,6 +70,10 @@ describe WithoutScope::ActsAsRevisable do
70
70
  @project.sessions.size.should == 1
71
71
  end
72
72
 
73
+ it "should have a single revision with a revision_number of zero" do
74
+ @project.revisions.collect{ |rev| rev.revision_number }.should == [0]
75
+ end
76
+
73
77
  it "should return an instance of the revision class" do
74
78
  @project.revisions.first.should be_an_instance_of(Session)
75
79
  end
@@ -79,6 +83,22 @@ describe WithoutScope::ActsAsRevisable do
79
83
  end
80
84
  end
81
85
 
86
+ describe "with multiple revisions" do
87
+ before(:each) do
88
+ @project.update_attribute(:name, "Stephen")
89
+ @project.update_attribute(:name, "Michael")
90
+ end
91
+
92
+ it "should have a revision_number of two" do
93
+ @project.revision_number.should == 2
94
+ end
95
+
96
+ it "should have revisions with revision_number values of zero and one" do
97
+ @project.revisions.collect{ |rev| rev.revision_number }.should == [1,0]
98
+ end
99
+ end
100
+
101
+
82
102
  describe "with excluded columns modified" do
83
103
  before(:each) do
84
104
  @project.update_attribute(:unimportant, "a new value")
data/spec/spec_helper.rb CHANGED
@@ -15,7 +15,7 @@ end
15
15
  $:.unshift(File.dirname(__FILE__) + '/../lib')
16
16
  require 'acts_as_revisable'
17
17
 
18
- ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :dbfile => ":memory:")
18
+ ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :database => ":memory:")
19
19
 
20
20
  def setup_db
21
21
  ActiveRecord::Schema.define(:version => 1) do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rich-acts_as_revisable
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.5
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rich Cavanaugh