我向我添加了應用程序國家分隔的內容。國家在應用程序中通過子域從IP地址設置。如何逃避rspecs中的重定向
before_action :check_domain
def check_domain
redirect_to(subdomain: current_country.slug) unless Country.find_by(slug: request.subdomain)
end
我已加入這個我application_controller從他們的IP addresess重定向權國家的用戶(如果網址無子域的話)。在工作正常,但我的規格很多,因爲它(沒有重定向通過每個規格)。例如規格:
要求 「rails_helper」
describe "Update user's preferred subjects", type: :request do
let!(:video) { create(:video, :with_tags, tags: ["math"]) }
let!(:related_video) { create(:video, :with_tags, tags: ["math"], subject: video.subject) }
let!(:related_survey) { create(:survey, :with_tags, tags: ["math"], subject: video.subject) }
it "responds with related materials" do
get("/videos/#{video.id}/related_materials.json")
expect(response_body.keys).to match_array(%w(videos offline_materials surveys meta))
expect(response_body).to eq_serialized(
RelatedMaterialsQuery.new(video, {}),
serializer: RelatedMaterialsSerializer
)
end
end
我得到了一個錯誤:
JSON::ParserError:
784: unexpected token at '<html><body>You are being <a href="http://guyana-1.example.com/videos/1/related_materials">redirected</a>.</body></html>'
我應該在rspec的變化來傳遞呢?它試圖解析html而不是json,因爲它重定向到了國家子域名。我應該如何解決它?謝謝。
請查看https://stackoverflow.com/questions/2556627/rails-rspec-set-subdomain –