aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/type
Commit message (Collapse)AuthorAgeFilesLines
* 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`