Hartl 레일 튜토리얼이 끝나고 Rspec 문제가 발생했습니다. 알아낼 수없는 문제입니다. http://www.railstutorial.org/book/user_microposts#sec-access_control 목록 10.23에서 소개 된이 개 테스트는 다음과 같은 메시지와 함께 실패 : 여기 Hartl ROR Tutorial 10 장 Rspec 테스트에 실패했습니다.
Failures:
1) Authentication authorization for non-signed-in users in the Microposts controller submitting to the create action
Failure/Error: before { post microposts_path }
ActionController::ParameterMissing:
param is missing or the value is empty: micropost
# ./app/controllers/microposts_controller.rb:20:in `micropost_params'
# ./app/controllers/microposts_controller.rb:5:in `create'
# ./spec/requests/authentication_pages_spec.rb:107:in `block (6 levels) in <top (required)>'
2) Authentication authorization for non-signed-in users in the Microposts controller submitting to the destroy action
Failure/Error: before { delete micropost_path(FactoryGirl.create(:micropost)) }
ActionView::MissingTemplate:
Missing template microposts/destroy, application/destroy with {:locale=>[:en], :formats=>[:html], :handlers=>[:erb, :builder, :raw, :ruby, :jbuilder, :coffee]}. Searched in:
* "/Users/name/Sites/sample_app/app/views"
# ./spec/requests/authentication_pages_spec.rb:112:in `block (6 levels) in <top (required)>'
내 authentication_pages_spec.rb : 그것은 아직 micropost을 찾고처럼
1 위를 들면
require 'spec_helper'
describe "Authentication" do
subject { page }
describe "signin page" do
before { visit signin_path }
it { should have_content('Sign in') }
it { should have_title('Sign in') }
end
describe "signin" do
before { visit signin_path }
describe "with invalid information" do
before { click_button "Sign in" }
it { should have_title('Sign in') }
it { should have_error_message('Invalid') }
it { should_not have_link('Users', href: users_path) }
it { should_not have_link('Sign out', href: signout_path) }
it { should have_link('Help', href: help_path) }
it { should have_link('Home', href: root_path) }
it { should have_link('Sign in', href: signin_path) }
describe "after visiting another page" do
before { click_link "Home" }
it { should_not have_selector('div.alert.alert-error') }
end
end
describe "with valid information" do
let(:user) { FactoryGirl.create(:user) }
before { sign_in user }
it { should have_title(user.name) }
it { should have_link('Users', href: users_path) }
it { should have_link('Profile', href: user_path(user)) }
it { should have_link('Settings', href: edit_user_path(user)) }
it { should have_link('Sign out', href: signout_path) }
it { should_not have_link('Sign in', href: signin_path) }
describe "create new user goes to root_path" do
before { visit new_user_path }
it { should_not have_title('Sign up') }
end
describe "followed by signout" do
before { click_link "Sign out" }
it { should have_link('Sign in') }
end
end
end
describe "authorization" do
describe "as admin user"
let(:admin) { FactoryGirl.create(:admin) }
before { sign_in admin, no_capybara: true }
describe "prohibit admin for self deletion" do
specify do
expect { delete user_path(admin) }.not_to change(User, :count).by(-1)
end
end
describe "for non-signed-in users" do
let(:user) { FactoryGirl.create(:user) }
describe "when attempting to visit a protected page" do
before do
visit edit_user_path(user)
fill_in "Email", with: user.email
fill_in "Password", with: user.password
click_button "Sign in"
end
describe "after signing in" do
it "should render the desired protected page" do
expect(page).to have_title('Edit user')
end
describe "when signing in again" do
before do
click_link "Sign out"
visit signin_path
fill_in "Email", with: user.email
fill_in "Password", with: user.password
click_button "Sign in"
end
it "should render the default (profile) page" do
expect(page).to have_title(user.name)
end
end
end
end
describe "in the Microposts controller" do
describe "submitting to the create action" do
before { post microposts_path }
specify { expect(response).to redirect_to(signin_path) }
end
describe "submitting to the destroy action" do
before { delete micropost_path(FactoryGirl.create(:micropost)) }
specify { expect(response).to redirect_to(signin_path) }
end
end
describe "in the Users controller" do
describe "visiting the user index" do
before { visit users_path }
it { should have_title('Sign in') }
end
describe "visiting the edit page" do
before { visit edit_user_path(user) }
it { should have_title('Sign in') }
end
describe "when attempting to visit a protected page" do
before do
visit edit_user_path(user)
fill_in "Email", with: user.email
fill_in "Password", with: user.password
click_button "Sign in"
end
describe "after signing in" do
it "should render the desired protected page" do
expect(page).to have_title('Edit user')
end
end
end
describe "submitting to the update action" do
before { patch user_path(user) }
specify { expect(response).to redirect_to(root_url) }
end
end
describe "as non-admin user" do
let(:user) { FactoryGirl.create(:user) }
let(:non_admin) { FactoryGirl.create(:user) }
before { sign_in non_admin, no_capybara: true }
describe "submitting a DELETE request to the Users#destroy action" do
before { delete user_path(user) }
specify { expect(response).to redirect_to(root_url) }
end
end
end
end
describe "as wrong user" do
let(:user) { FactoryGirl.create(:user) }
let(:wrong_user) { FactoryGirl.create(:user, email: "[email protected]") }
before { sign_in user, no_capybara: true }
describe "submitting a GET request to the Users#edit action" do
before { get edit_user_path(wrong_user) }
specify { expect(response.body).not_to match(full_title('Edit user')) }
specify { expect(response).to redirect_to(root_url) }
end
describe "submitting a PATCH request to the Users#update action" do
before { patch user_path(wrong_user) }
specify { expect(response).to redirect_to(root_url) }
end
end
end
)이 보인다 그걸 완전히 통과 시켜서 서명 페이지로 가야합니다. (마이크로 포스트 컨트롤러 아래에서 볼 수 있듯이 이전 작업 설정을 통해 사용자가 로그인했는지 확인하고 로그인 페이지로 전달하지 않아야합니다.) 이것은 모든 행동에 적용됨).
번호 2)에 대한보기가 없으며 존재하지 않을 것입니까? 왜이 일을하는거야? 이 동작을 어떻게 중지합니까?
응용 프로그램이 마이크로 포스트 컨트롤러에서 이전 필터를 건너 뛰고있는 것 같습니다.
class MicropostsController < ApplicationController
before_action :signed_in_user
def create
@micropost = current_user.microposts.build(micropost_params)
if @micropost.save
flash[:success] = "Micropost created!"
redirect_to root_url
else
render 'static_pages/home'
end
end
def destroy
end
private
def micropost_params
params.require(:micropost).permit(:content)
end
end
& 내 signed_in_user 및 sign_in : 여기
내 microposts_controller.rb입니까? 내 세션에 앉아있는 방법 _helper.rb
def signed_in_user
unless signed_in?
store_location
redirect_to signin_url, notice: "Please sign in."
end
end
def signed_in?
!current_user.nil?
end
내 검사가 실패한 이유에 대한 통찰력이 있으십니까?