2011-12-19 15:30:14 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2012-08-15 14:52:32 +01:00
|
|
|
shared_context "issues controller" do
|
2013-04-03 12:11:50 +01:00
|
|
|
before do
|
2012-08-15 14:52:32 +01:00
|
|
|
stub_symlink_methods
|
|
|
|
|
2013-07-22 16:19:25 +01:00
|
|
|
@project = FactoryGirl.create(:project_with_commit)
|
2012-08-15 14:52:32 +01:00
|
|
|
@issue_user = FactoryGirl.create(:user)
|
|
|
|
|
2014-01-21 04:51:49 +00:00
|
|
|
@issue = FactoryGirl.create(:issue, project_id: @project.id, assignee_id: @issue_user.id)
|
|
|
|
@label = FactoryGirl.create(:label, project_id: @project.id)
|
|
|
|
|
|
|
|
@project_with_turned_off_issues = FactoryGirl.create(:project, has_issues: false)
|
|
|
|
@turned_of_issue = FactoryGirl.create(:issue, project_id: @project_with_turned_off_issues.id, assignee_id: @issue_user.id)
|
2012-08-15 14:52:32 +01:00
|
|
|
|
2012-09-06 18:45:13 +01:00
|
|
|
@user = FactoryGirl.create(:user)
|
|
|
|
set_session_for(@user)
|
2012-08-15 14:52:32 +01:00
|
|
|
|
|
|
|
@create_params = {
|
2014-03-19 07:19:03 +00:00
|
|
|
name_with_owner: @project.name_with_owner,
|
2014-01-21 04:51:49 +00:00
|
|
|
issue: {
|
|
|
|
title: "issue1",
|
|
|
|
body: "issue body",
|
2015-04-29 00:26:03 +01:00
|
|
|
labelings_attributes: { @label.id.to_s => { label_id: @label.id }},
|
2014-01-21 04:51:49 +00:00
|
|
|
assignee_id: @issue_user.id
|
2013-04-03 12:11:50 +01:00
|
|
|
}
|
2012-08-15 14:52:32 +01:00
|
|
|
}
|
2012-09-06 18:45:13 +01:00
|
|
|
|
2015-02-02 18:21:43 +00:00
|
|
|
@update_params = { name_with_owner: @project.name_with_owner, issue: { title: "issue2" }, format: :json }
|
2012-09-06 18:45:13 +01:00
|
|
|
|
2015-04-23 06:14:22 +01:00
|
|
|
@pull = create_pull_request(@project)
|
2012-08-15 14:52:32 +01:00
|
|
|
end
|
2012-09-06 18:45:13 +01:00
|
|
|
|
2012-08-15 14:52:32 +01:00
|
|
|
end
|
|
|
|
|
2012-09-06 18:45:13 +01:00
|
|
|
shared_examples_for 'issue user with project guest rights' do
|
2011-12-23 10:56:46 +00:00
|
|
|
it 'should be able to perform index action' do
|
2014-03-19 07:19:03 +00:00
|
|
|
get :index, name_with_owner: @project.name_with_owner
|
2015-03-05 23:45:37 +00:00
|
|
|
expect(response).to render_template(:index)
|
2011-12-23 10:56:46 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should be able to perform show action' do
|
2014-03-19 07:19:03 +00:00
|
|
|
get :show, name_with_owner: @project.name_with_owner, id: @issue.serial_id
|
2015-03-05 23:45:37 +00:00
|
|
|
expect(response).to render_template(:show)
|
2011-12-23 10:56:46 +00:00
|
|
|
end
|
2012-09-06 18:45:13 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
shared_examples_for 'issue user with project reader rights' do
|
2012-05-30 17:03:07 +01:00
|
|
|
|
|
|
|
it 'should be able to perform index action on hidden project' do
|
2014-01-21 04:51:49 +00:00
|
|
|
@project.update_attributes(visibility: 'hidden')
|
2014-03-19 07:19:03 +00:00
|
|
|
get :index, name_with_owner: @project.name_with_owner
|
2015-03-05 23:45:37 +00:00
|
|
|
expect(response).to render_template(:index)
|
2012-05-30 17:03:07 +01:00
|
|
|
end
|
2011-12-23 10:56:46 +00:00
|
|
|
|
|
|
|
it 'should be able to perform create action' do
|
|
|
|
post :create, @create_params
|
2015-03-05 23:45:37 +00:00
|
|
|
expect(response).to redirect_to(project_issues_path(@project))
|
2011-12-23 10:56:46 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should create issue object into db' do
|
2015-03-05 23:45:37 +00:00
|
|
|
expect do
|
|
|
|
post :create, @create_params
|
|
|
|
end.to change(Issue, :count).by(1)
|
2011-12-23 10:56:46 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-04-03 12:11:50 +01:00
|
|
|
shared_examples_for 'issue user with project writer rights' do
|
|
|
|
it 'should be able to perform index action on hidden project' do
|
2014-01-21 04:51:49 +00:00
|
|
|
@project.update_attributes(visibility: 'hidden')
|
2014-03-19 07:19:03 +00:00
|
|
|
get :index, name_with_owner: @project.name_with_owner
|
2015-03-05 23:45:37 +00:00
|
|
|
expect(response).to render_template(:index)
|
2013-04-03 12:11:50 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should create issue object into db' do
|
2015-03-05 23:45:37 +00:00
|
|
|
expect do
|
|
|
|
post :create, @create_params
|
|
|
|
end.to change(Issue, :count).by(1)
|
2013-04-03 12:11:50 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'perform create action' do
|
|
|
|
before { post :create, @create_params }
|
|
|
|
|
|
|
|
it 'user should be assigned to issue' do
|
2015-03-05 23:45:37 +00:00
|
|
|
expect(@project.issues.last.assignee_id).to_not be_nil
|
2013-04-03 12:11:50 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'label should be attached to issue' do
|
2015-02-19 01:12:08 +00:00
|
|
|
expect(@project.issues.last.labels.count).to eq 1
|
2013-04-03 12:11:50 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-12-23 10:56:46 +00:00
|
|
|
shared_examples_for 'user with issue update rights' do
|
|
|
|
it 'should be able to perform update action' do
|
2014-01-21 04:51:49 +00:00
|
|
|
put :update, {id: @issue.serial_id}.merge(@update_params)
|
2015-03-05 23:45:37 +00:00
|
|
|
expect(response).to be_success
|
2011-12-23 10:56:46 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should update issue title' do
|
2014-01-21 04:51:49 +00:00
|
|
|
put :update, {id: @issue.serial_id}.merge(@update_params)
|
2015-03-05 23:45:37 +00:00
|
|
|
expect(@issue.reload.title).to eq 'issue2'
|
2011-12-23 10:56:46 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
shared_examples_for 'user without issue update rights' do
|
|
|
|
it 'should not be able to perform update action' do
|
2014-01-21 04:51:49 +00:00
|
|
|
put :update, {id: @issue.serial_id}.merge(@update_params)
|
2015-03-05 23:45:37 +00:00
|
|
|
expect(response).to redirect_to(forbidden_path)
|
2011-12-23 10:56:46 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should not update issue title' do
|
2014-01-21 04:51:49 +00:00
|
|
|
put :update, {id: @issue.serial_id}.merge(@update_params)
|
2015-03-05 23:45:37 +00:00
|
|
|
expect(@issue.reload.title).to_not eq 'issue2'
|
2011-12-23 10:56:46 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-03-20 23:11:12 +00:00
|
|
|
# shared_examples_for 'user without issue destroy rights' do
|
|
|
|
# it 'should not be able to perform destroy action' do
|
|
|
|
# delete :destroy, id: @issue.serial_id, name_with_owner: @project.name_with_owner
|
2015-03-05 23:45:37 +00:00
|
|
|
# expect(response).to redirect_to(controller.current_user ? forbidden_path : new_user_session_path)
|
2014-03-20 23:11:12 +00:00
|
|
|
# end
|
2011-12-23 10:56:46 +00:00
|
|
|
|
2014-03-20 23:11:12 +00:00
|
|
|
# it 'should not reduce issues count' do
|
2015-03-05 23:45:37 +00:00
|
|
|
# expect
|
|
|
|
# delete :destroy, id: @issue.serial_id, name_with_owner: @project.name_with_owner
|
|
|
|
# end.to change(Issue, :count).by(0)
|
2014-03-20 23:11:12 +00:00
|
|
|
# end
|
|
|
|
# end
|
2011-12-23 10:56:46 +00:00
|
|
|
|
|
|
|
shared_examples_for 'project with issues turned off' do
|
2012-09-06 18:45:13 +01:00
|
|
|
it 'should not be able to perform index action' do
|
2014-03-19 07:19:03 +00:00
|
|
|
get :index, name_with_owner: @project_with_turned_off_issues.name_with_owner
|
2015-03-05 23:45:37 +00:00
|
|
|
expect(response).to redirect_to(forbidden_path)
|
2011-12-23 10:56:46 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should not be able to perform show action' do
|
2014-03-19 07:19:03 +00:00
|
|
|
get :show, name_with_owner: @project_with_turned_off_issues.name_with_owner, id: @turned_of_issue.serial_id
|
2015-03-05 23:45:37 +00:00
|
|
|
expect(response).to redirect_to(forbidden_path)
|
2011-12-23 10:56:46 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-02-19 01:12:08 +00:00
|
|
|
describe Projects::IssuesController, type: :controller do
|
2012-08-15 14:52:32 +01:00
|
|
|
include_context "issues controller"
|
2011-12-23 10:56:46 +00:00
|
|
|
|
|
|
|
context 'for global admin user' do
|
2015-03-05 23:45:37 +00:00
|
|
|
before do
|
2012-09-06 18:45:13 +01:00
|
|
|
@user.role = "admin"
|
|
|
|
@user.save
|
2011-12-23 10:56:46 +00:00
|
|
|
end
|
|
|
|
|
2012-09-06 18:45:13 +01:00
|
|
|
it_should_behave_like 'issue user with project guest rights'
|
|
|
|
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 'project with issues turned off'
|
2014-03-20 23:11:12 +00:00
|
|
|
# it_should_behave_like 'user without issue destroy rights'
|
2011-12-23 10:56:46 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'for project admin user' do
|
2015-03-05 23:45:37 +00:00
|
|
|
before do
|
2014-03-18 09:31:01 +00:00
|
|
|
create_relation(@project, @user, 'admin')
|
2011-12-23 10:56:46 +00:00
|
|
|
end
|
|
|
|
|
2012-09-06 18:45:13 +01:00
|
|
|
it_should_behave_like 'issue user with project guest rights'
|
2011-12-23 10:56:46 +00:00
|
|
|
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 'project with issues turned off'
|
2014-03-20 23:11:12 +00:00
|
|
|
# it_should_behave_like 'user without issue destroy rights'
|
2011-12-23 10:56:46 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'for project owner user' do
|
2015-03-05 23:45:37 +00:00
|
|
|
before do
|
2012-09-06 18:45:13 +01:00
|
|
|
@user = @project.owner
|
2011-12-23 10:56:46 +00:00
|
|
|
set_session_for(@user)
|
|
|
|
end
|
|
|
|
|
2012-09-06 18:45:13 +01:00
|
|
|
it_should_behave_like 'issue user with project guest rights'
|
2011-12-23 10:56:46 +00:00
|
|
|
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 'project with issues turned off'
|
2014-03-20 23:11:12 +00:00
|
|
|
# it_should_behave_like 'user without issue destroy rights'
|
2011-12-23 10:56:46 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'for project reader user' do
|
2015-03-05 23:45:37 +00:00
|
|
|
before do
|
2014-03-18 09:31:01 +00:00
|
|
|
create_relation(@project, @user, 'reader')
|
2011-12-23 10:56:46 +00:00
|
|
|
end
|
|
|
|
|
2012-09-06 18:45:13 +01:00
|
|
|
it_should_behave_like 'issue user with project guest rights'
|
2011-12-23 10:56:46 +00:00
|
|
|
it_should_behave_like 'issue user with project reader rights'
|
|
|
|
it_should_behave_like 'user without issue update rights'
|
|
|
|
it_should_behave_like 'project with issues turned off'
|
2014-03-20 23:11:12 +00:00
|
|
|
# it_should_behave_like 'user without issue destroy rights'
|
2011-12-23 10:56:46 +00:00
|
|
|
|
2013-04-03 12:11:50 +01:00
|
|
|
context 'perform create action' do
|
|
|
|
before { post :create, @create_params }
|
|
|
|
|
|
|
|
it 'user should not be assigned to issue' do
|
2015-03-05 23:45:37 +00:00
|
|
|
expect(@project.issues.last.assignee_id).to be_nil
|
2013-04-03 12:11:50 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'label should not be attached to issue' do
|
2015-02-19 01:12:08 +00:00
|
|
|
expect(@project.issues.last.labels.count).to eq 0
|
2013-04-03 12:11:50 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-07-22 16:19:25 +01:00
|
|
|
it 'should return 404' do
|
2014-03-19 07:19:03 +00:00
|
|
|
get :show, name_with_owner: @project.name_with_owner, id: 999999
|
2015-03-05 23:45:37 +00:00
|
|
|
expect(response).to render_template(file: "#{Rails.root}/public/404.html")
|
2013-07-22 16:19:25 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should redirect to pull request page' do
|
2015-03-05 23:45:37 +00:00
|
|
|
get :show, name_with_owner: @project.name_with_owner, id: @pull.reload.serial_id
|
|
|
|
expect(response).to redirect_to(project_pull_request_path(@project, @pull))
|
2013-07-22 16:19:25 +01:00
|
|
|
end
|
2015-04-23 06:14:22 +01:00
|
|
|
|
|
|
|
it 'should redirect to pull request in project with turned off issues' do
|
|
|
|
@project.update_attribute :has_issues, false
|
|
|
|
get :show, name_with_owner: @project.name_with_owner, id: @pull.reload.serial_id
|
|
|
|
expect(response).to redirect_to(project_pull_request_path(@project, @pull))
|
|
|
|
end
|
|
|
|
|
2011-12-23 10:56:46 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'for project writer user' do
|
2015-03-05 23:45:37 +00:00
|
|
|
before do
|
2014-03-18 09:31:01 +00:00
|
|
|
create_relation(@project, @user, 'writer')
|
2011-12-23 10:56:46 +00:00
|
|
|
end
|
|
|
|
|
2012-09-06 18:45:13 +01:00
|
|
|
it_should_behave_like 'issue user with project guest rights'
|
2011-12-23 10:56:46 +00:00
|
|
|
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 'project with issues turned off'
|
2014-03-20 23:11:12 +00:00
|
|
|
# it_should_behave_like 'user without issue destroy rights'
|
2011-12-23 10:56:46 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'for issue assign user' do
|
2015-03-05 23:45:37 +00:00
|
|
|
before do
|
2011-12-23 10:56:46 +00:00
|
|
|
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 'project with issues turned off'
|
2014-03-20 23:11:12 +00:00
|
|
|
# it_should_behave_like 'user without issue destroy rights'
|
2011-12-23 10:56:46 +00:00
|
|
|
end
|
2012-04-05 18:11:02 +01:00
|
|
|
|
|
|
|
context 'for guest' do
|
2012-05-30 17:03:07 +01:00
|
|
|
|
2015-03-05 23:45:37 +00:00
|
|
|
before do
|
2012-09-06 18:45:13 +01:00
|
|
|
set_session_for(User.new)
|
|
|
|
end
|
2012-05-30 17:03:07 +01:00
|
|
|
|
2012-09-06 18:45:13 +01:00
|
|
|
if APP_CONFIG['anonymous_access']
|
2014-01-21 04:51:49 +00:00
|
|
|
|
2012-09-06 18:45:13 +01:00
|
|
|
it_should_behave_like 'issue user with project guest rights'
|
2014-01-21 04:51:49 +00:00
|
|
|
|
2012-05-30 17:03:07 +01:00
|
|
|
it 'should not be able to perform index action on hidden project' do
|
2014-01-21 04:51:49 +00:00
|
|
|
@project.update_attributes(visibility: 'hidden')
|
2014-03-19 07:19:03 +00:00
|
|
|
get :index, name_with_owner: @project.name_with_owner
|
2015-03-05 23:45:37 +00:00
|
|
|
expect(response).to redirect_to(forbidden_path)
|
2012-05-30 17:03:07 +01:00
|
|
|
end
|
2012-09-06 18:45:13 +01:00
|
|
|
|
2012-04-05 18:11:02 +01:00
|
|
|
else
|
|
|
|
it 'should not be able to perform index action' do
|
2014-03-19 07:19:03 +00:00
|
|
|
get :index, name_with_owner: @project.name_with_owner
|
2015-03-05 23:45:37 +00:00
|
|
|
expect(response).to redirect_to(new_user_session_path)
|
2012-04-05 18:11:02 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should not be able to perform show action' do
|
2014-03-19 07:19:03 +00:00
|
|
|
get :show, name_with_owner: @project.name_with_owner, id: @issue.serial_id
|
2015-03-05 23:45:37 +00:00
|
|
|
expect(response).to redirect_to(new_user_session_path)
|
2012-04-05 18:11:02 +01:00
|
|
|
end
|
2012-05-30 17:03:07 +01:00
|
|
|
|
|
|
|
it 'should not be able to perform index action on hidden project' do
|
2014-01-21 04:51:49 +00:00
|
|
|
@project.update_attributes(visibility: 'hidden')
|
2014-03-19 07:19:03 +00:00
|
|
|
get :index, name_with_owner: @project.name_with_owner
|
2015-03-05 23:45:37 +00:00
|
|
|
expect(response).to redirect_to(new_user_session_path)
|
2012-05-30 17:03:07 +01:00
|
|
|
end
|
2012-04-05 18:11:02 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should not be able to perform create action' do
|
|
|
|
post :create, @create_params
|
2015-03-05 23:45:37 +00:00
|
|
|
expect(response).to redirect_to(new_user_session_path)
|
2012-04-05 18:11:02 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should not create issue object into db' do
|
2015-03-05 23:45:37 +00:00
|
|
|
expect do
|
|
|
|
post :create, @create_params
|
|
|
|
end.to change(Issue, :count).by(0)
|
2012-04-05 18:11:02 +01:00
|
|
|
end
|
|
|
|
|
2015-02-02 18:21:43 +00:00
|
|
|
#it_should_behave_like 'user without issue update rights'
|
|
|
|
it 'should not be able to perform update action' do
|
|
|
|
put :update, {id: @issue.serial_id}.merge(@update_params)
|
2015-03-05 23:45:37 +00:00
|
|
|
expect(response.code).to eq '401'
|
2015-02-02 18:21:43 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should not update issue title' do
|
|
|
|
put :update, {id: @issue.serial_id}.merge(@update_params)
|
2015-03-05 23:45:37 +00:00
|
|
|
expect(@issue.reload.title).to_not eq 'issue2'
|
2015-02-02 18:21:43 +00:00
|
|
|
end
|
|
|
|
|
2014-03-20 23:11:12 +00:00
|
|
|
# it_should_behave_like 'user without issue destroy rights'
|
2012-04-05 18:11:02 +01:00
|
|
|
end
|
2011-12-19 15:30:14 +00:00
|
|
|
end
|