Sha256: 0f073b4d4ae98d4b4efcd3b578ba3b740eb8b3262f55867890657176bc144e1a

Contents?: true

Size: 1.33 KB

Versions: 2

Compression:

Stored size: 1.33 KB

Contents

require 'test_helper'
require 'action_controller'

class LoginProtectionController < ActionController::Base
  include ShopifyApp::LoginProtection
  helper_method :shop_session

  def index
    render nothing: true
  end
end

class LoginProtectionTest < ActionController::TestCase
  tests LoginProtectionController

  def setup
    ShopifySessionRepository.storage = InMemorySessionStore
  end

  def test_calling_shop_session_returns_nil_when_session_is_nil
    with_application_test_routes do
      session[:shopify] = nil
      get :index
      assert_nil @controller.shop_session
    end
  end

  def test_calling_shop_session_retreives_session_from_storage
    with_application_test_routes do
      session[:shopify] = "foobar"
      get :index
      ShopifySessionRepository.expects(:retrieve).returns(session).once
      assert @controller.shop_session
    end
  end

  def test_shop_session_is_memoized_and_does_not_retreive_session_twice
    with_application_test_routes do
      session[:shopify] = "foobar"
      get :index
      ShopifySessionRepository.expects(:retrieve).returns(session).once
      assert @controller.shop_session
      assert @controller.shop_session
    end
  end

  def with_application_test_routes
    with_routing do |set|
      set.draw do
        get '/' => 'login_protection#index'
      end
      yield
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
shopify_app-5.0.2 test/lib/shopify_app/login_protection_test.rb
shopify_app-5.0.1 test/lib/shopify_app/login_protection_test.rb