2012-04-26 23 views
0

ActsAsTenantを使用してアプリケーションにマルチテナントを適用します。現在のテナントがnilかどうかをチェックすることによって、各リクエストの前にサブドメインをチェックします。RSpec:現在のサブドメインを検証

require 'spec_helper' 

describe SessionsController do 

    let(:client) { create(:client) } 

    before(:each) do 
    @request.host = "#{client.account_name}.lvh.me" 
    end 

    describe "GET 'new'" do 
    context "for invalid subdomains" do 
     it "should redirect the user to the 404 page" do 
     @request.host = "foo.lvh.me" 
     response.should redirect_to "/404.html" 
     end 
    end 
    end 
end 

仕様は次のエラーメッセージで失敗します:

私はこの動作をテストするには、次のスペックを持っている

class ApplicationController < ActionController::Base 
    protect_from_forgery 

    set_current_tenant_by_subdomain(:client, :account_name) 

    before_filter :check_subdomain 

    private 

    def check_subdomain 
    redirect_to("/404.html") if ActsAsTenant.current_tenant.nil? 
    end 
end 

:現在のテナントがnilであれば、私は404ページにユーザーをリダイレクト

F 

Failures: 

    1) SessionsController GET 'new' for invalid subdomains should redirect the user to the 404 page 
    Failure/Error: response.should redirect_to "/404.html" 
     Expected response to be a <:redirect>, but was <200> 
    # ./spec/controllers/sessions_controller_spec.rb:15:in `block (4 levels) in <top (required)>' 

Finished in 0.2098 seconds 
1 example, 1 failure 

Failed examples: 

rspec ./spec/controllers/sessions_controller_spec.rb:13 # SessionsController GET 'new' for invalid subdomains should redirect the user to the 404 page 

私の質問は:なぜですか??なぜこの仕様は失敗するのですか?私はブラウザから手動でテストしようとしましたが、正常に動作しました。

+1

私は絶対に素晴らしい質問の書式設定!このような質問を多くの人にお願いします。そのSICCO!特定の、有益な、簡潔な、そしてトピック上の!よかったね! – ddd

答えて

0

同じ問題を抱えている可能性のある人は、応答をテストする前にリクエストを行うことを忘れないでください!!!!!すなわち:追加するget :new

関連する問題