aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/adapter_test.rb
Commit message (Collapse)AuthorAgeFilesLines
* Auto-correct `Style/StringLiterals` cop offencesRyuta Kamizono2019-04-131-4/+4
| | | | Somehow Code Climate is not working as expected for now?
* 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
* Clear query cache when truncate table(s)Ryuta Kamizono2019-04-041-8/+36
|
* Make `truncate_tables` to bulk statementsRyuta Kamizono2019-03-171-3/+3
| | | | | | | | | | | | | | | | | | Before: ``` (16.4ms) TRUNCATE TABLE `author_addresses` (20.5ms) TRUNCATE TABLE `authors` (19.4ms) TRUNCATE TABLE `posts` ``` After: ``` Truncate Tables (19.5ms) TRUNCATE TABLE `author_addresses`; TRUNCATE TABLE `authors`; TRUNCATE TABLE `posts` ```
* Extract `truncate` and `truncate_tables` into database statementsRyuta Kamizono2019-03-171-0/+22
| | | | This is to easier make `truncate_tables` to bulk statements.
* Don't test `disconnect!` if in memory dbRyuta Kamizono2019-03-101-8/+8
| | | | `disconnect!` will lose all tables and fixtures if in memory db.
* Fix `reconnect!` to work after `disconnect!`Ryuta Kamizono2019-03-101-7/+9
|
* SQLite3: Implement `add_foreign_key` and `remove_foreign_key`Ryuta Kamizono2019-02-111-0/+4
| | | | | | | | | | | | I implemented Foreign key create in `create_table` for SQLite3 at #24743. This follows #24743 to implement `add_foreign_key` and `remove_foreign_key`. Unfortunately SQLite3 has one limitation that `PRAGMA foreign_key_list(table-name)` doesn't have constraint name. So we couldn't implement find/remove foreign key by name for now. Fixes #35207. Closes #31343.
* Add test case for `preventing_writes?`Ryuta Kamizono2019-01-021-0/+10
| | | | Since the `preventing_writes?` is public API.
* Enable `Style/RedundantBegin` cop to avoid newly adding redundant begin blockRyuta Kamizono2018-12-211-12/+10
| | | | | | | | | | 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.
* Ensure that preventing writes is invoked before `materialize_transactions` ↵Ryuta Kamizono2018-12-121-9/+21
| | | | consistently
* Prevent write queries for `exec_query`Ryuta Kamizono2018-12-111-0/+37
| | | | Follow up #34505.
* 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`.
* Redact SQL in errorsGannon McGibbon2018-11-221-12/+0
| | | | | Move `ActiveRecord::StatementInvalid` SQL to error property. Also add bindings as an error property.
* Enable `Performance/UnfreezeString` copyuuji.yaginuma2018-09-231-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | In Ruby 2.3 or later, `String#+@` is available and `+@` is faster than `dup`. ```ruby # frozen_string_literal: true require "bundler/inline" gemfile(true) do source "https://rubygems.org" gem "benchmark-ips" end Benchmark.ips do |x| x.report('+@') { +"" } x.report('dup') { "".dup } x.compare! end ``` ``` $ ruby -v benchmark.rb ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-linux] Warming up -------------------------------------- +@ 282.289k i/100ms dup 187.638k i/100ms Calculating ------------------------------------- +@ 6.775M (± 3.6%) i/s - 33.875M in 5.006253s dup 3.320M (± 2.2%) i/s - 16.700M in 5.032125s Comparison: +@: 6775299.3 i/s dup: 3320400.7 i/s - 2.04x slower ```
* Fix deprecation hash warning - activerecord testVitor Oliveira2018-09-201-1/+1
|
* `supports_xxx?` returns whether a feature is supported by the backendRyuta Kamizono2018-09-081-0/+25
| | | | Rather than a configuration on the connection.
* Deprecate most methods which were never used in `DatabaseLimits`Ryuta Kamizono2018-09-051-0/+28
| | | | | | | | | `DatabaseLimits` and those methods were introduced at 3809c80, but most methods were never used and never tested from the beginning (except `table_alias_length`, `index_name_length`, and `in_clause_length` (since 66c09372)). There is no reason to maintain unused those methods for about 8 years.
* Omit BEGIN/COMMIT statements for empty transactionsEugene Kenny2018-08-131-0/+1
| | | | | | | | | | | | | | | | | | | | | | 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.
* MySQL: Raise ActiveRecord::InvalidForeignKey for foreign-key constraint ↵George Claghorn2018-07-301-5/+16
| | | | violations on delete
* Bump minimum SQLite version to 3.8Yasuo Honda2018-05-211-0/+4
| | | | | | | | | | | | | | These OS versions have SQLite 3.8 or higher by default. - macOS 10.10 (Yosemite) or higher - Ubuntu 14.04 LTS or higher Raising the minimum version of SQLite 3.8 introduces these changes: - All of bundled adapters support `supports_multi_insert?` - SQLite 3.8 always satisifies `supports_foreign_keys_in_create?` and `supports_partial_index?` - sqlite adapter can support `alter_table` method for foreign key referenced tables by #32865 - Deprecated `supports_multi_insert?` method
* Replace `assert !` with `assert_not`Daniel Colson2018-04-191-1/+1
| | | | | This autocorrects the violations after adding a custom cop in 3305c78dcd.
* Deprecate update_attributes and update_attributes!Eddie Lebow2018-02-171-1/+1
| | | | Closes #31998
* Use assert_empty and assert_not_emptyDaniel Colson2018-01-251-1/+1
|
* Use assert_predicate and assert_not_predicateDaniel Colson2018-01-251-5/+5
|
* Fix `can't modify frozen String` error in an AR testKoichi ITO2017-08-191-2/+2
|
* Restore the ability that SQL with binds for `insert`, `update`, and `delete` ↵Ryuta Kamizono2017-08-181-0/+32
| | | | | | | | (#29944) Since 213796f, it was lost the ability that SQL with binds for `insert`, `update`, and `delete` (like `select_all`). This restores the ability because `insert`, `update`, and `delete` are public API, so it should not be removed without deprecation.
* Merge remote-tracking branch 'origin/master' into unlock-minitestRafael Mendonça França2017-08-011-3/+3
|\
| * Refactor Active Record to let Arel manage bind paramsSean Griffin2017-07-241-3/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | A common source of bugs and code bloat within Active Record has been the need for us to maintain the list of bind values separately from the AST they're associated with. This makes any sort of AST manipulation incredibly difficult, as any time we want to potentially insert or remove an AST node, we need to traverse the entire tree to find where the associated bind parameters are. With this change, the bind parameters now live on the AST directly. Active Record does not need to know or care about them until the final AST traversal for SQL construction. Rather than returning just the SQL, the Arel collector will now return both the SQL and the bind parameters. At this point the connection adapter will have all the values that it had before. A bit of this code is janky and something I'd like to refactor later. In particular, I don't like how we're handling associations in the predicate builder, the special casing of `StatementCache::Substitute` in `QueryAttribute`, or generally how we're handling bind value replacement in the statement cache when prepared statements are disabled. This also mostly reverts #26378, as it moved all the code into a location that I wanted to delete. /cc @metaskills @yahonda, this change will affect the adapters Fixes #29766. Fixes #29804. Fixes #26541. Close #28539. Close #24769. Close #26468. Close #26202. There are probably other issues/PRs that can be closed because of this commit, but that's all I could find on the first few pages.
| * Merge pull request #29732 from kirs/frozen-activerecordRafael França2017-07-211-0/+2
| |\ | | | | | | Use frozen-string-literal in ActiveRecord
| | * Use frozen-string-literal in ActiveRecordKir Shatrov2017-07-191-0/+2
| | |
| * | Revert "Extract `bind_param` and `bind_attribute` into `ActiveRecord::TestCase`"Sean Griffin2017-07-211-1/+1
| |/ | | | | | | | | | | | | | | This reverts commit b6ad4052d18e4b29b8a092526c2beef013e2bf4f. This is not something that the majority of Active Record should be testing or care about. We should look at having fewer places rely on these details, not make it easier to rely on them.
* / Move `reset_pk_sequence!` test to `AdapterTestWithoutTransaction`yuuji.yaginuma2017-07-171-20/+20
|/ | | | | | | | | | | | | | | | | | | If execute PostgreSQL test with specifying 53853 for seed, the following error will occur. ``` 1) Error: TransactionTest#test_restore_custom_primary_key_after_rollback: ActiveRecord::RecordNotUnique: PG::UniqueViolation: ERROR: duplicate key value violates unique constraint "movies_pkey" DETAIL: Key (movieid)=(2) already exists. : INSERT INTO "movies" ("name") VALUES ($1) RETURNING "movieid" ``` travis is here https://travis-ci.org/rails/rails/jobs/254095918 As with #29287, it seems like a problem that the value of primary key obtained from connection gets different. Therefore, fixed to execute that test within transaction.
* Remove driver-specific hard-coding in the tests.Dennis Taylor2017-07-071-9/+1
|
* Rename the StatementInvalid test method for clarity.Dennis Taylor2017-07-071-1/+1
|
* Use StandardError instead of RuntimeError.Dennis Taylor2017-07-061-2/+2
| | | | Whoops.
* Fix indentation style for private method.Dennis Taylor2017-07-051-5/+5
|
* Don't translate non-database exceptions.Dennis Taylor2017-07-051-0/+30
| | | | The AbstractAdapter will translate all StandardErrors generated during the course of a query into ActiveRecord::StatementInvalids. Unfortunately, it'll also mangle non-database-related errors generated in ActiveSupport::Notification callbacks after the query has successfully completed. This should prevent it from translating errors from ActiveSupport::Notifications.
* Revert "Merge pull request #29540 from kirs/rubocop-frozen-string"Matthew Draper2017-07-021-1/+0
| | | | | This reverts commit 3420a14590c0e6915d8b6c242887f74adb4120f9, reversing changes made to afb66a5a598ce4ac74ad84b125a5abf046dcf5aa.
* Enforce frozen string in RubocopKir Shatrov2017-07-011-0/+1
|
* Extract `bind_param` and `bind_attribute` into `ActiveRecord::TestCase`Ryuta Kamizono2017-05-041-1/+1
| | | | These are used in tests from anywhere.
* Merge pull request #27939 from kamipo/fix_select_all_with_legacy_bindsRafael França2017-03-201-0/+9
|\ | | | | Fix `select_all` with legacy `binds`
| * Fix `select_all` with legacy `binds`Ryuta Kamizono2017-02-121-0/+9
| | | | | | | | Fixes #27923.
* | `valid_type?` should accept only supported typesRyuta Kamizono2017-02-281-0/+10
|/ | | | | | | | | | | | | | | | | | | | `valid_type?` is used in schema dumper to determine if a type is supported. So if `valid_type?(:foobar)` is true, it means that schema dumper is allowed to create `t.foobar`. But it doesn't work. I think that `valid_type?` should accept only supported types. https://github.com/rails/rails/blob/v5.1.0.beta1/activerecord/lib/active_record/schema_dumper.rb#L135-L142 ```ruby columns.each do |column| raise StandardError, "Unknown type '#{column.sql_type}' for column '#{column.name}'" unless @connection.valid_type?(column.type) next if column.name == pk type, colspec = @connection.column_spec(column) tbl.print " t.#{type} #{column.name.inspect}" tbl.print ", #{format_colspec(colspec)}" if colspec.present? tbl.puts end ```
* `primary_key` and `references` columns should be identical typeRyuta Kamizono2017-02-071-1/+1
| | | | | | | | Follow up to #26266. The default type of `primary_key` and `references` were changed to `bigint` since #26266. But legacy migration and sqlite3 adapter should keep its previous behavior.
* Merge pull request #27700 from kenta-s/remove-meaningless-line-from-adapter-testAndrew White2017-01-171-1/+0
|\ | | | | Remove meaningless line from adapter_test.rb
| * Remove meaningless line from adapter_test.rbkenta-s2017-01-161-1/+0
| |
* | Translate Foreign Key violation to the specific exception for SQLite3 adapterRyuta Kamizono2017-01-161-45/+53
|/ | | | | | Raise `ActiveRecord::InvalidForeignKey` when a record cannot be inserted or updated because it references a non-existent record for SQLite3 adapter.
* Revert "Merge pull request #21233 from ↵Rafael Mendonça França2017-01-031-17/+17
| | | | | | | | | | mtsmfm/disable-referential-integrity-without-superuser-privileges" This reverts commit eeac6151a55cb7d5f799e1ae33aa64a839cbc3aa, reversing changes made to 5c40239d3104543e70508360d27584a3e4dc5baf. Reason: Broke the isolated tests. https://travis-ci.org/rails/rails/builds/188721346
* Merge pull request #21233 from ↵Rafael França2017-01-031-17/+17
|\ | | | | | | | | mtsmfm/disable-referential-integrity-without-superuser-privileges Use `SET CONSTRAINTS` for `disable_referential_integrity` without superuser privileges