2012-08-26 23:13:03 +02:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe UsersProjectObserver do
|
2012-09-15 00:00:59 +02:00
|
|
|
let(:users_project) { stub.as_null_object }
|
2012-08-26 23:13:03 +02:00
|
|
|
subject { UsersProjectObserver.instance }
|
|
|
|
|
|
|
|
describe "#after_create" do
|
|
|
|
it "should called when UsersProject created" do
|
|
|
|
subject.should_receive(:after_create)
|
2012-09-15 00:00:59 +02:00
|
|
|
|
2012-08-26 23:13:03 +02:00
|
|
|
UsersProject.observers.enable :users_project_observer do
|
2012-09-15 00:00:59 +02:00
|
|
|
create(:users_project)
|
2012-08-26 23:13:03 +02:00
|
|
|
end
|
|
|
|
end
|
2012-09-15 00:00:59 +02:00
|
|
|
|
2012-08-26 23:13:03 +02:00
|
|
|
it "should send email to user" do
|
2012-09-15 00:00:59 +02:00
|
|
|
Event.stub(:create => true)
|
|
|
|
Notify.should_receive(:project_access_granted_email).and_return(stub(deliver: true))
|
|
|
|
|
2012-08-26 23:13:03 +02:00
|
|
|
subject.after_create(users_project)
|
|
|
|
end
|
2012-09-15 00:00:59 +02:00
|
|
|
|
2012-09-09 22:18:28 +02:00
|
|
|
it "should create new event" do
|
|
|
|
Event.should_receive(:create).with(
|
2012-09-15 00:00:59 +02:00
|
|
|
project_id: users_project.project.id,
|
|
|
|
action: Event::Joined,
|
2012-09-09 22:18:28 +02:00
|
|
|
author_id: users_project.user.id
|
|
|
|
)
|
2012-09-15 00:00:59 +02:00
|
|
|
|
2012-09-09 22:18:28 +02:00
|
|
|
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
|
|
|
|
subject.should_receive(:after_update)
|
2012-09-15 00:00:59 +02:00
|
|
|
|
2012-08-26 23:32:03 +02:00
|
|
|
UsersProject.observers.enable :users_project_observer do
|
2012-09-15 00:00:59 +02:00
|
|
|
create(:users_project).update_attribute(:project_access, 40)
|
2012-08-26 23:32:03 +02:00
|
|
|
end
|
|
|
|
end
|
2012-09-15 00:00:59 +02:00
|
|
|
|
2012-08-26 23:32:03 +02:00
|
|
|
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-15 00:00:59 +02:00
|
|
|
|
2012-08-26 23:32:03 +02:00
|
|
|
subject.after_update(users_project)
|
|
|
|
end
|
|
|
|
end
|
2012-09-15 00:00:59 +02:00
|
|
|
|
2012-09-09 23:27:47 +02:00
|
|
|
describe "#after_destroy" do
|
|
|
|
it "should called when UsersProject destroyed" do
|
|
|
|
subject.should_receive(:after_destroy)
|
2012-09-15 00:00:59 +02:00
|
|
|
|
2012-09-09 23:27:47 +02:00
|
|
|
UsersProject.observers.enable :users_project_observer do
|
2012-09-15 00:00:59 +02:00
|
|
|
create(:users_project).destroy
|
2012-09-09 23:27:47 +02:00
|
|
|
end
|
|
|
|
end
|
2012-09-15 00:00:59 +02:00
|
|
|
|
2012-09-09 23:27:47 +02:00
|
|
|
it "should create new event" do
|
|
|
|
Event.should_receive(:create).with(
|
2012-09-15 00:00:59 +02:00
|
|
|
project_id: users_project.project.id,
|
|
|
|
action: Event::Left,
|
2012-09-09 23:27:47 +02:00
|
|
|
author_id: users_project.user.id
|
|
|
|
)
|
|
|
|
subject.after_destroy(users_project)
|
|
|
|
end
|
|
|
|
end
|
2012-08-26 23:13:03 +02:00
|
|
|
end
|