Skip to content

Instantly share code, notes, and snippets.

@yclian
Created August 1, 2012 00:41
Show Gist options
  • Save yclian/3222052 to your computer and use it in GitHub Desktop.
Save yclian/3222052 to your computer and use it in GitHub Desktop.
FactoryGirl.define do
factory :person do
sequence(:name) { |n| "Nicole Neal (#{n})" }
factory :person_with_party do
after_create do |person|
# TODO
# party = FactoryGirl.create(:party)
# FactoryGirl.create(:party_membership, { party: party, member: member, joined_at: 1.year.ago.year })
end
end
end
factory :user do
sequence(:name) { |n| "user-#{n}" }
after_build do |u|
u.generate_api_key
end
end
end
78 Query BEGIN
78 Query SAVEPOINT "b27c3df7d79306e86bcd80c4d75e564fd1873af26fb6d2e842132544ee86b49"
78 Query INSERT INTO `people` (`type`, `name`) VALUES ('Person', 'Nicole Neal (1)')
78 Query SELECT `id`, `type`, `uuid`, `timestamp`, `updated_at`, `name`, `email`, `facebook`, `twitter`, `linkedin`, `www`, `phone`, `fax`, `race`, `sex`, `birth_year`, `deceased_at` FROM `people` ORDER BY `id`
78 Query SELECT `id`, `type`, `education`, `home_address`, `office_address`, `biography` FROM `people` WHERE `id` = 41 ORDER BY `id`
78 Query INSERT INTO `logs` (`timestamp`, `remote_addr`, `method`, `return_code`, `return_size`) VALUES ('2012-08-01 08:42:50', '127.0.0.1', 'GET', '200', 365)
78 Query SELECT `id`, `uuid`, `timestamp`, `updated_at`, `type`, `email`, `facebook`, `twitter`, `linkedin`, `www`, `phone`, `fax`, `race`, `sex`, `birth_year`, `deceased_at` FROM `people` WHERE `id` = 41 ORDER BY `id`
78 Query SELECT `id`, `type`, `education`, `home_address`, `office_address`, `biography` FROM `people` WHERE `id` = 41 ORDER BY `id`
78 Query ROLLBACK TO SAVEPOINT "b27c3df7d79306e86bcd80c4d75e564fd1873af26fb6d2e842132544ee86b49"
78 Query SAVEPOINT "7c06c151ead8993d0c39c9f53028458641dee8b7f97769463cdcc12d15c9d45"
78 Query INSERT INTO `people` (`type`, `name`) VALUES ('Person', 'Nicole Neal (2)')
78 Query SELECT COUNT(*) FROM `people`
78 Query SELECT `id`, `type`, `uuid`, `timestamp`, `updated_at`, `name`, `email`, `facebook`, `twitter`, `linkedin`, `www`, `phone`, `fax`, `race`, `sex`, `birth_year`, `deceased_at` FROM `people` ORDER BY `id` DESC LIMIT 42
78 Query SELECT `id`, `type`, `education`, `home_address`, `office_address`, `biography` FROM `people` WHERE `id` = 42 ORDER BY `id`
78 Query INSERT INTO `logs` (`timestamp`, `remote_addr`, `method`, `return_code`, `return_size`) VALUES ('2012-08-01 08:42:50', '127.0.0.1', 'GET', '200', 420)
78 Query SELECT `id`, `uuid`, `timestamp`, `updated_at`, `type`, `email`, `facebook`, `twitter`, `linkedin`, `www`, `phone`, `fax`, `race`, `sex`, `birth_year`, `deceased_at` FROM `people` WHERE `id` = 42 ORDER BY `id`
78 Query SELECT `id`, `type`, `education`, `home_address`, `office_address`, `biography` FROM `people` WHERE `id` = 42 ORDER BY `id`
78 Query ROLLBACK TO SAVEPOINT "7c06c151ead8993d0c39c9f53028458641dee8b7f97769463cdcc12d15c9d45"
78 Query SAVEPOINT "6ab18a3e925fa7c4123e643bfebd00afb9c86a017d5e553f611801fb1243c89"
78 Query INSERT INTO `people` (`type`, `name`) VALUES ('Person', 'Nicole Neal (3)')
78 Query INSERT INTO `users` (`uuid`, `timestamp`, `name`, `api_key`) VALUES ('74233565-791e-5a61-9436-ad124dc63ccc', '2012-08-01 08:42:50', 'user-1', '853b15dd-be1d-59ad-8670-167866bfbef2')
78 Query SELECT `id`, `uuid`, `timestamp`, `name`, `api_key` FROM `users` WHERE `api_key` = '853b15dd-be1d-59ad-8670-167866bfbef2' ORDER BY `id` LIMIT 1
78 Query SELECT `id`, `uuid`, `timestamp`, `name`, `api_key` FROM `users` WHERE `api_key` = '853b15dd-be1d-59ad-8670-167866bfbef2' ORDER BY `id` LIMIT 1
78 Query INSERT INTO `logs` (`timestamp`, `remote_addr`, `method`, `return_code`, `return_size`, `user_uuid`) VALUES ('2012-08-01 08:42:50', '127.0.0.1', 'POST', '404', 452, '74233565-791e-5a61-9436-ad124dc63ccc')
78 Query SELECT COUNT(*) FROM `people` WHERE `name` LIKE '%Samantha%Saint%'
78 Query ROLLBACK TO SAVEPOINT "6ab18a3e925fa7c4123e643bfebd00afb9c86a017d5e553f611801fb1243c89"
78 Query ROLLBACK
require 'spec_helper'
describe '/people', :type => :api do
let (:user) { create :user }
before :each do
@person = create :person
end
context 'Getting all people' do
it "should return created persons" do
get '/people'
last_response.body.should have_json_path 'payload'
last_response.body.should include_json(@person.to_json).at_path('payload')
end
end
context 'Getting a person with their UUID' do
it "should return the specified person" do
get "/people/#{@person.id}"
last_response.body.should have_json_path 'payload'
last_response.body.should have_json_size(1).at_path('payload')
last_response.body.should be_json_eql(@person.to_json).at_path('payload/0')
end
end
context 'Creating a person' do
it "should be persisted and readable after" do
post "/people/person?api_key=#{user.api_key}", build(:person, { name: 'Samantha Saint' }).to_json
Person.all(:name.like => '%Samantha%Saint%').count.should == 1
end
end
end
/people
Getting all people
should return created persons
Getting a person with their UUID
should return the specified person
Creating a person
should be persisted and readable after (FAILED - 1)
Failures:
1) /people Creating a person should be persisted and readable after
Failure/Error: Person.all(:name.like => '%Samantha%Saint%').count.should == 1
expected: 1
got: 0 (using ==)
# ./spec/api/people_spec.rb:31:in `block (3 levels) in <top (required)>'
Finished in 0.26432 seconds
3 examples, 1 failure
Failed examples:
rspec ./spec/api/people_spec.rb:29 # /people Creating a person should be persisted and readable after
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment