Commit c8eb2a91 authored by Shinya Maeda's avatar Shinya Maeda

Fix spec. Revert update check.

parent 9b58b8e3
...@@ -136,6 +136,7 @@ module API ...@@ -136,6 +136,7 @@ module API
authorize_update_builds! authorize_update_builds!
build = find_build!(params[:job_id]) build = find_build!(params[:job_id])
authorize!(:update_build, build)
authorize!(:erase_build, build) authorize!(:erase_build, build)
return forbidden!('Job is not erasable!') unless build.erasable? return forbidden!('Job is not erasable!') unless build.erasable?
......
...@@ -169,6 +169,7 @@ module API ...@@ -169,6 +169,7 @@ module API
authorize_update_builds! authorize_update_builds!
build = get_build!(params[:build_id]) build = get_build!(params[:build_id])
authorize!(:update_build, build)
authorize!(:erase_build, build) authorize!(:erase_build, build)
return forbidden!('Build is not erasable!') unless build.erasable? return forbidden!('Build is not erasable!') unless build.erasable?
......
...@@ -270,6 +270,23 @@ describe Ci::Build do ...@@ -270,6 +270,23 @@ describe Ci::Build do
end end
end end
describe '#owned_by?' do
subject { build.owned_by?(user) }
context 'when user is owner' do
let(:build) { create(:ci_build, pipeline: pipeline, user: user) }
it { is_expected.to be_truthy }
end
context 'when user is not owner' do
let(:another_user) { create(:user) }
let(:build) { create(:ci_build, pipeline: pipeline, user: another_user) }
it { is_expected.to be_falsy }
end
end
describe '#detailed_status' do describe '#detailed_status' do
it 'returns a detailed status' do it 'returns a detailed status' do
expect(build.detailed_status(user)) expect(build.detailed_status(user))
......
...@@ -151,10 +151,9 @@ describe Ci::BuildPolicy do ...@@ -151,10 +151,9 @@ describe Ci::BuildPolicy do
end end
end end
# TODO: Finish spec
describe 'rules for erase build' do describe 'rules for erase build' do
let(:project) { create(:project, :repository) } let(:project) { create(:project, :repository) }
let(:another_user) { create(:user) } let(:build) { create(:ci_build, pipeline: pipeline, user: owner) }
context 'when developer created a build' do context 'when developer created a build' do
before do before do
...@@ -162,13 +161,13 @@ describe Ci::BuildPolicy do ...@@ -162,13 +161,13 @@ describe Ci::BuildPolicy do
end end
context 'when the build was created by the user' do context 'when the build was created by the user' do
let(:build) { create(:ci_build, user: user) } let(:owner) { user }
it { expect(policy).to be_allowed :erase_build } it { expect(policy).to be_allowed :erase_build }
end end
context 'when the build was created by others' do context 'when the build was created by others' do
let(:build) { create(:ci_build, user: another_user) } let(:owner) { create(:user) }
it { expect(policy).to be_disallowed :erase_build } it { expect(policy).to be_disallowed :erase_build }
end end
...@@ -180,13 +179,13 @@ describe Ci::BuildPolicy do ...@@ -180,13 +179,13 @@ describe Ci::BuildPolicy do
end end
context 'when the build was created by the user' do context 'when the build was created by the user' do
let(:build) { create(:ci_build, user: user) } let(:owner) { user }
it { expect(policy).to be_allowed :erase_build } it { expect(policy).to be_allowed :erase_build }
end end
context 'when the build was created by others' do context 'when the build was created by others' do
let(:build) { create(:ci_build, user: another_user) } let(:owner) { create(:user) }
it { expect(policy).to be_allowed :erase_build } it { expect(policy).to be_allowed :erase_build }
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment