Skip to content

Commit

Permalink
Rails 4 always has a scope, not an array
Browse files Browse the repository at this point in the history
  • Loading branch information
justinfrench committed Nov 7, 2014
1 parent 2f6606e commit 73ca1a0
Showing 1 changed file with 3 additions and 10 deletions.
13 changes: 3 additions & 10 deletions spec/spec_helper.rb
Expand Up @@ -161,9 +161,8 @@ def respond_to?(sym)
end
end

# In Rails 3 Model.all returns an array. In Rails 4, it returns an
# association proxy, which quacks a lot like an array. We use this in stubs
# or mocks where we need to return the later.
# Model.all returns an association proxy, which quacks a lot like an array.
# We use this in stubs or mocks where we need to return the later.
#
# TODO try delegate?
# delegate :map, :size, :length, :first, :to_ary, :each, :include?, :to => :array
Expand Down Expand Up @@ -246,14 +245,8 @@ def author_path(*args); "/authors/1"; end
def authors_path(*args); "/authors"; end
def new_author_path(*args); "/authors/new"; end

# Returns the array for Rails 3 and a thing that looks looks like an
# association proxy for Rails 4+
def author_array_or_scope(the_array = [@fred, @bob])
if ::Formtastic::Util.rails3?
the_array
else
MockScope.new(the_array)
end
MockScope.new(the_array)
end

@fred = ::Author.new
Expand Down

0 comments on commit 73ca1a0

Please sign in to comment.