Module: ExternalServices::RSpec::Helpers
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/rspec/helpers.rb
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
- #expect_api_action(params) ⇒ Object
- #expect_api_action_on_create(obj = nil) ⇒ Object
- #expect_api_action_on_destroy(obj = nil) ⇒ Object
- #expect_api_action_on_update(obj = nil) ⇒ Object
- #perform_unprocessed_actions ⇒ Object
- #remove_api_actions(api_name) ⇒ Object
- #unexpect_api_action(params) ⇒ Object
Instance Method Details
#expect_api_action(params) ⇒ Object
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/rspec/helpers.rb', line 112 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
100 101 102 |
# File 'lib/rspec/helpers.rb', line 100 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
108 109 110 |
# File 'lib/rspec/helpers.rb', line 108 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
104 105 106 |
# File 'lib/rspec/helpers.rb', line 104 def expect_api_action_on_update(obj = nil) expect_api_action(initiator: obj, method: @methods[:update]) end |
#perform_unprocessed_actions ⇒ Object
134 135 136 137 |
# File 'lib/rspec/helpers.rb', line 134 def perform_unprocessed_actions @action_class.unprocessed.each(&:execute!) @api_object.reload end |
#remove_api_actions(api_name) ⇒ Object
96 97 98 |
# File 'lib/rspec/helpers.rb', line 96 def remove_api_actions(api_name) "ExternalServices::ApiActions::#{api_name.to_s.camelize}".constantize.delete_all end |
#unexpect_api_action(params) ⇒ Object
130 131 132 |
# File 'lib/rspec/helpers.rb', line 130 def unexpect_api_action(params) expect_api_action(params.merge(expectation: false)) end |