module ExternalServices::RSpec::Helpers

Public Instance Methods

expect_api_action(params) click to toggle source
# File lib/rspec/helpers.rb, line 110
def expect_api_action(params)
  params[:initiator] ||= @api_object
  expectation = params.delete(:expectation)
  expectation = true if expectation.nil?
  count = params.delete(:count)
  data = params.delete(:data) || {}

  actions = @action_class.where(params).select do |a|
    data.reject { |k, v| a.data[k.to_s] == v }.empty?
  end

  if count
    expect(actions.count).send expectation ? 'to' : 'not_to', eq(count)
  else
    expect(actions.any?).to eq(expectation)
  end
end
expect_api_action_on_create(obj = nil) click to toggle source
# File lib/rspec/helpers.rb, line 98
def expect_api_action_on_create(obj = nil)
  expect_api_action(initiator: obj, method: @methods[:create])
end
expect_api_action_on_destroy(obj = nil) click to toggle source
# File lib/rspec/helpers.rb, line 106
def expect_api_action_on_destroy(obj = nil)
  expect_api_action(initiator: obj, method: @methods[:destroy])
end
expect_api_action_on_update(obj = nil) click to toggle source
# File lib/rspec/helpers.rb, line 102
def expect_api_action_on_update(obj = nil)
  expect_api_action(initiator: obj, method: @methods[:update])
end
perform_unprocessed_actions() click to toggle source
# File lib/rspec/helpers.rb, line 132
def perform_unprocessed_actions
  @action_class.unprocessed.each(&:execute!)
  @api_object.reload
end
remove_api_actions(api_name) click to toggle source
# File lib/rspec/helpers.rb, line 94
def remove_api_actions(api_name)
  "ExternalServices::ApiActions::#{api_name.to_s.camelize}".constantize.delete_all
end
unexpect_api_action(params) click to toggle source
# File lib/rspec/helpers.rb, line 128
def unexpect_api_action(params)
  expect_api_action(params.merge(expectation: false))
end