Class: ApiMaker::CommandSpecHelper
- Inherits:
-
Object
- Object
- ApiMaker::CommandSpecHelper
- Defined in:
- lib/api_maker/command_spec_helper.rb
Defined Under Namespace
Classes: AddedCommand
Instance Attribute Summary collapse
-
#collection ⇒ Object
readonly
Returns the value of attribute collection.
-
#command_class ⇒ Object
readonly
Returns the value of attribute command_class.
-
#commands ⇒ Object
readonly
Returns the value of attribute commands.
Instance Method Summary collapse
- #add_command(args: {}, primary_key: nil) ⇒ Object
- #command ⇒ Object
- #controller ⇒ Object
- #execute! ⇒ Object
-
#initialize(command:, collection: nil, controller: nil) ⇒ CommandSpecHelper
constructor
A new instance of CommandSpecHelper.
- #response ⇒ Object
Constructor Details
#initialize(command:, collection: nil, controller: nil) ⇒ CommandSpecHelper
Returns a new instance of CommandSpecHelper.
4 5 6 7 8 9 |
# File 'lib/api_maker/command_spec_helper.rb', line 4 def initialize(command:, collection: nil, controller: nil) @collection = collection @command_class = command @commands = {} @controller = controller || double end |
Instance Attribute Details
#collection ⇒ Object (readonly)
Returns the value of attribute collection.
2 3 4 |
# File 'lib/api_maker/command_spec_helper.rb', line 2 def collection @collection end |
#command_class ⇒ Object (readonly)
Returns the value of attribute command_class.
2 3 4 |
# File 'lib/api_maker/command_spec_helper.rb', line 2 def command_class @command_class end |
#commands ⇒ Object (readonly)
Returns the value of attribute commands.
2 3 4 |
# File 'lib/api_maker/command_spec_helper.rb', line 2 def commands @commands end |
Instance Method Details
#add_command(args: {}, primary_key: nil) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/api_maker/command_spec_helper.rb', line 11 def add_command(args: {}, primary_key: nil) id = commands.length + 1 commands[id] = { args: ActionController::Parameters.new(args), id: id, primary_key: primary_key } AddedCommand.new(id, response) end |
#command ⇒ Object
23 24 25 26 27 28 29 30 31 32 |
# File 'lib/api_maker/command_spec_helper.rb', line 23 def command @command ||= command_class.new( ability: controller.__send__(:current_ability), args: controller.__send__(:api_maker_args), collection: collection, commands: commands, command_response: response, controller: controller ) end |
#controller ⇒ Object
34 35 36 |
# File 'lib/api_maker/command_spec_helper.rb', line 34 def controller @controller ||= double(current_user: user) end |
#execute! ⇒ Object
38 39 40 41 |
# File 'lib/api_maker/command_spec_helper.rb', line 38 def execute! command.execute! ServicePattern::Response.new(success: true) end |
#response ⇒ Object
43 44 45 |
# File 'lib/api_maker/command_spec_helper.rb', line 43 def response @response ||= ApiMaker::CommandResponse.new(controller: @controller) end |