Created
February 15, 2014 00:17
-
-
Save zaneclaes/9012345 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def self.get_by_id(id, current_user) | |
binding.pry # ID is 1 | |
begin | |
trip_invoice = TripInvoice.find(id) | |
rescue | |
raise ServiceModelBase::RecordNotFoundError | |
end | |
raise ServiceModelBase::NotAuthorizedError unless self.has_access?(trip_invoice, current_user) | |
self.new(trip_invoice, current_user) | |
end | |
// And the spec... | |
require 'spec_helper' | |
describe Api::V2::V2BaseController do | |
include_context 'for requests to api.airbnb.com' | |
describe 'logged in users' do | |
let(:user) { FactoryGirl.create(:user) } | |
let(:reservation) { FactoryGirl.create(:reservation2, :new, :guest => user) } | |
let(:trip_invoice) { FactoryGirl.create(:trip_invoice) } | |
before(:each) do | |
@oauth_client_id, @oauth_token = oauth2_login_as(user) | |
@params = { | |
:api_version => 'v2', | |
:oauth_token => @oauth_token, | |
:api_key => @oauth_client_id, | |
} | |
end | |
describe '#get' do | |
context 'invoice found' do | |
it 'returns an invoice' do | |
pp trip_invoice | |
get :show, @params.merge!(:id => trip_invoice.id, :resource => 'trip_invoices') | |
pp response.body | |
pp @trip_invoice | |
response.ok?.should be_true | |
response.code.should eql "200" | |
pp response.json | |
end | |
end | |
end | |
end | |
end | |
require 'spec_helper' | |
describe Api::V2::V2BaseController do | |
include_context 'for requests to api.airbnb.com' | |
describe 'logged in users' do | |
let(:user) { FactoryGirl.create(:user) } | |
let(:reservation) { FactoryGirl.create(:reservation2, :new, :guest => user) } | |
let(:trip_invoice) { FactoryGirl.create(:trip_invoice) } | |
before(:each) do | |
@oauth_client_id, @oauth_token = oauth2_login_as(user) | |
@params = { | |
:api_version => 'v2', | |
:oauth_token => @oauth_token, | |
:api_key => @oauth_client_id, | |
} | |
end | |
describe '#get' do | |
context 'invoice found' do | |
it 'returns an invoice' do | |
pp trip_invoice | |
get :show, @params.merge!(:id => trip_invoice.id, :resource => 'trip_invoices') | |
pp response.body | |
pp @trip_invoice | |
response.ok?.should be_true | |
response.code.should eql "200" | |
pp response.json | |
end | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment