rplatform-rails 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG +0 -0
- data/History.txt +2 -0
- data/Manifest.txt +22 -0
- data/README.txt +33 -0
- data/Rakefile +15 -0
- data/init.rb +22 -0
- data/lib/rplatform-rails.rb +45 -0
- data/lib/rplatform_rails/controller_extensions.rb +572 -0
- data/lib/rplatform_rails/model_extensions.rb +218 -0
- data/lib/rplatform_rails/session_extensions.rb +198 -0
- data/lib/rplatform_rails/status_manager.rb +312 -0
- data/lib/rplatform_rails/view_extensions.rb +93 -0
- data/tasks/all.rake +176 -0
- data/templates/debug_panel.rhtml +220 -0
- data/templates/exception_backtrace.rhtml +105 -0
- data/test/api_test.rb +203 -0
- data/test/controller_test.rb +257 -0
- data/test/initialization_test.rb +29 -0
- data/test/model_test.rb +142 -0
- data/test/session_test.rb +64 -0
- data/test/test_helper.rb +105 -0
- data/test/view_test.rb +30 -0
- metadata +92 -0
@@ -0,0 +1,29 @@
|
|
1
|
+
require File.dirname(__FILE__) + "/test_helper"
|
2
|
+
require "test/unit"
|
3
|
+
require "rubygems"
|
4
|
+
require "mocha"
|
5
|
+
require 'application_controller'
|
6
|
+
|
7
|
+
class InitializationTest < Test::Unit::TestCase
|
8
|
+
|
9
|
+
def setup
|
10
|
+
@controller = DummyController.new
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_yml_loaded_properly
|
14
|
+
assert FACEBOOK["key"]
|
15
|
+
assert FACEBOOK["secret"]
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_controller_paths_for_canvas_apps_are_relative
|
19
|
+
if FACEBOOK["canvas_path"]
|
20
|
+
assert(/^\/(.*)\/$/.match(@controller.facebook_canvas_path), "canvas_path should be relative (check your facebook.yml)")
|
21
|
+
end
|
22
|
+
|
23
|
+
if FACEBOOK["callback_path"]
|
24
|
+
assert(/^\/(.*)\/$/.match(@controller.facebook_callback_path), "callback_path should be relative (check your facebook.yml)")
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
|
data/test/model_test.rb
ADDED
@@ -0,0 +1,142 @@
|
|
1
|
+
require File.dirname(__FILE__) + "/test_helper"
|
2
|
+
require "test/unit"
|
3
|
+
require "rubygems"
|
4
|
+
require "mocha"
|
5
|
+
|
6
|
+
class ModelTest < Test::Unit::TestCase
|
7
|
+
|
8
|
+
def test_acts_as_facebook_user_is_present
|
9
|
+
assert @model.class.respond_to?(:acts_as_facebook_user)
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_facebook_extensions_are_present
|
13
|
+
assert @model.respond_to?(:facebook_api_key)
|
14
|
+
assert @model.respond_to?(:facebook_api_secret)
|
15
|
+
assert @model.respond_to?(:facebook_session)
|
16
|
+
assert @model.respond_to?(:facebook_session=)
|
17
|
+
|
18
|
+
RFacebook::Rails::ModelExtensions::ActsAsFacebookUser::FIELDS.each do |field|
|
19
|
+
assert @model.respond_to?(field), "Any model that acts_as_facebook_user should respond to '#{field}'"
|
20
|
+
end
|
21
|
+
|
22
|
+
assert @model.class.respond_to?(:find_or_create_by_facebook_session)
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_facebook_properties_dispatched_to_internal_session
|
26
|
+
|
27
|
+
# allow session to be used
|
28
|
+
@model.facebook_session.expects(:ready?).at_least_once.returns(true)
|
29
|
+
@model.facebook_session.expects(:post_request).at_least_once.returns @dummy_users_getInfo_response
|
30
|
+
|
31
|
+
# try a bunch of fields
|
32
|
+
assert_equal "http://photos-055.facebook.com/ip007/profile3/1271/65/s8055_39735.jpg", @model.pic, "Pic URL should be consistent with the facebook.users.getInfo response XML"
|
33
|
+
assert_equal "November 3", @model.birthday, "Birthday should be consistent with the facebook.users.getInfo response XML"
|
34
|
+
assert_equal "The Brothers K, GEB, Ken Wilber, Zen and the Art, Fitzgerald, The Emporer's New Mind, The Wonderful Story of Henry Sugar", @model.books, "Books should be consistent with the facebook.users.getInfo response XML"
|
35
|
+
assert_equal "Dave", @model.first_name, "First name should be consistent with the facebook.users.getInfo response XML"
|
36
|
+
end
|
37
|
+
|
38
|
+
|
39
|
+
def setup
|
40
|
+
@model = DummyModel.allocate # TODO: how do we properly test model instances that don't have database backing?
|
41
|
+
|
42
|
+
@dummy_users_getInfo_response = <<-EOF
|
43
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
44
|
+
<users_getInfo_response xmlns="http://api.facebook.com/1.0/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://api.facebook.com/1.0/ http://api.facebook.com/1.0/facebook.xsd" list="true">
|
45
|
+
<user>
|
46
|
+
<uid>8055</uid>
|
47
|
+
<about_me>This field perpetuates the glorification of the ego. Also, it has a character limit.</about_me>
|
48
|
+
<activities>Here: facebook, etc. There: Glee Club, a capella, teaching.</activities>
|
49
|
+
<affiliations list="true">
|
50
|
+
<affiliation>
|
51
|
+
<nid>50453093</nid>
|
52
|
+
<name>Facebook Developers</name>
|
53
|
+
<type>work</type>
|
54
|
+
<status/>
|
55
|
+
<year/>
|
56
|
+
</affiliation>
|
57
|
+
</affiliations>
|
58
|
+
<birthday>November 3</birthday>
|
59
|
+
<books>The Brothers K, GEB, Ken Wilber, Zen and the Art, Fitzgerald, The Emporer's New Mind, The Wonderful Story of Henry Sugar</books>
|
60
|
+
<current_location>
|
61
|
+
<city>Palo Alto</city>
|
62
|
+
<state>CA</state>
|
63
|
+
<country>United States</country>
|
64
|
+
<zip>94303</zip>
|
65
|
+
</current_location>
|
66
|
+
<education_history list="true">
|
67
|
+
<education_info>
|
68
|
+
<name>Harvard</name>
|
69
|
+
<year>2003</year>
|
70
|
+
<concentrations list="true">
|
71
|
+
<concentration>Applied Mathematics</concentration>
|
72
|
+
<concentration>Computer Science</concentration>
|
73
|
+
</concentrations>
|
74
|
+
</education_info>
|
75
|
+
</education_history>
|
76
|
+
<first_name>Dave</first_name>
|
77
|
+
<hometown_location>
|
78
|
+
<city>York</city>
|
79
|
+
<state>PA</state>
|
80
|
+
<country>United States</country>
|
81
|
+
<zip>0</zip>
|
82
|
+
</hometown_location>
|
83
|
+
<hs_info>
|
84
|
+
<hs1_name>Central York High School</hs1_name>
|
85
|
+
<hs2_name/>
|
86
|
+
<grad_year>1999</grad_year>
|
87
|
+
<hs1_id>21846</hs1_id>
|
88
|
+
<hs2_id>0</hs2_id>
|
89
|
+
</hs_info>
|
90
|
+
<is_app_user>1</is_app_user>
|
91
|
+
<has_added_app>1</has_added_app>
|
92
|
+
<interests>coffee, computers, the funny, architecture, code breaking,snowboarding, philosophy, soccer, talking to strangers</interests>
|
93
|
+
<last_name>Fetterman</last_name>
|
94
|
+
<meeting_for list="true">
|
95
|
+
<seeking>Friendship</seeking>
|
96
|
+
</meeting_for>
|
97
|
+
<meeting_sex list="true">
|
98
|
+
<sex>female</sex>
|
99
|
+
</meeting_sex>
|
100
|
+
<movies>Tommy Boy, Billy Madison, Fight Club, Dirty Work, Meet the Parents, My Blue Heaven, Office Space </movies>
|
101
|
+
<music>New Found Glory, Daft Punk, Weezer, The Crystal Method, Rage, the KLF, Green Day, Live, Coldplay, Panic at the Disco, Family Force 5</music>
|
102
|
+
<name>Dave Fetterman</name>
|
103
|
+
<notes_count>0</notes_count>
|
104
|
+
<pic>http://photos-055.facebook.com/ip007/profile3/1271/65/s8055_39735.jpg</pic>
|
105
|
+
<pic_big>http://photos-055.facebook.com/ip007/profile3/1271/65/n8055_39735.jpg</pic>
|
106
|
+
<pic_small>http://photos-055.facebook.com/ip007/profile3/1271/65/t8055_39735.jpg</pic>
|
107
|
+
<pic_square>http://photos-055.facebook.com/ip007/profile3/1271/65/q8055_39735.jpg</pic>
|
108
|
+
<political>Moderate</political>
|
109
|
+
<profile_update_time>1170414620</profile_update_time>
|
110
|
+
<quotes/>
|
111
|
+
<relationship_status>In a Relationship</relationship_status>
|
112
|
+
<religion/>
|
113
|
+
<sex>male</sex>
|
114
|
+
<significant_other_id xsi:nil="true"/>
|
115
|
+
<status>
|
116
|
+
<message/>
|
117
|
+
<time>0</time>
|
118
|
+
</status>
|
119
|
+
<timezone>-8</timezone>
|
120
|
+
<tv>cf. Bob Trahan</tv>
|
121
|
+
<wall_count>121</wall_count>
|
122
|
+
<work_history list="true">
|
123
|
+
<work_info>
|
124
|
+
<location>
|
125
|
+
<city>Palo Alto</city>
|
126
|
+
<state>CA</state>
|
127
|
+
<country>United States</country>
|
128
|
+
</location>
|
129
|
+
<company_name>Facebook</company_name>
|
130
|
+
<position>Software Engineer</position>
|
131
|
+
<description>Tech Lead, Facebook Platform</description>
|
132
|
+
<start_date>2006-01</start_date>
|
133
|
+
<end_date/>
|
134
|
+
</work_info>
|
135
|
+
</work_history>
|
136
|
+
</user>
|
137
|
+
</users_getInfo_response>
|
138
|
+
EOF
|
139
|
+
end
|
140
|
+
|
141
|
+
end
|
142
|
+
|
@@ -0,0 +1,64 @@
|
|
1
|
+
require File.dirname(__FILE__) + "/test_helper"
|
2
|
+
require "test/unit"
|
3
|
+
require "rubygems"
|
4
|
+
require "mocha"
|
5
|
+
|
6
|
+
class SessionTest < Test::Unit::TestCase
|
7
|
+
|
8
|
+
def setup
|
9
|
+
@controller = DummyController.new
|
10
|
+
@request = ActionController::TestRequest.new
|
11
|
+
@response = ActionController::TestResponse.new
|
12
|
+
|
13
|
+
@cgi_session_placeholder = CGI::Session.allocate
|
14
|
+
|
15
|
+
# RFacebook extends a certain subset of Rails session stores,
|
16
|
+
# so we must test them each individually
|
17
|
+
@sessionStoresToTest = [
|
18
|
+
CGI::Session::PStore,
|
19
|
+
CGI::Session::ActiveRecordStore,
|
20
|
+
CGI::Session::DRbStore,
|
21
|
+
CGI::Session::FileStore,
|
22
|
+
CGI::Session::MemoryStore
|
23
|
+
]
|
24
|
+
|
25
|
+
begin
|
26
|
+
# optionally check MemCacheStore (only if memcache-client is installed)
|
27
|
+
@sessionStoresToTest << CGI::Session::MemCacheStore
|
28
|
+
rescue Exception => e
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_cgi_session_helpers_are_present
|
34
|
+
@cgi_session_placeholder.respond_to?(:force_to_be_new!, true)
|
35
|
+
@cgi_session_placeholder.respond_to?(:using_facebook_session_id?, true)
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_cgi_session_overrides_are_present
|
39
|
+
assert_rfacebook_overrides_method(@cgi_session_placeholder, :initialize)
|
40
|
+
assert_rfacebook_overrides_method(@cgi_session_placeholder, :new_session)
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_session_store_overrides_are_present
|
44
|
+
# assert that each of the extended stores has the special RFacebook overrides
|
45
|
+
# that enable session storage when inside the canvas
|
46
|
+
@sessionStoresToTest.each do |storeKlass|
|
47
|
+
assert_rfacebook_overrides_method(storeKlass.allocate, :initialize)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_cgi_session_grabs_fb_sig_session_key
|
52
|
+
# TODO: implement test
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_session_store_uses_overridden_init_method_when_in_canvas
|
56
|
+
# TODO: implement test
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_session_store_uses_original_init_method_when_not_in_canvas
|
60
|
+
# TODO: implement test
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
64
|
+
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,105 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '../../../../config/environment.rb'))
|
2
|
+
require "action_controller/test_process"
|
3
|
+
require "action_controller/integration"
|
4
|
+
|
5
|
+
# helpers for all RFacebook unit tests
|
6
|
+
class Test::Unit::TestCase
|
7
|
+
|
8
|
+
def assert_rfacebook_overrides_method(object, methodSymbol)
|
9
|
+
# by convention, RFacebook uses the alias_method_chain on certain methods
|
10
|
+
rfacebookMethodSymbol = "#{methodSymbol}_with_rfacebook".to_sym
|
11
|
+
aliasedMethodSymbol = "#{methodSymbol}_without_rfacebook".to_sym
|
12
|
+
|
13
|
+
# string description of this object
|
14
|
+
objectDescription = object.is_a?(Class) ? object.to_s : object.class.to_s
|
15
|
+
|
16
|
+
# ensure that the original method is still available
|
17
|
+
assert object.respond_to?(aliasedMethodSymbol, true), "Could not find original #{objectDescription}::#{methodSymbol}"
|
18
|
+
|
19
|
+
# ensure that the object has the RFacebook override
|
20
|
+
assert object.respond_to?(rfacebookMethodSymbol, true), "Could not find RFacebook override of #{objectDescription}::#{methodSymbol}"
|
21
|
+
|
22
|
+
# ensure that the override is actually overriding the given method
|
23
|
+
assert object.method(methodSymbol) == object.method(rfacebookMethodSymbol), "#{objectDescription}::#{methodSymbol} does not appear to be overridden by RFacebook"
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
|
28
|
+
# dummy controller used in many test cases
|
29
|
+
class DummyController < ActionController::Base
|
30
|
+
|
31
|
+
before_filter :require_facebook_login, :only => [:index]
|
32
|
+
|
33
|
+
# actions
|
34
|
+
def index
|
35
|
+
render :text => "viewing index"
|
36
|
+
end
|
37
|
+
|
38
|
+
def nofilter
|
39
|
+
render :text => "no filter needed"
|
40
|
+
end
|
41
|
+
|
42
|
+
def shouldbeinstalled
|
43
|
+
if require_facebook_install
|
44
|
+
render :text => "app is installed"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def doredirect
|
49
|
+
redirect_to params[:redirect_url]
|
50
|
+
end
|
51
|
+
|
52
|
+
def render_foobar_action_on_callback
|
53
|
+
render :text => url_for("#{facebook_callback_path}foobar")
|
54
|
+
end
|
55
|
+
|
56
|
+
|
57
|
+
# utility methods
|
58
|
+
|
59
|
+
def rescue_action(e)
|
60
|
+
raise e
|
61
|
+
end
|
62
|
+
|
63
|
+
|
64
|
+
def stub_fbparams(overriddenOptions={})
|
65
|
+
self.stubs(:fbparams).returns({
|
66
|
+
"session_key" => "12345",
|
67
|
+
"user" => "9876",
|
68
|
+
"expires" => Time.now.to_i*2, # timeout long in the future
|
69
|
+
"time" => Time.now.to_i*2, # timeout long in the future
|
70
|
+
}.merge(overriddenOptions))
|
71
|
+
end
|
72
|
+
|
73
|
+
def simulate_inside_canvas(moreParams={})
|
74
|
+
self.stub_fbparams({"in_canvas"=>"1"})
|
75
|
+
@extra_params = {"fb_sig_in_canvas"=>"1"}.merge(moreParams)
|
76
|
+
end
|
77
|
+
|
78
|
+
def params
|
79
|
+
if @extra_params
|
80
|
+
(super || {}).merge(@extra_params)
|
81
|
+
else
|
82
|
+
super
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
# for external apps
|
87
|
+
def finish_facebook_login
|
88
|
+
render :text => "finished facebook login"
|
89
|
+
end
|
90
|
+
|
91
|
+
end
|
92
|
+
|
93
|
+
# dummy model used in a few test cases
|
94
|
+
class DummyModel < ActiveRecord::Base
|
95
|
+
acts_as_facebook_user
|
96
|
+
|
97
|
+
def facebook_uid
|
98
|
+
"dummyuid"
|
99
|
+
end
|
100
|
+
|
101
|
+
def facebook_session_key
|
102
|
+
"dummysessionkey"
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
data/test/view_test.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
require File.dirname(__FILE__) + "/test_helper"
|
2
|
+
require "test/unit"
|
3
|
+
require "rubygems"
|
4
|
+
require "mocha"
|
5
|
+
|
6
|
+
class ViewTest < Test::Unit::TestCase
|
7
|
+
|
8
|
+
def test_extensions_are_present
|
9
|
+
assert @view.respond_to?(:in_facebook_canvas?)
|
10
|
+
assert @view.respond_to?(:in_facebook_frame?)
|
11
|
+
assert @view.respond_to?(:in_mock_ajax?)
|
12
|
+
assert @view.respond_to?(:fbparams)
|
13
|
+
assert @view.respond_to?(:fbsession)
|
14
|
+
assert @view.respond_to?(:image_path)
|
15
|
+
assert @view.respond_to?(:facebook_debug_panel)
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_image_path_should_not_rewrite_absolute_urls
|
19
|
+
# TODO: implement test
|
20
|
+
end
|
21
|
+
|
22
|
+
def setup
|
23
|
+
@controller = DummyController.new
|
24
|
+
@request = ActionController::TestRequest.new
|
25
|
+
@response = ActionController::TestResponse.new
|
26
|
+
@view = ActionView::Base.allocate # TODO: how do we unit test views in Rails?
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
|
metadata
ADDED
@@ -0,0 +1,92 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rplatform-rails
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Curtis Edmond
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2008-07-14 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: hoe
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 1.6.0
|
24
|
+
version:
|
25
|
+
description: ""
|
26
|
+
email: curtis.edmond@gmail.com
|
27
|
+
executables: []
|
28
|
+
|
29
|
+
extensions: []
|
30
|
+
|
31
|
+
extra_rdoc_files:
|
32
|
+
- History.txt
|
33
|
+
- Manifest.txt
|
34
|
+
- README.txt
|
35
|
+
files:
|
36
|
+
- CHANGELOG
|
37
|
+
- History.txt
|
38
|
+
- Manifest.txt
|
39
|
+
- README.txt
|
40
|
+
- Rakefile
|
41
|
+
- init.rb
|
42
|
+
- lib/rplatform-rails.rb
|
43
|
+
- lib/rplatform_rails/controller_extensions.rb
|
44
|
+
- lib/rplatform_rails/model_extensions.rb
|
45
|
+
- lib/rplatform_rails/session_extensions.rb
|
46
|
+
- lib/rplatform_rails/status_manager.rb
|
47
|
+
- lib/rplatform_rails/view_extensions.rb
|
48
|
+
- tasks/all.rake
|
49
|
+
- templates/debug_panel.rhtml
|
50
|
+
- templates/exception_backtrace.rhtml
|
51
|
+
- test/api_test.rb
|
52
|
+
- test/controller_test.rb
|
53
|
+
- test/initialization_test.rb
|
54
|
+
- test/model_test.rb
|
55
|
+
- test/session_test.rb
|
56
|
+
- test/test_helper.rb
|
57
|
+
- test/view_test.rb
|
58
|
+
has_rdoc: true
|
59
|
+
homepage: http://rplatform.rubyforge.org/
|
60
|
+
post_install_message:
|
61
|
+
rdoc_options:
|
62
|
+
- --main
|
63
|
+
- README.txt
|
64
|
+
require_paths:
|
65
|
+
- lib
|
66
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
67
|
+
requirements:
|
68
|
+
- - ">="
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: "0"
|
71
|
+
version:
|
72
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: "0"
|
77
|
+
version:
|
78
|
+
requirements: []
|
79
|
+
|
80
|
+
rubyforge_project: rplatform
|
81
|
+
rubygems_version: 1.2.0
|
82
|
+
signing_key:
|
83
|
+
specification_version: 2
|
84
|
+
summary: A rails interface for Facebook's Platform API
|
85
|
+
test_files:
|
86
|
+
- test/api_test.rb
|
87
|
+
- test/controller_test.rb
|
88
|
+
- test/initialization_test.rb
|
89
|
+
- test/model_test.rb
|
90
|
+
- test/session_test.rb
|
91
|
+
- test/test_helper.rb
|
92
|
+
- test/view_test.rb
|