aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test
Commit message (Collapse)AuthorAgeFilesLines
...
* | | | | | | Merge branch 'brainopia-remember_frozen_state_in_transaction'Sean Griffin2014-12-261-0/+15
|\ \ \ \ \ \ \
| * | | | | | | Propagate frozen state during transaction changesbrainopia2014-12-261-0/+14
|/ / / / / / /
* | | | | | | Correctly ignore `case_sensitive` for UUID uniqueness validationSean Griffin2014-12-261-0/+17
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | I think we should deprecate this behavior and just error if you tell us to do a case insensitive comparison for types which are not case sensitive. Partially reverts 35592307 Fixes #18195
* | | | | | | Dump the default `nil` for PostgreSQL UUID primary key.Ryuta Kamizono2014-12-261-0/+6
| | | | | | |
* | | | | | | Don't treat `nil` as changed in serialized typesSean Griffin2014-12-231-0/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | We were ignoring the `default_value?` escape clause in the serialized type, which caused the default value to always be treated as changed. Fixes #18169
* | | | | | | Merge pull request #18167 from al2o3cr/checkin_connection_leakSean Griffin2014-12-231-0/+30
|\ \ \ \ \ \ \ | | | | | | | | | | | | | | | | Fix connection leak when a thread checks in additional connections.
| * | | | | | | Fix connection leak when a thread checks in additional connections.Matt Jones2014-12-231-0/+30
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The code in `ConnectionPool#release` assumed that a single thread only ever holds a single connection, and thus that releasing a connection only requires the owning thread_id. There is a trivial counterexample to this assumption: code that checks out additional connections from the pool in the same thread. For instance: connection_1 = ActiveRecord::Base.connection connection_2 = ActiveRecord::Base.connection_pool.checkout ActiveRecord::Base.connection_pool.checkin(connection_2) connection_3 = ActiveRecord::Base.connection At this point, connection_1 has been removed from the `@reserved_connections` hash, causing a NEW connection to be returned as connection_3 and the loss of any tracking info on connection_1. As long as the thread in this example lives, connection_1 will be inaccessible and un-reapable. If this block of code runs more times than the size of the connection pool in a single thread, every subsequent connection attempt will timeout, as all of the available connections have been leaked. Reverts parts of 9e457a8654fa89fe329719f88ae3679aefb21e56 and essentially all of 4367d2f05cbeda855820e25a08353d4b7b3457ac
* | | | | | | | Merge Pull Request #18157Sean Griffin2014-12-231-0/+10
|\ \ \ \ \ \ \ \ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Conflicts: activerecord/CHANGELOG.md
| * | | | | | | | Don't raise on out-of-range datetimes passed by a userGrey Baker2014-12-231-0/+10
| |/ / / / / / /
* / / / / / / / Fixing numeric attrs when set to same negative valueDaniel Fox2014-12-232-0/+10
|/ / / / / / / | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This bug occurs when an attribute of an ActiveRecord model is an ActiveRecord::Type::Integer type or a ActiveRecord::Type::Decimal type (or any other type that includes the ActiveRecord::Type::Numeric module. When the value of the attribute is negative and is set to the same negative value, it is marked as changed. Take the following example of a Person model with the integer attribute age: class Person < ActiveRecord::Base # age :integer(4) end The following will produce the error: person = Person.new(age: -1) person.age = -1 person.changes => { "age" => [-1, -1] } person.age_changed? => true The problematic line is here: module ActiveRecord module Type module Numeric ... def non_numeric_string?(value) # 'wibble'.to_i will give zero, we want to make sure # that we aren't marking int zero to string zero as # changed. value.to_s !~ /\A\d+\.?\d*\z/ end end end end The regex match doesn't accept numbers with a leading '-'.
* | | | | | | Don't perform statement caching for `find` when called from a scopeSean Griffin2014-12-222-1/+31
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* | | | | | | Don't calculate all in-place changes to determine if attribute_changed?Sean Griffin2014-12-221-0/+15
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Calling `changed_attributes` will ultimately check if every mutable attribute has changed in place. Since this gets called whenever an attribute is assigned, it's extremely slow. Instead, we can avoid this calculation until we actually need it. Fixes #18029
* | | | | | | Don't wrap `create_table` in a transaction for tests which run on MySQLSean Griffin2014-12-221-3/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | PG will warn without it, but mysql2 errors out.
* | | | | | | Add `foreign_key` as an option to `references` for `change_table`Sean Griffin2014-12-221-0/+43
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This has the same comments as 9af90ffa00ba35bdee888e3e1ab775ba0bdbe72c, however it affects the `add_reference` method, and `t.references` in the context of a `change_table` block. There is a lot of duplication of code between creating and updating tables. We should re-evaluate the structure of this code from a high level so changes like this don't need to be made in two places. (Note to self)
* | | | | | | Add a `foreign_key` option to `references` while creating the tableSean Griffin2014-12-221-0/+60
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Rather than having to do: create_table :posts do |t| t.references :user end add_foreign_key :posts, :users You can instead do: create_table :posts do |t| t.references :user, foreign_key: true end Similar to the `index` option, you can also pass a hash. This will be passed as the options to `add_foreign_key`. e.g.: create_table :posts do |t| t.references :user, foreign_key: { primary_key: :other_id } end is equivalent to create_table :posts do |t| t.references :user end add_foreign_key :posts, :users, primary_key: :other_id
* | | | | | | Add `force: true` to table created in testsSean Griffin2014-12-221-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | If the test is interrupted in a way that the teardown block fails to run, the tests will fail to run until the table is removed manually without this option.
* | | | | | | Correctly handle limit on int4 and int8 types in PGSean Griffin2014-12-221-0/+25
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | PG doesn't register it's types using the `int(4)` format that others do. As such, if we alias `int8` to the other integer types, the range information is lost. This is fixed by simply registering it separately. The other option (which I specifically chose to avoid) is to pass the information of the original type that was being aliased as an argument. I'd rather avoid that, since an alias should truly be treated the same. If we need different behavior for a different type, we should explicitly register it with that, and not have a conditional based on aliasing. Fixes #18144 [Sean Griffin & ysbaddaden]
* | | | | | | Correctly handle Float -> BigDecimal with unspecified precisionSean Griffin2014-12-221-0/+5
| |/ / / / / |/| | | | | | | | | | | | | | | | | Fixes #18122
* | | | | | `force: :cascade` to recreate tables referenced by foreign-keys.Yves Senn2014-12-193-1/+37
| | | | | |
* | | | | | Relax the UUID regexGodfrey Chan2014-12-181-3/+7
|/ / / / / | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Apparently PG does not validate against RFC 4122. The intent of the original patch is just to protect against PG errors (which potentially breaks txns, etc) because of bad user input, so we shouldn't try any harder than PG itself. Closes #17931
* | | | | Remove unused lineRyuta Kamizono2014-12-171-1/+0
| | | | |
* | | | | `update_column` take ruby-land input, not database-land inputSean Griffin2014-12-161-2/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | In the case of serialized columns, we would expect the unserialized value as input, not the serialized value. The original issue which made this distinction, #14163, introduced a bug. If you passed serialized input to the method, it would double serialize when it was sent to the database. You would see the wrong input upon reloading, or get an error if you had a specific type on the serialized column. To put it another way, `update_column` is a special case of `update_all`, which would take `['a']` and not `['a'].to_yaml`, but you would not pass data from `params` to it. Fixes #18037
* | | | | Add test case for joined pluckSean Griffin2014-12-111-0/+7
| | | | | | | | | | | | | | | | | | | | https://github.com/rails/rails/commit/39542fba54328ca048fb75a5d5b37f8e1d4c1f37#commitcomment-8938379
* | | | | Improve the test case introduced by bd0d47eSean Griffin2014-12-111-19/+10
| | | | |
* | | | | Merge pull request #17994 from mfazekas/pluck-bind-values-masterSean Griffin2014-12-111-0/+24
|\ \ \ \ \ | | | | | | | | | | | | Fix ProtocolViolation/bind message for polymorphic + pluck or group+calc
| * | | | | Fix ProtocolViolation/bind message supplies for polymorphic + pluck or groupMiklos Fazkeas2014-12-111-0/+24
| | | | | |
* | | | | | Fix undesirable RangeError by Type::Integer. Add Type::UnsignedInteger.Ryuta Kamizono2014-12-123-0/+78
|/ / / / /
* | | | | Merge pull request #17970 from ulissesalmeida/foreign-type-has-many-has-oneRafael Mendonça França2014-12-105-0/+32
|\ \ \ \ \ | | | | | | | | | | | | Add foreign_type option for polymorphic has_one and has_many.
| * | | | | Add foreign_type option for polymorphic has_one and has_many.Ulisses Almeida + Kassio Borges2014-12-085-0/+32
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* | | | | | Unused csv fixture fileAkira Matsuda2014-12-091-1/+0
| | | | | |
* | | | | | Merge pull request #17972 from claudiob/remove-unused-callback-fixturesCarlos Antonio da Silva2014-12-091-46/+0
|\ \ \ \ \ \ | | | | | | | | | | | | | | Remove unused "Developer" fixtures from tests
| * | | | | | Remove unused "Developer" fixtures from testsclaudiob2014-12-081-46/+0
| |/ / / / / | | | | | | | | | | | | | | | | | | | | | | | | The `RecursiveCallbackDeveloper` and `ImmutableMethodDeveloper` classes are not used anymore in tests, and neither is the `@cancelled` variable.
* | | | | | Update test case for TZ aware attributesSean Griffin2014-12-081-4/+14
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The test added in 42418cfc94d1356d35d28d786f63e7fab9406ad6 wasn't actually testing anything, since the bug was with TZ aware attributes only.
* | | | | | Allow custom handling of non-standard types in `time_zone_conversion`Sean Griffin2014-12-081-0/+6
|/ / / / / | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | PostgreSQL for example, allows infinity as a valid value for date time columns. The PG type has explicit handling for that case. However, time zone conversion will end up trampling that handling. Unfortunately, we can't call super and then convert time zones. However, if we get back nil from `.in_time_zone`, it's something we didn't expect so we can let the superclass handle it. Fixes #17971
* | | | | Don't error when `attributes` is called on a frozen AR modelSean Griffin2014-12-081-0/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | `freeze` will ultimately end up freezing the `AttributeSet`, which in turn freezes its `@attributes` hash. However, we actually insert a special object to lazily instantiate the values of the hash on demand. When it does need to actually instantiate all of them for iteration (the only case is `ActiveRecord::Base#attributes`, which calls `AttributeSet#to_h`), it will set an instance variable as a performance optimization Since it's just an optimization for subsequent calls, and that method being called at all is a very uncommon case, we can just leave the ivar alone if we're frozen, as opposed to coming up with some overly complicated mechanism for freezing which allows us to continue to modify ourselves. Fixes #17960
* | | | | Revert to 4.1 behavior for casting PG arraysSean Griffin2014-12-081-5/+20
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The user is able to pass PG string literals in 4.1, and have it converted to an array. This is also possible in 4.2, but it would remain in string form until saving and reloading, which breaks our `attr = save.reload.attr` contract. I think we should deprecate this in 5.0, and only allow array input from user sources. However, this currently constitutes a breaking change to public API that did not go through a deprecation cycle.
* | | | | Make error message clearer that :on requires a symbol, not a stringCarol Nichols2014-12-071-0/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The validation added in 5a3dc8092d19c816b0b1203945639cb91d065847 will reject values for the `:on` option for after_commit and after_rollback callbacks that are string values like `"create"`. However, the error message says ":on conditions for after_commit and after_rollback callbacks have to be one of create,destroy,update". That looks like a string value *would* be valid. This commit changes the error message to say ":on conditions for after_commit and after_rollback callbacks have to be one of [:create, :destroy, :update]", making it clearer that symbols are required.
* | | | | Add `force: true` to tables created in PG testsSean Griffin2014-12-052-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | If the tests are interupted and the teardown block doesn't run, the developer needs to delete these manually in order to be able to run the tests again.
* | | | | Correctly respect subtypes for PG arrays and rangesSean Griffin2014-12-051-0/+18
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The type registration was simply looking for the OID, and eagerly fetching/constructing the sub type when it was registered. However, numeric types have additional parameters which are extracted from the actual SQL string of the type during lookup, and can have their behavior change based on the result. We simply need to use the block form of registration, and look up the subtype lazily instead. Fixes #17935
* | | | | Merge pull request #17919 from mrgilman/stop-supporting-nested-arraysSean Griffin2014-12-042-30/+0
|\ \ \ \ \ | | | | | | | | | | | | Remove deprecated behavior allowing nested arrays as query values
| * | | | | Remove deprecated behavior allowing nested arrays as query valuesMelanie Gilman2014-12-042-30/+0
| | | | | |
* | | | | | Correctly handle multiple attribute method prefix/suffixes which matchSean Griffin2014-12-041-0/+10
|/ / / / / | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Active Record defines `attribute_method_suffix :?`. That suffix will match any predicate method when the lookup occurs in Active Model. This will make it incorrectly decide that `id_changed?` should not exist, because it attempts to determine if the attribute `id_changed` is present, rather than `id` with the `_changed?` suffix. Instead, we will look for any correct match.
* | | | | Deprecate `Class` handler in `PredicateBuilder`Melanie Gilman2014-12-041-1/+3
| | | | | | | | | | | | | | | | | | | | Users should pass strings to queries instead of classes
* | | | | Prevent Symbol GCRyuta Kamizono2014-12-041-0/+3
| | | | |
* | | | | Failure to rollback t.timestamps when within a change_table migrationnoam2014-12-034-6/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When running the following migration: change_table(:table_name) { |t| t/timestamps } The following error was produced: wrong number of arguments (2 for 1) .... /connection_adapters/abstract/schema_statements.rb:851:in `remove_timestamps' This is due to `arguments` containing an empty hash as its second argument.
* | | | | skip test to get `sqlite3_mem` suite passing.Yves Senn2014-12-031-1/+1
| | | | |
* | | | | Merge pull request #17889 from mxie/mx-fix-nonexistent-typoSean Griffin2014-12-025-8/+8
|\ \ \ \ \ | | | | | | | | | | | | Fix "nonexistent" typo in tests
| * | | | | Fix "nonexistent" typo in testsMelissa Xie2014-12-025-8/+8
| | | | | |
* | | | | | Require missing association in testSean Griffin2014-12-021-0/+1
|/ / / / /
* | | | | Refactor `build_from_hash` to convert dot notation to hash firstMelanie Gilman2014-12-021-0/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This ensures that we're handling all forms of nested tables the same way. We're aware that the `convert_dot_notation_to_hash` method will cause a performance hit, and we intend to come back to it once we've refactored some of the surrounding code. [Melissa Xie & Melanie Gilman]