Closed professor closed 5 months ago
I thought this might be a solution, but it also fails:
it { is_expected.to validate_presence_of(:company_id).on(:create) }
Hey @professor, thanks for opening this issue. I'll have more time to look at it this Friday. Meanwhile, would you mind trying it out with a subject that is not persisted?
Using the example you provided
RSpec.describe MyClass, type: :model do
describe 'validation' do
subject { build(:my_class) }
it { is_expected.to validate_presence_of(:company_id) }
end
end
Please let me know if that works.
Yes, switching from a create
to a build
works.
Thank you for the suggstion.
Description
Rails 7.1 modifies
raise_on_assign_to_attr_readonly
link to be enabled by default. In the past, the code would silently carry on. I'm now fixing our code base to no longer write to a read_only attribute.It appears that shoulda-matchers attempts to write to read only attributes.
Reproduction Steps
Expected behavior
tests to pass
Actual behavior
System configuration
shoulda_matchers version: 6.2.0 rails version: 7.1.3.2 ruby version: 3.3.1