Class: CulpaHelpers::BrickCall

Inherits:
Object
  • Object
show all
Defined in:
lib/culpa/test_helpers.rb

Overview

Class used to mock a brick call

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(brick_name) ⇒ BrickCall

Returns a new instance of BrickCall.



24
25
26
27
28
# File 'lib/culpa/test_helpers.rb', line 24

def initialize(brick_name)
  @brick_name = brick_name.to_s
  @session = Session.new('InMemory', {'duration' => 600}, nil)
  @from_done = false
end

Instance Attribute Details

#from_doneObject (readonly)

Returns the value of attribute from_done.



22
23
24
# File 'lib/culpa/test_helpers.rb', line 22

def from_done
  @from_done
end

Instance Method Details

#callObject



48
49
50
51
52
53
54
55
56
57
58
# File 'lib/culpa/test_helpers.rb', line 48

def call
  return unless @from_done
  return @call_cache if @call_done
  @envelope ||= Culpa::Envelope.new({})
  @params ||= Culpa::EnvelopeRequest.new({})
  @action_const.new(@envelope, @params, @session).send(@brick_name)
  @call_done = true
  return @call_cache = { to_render: nil, envelope: @envelope }
rescue Action::RenderNow => renderer
  return @call_cache = { to_render: renderer.to_render, envelope: @envelope }
end

#from(action_const) ⇒ Object



30
31
32
33
34
# File 'lib/culpa/test_helpers.rb', line 30

def from(action_const)
  @from_done = true
  @action_const = action_const
  self
end

#with(opts) ⇒ Object



40
41
42
43
44
45
46
# File 'lib/culpa/test_helpers.rb', line 40

def with(opts)
  opts[:envelope] ||= {}
  @envelope = Culpa::Envelope.new(opts[:envelope])
  opts.delete(:envelope)
  @params = Culpa::EnvelopeRequest.new(opts)
  self
end

#with_session(hash) ⇒ Object



36
37
38
# File 'lib/culpa/test_helpers.rb', line 36

def with_session(hash)
  @session.merge!(hash)
end