aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/adapters/postgresql/array_test.rb
Commit message (Collapse)AuthorAgeFilesLines
* Consistently apply adapter behavior when serializing arraysSean Griffin2017-01-031-3/+14
| | | | | | | | | | | | | | | | | | | | | | | | | | In f1a0fa9 we moved backend specific timestamp behavior out of the type and into the adapter. This was in line with our general attempt to reduce the number of adapter specific type subclasses. However, on PG, the array type performs all serialization, including database encoding in its serialize method. This means that we have converted the value into a string before reaching the database, so no adapter specific logic can be applied (and this also means that timestamp arrays were using the default `.to_s` method on the given object, which likely meant timestamps were being ignored in certain cases as well) Ultimately I want to do a more in depth refactoring which separates database serializer objects from the active model type objects, to give us a less awkward API for introducing the attributes API onto Active Model. However, in the short term, we follow the solution we've applied elsewhere for this. Move behavior off of the type and into the adapter, and use a data object to allow the type to communicate information up the stack. Fixes #27514.
* Dump array subtype options correctlyRyuta Kamizono2017-01-011-3/+5
| | | | | Currently schema dumper does not dump array subtype `precision` and `scale` options. This commit fixes the issue.
* use `force_encoding` instread of `encode!` to avoid `UndefinedConversionError`yuuji.yaginuma2016-11-171-3/+3
| | | | | | | | | | | | | | | `PG::TextEncoder::Array#encode` returns the encoded value with `ASCII-8BIT`. But in some cases, trying to convert `ASCII-8BIT` to `UTF-8` cause an error. ```ruby "{\xE3\x83\x95\xE3\x82\xA1\xE3\x82\xA4\xE3\x83\xAB}".encode!(Encoding::UTF_8) # => Encoding::UndefinedConversionError: "\xE3" from ASCII-8BIT to UTF-8 ``` Should use `force_encoding` to avoid this error. Follow up to 7ba3a48df5bfdc5e98506bb829f937e03b55a5b3 Ref: https://github.com/rails/rails/pull/23619#issuecomment-189924036
* Add more rubocop rules about whitespacesRafael Mendonça França2016-10-291-9/+9
|
* Attempt to maintain encoding for arrays of strings with PGSean Griffin2016-08-311-0/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | I still think that this is something that should be handled in the pg gem, but it's not going to end up happening there so we'll do it here instead. Once we bump to pg 0.19 we can pass the encoding to the `encode` method instead. This issue occurs because C has no concept of encoding (or strings, really). The bytes that we pass here when sending the value to the database will always be interpreted as whatever encoding the connection is currently configured to use. That means that roundtripping to the database will lose no information However, after assigning we round trip through our type system without hitting the database. The only way that we can do the "correct" thin here would be to actually give a reference to the connection to the array type and have it check the current value of the connection's encoding -- which I'm strongly opposed to. We could also pass in the encoding when it's constructed, but since that can change independently of the type I'm not a huge fan of that either. This feels like a reasonable middle ground, where if we have an array of strings we simply use the encoding of the string we're given. Fixes #26326.
* Merge pull request #26074 from kamipo/where_by_attribute_with_array_or_rangeRafael França2016-08-161-0/+6
|\ | | | | `where` by `array|range` attribute with array or range value
| * `where` by `array|range` attribute with array or range valueRyuta Kamizono2016-08-111-0/+6
| | | | | | | | | | | | | | Currently predicate builder cannot build a predicate for `array|range` attribute. This commit fixes the issue. Related #25671.
* | Add three new rubocop rulesRafael Mendonça França2016-08-161-1/+1
|/ | | | | | | | Style/SpaceBeforeBlockBraces Style/SpaceInsideBlockBraces Style/SpaceInsideHashLiteralBraces Fix all violations in the repository.
* applies remaining conventions across the projectXavier Noria2016-08-061-1/+1
|
* normalizes indentation and whitespace across the projectXavier Noria2016-08-061-13/+13
|
* applies new string literal convention in activerecord/testXavier Noria2016-08-061-40/+40
| | | | | The current code base is not uniform. After some discussion, we have chosen to go with double quotes by default.
* Do not specal case inspecting associated arrays of over 10 elements, ↵Kevin McPhillips2016-06-291-1/+6
| | | | preventing infinite looping in some cases.
* make it possible to run AR tests with bin/testYves Senn2015-06-111-4/+4
|
* Fix intermittent test failuresSean Griffin2015-03-091-0/+1
| | | | | | | | | | | The default value of `"pg_arrays"."tags"` is being changed to `[]` in one test, but the column information on the model isn't reset after it's changed back. As such, we think the default value is `[]` when in the database it's actually `nil`. That means any test which was assigning `[]` to a new record would have that key skipped with partial writes, as it hasn't changed from the default. However since the *actual* default value is `nil`, we get back values that the test doesn't expect, and it fails.
* prefer `drop_table if_exists: true` over raw SQL.Yves Senn2015-02-181-1/+1
| | | | | | | /cc @yahonda This makes it easier for third party adapters to run our tests, even if that database does not support IF EXISTS.
* `type_cast_for_database` -> `serialize`Sean Griffin2015-02-171-3/+3
|
* `Type#type_cast_from_database` -> `Type#deserialize`Sean Griffin2015-02-171-3/+3
|
* Remove unused lineRyuta Kamizono2015-02-081-1/+0
|
* rm `Type#number?`Sean Griffin2015-02-071-2/+0
| | | | | This predicate is only used in `query_attribute`, and is relatively easy to remove without adding a bunch of is a checks.
* Removed magic comments # encoding: utf-8 , since its default from ruby 2.0 ↵Vipul A M2015-02-031-1/+0
| | | | onwards.
* Remove most type related predicates from `Column`Sean Griffin2015-01-301-7/+9
| | | | | | Remaining are `limit`, `precision`, `scale`, and `type` (the symbol version). These will remain on the column, since they mirror the options to the `column` method in the schema definition DSL
* Should escape regexp wildcard character `.`Ryuta Kamizono2015-01-191-2/+2
| | | | | `.` is regexp meta character. It should be escape for `assert_match` correctly.
* Prefer `array?` rather than `array`Ryuta Kamizono2015-01-041-3/+3
| | | | | | Slightly refactoring `PostgreSQLColumn`. `array` should be readonly. `default_function` should be initialized by `super`. `sql_type` has been removed `[]`. Since we already choose to remove it we should not change.
* Revert to 4.1 behavior for casting PG arraysSean Griffin2014-12-081-5/+20
| | | | | | | | | | The user is able to pass PG string literals in 4.1, and have it converted to an array. This is also possible in 4.2, but it would remain in string form until saving and reloading, which breaks our `attr = save.reload.attr` contract. I think we should deprecate this in 5.0, and only allow array input from user sources. However, this currently constitutes a breaking change to public API that did not go through a deprecation cycle.
* pg tests, move uniqueness validation test to array tests.Yves Senn2014-12-021-0/+15
|
* tests, move schema shorthand assertions into pg specific tests.Yves Senn2014-12-021-0/+8
|
* pg, test assigning non-array values to an array column. Closes #14716.Yves Senn2014-10-161-0/+9
| | | | | | The behavior has changed since 4.1 and non-array values are no longer type casted to a blank array. This way the user can define custom validations on that property.
* Added enable_extension! to helperAbdelkader Boudih2014-09-051-6/+2
|
* Remove the `text?` predicate from the type objectsSean Griffin2014-07-061-1/+0
| | | | | | | This was only used for uniqueness validations. The first usage was in conjunction with `limit`. Types which cast to string, but are not considered text cannot have a limit. The second case was only with an explicit `:case_sensitive => true` option given by the user.
* Consolidate testing of update_all type castingSean Griffin2014-06-261-10/+0
| | | | | | | | | | | | | | We have several test cases on "tricky" types that are essentially testing that `update_all` goes through the same type casting behavior as a normal assignment + save. We recently had another case to add this test for another type in https://github.com/rails/rails/pull/12742. Rather than testing this separately for every type which is "tricky" when round tripping, let's instead have a fairly exhaustive test that ensures we're getting the correct values at every step for `update_all`. Given the structure of the code now, we can be confident that if the type is correct, and `update_all` is type casting correctly, we're going to get the right behavior for all types.
* Reconnect after possibly enabling hstoreMatthew Draper2014-06-181-0/+2
|
* Merge pull request #15782 from sgrif/sg-column-defaultsMatthew Draper2014-06-181-7/+4
|\ | | | | Don't type cast the default on the column
| * Don't type cast the default on the columnSean Griffin2014-06-171-7/+4
| | | | | | | | | | | | | | If we want to have type decorators mess with the attribute, but not the column, we need to stop type casting on the column. Where possible, we changed the tests to test the value of `column_defaults`, which is public API. `Column#default` is not.
* | Enable hstore in array testsSean Griffin2014-06-171-0/+6
| |
* | Detect mutations of arrays and array membersSean Griffin2014-06-171-0/+23
| |
* | Ensure `OID::Array#type_cast_for_database` matches PG's quoting behaviorSean Griffin2014-06-171-0/+18
|/ | | | | | Also takes a step towards supporting types which use a character other than ',' for the delimiter (`box` is the only built in type for which this is the case)
* PG arrays should type cast user inputSean Griffin2014-06-131-2/+7
| | | | | | We guarantee that `model.value` does not change after `model.save && model.reload`. This requires type casting user input for non-string types.
* Rename `type_cast` to `type_cast_from_database`Sean Griffin2014-06-091-3/+3
| | | | | | | | In some cases there is a difference between the two, we should always be doing one or the other. For convenience, `type_cast` is still a private method on type, so new types that do not need different behavior don't need to implement two methods, but it has been moved to private so it cannot be used accidentally.
* Ensure time zones don't change after round trip with array columnsSean Griffin2014-06-071-0/+2
| | | | | The times would be equivalent, even if they were in different time zones. E.g. 12:00 UTC == 5:00 PDT
* Don't rely on `Time.current` in testsSean Griffin2014-06-071-5/+10
| | | | Millisecond inequality causes failures on Travis
* Add array support when time zone aware attributes are enabledSean Griffin2014-06-071-0/+16
|
* Revert "test pg, we don't care about the internal state of `column#default`."Yves Senn2014-06-031-0/+4
| | | | | | | | | | | | | | Revert "test pg, remove unused column assignments. Follow up to 254cdf47" Related to #15492 This reverts commit 254cdf4728291277f3fbaa854f34495030e476b4. This reverts commit 4bcf9029452e0c760af04faab6b549710401e8cf. There are public methods that assume `Column#default` is type casted. The return value of `Column#default` is publicly relevant and should not change. /cc @sgrif
* test pg, remove unused column assignments. Follow up to 254cdf47Yves Senn2014-06-031-2/+0
|
* test pg, rm unused requires.Yves Senn2014-06-031-2/+0
|
* test pg, we don't care about the internal state of `column#default`.Yves Senn2014-06-031-2/+0
| | | | | That data is internal to Active Record. What we care about is that new records have the right default value.
* Rename `oid_type` to `cast_type` to make PG columns consistentSean Griffin2014-05-211-10/+1
|
* test, move all pg array tests into `postgresql/array_test.rb`.Yves Senn2014-05-131-5/+28
|
* test, use `columns_hash[]` in place of `columns.find {}`.Yves Senn2014-05-121-2/+2
|
* pg, `change_column_default` accepts `[]`. Closes #11586.Yves Senn2014-05-121-1/+9
|
* PostgreSQL and SQLite, remove varchar limit. [Vladimir Sazhin & Toms Mikoss ↵Yves Senn2014-04-041-1/+1
| | | | | | | | | | | | | | | | & Yves Senn] There is no reason for the PG adapter to have a default limit of 255 on :string columns. See this snippet from the PG docs: Tip: There is no performance difference among these three types, apart from increased storage space when using the blank-padded type, and a few extra CPU cycles to check the length when storing into a length-constrained column. While character(n) has performance advantages in some other database systems, there is no such advantage in PostgreSQL; in fact character(n) is usually the slowest of the three because of its additional storage costs. In most situations text or character varying should be used instead.