Skip to content
Permalink
Browse files

Add code from episode 06

This commits the spec, routes, and controller changes from episode 06,
which covers refactoring the routes.
  • Loading branch information...
brettchalupa committed Nov 22, 2017
1 parent ea8337a commit 8f9dc32173f1b9a202b25fdeac92aa50732ea955
@@ -6,6 +6,11 @@ The completed code from Episode 06. This episode covers refactoring the
code from the previous episodes into more organized routes to prepare
the app for more functionality.

This episode covers:

- Creating namespaces in Rails routes
- Making adjustments to existing specs

Install the dependencies `bundle install` and run the specs with `bin/rspec`.

Software used:
@@ -1,4 +1,4 @@
class ConsolesController < ApplicationController
class Api::ConsolesController < ApplicationController
def index
if params[:manufacturer].present?
consoles = Console.where(manufacturer: params[:manufacturer])
@@ -1,4 +1,4 @@
class StatusController < ApplicationController
class Api::StatusController < ApplicationController
def index
render(json: { 'status' => 'ok' })
end
@@ -1,6 +1,9 @@
Rails.application.routes.draw do
get('home' => 'home#index')
root(to: 'home#index')
get('about' => 'about#index')
get('status' => 'status#index')
get('consoles' => 'consoles#index')

namespace :api do
get('status' => 'status#index')
get('consoles' => 'consoles#index')
end
end
@@ -2,7 +2,7 @@

RSpec.describe 'Home features' do
it 'displays the name of the app and links to the About page' do
visit('/home')
visit('/')
expect(page).to have_content('Game Tracker')
click_link('About')
expect(current_path).to eql('/about')
@@ -12,9 +12,9 @@
Console.create(name: 'PS2', manufacturer: 'Sony')
end

describe 'GET /consoles' do
describe 'GET /api/consoles' do
it 'returns an array of the consoles' do
get('/consoles')
get('/api/consoles')
expect(response_json['consoles']).to contain_exactly(
'Nintendo NES',
'Nintendo SNES',
@@ -28,7 +28,7 @@
end

it 'supports specifying consoles for a specific manufacturer' do
get('/consoles', params: { manufacturer: 'Nintendo' })
get('/api/consoles', params: { manufacturer: 'Nintendo' })
expect(response_json['consoles']).to contain_exactly(
'Nintendo NES',
'Nintendo SNES',
@@ -1,9 +1,9 @@
require 'rails_helper'

RSpec.describe 'Status requests' do
describe 'GET /status' do
describe 'GET /api/status' do
it 'returns a status message' do
get('/status')
get('/api/status')
expect(response_json['status']).to eql('ok')
expect(response.status).to eql(200)
end

0 comments on commit 8f9dc32

Please sign in to comment.
You can’t perform that action at this time.