Here's what I have:
An application helper method that calls a controller helper method (private) from it.
Code:
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
And here is the problem: The coluna_ordenacao
and direcao_ordenacao
methods can't be called from RSpec, it gives me the following error:
undefined local variable or method `coluna_ordenacao' for #<RSpec::Core::ExampleGroup::Nested_1::Nested_2:0x7fbf0a9fe3d8>
Is there any way for that to work? Btw I'm testing the helper, not the controller
You can access private methods in tests using .send(:private_methods_name)
see documentation
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With