I was working on another branch and as part of my commit, Rubocop
removed a validation (but not the spec that asserted the validation).
Below is the "non-updating" rubocop offense on the other branch.
```shell
❯ rubocop ./app/models/notification_subscription.rb
Inspecting 1 file
C
Offenses:
app/models/notification_subscription.rb:13:29: C: [Correctable]
Rails/RedundantPresenceValidationOnBelongsTo: Remove explicit presence
validation for notifiable_id.
validates :notifiable_id, presence: true
^^^^^^^^^^^^^^
1 file inspected, 1 offense detected, 1 offense auto-correctable
```
To remediate, I ran:
```shell
> rubocop --only "Rails/RedundantPresenceValidationOnBelongsTo" \
--auto-correct
```
This resolved the `app/models`. Then did some regex magic and removed
the assertions from `spec/models`.
For Forem folks, I wrote a [forem.team post][1] discuss if this is how
we want to proceed.
[1]:https://forem.team/jeremy/rubocop-auto-updating-mayhem-33a6
25 lines
667 B
Ruby
25 lines
667 B
Ruby
require "rails_helper"
|
|
|
|
RSpec.describe DiscussionLock, type: :model do
|
|
let(:discussion_lock) { create(:discussion_lock) }
|
|
|
|
describe "relationships" do
|
|
it { is_expected.to belong_to(:article) }
|
|
it { is_expected.to belong_to(:locking_user) }
|
|
end
|
|
|
|
describe "validations" do
|
|
subject { discussion_lock }
|
|
|
|
it { is_expected.to validate_uniqueness_of(:article_id) }
|
|
|
|
it "sanitizes attributes before validation", :aggregate_failures do
|
|
discussion_lock = described_class.new(notes: "", reason: " ")
|
|
|
|
discussion_lock.validate
|
|
|
|
expect(discussion_lock.notes).to be_nil
|
|
expect(discussion_lock.reason).to be_nil
|
|
end
|
|
end
|
|
end
|