这就是我所拥有的:
从中调用控制器助手方法(私有)的应用程序助手方法。
代码:
ApplicationHelper:
def ordenar(coluna, titulo = nil)
titulo ||= coluna.titleize
css_class = (coluna == **coluna_ordenacao**) ? "#{**direcao_ordenacao**}" : "ordenavel"
direcao = (coluna == **coluna_ordenacao** and **direcao_ordenacao** == "asc") ? :desc : :asc
link_to titulo, {:sort => coluna, :direction => direcao}, {:class => css_class}
end
的ApplicationController:
helper_method :coluna_ordenacao, :direcao_ordenacao
private
def coluna_ordenacao
return params[:sort] if params[:sort] and params[:sort].split(' ').size == 1
return :created_at
end
def direcao_ordenacao
return %w[asc desc].include?(params[:direction]) ? params[:direction] : :desc
end
以下是问题:无法从RSpec调用coluna_ordenacao
和direcao_ordenacao
方法,它给出了以下错误:
undefined local variable or method `coluna_ordenacao' for #<RSpec::Core::ExampleGroup::Nested_1::Nested_2:0x7fbf0a9fe3d8>
有没有办法让它起作用?顺便说一句,我正在测试助手,而不是控制器