2019-04-29 19:27:42 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2019-04-03 15:41:04 -05:00
|
|
|
require 'rails_helper'
|
|
|
|
require_dependency 'jobs/regular/create_user_reviewable'
|
|
|
|
|
|
|
|
describe Jobs::CreateUserReviewable do
|
|
|
|
|
|
|
|
let(:user) { Fabricate(:user) }
|
|
|
|
|
|
|
|
it "creates the reviewable" do
|
2019-04-11 10:11:35 -05:00
|
|
|
SiteSetting.must_approve_users = true
|
2019-04-03 15:41:04 -05:00
|
|
|
described_class.new.execute(user_id: user.id)
|
|
|
|
|
|
|
|
reviewable = Reviewable.find_by(target: user)
|
|
|
|
expect(reviewable).to be_present
|
|
|
|
expect(reviewable.pending?).to eq(true)
|
|
|
|
expect(reviewable.payload['username']).to eq(user.username)
|
|
|
|
expect(reviewable.payload['name']).to eq(user.name)
|
|
|
|
expect(reviewable.payload['email']).to eq(user.email)
|
|
|
|
end
|
2019-04-11 10:11:35 -05:00
|
|
|
|
2019-04-11 11:30:54 -05:00
|
|
|
it "should not raise an error if there is a reviewable already" do
|
|
|
|
SiteSetting.must_approve_users = true
|
|
|
|
described_class.new.execute(user_id: user.id)
|
|
|
|
described_class.new.execute(user_id: user.id)
|
2019-04-23 14:46:18 -05:00
|
|
|
|
|
|
|
reviewable = Reviewable.find_by(target: user)
|
|
|
|
expect(reviewable.reviewable_scores.size).to eq(1)
|
2019-04-11 11:30:54 -05:00
|
|
|
end
|
|
|
|
|
2019-04-11 10:11:35 -05:00
|
|
|
describe "reasons" do
|
|
|
|
it "does nothing if there's no reason" do
|
|
|
|
described_class.new.execute(user_id: user.id)
|
|
|
|
expect(Reviewable.find_by(target: user)).to be_blank
|
|
|
|
end
|
|
|
|
|
|
|
|
it "adds must_approve_users if enabled" do
|
|
|
|
SiteSetting.must_approve_users = true
|
|
|
|
described_class.new.execute(user_id: user.id)
|
|
|
|
reviewable = Reviewable.find_by(target: user)
|
|
|
|
score = reviewable.reviewable_scores.first
|
|
|
|
expect(score).to be_present
|
|
|
|
expect(score.reason).to eq('must_approve_users')
|
|
|
|
end
|
|
|
|
|
|
|
|
it "adds invite_only if enabled" do
|
|
|
|
SiteSetting.invite_only = true
|
|
|
|
described_class.new.execute(user_id: user.id)
|
|
|
|
reviewable = Reviewable.find_by(target: user)
|
|
|
|
score = reviewable.reviewable_scores.first
|
|
|
|
expect(score).to be_present
|
|
|
|
expect(score.reason).to eq('invite_only')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-04-03 15:41:04 -05:00
|
|
|
end
|