./test\unit\product_test.rb:1:in `require': no such file to load -- test_helper (LoadError)
 from ./test\unit\product_test.rb:1
 from E:\Rails\.metadata\.plugins\org.radrails.rails.core\run_auto2.rb:2:in `require'
 from E:\Rails\.metadata\.plugins\org.radrails.rails.core\run_auto2.rb:2
 from E:/Rails/.metadata/.plugins/org.rubypeople.rdt.testunit/RemoteTestRunner.rb:294:in `require'
 from E:/Rails/.metadata/.plugins/org.rubypeople.rdt.testunit/RemoteTestRunner.rb:294


require 'test/test_helper'

class ProductTest < ActiveSupport::TestCase
# Replace this with your real tests.
fixtures :products
def test_truth
assert true
end
end

Aptana Studio RadRails를 사용하는 사용자라면 Auto Test Suite를 실행했을 경우 위와 같은 에러를 쉽게 접할 수 있다. 이는 각 xxxx_test.rb 파일의 require 값이 잘 못 되어 있어서 발생하는 데, 대부분 require 값의 앞에 test/ 경로를 추가해 주면 해결이 가능하다.

이올린에 북마크하기(0) 이올린에 추천하기(0)
2008/07/31 13:49 2008/07/31 13:49

<h1>Administrators</h1>
<ul>
<% for user in @all_users %>
<li>
<%= link_to "[X]",
{ :controller => 'login' , :action => 'delete_user', :id => user },
{ :method => :post , :confirm => "Really delete #{user.name}?" }
-%>
<%=h user.name%>
</li>
<% end %>
</ul>
/depot/app/views/login/list_users.html.erb line 7 < 책 218쪽 >

:post => true 에서 :method => :post 로 변경하여야 정상 작동한다.

:post => true 라고 쓰면 단지 <a> 태그안에 post = true 라고 변환한다.
즉 결과물은 <a href="xxxx" post=true>xxxx</a> 당연히 정상동작하지 않는다.
앞에서 배운대로  :method => :post 로 작성하면 rails에서 자동으로 post 로 값을 보내는 스크립트를 만들어준다.


<a href="/login/delete_user/4"onclick="if (confirm('Really delete xxxx?'))
{ var f = document.createElement('form'); f.style.display = 'none';
this.parentNode.appendChild(f); f.method = 'POST';
f.action = this.href;var s = document.createElement('input');
s.setAttribute('type', 'hidden'); s.setAttribute('name', 'authenticity_token');
s.setAttribute('value', '해쉬값'); f.appendChild(s);f.submit(); };return false;"
>
:method => :post 로 작성한 결과물.
이올린에 북마크하기(0) 이올린에 추천하기(0)
2008/07/31 09:55 2008/07/31 09:55
 
원본
<%= form_remote_tag :url => { :action => :add_to_cart, :id => product } do %>
<%= submit_tag "Add to Cart" %>
<%= end %>
수정 후

<% form_remote_tag :url => { :action => :add_to_cart, :id => product } do %>
<%= submit_tag "Add to Cart" %>
<% end %>

/app/views/store/index.rhtml file 14 line <책 162쪽>

순환문과 end가 책에서는 <%= 태그 안에들어있어서 에러를 발생시킨다.
각각 <% 로 바꿔주면 문제는 사라진다.

<%

루비코드의 시작을 알리는 태그. 결과 반환이 필요없는 코드들이 들어갈 때 사용한다.

<%=

해당 태그안의 결과물이 출력되길 원할 때 사용한다.

<%=h

해당 태그안의 결과물이 보안에 취약하지 않게 변환되어서 출력된다. < 가 &lt로 변환 되는 식으로 출력될 결과물이 html 태그나 실행될 수 있는 코드로 이용되지 않게 막는다.
이올린에 북마크하기(0) 이올린에 추천하기(0)
2008/07/18 17:26 2008/07/18 17:26

[에러잡기] 레일스와 함께하는 애자일 웹 개발 in Rails 2.0.2

[8 장 태스크C : 장바구니 생성]에서 Rails 2.0.2를 사용하는 경우 발생하는 문제점에 대한 정리와 해결책 입니다.

발생 경위

/config/environment.rb file 42 line <책 132p>

# Use the database for sessions instead of the cookie-based default,
# which shouldn't be used to store highly confidential information
# (create the session table with 'rake db:sessions:create')

config.action_controller.session_store = :active_record_store

데이터베이스에서 세션 두기 항목에서 세션정보의 저장소를 데이터 베이스로 지정하는 과정에서
위의 빨간부분만 주석처리를 제거할 것을 지시하고 있습니다. 책을 따라갈 경우 아래와 같은 에러 메세지를 만날 수 있습니다.
 
ActionController::InvalidAuthenticityToken

No :secret given to the #protect_from_forgery call.  Set that or use a session store capable of generating its own keys (Cookie Session Store).

비밀이 위조로부터 보호라는 요청을 했다. 가 되나요? 여기서 secret은 비밀이 아니라 secret이라는 객체를 뜻하는 것 같습니다.

해결책

이 부분은 /config/enviroment.rb 에서 해결책을 찾을 수 없고, /app/controllers/application.rb 에서 답을 찾을 수 있습니다. 몇줄안 되는 소스인데 뒤져보면 secret에 관한 주석을 찾을 수 있습니다.

/app/controllers/application.rb file 7 line

# See ActionController::RequestForgeryProtection for details
# Uncomment the :secret if you're not using the cookie session store
protect_from_forgery
  :secret => '8c0e411f8a0da1fd5e01bd72a0c3f4b7'

당신이 쿠키 세션 저장소를 사용하고 있지 않다면 :secret의 사용을 추천하지 않는다. 쿠키 세션 저장소를 사용하고 있지 않다면 :secret의 주석을 없애세요. 라고 하는것 같군요. 빨간 부분의 주석을 없애주면 위의 에러는 사라집니다. 영어가 짧고 ruby에 대한 이해도 짧은 터라 이해하기엔 많이 부족한 감이 있네요. 이유를 설명해 주실 수 있는 분 설명 부탁해요~! db에 들어간 세션값의 도용을 막기 위해 추가된 사항인 듯 합니다.


이올린에 북마크하기(0) 이올린에 추천하기(0)
2008/07/10 11:49 2008/07/10 11:49
openclose