|
| 1 | +Feature: engine routes for controllers |
| 2 | + |
| 3 | + Controller specs can specify the routeset that will be used for the example |
| 4 | + group. This is most useful when testing Rails engines. |
| 5 | + |
| 6 | + @unsupported-on-rails-3-0 |
| 7 | + Scenario: specify engine route |
| 8 | + Given a file named "spec/controllers/widgets_controller_spec.rb" with: |
| 9 | + """ruby |
| 10 | + require "spec_helper" |
| 11 | +
|
| 12 | + # A very simple Rails engine |
| 13 | + module MyEngine |
| 14 | + class Engine < ::Rails::Engine |
| 15 | + isolate_namespace MyEngine |
| 16 | + end |
| 17 | +
|
| 18 | + Engine.routes.draw do |
| 19 | + resources :widgets, :only => [:show] do |
| 20 | + get :random, :on => :collection |
| 21 | + end |
| 22 | + end |
| 23 | +
|
| 24 | + class WidgetsController < ::ActionController::Base |
| 25 | + def random |
| 26 | + @random_widget = Widget.all.shuffle.first |
| 27 | + redirect_to widget_path(@random_widget) |
| 28 | + end |
| 29 | +
|
| 30 | + def show |
| 31 | + @widget = Widget.find(params[:id]) |
| 32 | + render :text => @widget.name |
| 33 | + end |
| 34 | + end |
| 35 | + end |
| 36 | +
|
| 37 | + describe MyEngine::WidgetsController do |
| 38 | + routes { MyEngine::Engine.routes } |
| 39 | +
|
| 40 | + it "redirects to a random widget" do |
| 41 | + widget1 = Widget.create!(:name => "Widget 1") |
| 42 | + widget2 = Widget.create!(:name => "Widget 2") |
| 43 | +
|
| 44 | + get :random |
| 45 | + expect(response).to be_redirect |
| 46 | + expect(response).to redirect_to(assigns(:random_widget)) |
| 47 | + end |
| 48 | + end |
| 49 | + """ |
| 50 | + When I run `rspec spec` |
| 51 | + Then the examples should all pass |
0 commit comments