diff options
author | randx <dmitriy.zaporozhets@gmail.com> | 2012-09-15 02:00:59 +0400 |
---|---|---|
committer | randx <dmitriy.zaporozhets@gmail.com> | 2012-09-15 02:00:59 +0400 |
commit | a82977c64843aa177498f1a715121ae6e38bc323 (patch) | |
tree | ddccf4c68c46935d4dffa82fdb5c663bd5c65ac1 /spec/observers | |
parent | 0d66cf2a38540056b6400c526e62ccc0cbc3144d (diff) |
A bit of test refactoring
Diffstat (limited to 'spec/observers')
-rw-r--r-- | spec/observers/users_project_observer_spec.rb | 41 |
1 files changed, 21 insertions, 20 deletions
diff --git a/spec/observers/users_project_observer_spec.rb b/spec/observers/users_project_observer_spec.rb index f38d98620a3..07d71da8c71 100644 --- a/spec/observers/users_project_observer_spec.rb +++ b/spec/observers/users_project_observer_spec.rb @@ -1,34 +1,32 @@ 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, - project: project, - user: user )} + let(:users_project) { stub.as_null_object } 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) + create(:users_project) 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)) + Event.stub(:create => true) + Notify.should_receive(:project_access_granted_email).and_return(stub(deliver: true)) + subject.after_create(users_project) end + it "should create new event" do Event.should_receive(:create).with( - project_id: users_project.project.id, - action: Event::Joined, + project_id: users_project.project.id, + action: Event::Joined, author_id: users_project.user.id ) + subject.after_create(users_project) end end @@ -36,29 +34,32 @@ describe UsersProjectObserver do 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) + create(: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 + 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] - ) + create(:users_project).destroy end end + it "should create new event" do Event.should_receive(:create).with( - project_id: users_project.project.id, - action: Event::Left, + project_id: users_project.project.id, + action: Event::Left, author_id: users_project.user.id ) subject.after_destroy(users_project) |