Permalink
Browse files

fixed scoping issue on finders

  • Loading branch information...
1 parent 7e6b585 commit b6648f92d7acce662cdc7625a488fb012452a7be @chargify-pair chargify-pair committed Jan 19, 2013
@@ -100,7 +100,7 @@ def is_branching!(value=true) #:nodoc:
def branch_source
self[:branch_source] ||= if self[:revisable_branched_from_id]
- self.class.where(:id => self[:revisable_branched_from_id]).with_revisions.first
+ self.class.where(:id => self[:revisable_branched_from_id]).with_revisions
else
nil
end
@@ -2,9 +2,9 @@ module WithoutScope
module ActsAsRevisable
# This module is mixed into the revision classes.
- #
+ #
# ==== Callbacks
- #
+ #
# * +before_revise+ is called before the record is revised.
# * +after_revise+ is called after the record is revised.
# * +before_revert+ is called before the record is reverted.
@@ -49,22 +49,22 @@ class << base
end
# Finds a specific revision of self.
- #
- # The +by+ parameter can be a revision_class instance,
+ #
+ # The +by+ parameter can be a revision_class instance,
# the symbols :first, :previous or :last, a Time instance
# or an Integer.
- #
+ #
# When passed a revision_class instance, this method
# simply returns it. This is used primarily by revert_to!.
- #
+ #
# When passed :first it returns the first revision created.
- #
+ #
# When passed :previous or :last it returns the last revision
# created.
- #
+ #
# When passed a Time instance it returns the revision that
# was the current record at the given time.
- #
+ #
# When passed an Integer it returns the revision with that
# revision_number.
def find_revision(by)
@@ -95,18 +95,18 @@ def find_revision(by)
# Returns a revisable_class instance initialized with the record
# found using find_revision.
- #
+ #
# The +what+ parameter is simply passed to find_revision and the
# returned record forms the basis of the reverted record.
- #
+ #
# ==== Callbacks
- #
+ #
# * +before_revert+ is called before the record is reverted.
# * +after_revert+ is called after the record is reverted.
- #
- # If :without_revision => true has not been passed the
+ #
+ # If :without_revision => true has not been passed the
# following callbacks are also called:
- #
+ #
# * +before_revise+ is called before the record is revised.
# * +after_revise+ is called after the record is revised.
def revert_to(what, *args, &block) #:yields:
@@ -170,7 +170,7 @@ def is_reverting!(val=true) #:nodoc:
set_revisable_state(:reverting, val)
end
- # Returns true if the _record_ (not just this instance
+ # Returns true if the _record_ (not just this instance
# of the record) is currently being reverted.
def is_reverting?
get_revisable_state(:reverting) || false
@@ -198,13 +198,13 @@ def no_revision? #:nodoc:
# Force an immediate revision whether or
# not any columns have been modified.
- #
+ #
# The +args+ catch-all argument is not used. It's primarily
# there to allow +revise!+ to be used directly as an association
# callback since association callbacks are passed an argument.
- #
+ #
# ==== Callbacks
- #
+ #
# * +before_revise+ is called before the record is revised.
# * +after_revise+ is called after the record is revised.
def revise!(*args)
@@ -227,19 +227,19 @@ def revise!(*args)
#
# @project.revision_number # => 1
# @project.changeset do |project|
- # # each one of the following statements would
+ # # each one of the following statements would
# # normally trigger a revision
# project.update_attribute(:name, "new name")
# project.revise!
# project.revise!
# end
# @project.save
# @project.revision_number # => 2
- #
+ #
# ==== Callbacks
- #
+ #
# * +before_changeset+ is called before a changeset block is called.
- # * +after_changeset+ is called after a changeset block is called.
+ # * +after_changeset+ is called after a changeset block is called.
def changeset(&block)
return unless block_given?
@@ -257,7 +257,7 @@ def changeset(&block)
run_callbacks(:after_changeset)
end
ensure
- in_revision!(false)
+ in_revision!(false)
end
end
@@ -330,7 +330,7 @@ def before_revisable_update #:nodoc:
# Checks if an initialized revision_class has been stored
# in the accessor. If it has been, this instance is saved.
def after_revisable_update #:nodoc:
- if no_revision? # check and see if no_revision! was called in a callback
+ if no_revision? # check and see if no_revision! was called in a callback
self.revisable_revision = nil
return true
elsif self.revisable_revision
@@ -343,13 +343,13 @@ def after_revisable_update #:nodoc:
true
end
- # Returns true if the _record_ (not just this instance
+ # Returns true if the _record_ (not just this instance
# of the record) is currently being revised.
def in_revision?
get_revisable_state(:revision)
end
- # Manages the internal state of a +Revisable+ controlling
+ # Manages the internal state of a +Revisable+ controlling
# whether or not a record is being revised. This works across
# instances and is keyed on primary_key.
def in_revision!(val=true) #:nodoc:
@@ -440,9 +440,9 @@ def with_revisions
# acts_as_revisable's override for find that allows for
# including revisions in the find.
- #
+ #
# ==== Example
- #
+ #
# find(:all, :with_revisions => true)
#def find(*args) #:nodoc:
#options = args.grep(Hash).first
@@ -462,7 +462,7 @@ def revision_class_name #:nodoc:
self.revisable_options.revision_class_name || "#{self.name}Revision"
end
- # Returns the actual +Revision+ class based on the
+ # Returns the actual +Revision+ class based on the
# #revision_class_name.
def revision_class #:nodoc:
self.revisable_revision_class ||= self.revision_class_name.constantize
@@ -15,14 +15,14 @@ class Project
end
it "should allow for branch creation" do
- @project.should == @project.branch.branch_source
+ [@project].should == @project.branch.branch_source
end
it "should always tie the branch to the correct version" do
b = @project.branch!
@project.revise!
prev = @project.find_revision(:last)
- b.reload.branch_source.should == prev
+ b.reload.branch_source.should == [prev]
end
it "should have branches" do

0 comments on commit b6648f9

Please sign in to comment.