aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/adapters
Commit message (Collapse)AuthorAgeFilesLines
* Fix longer sequence name detection for serial columns (#28339)Ryuta Kamizono2017-10-151-0/+32
| | | | | | | | We already found the longer sequence name, but we could not consider whether it was the sequence name created by serial type due to missed a max identifier length limitation. I've addressed the sequence name consideration to respect the max identifier length. Fixes #28332.
* MySQL: Don't lose `auto_increment: true` in the `db/schema.rb`Ryuta Kamizono2017-10-151-0/+34
| | | | | | | | | | Currently `AUTO_INCREMENT` is implicitly used in the default primary key definition. But `AUTO_INCREMENT` is not only used for single column primary key, but also for composite primary key. In that case, `auto_increment: true` should be dumped explicitly in the `db/schema.rb`. Fixes #30894.
* Add JSON attribute test cases for SQLite3 adapterRyuta Kamizono2017-10-051-0/+29
|
* `Postgres::OID::Range` serializes to a `Range`, quote in `Quoting`Thomas Cannon2017-09-262-1/+52
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | PostgreSQL 9.1+ introduced range types, and Rails added support for using this datatype in ActiveRecord. However, the serialization of `PostgreSQL::OID::Range` was incomplete, because it did not properly quote the bounds that make up the range. A clear example of this is a `tsrange`. Normally, ActiveRecord quotes Date/Time objects to include the milliseconds. However, the way `PostgreSQL::OID::Range` serialized its bounds, the milliseconds were dropped. This meant that the value was incomplete and not equal to the submitted value. An example of normal timestamps vs. a `tsrange`. Note how the bounds for the range do not include their milliseconds (they were present in the ruby Range): UPDATE "iterations" SET "updated_at" = $1, "range" = $2 WHERE "iterations"."id" = $3 [["updated_at", "2017-09-23 17:07:01.304864"], ["range", "[2017-09-23 00:00:00 UTC,2017-09-23 23:59:59 UTC]"], ["id", 1234]] `PostgreSQL::OID::Range` serialized the range by interpolating a string for the range, which works for most cases, but does not work for timestamps: def serialize(value) if value.is_a?(::Range) from = type_cast_single_for_database(value.begin) to = type_cast_single_for_database(value.end) "[#{from},#{to}#{value.exclude_end? ? ')' : ']'}" else super end end (byebug) from = type_cast_single_for_database(value.begin) 2010-01-01 13:30:00 UTC (byebug) to = type_cast_single_for_database(value.end) 2011-02-02 19:30:00 UTC (byebug) "[#{from},#{to}#{value.exclude_end? ? ')' : ']'}" "[2010-01-01 13:30:00 UTC,2011-02-02 19:30:00 UTC)" @sgrif (the original implementer for Postgres Range support) provided some feedback about where the quoting should occur: Yeah, quoting at all is definitely wrong here. I'm not sure what I was thinking in 02579b5, but what this is doing is definitely in the wrong place. It should probably just be returning a range of subtype.serialize(value.begin) and subtype.serialize(value.end), and letting the adapter handle the rest. `Postgres::OID::Range` now returns a `Range` object, and `ActiveRecord::ConnectionAdapters::PostgreSQL::Quoting` can now encode and quote a `Range`: def encode_range(range) "[#{type_cast(range.first)},#{type_cast(range.last)}#{range.exclude_end? ? ')' : ']'}" end ... encode_range(range) #=> "['2010-01-01 13:30:00.670277','2011-02-02 19:30:00.745125')" This commit includes tests to make sure the milliseconds are preserved in `tsrange` and `tstzrange` columns
* Fix collided sequence name detectionRyuta Kamizono2017-09-181-0/+36
| | | | | | If collided named sequence already exists, newly created serial column will generate alternative sequence name. Fix sequence name detection to allow the alternative names.
* Add an extra assertion to ensure dumping schema default as expectedRyuta Kamizono2017-09-081-1/+4
|
* Fix `quote_default_expression` for UUID with array defaultRyuta Kamizono2017-09-081-0/+10
| | | | Fixes #30539.
* Omit the default limit for float columns (#28041)Ryuta Kamizono2017-08-271-1/+1
|
* Prefer to place a table options before `force: :cascade` (#28005)Ryuta Kamizono2017-08-271-4/+4
| | | | | | I was added a table options after `force: :cascade` in #17569 for not touching existing tests (reducing diff). But `force: :cascade` is not an important information. So I prefer to place a table options before `force: :cascade`.
* Merge pull request #30360 from gcourtemanche/transaction_timedoutRafael França2017-08-221-0/+6
|\ | | | | Add TransactionTimeout for MySQL error code 1205
| * Add TransactionTimeout for MySQL error code 1205Gabriel Courtemanche2017-08-221-0/+6
| |
* | Update links to use https instead of http [ci skip]Yoshiyuki Hirano2017-08-221-1/+1
|/
* Prevent extra `SET time zone` in `configure_connection` (#28413)Ryuta Kamizono2017-08-211-0/+7
| | | | | | | | `SET time zone 'value'` is an alias for `SET timezone TO 'value'`. https://www.postgresql.org/docs/current/static/sql-set.html So if `variables["timezone"]` is specified, it is enough to `SET timezone` once.
* Allow `serialize` with a custom coder on `json` and `array` columnsRyuta Kamizono2017-08-131-1/+25
| | | | | | | We already have a test case for `serialize` with a custom coder in `PostgresqlHstoreTest`. https://github.com/rails/rails/blob/v5.1.3/activerecord/test/cases/adapters/postgresql/hstore_test.rb#L316-L335
* Move `test_not_compatible_with_serialize_macro` to `JSONSharedTestCases`Ryuta Kamizono2017-08-111-11/+2
| | | | Because `JSONSharedTestCases` is also used for `Mysql2JSONTest`.
* Merge pull request #29520 from kirs/serialize-vs-postgres-native-columnSean Griffin2017-08-042-0/+18
|\ | | | | Do not let use `serialize` on native JSON/array column
| * Do not let use `serialize` on native JSON/array columnKir Shatrov2017-08-042-0/+18
| |
* | Merge remote-tracking branch 'origin/master' into unlock-minitestRafael Mendonça França2017-08-0168-26/+183
|\|
| * Merge pull request #29869 from kamipo/make_type_map_to_privateRafael França2017-07-212-7/+7
| |\ | | | | | | Make `type_map` to private because it is only used in the connection adapter
| | * Make `type_map` to private because it is only used in the connection adapterRyuta Kamizono2017-07-202-7/+7
| | | | | | | | | | | | | | | | | | | | | `type_map` is an internal API and it is only used in the connection adapter. And also, some type map initializer methods requires passed `type_map`, but those instances already has `type_map` in itself. So we don't need explicit passing `type_map` to the initializers.
| * | Merge pull request #29732 from kirs/frozen-activerecordRafael França2017-07-2168-0/+136
| |\ \ | | | | | | | | Use frozen-string-literal in ActiveRecord
| | * | Use frozen-string-literal in ActiveRecordKir Shatrov2017-07-1968-0/+136
| | |/
| * / Revert "Extract `bind_param` and `bind_attribute` into `ActiveRecord::TestCase`"Sean Griffin2017-07-215-15/+23
| |/ | | | | | | | | | | | | | | 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.
| * Merge pull request #29033 from kamipo/make_preload_query_to_prepared_statementsSean Griffin2017-07-182-2/+2
| |\ | | | | | | Make preload query to preparable
| | * Make preload query to preparableRyuta Kamizono2017-07-072-2/+2
| | | | | | | | | | | | | | | | | | | | | Currently preload query cannot be prepared statements even if `prepared_statements: true` due to array handler in predicate builder doesn't support making bind params. This makes preload query to preparable by don't passing array value if possible.
| * | Change sqlite3 boolean serialization to use 1 and 0Lisa Ugray2017-07-112-2/+15
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Abstract boolean serialization has been using 't' and 'f', with MySQL overriding that to use 1 and 0. This has the advantage that SQLite natively recognizes 1 and 0 as true and false, but does not natively recognize 't' and 'f'. This change in serialization requires a migration of stored boolean data for SQLite databases, so it's implemented behind a configuration flag whose default false value is deprecated. The flag itself can be deprecated in a future version of Rails. While loaded models will give the correct result for boolean columns without migrating old data, where() clauses will interact incorrectly with old data. While working in this area, also change the abstract adapter to use `"TRUE"` and `"FALSE"` as quoted values and `true` and `false` for unquoted. These are supported by PostreSQL, and MySQL remains overriden.
* | | Merge pull request #29380 from ↵Kasper Timm Hansen2017-07-151-0/+4
|\ \ \ | | | | | | | | | | | | | | | | y-yagi/insert_environment_value_to_table_before_check_environment Insert environment value to `InternalMetadata` table before check environment
| * | | Insert environment value to `InternalMetadata` after recreating the tableyuuji.yaginuma2017-06-091-0/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Sometimes `ActiveRecord::DatabaseTasksUtilsTask#test_raises_an_error_when_called_with_protected_environment` test fails. https://travis-ci.org/rails/rails/jobs/238861562 https://travis-ci.org/rails/rails/jobs/239950092 There seems to be an error because `environment` value is not exist. This is because did not set the environment after recreating the table in `SchemaMigrationsTest#test_initializes_internal_metadata_for_encoding_utf8mb4`. Therefore, we create value after the test to maintain the original state.
* | | | Merge branch 'master' into unlock-minitestKasper Timm Hansen2017-07-159-175/+31
|\ \ \ \ | |/ / / |/| / / | |/ /
| * | Merge pull request #29715 from reverbdotcom/ptd/fix-invalid-uuidsMatthew Draper2017-07-091-1/+3
| |\ \ | | | | | | | | Don't allow uuids with orphan curly braces
| | * | Don't allow uuids with orphan curly bracespdebelak2017-07-071-1/+3
| | |/ | | | | | | | | | | | | | | | | | | | | | The uuid validation regex was allowing uuids to have a single leading curly brace or single trailing curly brace. Saving with such a uuid would cause Postgres to generate an exception even though the record seemed valid. With this change, the regex requires both a leading *and* a trailing curly brace or neither to be valid.
| * / Use `information_schema` to extract `generation_expression` for MariaDBRyuta Kamizono2017-07-071-1/+1
| |/ | | | | | | | | | | Since MariaDB 10.2.5, `information_schema` supports Virtual Columns. Fixes #29670.
| * Revert "Merge pull request #29540 from kirs/rubocop-frozen-string"Matthew Draper2017-07-0268-68/+0
| | | | | | | | | | This reverts commit 3420a14590c0e6915d8b6c242887f74adb4120f9, reversing changes made to afb66a5a598ce4ac74ad84b125a5abf046dcf5aa.
| * Merge pull request #29540 from kirs/rubocop-frozen-stringMatthew Draper2017-07-0268-0/+68
| |\ | | | | | | | | | Enforce frozen string in Rubocop
| | * Enforce frozen string in RubocopKir Shatrov2017-07-0168-0/+68
| | |
| * | Merge pull request #29506 from pat/frozen-string-literalsMatthew Draper2017-07-023-8/+8
| |\ \ | | |/ | |/| | | | Make ActiveSupport frozen-string-literal friendly.
| | * Make ActiveRecord frozen string literal friendly.Pat Allan2017-06-203-8/+8
| | |
| * | Use bulk INSERT to insert fixturesKir Shatrov2017-06-201-0/+6
| |/ | | | | | | | | | | | | | | Improves the performance from O(n) to O(1). Previously it would require 50 queries to insert 50 fixtures. Now it takes only one query. Disabled on sqlite which doesn't support multiple inserts.
| * Allow `uuid_test.rb` to be loaded on all adaptersEugene Kenny2017-06-141-1/+2
| | | | | | | | | | | | | | | | | | Running `bin/test` from the activerecord directory produces this error: test/cases/adapters/postgresql/uuid_test.rb:43:in `<class:PostgresqlUUIDTest>': undefined method `supports_pgcrypto_uuid?' for #<ActiveRecord::ConnectionAdapters::SQLite3Adapter:0x007fc405e72a68> (NoMethodError) The test only actually runs on the PostgreSQL adapter; we can avoid triggering the error on other adapters with this `respond_to?` guard.
| * Merge pull request #28868 from yahonda/pg10_oid_unknown_to_textMatthew Draper2017-06-071-8/+8
| |\ | | | | | | PostgreSQL 10 converts unknown type to text type
| | * PostgreSQL 10 converts unknown OID 705 to text 25Yasuo Honda2017-06-061-8/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | - Rename test cases from `unknown` to `unrecognized` since unknown OID is one of possible unrecognized types by Rails - Use "select 'pg_catalog.pg_class'::regclass" whose OID is 2205, which will not be converted to recognized type in PostgreSQL 10. activerecord_unittest=# select oid, typname from pg_type where oid in (2205, 2277); oid | typname ------+---------- 2205 | regclass 2277 | anyarray (2 rows) Addresses #28868
| * | Remove redundant `assert_nothing_raised` before another assertionsRyuta Kamizono2017-06-061-2/+0
| |/ | | | | | | These `assert_nothing_raised` are covered by following assertions.
| * Testing `ReservedWordTest` for all adaptersRyuta Kamizono2017-06-051-151/+0
| | | | | | | | | | `ReservedWordTest` expects that any identifiers are quoted properly. It should be tested for all adapters.
| * Remove assert_nothing_raised, as test is already testing the required concernsPrathamesh Sonpatki2017-06-031-3/+3
| |
* | Explicitly clear type map before run ↵yuuji.yaginuma2017-06-031-6/+12
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | `test_only_reload_type_map_once_for_every_unknown_type` Currently, the following test fails. ``` bin/test -a sqlite3_mem --seed 37473 test/cases/relation_test.rb ``` This is due to reset connection in `test_respond_to_for_non_selected_element` postprocessing. This reset is added with #29332 for `test_only_reload_type_map_once_for_every_unknown_type`. Since the above test expects the type map to be empty at the time of test run, I think that it is better to empty the type map before test run.
* | Merge branch 'master' into unlock-minitestRafael Mendonça França2017-06-023-29/+23
|\|
| * Consolidate database specific JSON types to `Type::Json`Ryuta Kamizono2017-05-302-29/+13
| |
| * Fix UUID column with `null: true` and `default: nil`Ryuta Kamizono2017-05-301-0/+10
| | | | | | | | | | | | | | `quote_default_expression` can be passed nil value when `null: true` and `default: nil`. This addressed in that case. Fixes #29222.
* | Make sure to disable extension after testyuuji.yaginuma2017-05-311-6/+2
|/ | | | | If keep the extension, can not test properly to make sure that extension can be enabled.
* Prevent extra `current_database` query for `encoding`/`collation`/`ctype`Ryuta Kamizono2017-05-281-3/+9
|