class Object

Public Instance Methods

graphiti_context() click to toggle source
# File lib/graphiti_spec_helpers/rspec.rb, line 20
def graphiti_context
  @graphiti_context ||= begin
    ctx = OpenStruct.new
    ctx.current_user = current_user if respond_to?(:current_user)
    ctx.params = params
    ctx
  end
end
mock_api(url, json, call_count = 1) click to toggle source
# File lib/graphiti_spec_helpers/rspec.rb, line 65
def mock_api(url, json, call_count = 1)
  api_response = double(body: json.to_json)
  expect(Faraday).to receive(:get)
    .with(url, anything, anything)
    .exactly(call_count).times
    .and_return(api_response)
end
proxy() click to toggle source
# File lib/graphiti_spec_helpers/rspec.rb, line 40
def proxy
  @proxy ||= begin
    args = [params]
    args << base_scope if defined?(base_scope)
    resource.all(*args)
  end
end
records() click to toggle source
# File lib/graphiti_spec_helpers/rspec.rb, line 48
def records
  proxy.data
end
render(runtime_options = {}) click to toggle source

If you need to set context:

Graphiti.with_context my_context, {} do

render

end

# File lib/graphiti_spec_helpers/rspec.rb, line 34
def render(runtime_options = {})
  json = proxy.to_jsonapi(runtime_options)
  response.body = json
  json
end
response() click to toggle source
# File lib/graphiti_spec_helpers/rspec.rb, line 52
def response
  @response ||= OpenStruct.new
end