Skip to content

Commit

Permalink
Rename creation query parameter, document creation params
Browse files Browse the repository at this point in the history
Doco ripped shamelessly from:

http://developers.facebook.com/docs/test_users/

Also, drop query parameter on TestUser#all, as there are no documented options.
  • Loading branch information
Travis Vachon committed Jul 13, 2011
1 parent 6e8913b commit 9c27b11
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 8 deletions.
28 changes: 23 additions & 5 deletions lib/mogli/test_user.rb
Expand Up @@ -12,16 +12,34 @@ module Mogli
class TestUser < User class TestUser < User
define_properties :access_token, :login_url, :password define_properties :access_token, :login_url, :password


def self.create(query, app_client) # test_user_params can include:
app_client.post("accounts/test-users", self, query) #
# installed: This is a Boolean parameter to specify whether your
# app should be installed for the test user at the time of
# creation. It is true by default.
#
# name: this is an optional string parameter. You can specify a
# name for the test user you create. The specified name will also
# be used in the email address assigned to the test user.
#
# permissions: This is a comma-separated list of {extended permissions}[http://developers.facebook.com/docs/reference/api/permissions/].
# Your app is granted these permissions for the new test user if
# installed is true.
#
# Example usage:
#
# Mogli::TestUser.create({:installed => false, :name => 'Zark Muckerberg', :permissions => 'user_events,create_event'}, client)
def self.create(test_user_params, app_client)
app_client.post("accounts/test-users", self, test_user_params)
end end


def self.all(query, app_client) def self.all(app_client)
app_client.get_and_map("accounts/test-users", self, query) app_client.get_and_map("accounts/test-users", self, {})
end end


def to_s def to_s
id # name is nil by default, so use id
id.to_s
end end
end end
end end
7 changes: 4 additions & 3 deletions spec/test_user_spec.rb
Expand Up @@ -7,8 +7,9 @@
describe "#create" do describe "#create" do
it "POSTs to the test user creation url" do it "POSTs to the test user creation url" do
Mogli::Client.should_receive(:post).with("https://graph.facebook.com/#{app_id}/accounts/test-users", Mogli::Client.should_receive(:post).with("https://graph.facebook.com/#{app_id}/accounts/test-users",
:body => {:access_token => access_token}).and_return({:id=>1, :login_url => 'http://example.com/hamsocks' }) :body => {:access_token => access_token, :installed => false, :name => 'The Sock Hammer'}).
user = Mogli::TestUser.create({}, Mogli::AppClient.new(access_token, app_id)) and_return({:id=>1, :login_url => 'http://example.com/hamsocks' })
user = Mogli::TestUser.create({:installed => false, :name => 'The Sock Hammer'}, Mogli::AppClient.new(access_token, app_id))
user.login_url.should == 'http://example.com/hamsocks' user.login_url.should == 'http://example.com/hamsocks'
end end
end end
Expand All @@ -17,7 +18,7 @@
it "GETs the test user url" do it "GETs the test user url" do
Mogli::Client.should_receive(:get).with("https://graph.facebook.com/#{app_id}/accounts/test-users", Mogli::Client.should_receive(:get).with("https://graph.facebook.com/#{app_id}/accounts/test-users",
:query => {:access_token => access_token}).and_return([{:id=>1, :login_url => 'http://example.com/hamsocks'}]) :query => {:access_token => access_token}).and_return([{:id=>1, :login_url => 'http://example.com/hamsocks'}])
users = Mogli::TestUser.all({}, Mogli::AppClient.new(access_token, app_id)) users = Mogli::TestUser.all(Mogli::AppClient.new(access_token, app_id))
users.first.login_url.should == 'http://example.com/hamsocks' users.first.login_url.should == 'http://example.com/hamsocks'
end end
end end
Expand Down

0 comments on commit 9c27b11

Please sign in to comment.