BigW Consortium Gitlab

project_group_link_spec.rb 1.09 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13
require 'spec_helper'

describe ProjectGroupLink do
  describe "Associations" do
    it { should belong_to(:group) }
    it { should belong_to(:project) }
  end

  describe "Validation" do
    let!(:project_group_link) { create(:project_group_link) }

    it { should validate_presence_of(:project_id) }
    it { should validate_uniqueness_of(:group_id).scoped_to(:project_id).with_message(/already shared/) }
14
    it { should validate_presence_of(:group) }
15 16
    it { should validate_presence_of(:group_access) }
  end
17 18 19

  describe "destroying a record", truncate: true do
    it "refreshes group users' authorized projects" do
20
      project     = create(:empty_project, :private)
21 22 23 24 25 26 27 28 29 30 31 32
      group       = create(:group)
      reporter    = create(:user)
      group_users = group.users

      group.add_reporter(reporter)
      project.project_group_links.create(group: group)
      group_users.each { |user| expect(user.authorized_projects).to include(project) }

      project.project_group_links.destroy_all
      group_users.each { |user| expect(user.authorized_projects).not_to include(project) }
    end
  end
33
end