From a8cea832536e8d6c84c297ba22690b0f38e70c40 Mon Sep 17 00:00:00 2001 From: Edger Date: Tue, 15 Apr 2014 19:24:08 +0400 Subject: [PATCH] is_fully_authenticated helper --- .../controllers/helpers.rb | 10 ++++++++++ spec/controllers/two_factor_auth_spec.rb | 20 +++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 spec/controllers/two_factor_auth_spec.rb diff --git a/lib/two_factor_authentication/controllers/helpers.rb b/lib/two_factor_authentication/controllers/helpers.rb index b64ffb0..ef38330 100644 --- a/lib/two_factor_authentication/controllers/helpers.rb +++ b/lib/two_factor_authentication/controllers/helpers.rb @@ -37,3 +37,13 @@ module TwoFactorAuthentication end end end + +module Devise + module Controllers + module Helpers + def is_fully_authenticated? + !session["warden.user.user.session"].try(:[], :need_two_factor_authentication) + end + end + end +end diff --git a/spec/controllers/two_factor_auth_spec.rb b/spec/controllers/two_factor_auth_spec.rb new file mode 100644 index 0000000..7c331f5 --- /dev/null +++ b/spec/controllers/two_factor_auth_spec.rb @@ -0,0 +1,20 @@ +require 'spec_helper' + +include Warden::Test::Helpers + +describe HomeController do + context "passed only 1st factor auth" do + let(:user) { create_user } + + describe "is_fully_authenticated helper" do + it "should be true" do + login_as user, scope: :user + visit user_two_factor_authentication_path + + + controller.is_fully_authenticated?.should be_true + end + end + + end +end \ No newline at end of file