Commit b99bc6d3 authored by James Lopez's avatar James Lopez

add group finder spec and logic

parent e0c06470
module Gitlab
module ImportExport
class GroupProjectFinder
def self.find(*args)
new(*args).find
end
def initialize(klass, attributes)
@klass = klass
@attributes = attributes
@group_id = @attributes['group_id']
@project_id = @attributes['project_id']
end
def find
@klass.where(where_clause)
end
private
def where_clause
@attributes.except('group_id', 'project_id').map do |key, value|
table[key].eq(value).and(table[:group_id].eq(@group_id))
.or(table[key].eq(value).and(table[:project_id].eq(@project_id)))
end.reduce(:or)
end
def table
@table ||= @klass.arel_table
end
end
end
end
require 'spec_helper'
describe Gitlab::ImportExport::GroupProjectFinder do
let(:project) do
create(:project,
:builds_disabled,
:issues_disabled,
name: 'project',
path: 'project',
group: create(:group))
end
it 'finds the right group label' do
group_label = create(:group_label, 'name': 'group label', 'group': project.group)
expect(described_class.find(Label,
title: 'group label',
'project_id': project.id,
'group_id': project.group.id)).to eq([group_label])
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