API를 개발 중이며 로그인 방법을 테스트하고 싶습니다. spec/controller
대신 spec/api/
에있는 API 사양. rspec-rails를 사용하고 있습니다. 이제 다음과 같은 사양이 있습니다.내 API 사양에서 세션에 액세스하십시오.
describe "/api/login.json", :type => :api do
let(:user) { FactoryGirl.create(:user) }
context "when called with correct credentials" do
before(:all) do
post "/api/v1/passenger/login.json",:email => user.email, :password => user.password
end
it "responds with HTTP 200" do
last_response.status.should == 200
end
it "sets the session correctly" do
session[:user_id].should == user.id # <-- ### Here ###
end
end
end
실패했습니다. session
은 nil입니다. 세션 변수에 어떻게 액세스합니까?
내 RSpec.configure
블록에 몇 가지 내용을 포함시켜야 할 것으로 생각하십니까?
당신은'request.session'을 시도 할 수 있습니다,하지만 난 그것을 작동하는지 확실하지 않다 :
이들 마법 단어로 요약된다. – Deradon
'request'는': type => : api' 테스트를 위해 도우미에 포함시킨'Rack :: Test :: Methods'에 정의 된 메소드입니다. 그것은'post'와'get'와 비슷한 메소드이고 URL을 매개 변수로 요구합니다. 그래서'request.session'은 단지'ArgumentError Exception : throws argument of argument (0 for 1)'을 던졌습니다. – iblue
은 설명 체인에서 더 높은 Api :: LoginController를 기술하고 있습니까? ActionController :: TestCase :: Behavior가 혼합되어 있는지 궁금합니다. controller.session에 액세스 할 수 있습니까? – oliverbarnes