aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/associations
Commit message (Collapse)AuthorAgeFilesLines
* add `extend` option on `has_and_belongs_to_many`.keepcosmos2015-05-261-0/+15
|
* deprecate `Relation#uniq` use `Relation#distinct` instead.Yves Senn2015-05-264-11/+11
| | | | | | | | | See #9683 for the reasons we switched to `distinct`. Here is the discussion that triggered the actual deprecation #20198. `uniq`, `uniq!` and `uniq_value` are still around. They will be removed in the next minor release after Rails 5.
* remove duplicate test.Yves Senn2015-05-081-10/+2
| | | | | | | | | The old `test_create_bang_returns_falsy_when_join_record_has_errors` had a missleading name and was a duplicate of `test_save_should_not_raise_exception_when_join_record_has_errors`. Since it had an assertion on the return value I renamed it accordingly and got rid of the duplicate test.
* AR::RecordNotSaved & RecordNotDestroyed should include an error messageYuki Nishijima2015-05-011-1/+2
| | | | | | | When `AR::Base.save!` or `AR::Base.destroy!` is called and an exception is raised, the exception doesn't have any error message or has a weird message like `#<FailedBulb:0x0000000907b4b8>`. Give a better message so we can easily understand why it's failing to save/destroy.
* Rename association option :class to :anonymous_classAndrew White2015-04-213-14/+14
| | | | | | | | | | | | | In 1f006c an option was added called :class to allow passing anonymous classes to association definitions. Since using :class instead of :class_name is a fairly common typo even amongst experienced developers this can result in hard to debug errors arising in raise_on_type_mismatch? To fix this we're renaming the option from :class to :anonymous_class as that is a more correct description of what the option is for. Since this was an internal, undocumented option there is no need for a deprecation. Fixes #19659
* Batch touch parent recordsArthur Neves2015-04-081-0/+18
| | | | | | | | | | [fixes #18606] Make belongs_to use touch over touch_later when running the callbacks. Add more tests and small method rename Thanks Jeremy for the feedback.
* Fix a regression introduced by removing unnecessary db call when replacingShintaro Kojima2015-04-041-0/+2
| | | | When replacing a has_many association with the same one, there is nothing to do with database but a setter method should still return the substituted value for backward compatibility.
* Fix eager loading association using default_scope for finder methods.Santosh Wadghule2015-03-311-0/+17
| | | | | | - Eager loading was not working for the default_scope (class method) for 'find' & 'find_by' methods. - Fixed these by adding a new check 'respond_to?(:default_scope)'.
* Merge pull request #19348 from Empact/null-scopeYves Senn2015-03-181-0/+12
|\ | | | | | | | | | | | | Reuse the CollectionAssociation#reader proxy cache if the foreign key is present from the start. Conflicts: activerecord/CHANGELOG.md
| * Reuse the CollectionAssociation#reader proxy cache if the foreign key is ↵Ben Woosley2015-03-151-0/+12
| | | | | | | | | | | | | | | | | | | | present from the start. When a new record has the necessary information prior to save, we can avoid busting the cache. We could simply clear the @proxy on #reset or #reset_scope, but that would clear the cache more often than necessary.
* | Closes rails/rails#18864: Renaming transactional fixtures to transactional testsBrandon Weiss2015-03-163-3/+3
|/ | | | | | | | | | | | | | | | | | | | | | | | | I’m renaming all instances of `use_transcational_fixtures` to `use_transactional_tests` and “transactional fixtures” to “transactional tests”. I’m deprecating `use_transactional_fixtures=`. So anyone who is explicitly setting this will get a warning telling them to use `use_transactional_tests=` instead. I’m maintaining backwards compatibility—both forms will work. `use_transactional_tests` will check to see if `use_transactional_fixtures` is set and use that, otherwise it will use itself. But because `use_transactional_tests` is a class attribute (created with `class_attribute`) this requires a little bit of hoop jumping. The writer method that `class_attribute` generates defines a new reader method that return the value being set. Which means we can’t set the default of `true` using `use_transactional_tests=` as was done previously because that won’t take into account anyone using `use_transactional_fixtures`. Instead I defined the reader method manually and it checks `use_transactional_fixtures`. If it was set then it should be used, otherwise it should return the default, which is `true`. If someone uses `use_transactional_tests=` then it will overwrite the backwards-compatible method with whatever they set.
* Revert ":cut: remove unnecessary rescue Exceptions"Yves Senn2015-03-061-1/+1
| | | | | | | | | | | | | | | | | This reverts commit ff18049ca6f27deb7e7f955478e1464f8d756332. This broke the AR build for every adapter: 1) Error: AssociationCallbacksTest#test_dont_add_if_before_callback_raises_exception: Exception: You can't add a post 2) Failure: QueryCacheTest#test_query_cache_doesnt_leak_cached_results_of_rolled_back_queries [/Users/senny/Projects/rails/activerecord/test/cases/query_cache_test.rb:235]: Expected: 1 Actual: 0 I'm reverting to get the build green again.
* :cut: remove unnecessary rescue ExceptionsAaron Patterson2015-03-051-1/+1
|
* Merge pull request #19105 from amatsuda/array_takeSean Griffin2015-03-021-0/+13
|\ | | | | Preserve Array#take(n) behaviour of HasManyAssociation
| * Preserve Array#take(n) behaviour of HasManyAssociationAkira Matsuda2015-02-281-0/+13
| |
* | Merge pull request #19077 from robin850/unknown-attribute-errorSean Griffin2015-03-021-1/+1
|\ \ | |/ |/| Move `UnknownAttributeError` to a more sane namespace
| * Follow-up to #10776Robin Dupret2015-02-261-1/+1
| | | | | | | | | | | | | | | | | | | | The name `ActiveModel::AttributeAssignment::UnknownAttributeError` is too implementation specific so let's move the constant directly under the ActiveModel namespace. Also since this constant used to be under the ActiveRecord namespace, to make the upgrade path easier, let's avoid raising the former constant when we deal with this error on the Active Record side.
* | Properly create through records when called with `where`Sean Griffin2015-02-261-0/+6
| | | | | | | | | | | | | | | | | | | | | | Various behaviors needed by associations (such as creating the through record) are lost when `where` is called, since we stop having a `CollectionProxy` and start having an `AssociationRelation` which does not contain this behavior. I *think* we should be able to rm `AssociationRelation`, but we have tests saying the changes required to do that would be bad (Without saying why. Of course. >_>) Fixes #19073.
* | Merge pull request #17297 from ↵Rafael Mendonça França2015-02-251-0/+25
|\ \ | |/ |/| | | | | rebyn/fix/17161-remove-objs-from-has_many-updates-fields Add specs for adding-to/clear has_many collections’s behavior on `updated_at`
| * Add specs for adding-to/clear has_many collections’s behavior on `updated_at`Tu Hoang2014-10-301-0/+25
| | | | | | | | | | | | | | | | | | | | | | There are behaviors mentioned in #17161 that: 1. are not documented properly, and 2. don't have specs This commit addresses the spec absence. For has_many collections, 1. addition (<<) should update the associated object's updated_at (if any) 2. .clear, depending on options[:dependent], calls delete_all, destroy_all, or nullifies the associated object(s)' foreign key.
* | Require `belongs_to` by default.Josef Šimánek2015-02-211-0/+50
| | | | | | | | Deprecate `required` option in favor of `optional` for belongs_to.
* | Merge branch 'rm-take' into 4-1-stableRafael Mendonça França2015-02-201-1/+29
| |
* | Optimize none? and one? relation query methods to use LIMIT and COUNT.Eugene Gilburg2015-02-121-0/+76
| | | | | | | | | | | | | | | | Use SQL COUNT and LIMIT 1 queries for none? and one? methods if no block or limit is given, instead of loading the entire collection to memory. The any? and many? methods already follow this behavior. [Eugene Gilburg & Rafael Mendonça França]
* | Merge branch 'master' into pr/18316Mingdong Luo2015-01-317-70/+45
|\ \ | | | | | | | | | | | | Conflicts: activerecord/CHANGELOG.md
| * | Provide a better error message on :required associationHenrik Nygren2015-01-281-2/+22
| | | | | | | | | | | | Fixes #18696.
| * | Use an `Attribute` object to represent a bind valueSean Griffin2015-01-271-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The column is primarily used for type casting, which we're trying to separate from the idea of a column. Since what we really need is the combination of a name, type, and value, let's use the object that we already have to represent that concept, rather than this tuple. No consumers of the bind values have been changed, only the producers (outside of tests which care too much about internals). This is *finally* possible since the bind values are now produced from a reasonable number of lcoations.
| * | `WhereClause#predicates` does not need to be publicSean Griffin2015-01-273-13/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The only place it was accessed was in tests. Many of them have another way that they can test their behavior, that doesn't involve reaching into internals as far as they did. `AssociationScopeTest` is testing a situation where the where clause would have one bind param per predicate, so it can just ignore the predicates entirely. The where chain test was primarly duplicating the logic tested on `WhereClause` directly, so I instead just make sure it calls the appropriate method which is fully tested in isolation.
| * | Test association was eager loaded, rather than reaching into internalsSean Griffin2015-01-261-2/+2
| | |
| * | Remove all references to `where_values` in testsSean Griffin2015-01-253-11/+11
| | |
| * | Extracted `ActiveRecord::AttributeAssignment` to ↵Bogdan Gusiev2015-01-231-1/+1
| | | | | | | | | | | | | | | | | | `ActiveModel::AttributesAssignment` Allows to use it for any object as an includable module.
| * | Merge pull request #18458 from brainopia/fix_after_commit_for_fixturesJeremy Kemper2015-01-201-1/+0
| |\ \ | | | | | | | | Support after_commit callbacks in transactional fixtures
| | * | after_commit runs after transactions with non-joinable parentsbrainopia2015-01-161-1/+0
| | | | | | | | | | | | | | | | | | | | | | | | after_commit callbacks run after committing a transaction whose parent is not `joinable?`: un-nested transactions, transactions within test cases, and transactions in `console --sandbox`.
| * | | tests, use `drop_table if_exists: true` in our test suite.Yves Senn2015-01-201-2/+2
| |/ /
| * | remove deprecated support to preload instance-dependent associaitons.Yves Senn2015-01-051-22/+9
| | | | | | | | | | | | Addresses https://github.com/rails/rails/commit/ed56e596a0467390011bc9d56d462539776adac1#commitcomment-9145960
| * | Remove deprecated automatic counter caches on `has_many :through`Rafael Mendonça França2015-01-041-26/+0
| | |
* | | Fix n+1 query problem when eager loading nil associations (fixes #18312)Sammy Larbi2015-01-031-0/+8
|/ /
* | Merge pull request #15309 from iantropov/issue_12698_build_throughRafael Mendonça França2015-01-021-1/+10
|\ \ | | | | | | | | | | | | | | | | | | | | | 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-1/+10
| | |
* | | Remove support to activerecord-deprecated_findersRafael Mendonça França2015-01-021-2/+1
| | |
* | | Merge pull request #15746 from amccloud/auto-inverse_of-in-moduleRafael Mendonça França2015-01-021-0/+12
|\ \ \ | | | | | | | | | | | | | | | | | | | | | | | | Fixed automatic inverse_of for models nested in module Conflicts: activerecord/CHANGELOG.md
| * | | Fixed automatic inverse_of for models nested in moduleAndrew McCloud2014-06-151-0/+12
| | | |
* | | | Fix warning: assigned but unused variable - postRyuta Kamizono2014-12-311-1/+1
| | | |
* | | | Fix error message when trying to create an associated recordRafael Mendonça França2014-12-301-0/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* | | | Share foreign_key_present? implementation in _has_ associationsbrainopia2014-12-312-35/+57
| | | |
* | | | `eager_load` preserves readonly flag for associationsTakashi Kokubun2014-12-301-1/+4
| | | |
* | | | Add foreign_type option for polymorphic has_one and has_many.Ulisses Almeida + Kassio Borges2014-12-082-0/+21
| | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* | | | Merge pull request #17889 from mxie/mx-fix-nonexistent-typoSean Griffin2014-12-023-4/+4
|\ \ \ \ | | | | | | | | | | Fix "nonexistent" typo in tests
| * | | | Fix "nonexistent" typo in testsMelissa Xie2014-12-023-4/+4
| | | | |
* | | | | Require missing association in testSean Griffin2014-12-021-0/+1
|/ / / /
* | | | Pass symbol as an argument instead of a blockErik Michaels-Ober2014-11-297-20/+18
| | | |