File: customized_redirect_to_test.rb

package info (click to toggle)
ruby-inherited-resources 1.13.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 824 kB
  • sloc: ruby: 4,388; makefile: 6
file content (43 lines) | stat: -rw-r--r-- 917 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
require 'test_helper'

class Post;
  def self.human_name; 'Post'; end
end

class PostsController < InheritedResources::Base
  actions :all, except: [:show]
end

class RedirectToIndexWithoutShowTest < ActionController::TestCase
  tests PostsController

  def setup
    draw_routes do
      resources :posts
    end
  end

  def teardown
    clear_routes
  end

  def test_redirect_index_url_after_create
    Post.stubs(:new).returns(mock_machine(save: true))
    assert !PostsController.respond_to?(:show)
    post :create
    assert_redirected_to 'http://test.host/posts'
  end

  def test_redirect_to_index_url_after_update
    Post.stubs(:find).returns(mock_machine(update: true))
    assert !PostsController.respond_to?(:show)
    put :update, params: { id: '42' }
    assert_redirected_to 'http://test.host/posts'
  end

  protected

    def mock_machine(stubs={})
      @mock_machine ||= mock(stubs)
    end
end