aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test
Commit message (Collapse)AuthorAgeFilesLines
* Fix dirty tracking for `touch`Ryuta Kamizono2019-04-152-4/+21
| | | | | | | | | | Before this fix, `touch` only clears dirty tracking for touched attributes, doesn't track saved (touched) changes. This fixes that tracks saved changes and carry over remaining changes. Fixes #33429. Closes #34306.
* Merge pull request #35970 from yskkin/reversible_commentRyuta Kamizono2019-04-153-0/+122
|\ | | | | make change_column_comment and change_table_comment invertible
| * make change_column_comment and change_table_comment invertibleYoshiyuki Kinjo2019-04-153-0/+122
| | | | | | | | | | | | | | | | | | We can revert migrations using `change_column_comment` or `change_table_comment` at current master. However, results are not what we expect: comments are remained in new status. This change tells previous comment to these methods in a way like `change_column_default`.
* | Don't expose `add_to_transaction`Ryuta Kamizono2019-04-142-4/+4
|/ | | | | | | | | | | | | | `add_to_transaction` was added at da840d1, but it should not be called by except internal, since `remember_transaction_record_state` should be called only once before saving. And also, currently `add_to_transaction` doesn't always add the record to transaction since da8de91, that is the reason hard to use that even in internal. Even if `add_to_transaction` ensure to add the record to transaction, that is an internal concern, people don't need to explicitly call `add_to_transaction`.
* Merge pull request #35966 from shioyama/define_validator_on_topic_subclassRyuta Kamizono2019-04-141-5/+7
|\ | | | | Add validation to subclass in tests to avoid polluting parent class
| * Add validation to subclass in tests to avoid polluting parent classChris Salzberg2019-04-131-5/+7
| | | | | | | | | | | | | | | | | | | | These two tests currently both define acceptance validators on the same class, Topic. This means that in either one test or the other, there are not one but *two* instances of the LazilyDefineAttributes module builder in the class' ancestors, which can result in unpredictable results. Subclassing Topic in each test avoids conflicts.
* | Merge pull request #35958 from yskkin/bulk_change_tableRyuta Kamizono2019-04-141-7/+17
|\ \ | |/ |/| use PostgreSQL's bulk_alter_table implementation
| * use PostgreSQL's bulk_alter_table implementationYoshiyuki Kinjo2019-04-131-7/+17
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Running this migration on mysql at current master fails because `add_references_for_alter` is missing. ``` change_table :users, bulk: true do |t| t.references :article end ``` This is also true for postgresql adapter, but its `bulk_alter_table` implementation can fallback in such case. postgresql's implementation is desirable to prevent unknown failure like this.
* | Auto-correct `Style/StringLiterals` cop offencesRyuta Kamizono2019-04-131-4/+4
| | | | | | | | Somehow Code Climate is not working as expected for now?
* | Fix `presicion` -> `precision`yuuji.yaginuma2019-04-132-6/+6
| | | | | | | | This fix is necessary to test precision's default correctly.
* | Fix test flakyness due to `test_truncate_tables`Guilherme Mansur2019-04-121-0/+16
|/ | | | | | | | | | | | | `Truncate Tables posts` will also reset the `AUTOINCREMENT` this causes a situation where if a test suite that uses the `taggings` fixtures runs and subsequently the `test_truncate_tables` run, newly created posts would reference the `tagging` in the database. This commit resest the state of the posts table after the `connection.truncate` call in the `test_truncate_tables`, as well as all other tests that call `trucate` This ensures the associations and db state remain consistent after the tests. Fixes: https://github.com/rails/rails/issues/35941
* Merge pull request #35918 from ↵Ryuta Kamizono2019-04-121-6/+8
|\ | | | | | | | | kamipo/lazy_sync_with_transaction_state_on_destroy Lazy sync with transaction state on destroy
| * Lazy sync with transaction state on destroyRyuta Kamizono2019-04-101-6/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This reverts commit 58410b3d566e6b93c7b71c0eec0fc11ec906b68e. If we have any implicit commit/rollback callbacks, it is necessary to add record to transaction explicitly like `:touch_deferred_attributes`. https://github.com/rails/rails/blob/5f261d04d6f857d49c75124df809adfbd6cd5b5e/activerecord/lib/active_record/touch_later.rb#L9 https://github.com/rails/rails/blob/5f261d04d6f857d49c75124df809adfbd6cd5b5e/activerecord/lib/active_record/touch_later.rb#L25 But I can't find any other implicit commit/rollback callbacks in our code base at least now. I think the `self.class.connection.add_transaction_record(self)` line doesn't cover any behavior.
* | Merge pull request #35920 from ↵Ryuta Kamizono2019-04-122-4/+26
|\ \ | | | | | | | | | | | | kamipo/dont_call_commit_callbacks_for_invalid_record Don't call after_commit callbacks despite a record isn't saved
| * | Don't call after_commit callbacks despite a record isn't savedRyuta Kamizono2019-04-122-4/+26
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Regardless of a record isn't saved (e.g. validation is failed), `after_commit` / `after_rollback` callbacks are invoked for now. To fix the issue, this adds a record to the current transaction only when a record is actually saved. Fixes #29747. Closes #29833.
* | | Fix `automatic_inverse_of` not to be disabled if extension block is givenRyuta Kamizono2019-04-124-10/+23
| | | | | | | | | | | | | | | | | | | | | | | | If an association has a scope, `automatic_inverse_of` is to be disabled. But extension block is obviously not a scope. It should not be regarded as a scope. Fixes #28806.
* | | Merge pull request #35838 from yahonda/more_than_1000_inlistRafael França2019-04-112-0/+42
|\ \ \ | |_|/ |/| | Address `ORA-01795: maximum number of expressions in a list is 1000`
| * | Address `ORA-01795: maximum number of expressions in a list is 1000`Yasuo Honda2019-04-112-0/+42
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * To address this error, this commit splits expressions by slices of 1000 elements. * "Oracle Database Error Messages 18c" https://docs.oracle.com/en/database/oracle/oracle-database/18/errmg/ ``` ORA-01795: maximum number of expressions in a list is 1000 Cause: Number of expressions in the query exceeded than 1000. Note that unused column/expressions are also counted Maximum number of expressions that are allowed are 1000. ``` * This commit addresses this ORA-01795 error Note: Actually addressing this error raises another "ORA-00913: too many values" Number of values Oracle database allows is 65535 regardless bind values or literal values. ```ruby $ ARCONN=oracle bin/test test/cases/bind_parameter_test.rb -n test_too_many_binds ... snip ... Error: ActiveRecord::BindParameterTest#test_too_many_binds: ActiveRecord::StatementInvalid: OCIError: ORA-01795: maximum number of expressions in a list is 1000 stmt.c:267:in oci8lib_260.so /home/yahonda/.rbenv/versions/2.6.2/lib/ruby/gems/2.6.0/gems/ruby-oci8-2.2.7/lib/oci8/cursor.rb:131:in `exec' /home/yahonda/git/oracle-enhanced/lib/active_record/connection_adapters/oracle_enhanced/oci_connection.rb:142:in `exec' /home/yahonda/git/oracle-enhanced/lib/active_record/connection_adapters/oracle_enhanced/database_statements.rb:41:in `block in exec_query' /home/yahonda/git/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb:676:in `block (2 levels) in log' /home/yahonda/.rbenv/versions/2.6.2/lib/ruby/2.6.0/monitor.rb:230:in `mon_synchronize' /home/yahonda/git/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb:675:in `block in log' /home/yahonda/git/rails/activesupport/lib/active_support/notifications/instrumenter.rb:24:in `instrument' /home/yahonda/git/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb:666:in `log' /home/yahonda/git/oracle-enhanced/lib/active_record/connection_adapters/oracle_enhanced/dbms_output.rb:36:in `log' /home/yahonda/git/oracle-enhanced/lib/active_record/connection_adapters/oracle_enhanced/database_statements.rb:24:in `exec_query' /home/yahonda/git/rails/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb:484:in `select' /home/yahonda/git/rails/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb:70:in `select_all' /home/yahonda/git/rails/activerecord/lib/active_record/connection_adapters/abstract/query_cache.rb:106:in `select_all' /home/yahonda/git/rails/activerecord/lib/active_record/relation/calculations.rb:299:in `block in execute_simple_calculation' /home/yahonda/git/rails/activerecord/lib/active_record/relation.rb:755:in `skip_query_cache_if_necessary' /home/yahonda/git/rails/activerecord/lib/active_record/relation/calculations.rb:299:in `execute_simple_calculation' /home/yahonda/git/rails/activerecord/lib/active_record/relation/calculations.rb:251:in `perform_calculation' /home/yahonda/git/rails/activerecord/lib/active_record/relation/calculations.rb:141:in `calculate' /home/yahonda/git/rails/activerecord/lib/active_record/relation/calculations.rb:49:in `count' /home/yahonda/git/rails/activerecord/test/cases/bind_parameter_test.rb:113:in `test_too_many_binds' bin/test test/cases/bind_parameter_test.rb:109 .............................F ```
* | | Revert "Remove unused callbacks in the `Topic` model"Ryuta Kamizono2019-04-101-0/+4
| | | | | | | | | | | | | | | | | | | | | | | | This reverts commit b33ccaa6c335e2ce482c9de1aa05e4a612aa84bc. That isn't hit by `git grep`, but actually used in meta-programming... https://github.com/rails/rails/blob/b33ccaa6c335e2ce482c9de1aa05e4a612aa84bc/activerecord/test/cases/transactions_test.rb#L1020-L1028
* | | Remove unused callbacks in the `Topic` modelRyuta Kamizono2019-04-101-4/+0
| |/ |/|
* | Merge pull request #28155 from lcreid/belongs_toRyuta Kamizono2019-04-105-0/+52
|\ \ | | | | | | | | | Fix "autosave: true" on belongs_to of join model causes invalid records to be saved
| * | Fix circular `autosave: true`Larry Reid2018-07-235-0/+52
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Use a variable local to the `save_collection_association` method in `activerecord/lib/active_record/autosave_association.rb`, instead of an instance variable. Prior to this PR, when there was a circular series of `autosave: true` associations, the callback for a `has_many` association was run while another instance of the same callback on the same association hadn't finished running. When control returned to the first instance of the callback, the instance variable had changed, and subsequent associated records weren't saved correctly. Specifically, the ID field for the `belongs_to` corresponding to the `has_many` was `nil`. Remove unnecessary test and comments. Fixes #28080.
* | | Add assertions for lazy sync transaction stateRyuta Kamizono2019-04-101-36/+49
| | |
* | | Remove duplicated attribute alias resolution in `_select!`Ryuta Kamizono2019-04-091-0/+1
| | | | | | | | | | | | This is also resolved in `arel_column`.
* | | Merge pull request #34800 from mqchau/mysqlCountDeleteRowInLockMatthew Draper2019-04-091-0/+28
|\ \ \ | | | | | | | | Wrap Mysql count of deleted rows in lock block to avoid conflict in test
| * | | Wrap Mysql count of deleted rows in lock block to avoid conflict in testQuan Chau2019-04-081-0/+28
| | | |
* | | | Merge pull request #35887 from kamipo/argument_errorRyuta Kamizono2019-04-096-12/+12
|\ \ \ \ | | | | | | | | | | Raise `ArgumentError` for invalid `:limit` and `:precision` like as other options
| * | | | Raise `ArgumentError` for invalid `:limit` and `:precision` like as other ↵Ryuta Kamizono2019-04-076-12/+12
| | |_|/ | |/| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | options When I've added new `:size` option in #35071, I've found that invalid `:limit` and `:precision` raises `ActiveRecordError` unlike other invalid options. I think that is hard to distinguish argument errors and statement invalid errors since the `StatementInvalid` is a subclass of the `ActiveRecordError`. https://github.com/rails/rails/blob/c9e4c848eeeb8999b778fa1ae52185ca5537fffe/activerecord/lib/active_record/errors.rb#L103 ```ruby begin # execute any migration rescue ActiveRecord::StatementInvalid # statement invalid rescue ActiveRecord::ActiveRecordError, ArgumentError # `ActiveRecordError` except `StatementInvalid` is maybe an argument error end ``` I'd say this is the inconsistency worth fixing. Before: ```ruby add_column :items, :attr1, :binary, size: 10 # => ArgumentError add_column :items, :attr2, :decimal, scale: 10 # => ArgumentError add_column :items, :attr3, :integer, limit: 10 # => ActiveRecordError add_column :items, :attr4, :datetime, precision: 10 # => ActiveRecordError ``` After: ```ruby add_column :items, :attr1, :binary, size: 10 # => ArgumentError add_column :items, :attr2, :decimal, scale: 10 # => ArgumentError add_column :items, :attr3, :integer, limit: 10 # => ArgumentError add_column :items, :attr4, :datetime, precision: 10 # => ArgumentError ```
* | | | Merge pull request #35892 from ryohashimoto/bulk_insert_logsEileen M. Uchitelle2019-04-081-0/+49
|\ \ \ \ | | | | | | | | | | Improve log messages for #insert_all` / `#upsert_all` etc. methods
| * | | | Improve log messages for #insert_all` / `#upsert_all` / `#insert` / `#upsert ↵Ryo Hashimoto2019-04-081-0/+49
| |/ / / | | | | | | | | | | | | | | | | | | | | | | | | | | | | etc. methods In #35077, `#insert_all` / `#upsert_all` / `#insert` / `#upsert` etc. methods are added. But Active Record logs only “Bulk Insert” log messages when they are invoked. This commit improves the log messages to use collect words for how invoked them.
* | | | When skipping duplicates in bulk insert on MySQL, avoid assigning id when ↵Bob Lail2019-04-081-0/+38
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | not specified If `id` is an `AUTONUMBER` column, then my former strategy here of assigning `no_op_column` to an arbitrary column would fail in this specific scenario: 1. `model.columns.first` is an AUTONUMBER column 2. `model.columns.first` is not assigned in the insert attributes I added three tests: the first test covers the actual error; the second test documents that this _isn't_ a problem when a value is given for the AUTONUMBER column and the third test ensures that this no-op strategy isn't secretly doing an UPSERT.
* | | | Fix GROUP BY with calculate longer name field to respect `table_alias_length`Ryuta Kamizono2019-04-082-0/+12
|/ / / | | | | | | | | | Follow up of c9e4c848eeeb8999b778fa1ae52185ca5537fffe.
* | | There is no need to check `null_relation?` in `empty_scope?`Ryuta Kamizono2019-04-062-0/+7
| | | | | | | | | | | | `values[:extending]` includes `NullRelation` if `null_relation?`.
* | | Association loading isn't to be affected by null relation scopingRyuta Kamizono2019-04-061-0/+24
| | | | | | | | | | | | | | | | | | Follow up of #35868. Closes #19349.
* | | Merge pull request #35868 from ↵Ryuta Kamizono2019-04-062-7/+20
|\ \ \ | | | | | | | | | | | | | | | | kamipo/association_isnt_to_be_affected_by_scoping_consistently Association loading isn't to be affected by scoping consistently
| * | | Association loading isn't to be affected by scoping consistentlyRyuta Kamizono2019-04-052-7/+20
| |/ / | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Follow-up of 5c71000, #29834, and #30271. Currently, preloading and eager loading are not to be affected by scoping, with the exception of `unscoped`. But non eager loaded association access is still affected by scoping. Although this is a breaking change, the association loading will work consistently whether preloaded / eager loaded or not. Before: ```ruby Post.where("1=0").scoping do Comment.find(1).post # => nil Comment.preload(:post).find(1).post # => #<Post id: 1, ...> Comment.eager_load(:post).find(1).post # => #<Post id: 1, ...> end ``` After: ```ruby Post.where("1=0").scoping do Comment.find(1).post # => #<Post id: 1, ...> Comment.preload(:post).find(1).post # => #<Post id: 1, ...> Comment.eager_load(:post).find(1).post # => #<Post id: 1, ...> end ``` Fixes #34638. Fixes #35398.
* | | Fix typo for touch later test description. laster -> laterAbhay Nikam2019-04-051-1/+1
| | |
* | | Add missing `touch_all` delegation to relationRyuta Kamizono2019-04-052-1/+33
|/ / | | | | | | Follow up of #31513.
* | Remove duplicated `test_find_last`Ryuta Kamizono2019-04-051-5/+0
| | | | | | | | This is completely same with `test_last`.
* | Stash `left_joins` into `joins` to deduplicate redundant LEFT JOINRyuta Kamizono2019-04-053-2/+15
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Originally the `JoinDependency` has the deduplication for eager loading (LEFT JOIN). This re-uses that deduplication for `left_joins`. And also, This makes left join order into part of joins, i.e.: Before: ``` association joins -> stash joins (eager loading, etc) -> string joins -> left joins ``` After: ``` association joins -> stash joins (eager loading, left joins, etc) -> string joins ``` Now string joins are able to refer left joins. Fixes #34325. Fixes #34332. Fixes #34536.
* | Merge pull request #35698 from mtsmfm/output-test-reportMatthew Draper2019-04-041-0/+2
|\ \ | | | | | | Output junit format test report
| * | Output junit format test reportFumiaki MATSUSHIMA2019-04-041-0/+2
| | |
* | | Fix `count(:all)` with eager loading and explicit select and orderRyuta Kamizono2019-04-042-0/+12
|/ / | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This follows up ebc09ed9ad9a04338138739226a1a92c7a2707ee. We've still experienced a regression for `size` (`count(:all)`) with eager loading and explicit select and order when upgrading Rails to 5.1. In that case, the eager loading enforces `distinct` to subselect but still keep the custom select, it would cause the ORDER BY with DISTINCT issue. ``` % ARCONN=postgresql bundle exec ruby -w -Itest test/cases/relations_test.rb -n test_size_with_eager_loading_and_custom_select_and_order Using postgresql Run options: -n test_size_with_eager_loading_and_custom_select_and_order --seed 8356 # Running: E Error: RelationTest#test_size_with_eager_loading_and_custom_select_and_order: ActiveRecord::StatementInvalid: PG::InvalidColumnReference: ERROR: for SELECT DISTINCT, ORDER BY expressions must appear in select list LINE 1: ..." ON "comments"."post_id" = "posts"."id" ORDER BY comments.i... ^ ``` As another problem on `distinct` is enforced, the result of `count` becomes fewer than expected if `select` is given explicitly. e.g. ```ruby Post.select(:type).count # => 11 Post.select(:type).distinct.count # => 3 ``` As long as `distinct` is enforced, we need to care to keep the result of `count`. This fixes both the `count` with eager loading problems.
* | Optimizer hints should be applied on Top level query as much as possibleRyuta Kamizono2019-04-042-0/+16
| | | | | | | | | | I've experienced this issue in our app, some hints only works on Top level query (e.g. `MAX_EXECUTION_TIME`).
* | Don't drop internal metadata tablesRyuta Kamizono2019-04-041-4/+2
| | | | | | | | | | | | | | | | Some tests expects that internal metadata tables exists, and we should not use `create_table` in transactional tests, since DDL in MySQL causes implicit commit. https://travis-ci.org/rails/rails/jobs/515438937#L3829
* | Ensure `reset_table_name` when table name prefix/suffix is changedRyuta Kamizono2019-04-044-17/+15
| | | | | | | | | | Also, `reset_column_information` is unnecessary since `reset_table_name` does that too.
* | Clear query cache when truncate table(s)Ryuta Kamizono2019-04-041-8/+36
| |
* | Fix fragile testsRyuta Kamizono2019-04-041-2/+4
| |
* | Respect table name prefix/suffix for `truncate_all`Ryuta Kamizono2019-04-042-1/+59
| |
* | Merge pull request #35795 from alimi/cache-database-versionEileen M. Uchitelle2019-04-038-11/+34
|\ \ | | | | | | Cache database version in schema cache