Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

move helper methods onto the controller

  • Loading branch information...
commit 95f8b3e08e2cdf45db7b29112d63205956167dcd 1 parent cf174eb
Mike Burns authored
10 app/controllers/application_controller.rb
View
@@ -4,7 +4,15 @@ class ApplicationController < ActionController::Base
include ApplicationHelper
include HoptoadNotifier::Catcher
- private
+ protected
+
+ def logged_in?
+ !current_user.nil?
+ end
+
+ def current_user
+ @current_user ||= User.find_by_id(session[:user_id])
+ end
def ensure_logged_in
unless logged_in?
8 app/helpers/application_helper.rb
View
@@ -2,12 +2,4 @@ module ApplicationHelper
def body_class
"#{controller.controller_name} #{controller.controller_name}-#{controller.action_name}"
end
-
- def logged_in?
- !current_user.nil?
- end
-
- def current_user
- @current_user ||= User.find_by_id(session[:user_id])
- end
end
25 test/unit/helpers/application_helper_test.rb
View
@@ -2,29 +2,4 @@
require 'action_view/test_case'
class ApplicationHelperTest < ActionView::TestCase
- def setup
- @controller = TestController.new
- @request = @controller.request
- stubs(:session).returns(@request.session)
- end
-
- logged_in do
- should "produce true when sent #logged_in?" do
- assert logged_in?
- end
-
- should "produce the user when sent #current_user" do
- assert_equal @user, current_user
- end
- end
-
- logged_out do
- should "produce false when sent #logged_in?" do
- assert ! logged_in?
- end
-
- should "produce nil when sent #current_user" do
- assert_nil current_user
- end
- end
end
Please sign in to comment.
Something went wrong with that request. Please try again.