Module: HammerCLIForeman::Testing::APIExpectations

Defined in:
lib/hammer_cli_foreman/testing/api_expectations.rb

Defined Under Namespace

Modules: ExpectationExtensions Classes: APICallMatcher, APIExpectationsDecorator, FakeApiConnection, TestAuthenticator

Instance Method Summary collapse

Instance Method Details

#api_connection(options = {}, version = '1.15') ⇒ Object



142
143
144
145
146
147
148
149
150
# File 'lib/hammer_cli_foreman/testing/api_expectations.rb', line 142

def api_connection(options={}, version = '1.15')
  FakeApiConnection.new({
    :uri => 'https://test.org',
    :apidoc_cache_dir => "test/data/#{version}",
    :apidoc_cache_name => 'foreman_api',
    :authenticator => TestAuthenticator.new('admin', 'changeme'),
    :dry_run => true
  }.merge(options))
end

#api_expects(resource = nil, action = nil, note = nil, &block) ⇒ Object



152
153
154
# File 'lib/hammer_cli_foreman/testing/api_expectations.rb', line 152

def api_expects(resource=nil, action=nil, note=nil, &block)
  APIExpectationsDecorator.new.expects_call(resource, action, note, &block)
end

#api_expects_no_callObject



156
157
158
# File 'lib/hammer_cli_foreman/testing/api_expectations.rb', line 156

def api_expects_no_call
  APIExpectationsDecorator.new.expects_no_call
end

#api_expects_search(resource = nil, search_options = {}, note = nil) ⇒ Object



160
161
162
# File 'lib/hammer_cli_foreman/testing/api_expectations.rb', line 160

def api_expects_search(resource=nil, search_options={}, note=nil)
  APIExpectationsDecorator.new.expects_search(resource, search_options, note)
end

#index_response(items, options = {}) ⇒ Object



164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
# File 'lib/hammer_cli_foreman/testing/api_expectations.rb', line 164

def index_response(items, options={})
  cnt = items.length
  {
    "total" => options.fetch(:total, cnt),
    "subtotal" => options.fetch(:subtotal, cnt),
    "page" => options.fetch(:page, 1),
    "per_page" => options.fetch(:per_page, cnt),
    "search" => "",
    "sort" => {
      "by" => nil,
      "order" => nil
    },
    "results" => items
  }
end