Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 2 additions & 8 deletions app/controllers/events_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,8 @@

class EventsController < ApplicationController
def index
render(json: { data: Elasticsearch::Model.client.info })
end

def create
render(json: { message: "create" })
end
message = { data: { action: "events#index" } }

def update
render(json: { message: "update" })
render(json: message)
end
end
3 changes: 2 additions & 1 deletion app/controllers/heartbeat_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

class HeartbeatController < ApplicationController
def index
message = { healthy: true }
message = { data: { healthy: true } }

render(json: message)
end
end
2 changes: 2 additions & 0 deletions config/environments/development.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,6 @@

config.active_job.verbose_enqueue_logs = true
config.action_controller.raise_on_missing_callback_actions = true

config.hosts << "www.example.com"
end
2 changes: 1 addition & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

Rails.application.routes.draw do
resources :heartbeat, only: [:index]
resources :events, only: [:index, :create, :update]
resources :events, only: [:index]
end
27 changes: 27 additions & 0 deletions spec/requests/events_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# frozen_string_literal: true

require "rails_helper"

RSpec.describe("EventsController", type: :request) do
describe "GET /index" do
it "returns a 200 status code" do
get "/events"

expect(response).to(have_http_status(:ok))
end

it "returns json" do
get "/events"

expect(response.content_type).to(eq("application/json; charset=utf-8"))
end

it "returns the expected data" do
get "/events"

expected = { data: { action: "events#index" } }

expect(JSON.parse(response.body, symbolize_names: true)).to(eq(expected))
end
end
end
11 changes: 8 additions & 3 deletions spec/requests/heartbeat_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,26 @@

require "rails_helper"

RSpec.describe("HeartbeatControllers", type: :request) do
RSpec.describe("HeartbeatController", type: :request) do
describe "GET /index" do
it "returns a 200 status code" do
get "/heartbeat"

expect(response).to(have_http_status(:ok))
end

it "returns json" do
get "/heartbeat"

expect(response.content_type).to(eq("application/json; charset=utf-8"))
end

it "retrurns the expected data" do
it "returns the expected data" do
get "/heartbeat"
expect(JSON.parse(response.body, symbolize_names: true)).to(eq({ healthy: true }))

expected = { data: { healthy: true } }

expect(JSON.parse(response.body, symbolize_names: true)).to(eq(expected))
end
end
end