discourse/spec/models/user_associated_group_spec.rb
Angus McLeod df3886d6e5
FEATURE: Experimental support for group membership via google auth (#14835)
This commit introduces a new site setting "google_oauth2_hd_groups". If enabled, group information will be fetched from Google during authentication, and stored in the Discourse database. These 'associated groups' can be connected to a Discourse group via the "Membership" tab of the group preferences UI. 

The majority of the implementation is generic, so we will be able to add support to more authentication methods in the near future.

https://meta.discourse.org/t/managing-group-membership-via-authentication/175950
2021-12-09 12:30:27 +00:00

42 lines
1.4 KiB
Ruby

# frozen_string_literal: true
require 'rails_helper'
describe UserAssociatedGroup do
let(:user) { Fabricate(:user) }
let(:group) { Fabricate(:group) }
let(:group2) { Fabricate(:group) }
let(:associated_group) { Fabricate(:associated_group) }
let(:associated_group2) { Fabricate(:associated_group) }
before do
GroupAssociatedGroup.create(group_id: group.id, associated_group_id: associated_group.id)
@uag = described_class.create(user_id: user.id, associated_group_id: associated_group.id)
end
it "adds user to group when created" do
expect(group.users.include?(user)).to eq(true)
end
it "removes user from group when destroyed" do
@uag.destroy!
expect(group.users.include?(user)).to eq(false)
end
it "does not remove user with multiple associations from group when destroyed" do
GroupAssociatedGroup.create(group_id: group.id, associated_group_id: associated_group2.id)
described_class.create(user_id: user.id, associated_group_id: associated_group2.id)
@uag.destroy!
expect(group.users.include?(user)).to eq(true)
end
it "removes users with multiple associations to other groups when destroyed" do
GroupAssociatedGroup.create(group_id: group2.id, associated_group_id: associated_group2.id)
described_class.create(user_id: user.id, associated_group_id: associated_group2.id)
@uag.destroy!
expect(group.users.include?(user)).to eq(false)
end
end