aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test
Commit message (Collapse)AuthorAgeFilesLines
* Merge pull request #31696 from BrentWheeldon/bmw-connection-pool-load-deadlockMatthew Draper2018-08-241-0/+38
|\ | | | | Prevent deadlocks when waiting for connection from pool.
| * Prevent deadlocks when waiting for connection from pool.Brent Wheeldon2018-03-231-0/+38
| | | | | | | | | | When a thread that had the load interlock but was blocked waiting to check a connection out of the connection pool but all of the threads using the available connections were blocked waiting to obtain the load interlock an `ActiveRecord::ConnectionTimeoutError` exception was be thrown by the thread waiting for the connection. When waiting for the connection to check out we should allow loading to proceed to avoid this deadlock.
* | Fix typo s/Topic/Tag/Ryuta Kamizono2018-08-231-1/+1
| | | | | | | | `Topic` isn't loaded in this test file.
* | Merge pull request #32647 from eugeneius/lazy_transactionsMatthew Draper2018-08-238-3/+82
|\ \ | | | | | | Omit BEGIN/COMMIT statements for empty transactions
| * | Omit BEGIN/COMMIT statements for empty transactionsEugene Kenny2018-08-138-3/+82
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | If a transaction is opened and closed without any queries being run, we can safely omit the `BEGIN` and `COMMIT` statements, as they only exist to modify the connection's behaviour inside the transaction. This removes the overhead of those statements when saving a record with no changes, which makes workarounds like `save if changed?` unnecessary. This implementation buffers transactions inside the transaction manager and materializes them the next time the connection is used. For this to work, the adapter needs to guard all connection use with a call to `materialize_transactions`. Because of this, adapters must opt in to get this new behaviour by implementing `supports_lazy_transactions?`. If `raw_connection` is used to get a reference to the underlying database connection, the behaviour is disabled and transactions are opened eagerly, as we can't know how the connection will be used. However when the connection is checked back into the pool, we can assume that the application won't use the reference again and reenable lazy transactions. This prevents a single `raw_connection` call from disabling lazy transactions for the lifetime of the connection.
* | | Merge pull request #33162 from utilum/stop_using_mochaKasper Timm Hansen2018-08-227-53/+88
|\ \ \ | | | | | | | | Stop using Mocha
| * | | Add method_call_assertions and use them instead of Mochautilum2018-08-134-36/+58
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Six Mocha calls prove quite resistant to Minitestification. For example, if we replace ``` ActiveRecord::Associations::HasManyAssociation .any_instance .expects(:reader) .never ``` with `assert_not_called`, Minitest wisely raises ``` NameError: undefined method `reader' for class `ActiveRecord::Associations::HasManyAssociation' ``` as `:reader` comes from a deeply embedded abstract class, `ActiveRecord::Associations::CollectionAssociation`. This patch tackles this difficulty by adding `ActiveSupport::Testing::MethodCallAsserts#assert_called_on_instance_of` which injects a stubbed method into `klass`, and verifies the number of times it is called, similar to `assert_called`. It also adds a convenience method, `assert_not_called_on_instance_of`, mirroring `assert_not_called`. It uses the new method_call_assertions to replace the remaining Mocha calls in `ActiveRecord` tests. [utilum + bogdanvlviv + kspath]
| * | | Stub with Minitest and test with MethodCallAssertionsutilum2018-08-133-17/+30
| |/ /
* | | Add database configuration to disable advisory locks.Guo Xiang Tan2018-08-223-0/+41
| | | | | | | | | | | | https://github.com/rails/rails/issues/31190
* | | Fix merging relation that order including `?`Ryuta Kamizono2018-08-211-0/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The `Relation::Merger` has a problem that order values would be merged as nested array. That was caused an issue #33664 since if array value is passed to `order` and first element in the array includes `?`, the array is regarded as a prepared statement and bind variables. https://api.rubyonrails.org/classes/ActiveRecord/Sanitization/ClassMethods.html#method-i-sanitize_sql_for_order Just merging that as splat args like other values would fix the issue. Fixes #33664.
* | | Merge pull request #33652 from tgxworld/improve_tests_pool_configRyuta Kamizono2018-08-202-5/+50
|\ \ \ | | | | | | | | Improve tests for ActiveRecord::ConnectionAdapters::ConnectionPool co…
| * | | Speed up slow ConnectionPool test case.Guo Xiang Tan2018-08-201-11/+19
| | | |
| * | | Improve tests for ActiveRecord::ConnectionAdapters::ConnectionPool ↵Guo Xiang Tan2018-08-192-2/+39
| | | | | | | | | | | | | | | | configurations.
* | | | Merge pull request #33657 from jychen7/fix-test-association-enumRyuta Kamizono2018-08-201-0/+3
|\ \ \ \ | | | | | | | | | | Improve test case to test enum correctly
| * | | | Improve test case to test enum correctlyRich2018-08-201-0/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | without define the enum in class “SpecialBook”, any string status will be casted to integer 0. Then the test have no meaning. [Rich Chen]
* | | | | SQLite3: Fix rename reference column not to lose foreign key constraintRyuta Kamizono2018-08-201-0/+16
|/ / / / | | | | | | | | | | | | Fixes #33520.
* / / / Address intermittent CI failure due to non-determined sort orderRyuta Kamizono2018-08-191-1/+1
|/ / / | | | | | | | | | https://travis-ci.org/rails/rails/jobs/417783260#L1173-L1179
* | | Ensure `foreign_keys` assertions after alter tableRyuta Kamizono2018-08-191-1/+5
| | | | | | | | | | | | | | | If `foreign_keys` is fetched before alter table, it couldn't notice whether foreign keys are broken or not after alter table.
* | | Merge pull request #33585 from yahonda/diag33520Ryuta Kamizono2018-08-161-0/+13
|\ \ \ | | | | | | | | | | | | SQLite3 adapter `alter_table` method restores foreign keys
| * | | SQLite3 adapter `alter_table` method restores foreign keysYasuo Honda2018-08-111-0/+13
| |/ / | | | | | | | | | Related to #33520
* | | Merge pull request #33603 from kamipo/fix_numericality_validatorRyuta Kamizono2018-08-163-2/+26
|\ \ \ | | | | | | | | Fix numericality validator not to be affected by custom getter
| * | | Fix numericality validator not to be affected by custom getterRyuta Kamizono2018-08-133-2/+26
| |/ / | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Since fe9547b6, numericality validator would parse raw value only when a value came from user to work type casting to a value from database. But that was caused a regression that the validator would work against getter value instead of parsed raw value, a getter is sometimes customized by people. #33550 There we never guarantees that the value before type cast was going to the used in this validation (actually here is only place that getter value might not be used), but we should not change the behavior unless there is some particular reason. The purpose of fe9547b6 is to work type casting to a value from database. We could achieve the purpose by using `read_attribute`, without using getter value. Fixes #33550.
* | | Fix bulk change table ignores comment option on PostgreSQL.Yoshiyuki Kinjo2018-08-151-2/+11
| | |
* | | Follow up #33530bogdanvlviv2018-08-151-0/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | - Move changelog entry of #33530 up in order to preserve the chronology since we always add new entries on the top of a changelog file. - Clarify the changelog entry - Clarify the docs of remove_foreign_key - Ensure reversible of `remove_foreign_key` with `:primary_key` and `:to_table` options.
* | | Allow `to_table` in `invert_remove_foreign_key`Rich2018-08-141-0/+8
|/ / | | | | | | | | | | | | | | | | | | | | | | remove_foreign_key supports - remove_foreign_key :accounts, :branches - remove_foreign_key :accounts, to_table: :branches but the second one is not reversible. This branch is to fix and allow second one to be reversible. [Nikolay Epifanov, Rich Chen]
* | Fix a wrong correctionKazuhiro Sera2018-08-081-1/+1
| |
* | Fix the obvious typos detected by github.com/client9/misspellKazuhiro Sera2018-08-085-16/+16
| |
* | Call build when extend with nested attributes definedAlireza Bashiri2018-08-022-1/+19
| | | | | | | | | | | | | | | | What? From now on when `accepts_nested_attributes_for` defined and `extend` option added the overwritten `build` method being called. [Alireza Bashiri, Martins Polakovs]
* | Revert "Merge pull request #24131 from brchristian/limit_and_primary_key"Ryuta Kamizono2018-08-011-15/+0
| | | | | | | | | | | | | | | | | | | | This reverts commit d162188dd662a7d9f62ba8431474f50bc35e3e93, reversing changes made to 3576782888c307e3e192c44e332b957cd1174128. Reason: #24131 conflicts the #5153's default order contract, it means that existing apps would be broken by that change. We don't want to break existing apps without a deprecation cycle.
* | Add test case for the #5153's default order contractRyuta Kamizono2018-08-011-0/+13
| |
* | Avoid extra scoping when using `Relation#update`Ryuta Kamizono2018-07-311-0/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Since 9ac7dd4, class level `update`, `destroy`, and `delete` were placed in the `Persistence` module as class methods. But `Relation#update` without passing ids which was introduced at #11898 is not a class method, and it was caused the extra scoping regression #33470. I moved the relation method back into the `Relation` to fix the regression. Fixes #33470.
* | MySQL: Raise ActiveRecord::InvalidForeignKey for foreign-key constraint ↵George Claghorn2018-07-301-5/+16
| | | | | | | | violations on delete
* | Don't expose configuration for a test.Kasper Timm Hansen2018-07-281-2/+3
| | | | | | | | Clean up some concepts in the code while we're here.
* | Avoid logging ActiveRecord::LogSubscriber as the query source when the ↵lsylvester2018-07-281-0/+13
| | | | | | | | source is ignored (#33455)
* | PostgreSQL 10 new relkind for partitioned tables (#31336)Yannick Schutz2018-07-271-0/+22
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * PostgreSQL 10 new relkind for partitioned tables Starting with PostgreSQL 10, we can now have partitioned tables natively * Add comment * Remove extra space * Add test for partition table in postgreSQL10 * Select 'p' for "BASE TABLE" and add a test case to support PostgreSQL 10 partition tables * Address RuboCop offense * Addressed incorrect `postgresql_version` Fixes #33008. [Yannick Schutz & Yasuo Honda & Ryuta Kamizono]
* | Remove Rubocop's comments from Rails code basebogdanvlviv2018-07-261-1/+1
| | | | | | | | | | | | | | | | | | | | PR#32381 added Rubocop's comments to some tests files in order to exclude `Performance/RedundantMerge`. Turn off `Performance` cops for tests files via `Exclude` in `.rubocop.yml`. Context https://github.com/rails/rails/pull/32381#discussion_r205212331
* | Merge pull request #32381 from q-centrix/update-codeclimate-configsRichard Schneeman2018-07-252-13/+13
|\ \ | | | | | | Turn on performance based cops
| * | Turn on performance based copsDillon Welch2018-07-232-13/+13
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Use attr_reader/attr_writer instead of methods method is 12% slower Use flat_map over map.flatten(1) flatten is 66% slower Use hash[]= instead of hash.merge! with single arguments merge! is 166% slower See https://github.com/rails/rails/pull/32337 for more conversation
* | | Normalize time value not to be affected by summer timeRyuta Kamizono2018-07-252-10/+40
|/ / | | | | | | Follow up of #33358 for SQLite3.
* | Merge pull request #30919 from seanlinsley/17622-before_save_strict_argumentsRyuta Kamizono2018-07-231-0/+27
|\ \ | | | | | | | | | Add strict argument checking to ActiveRecord callbacks
| * | add strict argument checking to ActiveRecord callbacksSean Linsley2018-07-221-0/+23
|/ / | | | | | | This ends up adding it to all save-related callbacks defined in `ActiveRecord::DefineCallbacks`, including e.g. `after_create`. Which should be fine: they didn't support `:on` in the first place.
* | Replace permissive Mocha expectationsutilum2018-07-222-32/+86
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Step 6 in #33162 When using Mocha like this: `ActiveRecord::Base.expects(:establish_connection).with(some_args)`, the expectations created look something like this: ``` @expectations= [#<Expectation:0x561350d968e0 expected exactly once, not yet invoked: ActiveRecord::Base.establish_connection("adapter" => "mysql2", "database" => nil) >, #<Expectation:0x561350dab8f8 allowed any number of times, not yet invoked: ActiveRecord::Base.establish_connection(any_parameters) >, #<Expectation:0x561350dc30c0 allowed any number of times, not yet invoked: ActiveRecord::Base.connection(any_parameters) >] ``` Minitest mocking (and the way we use it in `MethodCallAssertions`) expressly refuses to facilitate such permissiive expectations, insisting that all calls be specified in the actual expected order. This patch replaces such calls to `Mocha#expects` with `ActiveSupport::Testing::MethodCallAssertions` and specifies all expected calls in the epxected order.
* | Replace Mocha#stubs with assert_called_withutilum2018-07-221-6/+11
| | | | | | | | A correct, but not obvious use of `ActiveSupport::Testing::MethodCallAssertions`, which might also have been part of #33337 or #33391.
* | Fix Mocha replacement that slipped out of #33337utilum2018-07-221-11/+15
| |
* | tests for use of primary_key with limitBrian Christian2018-07-191-0/+15
| |
* | Merge pull request #33394 from kamipo/avoid_extra_scopingEileen M. Uchitelle2018-07-192-0/+6
|\ \ | | | | | | Avoid extra scoping in delegating to klass methods in the `scope` block
| * | Avoid extra scoping in delegating to klass methods in the `scope` blockRyuta Kamizono2018-07-192-0/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Since #29301, delegating to klass methods in the `scope` block would cause extra scoping by the receiver itself. The extra scoping would always override intermediate scoping like `unscoped` and caused the regression #33387. To keep the original scoping behavior, should avoid the extra scoping in the `scope` block. Fixes #33387.
* | | Merge pull request #33391 from utilum/method_call_assertions_instead_of_mochaRyuta Kamizono2018-07-195-98/+154
|\ \ \ | |/ / |/| | Use MethodCallAssertions instead of Mocha#expects
| * | Use MethodCallAssertions instead of Mocha#expectsutilum2018-07-195-98/+154
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Many calls to `Mocha#expects` preceded the introduction of `ActiveSupport::Testing::MethodCallAssertions` in 53f64c0fb, and many are simple to replace with `MethodCallAssertions`. This patch makes all these simple replacements. Step 5 in #33162
* | | Fix `insert_fixtures_set` to be restored original connection flagsRyuta Kamizono2018-07-191-5/+80
|/ / | | | | | | | | | | #33363 has two regressions. First one is that `insert_fixtures_set` is failed if flags is an array. Second one is that connection flags are not restored if `set_server_option` is not supported.