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
私の質問は:なぜですか??なぜこの仕様は失敗するのですか?私はブラウザから手動でテストしようとしましたが、正常に動作しました。
私は絶対に素晴らしい質問の書式設定!このような質問を多くの人にお願いします。そのSICCO!特定の、有益な、簡潔な、そしてトピック上の!よかったね! – ddd