aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases
Commit message (Collapse)AuthorAgeFilesLines
* 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-181-0/+8
|/ | | | | | | | | | | | | | | | 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-071-0/+19
| | | | | | | | | 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.
* Use default model enum in fixtures if not definedeileencodes2015-07-021-0/+6
| | | | | | | | | | | 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-251-0/+21
|/ /
* | 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
| | |
* | | raise ActiveModel::MissingAttributeError when trying to access a ↵Diego Carrion2015-06-161-0/+4
| | | | | | | | | | | | | | | | | | | | | | | | relationship without the foreign key attribute fixes regression reported on #20253 ActiveRecord::Base#[] was not used cause of 8b95420
* | | Merge pull request #20257 from ↵Arthur Nogueira Neves2015-06-151-0/+6
|\ \ \ | | | | | | | | | | | | | | | | prathamesh-sonpatki/test-for-serial-for-quoted-sequence Added test case for serial? method when sequence name is not quoted
| * | | Added test case for serial? method when sequence name is not quotedPrathamesh Sonpatki2015-05-221-0/+6
| | | | | | | | | | | | | | | | - Followup of https://github.com/rails/rails/pull/20190/.
* | | | make `remove_index :table, :column` reversible.Yves Senn2015-06-152-6/+15
| |_|/ |/| | | | | | | | | | | | | | | | | | | | | | | This used to raise a `IrreversibleMigration` error (since #10437). However since `remove_index :table, :column` is probably the most basic use-case we should make it reversible again. Conflicts: activerecord/CHANGELOG.md
* | | Add a test to ensure `serialize` persists `nil` as `NULL`Sean Griffin2015-06-121-0/+8
| | |
* | | Don't crash when mutating attributes in a getterSean Griffin2015-06-121-0/+16
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | If a getter has side effects on the DB, `changes_applied` will be called twice. The second time will try and remove the changed attributes cache, and will crash because it's already been unset. This also demonstrates that we shouldn't assume that calling getters won't change the value of `changed_attributes`, and we need to clear the cache if an attribute is modified. Fixes #20531.
* | | Merge pull request #20480 from senny/test_runnerYves Senn2015-06-1277-223/+227
|\ \ \ | | | | | | | | use our own runner for Rails framework components `bin/test`
| * | | make it possible to run AR tests with bin/testYves Senn2015-06-1177-223/+227
| | | |
* | | | Merge pull request #20226 from EpicH0liday/reversible-remove-foreign-keyYves Senn2015-06-121-1/+30
|\ \ \ \ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Make remove_foreign_key reversible Conflicts: activerecord/CHANGELOG.md
| * | | | Add an invert method for remove_foreign_keyAster Ryan2015-06-111-1/+30
| | | | |
* | | | | Add enum prefix/suffix option to enum definitionIgor Kapkov2015-06-121-0/+50
|/ / / / | | | | | | | | | | | | Fixes #17511 and #17415
* | | | Add a missing test case for the persistence behavior of `serialize`Sean Griffin2015-06-111-0/+13
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | `serialize` makes the contract that if it is given a class name, it will never return something other than an instance of that class. This means that it must cast `nil` to the empty form of that object. As such, we should then persist empty forms of that object as `nil`. While this is techincally under the contract of ``` model.attribute = value assert_equal model.attribute, model.tap(&:save).reload.attribute ``` which we can't actually test universally without property based testing, it has come up more than once and is worth calling out specifically since we aren't looking to change it.
* | | | Correctly handle array columns with defaults in the schema dumperSean Griffin2015-06-111-0/+5
|/ / / | | | | | | | | | | | | | | | | | | | | | | | | If the subtype provides custom schema dumping behavior, we need to defer to it. We purposely choose not to handle any values other than an array (which technically should only ever be `nil`, but I'd rather code defensively here). Fixes #20515.
* | | Merge pull request #20437 from pwnall/abstract_fixturesRafael Mendonça França2015-06-091-0/+10
|\ \ \ | | | | | | | | Fix crash when loading fixture with belongs_to association defined in abstract base class
| * | | Fix crash when loading fixture with belongs_to association defined in ↵Victor Costan2015-06-041-0/+10
| | | | | | | | | | | | | | | | abstract base class.
* | | | Return a `Point` object from the PG Point typeSean Griffin2015-06-051-11/+108
|/ / / | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This introduces a deprecation cycle to change the behavior of the default point type in the PostgreSQL adapter. The old behavior will continue to be available for the immediate future as `:legacy_point`. The current behavior of returning an `Array` causes several problems, the most significant of which is that we cannot differentiate between an array of points, and a point itself in the case of a column with the `point[]` type. The attributes API gives us a reasonable way to have a proper deprecation cycle for this change, so let's take advantage of it. If we like this change, we can also add proper support for the other geometric types (line, lseg, box, path, polygon, and circle), all of which are just aliases for string today. Fixes #20441
* | | Apply Active Record suppression to all savesGeorge Claghorn2015-06-041-1/+32
| | | | | | | | | | | | | | | | | | | | | It was not being applied to creates and updates attempted through the non-bang save methods. This means that, for example, creation of records for singular associations through the `create_*` methods was not appropriately ignored in .suppress blocks.
* | | Skip test that fails from outdated sqlite3 on travisSean Griffin2015-06-021-7/+9
| | |
* | | Fix postgresql DISTINCT requirement in pluck testKevin Deisz2015-06-021-2/+2
| | |
* | | Merge pull request #20362 from kddeisz/enumerable_pluckRafael Mendonça França2015-06-011-0/+21
|\ \ \ | | | | | | | | Allow Enumerable#pluck to take a splat.
| * | | Allow Enumerable#pluck to take a splat.Kevin Deisz2015-05-291-0/+21
| | | | | | | | | | | | | | | | | | | | | | | | This allows easier integration with ActiveRecord, such that AR#pluck will now use Enumerable#pluck if the relation is loaded, without needing to hit the database.
* | | | Map :bigint as NUMBER(19) sql_type by using `:limit => 19` for OracleYasuo Honda2015-06-012-2/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | since NUMBER(8) is not enough to store the maximum number of bigint. Oracle NUMBER(p,0) as handled as integer because there is no dedicated integer sql data type exist in Oracle database. Also NUMBER(p,s) precision can take up to 38. p means the number of digits, not the byte length. bigint type needs 19 digits as follows. $ irb 2.2.2 :001 > limit = 8 => 8 2.2.2 :002 > maxvalue_of_bigint = 1 << ( limit * 8 - 1) => 9223372036854775808 2.2.2 :003 > puts maxvalue_of_bigint.to_s.length 19 => nil 2.2.2 :004 >
* | | | Ensure symbols passed to `select` are always quotedSean Griffin2015-05-301-0/+22
|/ / / | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Our general contract in Active Record is that strings are assumed to be SQL literals, and symbols are assumed to reference a column. If a from clause is given, we shouldn't include the table name, but we should still quote the value as if it were a column. Upon fixing this, the tests were still failing on SQLite. This was because the column name being returned by the query was `"\"join\""` instead of `"join"`. This is actually a bug in SQLite that was fixed a long time ago, but I was using the version of SQLite included by OS X which has this bug. Since I'm guessing this will be a common case for contributors, I also added an explicit check with a more helpful error message. Fixes #20360
* | | Persist user provided default values, even if unchangedSean Griffin2015-05-282-26/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This is a usability change to fix a quirk from our definition of partial writes. By default, we only persist changed attributes. When creating a new record, this is assumed that the default values came from the database. However, if the user provided a default, it will not be persisted, since we didn't see it as "changed". Since this is a very specific case, I wanted to isolate it with the other quirks that come from user provided default values. The number of edge cases which are presenting themselves are starting to make me wonder if we should just remove the ability to assign a default, in favor of overriding `initialize`. For the time being, this is required for the attributes API to not have confusing behavior. We had to delete one test, since this actually changes the meaning of `.changed?` on Active Record models. It now specifically means `changed_from_database?`. While I think this will make the attributes API more ergonomic to use, it is a subtle change in definition (though not a backwards incompatible one). We should probably figure out the right place to document this. (Feel free to open a PR doing that if you're reading this). /cc @rafaelfranca @kirs @senny This is an alternate implementation of #19921. Close #19921. [Sean Griffin & Kir Shatrov]