4
サブドメイン制約をテストするコントローラテストを作成しようとしています。しかし、RSpecにサブドメインを設定させて、サブドメインが正確でない場合はエラーを返すことができません。RSpec&Rails 4でサブドメイン制約をテストする方法
私はスペック
module FrontendAPI
class EventsController < FrontendAPI::BaseController
def index
render json: []
end
end
end
events_controller.rb
namespace :frontend_api do
constraints subdomain: 'frontend-api' do
resources :events, only: [:index]
end
end
3.4
routes.rbを〜のRails 4.2.6とRSpecのを使用してい
RSpec.describe FrontendAPI::EventsController do
describe 'GET #index' do
context 'wrong subdomain' do
before do
@request.host = 'foo.example.com'
end
it 'responds with 404' do
get :index
expect(response).to have_http_status(:not_found)
end
end
end
end
これを行う方法はいくつかありますか?