aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/validations_test.rb
Commit message (Collapse)AuthorAgeFilesLines
* Add test case for ce48b5a366482d4b4c4c053e1e39e79d71987197Ryuta Kamizono2018-12-181-0/+7
|
* Fix numericality validator not to be affected by custom getterRyuta Kamizono2018-08-131-1/+17
| | | | | | | | | | | | | | | | | | | | Since fe9547b6, numericality validator would parse raw value only when a value came from user to work type casting to a value from database. But that was caused a regression that the validator would work against getter value instead of parsed raw value, a getter is sometimes customized by people. #33550 There we never guarantees that the value before type cast was going to the used in this validation (actually here is only place that getter value might not be used), but we should not change the behavior unless there is some particular reason. The purpose of fe9547b6 is to work type casting to a value from database. We could achieve the purpose by using `read_attribute`, without using getter value. Fixes #33550.
* Replace `assert !` with `assert_not`Daniel Colson2018-04-191-2/+2
| | | | | This autocorrects the violations after adding a custom cop in 3305c78dcd.
* Use assert_predicate and assert_not_predicateDaniel Colson2018-01-251-6/+6
|
* Suppress `warning: BigDecimal.new is deprecated` in activerecordYasuo Honda2017-12-131-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | `BigDecimal.new` has been deprecated in BigDecimal 1.3.3 which will be a default for Ruby 2.5. Refer https://github.com/ruby/bigdecimal/commit/533737338db915b00dc7168c3602e4b462b23503 ``` $ cd rails/activerecord/ $ git grep -l BigDecimal.new | grep \.rb | xargs sed -i -e "s/BigDecimal.new/BigDecimal/g" ``` - Changes made only to Active Record. Will apply the same change to other module once this commit is merged. - The following deprecation has not been addressed because it has been reported at `ActiveRecord::Result.new`. `ActiveRecord::Result.ancestors` did not show `BigDecimal`. * Not addressed ```ruby /path/to/rails/activerecord/lib/active_record/connection_adapters/mysql/database_statements.rb:34: warning: BigDecimal.new is deprecated ``` * database_statements.rb:34 ```ruby ActiveRecord::Result.new(result.fields, result.to_a) if result ``` * ActiveRecord::Result.ancestors ```ruby [ActiveRecord::Result, Enumerable, ActiveSupport::ToJsonWithActiveSupportEncoder, Object, Metaclass::ObjectMethods, Mocha::ObjectMethods, PP::ObjectMixin, ActiveSupport::Dependencies::Loadable, ActiveSupport::Tryable, JSON::Ext::Generator::GeneratorMethods::Object, Kernel, BasicObject] ``` This commit has been tested with these Ruby and BigDecimal versions - ruby 2.5 and bigdecimal 1.3.3 ``` $ ruby -v ruby 2.5.0dev (2017-12-14 trunk 61217) [x86_64-linux] $ gem list |grep bigdecimal bigdecimal (default: 1.3.3, default: 1.3.2) ``` - ruby 2.4 and bigdecimal 1.3.0 ``` $ ruby -v ruby 2.4.2p198 (2017-09-14 revision 59899) [x86_64-linux-gnu] $ gem list |grep bigdecimal bigdecimal (default: 1.3.0) ``` - ruby 2.3 and bigdecimal 1.2.8 ``` $ ruby -v ruby 2.3.5p376 (2017-09-14 revision 59905) [x86_64-linux] $ gem list |grep -i bigdecimal bigdecimal (1.2.8) ``` - ruby 2.2 and bigdecimal 1.2.6 ``` $ ruby -v ruby 2.2.8p477 (2017-09-14 revision 59906) [x86_64-linux] $ gem list |grep bigdecimal bigdecimal (1.2.6) ```
* Use frozen-string-literal in ActiveRecordKir Shatrov2017-07-191-0/+2
|
* Revert "Merge pull request #29540 from kirs/rubocop-frozen-string"Matthew Draper2017-07-021-1/+0
| | | | | This reverts commit 3420a14590c0e6915d8b6c242887f74adb4120f9, reversing changes made to afb66a5a598ce4ac74ad84b125a5abf046dcf5aa.
* Enforce frozen string in RubocopKir Shatrov2017-07-011-0/+1
|
* Fix regression in Numericality validator where extra decimal places on Bradley Priest2017-05-271-0/+14
| | | a user input for a decimal column were ignored by numerically validations
* Creating a new Topic class instead of class_eval for the existing oneYasuo Honda2016-08-111-4/+2
| | | | | | since it affects another test `ReflectionTest#test_read_attribute_names` Address #26099
* remove redundant curlies from hash argumentsXavier Noria2016-08-061-1/+1
|
* modernizes hash syntax in activerecordXavier Noria2016-08-061-4/+4
|
* applies new string literal convention in activerecord/testXavier Noria2016-08-061-11/+11
| | | | | The current code base is not uniform. After some discussion, we have chosen to go with double quotes by default.
* remove args from assert_nothing_raised in testsTara Scherner de la Fuente2016-02-221-1/+1
|
* `validates_acceptance_of` shouldn't require a database connectionSean Griffin2015-09-251-0/+11
| | | | | | | | | | | | | The implementation of `attribute_method?` on Active Record requires establishing a database connection and querying the schema. As a general rule, we don't want to require database connections for any class macro, as the class should be able to be loaded without a database (e.g. for things like compiling assets). Instead of eagerly defining these methods, we do it lazily the first time they are accessed via `method_missing`. This should not cause any performance hits, as it will only hit `method_missing` once for the entire class.
* Validate multiple contexts on `valid?` and `invalid?` at once.Dmitry Polushkin2015-09-071-0/+7
| | | | | | | | | | | | | | | | | | Example: ```ruby class Person include ActiveModel::Validations attr_reader :name, :title validates_presence_of :name, on: :create validates_presence_of :title, on: :update end person = Person.new person.valid?([:create, :update]) # => true person.errors.messages # => {:name=>["can't be blank"], :title=>["can't be blank"]} ```
* Revert "Merge pull request #21069 from ↵Rafael Mendonça França2015-09-071-7/+0
| | | | | | | | | dmitry/feature/validate-multiple-contexts-at-once" This reverts commit 51dd2588433457960cca592d5b5dac6e0537feac, reversing changes made to ecb4e4b21b3222b823fa24d4a0598b1f2f63ecfb. This broke Active Record tests
* Validate multiple contexts on `valid?` and `invalid?` at once.Dmitry Polushkin2015-07-301-0/+7
| | | | | | | | | | | | | | | | | | Example: ```ruby class Person include ActiveModel::Validations attr_reader :name, :title validates_presence_of :name, on: :create validates_presence_of :title, on: :update end person = Person.new person.valid?([:create, :update]) # => true person.errors.messages # => {:name=>["can't be blank"], :title=>["can't be blank"]} ```
* 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).
* Removed magic comments # encoding: utf-8 , since its default from ruby 2.0 ↵Vipul A M2015-02-031-1/+0
| | | | onwards.
* Ensure numericality validations work with mutationSean Griffin2014-12-011-0/+13
| | | | | | | | | | | | | | | | | | | | | The detection of in-place changes caused a weird unexpected issue with numericality validations. That validator (out of necessity) works on the `_before_type_cast` version of the attribute, since on an `:integer` type column, a non-numeric string would type cast to 0. However, strings are mutable, and we changed strings to ensure that the post type cast version of the attribute was a different instance than the before type cast version (so the mutation detection can work properly). Even though strings are the only mutable type for which a numericality validation makes sense, special casing strings would feel like a strange change to make here. Instead, we can make the assumption that for all mutable types, we should work on the post-type-cast version of the attribute, since all cases which would return 0 for non-numeric strings are immutable. Fixes #17852
* Build fix when running in isolationArun Agrawal2014-11-141-0/+1
| | | | | `Computer` class needs to be require See #17217 for more details
* Add AR::Base#validate! methodBogdan Gusiev2014-06-231-0/+14
| | | | | Acts same as valid? but raises AR::RecordInvalid exception if validation fails
* Merge pull request #10662 from ↵Carlos Antonio da Silva2014-05-111-9/+9
|\ | | | | | | | | take/change-test-name-for-ActiveRecord--Validations#valid- Refactor AR's validations_test.rb
| * Refactor AR's validations_test.rbTakehiro Adachi2013-12-031-9/+9
| | | | | | | | | | | | | | | | | | | | The `:context` switch feature is implemented in ActiveRecord::Validations#valid? method, so we should rename the test names, and execute `valid?` in the test. Change test name in AR's validations_test.rb This test is testing save method's code
* | ActiveRecord/ActiveModel '#validate' alias for 'valid?'Henrik Nyh2014-03-271-0/+15
| | | | | | | | | | | | | | | | It's unintuitive to call '#valid?' when you want to run validations but don't care about the return value. The alias in ActiveRecord isn't strictly necessary (the ActiveModel alias is still in effect), but it clarifies.
* | Prefer assert_raise instead of flunk + rescue to test for exceptionsCarlos Antonio da Silva2013-12-191-5/+3
|/ | | | | | Change most tests to make use of assert_raise returning the raised exception rather than relying on a combination of flunk + rescue to check for exception types/messages.
* Typo fixes [ci skip]Akshay Vishnoi2013-11-301-1/+1
|
* Remove mass assignment security from ActiveRecordGuillermo Iguaran2012-09-161-6/+0
|
* remove tests for #with_scope (it's now deprecated)Jon Leighton2012-04-251-24/+0
|
* Deprecate set_table_name in favour of self.table_name= or defining your own ↵Jon Leighton2011-11-291-1/+1
| | | | method.
* please use ruby -I lib:test path/to/test.rb, or export RUBY_OPTAaron Patterson2011-06-061-1/+1
|
* Refactor Active Record test connection setup. Please see the ↵Jon Leighton2011-06-041-1/+1
| | | | RUNNING_UNIT_TESTS file for details, but essentially you can now configure things in test/config.yml. You can also run tests directly via the command line, e.g. ruby path/to/test.rb (no rake needed, uses default db connection from test/config.yml). This will help us fix the CI by enabling us to isolate the different Rails versions to different databases.
* Cleanup deprecation warnings in active recordCarlos Antonio da Silva2010-09-061-43/+0
| | | | Signed-off-by: José Valim <jose.valim@gmail.com>
* removing unused models from testsSubba Rao Pasupuleti2010-07-211-5/+0
| | | | | | [#5153 state:resolved] Signed-off-by: José Valim <jose.valim@gmail.com>
* Validators should at model level and not at AR:Base level [Closes #4804]Neeraj Singh2010-06-101-0/+10
| | | | | | [#4804 state:resolved] Signed-off-by: David Heinemeier Hansson <david@loudthinking.com>
* Fix failing test.José Valim2010-05-211-6/+6
|
* Replace assert with assert_equal in some test casesNeeraj Singh2010-05-211-2/+2
| | | | | | [#4654 state:resolved] Signed-off-by: José Valim <jose.valim@gmail.com>
* Remove undocumented save_without_validation!Pratik Naik2010-05-111-6/+0
|
* Make sure valid? preceives the context as in ActiveModel API (ht: Carlos ↵José Valim2010-05-101-0/+17
| | | | Antonio)
* updated AR to work with the AMo model validation changesJosh Kalderimis2010-05-081-1/+1
|
* test_validates_acceptance_of_as_database_column fixedSantiago Pastorino2010-02-051-3/+3
| | | | | | [#3826 state:committed] Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
* Ensure deprecated validate methods are invoked when they are private [#3214 ↵José Valim2010-01-181-1/+18
| | | | status:resolved]
* save(false) is gone, use save(:validate => false) instead.José Valim2010-01-171-1/+9
|
* Simplify repair_validations on AR and make it work with new callbacks.José Valim2010-01-011-14/+14
|
* Don't publicize with_scope for tests since it may shadow public misuseJeremy Kemper2009-12-281-3/+3
|
* Move validator, human_name and human_attribute_name to ActiveModel, remove ↵José Valim2009-10-201-31/+0
| | | | | | deprecated error messages and add i18n_scope and lookup_ancestors. Signed-off-by: Carl Lerche <carllerche@mac.com>
* Fix default_error_messages back to the original messageAkira Matsuda2009-09-111-3/+6
| | | | Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
* Changed ActiveRecord to use new callbacks and speed up observers by only ↵José Valim2009-09-081-6/+3
| | | | | | notifying events that are actually being consumed. Signed-off-by: Joshua Peek <josh@joshpeek.com>
* Deprecate Model#validate/validate_on_create/validate_on_update. Use ↵Pratik Naik2009-03-211-0/+34
| | | | Model.validate :method and likewise