Help with integration tests

Hello, I’m trying to set up an integration test because functionnal
testing with cookies gave me headaches…

Now, I can’t have those integration tests working :

The ApplicationController is

class ApplicationController < ActionController::Base

helper_method :types_biens
helper_method :lire_critere
helper_method :ecrire_critere

@@types_biens = {’’ => ‘Tous’, ‘ma’ => ‘maison’, ‘app’ =>
‘appartements’}

def types_biens
return @@types_biens
end

def lire_critere(nom)
return cookies[“criteres_#{nom}”].to_s
end

def ecrire_critere(nom, valeur)
cookies[“criteres_#{nom}”] = valeur.to_s
end

end

The controller is

class CriteresController < ApplicationController

def change
if request.post?
ecrire_critere(‘type_bien’,params[:criteres][:type_bien])
ecrire_critere(‘localisation’,params[:criteres][:localisation])
ecrire_critere(‘superficie_mini’,params[:criteres][:superficie_mini])
redirect_to :controller => ‘menu_general’
end
end

end

The test file is

require “#{File.dirname(FILE)}/…/test_helper”
class CriteresCookies < ActionController::IntegrationTest

def test_change_critere
pp cookies
post :change, :criteres => {:type_bien => ‘ma’, :localisation =>
‘xxx’, :superficie_mini => 70}
assert_equal ‘ma’, @controller.lire_critere(“type_bien”)
assert_equal ‘xxx’, @controller.lire_critere(“localisation”)
assert_equal ‘70’, @controller.lire_critere(“superficie_mini”)
end

end

But unfortunately, the @lire_critere method defined in
CriteresController is not visible…
And pp cookies return an empty hash and pp @cookies return nil

So, where are the cookies ? Why the lire_critere method is not available
?

Note : when tried with a browser the controller and the cookie methods
works as excepted - the problem occurs when I try to create some tests
for them

Thanks

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs