aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test
Commit message (Collapse)AuthorAgeFilesLines
* Add ActiveRecord::Relation#in_batchesSina Siadat2015-08-071-2/+230
| | | | | | | | | | | | | | | | | `in_batches` yields Relation objects if a block is given, otherwise it returns an instance of `BatchEnumerator`. The existing `find_each` and `find_in_batches` methods work with batches of records. The new API allows working with relation batches as well. Examples: Person.in_batches.each_record(&:party_all_night!) Person.in_batches.update_all(awesome: true) Person.in_batches.delete_all Person.in_batches.map do |relation| relation.delete_all sleep 10 # Throttles the delete queries end
* Merge pull request #20459Sean Griffin2015-08-061-0/+93
|\
| * Add missing data types for ActiveRecord migrationsMehmet Emin İNAÇ2015-06-081-0/+93
| |
* | Merge pull request #21092 from vngrs/use_memoization_for_ids_readerRafael Mendonça França2015-08-061-0/+8
|\ \ | | | | | | Use memoization for collection associations ids reader
| * | Use memoization for collection associations ids readerMehmet Emin İNAÇ2015-08-031-0/+8
| | | | | | | | | | | | | | | | | | Fixes #21082 remove extra space
* | | Fix ambiguous argument warningMehmet Emin İNAÇ2015-08-021-1/+1
|/ / | | | | | | encapsulate all arguments
* | Merge pull request #20884Sean Griffin2015-08-011-0/+70
|\ \ | | | | | | | | | Add #cache_key to ActiveRecord::Relation.
| * | Add #cache_key to ActiveRecord::Relation.Alberto F. Capel2015-07-201-0/+70
| | |
* | | Merge pull request #20849 from vngrs/misleading_nested_exceptionsRafael Mendonça França2015-07-273-4/+12
|\ \ \ | | | | | | | | Fix misleading errors for has_one through relations
| * | | Fix misleading errors for has_one through relationsMehmet Emin İNAÇ2015-07-223-4/+12
| | | |
* | | | Remove @connection instance variable only when definedYasuo Honda2015-07-261-2/+2
| | | |
* | | | Properly allow uniqueness validations on primary keys.Sean Griffin2015-07-251-0/+19
| | | | | | | | | | | | | | | | | | | | | | | | This is an alternate implementation of #20966. [Sean Griffin & presskey]
* | | | `destroy` shouldn't raise when child associations fail to saveSean Griffin2015-07-241-0/+30
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Deep down in the association internals, we're calling `destroy!` rather than `destroy` when handling things like `dependent` or autosave association callbacks. Unfortunately, due to the structure of the code (e.g. it uses callbacks for everything), it's nearly impossible to pass whether to call `destroy` or `destroy!` down to where we actually need it. As such, we have to do some legwork to handle this. Since the callbacks are what actually raise the exception, we need to rescue it in `ActiveRecord::Callbacks`, rather than `ActiveRecord::Persistence` where it matters. (As an aside, if this code wasn't so callback heavy, it would handling this would likely be as simple as changing `destroy` to call `destroy!` instead of the other way around). Since we don't want to lose the exception when `destroy!` is called (in particular, we don't want the value of the `record` field to change to the parent class), we have to do some additional legwork to hold onto it where we can use it. Again, all of this is ugly and there is definitely a better way to do this. However, barring a much more significant re-architecting for what I consider to be a reletively minor improvement, I'm willing to take this small hit to the flow of this code (begrudgingly).
* | | | Remove ivar only when definedAkira Matsuda2015-07-241-2/+2
| | | | | | | | | | | | | | | | this fixes a failing test case
* | | | 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
|/ / /
* | | Deprecate and rename the keys for association restrict_dependent_destroyRoque Pinel2015-07-202-0/+39
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Previously `has_one` and `has_many` associations were using the `one` and `many` keys respectively. Both of these keys have special meaning in I18n (they are considered to be pluralizations) so by renaming them to `has_one` and `has_many` we make the messages more explicit and most importantly they don't clash with linguistical systems that need to validate translation keys (and their pluralizations). The `:'restrict_dependent_destroy.one'` key should be replaced with `:'restrict_dependent_destroy.has_one'`, and `:'restrict_dependent_destroy.many'` with `:'restrict_dependent_destroy.has_many'`. [Roque Pinel & Christopher Dell]
* | | Ensure that microsecond precision is only used for version of mysql that ↵Jori Hardman2015-07-203-1/+37
| | | | | | | | | | | | support it. Fixes #19711
* | | Fix minor typo in test nameSean Griffin2015-07-201-1/+1
| | |
* | | Fix state being carried over from previous transactionRoque Pinel2015-07-201-0/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This clears the transaction record state when the transaction finishes with a `:committed` status. Considering the following example where `name` is a required attribute. Before we had `new_record?` returning `true` for a persisted record: ```ruby author = Author.create! name: 'foo' author.name = nil author.save # => false author.new_record? # => true ```
* | | Correctly ignore `mark_for_destruction` without `autosave`Sean Griffin2015-07-202-0/+8
|/ / | | | | | | | | | | | | | | | | 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 the test that was broken by #16445 rather than deleting itSean Griffin2015-07-191-0/+12
| | | | | | | | | | | | | | | | Since the counter cache was properly being updated, the model became stale. Simply reloading the model before attempting to destroy is sufficient for this case. I believe this is enough of an edge case to be a valid change to the tests, even though it represents a potential breaking change.
* | Fix counter_cache for polymorphic associationsStefan Kanev2015-07-194-12/+15
| | | | | | | | | | | | | | | | | | | | | | | | | | | | 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`.
* | Merge pull request #20932 from twalpole/collection_association_parametersSean Griffin2015-07-181-1/+13
|\ \ | | | | | | Ensure that 'ActionController::Parameters' can still be passed to AR …
| * | Ensure that 'ActionController::Parameters' can still be passed to AR for ↵Thomas Walpole2015-07-181-1/+13
| | | | | | | | | | | | collection associations
* | | Ensure cyclic associations w/ autosave don't cause duplicate errorsSean Griffin2015-07-183-0/+23
|/ / | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* | Ensure that `ActionController::Parameters` can still be passed to ARSean Griffin2015-07-181-0/+23
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Since nested hashes are also instances of `ActionController::Parameters`, and we're explicitly looking to work with a hash for nested attributes, this caused breakage in several points. This is the minimum viable fix for the issue (and one that I'm not terribly fond of). I can't think of a better place to handle this at the moment. I'd prefer to use some sort of solution that doesn't special case AC::Parameters, but we can't use something like `to_h` or `to_a` since `Enumerable` adds both. While I've added a trivial test case for verifying this fix in isolation, we really need better integration coverage to prevent regressions like this in the future. We don't actually have a lot of great places for integration coverage at the moment, so I'm deferring it for now. Fixes #20922.
* | Silence deprecation warning from force reloadPrem Sichanugrist2015-07-1610-105/+125
| | | | | | | | | | | | | | | | | | | | | | | | We deprecate the support for passing an argument to force reload in 6eae366d0d2e5d5211eeaf955f56bd1dc6836758. That led to several deprecation warning when running Active Record test suite. This commit silence the warnings by properly calling `#reload` on the association proxy or on the association object instead. However, there are several places that `ActiveSupport::Deprecation.silence` are used as those tests actually tests the force reload functionality and will be removed once `master` is targeted next minor release (5.1).
* | Deprecate force association reload by passing truePrem Sichanugrist2015-07-156-0/+36
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This is to simplify the association API, as you can call `reload` on the association proxy or the parent object to get the same result. For collection association, you can call `#reload` on association proxy to force a reload: @user.posts.reload # Instead of @user.posts(true) For singular association, you can call `#reload` on the parent object to clear its association cache then call the association method: @user.reload.profile # Instead of @user.profile(true) Passing a truthy argument to force association to reload will be removed in Rails 5.1.
* | Replaced `ActiveSupport::Concurrency::Latch` with concurrent-ruby.Jerry D'Antonio2015-07-132-21/+21
| | | | | | | | | | | | | | | | | | | | The concurrent-ruby gem is a toolset containing many concurrency utilities. Many of these utilities include runtime-specific optimizations when possible. Rather than clutter the Rails codebase with concurrency utilities separate from the core task, such tools can be superseded by similar tools in the more specialized gem. This commit replaces `ActiveSupport::Concurrency::Latch` with `Concurrent::CountDownLatch`, which is functionally equivalent.
* | Fix regression caused by a01d164bRafael Mendonça França2015-07-072-0/+35
| | | | | | | | | | | | | | | | | | 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 test proving that accepts_nested_attributes_for is secure against ID ↵Victor Costan2015-07-071-0/+10
| | | | | | | | tampering attacks.
* | Fix spelling of `Thoughtleadering`eileencodes2015-07-021-1/+1
| | | | | | | | Not much of a thought leader if I can't spell it correctly :wink:
* | Use default model enum in fixtures if not definedeileencodes2015-07-022-0/+11
| | | | | | | | | | | | | | | | | | | | | | After 908cfef was introduced fixtures that did not set an enum would return nil instead of the default enum value. The fixtures should assume the default if a different enum is not defined. The change checks first if the enum is defined in the fixture before setting it based on the fixture.
* | Correct through associations using scopesSean Griffin2015-06-301-0/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The changes introduced to through associations in c80487eb were quite interesting. Changing `relation.merge!(scope)` to `relation = relation.merge(scope)` should in theory never cause any changes in behavior. The subtle breakage led to a surprising conclusion. The old code wasn't doing anything! Since `merge!` calls `instance_exec` when given a proc, and most scopes will look something like `has_many :foos, -> { where(foo: :bar) }`, if we're not capturing the return value, it's a no-op. However, removing the `merge` causes `unscope` to break. While we're merging in the rest of the chain elsewhere, we were never merging in `unscope` values, causing a breakage on associations where a default scope was being unscoped in an association scope (yuk!). This is subtly related to #20722, since it appears we were previously relying on this mutability. Fixes #20721. Fixes #20727.
* | Merge pull request #20699 from ↵Rafael Mendonça França2015-06-271-0/+31
|\ \ | | | | | | | | | | | | vngrs/foreign_key_with_table_name_suffix_and_prefix Add table name prefix and suffix support for foreign keys
| * | Add table name prefix and suffix support to add_foreign_key and ↵Mehmet Emin İNAÇ2015-06-251-0/+31
| | | | | | | | | | | | | | | | | | remove_foreign_key methods fix tests
* | | Add reversible syntax for change_column_defaultPrem Sichanugrist2015-06-262-0/+17
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Passing `:from` and `:to` to `change_column_default` makes this command reversible as user has defined its previous state. So, instead of having the migration command as: change_column_default(:posts, :state, "draft") They can write it as: change_column_default(:posts, :state, from: nil, to: "draft")
* | | Merge pull request #20677 from jmondo/decimal-default-stringSean Griffin2015-06-253-3/+8
|\ \ \ | | | | | | | | Display decimal defaults as strings to keep precision
| * | | Display decimal defaults as strings to keep precisionJohn Gesimondo2015-06-233-3/+8
| | | |
* | | | Add pending test for the great-grandparent touching bug from #19324David Heinemeier Hansson2015-06-256-0/+72
|/ / /
* | | Merge pull request #20552 from jamesdabbs/belongs-to-polymorphic-force-reloadYves Senn2015-06-231-0/+2
|\ \ \ | | | | | | | | | | | | Fix `undefined method uncached` for polymorphic belongs_to #20426
| * | | Fix `undefined method uncached` for polymorphic belongs_to #20426James Dabbs2015-06-131-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Unitialized polymorphic `belongs_to` associations raise an error while attempting to reload, as they attempt to make an uncached reload, but don't have a klass to fetch uncachedly. In this case, `loaded?` should be `false` anyway.
* | | | Merge pull request #20545 from dcrec1/20541Yves Senn2015-06-231-0/+26
|\ \ \ \ | |_|/ / |/| | | | | | | thrown ActiveRecord::AssociationTypeMismatch when assigning a wrong value for a namespaced association
| * | | thrown ActiveRecord::AssociationTypeMismatch when assigning a wrong value ↵Diego Carrion2015-06-221-0/+18
|/ / / | | | | | | | | | | | | for a namespaced association fixes #20541
* | | AR absence validator respects `marked_for_destruction?`. Closes #20449.Yves Senn2015-06-221-0/+75
| | | | | | | | | | | | Associated objects that were marked for destruction are considered absent.
* | | fix test not failing when executed isolatedDiego Carrion2015-06-191-1/+1
| | | | | | | | | | | | | | | the test was created in 7659fb6 the fixtures were added in c092dbe
* | | Use `Enumerable#sum` on `ActiveRecord::Relation` when a block is givenSean Griffin2015-06-191-0/+10
| | | | | | | | | | | | | | | | | | | | | | | | This matches our behavior in other cases where useful enumerable methods might have a different definition in `Relation`. Wanting to actually enumerate over the records in this case is completely reasonable, and wanting `.sum` is reasonable for the same reason it is on `Enumerable` in the first place.
* | | Merge pull request #19843 from marshall-lee/explain_cte_queriesYves Senn2015-06-191-0/+5
|\ \ \ | | | | | | | | | | | | | | | | | | | | | | | | Let WITH (CTE) queries be explainable Conflicts: activerecord/CHANGELOG.md
| * | | Let WITH (CTE) queries be explainableVladimir Kochnev2015-05-281-0/+5
| | | |