1
나는 사용자 및 포스트 모델을 보유하고 있습니다. 그리고 사용자 쇼보기에서 사용자의 게시물을 보여주는 해요 :will_paginate에 "order"매개 변수를 추가하면 Rspec 오류가 발생합니다.
users_controller.rb :
def show
@user = User.find(params[:id])
default_order = "created_at DESC"
params[:order_by] ||= default_order
@posts = @user.posts.paginate(page: params[:page],
per_page: 10,
order: params[:order_by]) if signed_in?
@posts = @user.posts.paginate(page: params[:page])
end
사용자/show.html.erb :
<% if @user.posts.any? %>
<h3>Posts (<%= @user.posts.count %>)</h3>
<ul class="posts unstyled">
<%= render @posts %>
</ul>
<%= will_paginate @posts %>
<% end %>
포스트 라이브 사이트에서 잘 표시됩니다.
user_pages_spec.rb : :이 사양 실행할 때
6) User pages profile page posts
Failure/Error: it { should have_content(p1.title) }
expected there to be content "Fo" in "Action Controller: Exception caught
body { background-color: #fff; color: #333; }
body, p, ol, ul, td {
font-family: helvetica, verdana, arial, sans-serif;
font-size: 13px;
line-height: 18px;
}
pre {
background-color: #eee;
padding: 10px;
font-size: 11px;
white-space: pre-wrap;
}
a { color: #000; }
a:visited { color: #666; }
a:hover { color: #fff; background-color:#000; }
ArgumentError in
Users#show
Showing /home/alex/rails/inkleak/app/views/users/show.html.erb where line #20 raised:
'nil' is not an ActiveModel-compatible object that returns a valid partial path.
Extracted source (around line #20):
17: <h3>Posts (<%= @user.posts.count %>)
을하고 가고 만 개 라인 같은 ... 간다 간다 :
describe "profile page" do
let(:user) { FactoryGirl.create(:user) }
let!(:p1) { FactoryGirl.create(:post, user: user, title: "Fo",
content: "Foo") }
let!(:p2) { FactoryGirl.create(:post, user: user, title: "Ba",
content: "Bar") }
before { visit user_path(user) }
it { should have_selector('h1', text: user.name) }
it { should have_selector('title', text: user.name) }
describe "posts" do
it { should have_content(p1.title) }
it { should have_content(p1.content) }
it { should have_content(p2.title) }
it { should have_content(p2.content) }
it { should have_content(user.posts.count) }
end
end
을 나는이 미친 오류가 발생합니다.
나는이 라인을 코멘트 경우 테스트가 잘 작동하기 때문에 이상한 :
#default_order = "created_at DESC"
#params[:order_by] ||= default_order
#order: params[:order_by])
어떤 문제가 될 수 있습니까?
편집 : 여기
내 공장입니다
factories.rb :
factory :user do
sequence(:name) { |n| "Person #{n}" }
sequence(:email) { |n| "person_#{n}@example.com"}
password "foobar"
password_confirmation "foobar"
factory :admin do
admin true
end
end
factory :post do
title "lorem"
content "lorem ipsum"
#tagging
category
user
after(:build) do |post|
post.tags << FactoryGirl.build(:tag)
end
end
당신은 당신이 게시 된 해당 오류의 라인 # 20를 게재 할 수 있습니까? 그것이 오류라고 말하는 곳입니다. –
@LeoCorrea 이것은 사용자 쇼보기에서 20 행입니다.'<% = render @posts %> '는 그 의미입니까? – alexchenco
다음에 대해 정의 된 팩토리가 있습니까? tag? 그것에 대해 불평 할 수도 있습니다. 'post.tags << FactoryGirl.build (: tag) –