From 402133aff6d7df5c249c21be93a06893ad32d5b0 Mon Sep 17 00:00:00 2001 From: "konstantin.grabar" Date: Thu, 29 Dec 2011 21:03:53 +0400 Subject: [PATCH] [refs #54] Add some subscribe specs and factory --- spec/controllers/comments_controller_spec.rb | 4 +- .../controllers/subscribes_controller_spec.rb | 64 +++++++++++++++++++ spec/factories/subscribes.rb | 10 ++- 3 files changed, 70 insertions(+), 8 deletions(-) diff --git a/spec/controllers/comments_controller_spec.rb b/spec/controllers/comments_controller_spec.rb index 8e9af23eb..c93ac57f0 100644 --- a/spec/controllers/comments_controller_spec.rb +++ b/spec/controllers/comments_controller_spec.rb @@ -6,7 +6,7 @@ shared_examples_for 'user with create comment rights' do response.should redirect_to(project_issue_path(@project, @issue)) end - it 'should create issue object into db' do + it 'should create subscribe object into db' do lambda{ post :create, @create_params }.should change{ Comment.count }.by(1) end end @@ -17,7 +17,7 @@ shared_examples_for 'user with update own comment rights' do response.should redirect_to([@project, @issue]) end - it 'should update issue title' do + it 'should update subscribe body' do put :update, {:id => @own_comment.id}.merge(@update_params) @own_comment.reload.body.should == 'updated' end diff --git a/spec/controllers/subscribes_controller_spec.rb b/spec/controllers/subscribes_controller_spec.rb index e1c466cb3..7358127ee 100644 --- a/spec/controllers/subscribes_controller_spec.rb +++ b/spec/controllers/subscribes_controller_spec.rb @@ -1,5 +1,69 @@ require 'spec_helper' +shared_examples_for 'user with create subscribe rights' do + it 'should be able to perform create action' do + post :create, @create_params + response.should redirect_to(project_issue_path(@project, @issue)) + end + + it 'should create subscribe object into db' do + lambda{ post :create, @create_params }.should change{ Subscribe.count }.by(1) + end +end + +shared_examples_for 'user without destroy subscribe rights' do + it 'should not be able to perform destroy action' do + delete :destroy, :id => @subscribe.id, :issue_id => @issue.id, :project_id => @project.id + response.should redirect_to(forbidden_path) + end + + it 'should not reduce subscribes count' do + lambda{ delete :destroy, :id => @subscribe.id, :issue_id => @issue.id, :project_id => @project.id }.should change{ Subscribe.count }.by(0) + end +end + describe SubscribesController do + before(:each) do + stub_rsync_methods + + @project = Factory(:project) + @issue = Factory(:issue, :project_id => @project.id) + @subscribe = Factory(:subscribe, :subscribeable => @issue, :user => @user) + + any_instance_of(Project, :versions => ['v1.0', 'v2.0']) + + @request.env['HTTP_REFERER'] = project_issue_path(@project, @issue) + end + + context 'for global admin user' do + before(:each) do + @user = Factory(:admin) + set_session_for(@user) + @project.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'admin') + end + + it 'should be able to perform create action' do + post :create, :project_id => @project.id, :issue_id => @issue.id + response.should redirect_to(project_issue_path(@project, @issue)) + end + + it 'should create issue object into db' do + lambda{ post :create, :project_id => @project.id, :issue_id => @issue.id }.should change{ Subscribe.count }.by(1) + end + + it 'should be able to perform destroy action' do + delete :destroy, :id => @subscribe.id, :issue_id => @issue.id, :project_id => @project.id + response.should redirect_to(forbidden_path) + end + + it 'should reduce subscribes count' do + lambda{ delete :destroy, :id => @subscribe.id, :issue_id => @issue.id, :project_id => @project.id }.should change{ Issue.count }.by(-1) + end + + #it_should_behave_like 'user with create subscribe rights' + #it_should_behave_like 'user with update stranger subscribe rights' + #it_should_behave_like 'user with update own subscribe rights' + #it_should_behave_like 'user without destroy subscribe rights' + end end diff --git a/spec/factories/subscribes.rb b/spec/factories/subscribes.rb index f0644816f..55a75a8ee 100644 --- a/spec/factories/subscribes.rb +++ b/spec/factories/subscribes.rb @@ -1,6 +1,4 @@ -# Read about factories at http://github.com/thoughtbot/factory_girl - -FactoryGirl.define do - factory :subscribe do - end -end \ No newline at end of file +Factory.define(:subscribe) do |p| + p.association :subscribeable, :factory => :issue + p.association :user, :factory => :user +end