我向我添加了应用程序国家分隔的内容。国家在应用程序中通过子域从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 –