Skip to content

Commit

Permalink
Merge pull request #741 from alphagov/add-tests-for-CD
Browse files Browse the repository at this point in the history
Add new test to increase coverage for continuous deployment
  • Loading branch information
callumknights authored Jan 5, 2021
2 parents 4d3986e + d846427 commit bffd5ba
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 10 deletions.
8 changes: 2 additions & 6 deletions app/controllers/links_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,8 @@ def update
end

def destroy
if @link.make_missing
redirect("deleted")
else
flash[:danger] = "Could not delete link."
redirect_back
end
@link.make_missing
redirect("deleted")
end

def homepage_links_status_csv
Expand Down
5 changes: 4 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
Rails.application.routes.draw do
root to: "links#index"

get "/healthcheck", to: proc { [200, {}, %w[OK]] }
get "/healthcheck", to: GovukHealthcheck.rack_response(
GovukHealthcheck::ActiveRecord,
GovukHealthcheck::SidekiqRedis,
)

resources "local_authorities", only: %i[index show], param: :local_authority_slug do
member do
Expand Down
9 changes: 9 additions & 0 deletions spec/controllers/links_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@
@local_authority = create(:local_authority)
@service = create(:service)
@interaction = create(:interaction)
@service_interaction = create(:service_interaction, service: @service, interaction: @interaction)
end

describe "GET destroy" do
it "deletes link and redirects" do
get :destroy, params: { local_authority_slug: @local_authority.slug, service_slug: @service.slug, interaction_slug: @interaction.slug }
expect(response).to have_http_status(302)
expect(flash[:success]).to match("Link has been deleted")
end
end

describe "GET edit" do
Expand Down
19 changes: 16 additions & 3 deletions spec/requests/healthcheck_spec.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,21 @@
RSpec.describe "healthcheck path", type: :request do
it "should respond with 'OK'" do
before do
get "/healthcheck"
end

it "returns a 200 HTTP status" do
expect(response).to have_http_status(:ok)
end

it "returns postgres connection status" do
json = JSON.parse(response.body)

expect(json["checks"]).to include("database_connectivity")
end

it "returns redis connections status" do
json = JSON.parse(response.body)

expect(response.status).to eq(200)
expect(response.body).to eq("OK")
expect(json["checks"]).to include("redis_connectivity")
end
end

0 comments on commit bffd5ba

Please sign in to comment.