mirror of
				https://github.com/nov/fb_graph2
				synced 2023-03-27 23:22:15 -04:00 
			
		
		
		
	user & accounts spec
This commit is contained in:
		
							parent
							
								
									4c682fd6bc
								
							
						
					
					
						commit
						05997b7624
					
				
					 8 changed files with 574 additions and 3 deletions
				
			
		| 
						 | 
				
			
			@ -19,5 +19,6 @@ Gem::Specification.new do |gem|
 | 
			
		|||
  gem.add_runtime_dependency 'activesupport', '>= 4.0'
 | 
			
		||||
  gem.add_development_dependency 'rake'
 | 
			
		||||
  gem.add_development_dependency 'simplecov'
 | 
			
		||||
  gem.add_development_dependency 'webmock'
 | 
			
		||||
  gem.add_development_dependency 'rspec', '>= 2'
 | 
			
		||||
end
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -25,7 +25,7 @@ module FbGraph2
 | 
			
		|||
            when :raw
 | 
			
		||||
              raw
 | 
			
		||||
            when :date
 | 
			
		||||
              Date.parse raw
 | 
			
		||||
              Date.strptime raw, '%m/%d/%Y' rescue raw
 | 
			
		||||
            when :time
 | 
			
		||||
              Time.parse raw
 | 
			
		||||
            when :timestamp
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										18
									
								
								spec/fb_graph2/edge/accounts_spec.rb
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										18
									
								
								spec/fb_graph2/edge/accounts_spec.rb
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,18 @@
 | 
			
		|||
require 'spec_helper'
 | 
			
		||||
 | 
			
		||||
describe FbGraph2::Edge::Accounts do
 | 
			
		||||
  context 'included in User' do
 | 
			
		||||
    describe '#accounts' do
 | 
			
		||||
      let(:me) { FbGraph2::User.me('token') }
 | 
			
		||||
      it 'should return pages with page token' do
 | 
			
		||||
        accounts = mock_graph :get, 'me/accounts', 'user/accounts' do
 | 
			
		||||
          me.accounts
 | 
			
		||||
        end
 | 
			
		||||
        account = accounts.first
 | 
			
		||||
        account.should be_instance_of FbGraph2::Page
 | 
			
		||||
        account.name.should == 'Identity Conference #idcon'
 | 
			
		||||
        account.access_token.should == 'page_token'
 | 
			
		||||
      end
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
| 
						 | 
				
			
			@ -1,5 +1,23 @@
 | 
			
		|||
require 'spec_helper'
 | 
			
		||||
 | 
			
		||||
