Sha256: 958f77d8d95c0bc99709f900d5588d3a67e195c4ecd0ef471a1943edb22eb4be

Contents?: true

Size: 1.39 KB

Versions: 10

Compression:

Stored size: 1.39 KB

Contents

require 'test_helper'
require 'action_controller'
require 'action_controller/base'

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

  def index
    render nothing: true
  end
end

class LoginProtectionTest < ActionController::TestCase
  tests LoginProtectionController

  setup do
    ShopifyApp::SessionRepository.storage = InMemorySessionStore
  end

  test "calling shop session returns nil when session is nil" do
    with_application_test_routes do
      session[:shopify] = nil
      get :index
      assert_nil @controller.shop_session
    end
  end

  test "calling shop session retreives session from storage" do
    with_application_test_routes do
      session[:shopify] = "foobar"
      get :index
      ShopifyApp::SessionRepository.expects(:retrieve).returns(session).once
      assert @controller.shop_session
    end
  end

  test "shop session is memoized and does not retreive session twice" do
    with_application_test_routes do
      session[:shopify] = "foobar"
      get :index
      ShopifyApp::SessionRepository.expects(:retrieve).returns(session).once
      assert @controller.shop_session
      assert @controller.shop_session
    end
  end

  private

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

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
shopify_app-6.1.2 test/shopify_app/login_protection_test.rb
shopify_app-6.1.1 test/shopify_app/login_protection_test.rb
shopify_app-6.1.0 test/shopify_app/login_protection_test.rb
shopify_app-6.0.6 test/shopify_app/login_protection_test.rb
shopify_app-6.0.5 test/shopify_app/login_protection_test.rb
shopify_app-6.0.4 test/shopify_app/login_protection_test.rb
shopify_app-6.0.3 test/shopify_app/login_protection_test.rb
shopify_app-6.0.2 test/shopify_app/login_protection_test.rb
shopify_app-6.0.1 test/shopify_app/login_protection_test.rb
shopify_app-6.0.0 test/shopify_app/login_protection_test.rb