Guest User

Untitled

a guest
Nov 23rd, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.40 KB | None | 0 0
  1. require 'test_helper'
  2.  
  3. class FoosController < ApplicationController
  4. def index
  5. render plain: 'something'
  6. end
  7. end
  8.  
  9. class UsersControllerTest < ActionDispatch::IntegrationTest
  10. def test_some_routing
  11. with_routing do |set|
  12. set.draw do
  13. get '/foos' => 'foos#index'
  14. end
  15.  
  16. get '/foos'
  17. assert_equal 200, response.status
  18. end
  19. end
  20. end
  21.  
  22. class ActionDispatch::IntegrationTest
  23. def with_routing(&block)
  24. yield ComfortableMexicanSofa::Application.routes
  25. ensure
  26. ComfortableMexicanSofa::Application.routes_reloader.reload!
  27. end
  28. end
  29.  
  30. def with_foo_route
  31. Rails.application.routes.draw do
  32. get 'foo' => 'foo#index'
  33. end
  34. yield
  35. Rails.application.routes_reloader.reload!
  36. end
  37.  
  38. with_foo_route do
  39. get '/foo'
  40. assert_equal 200, status
  41. end
  42.  
  43. require 'test_helper'
  44.  
  45. class ConcernedController < ApplicationController
  46. include Concern
  47.  
  48. def action
  49. render plain: "response", status: :ok
  50. end
  51. end
  52.  
  53. class ConcernTest < ActionDispatch::IntegrationTest
  54. setup do
  55. @controller = ConcernedController.new
  56.  
  57. Rails.application.routes.draw do
  58. get "/action" => "concerned#action"
  59. post "/action" => "concerned#action"
  60. end
  61. end
  62.  
  63. teardown do
  64. Rails.application.reload_routes!
  65. end
  66.  
  67. test "concern method" do
  68. post "/action"
  69.  
  70. # Test what the concern does
  71.  
  72. assert_response :ok
  73. assert_equal "Response", response.body
  74. end
  75. end
Add Comment
Please, Sign In to add comment