Commit 4ab3f265 authored by Sean Arnold's avatar Sean Arnold

Update specs to match finder changes

Use attr_writer
parent 14d1bf41
......@@ -44,6 +44,7 @@ class IssuableFinder
NEGATABLE_PARAMS_HELPER_KEYS = %i[project_id scope status include_subgroups].freeze
attr_accessor :current_user, :params
attr_writer :parent
delegate(*%i[assignee milestones], to: :params)
......@@ -204,10 +205,6 @@ class IssuableFinder
end
end
def parent=(obj)
@parent = obj
end
def parent_param=(obj)
@parent = obj
params[parent_param] = parent if parent
......
......@@ -6,9 +6,44 @@ RSpec.describe Gitlab::Graphql::Loaders::IssuableLoader do
subject { described_class.new(parent, finder) }
let(:params) { HashWithIndifferentAccess.new }
let(:finder_params) { finder.params.to_h.with_indifferent_access }
# 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
def execute
params[:project_id].issues.where(iid: params[:iids])
end
def parent_param=(obj)
@parent = obj
params[parent_param] = parent if parent
end
def parent_param
case parent
when Project
:project_id
when Group
:group_id
else
raise "Unexpected parent: #{parent.class}"
end
end
end
end
describe '#find_all' do
let(:finder) { double(:finder, params: params, execute: %i[x y z]) }
let(:finder) { issuable_finder(params: params, result: [:x, :y, :z]) }
where(:factory, :param_name) do
%i[project group].map { |thing| [thing, :"#{thing}_id"] }
......@@ -19,7 +54,7 @@ RSpec.describe Gitlab::Graphql::Loaders::IssuableLoader do
it 'assignes the parent parameter, and batching_find_alls the finder' do
expect(subject.find_all).to contain_exactly(:x, :y, :z)
expect(params).to include(param_name => parent)
expect(finder_params).to include(param_name => parent)
end
end
......@@ -34,12 +69,12 @@ RSpec.describe Gitlab::Graphql::Loaders::IssuableLoader do
describe '#batching_find_all' do
context 'the finder params are anything other than [iids]' do
let(:finder) { double(:finder, params: params, execute: [:foo]) }
let(:finder) { issuable_finder(params: params, result: [:foo]) }
let(:parent) { build_stubbed(:project) }
it 'batching_find_alls the finder, setting the correct parent parameter' do
expect(subject.batching_find_all).to eq([:foo])
expect(params[:project_id]).to eq(parent)
expect(finder_params[:project_id]).to eq(parent)
end
it 'allows a post-process block' do
......@@ -48,23 +83,6 @@ RSpec.describe Gitlab::Graphql::Loaders::IssuableLoader do
end
context 'the finder params are exactly [iids]' 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
def initialize(user, args)
@current_user = user
@params = HashWithIndifferentAccess.new(args.to_h)
end
def execute
params[:project_id].issues.where(iid: params[:iids])
end
end
end
it 'batches requests' do
issue_a = create(:issue)
issue_b = create(:issue)
......@@ -93,4 +111,13 @@ RSpec.describe Gitlab::Graphql::Loaders::IssuableLoader do
end
end
end
private
def issuable_finder(user: double(:user), params: {}, result: nil)
new_finder = finder_class.new(user, params)
allow(new_finder).to receive(:execute).and_return(result) if result
new_finder
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