Class: ApiMaker::SpecHelper::ExecuteCollectionCommand

Inherits:
ApplicationService
  • Object
show all
Includes:
RSpec::Mocks::ExampleMethods
Defined in:
lib/api_maker/spec_helper/execute_collection_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: {}, args: {}, command:, fake_controller: nil, model_class:) ⇒ ExecuteCollectionCommand

Returns a new instance of ExecuteCollectionCommand.



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

def initialize(ability: nil, api_maker_args: {}, args: {}, command:, fake_controller: nil, model_class:)
  @ability = ability
  @api_maker_args = api_maker_args
  @args = args
  @command = command
  @fake_controller = fake_controller
  @model_class = model_class
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_collection_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_collection_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_collection_command.rb', line 4

def command
  @command
end

#model_classObject (readonly)

Returns the value of attribute model_class.



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

def model_class
  @model_class
end

Instance Method Details

#abilityObject



21
22
23
# File 'lib/api_maker/spec_helper/execute_collection_command.rb', line 21

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

#fake_controllerObject



25
26
27
28
29
30
31
# File 'lib/api_maker/spec_helper/execute_collection_command.rb', line 25

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

#helperObject



33
34
35
36
37
38
39
# File 'lib/api_maker/spec_helper/execute_collection_command.rb', line 33

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

#helper_commandObject



41
42
43
44
45
# File 'lib/api_maker/spec_helper/execute_collection_command.rb', line 41

def helper_command
  @helper_command ||= helper.add_command(
    args: args
  )
end

#performObject



15
16
17
18
19
# File 'lib/api_maker/spec_helper/execute_collection_command.rb', line 15

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