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.



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

def initialize(brick_name)
  @brick_name = brick_name.to_s
  @from_done = false
end

Instance Attribute Details

#from_doneObject (readonly)

Returns the value of attribute from_done.



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

def from_done
  @from_done
end

Instance Method Details

#callObject



42
43
44
45
46
47
48
49
50
51
52
# File 'lib/culpa/test_helpers.rb', line 42

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).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



28
29
30
31
32
# File 'lib/culpa/test_helpers.rb', line 28

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

#with(opts) ⇒ Object



34
35
36
37
38
39
40
# File 'lib/culpa/test_helpers.rb', line 34

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