Sha256: 24119985915b4031e25123c49ca8bff3631c5123336c44adecfa4d5e0cdf028f

Contents?: true

Size: 1.4 KB

Versions: 50

Compression:

Stored size: 1.4 KB

Contents

require 'test_helper'

class DiscoApp::Admin::ShopsControllerTest < ActionController::TestCase
  include ActiveJob::TestHelper

  def setup
    ENV['ADMIN_APP_USERNAME'] = 'admin_app_username'
    ENV['ADMIN_APP_PASSWORD'] = 'admin_app_password'
    @routes = DiscoApp::Engine.routes
  end

  def teardown
    ENV['ADMIN_APP_USERNAME'] = nil
    ENV['ADMIN_APP_PASSWORD'] = nil
  end

  test 'can not access shops list without authorization' do
    get(:index)
    assert_response :unauthorized
  end

  test 'can not access shops list with incorrect username/password' do
    authenticate('fakeuser', 'blah blah')
    get(:index)
    assert_response :unauthorized
  end

  test 'can not access shops list with blank username/password' do
    authenticate('', '')
    get(:index)
    assert_response :unauthorized
  end

  test 'can not access shops list with blank username/password when env variables are blank' do
    ENV['ADMIN_APP_USERNAME'] = ''
    ENV['ADMIN_APP_PASSWORD'] = ''
    authenticate('', '')
    get(:index)
    assert_response :unauthorized
  end

  test 'can access shops list with correct username/password' do
    authenticate('admin_app_username', 'admin_app_password')
    get(:index)
    assert_response :ok
  end

  private

    def authenticate(username, password)
      request.env['HTTP_AUTHORIZATION'] = ActionController::HttpAuthentication::Basic.encode_credentials(username, password)
    end

end

Version data entries

50 entries across 50 versions & 1 rubygems

Version Path
disco_app-0.16.1.pre.sidekiq.pre.6.pre.release test/controllers/disco_app/admin/shops_controller_test.rb
disco_app-0.8.6 test/controllers/disco_app/admin/shops_controller_test.rb
disco_app-0.8.7 test/controllers/disco_app/admin/shops_controller_test.rb
disco_app-0.8.8 test/controllers/disco_app/admin/shops_controller_test.rb
disco_app-0.8.9 test/controllers/disco_app/admin/shops_controller_test.rb
disco_app-0.9.0 test/controllers/disco_app/admin/shops_controller_test.rb
disco_app-0.9.1 test/controllers/disco_app/admin/shops_controller_test.rb
disco_app-0.9.2 test/controllers/disco_app/admin/shops_controller_test.rb
disco_app-0.9.3 test/controllers/disco_app/admin/shops_controller_test.rb
disco_app-0.9.4 test/controllers/disco_app/admin/shops_controller_test.rb
disco_app-0.9.5 test/controllers/disco_app/admin/shops_controller_test.rb
disco_app-0.9.6 test/controllers/disco_app/admin/shops_controller_test.rb
disco_app-0.9.7 test/controllers/disco_app/admin/shops_controller_test.rb
disco_app-0.9.8 test/controllers/disco_app/admin/shops_controller_test.rb
disco_app-0.9.9 test/controllers/disco_app/admin/shops_controller_test.rb
disco_app-0.9.10 test/controllers/disco_app/admin/shops_controller_test.rb
disco_app-0.9.11 test/controllers/disco_app/admin/shops_controller_test.rb
disco_app-0.10.0 test/controllers/disco_app/admin/shops_controller_test.rb
disco_app-0.10.1 test/controllers/disco_app/admin/shops_controller_test.rb
disco_app-0.10.2 test/controllers/disco_app/admin/shops_controller_test.rb