rich-acts_as_revisable 1.0.5 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/acts_as_revisable/acts/deletable.rb +1 -1
- data/lib/acts_as_revisable/acts/revisable.rb +1 -1
- data/lib/acts_as_revisable/acts/revision.rb +1 -2
- data/lib/acts_as_revisable/version.rb +2 -2
- data/spec/find_spec.rb +4 -0
- data/spec/general_spec.rb +20 -0
- data/spec/spec_helper.rb +1 -1
- metadata +1 -1
@@ -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.
|
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
|
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", :
|
18
|
+
ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :database => ":memory:")
|
19
19
|
|
20
20
|
def setup_db
|
21
21
|
ActiveRecord::Schema.define(:version => 1) do
|