1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
rails--rails/activerecord/test/models
Marcelo Lauxen 5fdc7d385f Fix read_attribute_before_type_cast to consider attribute aliases
Numericality validations for aliased attributes are not able
to get the value of the attribute before type cast because
activerecord was trying to get the value of the attribute based
on attribute alias name and not the original attribute name.

Example of validation which would pass even if a invalid value
would be provided

    class MyModel < ActiveRecord::Base
      validates :aliased_balance, numericality: { greater_than_or_equal_to: 0 }
    end

If we instantiate MyModel like bellow it will be valid because
when numericality validation runs it will not be able to get the
value before type cast, so it uses the type casted value
which will be `0.0` and the validation will match.

    subject = MyModel.new(aliased_balance: "abcd")
    subject.valid?

But if we declare MyModel like this

    class MyModel < ActiveRecord::Base
      validates :balance, numericality: { greater_than_or_equal_to: 0 }
    end

and assign "abcd" value to `balance` when the validations
run the model will be invalid because activerecord will be able
to get the value before type cast.

With this change `read_attribute_before_type_cast` will be able to
get the value before type cast even when the attr_name is an
attribute_alias.
2020-10-18 20:32:47 -03:00
..
admin Update prefix and allow suffix options for store accessors 2018-06-12 07:10:09 -07:00
autoloadable
publisher
account.rb Ensure Contextual validations fire on associations 2019-10-04 12:17:53 +01:00
admin.rb
aircraft.rb
arunit2_model.rb
author.rb Fix incorrect result when eager loading with duplicated through association with join scope 2020-08-07 13:39:30 +09:00
auto_id.rb
binary.rb
binary_field.rb Handle binary strings in Active Record serialized columns 2020-10-14 11:57:34 +02:00
bird.rb Revert "Merge pull request #35186 from kamipo/fix_leaking_scope_on_relation_create" 2019-02-15 12:06:45 +09:00
book.rb Fix pluck to correctly type cast same column names and association columns 2020-05-13 20:24:42 +09:00
book_destroy_async.rb Destroy associations in a background job. 2020-09-24 14:24:15 -04:00
boolean.rb
bulb.rb Allow extra scoping in callbacks when create on association relation 2020-04-10 16:10:49 +09:00
cake_designer.rb
car.rb Fix unscoping association scope on joins not to raise an error 2020-04-16 00:34:41 +09:00
carrier.rb
cat.rb
categorization.rb
category.rb Fix reset of the source association when through association is loaded 2019-02-20 13:48:51 +02:00
chef.rb
citation.rb Eager loading/preloading should be worked regardless of large number of records 2018-09-12 01:11:38 +09:00
club.rb Enable Layout/EmptyLinesAroundAccessModifier cop 2019-06-13 12:00:45 +09:00
college.rb Removes require_dependency from the AR test suite 2020-05-06 09:01:38 +02:00
column.rb
column_name.rb
comment.rb Allow where references association names as joined table alias names 2020-08-26 10:07:13 +09:00
company.rb has_attribute? should be aware of attribute aliases 2020-06-03 00:59:35 +09:00
company_in_module.rb Enable Layout/EmptyLinesAroundAccessModifier cop 2019-06-13 12:00:45 +09:00
computer.rb
contact.rb Deduplicate various Active Record schema cache structures 2019-06-03 13:31:42 +02:00
content.rb
contract.rb Fix pluck and select with custom attributes 2019-02-13 02:47:46 +09:00
country.rb create_table with :primary_key option has no effect if id: false is given 2018-10-27 22:57:16 +09:00
course.rb Removes require_dependency from the AR test suite 2020-05-06 09:01:38 +02:00
customer.rb Remove unused/missing to_money converter in the test/doc 2018-01-29 16:45:29 +09:00
customer_carrier.rb
dashboard.rb Revert "Refactor uncastable through reflection test to detect join key overrides" 2020-09-25 17:49:52 -04:00
default.rb
department.rb
destroy_async_parent.rb Destroy associations in a background job. 2020-09-24 14:24:15 -04:00
destroy_async_parent_soft_delete.rb Destroy associations in a background job. 2020-09-24 14:24:15 -04:00
developer.rb Support where with comparison operators (>, >=, <, and <=) 2020-07-06 10:24:48 +09:00
dl_keyed_belongs_to.rb Destroy associations in a background job. 2020-09-24 14:24:15 -04:00
dl_keyed_belongs_to_soft_delete.rb Destroy associations in a background job. 2020-09-24 14:24:15 -04:00
dl_keyed_has_many.rb Destroy associations in a background job. 2020-09-24 14:24:15 -04:00
dl_keyed_has_many_through.rb Destroy associations in a background job. 2020-09-24 14:24:15 -04:00
dl_keyed_has_one.rb Destroy associations in a background job. 2020-09-24 14:24:15 -04:00
dl_keyed_join.rb Destroy associations in a background job. 2020-09-24 14:24:15 -04:00
dog.rb
dog_lover.rb
doubloon.rb
drink_designer.rb Polymorphic has_one touch: Reset association cache result after create transaction 2019-07-31 05:59:23 +02:00
edge.rb
electron.rb
engine.rb
entrant.rb
entry.rb Add delegated type to Active Record (#39341) 2020-05-23 15:14:40 -07:00
essay.rb
essay_destroy_async.rb Destroy associations in a background job. 2020-09-24 14:24:15 -04:00
event.rb
eye.rb
face.rb Rename horrible and dirty to puzzled and confused in test models 2020-08-25 18:32:52 +02:00
family.rb
family_tree.rb
friendship.rb
frog.rb Merge pull request #30956 from CJStadler/with-lock-changed-deprecation 2018-03-28 13:11:01 -04:00
guid.rb
guitar.rb
hotel.rb
human.rb Rename horrible and dirty to puzzled and confused in test models 2020-08-25 18:32:52 +02:00
image.rb :polymorphic, :as, and :foreign_type are valid for polymorphic association 2019-11-10 10:54:58 +09:00
interest.rb Replace test Man with Human 2020-08-14 11:37:09 -04:00
invoice.rb
item.rb
job.rb
joke.rb
keyboard.rb
legacy_thing.rb
lesson.rb
line_item.rb
liquid.rb
matey.rb
measurement.rb This PR adds support to retrieve partitioned indexes when asking for 2020-02-06 07:36:44 +02:00
member.rb Ensure to calculate column aliases after all table aliases are constructed 2018-06-19 22:21:51 +09:00
member_detail.rb Using existing models for building multiple has_one through tests 2018-04-22 04:16:44 +09:00
member_type.rb
membership.rb
mentor.rb
message.rb Add delegated type to Active Record (#39341) 2020-05-23 15:14:40 -07:00
minimalistic.rb
minivan.rb
mixed_case_monkey.rb Replace test Man with Human 2020-08-14 11:37:09 -04:00
molecule.rb
mouse.rb Don't validate non dirty association targets 2019-07-15 18:21:20 +01:00
movie.rb
node.rb
non_primary_key.rb
notification.rb
numeric_data.rb Fix read_attribute_before_type_cast to consider attribute aliases 2020-10-18 20:32:47 -03:00
order.rb
organization.rb
other_dog.rb Removes require_dependency from the AR test suite 2020-05-06 09:01:38 +02:00
owner.rb
parrot.rb Exercise HABTM fixtures with foreign key constraints 2018-10-30 11:08:41 +09:00
person.rb Enable Layout/EmptyLinesAroundAccessModifier cop 2019-06-13 12:00:45 +09:00
personal_legacy_thing.rb
pet.rb
pet_treasure.rb
pirate.rb Ensure Contextual validations fire on associations 2019-10-04 12:17:53 +01:00
possession.rb
post.rb Avoid implicit create_with for StiClass.all 2020-08-01 23:02:50 +09:00
price_estimate.rb Fix numericality validator not to be affected by custom getter 2018-08-13 23:28:46 +09:00
professor.rb Removes require_dependency from the AR test suite 2020-05-06 09:01:38 +02:00
project.rb
publisher.rb
randomly_named_c1.rb
rating.rb Maintain extra joins for string or complex arel conditions 2019-10-04 13:29:18 +09:00
reader.rb
recipe.rb
record.rb
reference.rb Ensure StatementCache#execute never raises RangeError 2019-01-18 16:01:14 +09:00
reply.rb Allow attribute aliases for validates_uniqueness_of 2020-06-01 22:44:39 +09:00
section.rb Fix circular autosave: true 2018-07-23 14:53:27 -07:00
seminar.rb Fix circular autosave: true 2018-07-23 14:53:27 -07:00
session.rb Fix circular autosave: true 2018-07-23 14:53:27 -07:00
ship.rb Ensure Contextual validations fire on associations 2019-10-04 12:17:53 +01:00
ship_part.rb
shop.rb
shop_account.rb
speedometer.rb
sponsor.rb Make reflection.klass raise if polymorphic? not to be misused 2018-02-19 00:11:29 +09:00
squeak.rb Don't validate non dirty association targets 2019-07-15 18:21:20 +01:00
string_key_object.rb
student.rb
subscriber.rb Revert "Refactor uncastable through reflection test to detect join key overrides" 2020-09-25 17:49:52 -04:00
subscription.rb Revert "Refactor uncastable through reflection test to detect join key overrides" 2020-09-25 17:49:52 -04:00
tag.rb Fix newly added reflection order when redefining association 2018-01-04 22:55:16 +09:00
tagging.rb Don't update counter cache when through record was not destroyed 2018-01-14 20:46:19 +00:00
task.rb
topic.rb Allow define scope for Ruby reserved keywords 2020-05-14 21:39:39 +09:00
toy.rb
traffic_light.rb
treasure.rb
treaty.rb create_table with :primary_key option has no effect if id: false is given 2018-10-27 22:57:16 +09:00
tree.rb
tuning_peg.rb
tyre.rb
user.rb Allow token length configuration for has_secure_token method 2019-04-09 17:25:50 -04:00
uuid_child.rb
uuid_item.rb
uuid_parent.rb
vegetables.rb move ActiveRecord::Persistance#becomes logic into initialize block 2020-09-20 10:24:19 -06:00
vertex.rb
warehouse_thing.rb
wheel.rb Fix touch option to behave consistently with Persistence#touch method 2018-06-18 19:08:41 +09:00
without_table.rb
zine.rb