Class: ApiMaker::SpecHelper::ExecuteMemberCommand

Inherits:
ApplicationService
  • Object
show all
Includes:
RSpec::Mocks::ExampleMethods
Defined in:
lib/api_maker/spec_helper/execute_member_command.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from ApplicationService

#api_maker_json

Constructor Details

#initialize(ability: nil, api_maker_args: nil, collection: nil, command:, fake_controller: nil, model:, args: {}) ⇒ ExecuteMemberCommand

Returns a new instance of ExecuteMemberCommand.



6
7
8
9
10
11
12
13
14
# File 'lib/api_maker/spec_helper/execute_member_command.rb', line 6

def initialize(ability: nil, api_maker_args: nil, collection: nil, command:, fake_controller: nil, model:, args: {})
  @ability = ability
  @api_maker_args = api_maker_args
  @args = args
  @collection = collection
  @command = command
  @fake_controller = fake_controller
  @model = model
end

Instance Attribute Details

#api_maker_argsObject (readonly)

Returns the value of attribute api_maker_args.



4
5
6
# File 'lib/api_maker/spec_helper/execute_member_command.rb', line 4

def api_maker_args
  @api_maker_args
end

#argsObject (readonly)

Returns the value of attribute args.



4
5
6
# File 'lib/api_maker/spec_helper/execute_member_command.rb', line 4

def args
  @args
end

#commandObject (readonly)

Returns the value of attribute command.



4
5
6
# File 'lib/api_maker/spec_helper/execute_member_command.rb', line 4

def command
  @command
end

#modelObject (readonly)

Returns the value of attribute model.



4
5
6
# File 'lib/api_maker/spec_helper/execute_member_command.rb', line 4

def model
  @model
end

Instance Method Details

#abilityObject



22
23
24
# File 'lib/api_maker/spec_helper/execute_member_command.rb', line 22

def ability
  @ability ||= ApiMaker::Ability.new(api_maker_args: api_maker_args)
end

#collectionObject



26
27
28
# File 'lib/api_maker/spec_helper/execute_member_command.rb', line 26

def collection
  @collection ||= model.class.where(id: model.id)
end

#fake_controllerObject



30
31
32
33
34
35
36
# File 'lib/api_maker/spec_helper/execute_member_command.rb', line 30

def fake_controller
  @fake_controller ||= instance_double(
    ApiMaker::BaseController,
    api_maker_args: api_maker_args,
    current_ability: ability
  )
end

#helperObject



38
39
40
41
42
43
44
# File 'lib/api_maker/spec_helper/execute_member_command.rb', line 38

def helper
  @helper ||= ApiMaker::CommandSpecHelper.new(
    collection: collection,
    command: command,
    controller: fake_controller
  )
end

#helper_commandObject



46
47
48
49
50
51
# File 'lib/api_maker/spec_helper/execute_member_command.rb', line 46

def helper_command
  @helper_command ||= helper.add_command(
    primary_key: model.id,
    args: args
  )
end

#performObject



16
17
18
19
20
# File 'lib/api_maker/spec_helper/execute_member_command.rb', line 16

def perform
  helper_command
  helper.execute!
  succeed! helper_command.result
end