2012-08-26 23:13:03 +02:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe UsersProjectObserver do
|
|
|
|
let(:user) { Factory.create :user }
|
|
|
|
let(:project) { Factory.create(:project,
|
|
|
|
code: "Fuu",
|
|
|
|
path: "Fuu" ) }
|
|
|
|
let(:users_project) { Factory.create(:users_project,
|
2012-08-26 23:32:03 +02:00
|
|
|
project: project,
|
|
|
|
user: user )}
|
2012-08-26 23:13:03 +02:00
|
|
|
subject { UsersProjectObserver.instance }
|
|
|
|
|
2012-09-03 20:46:17 +02:00
|
|
|
describe "#after_commit" do
|
2012-08-26 23:13:03 +02:00
|
|
|
it "should called when UsersProject created" do
|
2012-09-03 20:46:17 +02:00
|
|
|
subject.should_receive(:after_commit).once
|
2012-08-26 23:13:03 +02:00
|
|
|
UsersProject.observers.enable :users_project_observer do
|
|
|
|
Factory.create(:users_project,
|
|
|
|
project: project,
|
|
|
|
user: user)
|
|
|
|
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))
|
2012-09-03 19:48:38 +02:00
|
|
|
subject.after_commit(users_project)
|
2012-08-26 23:13:03 +02:00
|
|
|
end
|
2012-09-09 22:18:28 +02:00
|
|
|
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
|
2012-08-26 23:13:03 +02:00
|
|
|
end
|
2012-08-26 23:32:03 +02:00
|
|
|
|
|
|
|
describe "#after_update" do
|
|
|
|
it "should called when UsersProject updated" do
|
2012-09-03 20:46:17 +02:00
|
|
|
subject.should_receive(:after_commit).once
|
2012-08-26 23:32:03 +02:00
|
|
|
UsersProject.observers.enable :users_project_observer do
|
|
|
|
users_project.update_attribute(:project_access, 40)
|
|
|
|
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))
|
2012-09-03 19:48:38 +02:00
|
|
|
subject.after_commit(users_project)
|
2012-08-26 23:32:03 +02:00
|
|
|
end
|
2012-09-03 20:46:17 +02:00
|
|
|
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
|
2012-08-26 23:32:03 +02:00
|
|
|
end
|
2012-09-09 23:27:47 +02:00
|
|
|
describe "#after_destroy" do
|
|
|
|
it "should called when UsersProject destroyed" do
|
|
|
|
subject.should_receive(:after_destroy)
|
|
|
|
UsersProject.observers.enable :users_project_observer do
|
|
|
|
UsersProject.bulk_delete(
|
|
|
|
users_project.project,
|
|
|
|
[users_project.user.id]
|
|
|
|
)
|
|
|
|
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
|
2012-08-26 23:13:03 +02:00
|
|
|
end
|