Commit b02e0d5d authored by Alex Kalderimis's avatar Alex Kalderimis

Add by_sha scope, for use in version finder

This adds a new scope `by_sha` to DesignManagement::Version, and allows
it to be used in the version finder.
parent b885e992
......@@ -24,6 +24,7 @@ module DesignManagement
items = design_or_collection.versions
items = by_earlier_or_equal_to(items)
items = by_sha(items)
items.ordered
end
......@@ -34,5 +35,11 @@ module DesignManagement
items.earlier_or_equal_to(params[:earlier_or_equal_to])
end
def by_sha(items)
return items unless params[:sha]
items.by_sha(params[:sha])
end
end
end
......@@ -55,6 +55,7 @@ module DesignManagement
scope :earlier_or_equal_to, -> (version) { where('id <= ?', version) }
scope :ordered, -> { order(id: :desc) }
scope :for_issue, -> (issue) { where(issue: issue) }
scope :by_sha, -> (sha) { where(sha: sha) }
# This is the one true way to create a Version.
#
......
......@@ -79,6 +79,20 @@ describe DesignManagement::VersionsFinder do
it { is_expected.to contain_exactly(version_1, version_2) }
end
end
describe 'returning versions by SHA' do
context 'when argument is the first version' do
let(:params) { { sha: version_1.sha } }
it { is_expected.to contain_exactly(version_1) }
end
context 'when argument is the second version' do
let(:params) { { sha: version_2.sha } }
it { is_expected.to contain_exactly(version_2) }
end
end
end
end
end
......
......@@ -60,6 +60,14 @@ describe DesignManagement::Version do
end
end
end
describe '.by_sha' do
it 'can find versions by sha' do
[version_1, version_2].each do |version|
expect(described_class.by_sha(version.sha)).to contain_exactly(version)
end
end
end
end
describe ".create_for_designs" do
......
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