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
60 lines
1.9 KiB
Ruby
60 lines
1.9 KiB
Ruby
require "rails_helper"
|
|
|
|
RSpec.describe Follow, type: :model do
|
|
let(:user) { create(:user) }
|
|
let(:tag) { create(:tag) }
|
|
let(:user_2) { create(:user) }
|
|
|
|
describe "validations" do
|
|
subject { user.follow(user_2) }
|
|
|
|
it { is_expected.to validate_inclusion_of(:subscription_status).in_array(%w[all_articles none]) }
|
|
it { is_expected.to validate_presence_of(:followable_type) }
|
|
it { is_expected.to validate_presence_of(:follower_type) }
|
|
it { is_expected.to validate_presence_of(:subscription_status) }
|
|
end
|
|
|
|
it "follows user" do
|
|
user.follow(user_2)
|
|
expect(user.following?(user_2)).to eq(true)
|
|
end
|
|
|
|
it "calculates points with explicit and implicit combined" do
|
|
user.follow(tag)
|
|
follow = described_class.last
|
|
follow.explicit_points = 2.0
|
|
follow.implicit_points = 3.0
|
|
follow.save
|
|
expect(follow.points).to eq(5.0)
|
|
end
|
|
|
|
context "when enqueuing jobs" do
|
|
it "enqueues send notification worker" do
|
|
expect do
|
|
described_class.create(follower: user, followable: user_2)
|
|
end.to change(Follows::SendEmailNotificationWorker.jobs, :size).by(1)
|
|
end
|
|
end
|
|
|
|
context "when creating and inline" do
|
|
it "touches the follower user while creating" do
|
|
timestamp = 1.day.ago
|
|
user.update_columns(updated_at: timestamp, last_followed_at: timestamp)
|
|
described_class.create!(follower: user, followable: user_2)
|
|
|
|
user.reload
|
|
expect(user.updated_at).to be > timestamp
|
|
expect(user.last_followed_at).to be > timestamp
|
|
end
|
|
|
|
it "sends an email notification" do
|
|
allow(ForemInstance).to receive(:smtp_enabled?).and_return(true)
|
|
user_2.notification_setting.update(email_follower_notifications: true)
|
|
expect do
|
|
Sidekiq::Testing.inline! do
|
|
described_class.create!(follower: user, followable: user_2)
|
|
end
|
|
end.to change(EmailMessage, :count).by(1)
|
|
end
|
|
end
|
|
end
|