docbrown/spec/models/follow_spec.rb
Michael Kohl 09828853f6
✂✂✂ Remove Connect (#14734)
* Remove Connect

* Remove more Connect specs

* Remove a lot more Connect code

* 🚮

* It all has to go

* Explicitly add httpclient

* Update application layout

* Remove messages association from User

* Start fixing specs

* reintroduce util function and refactor references

* Remove Connect Cypress test

* Fix more specs

* Remove Connect from listings

* Ignore contact_via_connect column on listings

* Remove contact_via_connect usages

* Ignore mod_chat_channel_id on tags

* Drop Connect tables

* Remove email_connect_messages from user notification settings

* Re-add httpclient 2.8.3

This was mistakenly removed as a merge conflict

* Don't need to exclude removed chat channel file

* Remove unneeded style for chat channels

* Remove unneeded channel list prop type

* Remove chat channels index/connect-link from getPageEntries

* Re-add comment from httpclient in Gemfile

* Remove connect references from mailers

Tag Moderators no longer have a chat channel

No longer will users be notified about new messages (there won't be
any)

No longer will users be notified about channel invites (you can't
invite anyone anymore)

* Don't configure Pusher and remove PUSHER_* from .env_sample

since it's removed from gemfile, the Pusher constant will not resolve, if this is
configured in the environment variables we'll fail to boot.

Co-authored-by: Suzanne Aitchison <suzanne@forem.com>
Co-authored-by: Dan Uber <dan@forem.com>
2021-11-18 08:21:00 -06:00

62 lines
2 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_id) }
it { is_expected.to validate_presence_of(:followable_type) }
it { is_expected.to validate_presence_of(:follower_id) }
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