]> git.openstreetmap.org Git - rails.git/blob - test/controllers/api/user_blocks_controller_test.rb
Merge remote-tracking branch 'upstream/pull/4735'
[rails.git] / test / controllers / api / user_blocks_controller_test.rb
1 require "test_helper"
2
3 module Api
4   class UserBlocksControllerTest < ActionDispatch::IntegrationTest
5     def test_routes
6       assert_routing(
7         { :path => "/api/0.6/user_blocks/1", :method => :get },
8         { :controller => "api/user_blocks", :action => "show", :id => "1" }
9       )
10       assert_routing(
11         { :path => "/api/0.6/user_blocks/1.json", :method => :get },
12         { :controller => "api/user_blocks", :action => "show", :id => "1", :format => "json" }
13       )
14     end
15
16     def test_show
17       block = create(:user_block)
18
19       get api_user_block_path(:id => block)
20       assert_response :success
21       assert_select "user_block[id='#{block.id}']", 1
22
23       get api_user_block_path(:id => block, :format => "json")
24       assert_response :success
25       js = ActiveSupport::JSON.decode(@response.body)
26       assert_not_nil js
27       assert_equal block.id, js["user_block"]["id"]
28     end
29
30     def test_show_not_found
31       get api_user_block_path(:id => 123)
32       assert_response :not_found
33       assert_equal "text/plain", @response.media_type
34     end
35   end
36 end