describe FbGraph2::User do
 | 
			
		||||
  it :TODO
 | 
			
		||||
  describe '.me' do
 | 
			
		||||
    let(:klass) { FbGraph2::User }
 | 
			
		||||
 | 
			
		||||
    it 'should not call API' do
 | 
			
		||||
      expect do
 | 
			
		||||
        me = klass.me 'token'
 | 
			
		||||
        me.should be_instance_of klass
 | 
			
		||||
      end.not_to request_to 'me'
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    context 'when fetched' do
 | 
			
		||||
      it 'should call API' do
 | 
			
		||||
        me = mock_graph :get, 'me', 'user/me' do
 | 
			
		||||
          FbGraph2::User.me('token').fetch
 | 
			
		||||
        end
 | 
			
		||||
        me.should be_instance_of klass
 | 
			
		||||
      end
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
							
								
								
									
										24
									
								
								spec/mock_json/user/accounts.json
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										24
									
								
								spec/mock_json/user/accounts.json
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,24 @@
 | 
			
		|||
{
 | 
			
		||||
  "data": [{
 | 
			
		||||
    "category": "Community",
 | 
			
		||||
    "name": "Identity Conference #idcon",
 | 
			
		||||
    "access_token": "page_token",
 | 
			
		||||
    "perms": ["ADMINISTER", "EDIT_PROFILE", "CREATE_CONTENT", "MODERATE_CONTENT", "CREATE_ADS", "BASIC_ADMIN"],
 | 
			
		||||
    "id": "367989543259757"
 | 
			
		||||
  }, {
 | 
			
		||||
    "category": "Community organization",
 | 
			
		||||
    "name": "OAuth.jp",
 | 
			
		||||
    "access_token": "page_token",
 | 
			
		||||
    "perms": ["ADMINISTER", "EDIT_PROFILE", "CREATE_CONTENT", "MODERATE_CONTENT", "CREATE_ADS", "BASIC_ADMIN"],
 | 
			
		||||
    "id": "140478125968442"
 | 
			
		||||
  }, {
 | 
			
		||||
    "category": "Non-profit organization",
 | 
			
		||||
    "name": "OpenID Foundation Japan",
 | 
			
		||||
    "access_token": "access_token",
 | 
			
		||||
    "perms": ["ADMINISTER", "EDIT_PROFILE", "CREATE_CONTENT", "MODERATE_CONTENT", "CREATE_ADS", "BASIC_ADMIN"],
 | 
			
		||||
    "id": "157574337644417"
 | 
			
		||||
  }],
 | 
			
		||||
  "paging": {
 | 
			
		||||
    "next": "https:\/\/graph.facebook.com\/v2.0\/579612276\/accounts?limit=5000&offset=5000&__after_id=enc_AeyErLVKPOCVAXiRThtd3kSkz__A4QR6eZWAQTTTWw-QCDtft_TmuaKhPOxK_I993BKoO1VIgoyXIAd72ZZNYvrw"
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										421
									
								
								spec/mock_json/user/me.json
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										421
									
								
								spec/mock_json/user/me.json
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,421 @@
 | 
			
		|||
{
 | 
			
		||||
  "id": "10152411392127277",
 | 
			
		||||
  "bio": "Ruby/Rails developer, developing several gems like fb_graph, rack-oauth2, paypal-express, openid_connect, activitystreams etc.",
 | 
			
		||||
  "birthday": "12/13/1981",
 | 
			
		||||
  "education": [{
 | 
			
		||||
    "classes": [{
 | 
			
		||||
      "id": "114799961869204",
 | 
			
		||||
      "name": "3rd year high school"
 | 
			
		||||
    }, {
 | 
			
		||||
      "id": "196267900399898",
 | 
			
		||||
      "name": "2nd year",
 | 
			
		||||
      "with": [{
 | 
			
		||||
        "id": "10152979910439657",
 | 
			
		||||
        "name": "Ikuko Kishida"
 | 
			
		||||
      }]
 | 
			
		||||
    }, {
 | 
			
		||||
      "id": "128688833868666",
 | 
			
		||||
      "name": "1st year",
 | 
			
		||||
      "with": [{
 | 
			
		||||
        "id": "10203579017097193",
 | 
			
		||||
        "name": "Yuko Shimabata"
 | 
			
		||||
      }]
 | 
			
		||||
    }],
 | 
			
		||||
    "school": {
 | 
			
		||||
      "id": "168218936549964",
 | 
			
		||||
      "name": "Doshisha High School"
 | 
			
		||||
    },
 | 
			
		||||
    "type": "High School",
 | 
			
		||||
    "year": {
 | 
			
		||||
      "id": "324576644221180",
 | 
			
		||||
      "name": "2000"
 | 
			
		||||
    }
 | 
			
		||||
  }, {
 | 
			
		||||
    "classes": [{
 | 
			
		||||
      "id": "157989264254684",
 | 
			
		||||
      "name": "Intelligent Systems Design Laboratory '04",
 | 
			
		||||
      "with": [{
 | 
			
		||||
        "id": "682734878458663",
 | 
			
		||||
        "name": "Keiji Yamamoto"
 | 
			
		||||
      }]
 | 
			
		||||
    }],
 | 
			
		||||
    "concentration": [{
 | 
			
		||||
      "id": "109532545739630",
 | 
			
		||||
      "name": "Engineering"
 | 
			
		||||
    }],
 | 
			
		||||
    "school": {
 | 
			
		||||
      "id": "109239532428621",
 | 
			
		||||
      "name": "Doshisha University"
 | 
			
		||||
    },
 | 
			
		||||
    "type": "College",
 | 
			
		||||
    "year": {
 | 
			
		||||
      "id": "113125125403208",
 | 
			
		||||
      "name": "2004"
 | 
			
		||||
    }
 | 
			
		||||
  }, {
 | 
			
		||||
    "classes": [{
 | 
			
		||||
      "id": "137361399662343",
 | 
			
		||||
      "name": "Intelligent Systems Design Laboratory '07"
 | 
			
		||||
    }],
 | 
			
		||||
    "concentration": [{
 | 
			
		||||
      "id": "109532545739630",
 | 
			
		||||
      "name": "Engineering"
 | 
			
		||||
    }],
 | 
			
		||||
    "degree": {
 | 
			
		||||
      "id": "200416999973329",
 | 
			
		||||
      "name": "Master of Engineering"
 | 
			
		||||
    },
 | 
			
		||||
    "school": {
 | 
			
		||||
      "id": "109239532428621",
 | 
			
		||||
      "name": "Doshisha University"
 | 
			
		||||
    },
 | 
			
		||||
    "type": "Graduate School",
 | 
			
		||||
    "year": {
 | 
			
		||||
      "id": "140617569303679",
 | 
			
		||||
      "name": "2007"
 | 
			
		||||
    }
 | 
			
		||||
  }],
 | 
			
		||||
  "email": "nov@matake.jp",
 | 
			
		||||
  "favorite_teams": [{
 | 
			
		||||
    "id": "112498808761105",
 | 
			
		||||
    "name": "Bologna F.C. 1909"
 | 
			
		||||
  }, {
 | 
			
		||||
    "id": "103968596307357",
 | 
			
		||||
    "name": "Gamba Osaka"
 | 
			
		||||
  }],
 | 
			
		||||
  "first_name": "Nov",
 | 
			
		||||
  "gender": "male",
 | 
			
		||||
  "hometown": {
 | 
			
		||||
    "id": "112359252112966",
 | 
			
		||||
    "name": "Hirakata, Osaka"
 | 
			
		||||
  },
 | 
			
		||||
  "interested_in": ["female"],
 | 
			
		||||
  "languages": [{
 | 
			
		||||
    "id": "109549852396760",
 | 
			
		||||
    "name": "Japanese"
 | 
			
		||||
  }, {
 | 
			
		||||
    "id": "106059522759137",
 | 
			
		||||
    "name": "English"
 | 
			
		||||
  }],
 | 
			
		||||
  "last_name": "Matake",
 | 
			
		||||
  "link": "https://www.facebook.com/app_scoped_user_id/10152411392127277/",
 | 
			
		||||
  "location": {
 | 
			
		||||
    "id": "100563866688613",
 | 
			
		||||
    "name": "Kawasaki-shi, Kanagawa, Japan"
 | 
			
		||||
  },
 | 
			
		||||
  "locale": "en_US",
 | 
			
		||||
  "name": "Nov Matake",
 | 
			
		||||
  "relationship_status": "Married",
 | 
			
		||||
  "sports": [{
 | 
			
		||||
    "id": "114967135183020",
 | 
			
		||||
    "name": "Billiards"
 | 
			
		||||
  }, {
 | 
			
		||||
    "id": "104085636293671",
 | 
			
		||||
    "name": "Darts"
 | 
			
		||||
  }, {
 | 
			
		||||
    "id": "111124835576428",
 | 
			
		||||
    "name": "Rugby"
 | 
			
		||||
  }],
 | 
			
		||||
  "quotes": "求めなさい。そうすれば、与えられる。\r\n探しなさい。そうすれば、見つかる。\r\n門をたたきなさい。そうすれば、開かれる。\r\nだれでも、求める者は受け、探す者は見つけ、門をたたく者には開かれる。\r\n\r\nあなたがたのだれが、パンを欲しがる自分の子供に、石を与えるだろうか。魚を欲しがるのに、蛇を与えるだろうか。\r\n\r\nこのように、あなたがたは悪い者でありながらも、自分の子供に良い物を与えることを知っている。まして、あなたがたの天の父は、求める者に良い物をくださるにちがいない。\r\n\r\nだから、人にしてもらいたいと思うことは何でも、あなたがたも人にしなさい。\r\n\r\nこれこそ、律法と預言者である。",
 | 
			
		||||
  "timezone": 9,
 | 
			
		||||
  "updated_time": "2014-04-17T02:03:08+0000",
 | 
			
		||||
  "verified": true,
 | 
			
		||||
  "website": "http://matake.jp",
 | 
			
		||||
  "work": [{
 | 
			
		||||
    "employer": {
 | 
			
		||||
      "id": "212867592069252",
 | 
			
		||||
      "name": "GREE"
 | 
			
		||||
    },
 | 
			
		||||
    "position": {
 | 
			
		||||
      "id": "137221592980321",
 | 
			
		||||
      "name": "Developer"
 | 
			
		||||
    },
 | 
			
		||||
    "start_date": "2013-02-01"
 | 
			
		||||
  }, {
 | 
			
		||||
    "employer": {
 | 
			
		||||
      "id": "157574337644417",
 | 
			
		||||
      "name": "OpenID Foundation Japan"
 | 
			
		||||
    },
 | 
			
		||||
    "position": {
 | 
			
		||||
      "id": "103770909661937",
 | 
			
		||||
      "name": "Evangelist"
 | 
			
		||||
    },
 | 
			
		||||
    "start_date": "2011-09-01"
 | 
			
		||||
  }, {
 | 
			
		||||
    "employer": {
 | 
			
		||||
      "id": "19124593579",
 | 
			
		||||
      "name": "OpenID Foundation"
 | 
			
		||||
    },
 | 
			
		||||
    "position": {
 | 
			
		||||
      "id": "139666082733546",
 | 
			
		||||
      "name": "Member"
 | 
			
		||||
    },
 | 
			
		||||
    "start_date": "2011-08-01"
 | 
			
		||||
  }, {
 | 
			
		||||
    "description": "Translating OpenID & OAuth related documents into Japanese.",
 | 
			
		||||
    "employer": {
 | 
			
		||||
      "id": "157574337644417",
 | 
			
		||||
      "name": "OpenID Foundation Japan"
 | 
			
		||||
    },
 | 
			
		||||
    "position": {
 | 
			
		||||
      "id": "279848128693060",
 | 
			
		||||
      "name": "Translation & Education Working Group Leader"
 | 
			
		||||
    },
 | 
			
		||||
    "projects": [{
 | 
			
		||||
      "id": "223851157668338",
 | 
			
		||||
      "description": "RFC 6749, 6750, 6819",
 | 
			
		||||
      "end_date": "2013-01-01",
 | 
			
		||||
      "name": "OAuth 2.0 Spec Translation",
 | 
			
		||||
      "start_date": "2013-01-01",
 | 
			
		||||
      "with": [{
 | 
			
		||||
        "id": "10203856708878032",
 | 
			
		||||
        "name": "Yusuke Kondo"
 | 
			
		||||
      }, {
 | 
			
		||||
        "id": "10203073519271473",
 | 
			
		||||
        "name": "Ryo Ito"
 | 
			
		||||
      }, {
 | 
			
		||||
        "id": "672668269435107",
 | 
			
		||||
        "name": "Naohiro Fujie"
 | 
			
		||||
      }, {
 | 
			
		||||
        "id": "634113926669120",
 | 
			
		||||
        "name": "Masaru Kurahayashi"
 | 
			
		||||
      }, {
 | 
			
		||||
        "id": "10201113604960646",
 | 
			
		||||
        "name": "Tatsuya Katsuhara"
 | 
			
		||||
      }, {
 | 
			
		||||
        "id": "652608194806969",
 | 
			
		||||
        "name": "Boku Kihara"
 | 
			
		||||
      }, {
 | 
			
		||||
        "id": "648027665265419",
 | 
			
		||||
        "name": "Kazuki Shimizu"
 | 
			
		||||
      }, {
 | 
			
		||||
        "id": "562632100518923",
 | 
			
		||||
        "name": "Satoshi Yagi"
 | 
			
		||||
      }, {
 | 
			
		||||
        "id": "10203985460665265",
 | 
			
		||||
        "name": "Noboru Kurumai"
 | 
			
		||||
      }]
 | 
			
		||||
    }, {
 | 
			
		||||
      "id": "223851157668338",
 | 
			
		||||
      "description": "draft 22",
 | 
			
		||||
      "end_date": "2011-11-01",
 | 
			
		||||
      "name": "OAuth 2.0 Spec Translation",
 | 
			
		||||
      "start_date": "2011-10-01",
 | 
			
		||||
      "with": [{
 | 
			
		||||
        "id": "10201113604960646",
 | 
			
		||||
        "name": "Tatsuya Katsuhara"
 | 
			
		||||
      }, {
 | 
			
		||||
        "id": "10203599839574972",
 | 
			
		||||
        "name": "Taizo Matsuoka"
 | 
			
		||||
      }, {
 | 
			
		||||
        "id": "10203856708878032",
 | 
			
		||||
        "name": "Yusuke Kondo"
 | 
			
		||||
      }, {
 | 
			
		||||
        "id": "10203073519271473",
 | 
			
		||||
        "name": "Ryo Ito"
 | 
			
		||||
      }, {
 | 
			
		||||
        "id": "672668269435107",
 | 
			
		||||
        "name": "Naohiro Fujie"
 | 
			
		||||
      }, {
 | 
			
		||||
        "id": "634113926669120",
 | 
			
		||||
        "name": "Masaru Kurahayashi"
 | 
			
		||||
      }, {
 | 
			
		||||
        "id": "652608194806969",
 | 
			
		||||
        "name": "Boku Kihara"
 | 
			
		||||
      }]
 | 
			
		||||
    }, {
 | 
			
		||||
      "id": "223851157668338",
 | 
			
		||||
      "description": "draft 10",
 | 
			
		||||
      "end_date": "2010-11-01",
 | 
			
		||||
      "name": "OAuth 2.0 Spec Translation",
 | 
			
		||||
      "start_date": "2010-09-01",
 | 
			
		||||
      "with": [{
 | 
			
		||||
        "id": "10152392979304293",
 | 
			
		||||
        "name": "Eiji Kitamura"
 | 
			
		||||
      }, {
 | 
			
		||||
        "id": "10202539573504945",
 | 
			
		||||
        "name": "Takanori Ishikawa"
 | 
			
		||||
      }, {
 | 
			
		||||
        "id": "10203599839574972",
 | 
			
		||||
        "name": "Taizo Matsuoka"
 | 
			
		||||
      }, {
 | 
			
		||||
        "id": "10203073519271473",
 | 
			
		||||
        "name": "Ryo Ito"
 | 
			
		||||
      }, {
 | 
			
		||||
        "id": "10201113604960646",
 | 
			
		||||
        "name": "Tatsuya Katsuhara"
 | 
			
		||||
      }, {
 | 
			
		||||
        "id": "10203856708878032",
 | 
			
		||||
        "name": "Yusuke Kondo"
 | 
			
		||||
      }, {
 | 
			
		||||
        "id": "779688938729375",
 | 
			
		||||
        "name": "Toyoaki Ohgochi"
 | 
			
		||||
      }, {
 | 
			
		||||
        "id": "10152359746567310",
 | 
			
		||||
        "name": "Daichi Morifuji"
 | 
			
		||||
      }]
 | 
			
		||||
    }, {
 | 
			
		||||
      "id": "295286707152335",
 | 
			
		||||
      "end_date": "2010-03-01",
 | 
			
		||||
      "name": "OAuth 1.0 Spec Translation",
 | 
			
		||||
      "start_date": "2010-02-01",
 | 
			
		||||
      "with": [{
 | 
			
		||||
        "id": "10203073519271473",
 | 
			
		||||
        "name": "Ryo Ito"
 | 
			
		||||
      }, {
 | 
			
		||||
        "id": "10201113604960646",
 | 
			
		||||
        "name": "Tatsuya Katsuhara"
 | 
			
		||||
      }, {
 | 
			
		||||
        "id": "10152392979304293",
 | 
			
		||||
        "name": "Eiji Kitamura"
 | 
			
		||||
      }, {
 | 
			
		||||
        "id": "10203599839574972",
 | 
			
		||||
        "name": "Taizo Matsuoka"
 | 
			
		||||
      }, {
 | 
			
		||||
        "id": "10203856708878032",
 | 
			
		||||
        "name": "Yusuke Kondo"
 | 
			
		||||
      }]
 | 
			
		||||
    }, {
 | 
			
		||||
      "id": "275379439146839",
 | 
			
		||||
      "end_date": "2010-01-01",
 | 
			
		||||
      "name": "OpenID Authentication 2.0 Spec Translation",
 | 
			
		||||
      "start_date": "2009-10-01",
 | 
			
		||||
      "with": [{
 | 
			
		||||
        "id": "10203073519271473",
 | 
			
		||||
        "name": "Ryo Ito"
 | 
			
		||||
      }, {
 | 
			
		||||
        "id": "10201113604960646",
 | 
			
		||||
        "name": "Tatsuya Katsuhara"
 | 
			
		||||
      }, {
 | 
			
		||||
        "id": "10203599839574972",
 | 
			
		||||
        "name": "Taizo Matsuoka"
 | 
			
		||||
      }]
 | 
			
		||||
    }],
 | 
			
		||||
    "start_date": "2009-12-01"
 | 
			
		||||
  }, {
 | 
			
		||||
    "end_date": "2013-01-01",
 | 
			
		||||
    "employer": {
 | 
			
		||||
      "id": "1414141888809913",
 | 
			
		||||
      "name": "CyberAgent America"
 | 
			
		||||
    },
 | 
			
		||||
    "location": {
 | 
			
		||||
      "id": "114600441890814",
 | 
			
		||||
      "name": "Shibuya, Tokyo"
 | 
			
		||||
    },
 | 
			
		||||
    "position": {
 | 
			
		||||
      "id": "137221592980321",
 | 
			
		||||
      "name": "Developer"
 | 
			
		||||
    },
 | 
			
		||||
    "start_date": "2012-02-01"
 | 
			
		||||
  }, {
 | 
			
		||||
    "end_date": "2012-02-01",
 | 
			
		||||
    "employer": {
 | 
			
		||||
      "id": "216536155172635",
 | 
			
		||||
      "name": "Cerego Japan"
 | 
			
		||||
    },
 | 
			
		||||
    "location": {
 | 
			
		||||
      "id": "112261372122567",
 | 
			
		||||
      "name": "Shibuya, Tokyo"
 | 
			
		||||
    },
 | 
			
		||||
    "position": {
 | 
			
		||||
      "id": "116439701737440",
 | 
			
		||||
      "name": "Rails Developer"
 | 
			
		||||
    },
 | 
			
		||||
    "projects": [{
 | 
			
		||||
      "id": "147355305316648",
 | 
			
		||||
      "end_date": "2012-02-01",
 | 
			
		||||
      "name": "i know",
 | 
			
		||||
      "start_date": "2011-02-01"
 | 
			
		||||
    }, {
 | 
			
		||||
      "id": "115003951868033",
 | 
			
		||||
      "end_date": "2011-03-01",
 | 
			
		||||
      "name": "Smart FM",
 | 
			
		||||
      "start_date": "2009-03-01"
 | 
			
		||||
    }, {
 | 
			
		||||
      "id": "147355305316648",
 | 
			
		||||
      "end_date": "2009-02-01",
 | 
			
		||||
      "name": "i know",
 | 
			
		||||
      "start_date": "2008-10-01"
 | 
			
		||||
    }],
 | 
			
		||||
    "start_date": "2008-10-01"
 | 
			
		||||
  }, {
 | 
			
		||||
    "end_date": "2008-09-01",
 | 
			
		||||
    "employer": {
 | 
			
		||||
      "id": "110398398982373",
 | 
			
		||||
      "name": "ドリコム"
 | 
			
		||||
    },
 | 
			
		||||
    "position": {
 | 
			
		||||
      "id": "108480125843293",
 | 
			
		||||
      "name": "Web Developer"
 | 
			
		||||
    },
 | 
			
		||||
    "projects": [{
 | 
			
		||||
      "id": "196036717085376",
 | 
			
		||||
      "end_date": "2008-01-01",
 | 
			
		||||
      "name": "Drecom Blog",
 | 
			
		||||
      "start_date": "2008-01-01",
 | 
			
		||||
      "with": [{
 | 
			
		||||
        "id": "10202539573504945",
 | 
			
		||||
        "name": "Takanori Ishikawa"
 | 
			
		||||
      }]
 | 
			
		||||
    }, {
 | 
			
		||||
      "id": "186298551407738",
 | 
			
		||||
      "end_date": "2008-05-01",
 | 
			
		||||
      "name": "Resumy",
 | 
			
		||||
      "start_date": "2008-01-01",
 | 
			
		||||
      "with": [{
 | 
			
		||||
        "id": "10202539573504945",
 | 
			
		||||
        "name": "Takanori Ishikawa"
 | 
			
		||||
      }]
 | 
			
		||||
    }, {
 | 
			
		||||
      "id": "133078480094168",
 | 
			
		||||
      "end_date": "2007-12-01",
 | 
			
		||||
      "name": "Drecom Wanted",
 | 
			
		||||
      "start_date": "2006-04-01",
 | 
			
		||||
      "with": [{
 | 
			
		||||
        "id": "10152349447699566",
 | 
			
		||||
        "name": "Hiroumi Mitani"
 | 
			
		||||
      }]
 | 
			
		||||
    }],
 | 
			
		||||
    "start_date": "2006-01-01",
 | 
			
		||||
    "with": [{
 | 
			
		||||
      "id": "10202539573504945",
 | 
			
		||||
      "name": "Takanori Ishikawa"
 | 
			
		||||
    }, {
 | 
			
		||||
      "id": "10202864487006831",
 | 
			
		||||
      "name": "Shoichi Imamura"
 | 
			
		||||
    }]
 | 
			
		||||
  }, {
 | 
			
		||||
    "description": "NPO for IT education",
 | 
			
		||||
    "end_date": "2007-03-01",
 | 
			
		||||
    "employer": {
 | 
			
		||||
      "id": "200555370122204",
 | 
			
		||||
      "name": "Kyoto CtoG.org"
 | 
			
		||||
    },
 | 
			
		||||
    "location": {
 | 
			
		||||
      "id": "107601722603088",
 | 
			
		||||
      "name": "Kyoto"
 | 
			
		||||
    },
 | 
			
		||||
    "position": {
 | 
			
		||||
      "id": "107957955904825",
 | 
			
		||||
      "name": "Founder"
 | 
			
		||||
    },
 | 
			
		||||
    "start_date": "2003-10-01",
 | 
			
		||||
    "with": [{
 | 
			
		||||
      "id": "10203411865798623",
 | 
			
		||||
      "name": "Junya Wako"
 | 
			
		||||
    }, {
 | 
			
		||||
      "id": "667000650003141",
 | 
			
		||||
      "name": "Ken-ichi Niimi"
 | 
			
		||||
    }, {
 | 
			
		||||
      "id": "10152381152939826",
 | 
			
		||||
      "name": "Hiroyuki Makino"
 | 
			
		||||
    }]
 | 
			
		||||
  }, {
 | 
			
		||||
    "end_date": "0000-00",
 | 
			
		||||
    "employer": {
 | 
			
		||||
      "id": "246222982173835",
 | 
			
		||||
      "name": "Capy Inc."
 | 
			
		||||
    },
 | 
			
		||||
    "start_date": "0000-00"
 | 
			
		||||
  }]
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -5,4 +5,8 @@ SimpleCov.start do
 | 
			
		|||
end
 | 
			
		||||
 | 
			
		||||
require 'rspec'
 | 
			
		||||
require 'fb_graph2'
 | 
			
		||||
require 'fb_graph2'
 | 
			
		||||
 | 
			
		||||
Dir[File.join(__dir__, 'spec_helper/*.rb')].each do |file|
 | 
			
		||||
  require file
 | 
			
		||||
end
 | 
			
		||||
							
								
								
									
										85
									
								
								spec/spec_helper/mock_graph.rb
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										85
									
								
								spec/spec_helper/mock_graph.rb
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,85 @@
 | 
			
		|||
require 'webmock/rspec'
 | 
			
		||||
 | 
			
		||||
module MockGraph
 | 
			
		||||
  def mock_graph(method, path, response_path, options = {})
 | 
			
		||||
    stub_request(
 | 
			
		||||
      method,
 | 
			
		||||
      endpoint_for(path)
 | 
			
		||||
    ).with(
 | 
			
		||||
      request_for(method, options)
 | 
			
		||||
    ).to_return(
 | 
			
		||||
      response_for(response_path, options)
 | 
			
		||||
    )
 | 
			
		||||
    if block_given?
 | 
			
		||||
      response = yield
 | 
			
		||||
      a_request(
 | 
			
		||||
        method,
 | 
			
		||||
        endpoint_for(path)
 | 
			
		||||
      ).with(
 | 
			
		||||
        request_for(method, options)
 | 
			
		||||
      ).should have_been_made.once
 | 
			
		||||
      response
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def request_to(path, method = :get)
 | 
			
		||||
    raise_error { |e|
 | 
			
		||||
      e.should be_instance_of WebMock::NetConnectNotAllowedError
 | 
			
		||||
      e.message.should include("Unregistered request: #{method.to_s.upcase}")
 | 
			
		||||
      e.message.should include(endpoint_for path)
 | 
			
		||||
    }
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  private
 | 
			
		||||
 | 
			
		||||
  def endpoint_for(path)
 | 
			
		||||
    File.join(FbGraph2.root_url, path)
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def request_for(method, options = {})
 | 
			
		||||
    request = {}
 | 
			
		||||
    if options[:access_token]
 | 
			
		||||
      options[:params] ||= {}
 | 
			
		||||
      options[:params][:access_token] = options[:access_token].to_s
 | 
			
		||||
    end
 | 
			
		||||
    if options[:params]
 | 
			
		||||
      case method
 | 
			
		||||
      when :post, :put
 | 
			
		||||
        request[:body] = options[:params]
 | 
			
		||||
      else
 | 
			
		||||
        request[:query] = options[:params]
 | 
			
		||||
      end
 | 
			
		||||
    end
 | 
			
		||||
    request
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def response_for(response_path, options = {})
 | 
			
		||||
    response = {}
 | 
			
		||||
    response[:body] = response_file_for response_path
 | 
			
		||||
    if options[:status]
 | 
			
		||||
      response[:status] = options[:status]
 | 
			
		||||
    end
 | 
			
		||||
    response
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def response_file_for(response_path)
 | 
			
		||||
    _response_file_path_ = if File.exist? response_path
 | 
			
		||||
      response_path
 | 
			
		||||
    else
 | 
			
		||||
      File.join(
 | 
			
		||||
        File.dirname(__FILE__), '../mock_json', "#{response_path}.json"
 | 
			
		||||
      )
 | 
			
		||||
    end
 | 
			
		||||
    unless File.exist? _response_file_path_
 | 
			
		||||
      response_file_required! _response_file_path_
 | 
			
		||||
    end
 | 
			
		||||
    File.new _response_file_path_, 'r', encoding: 'utf-8'
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def response_file_required!(response_path)
 | 
			
		||||
    warn 'No response file found.'
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
include MockGraph
 | 
			
		||||
WebMock.disable_net_connect!
 | 
			
		||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue