Commit 5f7da1db6fdee040837dcfa7f6dd202c67a137f3

Authored by Diego Camarinha
2 parents 1c82f9f1 9bc3ce85

Merge pull request #227 from mezuro/tutorials_not_found

Handle invalid tutorial names
app/controllers/tutorials_controller.rb
1 1 class TutorialsController < ApplicationController
  2 + rescue_from ActionView::MissingTemplate, with: :not_found
  3 +
2 4 def view
3 5 render params[:name]
4 6 end
... ...
spec/controllers/tutorials_controller_spec.rb
... ... @@ -2,13 +2,25 @@ require &#39;rails_helper&#39;
2 2  
3 3 describe TutorialsController do
4 4 describe 'view' do
5   - let!(:name) { "analyzing" }
  5 + context 'with a valid name' do
  6 + let!(:name) { "analyzing" }
6 7  
7   - before :each do
8   - get :view, name: name
  8 + before :each do
  9 + get :view, name: name
  10 + end
  11 +
  12 + it { is_expected.to render_template(name) }
  13 + it { is_expected.to respond_with(:success) }
9 14 end
10 15  
11   - it { is_expected.to render_template(name) }
12   - it { is_expected.to respond_with(:success) }
  16 + context 'with a invalid name' do
  17 + let!(:name) { "invalid_name" }
  18 +
  19 + before :each do
  20 + get :view, name: name
  21 + end
  22 +
  23 + it { is_expected.to respond_with(:not_found) }
  24 + end
13 25 end
14 26 end
... ...