This instance will be upgraded to Heptapod 0.31.0rc on 2022-05-19 at 11:00 UTC+2 (a few minutes of down time)

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

require 'spec_helper'

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

Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
21
22
  describe "Associations" do
    it { should have_many :projects }
23
    it { should have_many :group_members }
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
24
25
  end

26
27
  it { should validate_presence_of :name }
  it { should validate_uniqueness_of(:name) }
Dmitriy Zaporozhets's avatar
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 }
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
31
32

  describe :users do
33
    it { group.users.should == group.owners }
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
34
35
36
37
38
  end

  describe :human_name do
    it { group.human_name.should == group.name }
  end
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
39
40
41

  describe :add_users do
    let(:user) { create(:user) }
42
    before { group.add_user(user, GroupMember::MASTER) }
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
43

44
    it { group.group_members.masters.map(&:user).should include(user) }
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
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's avatar
Steven Thonus committed
58
59
60

  describe :avatar_type do
    let(:user) { create(:user) }
61
    before { group.add_user(user, GroupMember::MASTER) }
Steven Thonus's avatar
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