blob: cbe4224803371ffe451c918c1f1e5dfa4ff5db55 (
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
69
70
71
72
73
74
75
76
|
require 'spec_helper'
describe UsersProjectObserver do
let(:user) { create(:user) }
let(:project) { create(:project,
code: "Fuu",
path: "Fuu" ) }
let(:users_project) { create(:users_project,
project: project,
user: user )}
subject { UsersProjectObserver.instance }
describe "#after_commit" do
it "should called when UsersProject created" do
subject.should_receive(:after_commit).once
UsersProject.observers.enable :users_project_observer do
create(:users_project)
end
end
it "should send email to user" do
Notify.should_receive(:project_access_granted_email).with(users_project.id).and_return(double(deliver: true))
subject.after_commit(users_project)
Event.stub(:create => true)
end
it "should create new event" do
Event.should_receive(:create).with(
project_id: users_project.project.id,
action: Event::Joined,
author_id: users_project.user.id
)
subject.after_create(users_project)
end
end
describe "#after_update" do
it "should called when UsersProject updated" do
subject.should_receive(:after_commit).once
UsersProject.observers.enable :users_project_observer do
create(:users_project).update_attribute(:project_access, UsersProject::MASTER)
end
end
it "should send email to user" do
Notify.should_receive(:project_access_granted_email).with(users_project.id).and_return(double(deliver: true))
subject.after_commit(users_project)
end
it "should not called after UsersProject destroyed" do
subject.should_not_receive(:after_commit)
UsersProject.observers.enable :users_project_observer do
users_project.destroy
end
end
end
describe "#after_destroy" do
it "should called when UsersProject destroyed" do
subject.should_receive(:after_destroy)
UsersProject.observers.enable :users_project_observer do
create(:users_project).destroy
end
end
it "should create new event" do
Event.should_receive(:create).with(
project_id: users_project.project.id,
action: Event::Left,
author_id: users_project.user.id
)
subject.after_destroy(users_project)
end
end
end
|