cwninja-facebooker 1.0.8
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.txt +0 -0
- data/COPYING +19 -0
- data/History.txt +16 -0
- data/Manifest.txt +114 -0
- data/README +46 -0
- data/README.txt +81 -0
- data/Rakefile +76 -0
- data/TODO.txt +10 -0
- data/generators/facebook/facebook_generator.rb +14 -0
- data/generators/facebook/templates/config/facebooker.yml +46 -0
- data/generators/facebook/templates/public/javascripts/facebooker.js +106 -0
- data/generators/facebook_controller/USAGE +33 -0
- data/generators/facebook_controller/facebook_controller_generator.rb +40 -0
- data/generators/facebook_controller/templates/controller.rb +7 -0
- data/generators/facebook_controller/templates/functional_test.rb +11 -0
- data/generators/facebook_controller/templates/helper.rb +2 -0
- data/generators/facebook_controller/templates/view.fbml.erb +2 -0
- data/generators/facebook_controller/templates/view.html.erb +2 -0
- data/generators/facebook_publisher/facebook_publisher_generator.rb +14 -0
- data/generators/facebook_publisher/templates/create_facebook_templates.rb +15 -0
- data/generators/facebook_publisher/templates/publisher.rb +3 -0
- data/generators/facebook_scaffold/USAGE +27 -0
- data/generators/facebook_scaffold/facebook_scaffold_generator.rb +118 -0
- data/generators/facebook_scaffold/templates/controller.rb +93 -0
- data/generators/facebook_scaffold/templates/facebook_style.css +2579 -0
- data/generators/facebook_scaffold/templates/functional_test.rb +89 -0
- data/generators/facebook_scaffold/templates/helper.rb +2 -0
- data/generators/facebook_scaffold/templates/layout.fbml.erb +6 -0
- data/generators/facebook_scaffold/templates/layout.html.erb +17 -0
- data/generators/facebook_scaffold/templates/style.css +74 -0
- data/generators/facebook_scaffold/templates/view_edit.fbml.erb +13 -0
- data/generators/facebook_scaffold/templates/view_edit.html.erb +18 -0
- data/generators/facebook_scaffold/templates/view_index.fbml.erb +24 -0
- data/generators/facebook_scaffold/templates/view_index.html.erb +24 -0
- data/generators/facebook_scaffold/templates/view_new.fbml.erb +12 -0
- data/generators/facebook_scaffold/templates/view_new.html.erb +17 -0
- data/generators/facebook_scaffold/templates/view_show.fbml.erb +10 -0
- data/generators/facebook_scaffold/templates/view_show.html.erb +10 -0
- data/generators/publisher/publisher_generator.rb +14 -0
- data/generators/xd_receiver/templates/xd_receiver.html +10 -0
- data/generators/xd_receiver/xd_receiver_generator.rb +9 -0
- data/init.rb +70 -0
- data/install.rb +12 -0
- data/lib/facebooker.rb +160 -0
- data/lib/facebooker/adapters/adapter_base.rb +87 -0
- data/lib/facebooker/adapters/bebo_adapter.rb +75 -0
- data/lib/facebooker/adapters/facebook_adapter.rb +48 -0
- data/lib/facebooker/admin.rb +28 -0
- data/lib/facebooker/batch_request.rb +44 -0
- data/lib/facebooker/data.rb +57 -0
- data/lib/facebooker/feed.rb +78 -0
- data/lib/facebooker/logging.rb +51 -0
- data/lib/facebooker/model.rb +123 -0
- data/lib/facebooker/models/affiliation.rb +10 -0
- data/lib/facebooker/models/album.rb +11 -0
- data/lib/facebooker/models/applicationproperties.rb +39 -0
- data/lib/facebooker/models/cookie.rb +10 -0
- data/lib/facebooker/models/education_info.rb +11 -0
- data/lib/facebooker/models/event.rb +26 -0
- data/lib/facebooker/models/friend_list.rb +14 -0
- data/lib/facebooker/models/group.rb +35 -0
- data/lib/facebooker/models/info_item.rb +10 -0
- data/lib/facebooker/models/info_section.rb +10 -0
- data/lib/facebooker/models/location.rb +8 -0
- data/lib/facebooker/models/notifications.rb +17 -0
- data/lib/facebooker/models/page.rb +27 -0
- data/lib/facebooker/models/photo.rb +10 -0
- data/lib/facebooker/models/tag.rb +12 -0
- data/lib/facebooker/models/user.rb +369 -0
- data/lib/facebooker/models/work_info.rb +9 -0
- data/lib/facebooker/parser.rb +547 -0
- data/lib/facebooker/rails/controller.rb +280 -0
- data/lib/facebooker/rails/facebook_asset_path.rb +18 -0
- data/lib/facebooker/rails/facebook_form_builder.rb +112 -0
- data/lib/facebooker/rails/facebook_pretty_errors.rb +14 -0
- data/lib/facebooker/rails/facebook_request_fix.rb +24 -0
- data/lib/facebooker/rails/facebook_session_handling.rb +69 -0
- data/lib/facebooker/rails/facebook_url_helper.rb +191 -0
- data/lib/facebooker/rails/facebook_url_rewriting.rb +39 -0
- data/lib/facebooker/rails/helpers.rb +642 -0
- data/lib/facebooker/rails/helpers/fb_connect.rb +34 -0
- data/lib/facebooker/rails/profile_publisher_extensions.rb +42 -0
- data/lib/facebooker/rails/publisher.rb +511 -0
- data/lib/facebooker/rails/routing.rb +49 -0
- data/lib/facebooker/rails/test_helpers.rb +88 -0
- data/lib/facebooker/rails/utilities.rb +22 -0
- data/lib/facebooker/server_cache.rb +24 -0
- data/lib/facebooker/service.rb +83 -0
- data/lib/facebooker/session.rb +564 -0
- data/lib/facebooker/version.rb +9 -0
- data/lib/net/http_multipart_post.rb +123 -0
- data/lib/tasks/facebooker.rake +18 -0
- data/lib/tasks/tunnel.rake +46 -0
- data/rails/init.rb +1 -0
- data/setup.rb +1585 -0
- data/templates/layout.erb +24 -0
- data/test/adapters_test.rb +98 -0
- data/test/batch_request_test.rb +82 -0
- data/test/event_test.rb +15 -0
- data/test/facebook_admin_test.rb +76 -0
- data/test/facebook_cache_test.rb +44 -0
- data/test/facebook_data_test.rb +86 -0
- data/test/facebooker_test.rb +855 -0
- data/test/fixtures/multipart_post_body_with_only_parameters.txt +33 -0
- data/test/fixtures/multipart_post_body_with_single_file.txt +38 -0
- data/test/fixtures/multipart_post_body_with_single_file_that_has_nil_key.txt +38 -0
- data/test/http_multipart_post_test.rb +54 -0
- data/test/logging_test.rb +43 -0
- data/test/model_test.rb +91 -0
- data/test/publisher_test.rb +458 -0
- data/test/rails_integration_test.rb +1221 -0
- data/test/session_test.rb +613 -0
- data/test/test_helper.rb +60 -0
- data/test/user_test.rb +270 -0
- metadata +185 -0
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
--MichaelNiessnerIsSuperDuperAwesome
|
|
2
|
+
Content-Disposition: form-data; name="aid"
|
|
3
|
+
|
|
4
|
+
940915667462717
|
|
5
|
+
--MichaelNiessnerIsSuperDuperAwesome
|
|
6
|
+
Content-Disposition: form-data; name="api_key"
|
|
7
|
+
|
|
8
|
+
77a52842357422fadd912a2600e6e53c
|
|
9
|
+
--MichaelNiessnerIsSuperDuperAwesome
|
|
10
|
+
Content-Disposition: form-data; name="call_id"
|
|
11
|
+
|
|
12
|
+
1172623588.023010
|
|
13
|
+
--MichaelNiessnerIsSuperDuperAwesome
|
|
14
|
+
Content-Disposition: form-data; name="caption"
|
|
15
|
+
|
|
16
|
+
Under the sunset
|
|
17
|
+
--MichaelNiessnerIsSuperDuperAwesome
|
|
18
|
+
Content-Disposition: form-data; name="method"
|
|
19
|
+
|
|
20
|
+
facebook.photos.upload
|
|
21
|
+
--MichaelNiessnerIsSuperDuperAwesome
|
|
22
|
+
Content-Disposition: form-data; name="session_key"
|
|
23
|
+
|
|
24
|
+
489727d0ab2efc6e8003018c-i2LLkn8BDb2s.
|
|
25
|
+
--MichaelNiessnerIsSuperDuperAwesome
|
|
26
|
+
Content-Disposition: form-data; name="sig"
|
|
27
|
+
|
|
28
|
+
dfa724b8a5cd97d9df4baf2b60d3484c
|
|
29
|
+
--MichaelNiessnerIsSuperDuperAwesome
|
|
30
|
+
Content-Disposition: form-data; name="v"
|
|
31
|
+
|
|
32
|
+
1.0
|
|
33
|
+
--MichaelNiessnerIsSuperDuperAwesome--
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
--MichaelNiessnerIsSuperDuperAwesome
|
|
2
|
+
Content-Disposition: form-data; name="aid"
|
|
3
|
+
|
|
4
|
+
940915667462717
|
|
5
|
+
--MichaelNiessnerIsSuperDuperAwesome
|
|
6
|
+
Content-Disposition: form-data; name="api_key"
|
|
7
|
+
|
|
8
|
+
77a52842357422fadd912a2600e6e53c
|
|
9
|
+
--MichaelNiessnerIsSuperDuperAwesome
|
|
10
|
+
Content-Disposition: form-data; name="call_id"
|
|
11
|
+
|
|
12
|
+
1172623588.023010
|
|
13
|
+
--MichaelNiessnerIsSuperDuperAwesome
|
|
14
|
+
Content-Disposition: form-data; name="caption"
|
|
15
|
+
|
|
16
|
+
Under the sunset
|
|
17
|
+
--MichaelNiessnerIsSuperDuperAwesome
|
|
18
|
+
Content-Disposition: form-data; name="method"
|
|
19
|
+
|
|
20
|
+
facebook.photos.upload
|
|
21
|
+
--MichaelNiessnerIsSuperDuperAwesome
|
|
22
|
+
Content-Disposition: form-data; name="session_key"
|
|
23
|
+
|
|
24
|
+
489727d0ab2efc6e8003018c-i2LLkn8BDb2s.
|
|
25
|
+
--MichaelNiessnerIsSuperDuperAwesome
|
|
26
|
+
Content-Disposition: form-data; name="sig"
|
|
27
|
+
|
|
28
|
+
dfa724b8a5cd97d9df4baf2b60d3484c
|
|
29
|
+
--MichaelNiessnerIsSuperDuperAwesome
|
|
30
|
+
Content-Disposition: form-data; name="v"
|
|
31
|
+
|
|
32
|
+
1.0
|
|
33
|
+
--MichaelNiessnerIsSuperDuperAwesome
|
|
34
|
+
Content-Disposition: form-data; name="file"; filename="somefilename.jpg"
|
|
35
|
+
Content-Type: image/jpg
|
|
36
|
+
|
|
37
|
+
[Raw file data here]
|
|
38
|
+
--MichaelNiessnerIsSuperDuperAwesome--
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
--MichaelNiessnerIsSuperDuperAwesome
|
|
2
|
+
Content-Disposition: form-data; name="aid"
|
|
3
|
+
|
|
4
|
+
940915667462717
|
|
5
|
+
--MichaelNiessnerIsSuperDuperAwesome
|
|
6
|
+
Content-Disposition: form-data; name="api_key"
|
|
7
|
+
|
|
8
|
+
77a52842357422fadd912a2600e6e53c
|
|
9
|
+
--MichaelNiessnerIsSuperDuperAwesome
|
|
10
|
+
Content-Disposition: form-data; name="call_id"
|
|
11
|
+
|
|
12
|
+
1172623588.023010
|
|
13
|
+
--MichaelNiessnerIsSuperDuperAwesome
|
|
14
|
+
Content-Disposition: form-data; name="caption"
|
|
15
|
+
|
|
16
|
+
Under the sunset
|
|
17
|
+
--MichaelNiessnerIsSuperDuperAwesome
|
|
18
|
+
Content-Disposition: form-data; name="method"
|
|
19
|
+
|
|
20
|
+
facebook.photos.upload
|
|
21
|
+
--MichaelNiessnerIsSuperDuperAwesome
|
|
22
|
+
Content-Disposition: form-data; name="session_key"
|
|
23
|
+
|
|
24
|
+
489727d0ab2efc6e8003018c-i2LLkn8BDb2s.
|
|
25
|
+
--MichaelNiessnerIsSuperDuperAwesome
|
|
26
|
+
Content-Disposition: form-data; name="sig"
|
|
27
|
+
|
|
28
|
+
dfa724b8a5cd97d9df4baf2b60d3484c
|
|
29
|
+
--MichaelNiessnerIsSuperDuperAwesome
|
|
30
|
+
Content-Disposition: form-data; name="v"
|
|
31
|
+
|
|
32
|
+
1.0
|
|
33
|
+
--MichaelNiessnerIsSuperDuperAwesome
|
|
34
|
+
Content-Disposition: form-data; filename="somefilename.jpg"
|
|
35
|
+
Content-Type: image/jpg
|
|
36
|
+
|
|
37
|
+
[Raw file data here]
|
|
38
|
+
--MichaelNiessnerIsSuperDuperAwesome--
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper.rb'
|
|
2
|
+
require 'rubygems'
|
|
3
|
+
require 'flexmock/test_unit'
|
|
4
|
+
require 'net/http_multipart_post'
|
|
5
|
+
|
|
6
|
+
class HttpMulitpartPostTest < Test::Unit::TestCase
|
|
7
|
+
def setup
|
|
8
|
+
super
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def fixture(string)
|
|
12
|
+
File.open(File.dirname(__FILE__) + "/fixtures/#{string}.txt").read
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def test_multipart_post_with_only_parameters
|
|
16
|
+
params = add_sample_facebook_params({})
|
|
17
|
+
post = Net::HTTP::MultipartPost.new("uri", params)
|
|
18
|
+
assert_equal fixture("multipart_post_body_with_only_parameters"), post.send(:body)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def test_multipart_post_with_a_single_file
|
|
22
|
+
params = add_sample_facebook_params({})
|
|
23
|
+
params[:file] = Net::HTTP::MultipartPostFile.new
|
|
24
|
+
params[:file].filename = "somefilename.jpg"
|
|
25
|
+
params[:file].content_type = "image/jpg"
|
|
26
|
+
params[:file].data = "[Raw file data here]"
|
|
27
|
+
post = Net::HTTP::MultipartPost.new("uri", params)
|
|
28
|
+
assert_equal fixture("multipart_post_body_with_single_file"), post.send(:body)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def test_multipart_post_with_a_single_file_parameter_that_has_nil_key
|
|
32
|
+
params = add_sample_facebook_params({})
|
|
33
|
+
params[nil] = Net::HTTP::MultipartPostFile.new("somefilename.jpg", "image/jpg", "[Raw file data here]")
|
|
34
|
+
post = Net::HTTP::MultipartPost.new("uri", params)
|
|
35
|
+
assert_equal fixture("multipart_post_body_with_single_file_that_has_nil_key"), post.send(:body)
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def test_multipart_post_should_have_correct_content_type
|
|
39
|
+
post = Net::HTTP::MultipartPost.new("uri", {})
|
|
40
|
+
assert post.send(:content_type) =~ /multipart\/form-data; boundary=/
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def add_sample_facebook_params(hash)
|
|
44
|
+
hash[:method] = "facebook.photos.upload"
|
|
45
|
+
hash[:v] = "1.0"
|
|
46
|
+
hash[:api_key] = "77a52842357422fadd912a2600e6e53c"
|
|
47
|
+
hash[:session_key] = "489727d0ab2efc6e8003018c-i2LLkn8BDb2s."
|
|
48
|
+
hash[:call_id] = "1172623588.023010"
|
|
49
|
+
hash[:caption] = "Under the sunset"
|
|
50
|
+
hash[:aid] = "940915667462717"
|
|
51
|
+
hash[:sig] = "dfa724b8a5cd97d9df4baf2b60d3484c"
|
|
52
|
+
hash
|
|
53
|
+
end
|
|
54
|
+
end
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper.rb'
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class LoggingTest < Test::Unit::TestCase
|
|
5
|
+
def setup
|
|
6
|
+
super
|
|
7
|
+
Facebooker.logger = Logger.new(STDERR)
|
|
8
|
+
Facebooker::Logging.skip_api_logging=false
|
|
9
|
+
end
|
|
10
|
+
def teardown
|
|
11
|
+
Facebooker.logger = nil
|
|
12
|
+
super
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def test_does_not_crash_with_nil_logger
|
|
16
|
+
Facebooker.logger = nil
|
|
17
|
+
Facebooker::Logging.log_fb_api('sample.api.call',
|
|
18
|
+
{'param1' => true, 'param2' => 'value2'})
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def test_does_not_crash_outside_rails
|
|
22
|
+
flexmock(Facebooker.logger, :logger).should_receive(:debug).once.with(String)
|
|
23
|
+
Facebooker::Logging.log_fb_api('sample.api.call',
|
|
24
|
+
{'param1' => true, 'param2' => 'value2'})
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def test_can_disable_logging
|
|
28
|
+
Facebooker::Logging.skip_api_logging = true
|
|
29
|
+
flexmock(Facebooker::Logging).should_receive(:log_info).never
|
|
30
|
+
Facebooker::Logging.log_fb_api('sample.api.call',
|
|
31
|
+
{'param1' => true, 'param2' => 'value2'})
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def test_plain_format
|
|
35
|
+
flexmock(Facebooker.logger, :logger).should_receive(:debug).once.with(
|
|
36
|
+
'sample.api.call (0) param1 = true')
|
|
37
|
+
Facebooker::Logging.log_fb_api('sample.api.call',
|
|
38
|
+
{'param1' => true})
|
|
39
|
+
ensure
|
|
40
|
+
Facebooker.logger = nil
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
end
|
data/test/model_test.rb
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper.rb'
|
|
2
|
+
require 'rubygems'
|
|
3
|
+
require 'flexmock/test_unit'
|
|
4
|
+
|
|
5
|
+
class TestFacebooker < Test::Unit::TestCase
|
|
6
|
+
|
|
7
|
+
class ComplexThing
|
|
8
|
+
include Facebooker::Model
|
|
9
|
+
attr_accessor :weight, :height
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
class Thing
|
|
13
|
+
include Facebooker::Model
|
|
14
|
+
attr_accessor :name, :job
|
|
15
|
+
hash_settable_accessor :complex_thing, ComplexThing
|
|
16
|
+
hash_settable_list_accessor :list_of_complex_things, ComplexThing
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
class PopulatingThing
|
|
20
|
+
include Facebooker::Model
|
|
21
|
+
populating_attr_accessor :first_name
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def test_can_instantiate_an_object_with_a_hash
|
|
25
|
+
h = {:name => "Blob", :job => "Monster"}
|
|
26
|
+
assert_equal("Blob", Thing.from_hash(h).name)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def test_ignores_non_model_keys
|
|
30
|
+
h = {:name => "Blob", :job => "Monster", :not_there=>true}
|
|
31
|
+
assert_equal("Blob", Thing.from_hash(h).name)
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def test_logs_non_model_keys
|
|
35
|
+
flexmock(Facebooker::Logging).should_receive(:log_info)
|
|
36
|
+
h = {:name => "Blob", :job => "Monster", :not_there=>true}
|
|
37
|
+
Thing.from_hash(h)
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def test_if_no_hash_is_given_to_model_constructor_no_attributes_are_set
|
|
42
|
+
assert_nothing_raised {
|
|
43
|
+
t = Thing.new
|
|
44
|
+
assert_nil(t.name)
|
|
45
|
+
}
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def test_can_declare_hash_settable_attributes
|
|
49
|
+
t = Thing.new({})
|
|
50
|
+
t.complex_thing = {:weight => 123, :height => 5.4}
|
|
51
|
+
assert_equal(123, t.complex_thing.weight)
|
|
52
|
+
t.complex_thing = ComplexThing.new(:weight => 321)
|
|
53
|
+
assert_equal(321, t.complex_thing.weight)
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def test_can_declare_attributes_which_are_settable_via_a_list_of_hashes
|
|
57
|
+
t = Thing.new
|
|
58
|
+
t.list_of_complex_things = [{:weight => 444, :height => 123.0}, {:weight => 222, :height => 321.1}]
|
|
59
|
+
assert_equal("123.0, 321.1", t.list_of_complex_things.map{|ct| ct.height.to_s}.sort.join(', '))
|
|
60
|
+
t.list_of_complex_things = [ComplexThing.new(:weight => 555), ComplexThing.new(:weight => 111)]
|
|
61
|
+
assert_equal("111, 555", t.list_of_complex_things.map{|ct| ct.weight.to_s}.sort.join(', '))
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
def test_if_you_try_to_use_a_models_session_without_initializing_it_first_you_get_a_descriptive_error
|
|
65
|
+
t = Thing.new
|
|
66
|
+
assert_raises(Facebooker::Model::UnboundSessionException) {
|
|
67
|
+
t.session
|
|
68
|
+
}
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def test_populating_reader_will_call_populate_if_model_was_not_previously_populated
|
|
72
|
+
t = PopulatingThing.new
|
|
73
|
+
flexmock(t).should_receive(:populate).once
|
|
74
|
+
t.first_name
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
def test_populating_reader_will_not_call_populate_if_model_was_previously_populated
|
|
78
|
+
t = PopulatingThing.new
|
|
79
|
+
flexmock(t).should_receive(:populated?).and_return(true)
|
|
80
|
+
flexmock(t).should_receive(:populate).never
|
|
81
|
+
t.first_name
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
def test_attempting_to_access_a_populating_reader_will_raise_an_exception_if_populate_was_not_defined
|
|
85
|
+
t = PopulatingThing.new
|
|
86
|
+
assert_raises(NotImplementedError) {
|
|
87
|
+
t.first_name
|
|
88
|
+
}
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
|
|
@@ -0,0 +1,458 @@
|
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper.rb'
|
|
2
|
+
require 'rubygems'
|
|
3
|
+
require 'flexmock/test_unit'
|
|
4
|
+
require 'action_controller'
|
|
5
|
+
require 'action_controller/test_process'
|
|
6
|
+
require 'active_record'
|
|
7
|
+
require File.dirname(__FILE__)+'/../init'
|
|
8
|
+
require 'facebooker/rails/controller'
|
|
9
|
+
require 'facebooker/rails/helpers/fb_connect'
|
|
10
|
+
require 'facebooker/rails/helpers'
|
|
11
|
+
require 'facebooker/rails/publisher'
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
module SymbolHelper
|
|
15
|
+
def symbol_helper_loaded
|
|
16
|
+
true
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
module ModuleHelper
|
|
21
|
+
def module_helper_loaded
|
|
22
|
+
true
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
::RAILS_DEFAULT_LOGGER = Logger.new(STDOUT)
|
|
27
|
+
|
|
28
|
+
class TestPublisher < Facebooker::Rails::Publisher
|
|
29
|
+
|
|
30
|
+
helper :symbol
|
|
31
|
+
helper ModuleHelper
|
|
32
|
+
|
|
33
|
+
def action(f)
|
|
34
|
+
send_as :action
|
|
35
|
+
from f
|
|
36
|
+
title "Action Title"
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def templatized_action(f)
|
|
40
|
+
send_as :templatized_action
|
|
41
|
+
from f
|
|
42
|
+
title_template "Templatized Action Title"
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def story(to)
|
|
46
|
+
send_as :story
|
|
47
|
+
recipients to
|
|
48
|
+
title 'Story Title'
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def notification(to,f)
|
|
52
|
+
send_as :notification
|
|
53
|
+
recipients to
|
|
54
|
+
from f
|
|
55
|
+
fbml "Not"
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def email(to,f)
|
|
59
|
+
send_as :email
|
|
60
|
+
recipients to
|
|
61
|
+
from f
|
|
62
|
+
title "Email"
|
|
63
|
+
fbml 'text'
|
|
64
|
+
text fbml
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def render_notification(to,f)
|
|
68
|
+
send_as :notification
|
|
69
|
+
recipients to
|
|
70
|
+
from f
|
|
71
|
+
fbml render(:inline=>"<%=module_helper_loaded%>")
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def profile_update(to,f)
|
|
76
|
+
send_as :profile
|
|
77
|
+
recipients to
|
|
78
|
+
profile "profile"
|
|
79
|
+
profile_action "profile_action"
|
|
80
|
+
mobile_profile "mobile_profile"
|
|
81
|
+
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
def profile_update_with_profile_main(to,f)
|
|
85
|
+
send_as :profile
|
|
86
|
+
recipients to
|
|
87
|
+
from f
|
|
88
|
+
profile "profile"
|
|
89
|
+
profile_action "profile_action"
|
|
90
|
+
mobile_profile "mobile_profile"
|
|
91
|
+
profile_main "profile_main"
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
def ref_update(user)
|
|
95
|
+
send_as :ref
|
|
96
|
+
fbml "fbml"
|
|
97
|
+
handle "handle"
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
def user_action_template
|
|
101
|
+
one_line_story_template "{*actor*} did stuff with {*friend*}"
|
|
102
|
+
short_story_template "{*actor*} has a title {*friend*}", render(:inline=>"This is a test render")
|
|
103
|
+
full_story_template "{*actor*} did a lot","This is the full body",:img=>{:some_params=>true}
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
def simple_user_action_template
|
|
107
|
+
one_line_story_template "{*actor*} did stuff with {*friend*}"
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
def user_action_with_action_links_template
|
|
111
|
+
one_line_story_template "{*actor*} did stuff with {*friend*}"
|
|
112
|
+
short_story_template "{*actor*} has a title {*friend*}", render(:inline=>"This is a test render")
|
|
113
|
+
full_story_template "{*actor*} did a lot","This is the full body",:img=>{:some_params=>true}
|
|
114
|
+
action_links action_link("Source","HREF")
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
def user_action(user)
|
|
118
|
+
send_as :user_action
|
|
119
|
+
from user
|
|
120
|
+
data :friend=>"Mike"
|
|
121
|
+
end
|
|
122
|
+
def user_action_with_story_size(user)
|
|
123
|
+
send_as :user_action
|
|
124
|
+
from user
|
|
125
|
+
story_size ONE_LINE
|
|
126
|
+
story_size FULL
|
|
127
|
+
story_size SHORT
|
|
128
|
+
data :friend=>"Mike"
|
|
129
|
+
end
|
|
130
|
+
def user_action_no_data(user)
|
|
131
|
+
send_as :user_action
|
|
132
|
+
from user
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
def no_send_as(to)
|
|
136
|
+
recipients to
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
def invalid_send_as(to)
|
|
140
|
+
send_as :fake
|
|
141
|
+
recipients to
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
class FacebookTemplateTest < Test::Unit::TestCase
|
|
147
|
+
FacebookTemplate = Facebooker::Rails::Publisher::FacebookTemplate
|
|
148
|
+
|
|
149
|
+
def setup
|
|
150
|
+
super
|
|
151
|
+
@template = mock("facebook template")
|
|
152
|
+
FacebookTemplate.stubs(:register).returns(@template)
|
|
153
|
+
FacebookTemplate.clear_cache!
|
|
154
|
+
end
|
|
155
|
+
|
|
156
|
+
def test_find_or_register_calls_find_cached
|
|
157
|
+
FacebookTemplate.expects(:find_cached).with(TestPublisher,"simple_user_action").returns(@template)
|
|
158
|
+
assert_equal FacebookTemplate.for_class_and_method(TestPublisher,"simple_user_action"),@template
|
|
159
|
+
end
|
|
160
|
+
|
|
161
|
+
def test_find_cached_should_use_cached_if_it_exists
|
|
162
|
+
FacebookTemplate.cache(TestPublisher,"simple_user_action",@template)
|
|
163
|
+
assert_equal FacebookTemplate.find_cached(TestPublisher,"simple_user_action"), @template
|
|
164
|
+
|
|
165
|
+
end
|
|
166
|
+
|
|
167
|
+
def test_find_cached_should_call_find_in_db_if_not_in_cache
|
|
168
|
+
FacebookTemplate.expects(:find_in_db).with(TestPublisher,"simple_user_action").returns(@template)
|
|
169
|
+
assert_equal FacebookTemplate.find_cached(TestPublisher,"simple_user_action"), @template
|
|
170
|
+
end
|
|
171
|
+
|
|
172
|
+
def test_find_in_db_should_run_find
|
|
173
|
+
FacebookTemplate.expects(:find_by_template_name).with("TestPublisher::simple_user_action").returns(@template)
|
|
174
|
+
@template.stubs(:template_changed?).returns(false)
|
|
175
|
+
assert_equal FacebookTemplate.find_in_db(TestPublisher,"simple_user_action"), @template
|
|
176
|
+
end
|
|
177
|
+
|
|
178
|
+
def test_find_in_db_should_register_if_not_found
|
|
179
|
+
FacebookTemplate.expects(:find_by_template_name).with("TestPublisher::simple_user_action").returns(nil)
|
|
180
|
+
FacebookTemplate.expects(:register).with(TestPublisher,"simple_user_action").returns(@template)
|
|
181
|
+
FacebookTemplate.find_cached(TestPublisher,"simple_user_action")
|
|
182
|
+
|
|
183
|
+
end
|
|
184
|
+
|
|
185
|
+
def test_find_in_db_should_check_for_change_if_found
|
|
186
|
+
FacebookTemplate.stubs(:find_by_template_name).returns(@template)
|
|
187
|
+
FacebookTemplate.stubs(:hashed_content).returns("MY CONTENT")
|
|
188
|
+
@template.expects(:template_changed?).with("MY CONTENT").returns(false)
|
|
189
|
+
FacebookTemplate.find_in_db(TestPublisher,"simple_user_action")
|
|
190
|
+
end
|
|
191
|
+
|
|
192
|
+
def test_find_in_db_should_destroy_old_record_if_changed
|
|
193
|
+
FacebookTemplate.stubs(:find_by_template_name).returns(@template)
|
|
194
|
+
FacebookTemplate.stubs(:hashed_content).returns("MY CONTENT")
|
|
195
|
+
@template.stubs(:template_changed?).returns(true)
|
|
196
|
+
@template.expects(:destroy)
|
|
197
|
+
FacebookTemplate.find_in_db(TestPublisher,"simple_user_action")
|
|
198
|
+
end
|
|
199
|
+
|
|
200
|
+
def test_find_in_db_should_re_register_if_changed
|
|
201
|
+
FacebookTemplate.stubs(:find_by_template_name).with("TestPublisher::simple_user_action").returns(@template)
|
|
202
|
+
FacebookTemplate.stubs(:hashed_content).returns("MY CONTENT")
|
|
203
|
+
@template.stubs(:template_changed?).returns(true)
|
|
204
|
+
@template.stubs(:destroy)
|
|
205
|
+
FacebookTemplate.expects(:register).with(TestPublisher,"simple_user_action").returns(@template)
|
|
206
|
+
FacebookTemplate.find_in_db(TestPublisher,"simple_user_action")
|
|
207
|
+
end
|
|
208
|
+
end
|
|
209
|
+
|
|
210
|
+
class PublisherTest < Test::Unit::TestCase
|
|
211
|
+
FacebookTemplate = Facebooker::Rails::Publisher::FacebookTemplate
|
|
212
|
+
|
|
213
|
+
def setup
|
|
214
|
+
super
|
|
215
|
+
@user = Facebooker::User.new
|
|
216
|
+
@user.id=4
|
|
217
|
+
@session = "session"
|
|
218
|
+
@user.stubs(:session).returns(@session)
|
|
219
|
+
end
|
|
220
|
+
|
|
221
|
+
def teardown
|
|
222
|
+
super
|
|
223
|
+
end
|
|
224
|
+
|
|
225
|
+
def test_create_action
|
|
226
|
+
action=TestPublisher.create_action(@user)
|
|
227
|
+
assert_equal Facebooker::Feed::Action,action.class
|
|
228
|
+
assert_equal "Action Title",action.title
|
|
229
|
+
end
|
|
230
|
+
|
|
231
|
+
def test_deliver_action
|
|
232
|
+
@user.expects(:publish_action)
|
|
233
|
+
TestPublisher.deliver_action(@user)
|
|
234
|
+
end
|
|
235
|
+
|
|
236
|
+
def test_create_story
|
|
237
|
+
action=TestPublisher.create_story(@user)
|
|
238
|
+
assert_equal Facebooker::Feed::Story,action.class
|
|
239
|
+
assert_equal "Story Title",action.title
|
|
240
|
+
end
|
|
241
|
+
|
|
242
|
+
def test_deliver_story
|
|
243
|
+
@user.expects(:publish_story)
|
|
244
|
+
TestPublisher.deliver_story(@user)
|
|
245
|
+
end
|
|
246
|
+
|
|
247
|
+
def test_create_notification
|
|
248
|
+
notification=TestPublisher.create_notification(12451752,@user)
|
|
249
|
+
assert_equal Facebooker::Rails::Publisher::Notification,notification.class
|
|
250
|
+
assert_equal "Not",notification.fbml
|
|
251
|
+
end
|
|
252
|
+
|
|
253
|
+
def test_deliver_notification
|
|
254
|
+
@session.expects(:send_notification)
|
|
255
|
+
TestPublisher.deliver_notification("12451752",@user)
|
|
256
|
+
end
|
|
257
|
+
|
|
258
|
+
def test_create_email
|
|
259
|
+
email=TestPublisher.create_email("12451752",@user)
|
|
260
|
+
assert_equal Facebooker::Rails::Publisher::Email,email.class
|
|
261
|
+
assert_equal "Email",email.title
|
|
262
|
+
assert_equal "text",email.text
|
|
263
|
+
assert_equal "text",email.fbml
|
|
264
|
+
end
|
|
265
|
+
|
|
266
|
+
def test_deliver_email
|
|
267
|
+
@session.expects(:send_email)
|
|
268
|
+
TestPublisher.deliver_email("12451752",@user)
|
|
269
|
+
end
|
|
270
|
+
|
|
271
|
+
def test_create_templatized_action
|
|
272
|
+
ta=TestPublisher.create_templatized_action(@user)
|
|
273
|
+
assert_equal Facebooker::Feed::TemplatizedAction,ta.class
|
|
274
|
+
assert_equal "Templatized Action Title",ta.title_template
|
|
275
|
+
|
|
276
|
+
end
|
|
277
|
+
|
|
278
|
+
|
|
279
|
+
|
|
280
|
+
def test_deliver_templatized_action
|
|
281
|
+
@user.expects(:publish_action)
|
|
282
|
+
TestPublisher.deliver_templatized_action(@user)
|
|
283
|
+
end
|
|
284
|
+
def test_create_profile_update
|
|
285
|
+
p=TestPublisher.create_profile_update(@user,@user)
|
|
286
|
+
assert_equal Facebooker::Rails::Publisher::Profile,p.class
|
|
287
|
+
assert_equal "profile",p.profile
|
|
288
|
+
assert_equal "profile_action",p.profile_action
|
|
289
|
+
assert_equal "mobile_profile",p.mobile_profile
|
|
290
|
+
end
|
|
291
|
+
def test_create_profile_update_with_profile_main
|
|
292
|
+
p=TestPublisher.create_profile_update_with_profile_main(@user,@user)
|
|
293
|
+
assert_equal Facebooker::Rails::Publisher::Profile,p.class
|
|
294
|
+
assert_equal "profile",p.profile
|
|
295
|
+
assert_equal "profile_action",p.profile_action
|
|
296
|
+
assert_equal "mobile_profile",p.mobile_profile
|
|
297
|
+
assert_equal "profile_main",p.profile_main
|
|
298
|
+
end
|
|
299
|
+
|
|
300
|
+
|
|
301
|
+
def test_deliver_profile
|
|
302
|
+
Facebooker::User.stubs(:new).returns(@user)
|
|
303
|
+
@user.expects(:set_profile_fbml).with('profile', 'mobile_profile', 'profile_action',nil)
|
|
304
|
+
TestPublisher.deliver_profile_update(@user,@user)
|
|
305
|
+
end
|
|
306
|
+
|
|
307
|
+
def test_deliver_profile_with_main
|
|
308
|
+
Facebooker::User.stubs(:new).returns(@user)
|
|
309
|
+
@user.expects(:set_profile_fbml).with('profile', 'mobile_profile', 'profile_action','profile_main')
|
|
310
|
+
TestPublisher.deliver_profile_update_with_profile_main(@user,@user)
|
|
311
|
+
end
|
|
312
|
+
|
|
313
|
+
|
|
314
|
+
def test_create_ref_update
|
|
315
|
+
p=TestPublisher.create_ref_update(@user)
|
|
316
|
+
assert_equal Facebooker::Rails::Publisher::Ref,p.class
|
|
317
|
+
assert_equal "fbml",p.fbml
|
|
318
|
+
assert_equal "handle",p.handle
|
|
319
|
+
end
|
|
320
|
+
|
|
321
|
+
def test_deliver_ref_update
|
|
322
|
+
Facebooker::Session.stubs(:create).returns(@session)
|
|
323
|
+
@server_cache="server_cache"
|
|
324
|
+
@session.expects(:server_cache).returns(@server_cache)
|
|
325
|
+
@server_cache.expects(:set_ref_handle).with("handle","fbml")
|
|
326
|
+
TestPublisher.deliver_ref_update(@user)
|
|
327
|
+
end
|
|
328
|
+
|
|
329
|
+
def test_register_user_action
|
|
330
|
+
Facebooker::Rails::Publisher::FacebookTemplate.expects(:register)
|
|
331
|
+
TestPublisher.register_user_action
|
|
332
|
+
end
|
|
333
|
+
def test_register_user_action_with_action_links
|
|
334
|
+
ActionController::Base.append_view_path("./test/../../app/views")
|
|
335
|
+
Facebooker::Rails::Publisher::FacebookTemplate.expects(:register)
|
|
336
|
+
TestPublisher.register_user_action_with_action_links
|
|
337
|
+
end
|
|
338
|
+
|
|
339
|
+
def test_create_user_action
|
|
340
|
+
@from_user = Facebooker::User.new
|
|
341
|
+
@session = Facebooker::Session.new("","")
|
|
342
|
+
@from_user.stubs(:session).returns(@session)
|
|
343
|
+
Facebooker::Rails::Publisher::FacebookTemplate.expects(:bundle_id_for_class_and_method).
|
|
344
|
+
with(TestPublisher,'user_action').
|
|
345
|
+
returns(20309041537)
|
|
346
|
+
ua = TestPublisher.create_user_action(@from_user)
|
|
347
|
+
assert_equal "user_action", ua.template_name
|
|
348
|
+
end
|
|
349
|
+
|
|
350
|
+
def test_publisher_user_action
|
|
351
|
+
@from_user = Facebooker::User.new
|
|
352
|
+
@session = Facebooker::Session.new("","")
|
|
353
|
+
@from_user.stubs(:session).returns(@session)
|
|
354
|
+
@session.expects(:publish_user_action).with(20309041537,{:friend=>"Mike"},nil,nil)
|
|
355
|
+
|
|
356
|
+
Facebooker::Rails::Publisher::FacebookTemplate.expects(:bundle_id_for_class_and_method).
|
|
357
|
+
with(TestPublisher, 'user_action').
|
|
358
|
+
returns(20309041537)
|
|
359
|
+
# pseudo_template = Struct.new(:bundle_id, :content_hash).new(20309041537, '')
|
|
360
|
+
# pseudo_template.expects(:matches_content?).returns(true)
|
|
361
|
+
# Facebooker::Rails::Publisher::FacebookTemplate.expects(:for).returns(pseudo_template)
|
|
362
|
+
TestPublisher.deliver_user_action(@from_user)
|
|
363
|
+
end
|
|
364
|
+
|
|
365
|
+
def test_publish_user_action_with_story_size
|
|
366
|
+
@from_user = Facebooker::User.new
|
|
367
|
+
@session = Facebooker::Session.new("","")
|
|
368
|
+
@from_user.stubs(:session).returns(@session)
|
|
369
|
+
@session.expects(:publish_user_action).with(20309041537,{:friend=>"Mike", :story_size=>2},nil,nil)
|
|
370
|
+
|
|
371
|
+
Facebooker::Rails::Publisher::FacebookTemplate.expects(:bundle_id_for_class_and_method).
|
|
372
|
+
with(TestPublisher, 'user_action_with_story_size').
|
|
373
|
+
returns(20309041537)
|
|
374
|
+
TestPublisher.deliver_user_action_with_story_size(@from_user)
|
|
375
|
+
|
|
376
|
+
end
|
|
377
|
+
|
|
378
|
+
def test_publishing_user_data_no_action_gives_nil_hash
|
|
379
|
+
@from_user = Facebooker::User.new
|
|
380
|
+
@session = Facebooker::Session.new("","")
|
|
381
|
+
@from_user.stubs(:session).returns(@session)
|
|
382
|
+
@session.expects(:publish_user_action).with(20309041537,{},nil,nil)
|
|
383
|
+
|
|
384
|
+
Facebooker::Rails::Publisher::FacebookTemplate.stubs(:bundle_id_for_class_and_method).returns(20309041537)
|
|
385
|
+
TestPublisher.deliver_user_action_no_data(@from_user)
|
|
386
|
+
end
|
|
387
|
+
def test_no_sends_as_raises
|
|
388
|
+
assert_raises(Facebooker::Rails::Publisher::UnspecifiedBodyType) {
|
|
389
|
+
TestPublisher.deliver_no_send_as(@user)
|
|
390
|
+
}
|
|
391
|
+
end
|
|
392
|
+
|
|
393
|
+
def test_invalid_send_as_raises
|
|
394
|
+
assert_raises(Facebooker::Rails::Publisher::UnknownBodyType) {
|
|
395
|
+
TestPublisher.deliver_invalid_send_as(@user)
|
|
396
|
+
}
|
|
397
|
+
end
|
|
398
|
+
|
|
399
|
+
|
|
400
|
+
def test_keeps_class_method_missing
|
|
401
|
+
assert_raises(NoMethodError) {
|
|
402
|
+
TestPublisher.fake
|
|
403
|
+
}
|
|
404
|
+
end
|
|
405
|
+
def test_keeps_instance_method_missing
|
|
406
|
+
assert_raises(NoMethodError) {
|
|
407
|
+
TestPublisher.new.fake
|
|
408
|
+
}
|
|
409
|
+
end
|
|
410
|
+
|
|
411
|
+
def test_image_urls
|
|
412
|
+
Facebooker.expects(:facebook_path_prefix).returns("/mike")
|
|
413
|
+
assert_equal({:src => '/images/image.png', :href => 'raw_string' },
|
|
414
|
+
TestPublisher.new.image('image.png', 'raw_string'))
|
|
415
|
+
assert_equal({:src => '/images/image.png', :href => 'http://apps.facebook.com/mike/pokes/do/1' },
|
|
416
|
+
TestPublisher.new.image('image.png', {:controller => :pokes, :action => :do, :id => 1}))
|
|
417
|
+
end
|
|
418
|
+
|
|
419
|
+
def test_action_link
|
|
420
|
+
assert_equal({:text=>"text", :href=>"href"}, TestPublisher.new.action_link("text","href"))
|
|
421
|
+
end
|
|
422
|
+
|
|
423
|
+
def test_default_url_options
|
|
424
|
+
Facebooker.expects(:facebook_path_prefix).returns("/mike")
|
|
425
|
+
assert_equal({:host=>"apps.facebook.com/mike"},TestPublisher.default_url_options)
|
|
426
|
+
end
|
|
427
|
+
|
|
428
|
+
def test_recipients
|
|
429
|
+
tp=TestPublisher.new
|
|
430
|
+
tp.recipients "a"
|
|
431
|
+
assert_equal("a",tp.recipients)
|
|
432
|
+
end
|
|
433
|
+
|
|
434
|
+
def test_symbol_helper
|
|
435
|
+
assert TestPublisher.new.symbol_helper_loaded
|
|
436
|
+
end
|
|
437
|
+
def test_module_helper
|
|
438
|
+
assert TestPublisher.new.module_helper_loaded
|
|
439
|
+
end
|
|
440
|
+
|
|
441
|
+
def test_with_render
|
|
442
|
+
#normally Rails would do this for us
|
|
443
|
+
if ActionController::Base.respond_to?(:append_view_path)
|
|
444
|
+
ActionController::Base.append_view_path("./test/../../app/views")
|
|
445
|
+
end
|
|
446
|
+
notification=TestPublisher.create_render_notification(12451752,@user)
|
|
447
|
+
assert_equal "true",notification.fbml
|
|
448
|
+
end
|
|
449
|
+
|
|
450
|
+
def test_notification_as_announcement
|
|
451
|
+
#normally Rails would do this for us
|
|
452
|
+
if ActionController::Base.respond_to?(:append_view_path)
|
|
453
|
+
ActionController::Base.append_view_path("./test/../../app/views")
|
|
454
|
+
end
|
|
455
|
+
notification=TestPublisher.create_render_notification(12451752,nil)
|
|
456
|
+
assert_equal "true",notification.fbml
|
|
457
|
+
end
|
|
458
|
+
end
|