Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed specs; remove strange spec for canvas permission check

  • Loading branch information...
commit 7ff18b350dd17aca3ff3fb31f02a4342b8b59463 1 parent 86306b7
@dekart authored
View
2  lib/facebooker2/rails/controller.rb
@@ -96,6 +96,8 @@ def fb_cookie_hash
hash[parts.first] = parts.last
end
+
+ hash
end
def fb_cookie?
View
4 lib/facebooker2/rails/controller/canvas_oauth.rb
@@ -13,9 +13,9 @@ def facebook_oauth_connect
# under the Authentication docs at http://developers.facebook.com/docs/authentication/)
if params[:code]
begin
- redirect_to Facebooker2.canvas_page_url + facebook_url_encryptor.decrypt(params[:fb_return_to])
+ redirect_to Facebooker2.canvas_page_url + facebook_url_encryptor.decrypt(params[:fb_return_to].to_s)
rescue ActiveSupport::MessageEncryptor::InvalidMessage
- Rails.logger.fatal "Failed to decrypt return URL: #{ params[:fb_return_to] }"
+ ::Rails.logger.fatal "Failed to decrypt return URL: #{ params[:fb_return_to] }"
redirect_to Facebooker2.canvas_page_url
end
View
2  lib/facebooker2/rails/helpers/facebook_connect.rb
@@ -52,7 +52,7 @@ def fb_server_fbml(style = nil, &proc)
concat(
content_tag('fb:serverFbml',
- content_tag(:script, content.html_safe, :type => 'text/fbml'),
+ content_tag(:script, content.try(:html_safe) || content, :type => 'text/fbml'),
:style => style
)
)
View
4 lib/facebooker2/rails/helpers/javascript.rb
@@ -70,12 +70,12 @@ def fb_connect_js(*args, &block)
JAVASCRIPT
js = <<-CODE
- <div id='fb-root'></div>
+ <div id="fb-root"></div>
<script type="text/javascript">#{ js }</script>
CODE
else
js = <<-CODE
- <div id='fb-root'></div>
+ <div id="fb-root"></div>
<script src="http://#{ js_url }" type="text/javascript"></script>
CODE
View
5 spec/facebooker2_spec.rb
@@ -32,18 +32,17 @@
end
it "can load the configuration via facebooker.yml" do
- ::Rails=mock("rails",:env=>"spec",:root=>File.dirname(__FILE__))
Facebooker2.load_facebooker_yaml
Facebooker2.app_id.should == "1234fromyaml"
Facebooker2.secret.should == "fromyaml"
end
it "raises an error if there is no configuration for the env" do
- ::Rails=mock("rails",:env=>"invalid",:root=>File.dirname(__FILE__))
+ ::Rails.stub!(:env).and_return('invalid')
+
lambda do
Facebooker2.load_facebooker_yaml
end.should raise_error(Facebooker2::NotConfigured)
-
end
end
View
6 spec/helpers/facebook_connect_spec.rb
@@ -30,21 +30,21 @@
fb_server_fbml do
end
- output_buffer.should == "<fb:serverFbml><script type='text/fbml'></script></fb:serverFbml>"
+ output_buffer.should == "<fb:serverFbml><script type=\"text/fbml\"></script></fb:serverFbml>"
end
it "includes the content inside the block" do
fb_server_fbml do
"inner text"
end
- output_buffer.should == "<fb:serverFbml><script type='text/fbml'>inner text</script></fb:serverFbml>"
+ output_buffer.should == "<fb:serverFbml><script type=\"text/fbml\">inner text</script></fb:serverFbml>"
end
it "allows specifying style attributes" do
fb_server_fbml "width: 750px;" do
end
- output_buffer.should == "<fb:serverFbml style=\"width: 750px;\"><script type='text/fbml'></script></fb:serverFbml>"
+ output_buffer.should == "<fb:serverFbml style=\"width: 750px;\"><script type=\"text/fbml\"></script></fb:serverFbml>"
end
end
View
10 spec/helpers/javascript_spec.rb
@@ -4,23 +4,25 @@
describe "fb_connect_async_js" do
it "loads with defaults" do
js = fb_connect_async_js '12345'
- js.should == <<-JAVASCRIPT
+ js.gsub(/\s+/, ' ').should == <<-JAVASCRIPT.gsub!(/\s+/, ' ')
<div id="fb-root"></div>
- <script>
+ <script type="text/javascript">
window.fbAsyncInit = function() {
FB.init({
appId : '12345',
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
- xfbml : true // parse XFBML
+ xfbml : true, // parse XFBML
+ channelUrl : 'null'
});
};
(function() {
- var e = document.createElement('script'); e.async = true;
+ var e = document.createElement('script');
e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
+ e.async = true;
document.getElementById('fb-root').appendChild(e);
}());
</script>
View
57 spec/rails/controller/canvas_oauth_spec.rb
@@ -3,18 +3,21 @@
class FakeCanvasOAuthController < ActionController::Base
include Facebooker2::Rails::Controller::CanvasOAuth
+ before_filter :check_connection_and_permissions
+
def callback_url
"my url"
end
+
+ def check_connection_and_permissions
+ ensure_canvas_connected(:permission, :other)
+ end
end
describe Facebooker2::Rails::Controller::CanvasOAuth do
before(:each) do
Facebooker2.canvas_page_name = 'my-application'
Facebooker2.app_id = '12345'
-
- FakeCanvasOAuthController._facebooker_oauth_callback_url = nil
- FakeCanvasOAuthController._facebooker_scope = nil
end
let :controller do
@@ -22,9 +25,9 @@ def callback_url
end
describe "should extend with OAuth class methods" do
- [ :ensure_canvas_connected_to_facebook, :create_facebook_oauth_callback ].each do |method|
+ [ :ensure_canvas_connected, :facebook_oauth_connect ].each do |method|
it "#{method}" do
- controller.class.respond_to?(method).should be_true
+ controller.respond_to?(method).should be_true
end
end
end
@@ -33,60 +36,26 @@ def callback_url
it "should fail if no canvas page is defined" do
Facebooker2.canvas_page_name = nil
- lambda { controller.send(:canvas_oauth_connect) }.should raise_error
+ lambda { controller.send(:facebook_oauth_connect) }.should raise_error
end
it "should throw an OAuth exception if there was an error in authenticating" do
controller.stub!(:params).and_return(:error => { :message => 'User denied access.' })
- lambda { controller.send(:canvas_oauth_connect) }.should raise_error(Facebooker2::OAuthException, 'User denied access.')
+ lambda { controller.send(:facebook_oauth_connect) }.should raise_error(Facebooker2::OAuthException, 'User denied access.')
end
it "should throw an OAuth exception if no code is returned" do
controller.stub!(:params).and_return({})
- lambda { controller.send(:canvas_oauth_connect) }.should raise_error(Facebooker2::OAuthException, 'No code returned.')
+ lambda { controller.send(:facebook_oauth_connect) }.should raise_error(Facebooker2::OAuthException, 'No code returned.')
end
it "should redirect to the canvas application on success" do
controller.stub!(:params).and_return(:code => '12345')
- controller.expects(:redirect_to).with('http://apps.facebook.com/my-application')
- controller.send(:canvas_oauth_connect)
+ controller.should_receive(:redirect_to).with('http://apps.facebook.com/my-application')
+ controller.send(:facebook_oauth_connect)
end
end
- describe "Ensuring canvas is connected" do
- describe "with a Symbol for a callback URL" do
- before(:each) do
- FakeCanvasOAuthController._facebooker_oauth_callback_url = :my_url
- FakeCanvasOAuthController._facebooker_scope = %w{permission other}
- end
-
- it "should render a redirect if none of the three pieces of info are defined" do
- controller.stub!(:current_facebook_user).and_return(nil)
- controller.stub!(:params).and_return({})
- controller.expects(:render).with() { |hash|
- hash[:text][Facebooker2.app_id] != nil &&
- hash[:text]["my url"] != nil &&
- hash[:text]["scope=permission,other"] != nil
- }
- end
-
- describe "should not render a redirect if" do
- it "a user if found" do
- controller.stub!(:current_facebook_user).and_return(true)
- controller.stub!(:params).and_return({})
- controller.expects(:render).never
- end
-
- [ :code, :error ].each do |param|
- it "param[:#{param}] exists" do
- controller.stub!(:current_facebook_user).and_return(nil)
- controller.stub!(:params).and_return(param => param)
- controller.expects(:render).never
- end
- end
- end
- end
- end
end
View
5 spec/rails/controller_spec.rb
@@ -13,6 +13,11 @@ class FakeController < ActionController::Base
let :controller do
controller = FakeController.new
controller.stub!(:params).and_return({})
+ controller.stub!(:request).and_return(
+ mock('environment variables',
+ :env => {'HTTP_SIGNED_REQUEST' => 'N1JJFILX63MufS1zpHZwN109VK1ggzEsD0N4pH-yPtc.eyJhbGdvcml0aG0iOiJITUFDLVNIQTI1NiIsImV4cGlyZXMiOjEyNzk4MjE2MDAsIm9hdXRoX3Rva2VuIjoiMTAzMTg4NzE2Mzk2NzI1fDIucnJRSktyRzFRYXpGYTFoa2Z6MWpMZ19fLjM2MDAuMTI3OTgyMTYwMC01MzI4Mjg4Njh8TWF4QVdxTWtVS3lKbEFwOVgwZldGWEF0M004LiIsInVzZXJfaWQiOiI1MzI4Mjg4NjgifQ'}
+ )
+ )
controller.stub!(:cookies).and_return("fbs_12345"=>"\"access_token=114355055262088|57f0206b01ad48bf84ac86f1-12451752|63WyZjRQbzowpN8ibdIfrsg80OA.&expires=0&secret=1e3375dcc4527e7ead0f82c095421690&session_key=57f0206b01ad48bf84ac86f1-12451752&sig=4337fcdee4cc68bb70ec495c0eebf89c&uid=12451752\"")
controller
end
View
14 spec/spec_helper.rb
@@ -37,4 +37,16 @@ class ApplicationController < ActionController::Base
Spec::Example::ExampleGroupFactory.default(ActiveSupport::TestCase)
-
+class Rails
+ def self.env
+ 'spec'
+ end
+
+ def self.root
+ Pathname.new(File.dirname(__FILE__))
+ end
+
+ def self.logger
+ Logger.new(STDOUT)
+ end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.