在本节中,我应该限制用户只能编辑和更新他自己的个人资料。到目前为止,我所有的测试都通过了,除了这个:
describe "as wrong user" do
let(:user) { FactoryGirl.create(:user) }
let(:wrong_user) { FactoryGirl.create(:user, email: "wrong@example.com") }
before { sign_in user }
describe "visiting Users#edit page" do
before { visit edit_user_path(wrong_user) }
it { should_not have_selector('title', text: full_title('Edit user')) }
end
describe "submitting a PUT request to the Users#update action" do
before { put user_path(wrong_user) }
specify { response.should redirect_to(root_path) }
end
end
特别是最后一部分,重定向,这是我在运行测试时得到的:
1) Authentication authorization as wrong user submitting a PUT request to the Users#update action
Failure/Error: specify { response.should redirect_to(root_path) }
Expected response to be a redirect to <http://www.example.com/> but was a redirect to <http://www.example.com/signin>
# ./spec/requests/authentication_spec.rb:86:in `block (5 levels) in <top (required)>'
但是在网站中,当我尝试做同样的事情时它工作得很好,用户被重定向到应用程序的 root_path。