Module: ExternalServices::RSpec::Helpers

Extended by:
ActiveSupport::Concern
Defined in:
lib/rspec/helpers.rb

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#expect_api_action(params) ⇒ Object



110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# 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) ⇒ Object



98
99
100
# 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) ⇒ Object



106
107
108
# 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) ⇒ Object



102
103
104
# 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_actionsObject



132
133
134
135
# 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) ⇒ Object



94
95
96
# 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) ⇒ Object



128
129
130
# File 'lib/rspec/helpers.rb', line 128

def unexpect_api_action(params)
  expect_api_action(params.merge(expectation: false))
end