Skip to content

Commit

Permalink
finding domain by uuid via account
Browse files Browse the repository at this point in the history
  • Loading branch information
Celestino Gomes committed Sep 18, 2013
1 parent 74321de commit bec5624
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
2 changes: 2 additions & 0 deletions lib/charging/domain.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ def self.find_by_uuid(account, uuid)

response = get_account_domain(account, uuid)

raise Http::LastResponseError.new(response) if response.code != 200

load_persisted_domain(MultiJson.decode(response.body), response, account)
rescue ::RestClient::Exception => exception
raise Http::LastResponseError.new(exception.response)
end
Expand Down
17 changes: 15 additions & 2 deletions spec/charging/domain_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
let(:account) { double('ServiceAccount', application_token: 'AwdhihciTgORGUjnkuk1vg==') }
let(:uuid) { '154932d8-66b8-4e6b-82f5-ebb1d32fe85d' }

context 'for new domain' do
context 'for new domain instance' do
let(:response_mock) { double(:response) }

subject do
Expand Down Expand Up @@ -100,7 +100,20 @@
end
end

xit 'should instanciate a domain' do
it 'should raise if not response to success (200)' do
response_mock = double('AcceptedResponse', code: 202, to_s: 'AcceptedResponse')

described_class
.should_receive(:get_account_domain)
.with(account, uuid)
.and_return(response_mock)

expect {
described_class.find_by_uuid(account, uuid)
}.to raise_error Charging::Http::LastResponseError, 'AcceptedResponse'
end

it 'should instanciate a domain' do
expect(result).to be_an_instance_of(Charging::Domain)
end
end
Expand Down

0 comments on commit bec5624

Please sign in to comment.