-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #122 from npauzenga/tasks/game-night-acceptance-specs
complete game_night acceptance specs
- Loading branch information
Showing
7 changed files
with
284 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
class IndexGameNight < StandardInteraction | ||
def execute | ||
context.game_nights = GameNight.all | ||
end | ||
|
||
def validate_output | ||
context.fail!(errors: "internal server error") unless context.game_nights | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
class GameNightSerializer < ActiveModel::Serializer | ||
attributes :id, :time, :location_name, :location_address | ||
attributes :id, :name, :time, :location_name, :location_address | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
require "rspec_api_documentation/dsl" | ||
|
||
RSpec.resource "GameNights" do | ||
let(:authenticated_user) do | ||
create(:confirmed_user) | ||
end | ||
|
||
let(:auth_token) do | ||
Knock::AuthToken.new(payload: { sub: authenticated_user.id }).token | ||
end | ||
|
||
def schema_path | ||
"./config/schema/schemata/game_night.json" | ||
end | ||
|
||
shared_context "game_night parameters" do | ||
parameter "name", <<-DESC, scope: :game_night | ||
The name of the game_night. | ||
DESC | ||
parameter "time", <<-DESC, scope: :game_night, required: true | ||
The time of the game_night. | ||
DESC | ||
parameter "location_name", <<-DESC, scope: :game_night, required: true | ||
The location of the game_night. | ||
DESC | ||
parameter "location_address", <<-DESC, scope: :game_night | ||
The address of the game_night. | ||
DESC | ||
end | ||
|
||
post "/game_nights" do | ||
let(:schema_path) { "#{Rails.root}/config/schema/api.json" } | ||
let(:last_response) { response } | ||
let(:last_request) { request } | ||
|
||
include_context "game_night parameters" | ||
|
||
let(:name) { "Waaggh" } | ||
let(:time) { "2015-09-12 22:49:27 +0530" } | ||
let(:location_name) { "Library" } | ||
let(:location_address) { "999 main st. Silver Spring, MD 20910" } | ||
|
||
header "Authorization", :auth_token | ||
|
||
example_request "POST /game_nights" do | ||
expect(status).to eq 201 | ||
|
||
json_response = JSON.parse(response_body) | ||
|
||
expect(json_response["data"]["attributes"]["name"]). | ||
to eq public_send(:name) | ||
|
||
expect(authenticated_user.game_nights.first.name). | ||
to eq public_send(:name) | ||
|
||
game_night = GameNight.first | ||
|
||
expect(game_night.users.first).to eq authenticated_user | ||
end | ||
end | ||
|
||
patch "/game_nights/:id" do | ||
include_context "game_night parameters" | ||
|
||
let!(:game_night) { create(:game_night) } | ||
let(:id) { game_night.id } | ||
|
||
parameter "id", <<-DESC, required: true | ||
The id of the game_night. | ||
DESC | ||
|
||
let(:name) { "New Name" } | ||
let(:time) { "2015-09-12 22:49:27 +0530" } | ||
let(:location_name) { "Library" } | ||
let(:location_address) { "999 main st. Silver Spring, MD 20910" } | ||
|
||
header "Authorization", :auth_token | ||
|
||
example_request "PATCH /game_nights/:id" do | ||
expect(status).to eq 200 | ||
|
||
game_night = JSON.parse(response_body) | ||
|
||
expect(game_night["data"]["attributes"]["name"]). | ||
to eq public_send(:name) | ||
end | ||
end | ||
|
||
get "/game_nights/:id" do | ||
let!(:game_night) { create(:game_night) } | ||
let(:id) { game_night.id } | ||
let(:name) { game_night.name } | ||
|
||
parameter "id", <<-DESC, required: true | ||
The id of the game_night. | ||
DESC | ||
|
||
header "Authorization", :auth_token | ||
|
||
example_request "GET /game_nights/:id" do | ||
expect(status).to eq 200 | ||
|
||
game_night = JSON.parse(response_body) | ||
|
||
expect(game_night["data"]["attributes"]["name"]). | ||
to eq public_send(:name) | ||
end | ||
end | ||
|
||
get "/game_nights/" do | ||
let!(:game_night1) { create(:game_night) } | ||
let!(:game_night2) { create(:game_night) } | ||
let!(:game_night3) { create(:game_night) } | ||
|
||
header "Authorization", :auth_token | ||
|
||
example_request "GET /game_nights/" do | ||
expect(status).to eq 200 | ||
|
||
list = JSON.parse(response_body) | ||
|
||
expect(list["data"][0].value?(game_night1.id.to_s)).to be_truthy | ||
expect(list["data"][1].value?(game_night2.id.to_s)).to be_truthy | ||
expect(list["data"][2].value?(game_night3.id.to_s)).to be_truthy | ||
end | ||
end | ||
|
||
delete "/game_nights/:id" do | ||
let!(:game_night) { create(:game_night) } | ||
let(:id) { game_night.id } | ||
|
||
header "Authorization", :auth_token | ||
|
||
parameter "id", <<-DESC, required: true | ||
The id of the game_night. | ||
DESC | ||
|
||
example_request "DELETE /game_nights/:id" do | ||
expect(status).to eq 204 | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
RSpec.describe IndexGameNight do | ||
describe ".call" do | ||
subject do | ||
described_class.call | ||
end | ||
|
||
let!(:game_night1) { create(:game_night) } | ||
let!(:game_night2) { create(:game_night) } | ||
let!(:game_night3) { create(:game_night) } | ||
|
||
context "when successful" do | ||
it "returns a successful context" do | ||
is_expected.to be_a_success | ||
end | ||
|
||
it "sets game_nights to an array of game_nights" do | ||
expect(subject.game_nights). | ||
to eq([game_night1, game_night2, game_night3]) | ||
end | ||
end | ||
|
||
context "when unsuccessful" do | ||
before do | ||
allow(GameNight).to receive(:all).and_return(nil) | ||
end | ||
|
||
it "fails" do | ||
is_expected.to be_a_failure | ||
end | ||
|
||
it "returns an error" do | ||
expect(subject.errors).to eq("internal server error") | ||
end | ||
end | ||
end | ||
end |