rails/activerecord/test/models
Jon Leighton 8606a7fbe9 Fix scope chaining + STI
See #9869 and #9929.

The problem arises from the following example:

    class Project < ActiveRecord::Base
      scope :completed, -> { where completed: true }
    end

    class MajorProject < Project
    end

When calling:

    MajorProject.where(tasks_count: 10).completed

This expands to:

    MajorProject.where(tasks_count: 10).scoping {
      MajorProject.completed
    }

However the lambda for the `completed` scope is defined on Project. This
means that when it is called, `self` is Project rather than
MajorProject. So it expands to:

    MajorProject.where(tasks_count: 10).scoping {
      Project.where(completed: true)
    }

Since the scoping was applied on MajorProject, and not Project, this
fails to apply the tasks_count condition.

The solution is to make scoping apply across STI classes. I am slightly
concerned about the possible side-effects of this, but no tests fail and
it seems ok. I guess we'll see.
2013-04-05 13:14:28 +01:00
..
admin define Active Record Store accessors in a module 2013-02-11 17:00:55 +03:00
autoloadable Fix ActiveRecord subclass_from_attrs when eager_load is false. 2013-03-06 11:46:07 +04:00
admin.rb Support fixtures for namespaced models [#2965 state:resolved] 2010-04-25 16:04:38 +02:00
aircraft.rb Refactoring test_has_many_with_pluralize_table_names_false test 2011-05-20 01:53:13 -05:00
arunit2_model.rb added test for #3732 2012-02-10 17:35:22 -05:00
author.rb rename Relation#uniq to Relation#distinct. #uniq still works. 2013-03-15 14:15:47 +01:00
auto_id.rb move assets and models 2008-01-18 07:27:03 +00:00
binary.rb move assets and models 2008-01-18 07:27:03 +00:00
bird.rb Allow nested attributes in associations to update values in it's owner object. Fixes a regression from 3.0.x 2011-12-14 20:13:03 -06:00
book.rb rename Relation#uniq to Relation#distinct. #uniq still works. 2013-03-15 14:15:47 +01:00
boolean.rb Add missing model 2010-08-14 18:49:04 -03:00
bulb.rb Make sure the tests pass in the case closer to described in #8195 2012-12-10 17:35:16 -03:00
car.rb Convert association macros to the new syntax 2012-07-20 14:14:51 +01:00
categorization.rb Deprecate eager-evaluated scopes. 2012-03-21 22:18:18 +00:00
category.rb Goodbye there, very special rubbish! 2013-01-24 18:40:59 +09:00
citation.rb move assets and models 2008-01-18 07:27:03 +00:00
club.rb Merge branch 'master' into nested_has_many_through 2011-03-04 09:30:27 +00:00
college.rb added test for #3732 2012-02-10 17:35:22 -05:00
column_name.rb move assets and models 2008-01-18 07:27:03 +00:00
comment.rb Fix scope chaining + STI 2013-04-05 13:14:28 +01:00
company_in_module.rb Revert "Unused methods, module, etc." 2013-01-24 21:44:02 +09:00
company.rb Added STI support to init and building associations 2012-11-29 05:50:34 +00:00
computer.rb move assets and models 2008-01-18 07:27:03 +00:00
contact.rb Add some coverage for AR serialization with serializable_hash 2012-06-22 08:28:03 -03:00
contract.rb Tests for issue #1360 2011-05-31 19:47:34 +01:00
country.rb Deprecate set_primary_key in favour of self.primary_key= 2011-11-29 20:13:37 +00:00
course.rb added test for #3732 2012-02-10 17:35:22 -05:00
customer.rb Revert "Removing composed_of from ActiveRecord." 2012-07-27 19:25:14 -03:00
dashboard.rb Deprecate set_primary_key in favour of self.primary_key= 2011-11-29 20:13:37 +00:00
default.rb move assets and models 2008-01-18 07:27:03 +00:00
developer.rb Fix .update_all and .delete_all when using a condition on a joined table 2013-01-11 12:31:09 -05:00
dog_lover.rb Update other counter caches on destroy 2013-03-20 13:43:07 -07:00
dog.rb Update other counter caches on destroy 2013-03-20 13:43:07 -07:00
edge.rb move assets and models 2008-01-18 07:27:03 +00:00
electron.rb Eager loading an association should not change the count of children 2010-08-02 17:12:59 +02:00
engine.rb expanding the test to include both type of order declaration 2010-09-18 20:49:19 +02:00
entrant.rb move assets and models 2008-01-18 07:27:03 +00:00
essay.rb Support for :primary_key option on the source reflection of a through association, where the source is a has_one or has_many 2010-10-19 14:14:06 +01:00
event.rb Ensure validates_uniqueness_of considers limit on the field. [#1042 state:resolved] 2009-03-07 13:52:17 +00:00
eye.rb use persisted? instead of new_record? wherever possible 2010-11-09 13:54:04 -02:00
face.rb Make polymorphic_inverse_of in Reflection throw an InverseOfAssociationNotFoundError if the supplied class doesn't have the appropriate association. [#3520 state:resolved] 2009-12-28 15:12:17 +01:00
friendship.rb Refactor Person/Friendship relationships to be more intuitive 2013-03-17 02:11:19 -04:00
guid.rb Fix validates_uniqueness_of for SQL keywords [#23 state:resolved] 2008-05-11 19:30:03 +01:00
interest.rb Add inverse polymorphic association support. [#3520 state:resolved] 2009-12-28 15:12:13 +01:00
invoice.rb Add failing test that triggers the stack overflow 2010-01-08 21:45:02 +01:00
item.rb move assets and models 2008-01-18 07:27:03 +00:00
job.rb Fix naughty trailing whitespace 2010-10-31 11:21:28 +00:00
joke.rb Deprecate set_table_name in favour of self.table_name= or defining your own method. 2011-11-29 20:13:36 +00:00
keyboard.rb Deprecate set_primary_key in favour of self.primary_key= 2011-11-29 20:13:37 +00:00
legacy_thing.rb Deprecate set_locking_column in favour of self.locking_column= 2011-11-29 20:13:37 +00:00
lesson.rb Fixing ordering of HABTM association deletion [#6191 state:resolved] 2011-02-04 19:39:59 -02:00
line_item.rb Add failing test that triggers the stack overflow 2010-01-08 21:45:02 +01:00
liquid.rb rename Relation#uniq to Relation#distinct. #uniq still works. 2013-03-15 14:15:47 +01:00
man.rb Add inverse polymorphic association support. [#3520 state:resolved] 2009-12-28 15:12:13 +01:00
matey.rb move assets and models 2008-01-18 07:27:03 +00:00
member_detail.rb Fix naughty trailing whitespace 2010-10-31 11:21:28 +00:00
member_type.rb Fix preloading of has_one :through associations on belongs_to [#1507 state:resolved] 2008-12-18 19:19:36 +00:00
member.rb Use method compilation for association methods 2012-08-10 23:28:08 +01:00
membership.rb Don't use select() values from the join model of a through association. Fixes #508. 2011-05-11 08:56:01 +01:00
minimalistic.rb move assets and models 2008-01-18 07:27:03 +00:00
minivan.rb Deprecate set_primary_key in favour of self.primary_key= 2011-11-29 20:13:37 +00:00
mixed_case_monkey.rb Deprecate set_primary_key in favour of self.primary_key= 2011-11-29 20:13:37 +00:00
molecule.rb Eager loading an association should not change the count of children 2010-08-02 17:12:59 +02:00
movie.rb move assets and models 2008-01-18 07:27:03 +00:00
order.rb move assets and models 2008-01-18 07:27:03 +00:00
organization.rb Deprecate eager-evaluated scopes. 2012-03-21 22:18:18 +00:00
owner.rb has_many through obeys order on through association 2013-04-04 15:45:13 -04:00
parrot.rb Deprecate set_inheritance_column in favour of self.inheritance_column= 2011-11-29 20:13:36 +00:00
person.rb Refactor Person/Friendship relationships to be more intuitive 2013-03-17 02:11:19 -04:00
pet.rb Add missing require to inheritance test 2013-04-03 14:48:57 -03:00
pirate.rb allow to pass Symbol or Proc into :limit option of #accepts_nested_attributes_for 2012-08-26 03:02:05 +03:00
possession.rb Fix pluck when columns/tables are reserved words. 2012-09-05 18:00:07 -04:00
post.rb Fix cases where delete_records on a has_many association caused errors 2013-01-27 15:36:29 +00:00
price_estimate.rb Fix nested association references 2012-09-12 23:32:50 +01:00
project.rb rename Relation#uniq to Relation#distinct. #uniq still works. 2013-03-15 14:15:47 +01:00
randomly_named_c1.rb Test fixtures with custom model and table names 2011-12-30 10:34:01 +01:00
rating.rb Add a test for STI on the through where the through is nested, and change the code which support this 2011-03-05 20:10:24 +00:00
reader.rb Prevent Relation#merge from collapsing wheres on the RHS 2013-01-27 20:34:52 +00:00
reference.rb Rename update_attributes method to update, keep update_attributes as an alias 2013-01-03 11:51:21 -05:00
reply.rb unused scope 2013-01-02 05:48:56 +09:00
ship_part.rb Nested records (re: autosave) are now updated even when the intermediate parent record is unchanged [#4242 state:resolved] 2010-05-18 16:13:00 +02:00
ship.rb Nested records (re: autosave) are now updated even when the intermediate parent record is unchanged [#4242 state:resolved] 2010-05-18 16:13:00 +02:00
shop.rb Deletes trailing whitespaces (over text files only find * -type f -exec sed 's/[ \t]*$//' -i {} \;) 2010-08-14 04:12:33 -03:00
speedometer.rb test case to prevent duplicated associations with custom PK. 2013-02-24 16:49:47 +01:00
sponsor.rb Convert association macros to the new syntax 2012-07-20 14:14:51 +01:00
string_key_object.rb Deprecate set_primary_key in favour of self.primary_key= 2011-11-29 20:13:37 +00:00
student.rb Fixing ordering of HABTM association deletion [#6191 state:resolved] 2011-02-04 19:39:59 -02:00
subject.rb use persisted? instead of new_record? wherever possible 2010-11-09 13:54:04 -02:00
subscriber.rb Deprecate set_primary_key in favour of self.primary_key= 2011-11-29 20:13:37 +00:00
subscription.rb Fix reset_counters() crashing on has_many :through associations. 2012-10-02 23:49:32 +08:00
tag.rb move assets and models 2008-01-18 07:27:03 +00:00
tagging.rb rm unnecessary test 2012-07-20 19:35:02 +01:00
task.rb Revert "Unused methods, module, etc." 2013-01-24 21:44:02 +09:00
topic.rb Describing the reason for defining BlankTopic#blank? which will never be called 2013-01-24 22:07:43 +09:00
toy.rb Deprecate eager-evaluated scopes. 2012-03-21 22:18:18 +00:00
traffic_light.rb test case for serialize default values. 2013-03-07 17:26:35 +01:00
treasure.rb Accept belongs_to assoc. keys in ActiveRecord queries 2012-09-11 14:11:51 -04:00
treaty.rb Deprecate set_primary_key in favour of self.primary_key= 2011-11-29 20:13:37 +00:00
tyre.rb Ensure we can nest include calls [#5285 state:resolved] 2010-08-12 13:10:58 -03:00
vegetables.rb rewrite inheritance tests with a custom inheritance_column 2012-09-03 20:30:43 +02:00
vertex.rb move assets and models 2008-01-18 07:27:03 +00:00
warehouse_thing.rb Deprecate set_table_name in favour of self.table_name= or defining your own method. 2011-11-29 20:13:36 +00:00
wheel.rb reset_counter should work with non-traditional belongs_to and polymorphic belongs_to 2010-07-08 23:24:12 +02:00
without_table.rb Deprecate eager-evaluated scopes. 2012-03-21 22:18:18 +00:00
zine.rb Providing support for :inverse_of as an option to associations. 2009-05-04 15:27:39 -07:00