1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
rails--rails/activerecord/test/cases
eileencodes 51660f0191 Fix leaky chain on polymorphic association
If there was a polymorphic hm:t association with a scope AND second
non-scoped hm:t association on a model the polymorphic scope would leak
through into the call for the non-polymorhic hm:t association.

This would only break if `hotel.drink_designers` was called before
`hotel.recipes`. If `hotel.recipes` was called first there would be
no problem with the SQL.

Before (employable_type should not be here):
```
SELECT COUNT(*) FROM "drink_designers" INNER JOIN "chefs" ON
"drink_designers"."id" = "chefs"."employable_id" INNER JOIN
"departments" ON "chefs"."department_id" = "departments"."id" WHERE
"departments"."hotel_id" = ? AND "chefs"."employable_type" = ?
[["hotel_id", 1], ["employable_type", "DrinkDesigner"]]
```

After:
```
SELECT COUNT(*) FROM "recipes" INNER JOIN "chefs" ON "recipes"."chef_id"
= "chefs"."id" INNER JOIN "departments" ON "chefs"."department_id" =
"departments"."id" WHERE "departments"."hotel_id" = ?  [["hotel_id", 1]]
```

From the SQL you can see that `employable_type` was leaking through when
calling recipes. The solution is to dup the chain of the polymorphic
association so it doesn't get cached. Additionally, this follows
`scope_chain` which dup's the `source_reflection`'s `scope_chain`.

This required another model/table/relationship because the leak only
happens on a hm:t polymorphic that's called before another hm:t on the
same model.

I am specifically testing the SQL here instead of the number of records
becasue the test could pass if there was 1 drink designer recipe for the
drink designer chef even though the `employable_type` was leaking through.
This needs to specifically check that `employable_type` is not in the SQL
statement.
2015-03-15 10:39:42 -04:00
..
adapters pg, disable_referential_integrity only catches AR errors. 2015-03-11 14:34:53 +01:00
associations
attribute_methods
coders
connection_adapters
connection_specification
fixture_set
migration
relation
scoping
tasks
type
validations
adapter_test.rb
aggregations_test.rb
ar_schema_test.rb
associations_test.rb
attribute_decorators_test.rb
attribute_methods_test.rb
attribute_set_test.rb
attribute_test.rb
attributes_test.rb
autosave_association_test.rb
base_test.rb
batches_test.rb
binary_test.rb
bind_parameter_test.rb
calculations_test.rb
callbacks_test.rb
clone_test.rb
column_alias_test.rb
column_definition_test.rb
connection_management_test.rb
connection_pool_test.rb
core_test.rb
counter_cache_test.rb
custom_locking_test.rb
database_statements_test.rb
date_time_precision_test.rb
date_time_test.rb
defaults_test.rb
dirty_test.rb
disconnected_test.rb
dup_test.rb
enum_test.rb
explain_subscriber_test.rb
explain_test.rb
finder_respond_to_test.rb
finder_test.rb
fixtures_test.rb
forbidden_attributes_protection_test.rb
habtm_destroy_order_test.rb
helper.rb
hot_compatibility_test.rb
i18n_test.rb
inheritance_test.rb
integration_test.rb
invalid_connection_test.rb
invalid_date_test.rb
invertible_migration_test.rb
json_serialization_test.rb
locking_test.rb
log_subscriber_test.rb
migration_test.rb
migrator_test.rb
mixin_test.rb
modules_test.rb
multiparameter_attributes_test.rb
multiple_db_test.rb
nested_attributes_test.rb
nested_attributes_with_callbacks_test.rb
persistence_test.rb
pooled_connections_test.rb
primary_keys_test.rb
query_cache_test.rb
quoting_test.rb
readonly_test.rb
reaper_test.rb
reflection_test.rb Fix leaky chain on polymorphic association 2015-03-15 10:39:42 -04:00
relation_test.rb
relations_test.rb
reload_models_test.rb
result_test.rb
sanitize_test.rb
schema_dumper_test.rb
secure_token_test.rb
serialization_test.rb
serialized_attribute_test.rb
statement_cache_test.rb
store_test.rb
suppressor_test.rb
test_case.rb
time_precision_test.rb
timestamp_test.rb
transaction_callbacks_test.rb Fix before_commit when updating a record on the callback 2015-03-14 12:20:36 -04:00
transaction_isolation_test.rb
transactions_test.rb
type_test.rb
types_test.rb
unconnected_test.rb
validations_repair_helper.rb
validations_test.rb
view_test.rb
xml_serialization_test.rb
yaml_serialization_test.rb Add YAML compatibility for objects from Rails 4.2 2015-03-10 11:56:45 -06:00