aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/models
Commit message (Collapse)AuthorAgeFilesLines
* Merge pull request #19683 from tristang/require-option-for-counter-cacheRafael Mendonça França2015-08-133-5/+6
|\ | | | | | | Require explicit counter_cache option for has_many
| * Add tests for associations without counter_cacheTristan Gamilis2015-04-091-0/+1
| | | | | | | | | | Assert that counter_cache behaviour is not used on belongs_to or has_many associations if the option is not given explicitly.
| * Require explicit counter_cache option for has_manyTristan Gamilis2015-04-072-5/+5
| | | | | | | | | | | | | | | | | | | | Previously has_many associations assumed a counter_cache was to be used based on the presence of an appropriately named column. This is inconsistent, since the inverse belongs_to association will not make this assumption. See issues #19042 #8446. This commit checks for the presence of the counter_cache key in the options of either the has_many or belongs_to association as well as ensuring that the *_count column is present.
* | Merge pull request #19770 from vngrs/prevent_duplicated_where_clausesRafael Mendonça França2015-08-131-0/+7
|\ \ | | | | | | Prevent duplicating `where` clauses
| * | Prevent duplicating `where` clauses when model is extended from an abstract ↵Mehmet Emin İNAÇ2015-04-151-0/+7
| |/ | | | | | | | | | | | | | | | | | | class Fixes #19528 fix for mysql2 test better test
* | Skip statement cache on through association readerRafael Mendonça França2015-08-125-0/+40
| | | | | | | | | | | | | | If the through class has default scopes we should skip the statement cache. Closes #20745.
* | use correct DB connection for generated HABTM tableMatt Hanlon2015-08-071-0/+5
| |
* | Merge pull request #20849 from vngrs/misleading_nested_exceptionsRafael Mendonça França2015-07-271-3/+4
|\ \ | | | | | | Fix misleading errors for has_one through relations
| * | Fix misleading errors for has_one through relationsMehmet Emin İNAÇ2015-07-221-3/+4
| | |
* | | Rename the enum_{prefix,suffix} options to _{prefix,suffix}Robin Dupret2015-07-231-4/+4
| | | | | | | | | | | | | | | | | | This makes it more clear that they are reserved keywords and also it seems less redundant as the line already starts with the call to the `enum` method.
* | | fix rails testsMehmet Emin İNAÇ2015-07-211-1/+1
|/ /
* | Correctly ignore `mark_for_destruction` without `autosave`Sean Griffin2015-07-201-0/+1
| | | | | | | | | | | | | | | | | | As per the docs, `mark_for_destruction` should do nothing if `autosave` is not set to true. We normally persist associations on a record no matter what if the record is a new record, but we were always skipping records which were `marked_for_destruction?`. Fixes #20882
* | Fix counter_cache for polymorphic associationsStefan Kanev2015-07-191-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Also removes a false positive test that depends on the fixed bug: At this time, counter_cache does not work with polymorphic relationships (which is a bug). The test was added to make sure that no StaleObjectError is raised when the car is destroyed. No such error is currently raised because the lock version is not incremented by appending a wheel to the car. Furthermore, `assert_difference` succeeds because `car.wheels.count` does not check the counter cache, but the collection size. The test will fail if it is replaced with `car.wheels_count || 0`.
* | Ensure cyclic associations w/ autosave don't cause duplicate errorsSean Griffin2015-07-181-0/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This code is so fucked. Things that cause this bug not to replicate: - Defining the validation before the association (we end up calling `uniq!` on the errors in the autosave validation) - Adding `accepts_nested_attributes_for` (I have no clue why. The only thing it does that should affect this is adds `autosave: true` to the inverse reflection, and doing that manually doesn't fix this). This solution is a hack, and I'm almost certain there's a better way to go about it, but this shouldn't cause a huge hit on validation times, and is the simplest way to get it done. Fixes #20874.
* | Fix regression caused by a01d164bRafael Mendonça França2015-07-071-0/+16
| | | | | | | | | | | | | | | | | | When preload is used in a default scope the preload_values were returning nested arrays and causing the preloader to fail because it doesn't know how to deal with nested arrays. So before calling preload! we need to splat the arguments. This is not needed to includes because it flatten its arguments.
* | Add pending test for the great-grandparent touching bug from #19324David Heinemeier Hansson2015-06-252-0/+8
| |
* | Add enum prefix/suffix option to enum definitionIgor Kapkov2015-06-121-0/+4
| | | | | | | | Fixes #17511 and #17415
* | Fix crash when loading fixture with belongs_to association defined in ↵Victor Costan2015-06-041-0/+12
| | | | | | | | abstract base class.
* | allow setting of a demodulized class name when using STIAlex Robbin2015-05-111-0/+3
|/ | | | | | | | | | | | | | | | | | | | | If your STI class looks like this: ```ruby class Company < ActiveRecord::Base self.store_full_sti_class = false class GoodCo < Company end class BadCo < Company end end ``` The expectation (which is valid) is that the `type` in the database is saved as `GoodCo` or `BadCo`. However, another expectation should be that setting `type` to `GoodCo` would correctly instantiate the object as a `Company::GoodCo`. That second expectation is what this should fix.
* Fix leaky chain on polymorphic associationeileencodes2015-03-153-0/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* Merge pull request #18996 from morgoth/deprecate-more-errors-methodsYves Senn2015-02-192-2/+2
|\ | | | | | | Deprecate `ActiveModel::Errors` `add_on_empty` and `add_on_blank` methods
| * Deprecate `ActiveModel::Errors` `add_on_empty` and `add_on_blank` methodsWojciech Wnętrzak2015-02-192-2/+2
| | | | | | | | without replacement.
* | Add `ActiveRecord::Base.suppress`Michael Ryan2015-02-182-0/+6
|/
* Add line endings to files which are missing themSean Griffin2015-02-176-6/+6
| | | | | | These files get modified whenever someone uses a tool like `sed`. Let's just get this over with in one commit so it'd not adding diff noise to something else.
* Merge pull request #18512 from vipulnsward/18492-fixtures-with-stiAaron Patterson2015-01-312-3/+7
|\ | | | | Fix STI for fixtures from multi-files
| * Fixes #18492Vipul A M2015-01-142-3/+7
| | | | | | | | | | | | | | - Add check for not deleting previously created fixtures, to overcome sti fixtures from multiple files - Added fixtures and fixtures test to verify the same - Fixed wrong fixtures duplicating data insertion in same table
* | Always perform validations on nested attribute associationsSean Griffin2015-01-301-1/+2
| | | | | | | | | | | | | | Collection associations would have already been validated, but singular associations were not. Fixes #18735.
* | Added #or to ActiveRecord::RelationMatthew Draper2015-01-281-0/+3
| | | | | | | | | | | | | | Post.where('id = 1').or(Post.where('id = 2')) # => SELECT * FROM posts WHERE (id = 1) OR (id = 2) [Matthew Draper & Gael Muller]
* | Don't redefine autosave association callbacks in nested attrsSean Griffin2015-01-282-0/+2
| | | | | | | | | | | | | | | | These callbacks will already have been defined when the association was built. The check against `reflection.autosave` happens at call time, not at define time, so simply modifying the reflection is sufficient. Fixes #18704
* | Improve consistency of counter caches updating in memorySean Griffin2015-01-261-1/+1
|/ | | | | | | | | | | | | | | | | When we made sure that the counter gets updated in memory, we only did it on the has many side. The has many side only does the update if the belongs to cannot. The belongs to side was updated to update the counter cache (if it is able). This means that we need to check if the belongs_to is able to update in memory on the has_many side. We also found an inconsistency where the reflection names were used to grab the association which should update the counter cache. Since reflection names are now strings, this means it was using a different instance than the one which would have the inverse instance set. Fixes #18689 [Sean Griffin & anthonynavarre]
* remove deprecated support to preload instance-dependent associaitons.Yves Senn2015-01-051-4/+0
| | | | Addresses https://github.com/rails/rails/commit/ed56e596a0467390011bc9d56d462539776adac1#commitcomment-9145960
* Add has_secure_token to Active Recordrobertomiranda2015-01-041-0/+4
| | | | | | Update SecureToken Docs Add Changelog entry for has_secure_token [ci skip]
* Deprecate `false` as the way to halt AR callbacksclaudiob2015-01-025-5/+5
| | | | | | | | | | Before this commit, returning `false` in an ActiveRecord `before_` callback such as `before_create` would halt the callback chain. After this commit, the behavior is deprecated: will still work until the next release of Rails but will also display a deprecation warning. The preferred way to halt a callback chain is to explicitly `throw(:abort)`.
* Merge pull request #15309 from iantropov/issue_12698_build_throughRafael Mendonça França2015-01-021-0/+2
|\ | | | | | | | | | | | | | | Add setting of FK for throgh associations while building Conflicts: activerecord/CHANGELOG.md activerecord/test/cases/associations/has_many_through_associations_test.rb
| * Add setting of FK for throgh associations while buildingIvan Antropov2014-05-251-0/+2
| |
* | Fix error message when trying to create an associated recordRafael Mendonça França2014-12-301-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | This error only happens when the foreign key is missing. Before this fix the following exception was being raised: NoMethodError: undefined method `val' for #<Arel::Nodes::BindParam:0x007fc64d19c218> Now the message is: ActiveRecord::UnknownAttributeError: unknown attribute 'foreign_key' for Model.
* | AR specific length validator to respect `marked_for_destruction`.Yves Senn2014-12-301-0/+2
| | | | | | | | | | | | | | | | Closes #7247. Conflicts: activerecord/CHANGELOG.md activerecord/test/models/owner.rb
* | Remove all cases of manuallly wrapping `Arel::Nodes::Quoted`Sean Griffin2014-12-291-1/+1
| | | | | | | | | | | | | | | | | | | | This is no longer required now that we are injecting a type caster object into the Arel table, with the exception of uniqueness validations. Since it calls `ConnectionAdapter#type_cast`, the value has already been cast for the database. We don't want Arel to attempt to cast it further, so we need to continue wrapping it in a quoted node. This can potentially go away when this validator is refactored to make better use of `where` or the predicate builder.
* | Inform Arel we don't need additional type casting in testsSean Griffin2014-12-261-1/+1
| | | | | | | | | | | | | | Part of the larger refactoring to remove type casting from Arel. We can inform it that we already have the right type by wrapping the value in an `Arel::Nodes::Quoted`. This commit can be reverted when we have removed type casting from Arel in Rail 5.1
* | Don't perform statement caching for `find` when called from a scopeSean Griffin2014-12-221-0/+8
| | | | | | | | | | | | | | | | If there is a method defined such as `find_and_do_stuff(id)`, which then gets called on an association, we will perform statement caching and the parent ID will not change on subsequent calls. Fixes #18117
* | Add foreign_type option for polymorphic has_one and has_many.Ulisses Almeida + Kassio Borges2014-12-082-0/+6
| | | | | | | | | | | | | | To be possible to use a custom column name to save/read the polymorphic associated type in a has_many or has_one polymorphic association, now users can use the option :foreign_type to inform in what column the associated object type will be saved.
* | Fix "nonexistent" typo in testsMelissa Xie2014-12-022-4/+4
| |
* | Pass symbol as an argument instead of a blockErik Michaels-Ober2014-11-293-4/+4
| |
* | Fix includes on association with a scope containing joins along with conditionssiddharth@vinsol.com2014-11-211-0/+1
| | | | | | | | on the joined assoiciation
* | Ensure HABTM relationships produce valid class names (Fixes #17119)Sammy Larbi2014-11-091-0/+2
| |
* | Use bind values for joined tables in where statementsSean Griffin2014-11-012-0/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | In practical terms, this allows serialized columns and tz aware columns to be used in wheres that go through joins, where they previously would not behave correctly. Internally, this removes 1/3 of the cases where we rely on Arel to perform type casting for us. There were two non-obvious changes required for this. `update_all` on relation was merging its bind values with arel's in the wrong order. Additionally, through associations were assuming there would be no bind parameters in the preloader (presumably because the where would always be part of a join) [Melanie Gilman & Sean Griffin]
* | Raise an error for has_one associations which try to go :through a ↵Tu Hoang2014-10-151-0/+3
| | | | | | | | polymorphic association [#17263]
* | make sure cache is not used for collection assocations tooAaron Patterson2014-10-141-0/+1
| | | | | | | | follow up for #17052
* | Autosave callbacks shouldn't be `after_save`Agis-2014-10-131-0/+9
| | | | | | | | | | | | | | | | | | | | | | | | 068f092ced8483e557725542dd919ab7c516e567 registered autosave callbacks as `after_save` callbacks. This caused the regression described in #17209. Autosave callbacks should be registered as `after_update` and `after_create` callbacks, just like before. This is a partial revert of 068f092ced8483e557725542dd919ab7c516e567. Fixes #17209.
* | Better regression test for Fixtures with fk as a symbolArthur Neves2014-09-221-1/+1
| |