2019-11-18 03:06:28 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-10-13 16:50:36 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 18:09:03 +00:00
|
|
|
RSpec.describe Gitlab::GithubImport::PageCounter, :clean_gitlab_redis_cache do
|
2017-10-13 16:50:36 +00:00
|
|
|
let(:project) { double(:project, id: 1) }
|
|
|
|
let(:counter) { described_class.new(project, :issues) }
|
|
|
|
|
|
|
|
describe '#initialize' do
|
|
|
|
it 'sets the initial page number to 1 when no value is cached' do
|
|
|
|
expect(counter.current).to eq(1)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'sets the initial page number to the cached value when one is present' do
|
2020-03-14 00:09:30 +00:00
|
|
|
Gitlab::Cache::Import::Caching.write(counter.cache_key, 2)
|
2017-10-13 16:50:36 +00:00
|
|
|
|
|
|
|
expect(described_class.new(project, :issues).current).to eq(2)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#set' do
|
|
|
|
it 'overwrites the page number when the given number is greater than the current number' do
|
|
|
|
counter.set(4)
|
|
|
|
expect(counter.current).to eq(4)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not overwrite the page number when the given number is lower than the current number' do
|
|
|
|
counter.set(2)
|
|
|
|
counter.set(1)
|
|
|
|
|
|
|
|
expect(counter.current).to eq(2)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|