Cleanup of specs
This commit is contained in:
parent
eefcfdd1da
commit
ec4503e2d4
|
@ -1,74 +1,64 @@
|
||||||
require 'spec_helper'
|
require 'spec_helper'
|
||||||
|
|
||||||
describe Api::V1::IssuesController, type: :controller do
|
describe Api::V1::IssuesController, type: :controller do
|
||||||
|
let(:user) { FactoryGirl.create(:user) }
|
||||||
|
let(:project) { FactoryGirl.create(:project_with_commit) }
|
||||||
|
let(:issue) { FactoryGirl.create(:issue, project: project, user: user) }
|
||||||
|
let(:open_project) { FactoryGirl.create(:project) }
|
||||||
|
let(:open_issue) { FactoryGirl.create(:issue, project: open_project) }
|
||||||
|
let(:own_hidden_project) { FactoryGirl.create(:project, owner: user, visibility: 'hidden') }
|
||||||
|
let(:own_hidden_issue) { FactoryGirl.create(:issue, project: own_hidden_project, assignee: user) }
|
||||||
|
let(:hidden_project) { FactoryGirl.create(:project, visibility: 'hidden') }
|
||||||
|
let(:hidden_issue) { FactoryGirl.create(:issue, project: hidden_project) }
|
||||||
|
let(:create_params) { {issue: {title: 'title', body: 'body'}, project_id: project.id, format: :json} }
|
||||||
|
let(:update_params) { {issue: {title: 'new title'}, project_id: project.id, id: issue.serial_id, format: :json} }
|
||||||
|
|
||||||
before do
|
before do
|
||||||
stub_symlink_methods
|
stub_symlink_methods
|
||||||
allow_any_instance_of(Project).to receive(:versions).and_return(%w(v1.0 v2.0))
|
allow_any_instance_of(Project).to receive(:versions).and_return(%w(v1.0 v2.0))
|
||||||
|
|
||||||
@project = FactoryGirl.create(:project_with_commit)
|
|
||||||
@issue = FactoryGirl.create(:issue, project: @project)
|
|
||||||
|
|
||||||
@membered_issue = FactoryGirl.create(:issue)
|
|
||||||
@membered_project = @membered_issue.project
|
|
||||||
create_relation(@membered_project, @issue.user, 'reader')
|
|
||||||
|
|
||||||
@open_issue = FactoryGirl.create(:issue)
|
|
||||||
@open_project = @open_issue.project
|
|
||||||
|
|
||||||
@own_hidden_project = FactoryGirl.create(:project, owner: @issue.user)
|
|
||||||
@own_hidden_project.update_column :visibility, 'hidden'
|
|
||||||
@own_hidden_issue = FactoryGirl.create(:issue, project: @own_hidden_project, assignee: @issue.user)
|
|
||||||
|
|
||||||
@hidden_issue = FactoryGirl.create(:issue)
|
|
||||||
@hidden_project = @hidden_issue.project
|
|
||||||
@hidden_project.update_column :visibility, 'hidden'
|
|
||||||
|
|
||||||
@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}
|
|
||||||
|
|
||||||
@pull = @project.pull_requests.new issue_attributes: {title: 'test', body: 'testing'}
|
|
||||||
@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
|
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'read and accessible abilities' do
|
context 'read and accessible abilities' do
|
||||||
context 'for user' do
|
context 'for user' do
|
||||||
before do
|
before do
|
||||||
http_login(@issue.user)
|
http_login(user)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'can show issue in own project' do
|
it 'can show issue in own project' do
|
||||||
get :show, project_id: @project.id, id: @issue.serial_id, format: :json
|
get :show, project_id: project.id, id: issue.serial_id, format: :json
|
||||||
expect(response).to be_success
|
expect(response).to be_success
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should render right template for show action' do
|
it 'should render right template for show action' do
|
||||||
get :show, project_id: @project.id, id: @issue.serial_id, format: :json
|
get :show, project_id: project.id, id: issue.serial_id, format: :json
|
||||||
expect(response).to render_template('api/v1/issues/show')
|
expect(response).to render_template('api/v1/issues/show')
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'can show issue in open project' do
|
it 'can show issue in open project' do
|
||||||
get :show, project_id: @open_project.id, id: @open_issue.serial_id, format: :json
|
get :show, project_id: open_project.id, id: open_issue.serial_id, format: :json
|
||||||
expect(response).to be_success
|
expect(response).to be_success
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'can show issue in own hidden project' do
|
it 'can show issue in own hidden project' do
|
||||||
get :show, project_id: @own_hidden_project.id, id: @own_hidden_issue.serial_id, format: :json
|
get :show, project_id: own_hidden_project.id, id: own_hidden_issue.serial_id, format: :json
|
||||||
expect(response).to be_success
|
expect(response).to be_success
|
||||||
end
|
end
|
||||||
|
|
||||||
it "can't show issue in hidden project" do
|
it "can't show issue in hidden project" do
|
||||||
get :show, project_id: @hidden_project.id, id: @hidden_issue.serial_id, format: :json
|
get :show, project_id: hidden_project.id, id: hidden_issue.serial_id, format: :json
|
||||||
expect(response.code).to eq '403'
|
expect(response.code).to eq '403'
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should return three issues' do
|
it 'should return three issues' do
|
||||||
|
membered_issue = FactoryGirl.create(:issue)
|
||||||
|
membered_project = membered_issue.project
|
||||||
|
create_relation(membered_project, issue.user, 'reader')
|
||||||
|
|
||||||
|
issue && own_hidden_issue # init
|
||||||
get :all_index, filter: 'all', format: :json
|
get :all_index, filter: 'all', format: :json
|
||||||
expect(assigns[:issues]).to include(@issue)
|
expect(assigns[:issues]).to include(issue)
|
||||||
expect(assigns[:issues]).to include(@own_hidden_issue)
|
expect(assigns[:issues]).to include(own_hidden_issue)
|
||||||
expect(assigns[:issues]).to include(@membered_issue)
|
expect(assigns[:issues]).to include(membered_issue)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should render right template for all index action' do
|
it 'should render right template for all index action' do
|
||||||
|
@ -77,8 +67,9 @@ describe Api::V1::IssuesController, type: :controller do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should return only assigned issue' do
|
it 'should return only assigned issue' do
|
||||||
|
own_hidden_issue # init
|
||||||
get :user_index, format: :json
|
get :user_index, format: :json
|
||||||
expect(assigns[:issues]).to include(@own_hidden_issue)
|
expect(assigns[:issues]).to include(own_hidden_issue)
|
||||||
expect(assigns[:issues].count).to eq 1
|
expect(assigns[:issues].count).to eq 1
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -88,24 +79,30 @@ describe Api::V1::IssuesController, type: :controller do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should return 404' do
|
it 'should return 404' do
|
||||||
get :show, project_id: @project.id, id: 999999, format: :json
|
get :show, project_id: project.id, id: 999999, format: :json
|
||||||
expect(response.code).to eq '404'
|
expect(response.code).to eq '404'
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should redirect to pull request page' do
|
it 'should redirect to pull request page' do
|
||||||
get :show, project_id: @project.id, id: @pull.reload.serial_id, format: :json
|
pull = project.pull_requests.new issue_attributes: {title: 'test', body: 'testing'}
|
||||||
expect(response).to redirect_to(api_v1_project_pull_request_path(@project.id, @pull.serial_id))
|
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
|
||||||
|
|
||||||
|
get :show, project_id: project.id, id: pull.reload.serial_id, format: :json
|
||||||
|
expect(response).to redirect_to(api_v1_project_pull_request_path(project.id, pull.serial_id))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'for anonymous user' do
|
context 'for anonymous user' do
|
||||||
it 'can show issue in open project', anonymous_access: true do
|
it 'can show issue in open project', anonymous_access: true do
|
||||||
get :show, project_id: @project.id, id: @issue.serial_id, format: :json
|
get :show, project_id: project.id, id: issue.serial_id, format: :json
|
||||||
expect(response).to be_success
|
expect(response).to be_success
|
||||||
end
|
end
|
||||||
|
|
||||||
it "can't show issue in hidden project", anonymous_access: true do
|
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
|
get :show, project_id: hidden_project.id, id: hidden_issue.serial_id, format: :json
|
||||||
expect(response.code).to eq '403'
|
expect(response.code).to eq '403'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -119,54 +116,54 @@ describe Api::V1::IssuesController, type: :controller do
|
||||||
context 'create accessibility' do
|
context 'create accessibility' do
|
||||||
context 'for user' do
|
context 'for user' do
|
||||||
before do
|
before do
|
||||||
http_login(@issue.user)
|
http_login(user)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'can create issue in own project' do
|
it 'can create issue in own project' do
|
||||||
expect do
|
expect do
|
||||||
post :create, @create_params
|
post :create, create_params
|
||||||
end.to change(Issue, :count).by(1)
|
end.to change(Issue, :count).by(1)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'can create issue in own hidden project' do
|
it 'can create issue in own hidden project' do
|
||||||
expect do
|
expect do
|
||||||
post :create, @create_params.merge(project_id: @own_hidden_project.id)
|
post :create, create_params.merge(project_id: own_hidden_project.id)
|
||||||
end.to change(Issue, :count).by(1)
|
end.to change(Issue, :count).by(1)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'can create issue in open project' do
|
it 'can create issue in open project' do
|
||||||
expect do
|
expect do
|
||||||
post :create, @create_params.merge(project_id: @open_project.id)
|
post :create, create_params.merge(project_id: open_project.id)
|
||||||
end.to change(Issue, :count).by(1)
|
end.to change(Issue, :count).by(1)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "can't create issue in hidden project" do
|
it "can't create issue in hidden project" do
|
||||||
expect do
|
expect do
|
||||||
post :create, @create_params.merge(project_id: @hidden_project.id)
|
post :create, create_params.merge(project_id: hidden_project.id)
|
||||||
end.to change(Issue, :count).by(0)
|
end.to change(Issue, :count).by(0)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'can assignee issue in own project' do
|
it 'can assignee issue in own project' do
|
||||||
post :create, @create_params.deep_merge(project_id: @own_hidden_project.id, issue: {assignee_id: @issue.user.id})
|
post :create, create_params.deep_merge(project_id: own_hidden_project.id, issue: {assignee_id: user.id})
|
||||||
expect(@own_hidden_project.issues.order(:id).last.assignee.id).to eq @issue.user.id
|
expect(own_hidden_project.issues.order(:id).last.assignee.id).to eq user.id
|
||||||
end
|
end
|
||||||
|
|
||||||
it "can't assignee issue in open project" do
|
it "can't assignee issue in open project" do
|
||||||
post :create, @create_params.deep_merge(project_id: @open_project.id, issue: {assignee_id: @issue.user.id})
|
post :create, create_params.deep_merge(project_id: open_project.id, issue: {assignee_id: user.id})
|
||||||
expect(@open_project.issues.order(:id).last.assignee).to be_nil
|
expect(open_project.issues.order(:id).last.assignee).to be_nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'for anonymous user' do
|
context 'for anonymous user' do
|
||||||
it "can't create issue in project", anonymous_access: true do
|
it "can't create issue in project", anonymous_access: true do
|
||||||
expect do
|
expect do
|
||||||
post :create, @create_params
|
post :create, create_params
|
||||||
end.to change(Issue, :count).by(0)
|
end.to change(Issue, :count).by(0)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "can't create issue in hidden project", anonymous_access: true do
|
it "can't create issue in hidden project", anonymous_access: true do
|
||||||
expect do
|
expect do
|
||||||
post :create, @create_params.merge(project_id: @hidden_project.id)
|
post :create, create_params.merge(project_id: hidden_project.id)
|
||||||
end.to change(Issue, :count).by(0)
|
end.to change(Issue, :count).by(0)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -175,48 +172,48 @@ describe Api::V1::IssuesController, type: :controller do
|
||||||
context 'update accessibility' do
|
context 'update accessibility' do
|
||||||
context 'for user' do
|
context 'for user' do
|
||||||
before(:each) do
|
before(:each) do
|
||||||
http_login(@issue.user)
|
http_login(user)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'can update issue in own project' do
|
it 'can update issue in own project' do
|
||||||
put :update, @update_params
|
put :update, update_params
|
||||||
expect(@issue.reload.title).to eq 'new title'
|
expect(issue.reload.title).to eq 'new title'
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'can update issue in own hidden project' do
|
it 'can update issue in own hidden project' do
|
||||||
put :update, @update_params.merge(project_id: @own_hidden_project.id, id: @own_hidden_issue.serial_id)
|
put :update, update_params.merge(project_id: own_hidden_project.id, id: own_hidden_issue.serial_id)
|
||||||
expect(@own_hidden_issue.reload.title).to eq 'new title'
|
expect(own_hidden_issue.reload.title).to eq 'new title'
|
||||||
end
|
end
|
||||||
|
|
||||||
it "can't update issue in open project" do
|
it "can't update issue in open project" do
|
||||||
put :update, @update_params.merge(project_id: @open_project.id, id: @open_issue.serial_id)
|
put :update, update_params.merge(project_id: open_project.id, id: open_issue.serial_id)
|
||||||
expect(@open_issue.reload.title).to_not eq 'new title'
|
expect(open_issue.reload.title).to_not eq 'new title'
|
||||||
end
|
end
|
||||||
|
|
||||||
it "can't update issue in hidden project" do
|
it "can't update issue in hidden project" do
|
||||||
put :update, @update_params.merge(project_id: @hidden_project.id, id: @hidden_issue.serial_id)
|
put :update, update_params.merge(project_id: hidden_project.id, id: hidden_issue.serial_id)
|
||||||
expect(@hidden_issue.reload.title).to_not eq 'title'
|
expect(hidden_issue.reload.title).to_not eq 'title'
|
||||||
end
|
end
|
||||||
|
|
||||||
it "can't assignee issue in open project" do
|
it "can't assignee issue in open project" do
|
||||||
post :create, @update_params.deep_merge(project_id: @open_project.id, issue: {assignee_id: @issue.user.id})
|
post :create, update_params.deep_merge(project_id: open_project.id, issue: {assignee_id: user.id})
|
||||||
expect(@open_issue.reload.assignee.id).to_not eq @issue.user.id
|
expect(open_issue.reload.assignee.id).to_not eq issue.user.id
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'can assignee issue in own project' do
|
it 'can assignee issue in own project' do
|
||||||
post :create, @update_params.deep_merge(issue: {assignee_id: @issue.user.id})
|
post :create, update_params.deep_merge(issue: {assignee_id: issue.user.id})
|
||||||
expect(@issue.reload.assignee.id).to_not eq @issue.user.id
|
expect(issue.reload.assignee.id).to_not eq issue.user.id
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'for anonymous user' do
|
context 'for anonymous user' do
|
||||||
it "can't update issue in project", anonymous_access: true do
|
it "can't update issue in project", anonymous_access: true do
|
||||||
put :update, @update_params
|
put :update, update_params
|
||||||
expect(response.code).to eq '401'
|
expect(response.code).to eq '401'
|
||||||
end
|
end
|
||||||
|
|
||||||
it "can't update issue in hidden project", anonymous_access: true do
|
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)
|
put :update, update_params.merge(project_id: hidden_project.id, id: hidden_issue.serial_id)
|
||||||
expect(response.code).to eq '401'
|
expect(response.code).to eq '401'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
require 'spec_helper'
|
require 'spec_helper'
|
||||||
|
|
||||||
def create_pull to_ref, from_ref, owner, project = @project
|
def create_pull to_ref, from_ref, owner, project
|
||||||
pull = project.pull_requests.build issue_attributes: {title: 'test', body: 'testing'}
|
pull = project.pull_requests.build issue_attributes: {title: 'test', body: 'testing'}
|
||||||
pull.issue.user, pull.issue.project = owner, pull.to_project
|
pull.issue.user, pull.issue.project = owner, pull.to_project
|
||||||
pull.to_ref, pull.from_ref, pull.from_project = to_ref, from_ref, project
|
pull.to_ref, pull.from_ref, pull.from_project = to_ref, from_ref, project
|
||||||
|
@ -9,74 +9,81 @@ def create_pull to_ref, from_ref, owner, project = @project
|
||||||
end
|
end
|
||||||
|
|
||||||
describe Api::V1::PullRequestsController, type: :controller do
|
describe Api::V1::PullRequestsController, type: :controller do
|
||||||
|
let(:user) { FactoryGirl.create(:user) }
|
||||||
|
let(:project) { FactoryGirl.create(:project_with_commit, owner: user) }
|
||||||
|
let(:issue) { FactoryGirl.create(:issue, project: project) }
|
||||||
|
let(:pull) { create_pull 'master', 'non_conflicts', user, project }
|
||||||
|
let(:another_project) { FactoryGirl.create(:project_with_commit) }
|
||||||
|
let(:another_pull) { create_pull 'master', 'non_conflicts', another_project.owner, another_project }
|
||||||
|
let(:hidden_project) { FactoryGirl.create(:project_with_commit, visibility: 'hidden') }
|
||||||
|
let(:hidden_pull) { create_pull 'master', 'non_conflicts', hidden_project.owner, hidden_project }
|
||||||
|
let(:own_hidden_project) { FactoryGirl.create(:project_with_commit, owner: user, visibility: 'hidden') }
|
||||||
|
let(:own_hidden_pull) { create_pull 'master', 'non_conflicts', user, own_hidden_project }
|
||||||
|
let(:membered_project) { FactoryGirl.create(:project_with_commit) }
|
||||||
|
let(:membered_pull) { create_pull 'master', 'non_conflicts', membered_project.owner, membered_project }
|
||||||
|
let(:create_params) { {
|
||||||
|
pull_request: {
|
||||||
|
title: 'title',
|
||||||
|
body: 'body',
|
||||||
|
from_ref: 'conflicts',
|
||||||
|
to_ref: 'master'
|
||||||
|
},
|
||||||
|
project_id: project.id,
|
||||||
|
format: :json
|
||||||
|
} }
|
||||||
|
let(:update_params) { {
|
||||||
|
pull_request: {
|
||||||
|
title: 'new title'
|
||||||
|
},
|
||||||
|
project_id: project.id,
|
||||||
|
id: pull.serial_id,
|
||||||
|
format: :json
|
||||||
|
} }
|
||||||
|
|
||||||
before do
|
before do
|
||||||
stub_symlink_methods
|
stub_symlink_methods
|
||||||
|
|
||||||
@project = FactoryGirl.create(:project_with_commit)
|
own_hidden_pull.issue.update_column :assignee_id, user.id
|
||||||
@pull = create_pull 'master', 'non_conflicts', @project.owner
|
create_relation(membered_project, user, 'reader')
|
||||||
|
|
||||||
@another_project = FactoryGirl.create(:project_with_commit)
|
|
||||||
@another_pull = create_pull 'master', 'non_conflicts', @another_project.owner, @another_project
|
|
||||||
|
|
||||||
@hidden_project = FactoryGirl.create(:project_with_commit)
|
|
||||||
@hidden_project.update_column :visibility, 'hidden'
|
|
||||||
@hidden_pull = create_pull 'master', 'non_conflicts', @hidden_project.owner, @hidden_project
|
|
||||||
|
|
||||||
@own_hidden_project = FactoryGirl.create(:project_with_commit, owner: @project.owner)
|
|
||||||
@own_hidden_project.update_column :visibility, 'hidden'
|
|
||||||
@own_hidden_pull = create_pull 'master', 'non_conflicts', @own_hidden_project.owner, @own_hidden_project
|
|
||||||
@own_hidden_pull.issue.update_column :assignee_id, @project.owner.id
|
|
||||||
|
|
||||||
@membered_project = FactoryGirl.create(:project_with_commit)
|
|
||||||
@membered_pull = create_pull 'master', 'non_conflicts', @membered_project.owner, @membered_project
|
|
||||||
create_relation(@membered_project, @pull.user, 'reader')
|
|
||||||
|
|
||||||
@create_params = {pull_request: {title: 'title', body: 'body',
|
|
||||||
from_ref: 'conflicts', to_ref: 'master'},
|
|
||||||
project_id: @project.id, format: :json}
|
|
||||||
|
|
||||||
@update_params = {pull_request: {title: 'new title'},
|
|
||||||
project_id: @project.id, id: @pull.serial_id, format: :json}
|
|
||||||
|
|
||||||
@issue = FactoryGirl.create(:issue, project: @project)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'read and accessible abilities' do
|
context 'read and accessible abilities' do
|
||||||
context 'for user' do
|
context 'for user' do
|
||||||
before do
|
before do
|
||||||
http_login(@project.owner)
|
http_login(user)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'can show pull request in own project' do
|
it 'can show pull request in own project' do
|
||||||
get :show, project_id: @project.id, id: @pull.serial_id, format: :json
|
get :show, project_id: project.id, id: pull.serial_id, format: :json
|
||||||
expect(response).to be_success
|
expect(response).to be_success
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should render right template for show action' do
|
it 'should render right template for show action' do
|
||||||
get :show, project_id: @project.id, id: @pull.serial_id, format: :json
|
get :show, project_id: project.id, id: pull.serial_id, format: :json
|
||||||
expect(response).to render_template('api/v1/pull_requests/show')
|
expect(response).to render_template('api/v1/pull_requests/show')
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'can show pull request in open project' do
|
it 'can show pull request in open project' do
|
||||||
get :show, project_id: @another_project.id, id: @another_pull.serial_id, format: :json
|
get :show, project_id: another_project.id, id: another_pull.serial_id, format: :json
|
||||||
expect(response).to be_success
|
expect(response).to be_success
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'can show pull request in own hidden project' do
|
it 'can show pull request in own hidden project' do
|
||||||
get :show, project_id: @own_hidden_project.id, id: @own_hidden_pull.serial_id, format: :json
|
get :show, project_id: own_hidden_project.id, id: own_hidden_pull.serial_id, format: :json
|
||||||
expect(response).to be_success
|
expect(response).to be_success
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'cant show pull request in hidden project' do
|
it 'cant show pull request in hidden project' do
|
||||||
get :show, project_id: @hidden_project.id, id: @hidden_pull.serial_id, format: :json
|
get :show, project_id: hidden_project.id, id: hidden_pull.serial_id, format: :json
|
||||||
expect(response.status).to eq 403
|
expect(response.status).to eq 403
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should return three pull requests' do
|
it 'should return three pull requests' do
|
||||||
|
pull && own_hidden_pull && membered_pull # init
|
||||||
get :all_index, filter: 'all', format: :json
|
get :all_index, filter: 'all', format: :json
|
||||||
expect(assigns[:pulls]).to include(@pull)
|
expect(assigns[:pulls]).to include(pull)
|
||||||
expect(assigns[:pulls]).to include(@own_hidden_pull)
|
expect(assigns[:pulls]).to include(own_hidden_pull)
|
||||||
expect(assigns[:pulls]).to include(@membered_pull)
|
expect(assigns[:pulls]).to include(membered_pull)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should render right template for all index action' do
|
it 'should render right template for all index action' do
|
||||||
|
@ -85,8 +92,9 @@ describe Api::V1::PullRequestsController, type: :controller do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should return only assigned pull request' do
|
it 'should return only assigned pull request' do
|
||||||
|
own_hidden_pull # init
|
||||||
get :user_index, format: :json
|
get :user_index, format: :json
|
||||||
expect(assigns[:pulls]).to include(@own_hidden_pull)
|
expect(assigns[:pulls]).to include(own_hidden_pull)
|
||||||
expect(assigns[:pulls].count).to eq 1
|
expect(assigns[:pulls].count).to eq 1
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -97,41 +105,41 @@ describe Api::V1::PullRequestsController, type: :controller do
|
||||||
|
|
||||||
%w(commits files).each do |action|
|
%w(commits files).each do |action|
|
||||||
it "can show pull request #{action} in own project" do
|
it "can show pull request #{action} in own project" do
|
||||||
get action, project_id: @project.id, id: @pull.serial_id, format: :json
|
get action, project_id: project.id, id: pull.serial_id, format: :json
|
||||||
expect(response).to be_success
|
expect(response).to be_success
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should render right template for commits action" do
|
it "should render right template for commits action" do
|
||||||
get action, project_id: @project.id, id: @pull.serial_id, format: :json
|
get action, project_id: project.id, id: pull.serial_id, format: :json
|
||||||
expect(response).to render_template("api/v1/pull_requests/#{action}")
|
expect(response).to render_template("api/v1/pull_requests/#{action}")
|
||||||
end
|
end
|
||||||
|
|
||||||
it "can't show pull request #{action} in hidden project" do
|
it "can't show pull request #{action} in hidden project" do
|
||||||
get action, project_id: @hidden_project.id, id: @hidden_pull.serial_id, format: :json
|
get action, project_id: hidden_project.id, id: hidden_pull.serial_id, format: :json
|
||||||
expect(response).to_not be_success
|
expect(response).to_not be_success
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should return 404' do
|
it 'should return 404' do
|
||||||
get :show, project_id: @project.id, id: 999999, format: :json
|
get :show, project_id: project.id, id: 999999, format: :json
|
||||||
expect(response.status).to eq 404
|
expect(response.status).to eq 404
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should redirect to issue page' do
|
it 'should redirect to issue page' do
|
||||||
get :show, project_id: @project.id, id: @issue.serial_id, format: :json
|
get :show, project_id: project.id, id: issue.serial_id, format: :json
|
||||||
expect(response).to redirect_to(api_v1_project_issue_path(@project.id, @issue.serial_id))
|
expect(response).to redirect_to(api_v1_project_issue_path(project.id, issue.serial_id))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'for anonymous user' do
|
context 'for anonymous user' do
|
||||||
it 'can show pull request in open project', anonymous_access: true do
|
it 'can show pull request in open project', anonymous_access: true do
|
||||||
get :show, project_id: @project.id, id: @pull.serial_id, format: :json
|
get :show, project_id: project.id, id: pull.serial_id, format: :json
|
||||||
expect(response).to be_success
|
expect(response).to be_success
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'cant show pull request in hidden project', anonymous_access: true do
|
it 'cant show pull request in hidden project', anonymous_access: true do
|
||||||
@project.update_column :visibility, 'hidden'
|
# project.update_column :visibility, 'hidden'
|
||||||
get :show, project_id: @project.id, id: @pull.serial_id, format: :json
|
get :show, project_id: hidden_project.id, id: hidden_pull.serial_id, format: :json
|
||||||
expect(response.status).to eq 403
|
expect(response.status).to eq 403
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -142,17 +150,17 @@ describe Api::V1::PullRequestsController, type: :controller do
|
||||||
|
|
||||||
%w(commits files).each do |action|
|
%w(commits files).each do |action|
|
||||||
it "can show pull request #{action} in project", anonymous_access: true do
|
it "can show pull request #{action} in project", anonymous_access: true do
|
||||||
get action, project_id: @project.id, id: @pull.serial_id, format: :json
|
get action, project_id: project.id, id: pull.serial_id, format: :json
|
||||||
expect(response).to be_success
|
expect(response).to be_success
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should render right template for commits action", anonymous_access: true do
|
it "should render right template for commits action", anonymous_access: true do
|
||||||
get action, project_id: @project.id, id: @pull.serial_id, format: :json
|
get action, project_id: project.id, id: pull.serial_id, format: :json
|
||||||
expect(response).to render_template("api/v1/pull_requests/#{action}")
|
expect(response).to render_template("api/v1/pull_requests/#{action}")
|
||||||
end
|
end
|
||||||
|
|
||||||
it "can't show pull request #{action} in hidden project", anonymous_access: true do
|
it "can't show pull request #{action} in hidden project", anonymous_access: true do
|
||||||
get action, project_id: @hidden_project.id, id: @hidden_pull.serial_id, format: :json
|
get action, project_id: hidden_project.id, id: hidden_pull.serial_id, format: :json
|
||||||
expect(response).to_not be_success
|
expect(response).to_not be_success
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -162,30 +170,30 @@ describe Api::V1::PullRequestsController, type: :controller do
|
||||||
context 'create accessibility' do
|
context 'create accessibility' do
|
||||||
context 'for user' do
|
context 'for user' do
|
||||||
before(:each) do
|
before(:each) do
|
||||||
http_login(@pull.user)
|
http_login(user)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'can create pull request in own project' do
|
it 'can create pull request in own project' do
|
||||||
expect do
|
expect do
|
||||||
post :create, @create_params
|
post :create, create_params
|
||||||
end.to change(PullRequest, :count).by(1)
|
end.to change(PullRequest, :count).by(1)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'can create pull request in own hidden project' do
|
it 'can create pull request in own hidden project' do
|
||||||
expect do
|
expect do
|
||||||
post :create, @create_params.merge(project_id: @own_hidden_project.id)
|
post :create, create_params.merge(project_id: own_hidden_project.id)
|
||||||
end.to change(PullRequest, :count).by(1)
|
end.to change(PullRequest, :count).by(1)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'can create pull request in open project' do
|
it 'can create pull request in open project' do
|
||||||
expect do
|
expect do
|
||||||
post :create, @create_params.merge(project_id: @another_project.id)
|
post :create, create_params.merge(project_id: another_project.id)
|
||||||
end.to change(PullRequest, :count).by(1)
|
end.to change(PullRequest, :count).by(1)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'cant create pull request in hidden project' do
|
it 'cant create pull request in hidden project' do
|
||||||
expect do
|
expect do
|
||||||
post :create, @create_params.merge(project_id: @hidden_project.id)
|
post :create, create_params.merge(project_id: hidden_project.id)
|
||||||
end.to_not change(PullRequest, :count)
|
end.to_not change(PullRequest, :count)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -193,13 +201,13 @@ describe Api::V1::PullRequestsController, type: :controller do
|
||||||
context 'for anonymous user' do
|
context 'for anonymous user' do
|
||||||
it 'cant create pull request in project', anonymous_access: true do
|
it 'cant create pull request in project', anonymous_access: true do
|
||||||
expect do
|
expect do
|
||||||
post :create, @create_params
|
post :create, create_params
|
||||||
end.to_not change(PullRequest, :count)
|
end.to_not change(PullRequest, :count)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'cant create pull request in hidden project', anonymous_access: true do
|
it 'cant create pull request in hidden project', anonymous_access: true do
|
||||||
expect do
|
expect do
|
||||||
post :create, @create_params.merge(project_id: @hidden_project.id)
|
post :create, create_params.merge(project_id: hidden_project.id)
|
||||||
end.to_not change(PullRequest, :count)
|
end.to_not change(PullRequest, :count)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -208,110 +216,112 @@ describe Api::V1::PullRequestsController, type: :controller do
|
||||||
context 'update accessibility' do
|
context 'update accessibility' do
|
||||||
context 'for user' do
|
context 'for user' do
|
||||||
before(:each) do
|
before(:each) do
|
||||||
http_login(@project.owner)
|
http_login(project.owner)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'can update pull request in own project' do
|
it 'can update pull request in own project' do
|
||||||
put :update, @update_params
|
put :update, update_params
|
||||||
expect(@pull.reload.title).to eq 'new title'
|
expect(pull.reload.title).to eq 'new title'
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'can update pull request in own hidden project' do
|
it 'can update pull request in own hidden project' do
|
||||||
put :update, @update_params.merge(project_id: @own_hidden_project.id, id: @own_hidden_pull.serial_id)
|
put :update, update_params.merge(project_id: own_hidden_project.id, id: own_hidden_pull.serial_id)
|
||||||
expect(@own_hidden_pull.reload.title).to eq 'new title'
|
expect(own_hidden_pull.reload.title).to eq 'new title'
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'cant update pull request in open project' do
|
it 'cant update pull request in open project' do
|
||||||
put :update, @update_params.merge(project_id: @another_project.id, id: @another_pull.serial_id)
|
put :update, update_params.merge(project_id: another_project.id, id: another_pull.serial_id)
|
||||||
expect(@another_pull.reload.title).to_not eq 'new title'
|
expect(another_pull.reload.title).to_not eq 'new title'
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'cant update pull request in hidden project' do
|
it 'cant update pull request in hidden project' do
|
||||||
put :update, @update_params.merge(project_id: @hidden_project.id, id: @hidden_pull.serial_id)
|
put :update, update_params.merge(project_id: hidden_project.id, id: hidden_pull.serial_id)
|
||||||
expect(@hidden_pull.reload.title).to_not eq 'title'
|
expect(hidden_pull.reload.title).to_not eq 'title'
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'can merge pull request in own project' do
|
it 'can merge pull request in own project' do
|
||||||
put :merge, project_id: @project.id, id: @pull.serial_id, format: :json
|
put :merge, project_id: project.id, id: pull.serial_id, format: :json
|
||||||
expect(@pull.reload.status).to eq 'merged'
|
expect(pull.reload.status).to eq 'merged'
|
||||||
expect(response).to be_success
|
expect(response).to be_success
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'can merge pull request in own hidden project' do
|
it 'can merge pull request in own hidden project' do
|
||||||
put :merge, project_id: @own_hidden_project.id, id: @own_hidden_pull.serial_id, format: :json
|
put :merge, project_id: own_hidden_project.id, id: own_hidden_pull.serial_id, format: :json
|
||||||
expect(@own_hidden_pull.reload.status).to eq 'merged'
|
expect(own_hidden_pull.reload.status).to eq 'merged'
|
||||||
expect(response).to be_success
|
expect(response).to be_success
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'cant merge pull request in open project' do
|
it 'cant merge pull request in open project' do
|
||||||
put :merge, project_id: @another_project.id, id: @another_pull.serial_id, format: :json
|
put :merge, project_id: another_project.id, id: another_pull.serial_id, format: :json
|
||||||
expect(@another_pull.reload.status).to eq 'ready'
|
expect(another_pull.reload.status).to eq 'ready'
|
||||||
expect(response.status).to eq 403
|
expect(response.status).to eq 403
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'cant merge pull request in hidden project' do
|
it 'cant merge pull request in hidden project' do
|
||||||
put :merge, project_id: @hidden_project.id, id: @hidden_pull.serial_id, format: :json
|
put :merge, project_id: hidden_project.id, id: hidden_pull.serial_id, format: :json
|
||||||
expect(@hidden_pull.reload.status).to eq 'ready'
|
expect(hidden_pull.reload.status).to eq 'ready'
|
||||||
expect(response.status).to eq 403
|
expect(response.status).to eq 403
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'for anonymous user' do
|
context 'for anonymous user' do
|
||||||
it 'cant update pull request in project', anonymous_access: true do
|
it 'cant update pull request in project', anonymous_access: true do
|
||||||
put :update, @update_params
|
put :update, update_params
|
||||||
expect(response.status).to eq 401
|
expect(response.status).to eq 401
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'cant update pull request in hidden project', anonymous_access: true do
|
it 'cant update pull request in hidden project', anonymous_access: true do
|
||||||
put :update, @update_params.merge(project_id: @hidden_project.id, id: @hidden_pull.serial_id)
|
put :update, update_params.merge(project_id: hidden_project.id, id: hidden_pull.serial_id)
|
||||||
expect(response.status).to eq 401
|
expect(response.status).to eq 401
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'cant merge pull request in open project' do
|
it 'cant merge pull request in open project' do
|
||||||
put :merge, project_id: @another_project.id, id: @another_pull.serial_id, format: :json
|
put :merge, project_id: another_project.id, id: another_pull.serial_id, format: :json
|
||||||
expect(@another_pull.reload.status).to eq 'ready'
|
expect(another_pull.reload.status).to eq 'ready'
|
||||||
expect(response.status).to eq 401
|
expect(response.status).to eq 401
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'cant merge pull request in hidden project' do
|
it 'cant merge pull request in hidden project' do
|
||||||
put :merge, project_id: @hidden_project.id, id: @hidden_pull.serial_id, format: :json
|
put :merge, project_id: hidden_project.id, id: hidden_pull.serial_id, format: :json
|
||||||
expect(@hidden_pull.reload.status).to eq 'ready'
|
expect(hidden_pull.reload.status).to eq 'ready'
|
||||||
expect(response.status).to eq 401
|
expect(response.status).to eq 401
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'send email messages' do
|
context 'send email messages' do
|
||||||
before do
|
let(:project_reader) { FactoryGirl.create :user }
|
||||||
@project_reader = FactoryGirl.create :user
|
let(:project_writer) { FactoryGirl.create :user }
|
||||||
create_relation(@project, @project_reader, 'reader')
|
let(:project_admin) { FactoryGirl.create :user }
|
||||||
@project_admin = FactoryGirl.create :user
|
|
||||||
create_relation(@project, @project_admin, 'admin')
|
|
||||||
@project_writer = FactoryGirl.create :user
|
|
||||||
create_relation(@project, @project_writer, 'writer')
|
|
||||||
|
|
||||||
http_login(@project_writer)
|
before do
|
||||||
|
create_relation(project, project_reader, 'reader')
|
||||||
|
create_relation(project, project_admin, 'admin')
|
||||||
|
create_relation(project, project_writer, 'writer')
|
||||||
|
|
||||||
|
http_login(project_writer)
|
||||||
|
pull # init
|
||||||
ActionMailer::Base.deliveries = []
|
ActionMailer::Base.deliveries = []
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should send two email messages to all project members' do
|
it 'should send two email messages to all project members' do
|
||||||
post :create, @create_params
|
post :create, create_params
|
||||||
expect(ActionMailer::Base.deliveries.count).to eq 3 # project owner + reader + admin
|
expect(ActionMailer::Base.deliveries.count).to eq 3 # project owner + reader + admin
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should send two email messages to admins and one to assignee' do
|
it 'should send two email messages to admins and one to assignee' do
|
||||||
post :create, @create_params.deep_merge(pull_request: {assignee_id: @project_reader.id})
|
post :create, create_params.deep_merge(pull_request: {assignee_id: project_reader.id})
|
||||||
expect(ActionMailer::Base.deliveries.count).to eq 3
|
expect(ActionMailer::Base.deliveries.count).to eq 3
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should send email message to new assignee' do
|
it 'should send email message to new assignee' do
|
||||||
http_login(@project_admin)
|
http_login(project_admin)
|
||||||
put :update, @update_params.deep_merge(pull_request: {assignee_id: @project_reader.id})
|
put :update, update_params.deep_merge(pull_request: {assignee_id: project_reader.id})
|
||||||
expect(ActionMailer::Base.deliveries.count).to eq 1
|
expect(ActionMailer::Base.deliveries.count).to eq 1
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should not duplicate email message' do
|
it 'should not duplicate email message' do
|
||||||
post :create, @create_params.deep_merge(pull_request: {assignee_id: @project_admin.id})
|
post :create, create_params.deep_merge(pull_request: {assignee_id: project_admin.id})
|
||||||
expect(ActionMailer::Base.deliveries.count).to eq 3 # send to all project members
|
expect(ActionMailer::Base.deliveries.count).to eq 3 # send to all project members
|
||||||
expect(ActionMailer::Base.deliveries.map(&:to).uniq).to match_array(ActionMailer::Base.deliveries.map(&:to))
|
expect(ActionMailer::Base.deliveries.map(&:to).uniq).to match_array(ActionMailer::Base.deliveries.map(&:to))
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue