Skip to content

Commit

Permalink
fixed bug with options not being initialized to false and added tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pomartel committed Apr 1, 2011
1 parent a626851 commit 7266fb6
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/facebooker2/rails/helpers/javascript.rb
Expand Up @@ -13,9 +13,9 @@ def fb_html_safe(str)

def fb_connect_async_js(app_id=Facebooker2.app_id,options={},&proc)
opts = Hash.new.merge!(options)
cookie = opts[:cookie] || true
status = opts[:status] || true
xfbml = opts[:xfbml] || true
cookie = opts[:cookie].nil? ? true : opts[:cookie]
status = opts[:status].nil? ? true : opts[:status]
xfbml = opts[:xfbml].nil? ? true : opts[:xfbml]
channel_url = opts[:channel_url]
lang = opts[:locale] || 'en_US'
extra_js = capture(&proc) if block_given?
Expand Down
65 changes: 65 additions & 0 deletions spec/helpers/javascript_spec.rb
@@ -0,0 +1,65 @@
require "spec_helper"
describe Facebooker2::Rails::Helpers::Javascript, :type=>:helper do
include Facebooker2::Rails::Helpers
describe "fb_connect_async_js" do
it "loads with defaults" do
js = fb_connect_async_js '12345'
js.should == <<-JAVASCRIPT
<div id="fb-root"></div>
<script>
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
});
};
(function() {
var e = document.createElement('script'); e.async = true;
e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
document.getElementById('fb-root').appendChild(e);
}());
</script>
JAVASCRIPT
end

it "disables cookies" do
js = fb_connect_async_js '12345', :cookie => false
js.include?("cookie : false").should be_true, js
end

it "disables checking login status" do
js = fb_connect_async_js '12345', :status => false
js.include?("status : false").should be_true, js
end

it "disables xfbml parsing" do
js = fb_connect_async_js '12345', :xfbml => false
js.include?("xfbml : false").should be_true, js
end

it "adds a channel url" do
js = fb_connect_async_js '12345', :channel_url => 'http://channel.url'
js.include?("channelUrl : 'http://channel.url'").should be_true, js
end

it "changes the default locale" do
js = fb_connect_async_js '12345', :locale => 'fr_FR'
js.include?("//connect.facebook.net/fr_FR/all.js").should be_true, js
end

# Can't get this to work!
# it "adds extra js" do
# helper.output_buffer = ""
# fb_connect_async_js do
# "FB.Canvas.setAutoResize();"
# end
# helper.output_buffer.include?("FB.Canvas.setAutoResize();").should be_true, helper.output_buffer
# end

end
end

0 comments on commit 7266fb6

Please sign in to comment.