BigW Consortium Gitlab

users_project_observer_spec.rb 2.25 KB
Newer Older
1 2 3
require 'spec_helper'

describe UsersProjectObserver do
4
  before(:each) { enable_observers }
5
  after(:each) { disable_observers }
6

7
  let(:user) { create(:user) }
8
  let(:project) { create(:project) }
9
  subject { UsersProjectObserver.instance }
10
  before { subject.stub(notification: double('NotificationService').as_null_object) }
11

12
  describe "#after_update" do
13 14 15 16
    before do
      @users_project = create :users_project
    end

17
    it "should called when UsersProject updated" do
18
      subject.should_receive(:after_update)
19
      @users_project.update_attribute(:project_access, UsersProject::MASTER)
20
    end
randx committed
21

22
    it "should send email to user" do
23
      subject.should_receive(:notification)
24
      @users_project.update_attribute(:project_access, UsersProject::MASTER)
25
    end
26

27
    it "should not called after UsersProject destroyed" do
28
      subject.should_not_receive(:after_update)
29
      @users_project.destroy
30
    end
31
  end
randx committed
32

33
  describe "#after_destroy" do
34 35 36 37
    before do
      @users_project = create :users_project
    end

38 39
    it "should called when UsersProject destroyed" do
      subject.should_receive(:after_destroy)
40
      @users_project.destroy
41
    end
randx committed
42

43
    it "should create new event" do
44 45
      Event.should_receive(:create)
      @users_project.destroy
46 47
    end
  end
48 49 50 51 52

  describe "#after_create" do
    context 'wiki_enabled creates repository directory' do
      context 'wiki_enabled true creates wiki repository directory' do
        before do
Izaak Alpert committed
53
          @project = create(:project, wiki_enabled: true)
54 55
          @path = GollumWiki.new(@project, user).send(:path_to_repo)
        end
Izaak Alpert committed
56

57 58 59
        after do
          FileUtils.rm_rf(@path)
        end
Izaak Alpert committed
60

61 62 63 64 65
        it { File.exists?(@path).should be_true }
      end

      context 'wiki_enabled false does not create wiki repository directory' do
        before do
Izaak Alpert committed
66
          @project = create(:project, wiki_enabled: false)
67 68
          @path = GollumWiki.new(@project, user).send(:path_to_repo)
        end
Izaak Alpert committed
69

70 71 72
        it { File.exists?(@path).should be_false }
      end
    end
Dmitriy Zaporozhets committed
73 74 75 76 77 78 79 80 81 82 83 84 85

    it "should send email to user" do
      subject.should_receive(:notification)
      Event.stub(create: true)

      create(:users_project)
    end

    it "should create new event" do
      Event.should_receive(:create)

      create(:users_project)
    end
86
  end
87
end