Commit c69dc778 authored by Sean Arnold's avatar Sean Arnold

Use inheritance for stubbed class

- Add specs for setting parent in issues finder
parent 5ad098c9
......@@ -3,6 +3,7 @@
require 'spec_helper'
RSpec.describe IssuesFinder do
using RSpec::Parameterized::TableSyntax
include_context 'IssuesFinder context'
describe '#execute' do
......@@ -1022,4 +1023,33 @@ RSpec.describe IssuesFinder do
end
end
end
describe '#parent_param=' do
let(:finder) { described_class.new(nil) }
subject { finder.parent_param = obj }
where(:klass, :param) do
:Project | :project_id
:Group | :group_id
end
with_them do
let(:obj) { Object.const_get(klass, false).new }
it 'sets the params' do
subject
expect(finder.params[param]).to eq(obj)
end
end
context 'unexpected parent' do
let(:obj) { MergeRequest.new }
it 'raises an error' do
expect { subject }.to raise_error('Unexpected parent: MergeRequest')
end
end
end
end
......@@ -11,33 +11,15 @@ RSpec.describe Gitlab::Graphql::Loaders::IssuableLoader do
# Dumb finder class, that only implements what we need, and has
# predictable query counts.
let(:finder_class) do
Class.new do
attr_reader :current_user, :params
attr_accessor :parent
def initialize(user, args)
@current_user = user
@params = HashWithIndifferentAccess.new(args.to_h)
end
Class.new(IssuesFinder) do
def execute
params[:project_id].issues.where(iid: params[:iids])
end
def parent_param=(obj)
@parent = obj
params[parent_param] = parent if parent
end
private
def parent_param
case parent
when Project
:project_id
when Group
:group_id
else
raise "Unexpected parent: #{parent.class}"
end
def params_class
IssuesFinder::Params
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