Skip to content

Commit dbc2a0f

Browse files
Merge pull request #21 from datacite/add-specs
Add events_controller specs
2 parents dd3b7b2 + 155a5f0 commit dbc2a0f

File tree

6 files changed

+42
-13
lines changed

6 files changed

+42
-13
lines changed

app/controllers/events_controller.rb

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,8 @@
22

33
class EventsController < ApplicationController
44
def index
5-
render(json: { data: Elasticsearch::Model.client.info })
6-
end
7-
8-
def create
9-
render(json: { message: "create" })
10-
end
5+
message = { data: { action: "events#index" } }
116

12-
def update
13-
render(json: { message: "update" })
7+
render(json: message)
148
end
159
end

app/controllers/heartbeat_controller.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
class HeartbeatController < ApplicationController
44
def index
5-
message = { healthy: true }
5+
message = { data: { healthy: true } }
6+
67
render(json: message)
78
end
89
end

config/environments/development.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,6 @@
4242

4343
config.active_job.verbose_enqueue_logs = true
4444
config.action_controller.raise_on_missing_callback_actions = true
45+
46+
config.hosts << "www.example.com"
4547
end

config/routes.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22

33
Rails.application.routes.draw do
44
resources :heartbeat, only: [:index]
5-
resources :events, only: [:index, :create, :update]
5+
resources :events, only: [:index]
66
end
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# frozen_string_literal: true
2+
3+
require "rails_helper"
4+
5+
RSpec.describe("EventsController", type: :request) do
6+
describe "GET /index" do
7+
it "returns a 200 status code" do
8+
get "/events"
9+
10+
expect(response).to(have_http_status(:ok))
11+
end
12+
13+
it "returns json" do
14+
get "/events"
15+
16+
expect(response.content_type).to(eq("application/json; charset=utf-8"))
17+
end
18+
19+
it "returns the expected data" do
20+
get "/events"
21+
22+
expected = { data: { action: "events#index" } }
23+
24+
expect(JSON.parse(response.body, symbolize_names: true)).to(eq(expected))
25+
end
26+
end
27+
end

spec/requests/heartbeat_controller_spec.rb

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,26 @@
22

33
require "rails_helper"
44

5-
RSpec.describe("HeartbeatControllers", type: :request) do
5+
RSpec.describe("HeartbeatController", type: :request) do
66
describe "GET /index" do
77
it "returns a 200 status code" do
88
get "/heartbeat"
9+
910
expect(response).to(have_http_status(:ok))
1011
end
1112

1213
it "returns json" do
1314
get "/heartbeat"
15+
1416
expect(response.content_type).to(eq("application/json; charset=utf-8"))
1517
end
1618

17-
it "retrurns the expected data" do
19+
it "returns the expected data" do
1820
get "/heartbeat"
19-
expect(JSON.parse(response.body, symbolize_names: true)).to(eq({ healthy: true }))
21+
22+
expected = { data: { healthy: true } }
23+
24+
expect(JSON.parse(response.body, symbolize_names: true)).to(eq(expected))
2025
end
2126
end
2227
end

0 commit comments

Comments
 (0)