Permalink
Browse files

Add some tests.

  • Loading branch information...
1 parent 1b2022e commit 279dde338b54fb855f14394e5c34dcbc236bd682 pivotal-sumuru committed Jun 24, 2011
Showing with 76 additions and 25 deletions.
  1. +8 −0 .gitignore
  2. +3 −0 Gemfile
  3. +16 −0 Gemfile.lock
  4. +44 −0 spec/rack/facebook/method_fix_spec.rb
  5. +5 −0 spec/spec_helper.rb
  6. +0 −18 test/helper.rb
  7. +0 −7 test/test_rack-facebook-method-fix.rb
View
8 .gitignore
@@ -40,3 +40,11 @@ pkg
#
# For vim:
#*.swp
+.idea/.name
+.idea/.rakeTasks
+.idea/encodings.xml
+.idea/misc.xml
+.idea/modules.xml
+.idea/rack-facebook-method-fix.iml
+.idea/vcs.xml
+.idea/workspace.xml
View
3 Gemfile
@@ -10,4 +10,7 @@ group :development do
gem "bundler", "~> 1.0.0"
gem "jeweler", "~> 1.5.2"
gem "rcov", ">= 0"
+ gem "json"
+ gem "rspec"
+ gem "rack-test"
end
View
16 Gemfile.lock
@@ -1,13 +1,26 @@
GEM
remote: http://rubygems.org/
specs:
+ diff-lcs (1.1.2)
git (1.2.5)
jeweler (1.5.2)
bundler (~> 1.0.0)
git (>= 1.2.5)
rake
+ json (1.5.3)
+ rack (1.3.0)
+ rack-test (0.6.0)
+ rack (>= 1.0)
rake (0.8.7)
rcov (0.9.9)
+ rspec (2.6.0)
+ rspec-core (~> 2.6.0)
+ rspec-expectations (~> 2.6.0)
+ rspec-mocks (~> 2.6.0)
+ rspec-core (2.6.4)
+ rspec-expectations (2.6.0)
+ diff-lcs (~> 1.1.2)
+ rspec-mocks (2.6.0)
shoulda (2.11.3)
PLATFORMS
@@ -16,5 +29,8 @@ PLATFORMS
DEPENDENCIES
bundler (~> 1.0.0)
jeweler (~> 1.5.2)
+ json
+ rack-test
rcov
+ rspec
shoulda
View
44 spec/rack/facebook/method_fix_spec.rb
@@ -0,0 +1,44 @@
+require File.expand_path('spec_helper', File.join(File.dirname(__FILE__), '../../'))
+
+
+class MockRackWrapper
+ def initialize(response)
+ @response = response
+ end
+
+ def call(env)
+ @env = env
+ @response
+ end
+
+ def env
+ @env
+ end
+end
+
+describe Rack::Facebook::MethodFix do
+ context "with no exclusions" do
+ before do
+ header = [200, {"Content-type" => "test/plain", "Content-length" => "5"}, ["foo"]]
+ @rack_mock = MockRackWrapper.new(header)
+ facebook = Rack::Facebook::MethodFix.new(@rack_mock)
+ @request = Rack::MockRequest.new(facebook)
+ end
+
+ context "POST requests not from facebook" do
+ it 'should stay as a POST' do
+ @request.post("/", {})
+
+ @rack_mock.env["REQUEST_METHOD"].should == "POST"
+ end
+ end
+
+ context 'POST requests from facebook' do
+ it 'should be changed to GET requests' do
+ @request.post("/", {:params => {"signed_request" => 'nothing'}})
+
+ @rack_mock.env["REQUEST_METHOD"].should == "GET"
+ end
+ end
+ end
+end
View
5 spec/spec_helper.rb
@@ -0,0 +1,5 @@
+require 'rubygems'
+require 'bundler/setup'
+require 'rack/test'
+require 'rack/mock'
+require File.expand_path('../../lib/rack-facebook-method-fix', __FILE__)
View
18 test/helper.rb
@@ -1,18 +0,0 @@
-require 'rubygems'
-require 'bundler'
-begin
- Bundler.setup(:default, :development)
-rescue Bundler::BundlerError => e
- $stderr.puts e.message
- $stderr.puts "Run `bundle install` to install missing gems"
- exit e.status_code
-end
-require 'test/unit'
-require 'shoulda'
-
-$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
-$LOAD_PATH.unshift(File.dirname(__FILE__))
-require 'rack-facebook-method-fix'
-
-class Test::Unit::TestCase
-end
View
7 test/test_rack-facebook-method-fix.rb
@@ -1,7 +0,0 @@
-require 'helper'
-
-class TestRackFacebookMethodFix < Test::Unit::TestCase
- should "probably rename this file and start testing for real" do
- flunk "hey buddy, you should probably rename this file and start testing for real"
- end
-end

0 comments on commit 279dde3

Please sign in to comment.