Skip to content

Commit

Permalink
Adios, Context Optional
Browse files Browse the repository at this point in the history
  • Loading branch information
arsduo committed Sep 12, 2012
1 parent 6e151d0 commit 88a8dce
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 22 deletions.
12 changes: 6 additions & 6 deletions spec/fixtures/mock_facebook_responses.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ graph_api:

# OAuth error response
oauth_error: &oauth_error
no_token:
no_token:
code: 400
body: '{"error": {"code"=>2500, "type": "OAuthException", "message": "Error validating verification code."}}'

Expand All @@ -68,10 +68,10 @@ graph_api:

# -- Stubbed Responses --
root:
ids=contextoptional,koppel:
ids=facebook,koppel:
get:
with_token: '{"contextoptional":"{}","koppel":"{}"}'
no_token: '{"contextoptional":"{}","koppel":"{}"}'
with_token: '{"facebook":"{}","koppel":"{}"}'
no_token: '{"facebook":"{}","koppel":"{}"}'

# Ruby 1.8.7 and 1.9.2 generate JSON with different key ordering, hence we have to dynamically generate it here
batch=<%= MultiJson.dump([{"method" => "get", "relative_url" => "me"},{"method" => "get", "relative_url" => "koppel"}]) %>:
Expand Down Expand Up @@ -204,13 +204,13 @@ graph_api:
with_token: '{"id": 1, "name": 1, "updated_time": 1}'
no_token: '{"id": 1, "name": 1}'

/contextoptional:
/facebook:
no_args:
get:
with_token: '{"id": 1, "name": 1}'
no_token: '{"id": 1, "name": 1}'

/contextoptional/photos:
/facebook/photos:
no_args:
get:
with_token: '{"data": [{}], "paging": {"previous": "https:\/\/graph.facebook.com\/7204941866\/photos?limit=25&until=2008-09-15T18%3A30%3A25%2B0000", "next": "https:\/\/graph.facebook.com\/7204941866\/photos?limit=25&until=2008-09-15T18%3A30%3A25%2B0000"}}'
Expand Down
6 changes: 3 additions & 3 deletions spec/support/graph_api_shared_examples.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
end

it "gets multiple objects if they're a string" do
results = @api.get_objects("contextoptional,#{KoalaTest.user1}")
results = @api.get_objects("facebook,#{KoalaTest.user1}")
results.should have(2).items
end

Expand Down Expand Up @@ -602,12 +602,12 @@
it "can't post to a feed" do
(lambda do
attachment = {:name => "OAuth Playground", :link => "http://oauth.twoalex.com/"}
@result = @api.put_wall_post("Hello, world", attachment, "contextoptional")
@result = @api.put_wall_post("Hello, world", attachment, "facebook")
end).should raise_error(Koala::Facebook::AuthenticationError)
end

it "can't comment on an object" do
# random public post on the ContextOptional wall
# random public post on the facebook wall
lambda { @result = @api.put_comment("7204941866_119776748033392", "The hackathon was great!") }.should raise_error(Koala::Facebook::AuthenticationError)
end

Expand Down
26 changes: 13 additions & 13 deletions spec/support/koala_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@ class << self
attr_accessor :oauth_test_data, :subscription_test_data, :search_time
attr_accessor :test_user_api
end

# Test setup

def self.setup_test_environment!
setup_rspec

unless ENV['LIVE']
# By default the Koala specs are run using stubs for HTTP requests,
# so they won't fail due to Facebook-imposed rate limits or server timeouts.
#
# However as a result they are more brittle since
# we are not testing the latest responses from the Facebook servers.
# To be certain all specs pass with the current Facebook services,
# To be certain all specs pass with the current Facebook services,
# run LIVE=true bundle exec rake spec.
Koala.http_service = Koala::MockHTTPService
KoalaTest.setup_test_data(Koala::MockHTTPService::TEST_DATA)
Expand All @@ -36,7 +36,7 @@ def self.setup_test_environment!
rescue LoadError
puts "Unable to load adapter #{adapter}, using Net::HTTP."
end

Koala.http_service.http_options[:beta] = true if ENV["beta"] || ENV["BETA"]

# use a test user unless the developer wants to test against a real profile
Expand All @@ -47,7 +47,7 @@ def self.setup_test_environment!
end
end
end

def self.setup_rspec
# set up a global before block to set the token for tests
# set the token up for
Expand Down Expand Up @@ -85,15 +85,15 @@ def self.setup_test_data(data)
self.secret = data["oauth_test_data"]["secret"]
self.code = data["oauth_test_data"]["code"]
self.session_key = data["oauth_test_data"]["session_key"]

# fix the search time so it can be used in the mock responses
self.search_time = data["search_time"] || (Time.now - 3600).to_s
end

def self.testing_permissions
"read_stream, publish_stream, user_photos, user_videos, read_insights"
end

def self.setup_test_users
print "Setting up test users..."
@test_user_api = Koala::Facebook::TestUsers.new(:app_id => self.app_id, :secret => self.secret)
Expand All @@ -103,7 +103,7 @@ def self.setup_test_users
# before each test module, create two test users with specific names and befriend them
KoalaTest.create_test_users
end

config.after :suite do
# after each test module, delete the test users to avoid cluttering up the application
KoalaTest.destroy_test_users
Expand All @@ -122,9 +122,9 @@ def self.create_test_users
rescue Exception => e
Kernel.warn("Problem creating test users! #{e.message}")
raise
end
end
end

def self.destroy_test_users
[@live_testing_user, @live_testing_friend].each do |u|
puts "Unable to delete test user #{u.inspect}" if u && !(@test_user_api.delete(u) rescue false)
Expand All @@ -144,7 +144,7 @@ def self.validate_user_info(token)
end
puts "done!"
end

# Info about the testing environment
def self.real_user?
!(mock_interface? || @test_user_api)
Expand Down Expand Up @@ -189,7 +189,7 @@ def self.user2_name
end

def self.page
"contextoptional"
"facebook"
end

def self.app_properties
Expand Down

0 comments on commit 88a8dce

Please sign in to comment.