netshade-facebooker 1.0.6

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