2013-04-15 20:23:49 +01:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Api::V1::IssuesController do
|
2014-03-20 22:28:17 +00:00
|
|
|
before do
|
2013-04-15 20:23:49 +01:00
|
|
|
stub_symlink_methods
|
2014-01-21 04:51:49 +00:00
|
|
|
any_instance_of(Project, versions: ['v1.0', 'v2.0'])
|
2013-04-15 20:23:49 +01:00
|
|
|
|
2013-07-22 16:19:25 +01:00
|
|
|
@project = FactoryGirl.create(:project_with_commit)
|
2014-01-21 04:51:49 +00:00
|
|
|
@issue = FactoryGirl.create(:issue, project: @project)
|
2013-04-15 20:23:49 +01:00
|
|
|
|
|
|
|
@membered_issue = FactoryGirl.create(:issue)
|
|
|
|
@membered_project = @membered_issue.project
|
2014-03-18 09:31:01 +00:00
|
|
|
create_relation(@membered_project, @issue.user, 'reader')
|
2013-04-15 20:23:49 +01:00
|
|
|
|
|
|
|
@open_issue = FactoryGirl.create(:issue)
|
|
|
|
@open_project = @open_issue.project
|
|
|
|
|
2014-01-21 04:51:49 +00:00
|
|
|
@own_hidden_project = FactoryGirl.create(:project, owner: @issue.user)
|
2013-04-15 20:23:49 +01:00
|
|
|
@own_hidden_project.update_column :visibility, 'hidden'
|
2014-01-21 04:51:49 +00:00
|
|
|
@own_hidden_issue = FactoryGirl.create(:issue, project: @own_hidden_project, assignee: @issue.user)
|
2013-04-15 20:23:49 +01:00
|
|
|
|
|
|
|
@hidden_issue = FactoryGirl.create(:issue)
|
|
|
|
@hidden_project = @hidden_issue.project
|
|
|
|
@hidden_project.update_column :visibility, 'hidden'
|
|
|
|
|
2014-01-21 04:51:49 +00:00
|
|
|
@create_params = {issue: {title: 'title', body: 'body'}, project_id: @project.id, format: :json}
|
|
|
|
@update_params = {issue: {title: 'new title'}, project_id: @project.id, id: @issue.serial_id, format: :json}
|
2013-07-22 16:19:25 +01:00
|
|
|
|
2014-01-21 04:51:49 +00:00
|
|
|
@pull = @project.pull_requests.new issue_attributes: {title: 'test', body: 'testing'}
|
2013-07-22 16:19:25 +01:00
|
|
|
@pull.issue.user, @pull.issue.project = @project.owner, @pull.to_project
|
|
|
|
@pull.to_ref = 'master'
|
|
|
|
@pull.from_project, @pull.from_ref = @project, 'non_conflicts'
|
|
|
|
@pull.save
|
2013-04-15 20:23:49 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'read and accessible abilities' do
|
|
|
|
context 'for user' do
|
|
|
|
before(:each) do
|
|
|
|
http_login(@issue.user)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'can show issue in own project' do
|
2014-01-21 04:51:49 +00:00
|
|
|
get :show, project_id: @project.id, id: @issue.serial_id, format: :json
|
2013-04-15 20:23:49 +01:00
|
|
|
response.should be_success
|
|
|
|
end
|
|
|
|
|
2013-06-10 18:51:50 +01:00
|
|
|
it 'should render right template for show action' do
|
2014-01-21 04:51:49 +00:00
|
|
|
get :show, project_id: @project.id, id: @issue.serial_id, format: :json
|
2013-06-10 18:51:50 +01:00
|
|
|
response.should render_template('api/v1/issues/show')
|
|
|
|
end
|
|
|
|
|
2013-04-15 20:23:49 +01:00
|
|
|
it 'can show issue in open project' do
|
2014-01-21 04:51:49 +00:00
|
|
|
get :show, project_id: @open_project.id, id: @open_issue.serial_id, format: :json
|
2013-04-15 20:23:49 +01:00
|
|
|
response.should be_success
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'can show issue in own hidden project' do
|
2014-01-21 04:51:49 +00:00
|
|
|
get :show, project_id: @own_hidden_project.id, id: @own_hidden_issue.serial_id, format: :json
|
2013-04-15 20:23:49 +01:00
|
|
|
response.should be_success
|
|
|
|
end
|
|
|
|
|
2013-08-19 14:40:40 +01:00
|
|
|
it "can't show issue in hidden project" do
|
2014-01-21 04:51:49 +00:00
|
|
|
get :show, project_id: @hidden_project.id, id: @hidden_issue.serial_id, format: :json
|
2013-04-15 20:23:49 +01:00
|
|
|
response.status.should == 403
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should return three issues' do
|
2014-01-21 04:51:49 +00:00
|
|
|
get :all_index, filter: 'all', format: :json
|
2013-04-15 20:23:49 +01:00
|
|
|
assigns[:issues].should include(@issue)
|
|
|
|
assigns[:issues].should include(@own_hidden_issue)
|
|
|
|
assigns[:issues].should include(@membered_issue)
|
|
|
|
end
|
|
|
|
|
2013-06-10 18:51:50 +01:00
|
|
|
it 'should render right template for all index action' do
|
2014-01-21 04:51:49 +00:00
|
|
|
get :all_index, format: :json
|
2013-06-10 18:51:50 +01:00
|
|
|
response.should render_template('api/v1/issues/index')
|
|
|
|
end
|
|
|
|
|
2013-04-17 18:32:04 +01:00
|
|
|
it 'should return only assigned issue' do
|
2014-01-21 04:51:49 +00:00
|
|
|
get :user_index, format: :json
|
2013-04-17 18:32:04 +01:00
|
|
|
assigns[:issues].should include(@own_hidden_issue)
|
2013-06-28 17:15:17 +01:00
|
|
|
assigns[:issues].should have(1).item
|
2013-04-15 20:23:49 +01:00
|
|
|
end
|
2013-06-10 18:51:50 +01:00
|
|
|
|
|
|
|
it 'should render right template for user index action' do
|
2014-01-21 04:51:49 +00:00
|
|
|
get :user_index, format: :json
|
2013-06-10 18:51:50 +01:00
|
|
|
response.should render_template('api/v1/issues/index')
|
|
|
|
end
|
2013-07-22 20:27:55 +01:00
|
|
|
|
|
|
|
it 'should return 404' do
|
2014-01-21 04:51:49 +00:00
|
|
|
get :show, project_id: @project.id, id: 999999, format: :json
|
2013-07-22 20:27:55 +01:00
|
|
|
response.status.should == 404
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should redirect to pull request page' do
|
2014-01-21 04:51:49 +00:00
|
|
|
get :show, project_id: @project.id, id: @pull.serial_id, format: :json
|
2013-07-22 20:27:55 +01:00
|
|
|
response.should redirect_to(api_v1_project_pull_request_path(@project.id, @pull.serial_id))
|
|
|
|
end
|
2013-04-15 20:23:49 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'for anonymous user' do
|
2014-01-21 04:51:49 +00:00
|
|
|
it 'can show issue in open project', anonymous_access: true do
|
|
|
|
get :show, project_id: @project.id, id: @issue.serial_id, format: :json
|
2013-04-15 20:23:49 +01:00
|
|
|
response.should be_success
|
|
|
|
end
|
|
|
|
|
2014-01-21 04:51:49 +00:00
|
|
|
it "can't show issue in hidden project", anonymous_access: true do
|
|
|
|
get :show, project_id: @hidden_project.id, id: @hidden_issue.serial_id, format: :json
|
2013-04-15 20:23:49 +01:00
|
|
|
response.status.should == 403
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should not return any issues' do
|
2014-01-21 04:51:49 +00:00
|
|
|
get :all_index, filter: 'all', format: :json
|
2013-04-15 20:23:49 +01:00
|
|
|
response.status.should == 401
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'create accessibility' do
|
|
|
|
context 'for user' do
|
|
|
|
before(:each) do
|
|
|
|
http_login(@issue.user)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'can create issue in own project' do
|
2013-06-28 14:20:10 +01:00
|
|
|
lambda { post :create, @create_params}.should change{ Issue.count }.by(1)
|
2013-04-15 20:23:49 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'can create issue in own hidden project' do
|
2014-01-21 04:51:49 +00:00
|
|
|
lambda { post :create, @create_params.merge(project_id: @own_hidden_project.id)}.should change{ Issue.count }.by(1)
|
2013-04-15 20:23:49 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'can create issue in open project' do
|
2014-01-21 04:51:49 +00:00
|
|
|
lambda { post :create, @create_params.merge(project_id: @open_project.id)}.should change{ Issue.count }.by(1)
|
2013-04-15 20:23:49 +01:00
|
|
|
end
|
|
|
|
|
2013-08-19 14:40:40 +01:00
|
|
|
it "can't create issue in hidden project" do
|
2014-01-21 04:51:49 +00:00
|
|
|
lambda { post :create, @create_params.merge(project_id: @hidden_project.id)}.should change{ Issue.count }.by(0)
|
2013-04-15 20:23:49 +01:00
|
|
|
end
|
2013-08-19 11:53:12 +01:00
|
|
|
|
|
|
|
it 'can assignee issue in own project' do
|
2014-01-21 04:51:49 +00:00
|
|
|
post :create, @create_params.deep_merge(project_id: @own_hidden_project, issue: {assignee_id: @issue.user.id})
|
2013-08-19 14:40:58 +01:00
|
|
|
@own_hidden_project.issues.reload.last.assignee.id.should == @issue.user.id
|
2013-08-19 11:53:12 +01:00
|
|
|
end
|
|
|
|
|
2013-08-19 14:40:40 +01:00
|
|
|
it "can't assignee issue in open project" do
|
2014-01-21 04:51:49 +00:00
|
|
|
post :create, @create_params.deep_merge(project_id: @open_project.id, issue: {assignee_id: @issue.user.id})
|
2013-08-19 11:53:12 +01:00
|
|
|
@open_project.issues.reload.last.assignee.should be_nil
|
|
|
|
end
|
2013-04-15 20:23:49 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'for anonymous user' do
|
2014-01-21 04:51:49 +00:00
|
|
|
it "can't create issue in project", anonymous_access: true do
|
2013-06-28 14:20:10 +01:00
|
|
|
lambda { post :create, @create_params}.should change{ Issue.count }.by(0)
|
2013-04-15 20:23:49 +01:00
|
|
|
end
|
|
|
|
|
2014-01-21 04:51:49 +00:00
|
|
|
it "can't create issue in hidden project", anonymous_access: true do
|
|
|
|
lambda { post :create, @create_params.merge(project_id: @hidden_project.id)}.should change{ Issue.count }.by(0)
|
2013-04-15 20:23:49 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'update accessibility' do
|
|
|
|
context 'for user' do
|
|
|
|
before(:each) do
|
|
|
|
http_login(@issue.user)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'can update issue in own project' do
|
|
|
|
put :update, @update_params
|
|
|
|
@issue.reload.title.should == 'new title'
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'can update issue in own hidden project' do
|
2014-01-21 04:51:49 +00:00
|
|
|
put :update, @update_params.merge(project_id: @own_hidden_project.id, id: @own_hidden_issue.serial_id)
|
2013-04-15 20:23:49 +01:00
|
|
|
@own_hidden_issue.reload.title.should == 'new title'
|
|
|
|
end
|
|
|
|
|
2013-08-19 14:40:40 +01:00
|
|
|
it "can't update issue in open project" do
|
2014-01-21 04:51:49 +00:00
|
|
|
put :update, @update_params.merge(project_id: @open_project.id, id: @open_issue.serial_id)
|
2013-04-15 20:23:49 +01:00
|
|
|
@open_issue.reload.title.should_not == 'new title'
|
|
|
|
end
|
|
|
|
|
2013-08-19 14:40:40 +01:00
|
|
|
it "can't update issue in hidden project" do
|
2014-01-21 04:51:49 +00:00
|
|
|
put :update, @update_params.merge(project_id: @hidden_project.id, id: @hidden_issue.serial_id)
|
2013-04-15 20:23:49 +01:00
|
|
|
@hidden_issue.reload.title.should_not == 'title'
|
|
|
|
end
|
2013-08-19 11:53:12 +01:00
|
|
|
|
2013-08-19 14:40:40 +01:00
|
|
|
it "can't assignee issue in open project" do
|
2014-01-21 04:51:49 +00:00
|
|
|
post :create, @update_params.deep_merge(project_id: @open_project.id, issue: {assignee_id: @issue.user.id})
|
2013-08-19 11:53:12 +01:00
|
|
|
@open_issue.reload.assignee.id.should_not == @issue.user.id
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'can assignee issue in own project' do
|
2014-01-21 04:51:49 +00:00
|
|
|
post :create, @update_params.deep_merge(issue: {assignee_id: @issue.user.id})
|
2013-08-19 11:53:12 +01:00
|
|
|
@issue.reload.assignee.id.should_not == @issue.user.id
|
|
|
|
end
|
2013-04-15 20:23:49 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'for anonymous user' do
|
|
|
|
before(:each) do
|
|
|
|
@count = Issue.count
|
|
|
|
end
|
2014-01-21 04:51:49 +00:00
|
|
|
it "can't update issue in project", anonymous_access: true do
|
2013-04-15 20:23:49 +01:00
|
|
|
put :update, @update_params
|
|
|
|
response.status.should == 401
|
|
|
|
end
|
|
|
|
|
2014-01-21 04:51:49 +00:00
|
|
|
it "can't update issue in hidden project", anonymous_access: true do
|
|
|
|
put :update, @update_params.merge(project_id: @hidden_project.id, id: @hidden_issue.serial_id)
|
2013-04-15 20:23:49 +01:00
|
|
|
response.status.should == 401
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2013-06-28 14:20:10 +01:00
|
|
|
|
2013-04-15 20:23:49 +01:00
|
|
|
end
|