Skip to content

Commit

Permalink
support expanding person when retrieving survey response
Browse files Browse the repository at this point in the history
  • Loading branch information
mkdynamic committed Jul 19, 2014
1 parent 70d27c5 commit 565cf55
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/delighted/operations/retrieve.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ def self.included(klass)

module Pluralton
module ClassMethods
def retrieve(id, client = Delighted.shared_client)
json = client.get_json(path(id))
def retrieve(id, opts = {}, client = Delighted.shared_client)
opts = Utils.serialize_values(opts)
json = client.get_json(path(id), opts)
new(json)
end

Expand Down
16 changes: 16 additions & 0 deletions test/delighted_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,22 @@ def test_retrieving_a_survey_response
assert_equal '456', survey_response.id
end

def test_retrieving_a_survey_response_expand_person
uri = URI.parse("https://api.delightedapp.com/v1/survey_responses/456?expand%5B%5D=person")
headers = { 'Authorization' => "Basic #{["123abc:"].pack('m0')}", "Accept" => "application/json", 'User-Agent' => "Delighted RubyGem #{Delighted::VERSION}" }
response = Delighted::HTTPResponse.new(200, {}, Delighted::JSON.dump({ :id => '456', :person => { :id => '123', :email => 'foo@bar.com' }, :score => 10 }))
mock_http_adapter.expects(:request).with(:get, uri, headers).once.returns(response)

survey_response = Delighted::SurveyResponse.retrieve('456', :expand => ['person'])
assert_kind_of Delighted::SurveyResponse, survey_response
assert_equal({ :score => 10 }, survey_response.to_hash)
assert_kind_of Delighted::Person, survey_response.person
assert_equal '123', survey_response.person.id
assert_equal({ :email => 'foo@bar.com' }, survey_response.person.to_hash)
assert_equal 10, survey_response.score
assert_equal '456', survey_response.id
end

def test_updating_a_survey_response
uri = URI.parse("https://api.delightedapp.com/v1/survey_responses/456")
headers = { 'Authorization' => "Basic #{["123abc:"].pack('m0')}", "Accept" => "application/json", 'Content-Type' => 'application/json', 'User-Agent' => "Delighted RubyGem #{Delighted::VERSION}" }
Expand Down

0 comments on commit 565cf55

Please sign in to comment.