Permalink
Browse files

Fixes OfferSpec by including the offers when fetching the Task.

  • Loading branch information...
1 parent cfe7ed7 commit 4ee13094339002b3cc40acd89733b1ba4d35849e Brian Leonard & Steve Hull committed with nolastan Sep 13, 2012
@@ -32,7 +32,7 @@ def request(method, path, transformer, options = {})
def request_params(transformer, options = {})
{
:transform => transformer,
- :extra_body => options,
+ :extra_query => options[:extra_query] || {},
:extra_request => {
:headers => {
'X-Client-Application' => api_secret.to_s,
@@ -2,7 +2,9 @@ module Taskrabbit
class Offer < Smash
property :id
property :charge_price
+ property :comment
property :state
+ property :runner, :transformer => User
class << self
def all(scope, options = {})
@@ -30,14 +30,18 @@ class Task < Smash
class << self
def all(scope, options = {})
- scope.request('get', scope.association_path(self), Api::collection_transformers[self], options)
+ scope.request('get', scope.association_path(self), Api::collection_transformers[self], options_with_class_includes(options))
end
def create(api, params)
task = api.tasks.new(params)
task.save
task
end
+
+ def options_with_class_includes(options = {})
+ options.merge(:extra_query => {:include => {:task => properties.to_a}})
+ end
end
def fetch
@@ -66,5 +70,9 @@ def new_record?
def delete!
reload('delete', "tasks/#{id.to_s}")
end
+
+ def reload(method, path, options = {})
+ super(method, path, self.class.options_with_class_includes(options))
+ end
end
end
@@ -0,0 +1,90 @@
+---
+- !ruby/struct:VCR::HTTPInteraction
+ request: !ruby/struct:VCR::Request
+ method: :get
+ uri: https://taskrabbitdev.com:443/api/v1/tasks/52?include[task][]=errors&include[task][]=links&include[task][]=error&include[task][]=id&include[task][]=name&include[task][]=user&include[task][]=runner&include[task][]=runners&include[task][]=named_price&include[task][]=charge_price&include[task][]=cost_in_cents&include[task][]=number_runners_to_fill&include[task][]=state_label&include[task][]=city_id&include[task][]=city&include[task][]=description&include[task][]=private_description&include[task][]=private_runner&include[task][]=virtual&include[task][]=state&include[task][]=assignment_type&include[task][]=complete_by_time&include[task][]=state_changed_at&include[task][]=assign_by_time&include[task][]=location_visits&include[task][]=offers&include[task][]=other_locations_attributes&include[task][]=uploaded_photos_attributes&include[task][]=uploaded_sounds_attributes&include[offer][]=errors&include[offer][]=links&include[offer][]=error&include[offer][]=id&include[offer][]=charge_price&include[offer][]=comment&include[offer][]=state&include[offer][]=runner
+ body:
+ headers:
+ x-client-application:
+ - <API_SECRET>
+ authorization:
+ - OAuth <USER_WITH_CARD>
+ response: !ruby/struct:VCR::Response
+ status: !ruby/struct:VCR::ResponseStatus
+ code: 200
+ message: OK
+ headers:
+ server:
+ - nginx/1.0.11
+ date:
+ - Thu, 13 Sep 2012 00:15:04 GMT
+ content-type:
+ - application/json; charset=utf-8
+ status:
+ - 200 OK
+ set-cookie:
+ - current_geo=1053; path=/; expires=Tue, 13-Nov-2012 01:15:04 GMT
+ x-runtime:
+ - '0.233808'
+ content-length:
+ - '1625'
+ etag:
+ - ! '"7752ebc8b69f2bd2122470c71bff137e"'
+ x-ua-compatible:
+ - IE=Edge,chrome=1
+ cache-control:
+ - max-age=0, private, must-revalidate
+ body: ! '{"private_runner":false,"links":{"put":"/api/v1/tasks/52","html":"http://s-app1.taskrabbit.com/tasks/house-cleaning-7091","get":"/api/v1/tasks/52","offers":"/api/v1/tasks/52/offers","authenticated":"http://s-app1.taskrabbit.com/go/82d359e524666a2d8b96f6df1fbfcad4a720a0b4fed8c3f0985139a13a4d6433b65f7f05e80360af131d8f9638f8307e035b","delete":"/api/v1/tasks/52"},"charge_price":0,"runners":{"items":[]},"cost_in_cents":0,"id":52,"state_changed_at":1347490579,"assignment_type":"review","description":"I
+ need to clean my house","city":{"links":{"get":"/api/v1/cities/3"},"lat":37.77493,"id":1053,"lng":-122.419416,"name":"SF
+ Bay Area"},"assign_by_time":1347577200,"name":"House Cleaning","offers":{"items":[{"charge_price":26,"id":7,"runner":{"links":{"get":"/api/v1/users/32","avatar_url":"http://s-app1.taskrabbit.com/images/default_avatars/runner_thumb.png"},"friend_code_url":"http://taskrabbit.com/PAL/32","id":32,"short_name":"Fancy","display_name":"Fancy
+ R.","runner":true,"runner_level":1,"city":{"links":{"get":"/api/v1/cities/4"},"lat":40.714353,"id":1060,"lng":-74.005973,"name":"New
+ York City"},"email":"fancyrabbit@example.com","full_name":"Fancy R."},"state":"sent"}]},"location_visits":{"items":[{"lat":37.7867363,"zip":"94102","id":11,"complete":"213
+ Powell Street, San Francisco, CA, San Francisco, CA 94102","partial":"Powell
+ Street, San Francisco, CA, San Francisco, CA 94102","location_id":52,"lng":-122.4080542,"city":"San
+ Francisco","name":"Home","approximate_radius":0,"address":"213 Powell Street,
+ San Francisco, CA","state":"CA"}]},"state_label":"posted","complete_by_time":1347663600,"state":"opened"}'
+ http_version: '1.1'
+- !ruby/struct:VCR::HTTPInteraction
+ request: !ruby/struct:VCR::Request
+ method: :get
+ uri: https://taskrabbitdev.com:443/api/v1/tasks/52?include[task][]=errors&include[task][]=links&include[task][]=error&include[task][]=id&include[task][]=name&include[task][]=user&include[task][]=runner&include[task][]=runners&include[task][]=named_price&include[task][]=charge_price&include[task][]=cost_in_cents&include[task][]=number_runners_to_fill&include[task][]=state_label&include[task][]=city_id&include[task][]=city&include[task][]=description&include[task][]=private_description&include[task][]=private_runner&include[task][]=virtual&include[task][]=state&include[task][]=assignment_type&include[task][]=complete_by_time&include[task][]=state_changed_at&include[task][]=assign_by_time&include[task][]=location_visits&include[task][]=offers&include[task][]=other_locations_attributes&include[task][]=uploaded_photos_attributes&include[task][]=uploaded_sounds_attributes
+ body:
+ headers:
+ x-client-application:
+ - <API_SECRET>
+ authorization:
+ - OAuth <USER_WITH_CARD>
+ response: !ruby/struct:VCR::Response
+ status: !ruby/struct:VCR::ResponseStatus
+ code: 200
+ message: OK
+ headers:
+ server:
+ - nginx/1.0.11
+ date:
+ - Thu, 13 Sep 2012 00:30:49 GMT
+ content-type:
+ - application/json; charset=utf-8
+ status:
+ - 200 OK
+ set-cookie:
+ - current_geo=1053; path=/; expires=Tue, 13-Nov-2012 01:30:49 GMT
+ x-runtime:
+ - '0.192928'
+ content-length:
+ - '1245'
+ etag:
+ - ! '"1bb05d4c694e2dc4ee9b37e66b3175ba"'
+ x-ua-compatible:
+ - IE=Edge,chrome=1
+ cache-control:
+ - max-age=0, private, must-revalidate
+ body: ! '{"private_runner":false,"links":{"put":"/api/v1/tasks/52","html":"http://s-app1.taskrabbit.com/tasks/house-cleaning-7091","get":"/api/v1/tasks/52","offers":"/api/v1/tasks/52/offers","authenticated":"http://s-app1.taskrabbit.com/go/82d359e524666a2d8b96f6df1fbfcad4a720a0b4fed8c3f0985139a13a4d6433b65f7f05e80360af131d8f9638f8307e035b","delete":"/api/v1/tasks/52"},"charge_price":0,"runners":{"items":[]},"cost_in_cents":0,"id":52,"state_changed_at":1347490579,"assignment_type":"review","description":"I
+ need to clean my house","city":{"links":{"get":"/api/v1/cities/3"},"lat":37.77493,"id":1053,"lng":-122.419416,"name":"SF
+ Bay Area"},"assign_by_time":1347577200,"name":"House Cleaning","offers":{"items":[{"charge_price":26,"id":7,"created_at":1347493865,"comments":"I
+ clean a lot!","state":"sent"}]},"location_visits":{"items":[{"lat":37.7867363,"zip":"94102","id":11,"complete":"213
+ Powell Street, San Francisco, CA, San Francisco, CA 94102","partial":"Powell
+ Street, San Francisco, CA, San Francisco, CA 94102","location_id":52,"lng":-122.4080542,"city":"San
+ Francisco","name":"Home","approximate_radius":0,"address":"213 Powell Street,
+ San Francisco, CA","state":"CA"}]},"state_label":"posted","complete_by_time":1347663600,"state":"opened"}'
+ http_version: '1.1'
@@ -6,19 +6,18 @@
before :all do
tr = Taskrabbit::Api.new(TR_USERS[:with_card][:secret])
- VCR.use_cassette('tasks/properties', :record => :new_episodes) do
- @tr_task = tr.tasks.find(22545)
+ VCR.use_cassette('tasks/with_offers_properties', :record => :new_episodes) do
+ @tr_task = tr.tasks.find(ENV["TASK_ID"])
@tr_task.fetch
end
- VCR.use_cassette('offers/properties', :record => :new_episodes) do
- @offer = @tr_task.offers.first
- end
+ @offer = @tr_task.offers.first
end
subject { @offer }
- its(:id ) { should == 37439 }
- its(:charge_price ) { should == "Home" }
- its(:state ) { should == "432 example" }
+ its(:id ) { should == 7 }
+ its(:charge_price ) { should == 26 }
+ its(:state ) { should == "sent" }
+ its(:runner ) { should be_instance_of(Taskrabbit::User) }
end
end

0 comments on commit 4ee1309

Please sign in to comment.