Fix typecasting array of integers #13451

Merged
merged 1 commit into from Dec 22, 2013

Conversation

Projects
None yet
3 participants
Contributor

dmathieu commented Dec 22, 2013

When typecasting an array of integers, if the value happens to be provided as strings (in forms for example), quote_and_escape will receive a Numeric and try gsubing on it.
This fixes it, returning the value without modifying it.

Closes #13444

+ def test_type_cast_integers
+ x = PgArray.new(ratings: ['1', '2'])
+ assert x.save!
+ assert_equal(['1', '2'], x.ratings)
@senny

senny Dec 22, 2013

Member

shouldn't this be assert_equal([1, 2], x.ratings) ?

@dmathieu

dmathieu Dec 22, 2013

Contributor

It will be once we save the record.
Unfortunately, with the way things work currently, the attribute's value is what we provide it, even though the values are typed when saved in the database.

@senny

senny Dec 22, 2013

Member

I did some work on json and hstore columns a while back to cast them directly, I'll look into it for array columns too. This is another discussion though. Patch looks good.

@dmathieu

dmathieu Dec 22, 2013

Contributor

🌻

senny added a commit that referenced this pull request Dec 22, 2013

@senny senny merged commit c0a6ffb into rails:master Dec 22, 2013

1 check passed

default The Travis CI build passed
Details

senny added a commit that referenced this pull request Dec 22, 2013

@dmathieu dmathieu deleted the dmathieu:quoting_non_strings branch Dec 22, 2013

Contributor

dmathieu commented Dec 22, 2013

Thank you Yves 😘

Member

schneems commented Dec 22, 2013

Thanks to both of you! ❤️

senny added a commit that referenced this pull request Dec 22, 2013

senny added a commit that referenced this pull request Dec 22, 2013

CHANGELOG entry for #13451. [ci skip]
Conflicts:

	activerecord/CHANGELOG.md

senny added a commit that referenced this pull request Dec 22, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment