Skip to content
Browse files

a few tweaks

  • Loading branch information...
1 parent 91847b6 commit 4c039f4a9fd68f24614117e0bfcedcf368b2ec50 Rich Cavanaugh committed Jun 10, 2008
View
4 lib/acts_as_revisable/acts/revision.rb
@@ -41,12 +41,12 @@ class << base
end
# Return the revision prior to this one.
- def previous
+ def previous_revision
self.class.find(:first, :conditions => {:revisable_original_id => revisable_original_id, :revisable_number => revisable_number - 1})
end
# Return the revision after this one.
- def next
+ def next_revision
self.class.find(:first, :conditions => {:revisable_original_id => revisable_original_id, :revisable_number => revisable_number + 1})
end
View
6 lib/acts_as_revisable/clone_associations.rb
@@ -24,6 +24,12 @@ def clone_association(association, to)
def clone_belongs_to_association(association, to)
to.send(association.macro, association.name, association.options.clone)
end
+
+ def clone_has_many_association(association, to)
+ options = association.options.clone
+ options[:association_foreign_key] ||= "revisable_original_id"
+ to.send(association.macro, association.name, options)
+ end
end
end
end
View
4 spec/associations_spec.rb
@@ -13,10 +13,10 @@
end
it "should have a pretty named association" do
- lambda { @project.project_revisions }.should
+ lambda { @project.sessions }.should_not raise_error
end
it "should return all the revisions" do
@project.revisions.size.should == 3
- end
+ end
end
View
22 spec/general_spec.rb
@@ -11,12 +11,24 @@
describe "without revisions" do
it "should have a revision_number of zero" do
- @project.revision_number.should == 0
+ @project.revision_number.should be_zero
end
- it "should have no revisions" do
+ it "should be the current revision" do
+ @project.revisable_is_current.should be_true
+ end
+
+ it "should respond to current_revision? positively" do
+ @project.current_revision?.should be_true
+ end
+
+ it "should not have any revisions in the generic association" do
@project.revisions.should be_empty
end
+
+ it "should not have any revisions in the pretty named association" do
+ @project.sessions.should be_empty
+ end
end
describe "with revisions" do
@@ -28,10 +40,14 @@
@project.revision_number.should == 1
end
- it "should have a single revision" do
+ it "should have a single revision in the generic association" do
@project.revisions.size.should == 1
end
+ it "should have a single revision in the pretty named association" do
+ @project.sessions.size.should == 1
+ end
+
it "should return an instance of the revision class" do
@project.revisions.first.should be_an_instance_of(Session)
end

0 comments on commit 4c039f4

Please sign in to comment.
Something went wrong with that request. Please try again.