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