Commit 9bdb4b17 authored by Shinya Maeda's avatar Shinya Maeda

Add spec

parent 18238cac
......@@ -514,6 +514,22 @@ describe Ci::Build do
end
end
describe '#has_old_trace?' do
subject { build.has_old_trace? }
context 'when old trace exists' do
before do
build.update_column(:trace, 'old trace')
end
it { is_expected.to be_truthy }
end
context 'when old trace does not exist' do
it { is_expected.to be_falsy }
end
end
describe '#trace=' do
it "expect to fail trace=" do
expect { build.trace = "new" }.to raise_error(NotImplementedError)
......@@ -533,16 +549,32 @@ describe Ci::Build do
end
describe '#erase_old_trace!' do
subject { build.send(:read_attribute, :trace) }
subject { build.erase_old_trace! }
before do
build.send(:write_attribute, :trace, 'old trace')
context 'when old trace exists' do
before do
build.update_column(:trace, 'old trace')
end
it "erases old trace" do
subject
expect(build.old_trace).to be_nil
end
it "executes UPDATE query" do
recorded = ActiveRecord::QueryRecorder.new { subject }
expect(recorded.log.select { |l| l.match?(/UPDATE.*ci_builds/) }.count).to eq(1)
end
end
it "expect to receive data from database" do
build.erase_old_trace!
context 'when old trace does not exist' do
it 'does not execute UPDATE query' do
recorded = ActiveRecord::QueryRecorder.new { subject }
is_expected.to be_nil
expect(recorded.log.select { |l| l.match?(/UPDATE.*ci_builds/) }.count).to eq(0)
end
end
end
......
......@@ -589,6 +589,55 @@ shared_examples_for 'trace with disabled live trace feature' do
end
end
end
describe '#erase!' do
subject { trace.erase! }
context 'when it is a live trace' do
context 'when trace is stored in database' do
let(:build) { create(:ci_build) }
before do
build.update_column(:trace, 'sample trace')
end
it { expect(trace.raw).not_to be_nil }
it "removes trace" do
subject
expect(trace.raw).to be_nil
end
end
context 'when trace is stored in file storage' do
let(:build) { create(:ci_build, :trace_live) }
it { expect(trace.raw).not_to be_nil }
it "removes trace" do
subject
expect(trace.raw).to be_nil
end
end
end
context 'when it is an archived trace' do
let(:build) { create(:ci_build, :trace_artifact) }
it "has trace at first" do
expect(trace.raw).not_to be_nil
end
it "removes trace" do
subject
build.reload
expect(trace.raw).to be_nil
end
end
end
end
shared_examples_for 'trace with enabled live trace feature' do
......@@ -776,4 +825,35 @@ shared_examples_for 'trace with enabled live trace feature' do
end
end
end
describe '#erase!' do
subject { trace.erase! }
context 'when it is a live trace' do
let(:build) { create(:ci_build, :trace_live) }
it { expect(trace.raw).not_to be_nil }
it "removes trace" do
subject
expect(trace.raw).to be_nil
end
end
context 'when it is an archived trace' do
let(:build) { create(:ci_build, :trace_artifact) }
it "has trace at first" do
expect(trace.raw).not_to be_nil
end
it "removes trace" do
subject
build.reload
expect(trace.raw).to be_nil
end
end
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