aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test
Commit message (Collapse)AuthorAgeFilesLines
...
* | | Deprecate passing `migrations_paths` to ↵Ryuta Kamizono2018-12-281-0/+7
| | | | | | | | | | | | | | | | | | | | | `connection.assume_migrated_upto_version` Since #31727, `migrations_paths` in `assume_migrated_upto_version` is no longer used.
* | | Remove redundant assignning to `current_env`Ryuta Kamizono2018-12-281-1/+0
| |/ |/| | | | | This was introduced at https://github.com/rails/rails/commit/cfa1df4b07bee5b2bbcbf9edd2ac287b4fb23c18#diff-b36b9c41be30b05dc14d09d7f3b192efR436.
* | No need to handle if FrozenError is availableYasuo Honda2018-12-235-9/+5
| | | | | | | | | | | | | | Rails 6 requires Ruby 2.5, which introduces `FrozenError` https://docs.ruby-lang.org/en/2.5.0/NEWS.html Related to #31520
* | Merge pull request #34753 from ↵Eileen M. Uchitelle2018-12-212-0/+15
|\ \ | | | | | | | | | | | | eileencodes/raise-less-confusing-error-if-handler-doesnt-exist Raise helpful error when role doesn't exist
| * | Raise helpful error when role doesn't existEileen Uchitelle2018-12-212-0/+15
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | If you try to call `connected_to` with a role that doesn't have an established connection you used to get an error that said: ``` >> ActiveRecord::Base.connected_to(role: :i_dont_exist) { Home.first } ActiveRecord::ConnectionNotEstablished Exception: No connection pool with 'primary' found. ``` This is confusing because the connection could be established but we spelled the role wrong. I've changed this to raise if the `role` used in `connected_to` doesn't have an associated handler. Users who encounter this should either check that the role is spelled correctly (writin -> writing), establish a connection to that role in the model with connects_to, or use the `database` keyword for the `role`. I think this will provide a less confusing error message for those starting out with multiple databases.
* | | Merge pull request #34742 from kamipo/row_format_dynamic_by_defaultRyuta Kamizono2018-12-211-7/+14
|\ \ \ | | | | | | | | MySQL: `ROW_FORMAT=DYNAMIC` create table option by default
| * | | MySQL: `ROW_FORMAT=DYNAMIC` create table option by defaultRyuta Kamizono2018-12-191-7/+14
| |/ / | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Since MySQL 5.7.9, the `innodb_default_row_format` option defines the default row format for InnoDB tables. The default setting is `DYNAMIC`. The row format is required for indexing on `varchar(255)` with `utf8mb4` columns. As long as using MySQL 5.6, CI won't be passed even if MySQL server setting is properly configured the same as MySQL 5.7 (`innodb_file_per_table = 1`, `innodb_file_format = 'Barracuda'`, and `innodb_large_prefix = 1`) since InnoDB table is created as the row format `COMPACT` by default on MySQL 5.6, therefore indexing on string with `utf8mb4` columns aren't succeeded. Making `ROW_FORMAT=DYNAMIC` create table option by default for legacy MySQL version would mitigate the indexing issue on the user side, and it makes CI would be passed on MySQL 5.6 which is configured properly.
* | | Enable `Style/RedundantBegin` cop to avoid newly adding redundant begin blockRyuta Kamizono2018-12-2118-286/+234
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Currently we sometimes find a redundant begin block in code review (e.g. https://github.com/rails/rails/pull/33604#discussion_r209784205). I'd like to enable `Style/RedundantBegin` cop to avoid that, since rescue/else/ensure are allowed inside do/end blocks in Ruby 2.5 (https://bugs.ruby-lang.org/issues/12906), so we'd probably meets with that situation than before.
* | | Module#{attr,attr_accessor,attr_reader,attr_writer} become public since Ruby 2.5Ryuta Kamizono2018-12-213-3/+3
| | | | | | | | | | | | https://bugs.ruby-lang.org/issues/14132
* | | Module#{define_method,alias_method,undef_method,remove_method} become public ↵Ryuta Kamizono2018-12-214-9/+9
|/ / | | | | | | | | | | since Ruby 2.5 https://bugs.ruby-lang.org/issues/14133
* | Add test case for ce48b5a366482d4b4c4c053e1e39e79d71987197Ryuta Kamizono2018-12-181-0/+7
| |
* | Enable `Layout/SpaceAfterSemicolon` cop to avoid newly adding odd spacingRyuta Kamizono2018-12-131-3/+3
| | | | | | | | Ref https://github.com/rails/rails/commit/59ff1ba30d9f4d34b4d478104cc3f453e553c67a#diff-38fb97fba84b1ef0f311c4110a597c44R35
* | Ensure that preventing writes is invoked before `materialize_transactions` ↵Ryuta Kamizono2018-12-121-9/+21
| | | | | | | | consistently
* | Add AR::Base.connected_to?John Hawthorn2018-12-111-0/+11
| | | | | | | | | | This can be used to check the currently connected role. It's meant to mirror AR::Base.connected_to
* | An empty transaction does not raise the `ReadOnlyError` if preventing writesRyuta Kamizono2018-12-111-0/+10
| | | | | | | | | | | | BEGIN transaction would cause COMMIT or ROLLBACK, so unless COMMIT and ROLLBACK aren't treated as write queries as well as BEGIN, the `ReadOnlyError` would be raised.
* | Merge pull request #34666 from vinistock/upgrade_rubocop_and_fix_offensesRafael França2018-12-101-23/+23
|\ \ | | | | | | Upgrade Rubocop to 0.61.1 and fix offenses
| * | Upgrade Rubocop to 0.61.1 and fix offensesVinicius Stock2018-12-101-23/+23
| | |
* | | An explain query does not raise the `ReadOnlyError` if preventing writesRyuta Kamizono2018-12-111-0/+8
| | |
* | | Don't treat begin and rollback transactions as write queriesRyuta Kamizono2018-12-112-3/+14
|/ / | | | | | | | | Otherwise `save` method would raise the `ReadOnlyError` against `BEGIN` and `ROLLBACK` queries.
* | Prevent write queries for `exec_query`Ryuta Kamizono2018-12-111-0/+37
| | | | | | | | Follow up #34505.
* | Merge pull request #34632 from rails/rename-write-on-read-errorEileen M. Uchitelle2018-12-074-14/+14
|\ \ | | | | | | Rename error that occurs when writing on a read
| * | Rename error that occurs when writing on a readEileen Uchitelle2018-12-074-14/+14
| | | | | | | | | | | | | | | | | | | | | I originally named this `StatementInvalid` because that's what we do in GitHub, but `@tenderlove` pointed out that this means apps can't test for or explitly rescue this error. `StatementInvalid` is pretty broad so I've renamed this to `ReadOnlyError`.
* | | #create_or_find_by/!: add more tests and fix docs (#34653)Bogdan2018-12-081-0/+39
|/ / | | | | | | | | | | | | | | * `#create_or_find_by/!`: add more tests * Fix docs of `create_or_find_by` This method uses `find_by!` internally.
* | Fix join table column quoting with SQLite.Gannon McGibbon2018-12-051-0/+4
| |
* | Fix unstable ↵yuuji.yaginuma2018-12-051-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | `test_serialized_attribute_works_under_concurrent_initial_access` test Since bd62389307e138ee0f274a9d62697567a3334ea0, isolate test of `test_serialized_attribute_works_under_concurrent_initial_access` fails. ``` $ ./bin/test -w test/cases/serialized_attribute_test.rb -n test_serialized_attribute_works_under_concurrent_initial_access Using sqlite3 Run options: -n test_serialized_attribute_works_under_concurrent_initial_access --seed 32129 # Running: E Error: SerializedAttributeTest#test_serialized_attribute_works_under_concurrent_initial_access: ActiveRecord::StatementInvalid: SQLite3::SQLException: no such table: ``` If duplicate an unloaded model, it seems that method invocation for that class is not guaranteed. Use the original class to avoid it.
* | Merge pull request #34560 from gmcgibbon/fix_decorate_leak_on_serial_attr_testRafael França2018-12-041-0/+4
|\ \ | | | | | | Fix attribute decoration leak on serialized attribute test
| * | Fix attribute decoration leak on serialized attribute testGannon McGibbon2018-11-291-0/+4
| | |
* | | option to disable scopes that `ActiveRecord.enum` generates by defaultAlfred Dominic2018-12-041-0/+9
| | |
* | | Merge pull request #34609 from kamipo/delete_all_on_collection_proxyRyuta Kamizono2018-12-042-6/+16
|\ \ \ | | | | | | | | | | | | Ensure that `delete_all` on collection proxy returns affected count
| * | | Ensure that `delete_all` on collection proxy returns affected countRyuta Kamizono2018-12-042-6/+16
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Unlike the `Relation#delete_all`, `delete_all` on collection proxy doesn't return affected count. Since the `CollectionProxy` is a subclass of the `Relation`, this inconsistency is probably not intended, so it should return the count consistently.
* | | | Reset scope after collection deleteGannon McGibbon2018-12-042-0/+64
|/ / / | | | | | | | | | | | | Reset scope after delete on collection association to clear stale offsets of removed records.
* | | Fix NumericData.average test on ruby 2.6Abdallah Samman2018-12-031-2/+6
| | |
* | | Assigned but unused variable - birdutilum2018-12-031-1/+1
| | | | | | | | | | | | See: https://travis-ci.org/rails/rails/jobs/462233144#L1384
* | | Add ability to prevent writes to a databaseEileen Uchitelle2018-11-304-0/+206
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This PR adds the ability to prevent writes to a database even if the database user is able to write (ie the database is a primary and not a replica). This is useful for a few reasons: 1) when converting your database from a single db to a primary/replica setup - you can fix all the writes on reads early on, 2) when we implement automatic database switching or when an app is manually switching connections this feature can be used to ensure reads are reading and writes are writing. We want to make sure we raise if we ever try to write in read mode, regardless of database type and 3) for local development if you don't want to set up multiple databases but do want to support rw/ro queries. This should be used in conjunction with `connected_to` in write mode. For example: ``` ActiveRecord::Base.connected_to(role: :writing) do Dog.connection.while_preventing_writes do Dog.create! # will raise because we're preventing writes end end ActiveRecord::Base.connected_to(role: :reading) do Dog.connection.while_preventing_writes do Dog.first # will not raise because we're not writing end end ```
* | | Merge pull request #34572 from kamipo/fix_scoping_with_query_methodRyuta Kamizono2018-11-302-1/+7
|\ \ \ | | | | | | | | Fix the scoping with query methods in the scope block
| * | | Fix the scoping with query methods in the scope blockRyuta Kamizono2018-11-302-1/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Follow up #33394. #33394 only fixes the case of scoping with klass methods in the scope block which invokes `klass.all`. Query methods in the scope block also need to invoke `klass.all` to be affected by the scoping.
* | | | Allow aliased attributes in updateGannon McGibbon2018-11-291-0/+6
| | | | | | | | | | | | | | | | Allow aliased attributes to be used in `#update_columns` and `#update`.
* | | | Allow spaces in postgres table namesGannon McGibbon2018-11-281-0/+5
| |/ / |/| | | | | | | | | | | Fixes issue where "user post" is misinterpreted as "\"user\".\"post\"" when quoting table names with the postgres adapter.
* | | Merge pull request #33835 from schneems/schneems/faster_cache_versionSean Griffin2018-11-271-2/+80
|\ \ \ | | | | | | | | Use raw time string from DB to generate ActiveRecord#cache_version
| * | | Do not silently fail to generate a cache_versionschneems2018-10-171-0/+8
| | | | | | | | | | | | | | | | | | | | | | | | When an `updated_at` column exists on the model, but is not available on the instance (likely due to a select), we should raise an error rather than silently not generating a cache_version. Without this behavior it's likely that cache entries will not be able to be invalidated and this will happen without notice. This behavior was reported and described by @lsylvester in https://github.com/rails/rails/pull/34197#issuecomment-429668759.
| * | | Use raw time string from DB to generate ActiveRecord#cache_versionschneems2018-10-171-2/+72
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Currently, the `updated_at` field is used to generate a `cache_version`. Some database adapters return this timestamp value as a string that must then be converted to a Time value. This process requires a lot of memory and even more CPU time. In the case where this value is only being used for a cache version, we can skip the Time conversion by using the string value directly. - This PR preserves existing cache format by converting a UTC string from the database to `:usec` format. - Some databases return an already converted Time object, in those instances, we can directly use `created_at`. - The `updated_at_before_type_cast` can be a value that comes from either the database or the user. We only want to optimize the case where it is from the database. - If the format of the cache version has been changed, we cannot apply this optimization, and it is skipped. - If the format of the time in the database is not UTC, then we cannot use this optimization, and it is skipped. Some databases (notably PostgreSQL) returns a variable length nanosecond value in the time string. If the value ends in a zero, then it is truncated For instance instead of `2018-10-12 05:00:00.000000` the value `2018-10-12 05:00:00` is returned. We detect this case and pad the remaining zeros to ensure consistent cache version generation. Before: Total allocated: 743842 bytes (6626 objects) After: Total allocated: 702955 bytes (6063 objects) (743842 - 702955) / 743842.0 # => 5.4% ⚡️⚡️⚡️⚡️⚡️ Using the CodeTriage application and derailed benchmarks this PR shows between 9-11% (statistically significant) performance improvement versus the commit before it. Special thanks to @lsylvester for helping to figure out a way to preserve the usec format and for helping with many implementation details.
* | | | Merge pull request #34528 from DmitryTsepelev/fix-ignored-attributesRafael França2018-11-273-0/+26
|\ \ \ \ | |_|/ / |/| | | Additional types of ResultSet should not contain keys of #attributes_to_define_after_schema_loads
| * | | Cached columns_hash fields should be excluded from ResultSet#column_typesDmitryTsepelev2018-11-273-0/+26
| | | |
* | | | More exercise singular association queryRyuta Kamizono2018-11-284-7/+14
| | | | | | | | | | | | | | | | Follow up ba4e68f577efc76f351d30a2914e29942b97830e.
* | | | Ensure that singular association should execute limited queryRyuta Kamizono2018-11-282-5/+12
|/ / /
* | | Make implicit order column configurableTekin Suleyman2018-11-261-0/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When calling ordered finder methods such as +first+ or +last+ without an explicit order clause, ActiveRecord sorts records by primary key. This can result in unpredictable and surprising behaviour when the primary key is not an auto-incrementing integer, for example when it's a UUID. This change makes it possible to override the column used for implicit ordering such that +first+ and +last+ will return more predictable results. For Example: class Project < ActiveRecord::Base self.implicit_order_column = "created_at" end
* | | Merge pull request #34520 from yahonda/bump_pg93Rafael França2018-11-265-383/+361
|\ \ \ | | | | | | | | Bump the minimum version of PostgreSQL to 9.3
| * | | Bump the minimum version of PostgreSQL to 9.3Yasuo Honda2018-11-255-383/+361
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | https://www.postgresql.org/support/versioning/ - 9.1 EOLed on September 2016. - 9.2 EOLed on September 2017. 9.3 is also not supported since Nov 8, 2018. https://www.postgresql.org/about/news/1905/ I think it may be a little bit early to drop PostgreSQL 9.3 yet. * Deprecated `supports_ranges?` since no other databases support range data type * Add `supports_materialized_views?` to abstract adapter Materialized views itself is supported by other databases, other connection adapters may support them * Remove `with_manual_interventions` It was only necessary for PostgreSQL 9.1 or earlier * Drop CI against PostgreSQL 9.2
* | | | Merge pull request #34521 from azbshiri/mysql-exec-query-resultEileen M. Uchitelle2018-11-261-0/+5
|\ \ \ \ | | | | | | | | | | Test when using MySQL `exec_query` returns `ActiveRecord::Result` all…
| * | | | When running exec_query MySQL always returns ActiveRecord::ResultAlireza Bashiri2018-11-251-0/+5
| |/ / / | | | | | | | | | | | | | | | | When running `exec_query` with `INSERT` (or other write commands), MySQL returns `ActiveRecord::Result`.