Created
August 21, 2012 19:20
-
-
Save rknLA/3418487 to your computer and use it in GitHub Desktop.
api acceptance test for users' friendships.
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
# this is the second revision, and rspec/capybara don't complain about the nested `feature` directives. | |
# but the before() blocks have repetition that i'm not a fan of. would love to figure out how to DRY it up. | |
# see previous revision for what i was trying to do. | |
require 'spec_helper' | |
feature 'friend requests' do | |
before(:each) do | |
@me = User.create(:email => '[email protected]', :password => 'foobar') | |
@you = User.create(:email => '[email protected]', :password => 'bazqux') | |
end | |
scenario 'add a friend by friend id' do | |
post('/friends.json', { | |
authentication_token: @me.authentication_token, | |
friend_id: @you.id | |
}) | |
response.status.should == 201 | |
pending 'check the models to make sure the friendship did actually get created and is pending' | |
end | |
end | |
feature 'pending and requested friends' do | |
before(:each) do | |
@me = User.create(:email => '[email protected]', :password => 'foobar') | |
@you = User.create(:email => '[email protected]', :password => 'bazqux') | |
@me.add_friend_by_friend_id(@you.id) | |
end | |
scenario 'friends should not show up in your friends list until confirmed' do | |
get('/friends.json', { | |
authentication_token: @you.authentication_token | |
}) | |
response.status.should == 200 | |
result = ActiveSupport::JSON.decode(response.body) | |
result.should have_key 'friends' | |
result['friends'].should be_empty | |
end | |
scenario 'friends should not show up in my friends list until confirmed' do | |
get('/friends.json', { | |
authentication_token: @me.authentication_token | |
}) | |
response.status.should == 200 | |
result = ActiveSupport::JSON.decode(response.body) | |
result.should have_key 'friends' | |
result['friends'].should be_empty | |
end | |
scenario 'friends should show up in my pending_friends list' do | |
get('/friends/pending.json', { | |
authentication_token: @me.authentication_token | |
}) | |
response.status.should == 200 | |
result = ActiveSupport::JSON.decode(response.body) | |
result.should have_key 'pending_friends' | |
result['pending_friends'].length.should == 1 | |
result.should have_key 'requested_friends' | |
result['requested_friends'].length.should == 0 | |
friend = result['pending_friends'].first | |
friend['id'].should == @you.id | |
friend['email'].should == @you.email | |
friend.should_not have_key 'authentication_token' | |
end | |
scenario 'friends should show up in your requested_friends list' do | |
get('/friends/pending.json', { | |
authentication_token: @you.authentication_token | |
}) | |
response.status.should == 200 | |
result = ActiveSupport::JSON.decode(response.body) | |
result.should have_key 'pending_friends' | |
result['pending_friends'].length.should == 0 | |
result.should have_key 'requested_friends' | |
result['requested_friends'].length.should == 1 | |
friend = result['requested_friends'].first | |
friend['id'].should == @me.id | |
friend['email'].should == @me.email | |
friend.should_not have_key 'authentication_token' | |
end | |
scenario 'friends should be confirmable by the requestee' do | |
post('/friends/confirm.json', { | |
authentication_token: @you.authentication_token, | |
friend_id: @me.id | |
}) | |
response.status.should == 200 | |
pending 'check the model for friendship confirmation' | |
end | |
scenario 'friends should not be confirmable by the requestor' do | |
post('/friends/confirm.json', { | |
authentication_token: @me.authentication_token, | |
friend_id: @you.id | |
}) | |
response.status.should == 401 | |
pending 'check the model for friendship confirmation' | |
end | |
end | |
feature 'friends after approval' do | |
before(:each) do | |
@me = User.create(:email => '[email protected]', :password => 'foobar') | |
@you = User.create(:email => '[email protected]', :password => 'bazqux') | |
@me.add_friend_by_friend_id(@you.id) | |
@you.approve_friend(@me.id) | |
end | |
scenario 'confirmed friends should show up in the requestors friends list' do | |
get('/friends.json', { | |
authentication_token: @me.authentication_token | |
}) | |
response.status.should == 200 | |
result = ActiveSupport::JSON.decode(response.body) | |
result.should have_key 'friends' | |
result['friends'].length.should == 1 | |
friend = result['friends'].first | |
friend['id'].should == @you.id | |
friend['email'].should == @you.email | |
friend.should_not have_key 'authentication_token' | |
end | |
scenario 'confirmed friends should show up in the requestees friends list' do | |
get('/friends.json', { | |
authentication_token: @you.authentication_token | |
}) | |
response.status.should == 200 | |
result = ActiveSupport::JSON.decode(response.body) | |
result.should have_key 'friends' | |
result['friends'].length.should == 1 | |
friend = result['friends'].first | |
friend['id'].should == @me.id | |
friend['email'].should == @me.email | |
friend.should_not have_key 'authentication_token' | |
end | |
scenario 'confirmed friends should not show up in the requestors pending list' do | |
get('/friends/pending.json', { | |
authentication_token: @me.authentication_token | |
}) | |
response.status.should == 200 | |
result = ActiveSupport::JSON.decode(response.body) | |
result.should have_key 'pending_friends' | |
result['pending_friends'].should be_empty | |
result.should have_key 'requested_friends' | |
result['requested_friends'].should be_empty | |
end | |
scenario 'confirmed friend should not show up in the requested list' do | |
get('/friends/pending.json', { | |
authentication_token: @you.authentication_token | |
}) | |
response.status.should == 200 | |
result = ActiveSupport::JSON.decode(response.body) | |
result.should have_key 'pending_friends' | |
result['pending_friends'].should be_empty | |
result.should have_key 'requested_friends' | |
result['requested_friends'].should be_empty | |
end | |
scenario 'rejected friend should not show up in friends list' do | |
pending 'tbd' | |
end | |
end | |
feature 'friend search' do | |
before(:each) do | |
@me = User.create(:email => '[email protected]', :password => 'foobar') | |
@you = User.create(:email => '[email protected]', :password => 'bazqux') | |
end | |
scenario 'user can find friends by email address' do | |
get('/users/search.json', { | |
authentication_token: @me.authentication_token, | |
email: @you.email | |
}) | |
response.status.should == 200 | |
result = ActiveSupport::JSON.decode(response.body) | |
result.should have_key 'users' | |
result['users'].length.should == 1 | |
result['users'].first['email'].should == @you.email | |
result['users'].first['id'].should == @you.id | |
result['users'].first.should_not have_key 'authentication_token' | |
end | |
scenario 'empty search params yeilds no results' do | |
get('/users/search.json', { | |
authentication_token: @me.authentication_token, | |
}) | |
response.status.should == 200 | |
result = ActiveSupport::JSON.decode(response.body) | |
result.should have_key 'users' | |
result['users'].length.should == 0 | |
end | |
scenario 'user invites a friend via email' do | |
# it should create a new (unconfirmed) user account for the user, and send the user an email | |
post('/users/invite.json', { | |
authentication_token: @me.authentication_token, | |
email: '[email protected]' | |
}) | |
response.status.should == 202 | |
# and it should create a friend request from the inviting user to the invitee | |
new_user = User.find_by_email('[email protected]') | |
new_user.should_not be_nil | |
new_user.confirmed_at.should be_nil | |
friendship = Friendship.find_by_user_id_and_friend_id(@me.id, new_user.id) | |
friendship.should_not be_nil | |
end | |
scenario 'user invites a friend that already has an account' do | |
pending 'design functionality here' | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment