aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/type
Commit message (Collapse)AuthorAgeFilesLines
* Fix year value when casting a multiparameter time hashAndrew White2019-01-211-0/+22
| | | | | | | | | | | | | | | | | | | | | | | When assigning a hash to a time attribute that's missing a year component (e.g. a `time_select` with `:ignore_date` set to `true`) then the year defaults to 1970 instead of the expected 2000. This results in the attribute changing as a result of the save. Before: event = Event.new(start_time: { 4 => 20, 5 => 30 }) event.start_time # => 1970-01-01 20:30:00 UTC event.save event.reload event.start_time # => 2000-01-01 20:30:00 UTC After: event = Event.new(start_time: { 4 => 20, 5 => 30 }) event.start_time # => 2000-01-01 20:30:00 UTC event.save event.reload event.start_time # => 2000-01-01 20:30:00 UTC
* Enable `Performance/UnfreezeString` copyuuji.yaginuma2018-09-231-3/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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 ```
* Use assert_predicate and assert_not_predicateDaniel Colson2018-01-251-3/+3
|
* Use frozen-string-literal in ActiveRecordKir Shatrov2017-07-196-0/+12
|
* Revert "Merge pull request #29540 from kirs/rubocop-frozen-string"Matthew Draper2017-07-026-6/+0
| | | | | This reverts commit 3420a14590c0e6915d8b6c242887f74adb4120f9, reversing changes made to afb66a5a598ce4ac74ad84b125a5abf046dcf5aa.
* Enforce frozen string in RubocopKir Shatrov2017-07-016-0/+6
|
* Moved database-specific ActiveModel types into ActiveRecordIain Beeston2016-10-141-0/+17
| | | | ie. DecimalWithoutScale, Text and UnsignedInteger
* Merge pull request #24571 from raimo/patch-1Sean Griffin2016-10-041-1/+1
|\ | | | | Print the proper ::Float::INFINITY value when used as a default value
| * Print the proper ::Float::INFINITY value when used as a default valueRaimo Tuisku2016-05-231-1/+1
| | | | | | | | Addresses https://github.com/rails/rails/issues/22396
* | normalizes indentation and whitespace across the projectXavier Noria2016-08-061-1/+0
| |
* | modernizes hash syntax in activerecordXavier Noria2016-08-061-1/+1
| |
* | applies new string literal convention in activerecord/testXavier Noria2016-08-063-31/+31
|/ | | | | The current code base is not uniform. After some discussion, we have chosen to go with double quotes by default.
* skipped assertion on datetime seconds precision as it is only valid for ↵Ronak Jangir2015-09-241-0/+1
| | | | newer mysql versions
* Fixed taking precision into count when assigning a value to timestamp attributeBogdan Gusiev2015-09-231-0/+13
| | | | | | | | | | | | | | | | | Timestamp column can have less precision than ruby timestamp In result in how big a fraction of a second can be stored in the database. m = Model.create! m.created_at.usec == m.reload.created_at.usec # => false # due to different seconds precision in Time.now and database column If the precision is low enough, (mysql default is 0, so it is always low enough by default) the value changes when model is reloaded from the database. This patch fixes that issue ensuring that any timestamp assigned as an attribute is converted to column precision under the attribute.
* Move the appropriate type tests to the Active Model suiteSean Griffin2015-09-214-187/+0
| | | | | | | | | Any tests for a type which is not overridden by Active Record, and does not test the specifics of the attributes API interacting in more complex ways have no reason to be in the Active Record suite. Doing this revealed that the implementation of the date and time types in AM was actually completely broken, and incapable of returning any value other than `nil`.
* Respect scale of the column in the Decimal typeRafael Mendonça França2015-09-011-0/+5
| | | | [Rafael Mendonça França + Jean Boussier]
* remove redundant parenthesiskaranarora2015-05-141-1/+1
|
* `type_cast_from_user` -> `cast`Sean Griffin2015-02-173-28/+28
|
* `type_cast_for_database` -> `serialize`Sean Griffin2015-02-172-17/+17
|
* `Type#type_cast_from_database` -> `Type#deserialize`Sean Griffin2015-02-171-1/+1
|
* Add a global type registry, used to lookup and register typesSean Griffin2015-02-151-0/+133
| | | | | | | | As per previous discussions, we want to give users the ability to reference their own types with symbols, instead of having to pass the object manually. This adds the class that will be used to do so. ActiveRecord::Type.register(:money, MyMoneyType)
* Allow a symbol to be passed to `attribute`, in place of a type objectSean Griffin2015-02-061-1/+1
| | | | | | | | | | | | | | | | | | The same is not true of `define_attribute`, which is meant to be the low level no-magic API that sits underneath. The differences between the two APIs are: - `attribute` - Lazy (the attribute will be defined after the schema has loaded) - Allows either a type object or a symbol - `define_attribute` - Runs immediately (might get trampled by schema loading) - Requires a type object This was the last blocker in terms of public interface requirements originally discussed for this feature back in May. All the implementation blockers have been cleared, so this feature is probably ready for release (pending one more look-over by me).
* Move integer range validation to never raise on assignmentSean Griffin2015-01-232-15/+28
| | | | | | | | | | | | | | | | | Given that this was originally added to normalize an error that would have otherwise come from the database (inconsistently), it's more natural for us to raise in `type_cast_for_database`, rather than `type_cast_from_user`. This way, things like numericality validators can handle it instead if the user chooses to do so. It also fixes an issue where assigning an out of range value would make it impossible to assign a new value later. This fixes several vague issues, none of which were ever directly reported, so I have no issue number to give. Places it was mentioned which I can remember: - https://github.com/thoughtbot/shoulda-matchers/blob/9ba21381d7caf045053a81f32df7de2f49687820/lib/shoulda/matchers/active_model/allow_value_matcher.rb#L261-L263 - https://github.com/rails/rails/issues/18653#issuecomment-71197026
* Stop relying on columns in sqlite quoting testsSean Griffin2015-01-011-0/+6
| | | | | | The string encoding test wasn't using the types for anything. The boolean casting test included logic that should be in the tests for the types, and the string test was legitimately not testing anything useful.
* Fixing numeric attrs when set to same negative valueDaniel Fox2014-12-232-0/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This bug occurs when an attribute of an ActiveRecord model is an ActiveRecord::Type::Integer type or a ActiveRecord::Type::Decimal type (or any other type that includes the ActiveRecord::Type::Numeric module. When the value of the attribute is negative and is set to the same negative value, it is marked as changed. Take the following example of a Person model with the integer attribute age: class Person < ActiveRecord::Base # age :integer(4) end The following will produce the error: person = Person.new(age: -1) person.age = -1 person.changes => { "age" => [-1, -1] } person.age_changed? => true The problematic line is here: module ActiveRecord module Type module Numeric ... def non_numeric_string?(value) # 'wibble'.to_i will give zero, we want to make sure # that we aren't marking int zero to string zero as # changed. value.to_s !~ /\A\d+\.?\d*\z/ end end end end The regex match doesn't accept numbers with a leading '-'.
* Correctly handle Float -> BigDecimal with unspecified precisionSean Griffin2014-12-221-0/+5
| | | | Fixes #18122
* Remove unused lineRyuta Kamizono2014-12-171-1/+0
|
* Fix undesirable RangeError by Type::Integer. Add Type::UnsignedInteger.Ryuta Kamizono2014-12-121-0/+18
|
* Merge pull request #17807 from jvperrin/correct-integer-testRafael Mendonça França2014-11-271-1/+1
|\ | | | | Correct test description for large integer test
| * Correct test description for large integer testJason Perrin2014-11-031-1/+1
| |
* | Reintroduce cache with testsSean Griffin2014-11-191-0/+32
| |
* | Add tests for `TypeMap#fetch` and push up to `TypeMap`Sean Griffin2014-11-191-0/+15
| | | | | | | | | | | | | | It doesn't make sense for the subclass to implement this method, and not have it on the parent. We can also DRY up the implementation of `#lookup` to be defined in terms of fetch, which will give us a single point of entry
* | That last test was incorrect... ☕Sean Griffin2014-11-191-10/+0
| |
* | Introduce test to demonstrate regression caused by da99a2a2Sean Griffin2014-11-191-0/+10
| |
* | Revert the behavior of booleans in string columns to that of 4.1Sean Griffin2014-11-091-2/+2
|/ | | | | | | | | | | | | | | | | | | | | Why are people assigning booleans to string columns? >_> We unintentionally changed the behavior on Sqlite3 and PostgreSQL. Boolean values should cast to the database's representation of true and false. This is 't' and 'f' by default, and "1" and "0" on Mysql. The implementation to make the connection adapter specific behavior is hacky at best, and should be re-visted once we decide how we actually want to separate the concerns related to things that should change based on the database adapter. That said, this isn't something I'd expect to change based on my database adapter. We're storing a string, so the way the database represents a boolean should be irrelevant. It also seems strange for us to give booleans special behavior at all in string columns. Why is `to_s` not sufficient? It's inconsistent and confusing. Perhaps we should consider deprecating in the future. Fixes #17571
* Use the correct values for int max and minSean Griffin2014-10-311-0/+106
| | | | | We had accidentally gone one power of two too far. In addition, we need to handle minimum values as well as the maximum.
* Fix type casting to Decimal from Float with ...joker10072014-08-011-0/+5
| | | | | When I defines large precision column at RDBMS, I assigns float value, raise ArgumentError (precision too large).
* Fix decimal_test module and add new test for object responding to to_dMariano Valles2014-07-161-6/+15
|
* Fix case statement to use ::Numeric and ::StringMariano Valles2014-07-161-0/+24
|
* Detect in-place modifications on StringsSean Griffin2014-06-171-0/+36
|
* Move types to the top level `ActiveRecord` namespaceSean Griffin2014-05-271-0/+130
`ActiveRecord::ConnectionAdapters::Type::Value` => `ActiveRecord::Type::Value`