summaryrefslogtreecommitdiff
path: root/spec/observers/users_project_observer_spec.rb
blob: e33d8cc50fd6175ddb6d3908a3b9c224fcaa046b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
require 'spec_helper'

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

  let(:user) { create(:user) }
  let(:project) { create(:project) }
  subject { UsersProjectObserver.instance }
  before { subject.stub(notification: mock('NotificationService').as_null_object) }

  describe "#after_commit" do
    it "should called when UsersProject created" do
      subject.should_receive(:after_commit)
      create(:users_project)
    end

    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
  end

  describe "#after_update" do
    before do
      @users_project = create :users_project
    end

    it "should called when UsersProject updated" do
      subject.should_receive(:after_commit)
      @users_project.update_attribute(:project_access, UsersProject::MASTER)
    end

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

    it "should not called after UsersProject destroyed" do
      subject.should_not_receive(:after_commit)
      @users_project.destroy
    end
  end

  describe "#after_destroy" do
    before do
      @users_project = create :users_project
    end

    it "should called when UsersProject destroyed" do
      subject.should_receive(:after_destroy)
      @users_project.destroy
    end

    it "should create new event" do
      Event.should_receive(:create)
      @users_project.destroy
    end
  end
end