docbrown/spec/models/users/suspended_username_spec.rb
Anna Buianova 473594f192
Match spam role with existing suspended actions (#20477)
* Started matching spam and suspended roles

* Match spam and suspended roles in most cases

* Fixed check_suspended for unauthenticated users
2023-12-27 20:12:50 +00:00

40 lines
1.2 KiB
Ruby

require "rails_helper"
RSpec.describe Users::SuspendedUsername do
describe "validations" do
subject { create(:suspended_username) }
it { is_expected.to validate_presence_of(:username_hash) }
it { is_expected.to validate_uniqueness_of(:username_hash) }
end
describe ".previously_suspended?" do
it "returns true if the user has been previously suspended" do
user = create(:user, :suspended)
described_class.create_from_user(user)
expect(described_class.previously_suspended?(user.username)).to be true
end
it "returns true if the user has been previously assigned a spam roles" do
user = create(:user, :spam)
described_class.create_from_user(user)
expect(described_class.previously_suspended?(user.username)).to be true
end
it "returns false if the user has not been previously_suspended" do
user = create(:user)
expect(described_class.previously_suspended?(user.username)).to be false
end
end
describe ".create_from_user" do
it "records a hash of the username in the database" do
expect do
described_class.create_from_user(create(:user, :suspended))
end.to change(described_class, :count).by(1)
end
end
end