summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorAlexander Kutelev <alexander@kutelev.ru>2019-01-04 12:54:45 +0700
committerAlexander Kutelev <alexander.kutelev@neulion.com>2019-01-04 13:24:42 +0700
commitbcaf444b2107408b1eaf66bfc0d869b7b87b35f9 (patch)
tree3af6bf54ea79b85bd5d6846e03abcecfe60c7352 /spec
parentd56124b5e16e15afd830a1bdc8c34a4a57d898d8 (diff)
downloadgitlab-ce-bcaf444b2107408b1eaf66bfc0d869b7b87b35f9.tar.gz
Take contacted_at value from the DB when it is about to be displayed in the Web interface with sorting enabled.
Diffstat (limited to 'spec')
-rw-r--r--spec/helpers/runners_helper_spec.rb36
-rw-r--r--spec/models/ci/runner_spec.rb9
2 files changed, 45 insertions, 0 deletions
diff --git a/spec/helpers/runners_helper_spec.rb b/spec/helpers/runners_helper_spec.rb
index a4a483e68a8..bf00841fcb6 100644
--- a/spec/helpers/runners_helper_spec.rb
+++ b/spec/helpers/runners_helper_spec.rb
@@ -15,4 +15,40 @@ describe RunnersHelper do
runner = FactoryBot.build(:ci_runner, contacted_at: 1.second.ago, active: true)
expect(runner_status_icon(runner)).to include("Runner is online")
end
+
+ describe '#runner_contacted_at' do
+ let(:contacted_at_stored) { 1.hour.ago.change(usec: 0) }
+ let(:contacted_at_cached) { 1.second.ago.change(usec: 0) }
+ let(:runner) { create(:ci_runner, contacted_at: contacted_at_stored) }
+
+ before do
+ runner.cache_attributes(contacted_at: contacted_at_cached)
+ end
+
+ context 'without sorting' do
+ it 'returns cached value' do
+ expect(runner_contacted_at(runner)).to eq(contacted_at_cached)
+ end
+ end
+
+ context 'with sorting set to created_date' do
+ before do
+ controller.params[:sort] = 'created_date'
+ end
+
+ it 'returns cached value' do
+ expect(runner_contacted_at(runner)).to eq(contacted_at_cached)
+ end
+ end
+
+ context 'with sorting set to contacted_asc' do
+ before do
+ controller.params[:sort] = 'contacted_asc'
+ end
+
+ it 'returns stored value' do
+ expect(runner_contacted_at(runner)).to eq(contacted_at_stored)
+ end
+ end
+ end
end
diff --git a/spec/models/ci/runner_spec.rb b/spec/models/ci/runner_spec.rb
index ad79f8d4ce0..eb2daed7f32 100644
--- a/spec/models/ci/runner_spec.rb
+++ b/spec/models/ci/runner_spec.rb
@@ -817,4 +817,13 @@ describe Ci::Runner do
expect(runners).to eq([runner2, runner1])
end
end
+
+ describe '#uncached_contacted_at' do
+ let(:contacted_at_stored) { 1.hour.ago.change(usec: 0) }
+ let(:runner) { create(:ci_runner, contacted_at: contacted_at_stored) }
+
+ subject { runner.uncached_contacted_at }
+
+ it { is_expected.to eq(contacted_at_stored) }
+ end
end