Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

validate_presence_of throws ActiveRecord::SerializationTypeMismatch if attribute is serialized to an array #1220

Closed
stefanahman opened this issue Jun 12, 2019 · 4 comments · Fixed by #1222

Comments

@stefanahman
Copy link

This become a problem with https://github.com/thoughtbot/shoulda-matchers/releases/tag/v4.1.0

class Klass < ApplicationRecord
  serialize :arrays, Array
  validates :arrays, presence: true
end

# assertion
it { is_expected.to validate_presence_of(:arrays) }

This throws:

ActiveRecord::SerializationTypeMismatch:
  can't serialize `arrays`: was supposed to be a Array, but was a String. -- ""
@stefanahman
Copy link
Author

Similar to #643

@mcmire
Copy link
Collaborator

mcmire commented Jun 14, 2019

@stefanahman Hey! I merged in a PR that should fix this issue. Do you mind switching to master temporarily and see if it fixes your test?

@stefanahman
Copy link
Author

@stefanahman Hey! I merged in a PR that should fix this issue. Do you mind switching to master temporarily and see if it fixes your test?

This works fantastically!

@dannyfallon
Copy link

@mcmire I just bumped into this myself when upgrading from 3.x to 4.1 - are there any plans to cut a new release? 🤞

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

Successfully merging a pull request may close this issue.

3 participants