Skip to content

Commit

Permalink
Merge 1ec3ae1 into fc37fa2
Browse files Browse the repository at this point in the history
  • Loading branch information
npauzenga committed Jan 10, 2016
2 parents fc37fa2 + 1ec3ae1 commit 3680abb
Show file tree
Hide file tree
Showing 11 changed files with 256 additions and 1 deletion.
16 changes: 16 additions & 0 deletions app/controllers/game_nights_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
class GameNightsController < AuthenticationController
def create
end

def update
end

def show
end

def index
end

def destroy
end
end
2 changes: 2 additions & 0 deletions app/interactors/create_game_night.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class CreateGameNight < StandardInteraction
end
2 changes: 2 additions & 0 deletions app/interactors/delete_game_night.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class DeleteGameNight < StandardInteraction
end
2 changes: 2 additions & 0 deletions app/interactors/show_game_night.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class ShowGameNight < StandardInteraction
end
2 changes: 2 additions & 0 deletions app/interactors/update_game_night.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class UpdateGameNight < StandardInteraction
end
2 changes: 2 additions & 0 deletions app/serializers/game_night_serializer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class GameNightSerializer < ActiveModel::Serializer
end
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
mount Knock::Engine => "/signin"

resources :users, except: [:new, :edit]
resources :game_nights, except: [:new, :edit]
resources :password_resets, only: [:create, :update]
end
5 changes: 5 additions & 0 deletions db/migrate/20160110154158_add_name_to_game_nights.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddNameToGameNights < ActiveRecord::Migration
def change
add_column :game_nights, :name, :string
end
end
3 changes: 2 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20151219215255) do
ActiveRecord::Schema.define(version: 20160110154158) do

# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
Expand All @@ -24,6 +24,7 @@
t.datetime "updated_at", null: false
t.integer "group_id"
t.integer "organizer_id"
t.string "name"
end

add_index "game_nights", ["group_id"], name: "index_game_nights_on_group_id", using: :btree
Expand Down
221 changes: 221 additions & 0 deletions spec/controllers/game_nights_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,221 @@
include Helpers

RSpec.describe GameNightsController do
let(:user) { create(:confirmed_user) }
let(:game_night) { create(:game_night) }
let(:serializer) { GameNightSerializer.new(game_night) }
let(:serialization) do
ActiveModel::Serializer::Adapter.create(serializer)
end

before do
authenticate
end

describe "POST #create" do
let(:params) do
{ game_night: create_game_night_input.fetch(:game_night_params) }
end

let(:create_game_night_input) do
{ game_night_params: {
name: game_night.name,
time: game_night.time,
location_name: game_night.location_name }
}
end

let(:create_game_night_context) do
Interactor::Context.new(errors: :val, game_night: game_night)
end

before do
allow(CreateGameNight).to receive(:call).with(create_game_night_input).
and_return(create_game_night_context)
end

context "when called" do
it "calls the CreateGameNight interactor" do
expect(CreateGameNight).to receive(:call)
post :create, params
end
end

context "when CreateGameNight is a success" do
it "returns HTTP status 201" do
post :create, params
expect(response).to have_http_status(201)
end

it "renders the game_night as JSON" do
post :create, params
expect(serialization.to_json).to eq(response.body)
end
end

context "when CreateGameNight is a failure" do
let(:create_game_night_context) do
double(:context, success?: false, game_night: game_night)
end

it "returns HTTP status 422" do
post :create, params
expect(response).to have_http_status(422)
end

it "returns an error" do
game_night.errors.add("error")
post :create, params
expect(JSON.parse(response.body)).to eq("error")
end
end
end

describe "PATCH #update" do
let(:params) do
{ id: game_night.id,
game_night: update_game_night_input.fetch(:game_night_params) }
end

let(:update_game_night_input) do
{ game_night_params: {
name: game_night.name,
time: game_night.time,
location_name: game_night.location_name }
}
end

let(:update_game_night_context) do
Interactor::Context.new(errors: :val, game_night: game_night)
end

before do
allow(UpdateGameNight).to receive(:call).with(update_game_night_input).
and_return(update_game_night_context)
end

context "when called" do
it "calls the UpdateGameNight Interactor" do
expect(UpdateGameNight).to receive(:call)
patch :update, params
end
end

context "when UpdateGameNight is a success" do
it "returns HTTP status 200" do
patch :update, params
expect(response).to have_http_status(200)
end

it "renders the GameNight as JSON" do
patch :update, params
expect(serialization.to_json).to eq(response.body)
end
end

context "when UpdateGameNight is a failure" do
let(:update_game_night_context) do
double(:context, error: "invalid", success?: false)
end

it "renders an error" do
patch :update, params
expect(response.body).to eq("invalid")
end

it "returns HTTP status 500" do
patch :update, params
expect(response).to have_http_status(500)
end
end
end

describe "GET #show" do
let(:params) { { id: game_night.id } }
let(:show_game_night_input) { { id: params.fetch(:id).to_s } }

let(:show_game_night_context) do
Interactor::Context.new(errors: :val, game_night: game_night)
end

before do
allow(ShowGameNight).to receive(:call).with(show_game_night_input).
and_return(show_game_night_context)
end

context "when called" do
it "calls the ShowGameNight Interactor" do
expect(ShowGameNight).to receive(:call)
get :show, params
end
end

context "when ShowGameNight is a success" do
it "returns HTTP status 200" do
get :show, params
expect(response).to have_http_status(200)
end

it "renders the GameNight as JSON" do
get :show, params
expect(serialization.to_json).to eq(response.body)
end
end

context "when ShowGameNight is a failure" do
let(:show_game_night_context) do
double(:context, success?: false, game_night: game_night)
end

it "returns HTTP status 404" do
get :show, params
expect(response).to have_http_status(404)
end

it "renders an error" do
get :show, params
expect(response.body).to eq("invalid")
end
end
end

describe "DELETE #delete" do
let(:params) { { id: game_night.id } }
let(:delete_game_night_input) { { id: params.fetch(:id).to_s } }

let(:delete_game_night_context) do
Interactor::Context.new(errors: :val, game_night: game_night)
end

context "when called" do
it "calls the DeleteGameNight Interactor" do
expect(DeleteGameNight).to receive(:call)
delete :delete, params
end
end

context "when DeleteGameNight is a success" do
it "returns HTTP status 200" do
delete :destroy, params
expect(response).to have_http_status(200)
end
end

context "when DeleteGameNight is a failure" do
let(:delete_game_night_context) do
double(:context, success?: false, game_night: game_night)
end

it "returns HTTP status 500" do
delete :destroy, params
expect(response).to have_http_status(500)
end

it "renders an error" do
game_night.errors.add("error")
delete :destroy, params
expect(JSON.parse(response.body)).to eq("error")
end
end
end
end
1 change: 1 addition & 0 deletions spec/factories/game_night.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
FactoryGirl.define do
factory :game_night do
name Faker::Hipster.words(2)
time Time.zone.now
location_name Faker::Hipster.words(2)
location_address Faker::Address.street_name
Expand Down

0 comments on commit 3680abb

Please sign in to comment.