I have a module with an attribute which data type is an array.
class User < ActiveRecord::Base
attribute :nicknames, Array[String]
validates :nicknames, length: {maximum: 3}
end
How can test validation of quantity of nicknames of the user? I've tried to implement
require 'spec_helper'
RSpec.describe User, type: :model do
describe 'validation'
it { is_expected.to validate_length_of(:nicknames).is_at_most(3) }
end
end
but get the following error:
Failure/Error: it { is_expected.to validate_length_of('nickname').is_at_most(3) }
Expected User to validate that the length of
:nicknames is at most 3, but this could not be proved.
After setting :nicknames to
As indicated in the message above, :nicknames seems to be changing
certain values as they are set, and this could have something to do
with why this test is failing. If you've overridden the writer method
for this attribute, then you may need to change it to make this test
pass, or do something else entirely.
Also have tried methods from this problem but with no luck. Thanks in advance and any help will be appreciated.