Skip to content
Browse files

initial middleware functional specs

  • Loading branch information...
1 parent 72cf2ac commit 3b1ef349f8516c07b064fc4778a286250bef78b9 @ajsharp ajsharp committed
Showing with 45 additions and 0 deletions.
  1. +45 −0 spec/functional/middleware_spec.rb
View
45 spec/functional/middleware_spec.rb
@@ -0,0 +1,45 @@
+require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
+
+describe 'an app that includes the aarrr middleware' do
+ def app
+ app = Rack::Builder.app do
+
+ use AARRR::Middleware
+ run lambda { |env|
+ [200, {'Content-Type' => 'text/plain'}, ["Hello"]]
+ }
+ end
+ end
+
+ it "includes the id in a cookie in the response" do
+ response = Rack::MockRequest.new(app).get('/')
+ user = AARRR.users.find_one
+ response.headers['Set-Cookie'].should =~ /_utmarr=#{user["_id"]}; path=\//
+ end
+
+ context "when including with another middleware" do
+ def app
+ Rack::Builder.app do
+
+ use Rack::Session::Cookie, :key => 'rack.session',
+ :secret => 'secret',
+ :expire_after => 10000
+ use AARRR::Middleware
+ run lambda { |env|
+ env['rack.session'] = {"user_id" => 'myid'}
+ [200, {'Content-Type' => 'text/plain'}, []]
+ }
+ end
+ end
+
+ it "includes the session cookie in the response" do
+ get '/'
+ last_response.headers["Set-Cookie"].should =~ /rack\.session/
+ end
+
+ it "includes the aarrr cookie in the response" do
+ get '/'
+ last_response.headers['Set-Cookie'].should =~ /_utmarr/
+ end
+ end
+end

0 comments on commit 3b1ef34

Please sign in to comment.
Something went wrong with that request. Please try again.