diff options
author | Shinya Maeda <shinya@gitlab.com> | 2018-07-06 16:03:06 +0900 |
---|---|---|
committer | Shinya Maeda <shinya@gitlab.com> | 2018-07-06 16:03:06 +0900 |
commit | 9bdb4b179a515261875b7c201b4112bfb007436f (patch) | |
tree | 83497c3c8d5a9f9ecd6fa15ac283c2e3907e1744 /spec/models/ci | |
parent | 18238cac7444e0f8561015e9c16af5616eb0fae7 (diff) | |
download | gitlab-ce-9bdb4b179a515261875b7c201b4112bfb007436f.tar.gz |
Add spec
Diffstat (limited to 'spec/models/ci')
-rw-r--r-- | spec/models/ci/build_spec.rb | 44 |
1 files changed, 38 insertions, 6 deletions
diff --git a/spec/models/ci/build_spec.rb b/spec/models/ci/build_spec.rb index 0da1234ee3b..090ca159e08 100644 --- a/spec/models/ci/build_spec.rb +++ b/spec/models/ci/build_spec.rb @@ -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 |