Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add `exists?` and `update_all` to `CollectionProxy` for respects an association scope #25786

Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

@@ -29,7 +29,7 @@ module Associations
# instantiation of the actual post records.
class CollectionProxy < Relation
delegate(*(ActiveRecord::Calculations.public_instance_methods - [:count]), to: :scope)
delegate :find_nth, to: :scope
delegate :find_nth, :exists?, :update_all, :arel, to: :scope

def initialize(klass, association) #:nodoc:
@association = association
@@ -897,10 +897,6 @@ def include?(record)
!!@association.include?(record)
end

def arel #:nodoc:
scope.arel
end

def proxy_association
@association
end
@@ -439,6 +439,26 @@ def test_create_resets_cached_counters
assert_equal person, person.readers.first.person
end

def test_update_all_respects_association_scope
person = Person.new
person.first_name = 'Naruto'
person.references << Reference.new
person.id = 10
person.references
person.save!
assert_equal 1, person.references.update_all(favourite: true)

This comment has been minimized.

@kamipo

kamipo Jul 20, 2016
Author Member

Changed to use assert_equal instead of assert_nothing_raised.

end

def test_exists_respects_association_scope
person = Person.new
person.first_name = 'Sasuke'
person.references << Reference.new
person.id = 10
person.references
person.save!
assert_predicate person.references, :exists?

This comment has been minimized.

@kamipo

kamipo Jul 20, 2016
Author Member

Changed to use assert_predicate instead of assert.

end

def force_signal37_to_load_all_clients_of_firm
companies(:first_firm).clients_of_firm.each {|f| }
end
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.