From 9bd0e009860537e462bcb5dfa685f101d6d212cb Mon Sep 17 00:00:00 2001 From: Mike Mangino Date: Thu, 6 May 2010 11:00:33 -0400 Subject: [PATCH] Added request form --- .../rails/helpers/request_forms.rb | 17 ++++++++++++ spec/helpers/request_forms_spec.rb | 27 +++++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/lib/facebooker2/rails/helpers/request_forms.rb b/lib/facebooker2/rails/helpers/request_forms.rb index 5ac74d4..472c133 100644 --- a/lib/facebooker2/rails/helpers/request_forms.rb +++ b/lib/facebooker2/rails/helpers/request_forms.rb @@ -10,6 +10,23 @@ module Facebooker2 options = fb_stringify_vals({:showborder=>false,:actiontext=>message,:max=>20}.merge(options.dup)) tag("fb:multi-friend-selector",options) end + + def fb_request_form(type,url,message,options={},&block) + content = capture(&block) + concat(content_tag("fb:request-form", content.to_s + fb_forgery_protection_token_tag, + {:action=>url,:method=>"post",:invite=>true,:type=>type,:content=>message}.merge(options))) + end + + + def fb_forgery_protection_token_tag + unless protect_against_forgery? + '' + else + tag(:input, :type => "hidden", :name => request_forgery_protection_token.to_s, :value => form_authenticity_token) + end + end + + end end end diff --git a/spec/helpers/request_forms_spec.rb b/spec/helpers/request_forms_spec.rb index 04d9d71..57e2592 100644 --- a/spec/helpers/request_forms_spec.rb +++ b/spec/helpers/request_forms_spec.rb @@ -18,4 +18,31 @@ describe Facebooker2::Rails::Helpers::RequestForms, :type=>:helper do end end + + describe "request form" do + it "includes the name, url, and a message" do + fb_request_form "Title","URL","message" do + end + @output_buffer.should == "" + + end + + it "renders the yielded content" do + fb_request_form "Title","URL","message" do + "yielded" + end + @output_buffer.should =~ /yielded/ + end + + it "allows you to override params" do + fb_request_form "Title","URL","message",:invite=>false do + end + @output_buffer.should =~ /invite="false"/ + + end + + + end + + end \ No newline at end of file