0

アプリケーションにマルチテナンシーを適用するために ActsAsTenant を使用しています。現在のテナントが存在するかどうかを確認することで、各リクエストの前に常にサブドメインを確認しnilます。現在のテナントが の場合nil、ユーザーを 404 ページにリダイレクトします。

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

この動作をテストするための次の仕様があります。

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

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

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

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

4

1 に答える 1

0

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

于 2012-04-26T16:56:24.773 に答える