Commit ceb41f2e authored by Alex Kalderimis's avatar Alex Kalderimis

Add allow version finder to search by ID

This has the version finder use the `id_in` scope to query for versions
by ID.
parent d141b1e4
......@@ -11,6 +11,12 @@ module DesignManagement
#
# The object will have `#versions` called on it to set up the
# initial scope of the versions.
#
# valid params:
# - earlier_or_equal_to: Version
# - sha: String
# - version_id: Integer
#
def initialize(design_or_collection, current_user, params = {})
@design_or_collection = design_or_collection
@current_user = current_user
......@@ -25,6 +31,7 @@ module DesignManagement
items = design_or_collection.versions
items = by_earlier_or_equal_to(items)
items = by_sha(items)
items = by_version_id(items)
items.ordered
end
......@@ -36,6 +43,12 @@ module DesignManagement
items.earlier_or_equal_to(params[:earlier_or_equal_to])
end
def by_version_id(items)
return items unless params[:version_id]
items.id_in(params[:version_id])
end
def by_sha(items)
return items unless params[:sha]
......
......@@ -15,7 +15,9 @@ describe DesignManagement::VersionsFinder do
let(:design_or_collection) { issue.design_collection }
let(:params) { {} }
subject(:versions) { described_class.new(design_or_collection, user, params).execute }
let(:finder) { described_class.new(design_or_collection, user, params) }
subject(:versions) { finder.execute }
describe '#execute' do
shared_examples 'returns no results' do
......@@ -93,6 +95,34 @@ describe DesignManagement::VersionsFinder do
it { is_expected.to contain_exactly(version_2) }
end
end
describe 'returning versions by ID' do
context 'when argument is the first version' do
let(:params) { { version_id: version_1.id } }
it { is_expected.to contain_exactly(version_1) }
end
context 'when argument is the second version' do
let(:params) { { version_id: version_2.id } }
it { is_expected.to contain_exactly(version_2) }
end
end
describe 'mixing id and sha' do
context 'when arguments are consistent' do
let(:params) { { version_id: version_1.id, sha: version_1.sha } }
it { is_expected.to contain_exactly(version_1) }
end
context 'when arguments are in-consistent' do
let(:params) { { version_id: version_1.id, sha: version_2.sha } }
it { is_expected.to be_empty }
end
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