aboutsummaryrefslogtreecommitdiff
path: root/test/controllers/backends/terraform_aws_controller_test.rb
blob: f98890f351b1709e23e500b00fc01a3e04f361a6 (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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
require 'integration_test_helper'

class Backends::TerraformAwsControllerTest < ActionDispatch::IntegrationTest
  setup do
    login_as User.new(name: 'Test', email: 'test@example.com')
  end

  test 'new' do
    get new_terraform_aws_backend_path
    assert_response :success
  end

  test 'create' do
    attributes = {
      label: 'Test Backend',
      aws_region: 'test-region',
      aws_access_key_id: 'test-access-key-id',
      aws_secret_access_key: 'test-secret-access-key',
      route_53_zone_id: 'test-route-53-zone-id',
      vpc_id: 'test-vpc-id'
    }

    post(
      terraform_aws_backends_path,
      params: {
        backends_terraform_aws: attributes
      }
    )

    assert_response :redirect
    follow_redirect!
    assert_response :success

    backend = Backends::TerraformAws.last
    attributes.each do |(key, value)|
      assert_equal backend.send(key), value
    end
  end

  test 'update' do
    backend = Backends::TerraformAws.create(
      label: 'Old label',
      aws_region: 'old-test-region',
      aws_access_key_id: 'old-test-access-key-id',
      aws_secret_access_key: 'old-test-secret-access-key',
      route_53_zone_id: 'old-test-route-53-zone-id',
      vpc_id: 'test-vpc-id'
    )

    new_attributes = {
      label: 'New label',
      aws_access_key_id: 'new-test-access-key-id',
      aws_secret_access_key: 'new-test-secret-access-key'
    }

    put(
      terraform_aws_backend_path(backend),
      params: {
        backends_terraform_aws: new_attributes
      }
    )

    assert_response :success

    backend.reload
  end

  test 'show' do
    backend = Backends::TerraformAws.create(
      label: 'Test Backend',
      aws_region: 'old-test-region',
      aws_access_key_id: 'old-test-access-key-id',
      aws_secret_access_key: 'old-test-secret-access-key',
      route_53_zone_id: 'old-test-route-53-zone-id',
      vpc_id: 'test-vpc-id'
    )

    get terraform_aws_backend_path(backend)

    assert_response :success
  end

  test 'destroy' do
    backend = Backends::TerraformAws.create(
      label: 'Test Backend',
      aws_region: 'old-test-region',
      aws_access_key_id: 'old-test-access-key-id',
      aws_secret_access_key: 'old-test-secret-access-key',
      route_53_zone_id: 'old-test-route-53-zone-id',
      vpc_id: 'test-vpc-id'
    )

    delete terraform_aws_backend_path(backend)

    assert_response :redirect
  end
end