2011-06-25 15 views
0

このテストを検討してくださいがあります。 200を返すとされるアサーションは、実際には404を返します。 同じ要求に対して2つの異なる結果を返すためにラックはどのように動作しますか?私はそれを貼り付けることができますが、Githubにプロジェクトをチェックアウトすることができため同じ要求は、二つの異なる応答

module Blogrite 
    class Server 
    attr_accessor :status, :mimetype, :body, :provider 
    def initialize *args, &block 
     @status, @mimetype = 200, "text/html" 
     provider = args[0][:with].nil? ? :filesystem : args[0][:with] 
     @provider = Blogrite.const_get(provider.capitalize).new 
     # p "Server is running with #{@provider.class}." 
    end 

    def call env 
     begin 
     article = go env['PATH_INFO'].delete("/") 
     rescue Blogrite::Article::NoBodyError 
     @status = 404 
     end 

     @status = 404 if !article 
     @status = 403 if env["REQUEST_METHOD"] == 'POST' 
     @mimetype = "text/css" if env["PATH_INFO"].include?("css") 
     @body  = if article then article.render 
        elsif env.respond_to?(:to_yaml) then "<pre>#{env.to_yaml}</pre>" 
        else "oops" 
        end 

     [@status,{ "Content-Type" => @mimetype},[@body]] 
    end 

    def go path 
     f = @provider.fetch path 
     Article.parse f unless f.nil? 
    end 
    end 
end 

ワークフロー全体が大きすぎる:

このは、プロジェクト内のサーバ・クラスのコードです。私はあなたの助けに感謝します、ありがとう。

答えて

1

callファンクション内で@statusを初期化するのと同じくらい簡単に解決できます。

class Server 
     attr_accessor :status, :mimetype, :body, :provider 
     def initialize *args, &block 
-  @status, @mimetype = 200, "text/html" 
     provider = args[0][:with].nil? ? :filesystem : args[0][:with] 
     @provider = Blogrite.const_get(provider.capitalize).new 
     # p "Server is running with #{@provider.class}." 
     end 

     def call env 
     begin 
-  article = go env['PATH_INFO'].delete("/") 
+  @status, @mimetype = 200, "text/html" 
+  article = go env['PATH_INFO'].delete("/") 
     rescue Blogrite::Article::NoBodyError 
      @status = 404 
     end 

ラックインスタンスその方法 - 一度だけ呼ばれている - 要求者の邪魔にとどまります。すべての呼び出し関数は、サーバークラスではなく、独自の既定値を持つ必要があります。

私に助けてくれた@rubenfonsecaのおかげです。

関連する問題