Sha256: 95efc5503de7d2749c754adb2a3d3fb60da350bf105869461ded44d274200043
Contents?: true
Size: 1.87 KB
Versions: 2
Compression:
Stored size: 1.87 KB
Contents
require_relative "../../test_helper" module Unit module Urb class TestMiddleware < Minitest::Test describe URB::Middleware do before do @key = "123abc" @path = "/foo/bar?very=long&query=string&foo[]=bar&foo[]=baz" @value = "#{URB::PREFIX}#{@path}" end describe "when value not stored yet" do it "stores the passed path, redirects to the 'key URL' and alters the request parameters" do URB.instance_variable_set :@paths, {} URB.expects(:generate_key).returns @key get "/" assert_equal "{}", last_response.body post URB::PATH, {:path => @path} assert_equal 302, last_response.status follow_redirect! assert_equal({ "very" => "long", "query" => "string", "foo" => %w(bar baz) }.inspect, last_response.body) assert_equal({ @key => @path, @value => @key }, URB.instance_variable_get(:@paths)) end end describe "when value already stored" do it "alters the request parameters" do URB.instance_variable_set :@paths, { @key => @path, @value => @key } URB.expects(:generate_key).never get "#{URB::PATH}#{@key}" assert_equal({ "very" => "long", "query" => "string", "foo" => %w(bar baz) }.inspect, last_response.body) assert_equal({ @key => @path, @value => @key }, URB.instance_variable_get(:@paths)) end end end end end end def app Rack::Builder.app do use URB::Middleware run lambda { |env| params = Rack::Request.new(env).params [200, {"Content-Type" => "text/plain"}, [params.inspect]] } end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
urb-0.1.5 | test/unit/urb/test_middleware.rb |
urb-0.1.4 | test/unit/urb/test_middleware.rb |