BigW Consortium Gitlab

group_spec.rb 2.01 KB
Newer Older
1 2
# == Schema Information
#
Dmitriy Zaporozhets committed
3
# Table name: namespaces
4
#
Dmitriy Zaporozhets committed
5 6 7
#  id          :integer          not null, primary key
#  name        :string(255)      not null
#  path        :string(255)      not null
Dmitriy Zaporozhets committed
8
#  owner_id    :integer
Dmitriy Zaporozhets committed
9 10
#  created_at  :datetime
#  updated_at  :datetime
Dmitriy Zaporozhets committed
11 12
#  type        :string(255)
#  description :string(255)      default(""), not null
Dmitriy Zaporozhets committed
13
#  avatar      :string(255)
14 15 16 17 18
#

require 'spec_helper'

describe Group do
19 20
  let!(:group) { create(:group) }

21 22
  describe "Associations" do
    it { should have_many :projects }
23
    it { should have_many :group_members }
24 25
  end

26 27
  it { should validate_presence_of :name }
  it { should validate_uniqueness_of(:name) }
Dmitriy Zaporozhets committed
28 29
  it { should validate_presence_of :path }
  it { should validate_uniqueness_of(:path) }
30
  it { should_not validate_presence_of :owner }
31 32

  describe :users do
33
    it { group.users.should == group.owners }
34 35 36 37 38
  end

  describe :human_name do
    it { group.human_name.should == group.name }
  end
39 40 41

  describe :add_users do
    let(:user) { create(:user) }
42
    before { group.add_user(user, GroupMember::MASTER) }
43

44
    it { group.group_members.masters.map(&:user).should include(user) }
45
  end
46 47 48

  describe :add_users do
    let(:user) { create(:user) }
49
    before { group.add_users([user.id], GroupMember::GUEST) }
50 51

    it "should update the group permission" do
52 53 54 55
      group.group_members.guests.map(&:user).should include(user)
      group.add_users([user.id], GroupMember::DEVELOPER)
      group.group_members.developers.map(&:user).should include(user)
      group.group_members.guests.map(&:user).should_not include(user)
56 57
    end
  end
Steven Thonus committed
58 59 60

  describe :avatar_type do
    let(:user) { create(:user) }
61
    before { group.add_user(user, GroupMember::MASTER) }
Steven Thonus committed
62 63 64 65 66 67 68 69 70 71 72

    it "should be true if avatar is image" do
      group.update_attribute(:avatar, 'uploads/avatar.png')
      group.avatar_type.should be_true
    end

    it "should be false if avatar is html page" do
      group.update_attribute(:avatar, 'uploads/avatar.html')
      group.avatar_type.should == ["only images allowed"]
    end
  end
73
end