Skip to content

Instantly share code, notes, and snippets.

@taiyoh
Created December 25, 2012 01:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save taiyoh/4371275 to your computer and use it in GitHub Desktop.
Save taiyoh/4371275 to your computer and use it in GitHub Desktop.
facebook絡みの動作をテストする ref: http://qiita.com/items/53fafc145f7c496c301d
before(:all) do
# DatabaseClearnerを使ってDBを初期化
DatabaseClearner.clean
# テストユーザ作成のためのインスタンスをつくる
@test_users = Koala::Facebook::TestUsers.new(
:app_id => OmniAuthConfig::FACEBOOK_API_KEY,
:secret => OmniAuthConfig::FACEBOOK_SECRET_API_KEY
)
# 何人のユーザと友だち関係にいるか
number_of_networks = 5
# 指定したアプリに登録しているかどうか
installed_status = true
# アプリの権限
permissions = 'publish_stream'
networks = @test_users.create_network(
number_of_networks,
installed_status,
permissions
)
@target = nil # 後のテストの為に、特定のユーザだけピックアップしておく
networks.each do |obj|
@target = obj if @target.nil?
# optionanl: 特殊な情報が必要であれば、graphインスタンスを生成して自分の情報を取得
graph = Koala::Facebook::API.new obj["access_token"]
u = graph.get_object("me")
# optional: 必要であれば、DBに情報を格納
User.create(
:fb_id => u["id"],
:name => u["name"]
)
end
end
after(:all) do
# 作成したテストユーザをすべて削除
@test_users.delete_all
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment