2012-08-26 23:13:03 +02:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe UsersProjectObserver do
|
2012-11-06 04:31:55 +01:00
|
|
|
let(:user) { create(:user) }
|
2012-11-23 21:25:28 +01:00
|
|
|
let(:project) { create(:project) }
|
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
|
2013-01-02 19:25:25 +01:00
|
|
|
subject.should_receive(:after_commit)
|
2013-01-02 18:46:06 +01:00
|
|
|
create(:users_project)
|
2012-08-26 23:13:03 +02:00
|
|
|
end
|
2012-09-15 00:00:59 +02:00
|
|
|
|
2012-08-26 23:13:03 +02:00
|
|
|
it "should send email to user" do
|
2013-01-02 19:25:25 +01:00
|
|
|
Notify.should_receive(:project_access_granted_email).and_return(double(deliver: true))
|
2012-09-15 00:00:59 +02:00
|
|
|
Event.stub(:create => true)
|
2013-01-02 19:25:25 +01:00
|
|
|
|
|
|
|
create(:users_project)
|
2012-08-26 23:13:03 +02:00
|
|
|
end
|
2012-09-15 00:00:59 +02:00
|
|
|
|
2012-09-09 22:18:28 +02:00
|
|
|
it "should create new event" do
|
2013-01-02 19:25:25 +01:00
|
|
|
Event.should_receive(:create)
|
2012-09-15 00:00:59 +02:00
|
|
|
|
2013-01-02 19:25:25 +01:00
|
|
|
create(:users_project)
|
2012-09-09 22:18:28 +02:00
|
|
|
end
|
2012-08-26 23:13:03 +02:00
|
|
|
end
|
2012-08-26 23:32:03 +02:00
|
|
|
|
|
|
|
describe "#after_update" do
|
2013-01-02 19:25:25 +01:00
|
|
|
before do
|
|
|
|
@users_project = create :users_project
|
|
|
|
end
|
|
|
|
|
2012-08-26 23:32:03 +02:00
|
|
|
it "should called when UsersProject updated" do
|
2013-01-02 19:25:25 +01:00
|
|
|
subject.should_receive(:after_commit)
|
|
|
|
@users_project.update_attribute(:project_access, UsersProject::MASTER)
|
2012-08-26 23:32:03 +02:00
|
|
|
end
|
2012-09-15 00:00:59 +02:00
|
|
|
|
2012-08-26 23:32:03 +02:00
|
|
|
it "should send email to user" do
|
2013-01-02 19:25:25 +01:00
|
|
|
Notify.should_receive(:project_access_granted_email)
|
|
|
|
@users_project.update_attribute(:project_access, UsersProject::MASTER)
|
2012-08-26 23:32:03 +02:00
|
|
|
end
|
2013-01-02 19:25:25 +01:00
|
|
|
|
2012-09-03 20:46:17 +02:00
|
|
|
it "should not called after UsersProject destroyed" do
|
|
|
|
subject.should_not_receive(:after_commit)
|
2013-01-02 19:25:25 +01:00
|
|
|
@users_project.destroy
|
2012-09-03 20:46:17 +02:00
|
|
|
end
|
2012-08-26 23:32:03 +02:00
|
|
|
end
|
2012-09-15 00:00:59 +02:00
|
|
|
|
2012-09-09 23:27:47 +02:00
|
|
|
describe "#after_destroy" do
|
2013-01-02 19:25:25 +01:00
|
|
|
before do
|
|
|
|
@users_project = create :users_project
|
|
|
|
end
|
|
|
|
|
2012-09-09 23:27:47 +02:00
|
|
|
it "should called when UsersProject destroyed" do
|
|
|
|
subject.should_receive(:after_destroy)
|
2013-01-02 19:25:25 +01:00
|
|
|
@users_project.destroy
|
2012-09-09 23:27:47 +02:00
|
|
|
end
|
2012-09-15 00:00:59 +02:00
|
|
|
|
2012-09-09 23:27:47 +02:00
|
|
|
it "should create new event" do
|
2013-01-02 19:25:25 +01:00
|
|
|
Event.should_receive(:create)
|
|
|
|
@users_project.destroy
|
2012-09-09 23:27:47 +02:00
|
|
|
end
|
|
|
|
end
|
2012-08-26 23:13:03 +02:00
|
|
|
end
|