test/unit/runner_tests.rb in deas-0.43.3 vs test/unit/runner_tests.rb in deas-0.43.4

- old
+ new

@@ -42,54 +42,55 @@ @runner = @runner_class.new(@handler_class, :request => @request) end subject{ @runner } should have_readers :handler_class, :handler + should have_readers :request, :params, :route_path should have_readers :logger, :router, :template_source - should have_readers :request, :params, :route_path, :splat - should have_imeths :run, :to_rack - should have_imeths :status, :headers, :body, :content_type + should have_imeths :splat, :run, :to_rack + should have_imeths :status, :headers, :body, :content_type, :set_cookie should have_imeths :halt, :redirect, :send_file should have_imeths :render, :source_render, :partial, :source_partial should "know its handler and handler class" do assert_equal @handler_class, subject.handler_class assert_instance_of subject.handler_class, subject.handler end should "default its attrs" do runner = @runner_class.new(@handler_class) - assert_kind_of Deas::NullLogger, runner.logger - assert_kind_of Deas::Router, runner.router - assert_kind_of Deas::NullTemplateSource, runner.template_source assert_nil runner.request - assert_equal Hash.new, runner.params assert_equal '', runner.route_path + assert_equal Hash.new, runner.params + assert_kind_of Deas::NullLogger, runner.logger + assert_kind_of Deas::Router, runner.router + assert_kind_of Deas::NullTemplateSource, runner.template_source + assert_nil runner.splat end should "know its attrs" do args = { - :logger => Factory.string, - :router => Factory.string, - :template_source => Factory.string, :request => Factory.request, + :route_path => Factory.string, :params => { Factory.string => Factory.string }, - :route_path => Factory.string + :logger => Factory.string, + :router => Factory.string, + :template_source => Factory.string } runner = @runner_class.new(@handler_class, args) + assert_equal args[:request], runner.request + assert_equal args[:route_path], runner.route_path + assert_equal args[:params], runner.params assert_equal args[:logger], runner.logger assert_equal args[:router], runner.router assert_equal args[:template_source], runner.template_source - assert_equal args[:request], runner.request - assert_equal args[:params], runner.params - assert_equal args[:route_path], runner.route_path end should "know its splat value" do route_path = [ '/some/:value/other/:value/*', @@ -101,12 +102,12 @@ path_info = route_path.gsub(':value', params['value']).sub('*', splat) request_env = { 'PATH_INFO' => path_info } args = { :request => Factory.request(:env => request_env), - :params => params, - :route_path => route_path + :route_path => route_path, + :params => params } runner = @runner_class.new(@handler_class, args) assert_equal splat, runner.splat end @@ -117,12 +118,12 @@ path_info = route_path.gsub(':value', params['value']) request_env = { 'PATH_INFO' => path_info } args = { :request => Factory.request(:env => request_env), + :route_path => route_path, :params => params, - :route_path => route_path } runner = @runner_class.new(@handler_class, args) assert_nil runner.splat end @@ -134,12 +135,12 @@ path_info = "/some/#{Factory.string}" request_env = { 'PATH_INFO' => path_info } args = { :request => Factory.request(:env => request_env), + :route_path => route_path, :params => params, - :route_path => route_path } runner = @runner_class.new(@handler_class, args) assert_raises(SplatParseError){ runner.splat } end @@ -199,10 +200,14 @@ subject.body exp assert_equal exp, subject.body subject.body exp.first assert_equal exp, subject.body + + exp = [Factory.integer.to_s] + subject.body exp.first.to_i + assert_equal exp, subject.body end should "know and set its response content type header" do extname = ".#{Factory.string}" @@ -223,9 +228,38 @@ Factory.string => Factory.string } subject.content_type(extname, params) exp = "#{mime_type};#{params.map{ |k,v| k + '=' + v }.join(',')}" assert_equal exp, subject.headers['Content-Type'] + end + + should "set a cookie header with `set_cookie`" do + name, value = Factory.string, Factory.string + opts = { Factory.string => Factory.string } + exp_headers = {} + Rack::Utils.set_cookie_header!( + exp_headers, + name, + (opts || {}).merge(:value => value) + ) + + rack_utils_set_cookie_header_called_with = nil + Assert.stub(Rack::Utils, :set_cookie_header!) do |*args| + rack_utils_set_cookie_header_called_with = args + Assert.stub_send(Rack::Utils, :set_cookie_header!, *args) + end + + subject.set_cookie(name, value, opts) + + exp = [subject.headers, name, opts.merge(:value => value)] + assert_equal exp, rack_utils_set_cookie_header_called_with + exp = exp_headers['Set-Cookie'] + assert_includes exp, @runner.headers['Set-Cookie'] + + subject.set_cookie(name, value) + + exp = [subject.headers, name, { :value => value }] + assert_equal exp, rack_utils_set_cookie_header_called_with end end class HaltTests < InitTests