2012-08-26 17:13:03 -04: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 17:32:03 -04:00
|
|
|
project: project,
|
|
|
|
user: user )}
|
2012-08-26 17:13:03 -04:00
|
|
|
subject { UsersProjectObserver.instance }
|
|
|
|
|
|
|
|
describe "#after_create" do
|
|
|
|
it "should called when UsersProject created" do
|
|
|
|
subject.should_receive(:after_create)
|
|
|
|
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))
|
|
|
|
subject.after_create(users_project)
|
|
|
|
end
|
|
|
|
end
|
2012-08-26 17:32:03 -04:00
|
|
|
|
|
|
|
describe "#after_update" do
|
|
|
|
it "should called when UsersProject updated" do
|
|
|
|
subject.should_receive(:after_update)
|
|
|
|
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))
|
|
|
|
subject.after_update(users_project)
|
|
|
|
end
|
|
|
|
end
|
2012-08-26 17:13:03 -04:00
|
|
|
end
|