Skip to content

Instantly share code, notes, and snippets.

@endymion
Created August 23, 2012 15:27
Show Gist options
  • Select an option

  • Save endymion/3437745 to your computer and use it in GitHub Desktop.

Select an option

Save endymion/3437745 to your computer and use it in GitHub Desktop.
Example of how to post an update to a Guest record using the API.
def test_api_update_guest
post :create, @authentication.merge(
'guest' => {
'event' => @event.id,
'account' => @account.id,
'first' => 'Testy',
'last' => 'Testerson',
'phone' => '555 555-5555',
'email' => 'test@test.com',
}
), :format => 'json'
assert_equal 1, Guestlist.last.guests.count
guest = Guest.last
# This is what was posted:
assert_equal 'Testy', guest.first
assert_equal 'Testerson', guest.last
assert_equal '555 555-5555', guest.phone
assert_equal 'test@test.com', guest.email
# Update two things at once.
post :update, @authentication.merge(
'guest' => {
# Only send updated columns.
'phone' => '555 555-5556',
'email' => 'test2@test.com',
},
'id' => guest.id
), :format => 'json'
guest = Guest.last
# Not changed:
assert_equal 'Testy', guest.first
assert_equal 'Testerson', guest.last
# Updated:
assert_equal '555 555-5556', guest.phone
assert_equal 'test2@test.com', guest.email
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment