summaryrefslogtreecommitdiff
path: root/certs/test/functional/certs_controller_test.rb
blob: 7826dd6b211ba15915dbae7716934c0c48aa2596 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
require 'test_helper'

class CertsControllerTest < ActionController::TestCase

  test "send free cert without login" do
    cert = stub :to_s => "free cert"
    ClientCertificate.expects(:new).with(free: true).returns(cert)
    get :show
    assert_response :success
    assert_equal cert.to_s, @response.body
  end

  test "send cert" do
    login
    cert = stub :to_s => "real cert"
    ClientCertificate.expects(:new).with(free: false).returns(cert)
    get :show
    assert_response :success
    assert_equal cert.to_s, @response.body
  end

  test "login required if free certs disabled" do
    with_config free_certs_enabled: false do
      get :show
      assert_response :redirect
    end
  end

  test "get paid cert if free certs disabled" do
    with_config free_certs_enabled: false do
      login
      cert = stub :to_s => "real cert"
      ClientCertificate.expects(:new).with(free: false).returns(cert)
      get :show
      assert_response :success
      assert_equal cert.to_s, @response.body
    end
  end

end