aboutsummaryrefslogtreecommitdiff
path: root/test/controllers
diff options
context:
space:
mode:
authorChristopher Baines <mail@cbaines.net>2018-04-03 07:52:00 +0100
committerChristopher Baines <mail@cbaines.net>2018-04-03 21:58:55 +0100
commit9e622112a80f493eab53420d7dafedb9dd10a612 (patch)
tree6a21d19f6ff7ae72db8510f8e0ae813bb8a49045 /test/controllers
parenta29946a593988003cbd4637293c5b4cc1aee7eaa (diff)
downloadgovuk-mini-environment-admin-9e622112a80f493eab53420d7dafedb9dd10a612.tar
govuk-mini-environment-admin-9e622112a80f493eab53420d7dafedb9dd10a612.tar.gz
Improve the test suite
Add some tests, and setup the helpers. For some reason, directly running the test files requires the ugly `ENV['RAILS_ENV'] = 'test'` line at the top of the test_helper.rb file.
Diffstat (limited to 'test/controllers')
-rw-r--r--test/controllers/backends/terraform_aws_controller_test.rb85
-rw-r--r--test/controllers/backends/terraform_libvirt_controller_test.rb77
-rw-r--r--test/controllers/govuk_guix/revisions_controller_test.rb32
-rw-r--r--test/controllers/que_jobs_controller_test.rb21
-rw-r--r--test/controllers/setup_controller_test.rb12
5 files changed, 204 insertions, 23 deletions
diff --git a/test/controllers/backends/terraform_aws_controller_test.rb b/test/controllers/backends/terraform_aws_controller_test.rb
index 0c574fa..41373b8 100644
--- a/test/controllers/backends/terraform_aws_controller_test.rb
+++ b/test/controllers/backends/terraform_aws_controller_test.rb
@@ -1,14 +1,89 @@
-require 'test_helper'
+require 'integration_test_helper'
class Backends::TerraformAwsControllerTest < ActionDispatch::IntegrationTest
- test "should get new" do
- get backends_terraform_aws_new_url
+ 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'
+ }
+
+ 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'
+ )
+
+ 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 "should get show" do
- get backends_terraform_aws_show_url
+ 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'
+ )
+
+ 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'
+ )
+
+ delete terraform_aws_backend_path(backend)
+
+ assert_response :redirect
+ end
end
diff --git a/test/controllers/backends/terraform_libvirt_controller_test.rb b/test/controllers/backends/terraform_libvirt_controller_test.rb
index 376d753..b34a8ac 100644
--- a/test/controllers/backends/terraform_libvirt_controller_test.rb
+++ b/test/controllers/backends/terraform_libvirt_controller_test.rb
@@ -1,14 +1,81 @@
-require 'test_helper'
+require 'integration_test_helper'
class Backends::TerraformLibvirtControllerTest < ActionDispatch::IntegrationTest
- test "should get new" do
- get backends_terraform_libvirt_new_url
+ 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 "should get show" do
- get backends_terraform_libvirt_show_url
+ test 'create' do
+ attributes = {
+ label: 'Test Backend',
+ domain: 'test.backend.example.com',
+ uri: 'test://uri'
+ }
+
+ post(
+ terraform_libvirt_backends_path,
+ params: {
+ backends_terraform_libvirt: attributes
+ }
+ )
+
+ assert_response :redirect
+ follow_redirect!
assert_response :success
+
+ backend = Backends::TerraformLibvirt.last
+ attributes.each do |(key, value)|
+ assert_equal backend.send(key), value
+ end
end
+ test 'update' do
+ backend = Backends::TerraformLibvirt.create(
+ label: 'Old label',
+ domain: 'old.domain.example.com',
+ uri: 'old://uri'
+ )
+
+ new_attributes = {
+ label: 'New label'
+ }
+
+ put(
+ terraform_libvirt_backend_path(backend),
+ params: {
+ backends_terraform_libvirt: new_attributes
+ }
+ )
+
+ assert_response :success
+ end
+
+ test 'show' do
+ backend = Backends::TerraformLibvirt.create(
+ label: 'Test Backend',
+ domain: 'test.backend.example.com',
+ uri: 'test://uri'
+ )
+
+ get terraform_libvirt_backend_path(backend)
+
+ assert_response :success
+ end
+
+ test 'destroy' do
+ backend = Backends::TerraformLibvirt.create(
+ label: 'Test Backend',
+ domain: 'test.backend.example.com',
+ uri: 'test://uri'
+ )
+
+ delete terraform_libvirt_backend_path(backend)
+
+ assert_response :redirect
+ end
end
diff --git a/test/controllers/govuk_guix/revisions_controller_test.rb b/test/controllers/govuk_guix/revisions_controller_test.rb
index ae93202..51ca048 100644
--- a/test/controllers/govuk_guix/revisions_controller_test.rb
+++ b/test/controllers/govuk_guix/revisions_controller_test.rb
@@ -1,9 +1,35 @@
-require 'test_helper'
+require 'integration_test_helper'
class GovukGuix::RevisionsControllerTest < ActionDispatch::IntegrationTest
- test "should get index" do
- get govuk_guix_revisions_index_url
+ setup do
+ login_as User.new(name: 'Test', email: 'test@example.com')
+ end
+
+ test 'show' do
+ revision = GovukGuix::Revision.create(
+ commit_hash: 'test-commit-hash',
+ store_path: 'test-store-path'
+ )
+
+ get govuk_guix_revision_path(revision)
+
assert_response :success
end
+ test 'enqueue_fetch_revision' do
+ revision = 'test-revision'
+
+ GovukGuix::FetchRevisionJob.expects(:enqueue).with(revision)
+
+ post(
+ enqueue_fetch_govuk_guix_revision_path,
+ params: {
+ revision: revision
+ }
+ )
+
+ assert_response :redirect
+ follow_redirect!
+ assert_response :success
+ end
end
diff --git a/test/controllers/que_jobs_controller_test.rb b/test/controllers/que_jobs_controller_test.rb
index 691d0f3..f5821e3 100644
--- a/test/controllers/que_jobs_controller_test.rb
+++ b/test/controllers/que_jobs_controller_test.rb
@@ -1,14 +1,23 @@
-require 'test_helper'
+require 'integration_test_helper'
class QueJobsControllerTest < ActionDispatch::IntegrationTest
- test "should get cancel" do
- get que_jobs_cancel_url
- assert_response :success
+ setup do
+ login_as User.new
end
- test "should get retry_now" do
- get que_jobs_retry_now_url
+ test 'cancel' do
+ job = GovukGuix::FetchRevisionJob.enqueue('test-revision')
+
+ post cancel_que_job_path(job.attrs['job_id'])
+
assert_response :success
end
+ test 'retry now' do
+ job = GovukGuix::FetchRevisionJob.enqueue('test-revision')
+
+ post retry_now_que_job_path(job.attrs['job_id'])
+
+ assert_response :success
+ end
end
diff --git a/test/controllers/setup_controller_test.rb b/test/controllers/setup_controller_test.rb
index d350d63..0f8326b 100644
--- a/test/controllers/setup_controller_test.rb
+++ b/test/controllers/setup_controller_test.rb
@@ -1,7 +1,11 @@
-require 'test_helper'
+require 'integration_test_helper'
class SetupControllerTest < ActionDispatch::IntegrationTest
- # test "the truth" do
- # assert true
- # end
+ test 'show' do
+ login_as User.new(name: 'Test')
+
+ get setup_path
+
+ assert_response :success
+ end
end