I have this code in lib/user_session.rb
Its used by one of my controllers via include UserSession.
How can I test it? I've added tests in spec/lib/user_session.rb but the code relies on the session which I'm not sure how to mock.
module UserSession
def viewed
session[:viewed] ||= Array.new
return session[:viewed]
end
def viewed_add(id, name)
if viewed.select{|b| b[:id] == id}.empty?
session[:viewed] << {:id => id, :name => name}
end
return session[:viewed]
end
def viewed_delete(id)
unless id.nil?
session[:viewed].delete_if{|b| b[:id] == id}
return session[:viewed]
end
end
end