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

describe UsersProjectObserver do
4
  let(:user) { create(:user) }
5
  let(:project) { create(:project) }
6
  subject { UsersProjectObserver.instance }
7
  before { subject.stub(notification: mock('NotificationService').as_null_object) }
8

Alex Denisov's avatar
Alex Denisov committed
9
  describe "#after_commit" do
10
    it "should called when UsersProject created" do
11
      subject.should_receive(:after_commit)
12
      create(:users_project)
13
    end
randx's avatar
randx committed
14

15
    it "should send email to user" do
16
      subject.should_receive(:notification)
randx's avatar
randx committed
17
      Event.stub(:create => true)
18 19

      create(:users_project)
20
    end
randx's avatar
randx committed
21

22
    it "should create new event" do
23
      Event.should_receive(:create)
randx's avatar
randx committed
24

25
      create(:users_project)
26
    end
27
  end
28 29

  describe "#after_update" do
30 31 32 33
    before do
      @users_project = create :users_project
    end

34
    it "should called when UsersProject updated" do
35 36
      subject.should_receive(:after_commit)
      @users_project.update_attribute(:project_access, UsersProject::MASTER)
37
    end
randx's avatar
randx committed
38

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

Alex Denisov's avatar
Alex Denisov committed
44 45
    it "should not called after UsersProject destroyed" do
      subject.should_not_receive(:after_commit)
46
      @users_project.destroy
Alex Denisov's avatar
Alex Denisov committed
47
    end
48
  end
randx's avatar
randx committed
49

Alex Denisov's avatar
Alex Denisov committed
50
  describe "#after_destroy" do
51 52 53 54
    before do
      @users_project = create :users_project
    end

Alex Denisov's avatar
Alex Denisov committed
55 56
    it "should called when UsersProject destroyed" do
      subject.should_receive(:after_destroy)
57
      @users_project.destroy
Alex Denisov's avatar
Alex Denisov committed
58
    end
randx's avatar
randx committed
59

Alex Denisov's avatar
Alex Denisov committed
60
    it "should create new event" do
61 62
      Event.should_receive(:create)
      @users_project.destroy
Alex Denisov's avatar
Alex Denisov committed
63 64
    end
  end
65
end