1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
Commit graph

20 commits

Author SHA1 Message Date
Ryuta Kamizono
20da6c7eac Raise ArgumentError for invalid :limit and :precision like as other 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`.

c9e4c848ee/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
```
2019-04-07 16:14:42 +09:00
Ryuta Kamizono
b78e3b5e21 Test that no datetime precision isn't truncated on assignment
Also, max precision (= 6) isn't regarded as unlimited precision for now.
2019-02-27 03:20:35 +09:00
Andrew White
4d9126cfcc Apply time column precision on assignment
In #20317, datetime columns had their precision applied on assignment but
that behaviour wasn't applied to time columns - this commit fixes that.

Fixes #30301.
2018-03-11 18:19:20 +00:00
Kir Shatrov
831be98f9a Use frozen-string-literal in ActiveRecord 2017-07-19 22:27:07 +03:00
Matthew Draper
87b3e226d6 Revert "Merge pull request #29540 from kirs/rubocop-frozen-string"
This reverts commit 3420a14590, reversing
changes made to afb66a5a59.
2017-07-02 02:15:17 +09:30
Kir Shatrov
cfade1ec7e Enforce frozen string in Rubocop 2017-07-01 02:11:03 +03:00
Ken Collins
984873003c Allow SQLServerAdapter to opt into a few tests. 2017-01-16 08:58:04 -05:00
Xavier Noria
b326e82dc0 applies remaining conventions across the project 2016-08-06 20:20:22 +02:00
Xavier Noria
80e66cc4d9 normalizes indentation and whitespace across the project 2016-08-06 20:16:27 +02:00
Xavier Noria
9617db2078 applies new string literal convention in activerecord/test
The current code base is not uniform. After some discussion,
we have chosen to go with double quotes by default.
2016-08-06 18:26:53 +02:00
Ryuta Kamizono
28ec8c4a57 Add quoted_time for truncating the date part of a time column value
Context #24522.

TIME column on MariaDB doesn't ignore the date part of the string when
it coerces to time.

```
root@localhost [test] > CREATE TABLE `foos` (`id` int AUTO_INCREMENT PRIMARY KEY, `start` time(0), `finish` time(4)) ENGINE=InnoDB;
Query OK, 0 rows affected (0.02 sec)

root@localhost [test] > INSERT INTO `foos` (`start`, `finish`) VALUES ('2000-01-01 12:30:00', '2000-01-01 12:30:00.999900');
Query OK, 1 row affected, 2 warnings (0.00 sec)

Note (Code 1265): Data truncated for column 'start' at row 1
Note (Code 1265): Data truncated for column 'finish' at row 1
root@localhost [test] > SELECT `foos`.* FROM `foos`;
+----+----------+---------------+
| id | start    | finish        |
+----+----------+---------------+
|  1 | 12:30:00 | 12:30:00.9999 |
+----+----------+---------------+
1 row in set (0.00 sec)

root@localhost [test] > SELECT  `foos`.* FROM `foos` WHERE `foos`.`start` = '2000-01-01 12:30:00' LIMIT 1;
Empty set (0.00 sec)

root@localhost [test] > SELECT  `foos`.* FROM `foos` WHERE `foos`.`start` = '12:30:00' LIMIT 1;
+----+----------+---------------+
| id | start    | finish        |
+----+----------+---------------+
|  1 | 12:30:00 | 12:30:00.9999 |
+----+----------+---------------+
1 row in set (0.00 sec)
```
2016-04-14 14:22:16 +09:00
Vipul A M
bbb8f518b5 Include running mariadb on travis
- Specify we want to run on latest stable ruby for mariadb

- change in runs of builds

Make mariadb? method publicly available
2016-04-14 04:42:41 +05:30
Jeremy Daer
2224d06cfa Support microsecond datetime precision on MariaDB 5.3+.
We support microsecond datetime precision for MySQL 5.6.4+. MariaDB has
supported it since 5.3.0, but even 10.x versions return a compatible
version string like `5.5.5-10.1.8-MariaDB-log` which we parse as 5.5.5,
before MySQL supported microsecond precision.

Specialize our version check to account for MariaDB to fix.
2016-04-08 18:41:25 -07:00
Yasuo Honda
87ee4f4149 Consolidate tests for time and datetime columns options, limit and precision 2015-11-30 20:37:45 +00:00
Brandon Weiss
0965863564 Closes rails/rails#18864: Renaming transactional fixtures to transactional tests
I’m renaming all instances of `use_transcational_fixtures` to
`use_transactional_tests` and “transactional fixtures” to
“transactional tests”.

I’m deprecating `use_transactional_fixtures=`. So anyone who is
explicitly setting this will get a warning telling them to use
`use_transactional_tests=` instead.

I’m maintaining backwards compatibility—both forms will work.
`use_transactional_tests` will check to see if
`use_transactional_fixtures` is set and use that, otherwise it will use
itself. But because `use_transactional_tests` is a class attribute
(created with `class_attribute`) this requires a little bit of hoop
jumping. The writer method that `class_attribute` generates defines a
new reader method that return the value being set. Which means we can’t
set the default of `true` using `use_transactional_tests=` as was done
previously because that won’t take into account anyone using
`use_transactional_fixtures`. Instead I defined the reader method
manually and it checks `use_transactional_fixtures`. If it was set then
it should be used, otherwise it should return the default, which is
`true`. If someone uses `use_transactional_tests=` then it will
overwrite the backwards-compatible method with whatever they set.
2015-03-16 11:35:44 -07:00
Ryuta Kamizono
cddc298dea Add schema dumping tests for datetime and time precision 2015-02-20 10:26:06 +09:00
Ryuta Kamizono
a088ee9691 Format the time string according to the precision of the time column
It is also necessary to format a time column like a datetime column.
2015-02-20 10:25:31 +09:00
Ryuta Kamizono
9ef870c042 Allow :precision option for time type columns 2015-02-20 10:24:08 +09:00
Sean Griffin
89ba5bb456 Revert "Allow :precision option for time type columns"
This reverts commit 1502caefd3.

The test suite for the mysql adapter broke when this commit was used
with MySQL 5.6.

Conflicts:
	activerecord/CHANGELOG.md
2015-02-17 11:12:52 -07:00
Ryuta Kamizono
1502caefd3 Allow :precision option for time type columns 2015-02-12 07:23:53 +09:00