Skip to content

Commit

Permalink
Simplify test code by using to_params
Browse files Browse the repository at this point in the history
  • Loading branch information
lagartoflojo committed May 19, 2015
1 parent 3a756dc commit 63efcc3
Showing 1 changed file with 3 additions and 16 deletions.
19 changes: 3 additions & 16 deletions spec/connect/api_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -218,22 +218,12 @@

let(:api_endpoint) { '/connect/systems/products' }
let(:system_auth) { 'basic_auth_mock' }

let(:product) { Remote::Product.new(:identifier => 'SLES', :version => '12', :arch => 'x86_64') }

let(:payload) do
{
:identifier => 'SLES',
:version => '12',
:arch => 'x86_64',
:release_type => nil
}
end

it 'calls ConnectAPI with basic auth and params and receives a JSON in return' do
stub_upgrade_call
Connection.any_instance.should_receive(:put)
.with(api_endpoint, :auth => system_auth, :params => payload)
.with(api_endpoint, :auth => system_auth, :params => product.to_params)
.and_call_original
response = subject.new(client).upgrade_product(system_auth, product)
response.body['sources'].keys.first.should include('SUSE')
Expand All @@ -248,13 +238,12 @@
end

let(:product) { Remote::Product.new(:identifier => 'rodent', :version => 'good', :arch => 'z42', :release_type => 'foo') }
let(:query) { { :identifier => product.identifier, :version => product.version, :arch => product.arch, :release_type => 'foo' } }

it 'is authenticated via basic auth' do
payload = [
'/connect/systems/products',
:auth => 'Basic: encodedgibberish',
:params => query
:params => product.to_params
]
Connection.any_instance.should_receive(:get)
.with(*payload)
Expand Down Expand Up @@ -287,9 +276,7 @@
]
end

let(:query) do
{ installed_products: products.map(&:to_params) }
end
let(:query) { { installed_products: products.map(&:to_params) } }

it 'is authenticated via basic auth' do
payload = [
Expand Down

0 comments on commit 63efcc3

Please sign in to comment.