-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove unused game_id model, add scaffold for api spec Add factory_girl instead of using rails fixtures Remove the rest of the test dir
- Loading branch information
Showing
20 changed files
with
346 additions
and
80 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,3 +16,5 @@ | |
trebek.psd | ||
*.swp | ||
.DS_Store | ||
|
||
.byebug_history |
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,2 @@ | ||
--color | ||
--require spec_helper |
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
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,10 +1,9 @@ | ||
class Clue < ActiveRecord::Base | ||
attr_accessible :airdate, :answer, :question, :value, :category_id, :category | ||
belongs_to :category, :counter_cache => true | ||
|
||
|
||
def to_json(options={}) | ||
def to_json(options={}) | ||
options[:except] ||= [:updated_at, :created_at] | ||
super(options) | ||
end | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
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
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,7 +1,2 @@ | ||
# This file should contain all the record creation needed to seed the database with its default values. | ||
# The data can then be loaded with the rake db:seed (or created alongside the db with db:setup). | ||
# | ||
# Examples: | ||
# | ||
# cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }]) | ||
# Mayor.create(name: 'Emanuel', city: cities.first) | ||
|
||
Category.create(title: "Placeholder") |
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,112 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.describe ApiController, type: :controller do | ||
describe '#clues' do | ||
let!(:recent_clue) { FactoryGirl.create(:clue, airdate: Time.now - 1.week ) } | ||
let!(:cheap_clue) { FactoryGirl.create(:clue, value: 100 ) } | ||
let!(:new_clue ) { FactoryGirl.create(:clue, airdate: Time.now ) } | ||
|
||
it 'only returns the proper valued clues' do | ||
get :clues, value: cheap_clue.value, format: :json | ||
expect(response).to be_success | ||
|
||
body = JSON.parse(response.body) | ||
expect(body.count).to eq(1) | ||
|
||
clue = body.first | ||
expect(clue["id"]).to eq(cheap_clue.id) | ||
end | ||
|
||
it 'only returns clues within the proper airdates' do | ||
get :clues, min_date: recent_clue.airdate.to_s, max_date: (new_clue.airdate + 1.day).to_s, format: :json | ||
expect(response).to be_success | ||
|
||
body = JSON.parse(response.body) | ||
expect(body.count).to eq(2) | ||
|
||
response_ids = body.map { |h| h["id"] } | ||
expect(response_ids).to include(recent_clue.id) | ||
expect(response_ids).to include(new_clue.id) | ||
end | ||
|
||
it 'only returns clues from the proper category' do | ||
get :clues, category: cheap_clue.category_id, format: :json | ||
expect(response).to be_success | ||
body = JSON.parse(response.body) | ||
expect(body.count).to eq(1) | ||
|
||
clue = body.first | ||
expect(clue["id"]).to eq(cheap_clue.id) | ||
end | ||
|
||
it 'follows the correct offset' do | ||
get :clues, offset: 2, format: :json | ||
expect(response).to be_success | ||
body = JSON.parse(response.body) | ||
expect(body.count).to eq(1) | ||
end | ||
end | ||
|
||
describe '#random' do | ||
let!(:clue1) { FactoryGirl.create(:clue) } | ||
let!(:clue2) { FactoryGirl.create(:clue) } | ||
|
||
it 'returns the default of one clue' do | ||
get :random, format: :json | ||
expect(response).to be_success | ||
body = JSON.parse(response.body) | ||
expect(body.count).to eq(1) | ||
end | ||
|
||
it 'returns the passed count of clues' do | ||
get :random, count: 2, format: :json | ||
expect(response).to be_success | ||
body = JSON.parse(response.body) | ||
expect(body.count).to eq(2) | ||
end | ||
end | ||
|
||
describe '#categories' do | ||
let!(:category1) { FactoryGirl.create(:category) } | ||
let!(:category2) { FactoryGirl.create(:category) } | ||
|
||
it 'returns the correct count' do | ||
get :categories, count: 1, format: :json | ||
expect(response).to be_success | ||
body = JSON.parse(response.body) | ||
expect(body.count).to eq(1) | ||
end | ||
|
||
it 'returns the correct offset' do | ||
get :categories, offset: 1, format: :json | ||
expect(response).to be_success | ||
body = JSON.parse(response.body) | ||
expect(body.count).to eq(1) | ||
end | ||
end | ||
|
||
describe '#single_category' do | ||
let(:category) { FactoryGirl.create(:category) } | ||
it 'returns the right category for id' do | ||
get :single_category, id: category.id, format: :json | ||
expect(response).to be_success | ||
|
||
body = JSON.parse(response.body) | ||
expect(body["id"]).to eq(category.id) | ||
expect(body["title"]).to eq(category.title) | ||
expect(body["clues_count"]).to eq(category.clues_count) | ||
end | ||
end | ||
|
||
describe '#mark_invalid' do | ||
let!(:clue) { FactoryGirl.create(:clue) } | ||
|
||
it 'increments the invalid_count on selected clue' do | ||
expect{ | ||
get :mark_invalid, id: clue.id, format: :json | ||
expect(response).to be_success | ||
}.to change{ clue.reload.invalid_count }.from(nil).to(1) | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
FactoryGirl.define do | ||
factory :category do | ||
title "Names of things" | ||
clues_count 1 | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
FactoryGirl.define do | ||
factory :clue do | ||
answer "John" | ||
question "Last name Doe first name" | ||
value 400 | ||
airdate Chronic.parse('1985-04-10 17:00:00') | ||
category | ||
end | ||
end |
Oops, something went wrong.