discourse/spec/jobs/automatic_group_membership_spec.rb
Régis Hanol d6c63cc5b2 FIX: user's default group should only be set once
Setting a user's default groups based on their email address should only be done once, ie. when they confirm their email address.
Previously we were doing this everytime we'd save a user record 🤷
2017-06-14 19:20:18 +02:00

29 lines
1.0 KiB
Ruby

require 'rails_helper'
require_dependency 'jobs/regular/automatic_group_membership'
describe Jobs::AutomaticGroupMembership do
it "raises an error when the group id is missing" do
expect { Jobs::AutomaticGroupMembership.new.execute({}) }.to raise_error(Discourse::InvalidParameters)
end
it "updates the membership" do
user1 = Fabricate(:user, email: "no@bar.com")
user2 = Fabricate(:user, email: "no@wat.com")
user3 = Fabricate(:user, email: "noo@wat.com", staged: true)
user4 = Fabricate(:user, email: "yes@wat.com")
EmailToken.confirm(user4.email_tokens.last.token)
group = Fabricate(:group, automatic_membership_email_domains: "wat.com", automatic_membership_retroactive: true)
Jobs::AutomaticGroupMembership.new.execute(group_id: group.id)
group.reload
expect(group.users.include?(user1)).to eq(false)
expect(group.users.include?(user2)).to eq(false)
expect(group.users.include?(user3)).to eq(false)
expect(group.users.include?(user4)).to eq(true)
end
end