2012-01-30 20:39:34 +00:00
|
|
|
# -*- encoding : utf-8 -*-
|
2011-12-19 15:30:14 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2011-12-23 10:56:46 +00:00
|
|
|
shared_examples_for 'issue user with project reader rights' do
|
|
|
|
it 'should be able to perform index action' do
|
2012-04-23 21:55:42 +01:00
|
|
|
get :index, :owner_name => @project.owner.uname, :project_name => @project.name
|
2011-12-23 10:56:46 +00:00
|
|
|
response.should render_template(:index)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should be able to perform show action' do
|
2012-04-23 21:55:42 +01:00
|
|
|
get :show, :owner_name => @project.owner.uname, :project_name => @project.name, :id => @issue.serial_id
|
2011-12-23 10:56:46 +00:00
|
|
|
response.should render_template(:show)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
shared_examples_for 'issue user with project writer rights' do
|
|
|
|
it 'should be able to perform create action' do
|
|
|
|
post :create, @create_params
|
|
|
|
response.should redirect_to(project_issues_path(@project))
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should create issue object into db' do
|
|
|
|
lambda{ post :create, @create_params }.should change{ Issue.count }.by(1)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
shared_examples_for 'user with issue update rights' do
|
|
|
|
it 'should be able to perform update action' do
|
2011-12-28 02:57:42 +00:00
|
|
|
put :update, {:id => @issue.serial_id}.merge(@update_params)
|
2012-03-02 16:52:15 +00:00
|
|
|
response.code.should eq('200')
|
2011-12-23 10:56:46 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should update issue title' do
|
2011-12-28 02:57:42 +00:00
|
|
|
put :update, {:id => @issue.serial_id}.merge(@update_params)
|
2011-12-23 10:56:46 +00:00
|
|
|
@issue.reload.title.should == 'issue2'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
shared_examples_for 'user without issue update rights' do
|
|
|
|
it 'should not be able to perform update action' do
|
2011-12-28 02:57:42 +00:00
|
|
|
put :update, {:id => @issue.serial_id}.merge(@update_params)
|
2012-04-05 18:11:02 +01:00
|
|
|
response.should redirect_to(controller.current_user ? forbidden_path : new_user_session_path)
|
2011-12-23 10:56:46 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should not update issue title' do
|
2011-12-28 02:57:42 +00:00
|
|
|
put :update, {:id => @issue.serial_id}.merge(@update_params)
|
2011-12-23 10:56:46 +00:00
|
|
|
@issue.reload.title.should_not == 'issue2'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
shared_examples_for 'user without issue destroy rights' do
|
|
|
|
it 'should not be able to perform destroy action' do
|
2012-04-23 21:55:42 +01:00
|
|
|
delete :destroy, :id => @issue.serial_id, :owner_name => @project.owner.uname, :project_name => @project.name
|
2012-04-05 18:11:02 +01:00
|
|
|
response.should redirect_to(controller.current_user ? forbidden_path : new_user_session_path)
|
2011-12-23 10:56:46 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should not reduce issues count' do
|
2012-04-23 21:55:42 +01:00
|
|
|
lambda{ delete :destroy, :id => @issue.serial_id, :owner_name => @project.owner.uname, :project_name => @project.name }.should_not change{ Issue.count }
|
2011-12-23 10:56:46 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
shared_examples_for 'project with issues turned off' do
|
|
|
|
pending 'should not be able to perform index action' do
|
|
|
|
get :index, :project_id => @project_with_turned_off_issues.id
|
|
|
|
response.should render_template(:index)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should not be able to perform show action' do
|
2011-12-28 02:57:42 +00:00
|
|
|
get :show, :project_id => @project_with_turned_off_issues.id, :id => @turned_of_issue.serial_id
|
2011-12-23 10:56:46 +00:00
|
|
|
response.should redirect_to(forbidden_path)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-12-19 15:30:14 +00:00
|
|
|
describe IssuesController do
|
2011-12-23 10:56:46 +00:00
|
|
|
before(:each) do
|
|
|
|
stub_rsync_methods
|
|
|
|
|
2012-03-29 21:34:22 +01:00
|
|
|
@project = FactoryGirl.create(:project)
|
|
|
|
@issue_user = FactoryGirl.create(:user)
|
2011-12-23 10:56:46 +00:00
|
|
|
|
|
|
|
any_instance_of(Project, :versions => ['v1.0', 'v2.0'])
|
|
|
|
|
2012-04-13 20:44:04 +01:00
|
|
|
@issue = FactoryGirl.create(:issue, :project_id => @project.id, :assignee_id => @issue_user.id)
|
2011-12-23 10:56:46 +00:00
|
|
|
@create_params = {
|
2012-04-23 21:55:42 +01:00
|
|
|
:owner_name => @project.owner.uname, :project_name => @project.name,
|
2011-12-23 10:56:46 +00:00
|
|
|
:issue => {
|
|
|
|
:title => "issue1",
|
2012-04-23 21:55:42 +01:00
|
|
|
:body => "issue body"
|
2011-12-23 10:56:46 +00:00
|
|
|
},
|
2012-04-13 20:44:04 +01:00
|
|
|
:assignee_id => @issue_user.id,
|
|
|
|
:assignee_uname => @issue_user.uname
|
2011-12-23 10:56:46 +00:00
|
|
|
}
|
|
|
|
@update_params = {
|
2012-04-23 21:55:42 +01:00
|
|
|
:owner_name => @project.owner.uname, :project_name => @project.name,
|
2011-12-23 10:56:46 +00:00
|
|
|
:issue => {
|
|
|
|
:title => "issue2"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-29 21:34:22 +01:00
|
|
|
@project_with_turned_off_issues = FactoryGirl.create(:project, :has_issues => false)
|
2012-04-13 20:44:04 +01:00
|
|
|
@turned_of_issue = FactoryGirl.create(:issue, :project_id => @project_with_turned_off_issues.id, :assignee_id => @issue_user.id)
|
2011-12-23 10:56:46 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'for global admin user' do
|
|
|
|
before(:each) do
|
2012-03-29 21:34:22 +01:00
|
|
|
@admin = FactoryGirl.create(:admin)
|
2011-12-23 10:56:46 +00:00
|
|
|
set_session_for(@admin)
|
|
|
|
end
|
|
|
|
|
|
|
|
it_should_behave_like 'user without issue destroy rights'
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'for project admin user' do
|
|
|
|
before(:each) do
|
2012-03-29 21:34:22 +01:00
|
|
|
@user = FactoryGirl.create(:user)
|
2011-12-23 10:56:46 +00:00
|
|
|
set_session_for(@user)
|
2012-04-26 02:38:33 +01:00
|
|
|
@project.relations.create!(:actor_type => 'User', :actor_id => @user.id, :role => 'admin')
|
2011-12-23 10:56:46 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it_should_behave_like 'issue user with project reader rights'
|
|
|
|
it_should_behave_like 'issue user with project writer rights'
|
|
|
|
it_should_behave_like 'user with issue update rights'
|
|
|
|
it_should_behave_like 'user without issue destroy rights'
|
|
|
|
it_should_behave_like 'project with issues turned off'
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'for project owner user' do
|
|
|
|
before(:each) do
|
2012-03-29 21:34:22 +01:00
|
|
|
@user = FactoryGirl.create(:user)
|
2011-12-23 10:56:46 +00:00
|
|
|
set_session_for(@user)
|
2012-04-23 21:55:42 +01:00
|
|
|
@project.update_attribute(:owner, @user); @create_params[:owner_name] = @user.uname; @update_params[:owner_name] = @user.uname
|
2012-04-26 02:38:33 +01:00
|
|
|
@project.relations.create!(:actor_type => 'User', :actor_id => @user.id, :role => 'admin')
|
2011-12-23 10:56:46 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it_should_behave_like 'issue user with project reader rights'
|
|
|
|
it_should_behave_like 'issue user with project writer rights'
|
|
|
|
it_should_behave_like 'user with issue update rights'
|
|
|
|
it_should_behave_like 'user without issue destroy rights'
|
|
|
|
it_should_behave_like 'project with issues turned off'
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'for project reader user' do
|
|
|
|
before(:each) do
|
2012-03-29 21:34:22 +01:00
|
|
|
@user = FactoryGirl.create(:user)
|
2011-12-23 10:56:46 +00:00
|
|
|
set_session_for(@user)
|
2012-04-26 02:38:33 +01:00
|
|
|
@project.relations.create!(:actor_type => 'User', :actor_id => @user.id, :role => 'reader')
|
2011-12-23 10:56:46 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it_should_behave_like 'issue user with project reader rights'
|
|
|
|
it_should_behave_like 'user without issue update rights'
|
|
|
|
it_should_behave_like 'user without issue destroy rights'
|
|
|
|
it_should_behave_like 'project with issues turned off'
|
|
|
|
|
|
|
|
it 'should not be able to perform create action' do
|
|
|
|
post :create, @create_params
|
|
|
|
response.should redirect_to(forbidden_path)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should not create issue object into db' do
|
|
|
|
lambda{ post :create, @create_params }.should change{ Issue.count }.by(0)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'for project writer user' do
|
|
|
|
before(:each) do
|
2012-03-29 21:34:22 +01:00
|
|
|
@user = FactoryGirl.create(:user)
|
2011-12-23 10:56:46 +00:00
|
|
|
set_session_for(@user)
|
2012-04-26 02:38:33 +01:00
|
|
|
@project.relations.create!(:actor_type => 'User', :actor_id => @user.id, :role => 'writer')
|
2011-12-23 10:56:46 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it_should_behave_like 'issue user with project reader rights'
|
|
|
|
it_should_behave_like 'issue user with project writer rights'
|
|
|
|
it_should_behave_like 'user without issue update rights'
|
|
|
|
it_should_behave_like 'user without issue destroy rights'
|
|
|
|
it_should_behave_like 'project with issues turned off'
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'for issue assign user' do
|
|
|
|
before(:each) do
|
|
|
|
set_session_for(@issue_user)
|
|
|
|
end
|
2011-12-19 15:30:14 +00:00
|
|
|
|
2012-04-16 18:51:51 +01:00
|
|
|
it_should_behave_like 'user without issue update rights'
|
2011-12-23 10:56:46 +00:00
|
|
|
it_should_behave_like 'user without issue destroy rights'
|
|
|
|
it_should_behave_like 'project with issues turned off'
|
|
|
|
end
|
2012-04-05 18:11:02 +01:00
|
|
|
|
|
|
|
context 'for guest' do
|
|
|
|
if APP_CONFIG['anonymous_access']
|
|
|
|
it_should_behave_like 'issue user with project reader rights'
|
|
|
|
else
|
|
|
|
it 'should not be able to perform index action' do
|
2012-04-23 21:55:42 +01:00
|
|
|
get :index, :owner_name => @project.owner.uname, :project_name => @project.name
|
2012-04-05 18:11:02 +01:00
|
|
|
response.should redirect_to(new_user_session_path)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should not be able to perform show action' do
|
2012-04-23 21:55:42 +01:00
|
|
|
get :show, :owner_name => @project.owner.uname, :project_name => @project.name, :id => @issue.serial_id
|
2012-04-05 18:11:02 +01:00
|
|
|
response.should redirect_to(new_user_session_path)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should not be able to perform create action' do
|
|
|
|
post :create, @create_params
|
|
|
|
response.should redirect_to(new_user_session_path)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should not create issue object into db' do
|
|
|
|
lambda{ post :create, @create_params }.should_not change{ Issue.count }
|
|
|
|
end
|
|
|
|
|
|
|
|
it_should_behave_like 'user without issue update rights'
|
|
|
|
it_should_behave_like 'user without issue destroy rights'
|
|
|
|
end
|
2011-12-19 15:30:14 +00:00
|
|
|
end
|