From 9bc3ce8558cb310e4d88ab32ffa75e833c6b3802 Mon Sep 17 00:00:00 2001 From: Rafael Reggiani Manzo Date: Wed, 10 Jun 2015 13:04:39 -0300 Subject: [PATCH] Handle invalid tutorial names --- app/controllers/tutorials_controller.rb | 2 ++ spec/controllers/tutorials_controller_spec.rb | 22 +++++++++++++++++----- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/app/controllers/tutorials_controller.rb b/app/controllers/tutorials_controller.rb index d46e0ec..44a166c 100644 --- a/app/controllers/tutorials_controller.rb +++ b/app/controllers/tutorials_controller.rb @@ -1,4 +1,6 @@ class TutorialsController < ApplicationController + rescue_from ActionView::MissingTemplate, with: :not_found + def view render params[:name] end diff --git a/spec/controllers/tutorials_controller_spec.rb b/spec/controllers/tutorials_controller_spec.rb index a384362..cd24003 100644 --- a/spec/controllers/tutorials_controller_spec.rb +++ b/spec/controllers/tutorials_controller_spec.rb @@ -2,13 +2,25 @@ require 'rails_helper' describe TutorialsController do describe 'view' do - let!(:name) { "analyzing" } + context 'with a valid name' do + let!(:name) { "analyzing" } - before :each do - get :view, name: name + before :each do + get :view, name: name + end + + it { is_expected.to render_template(name) } + it { is_expected.to respond_with(:success) } end - it { is_expected.to render_template(name) } - it { is_expected.to respond_with(:success) } + context 'with a invalid name' do + let!(:name) { "invalid_name" } + + before :each do + get :view, name: name + end + + it { is_expected.to respond_with(:not_found) } + end end end -- libgit2 0.21.2