2 require_relative "../user_blocks/table_test_helper"
5 class IssuedBlocksControllerTest < ActionDispatch::IntegrationTest
6 include UserBlocks::TableTestHelper
9 # test all routes which lead to this controller
12 { :path => "/user/username/blocks_by", :method => :get },
13 { :controller => "users/issued_blocks", :action => "show", :user_display_name => "username" }
18 moderator_user = create(:moderator_user)
19 second_moderator_user = create(:moderator_user)
20 normal_user = create(:user)
21 active_block = create(:user_block, :creator => moderator_user)
22 expired_block = create(:user_block, :expired, :creator => second_moderator_user)
23 revoked_block = create(:user_block, :revoked, :creator => second_moderator_user)
25 # Asking for a list of blocks with a bogus user name should fail
26 get user_issued_blocks_path("non_existent_user")
27 assert_response :not_found
28 assert_template "users/no_such_user"
29 assert_select "h1", "The user non_existent_user does not exist"
31 # Check the list of blocks given by one moderator
32 get user_issued_blocks_path(moderator_user)
33 assert_response :success
34 assert_select "h1 a[href='#{user_path moderator_user}']", :text => moderator_user.display_name
35 assert_select "a.active[href='#{user_issued_blocks_path moderator_user}']"
36 assert_select "table#block_list tbody", :count => 1 do
38 assert_select "a[href='#{user_block_path(active_block)}']", 1
41 # Check the list of blocks given by a different moderator
42 get user_issued_blocks_path(second_moderator_user)
43 assert_response :success
44 assert_select "h1 a[href='#{user_path second_moderator_user}']", :text => second_moderator_user.display_name
45 assert_select "a.active[href='#{user_issued_blocks_path second_moderator_user}']"
46 assert_select "table#block_list tbody", :count => 1 do
48 assert_select "a[href='#{user_block_path(expired_block)}']", 1
49 assert_select "a[href='#{user_block_path(revoked_block)}']", 1
52 # Check the list of blocks (not) given by a normal user
53 get user_issued_blocks_path(normal_user)
54 assert_response :success
55 assert_select "table#block_list", false
56 assert_select "p", "#{normal_user.display_name} has not made any blocks yet."
60 user = create(:moderator_user)
61 user_blocks = create_list(:user_block, 50, :creator => user).reverse
62 next_path = user_issued_blocks_path(user)
65 assert_response :success
66 check_user_blocks_table user_blocks[0...20]
67 check_no_page_link "Newer Blocks"
68 next_path = check_page_link "Older Blocks"
71 assert_response :success
72 check_user_blocks_table user_blocks[20...40]
73 check_page_link "Newer Blocks"
74 next_path = check_page_link "Older Blocks"
77 assert_response :success
78 check_user_blocks_table user_blocks[40...50]
79 check_page_link "Newer Blocks"
80 check_no_page_link "Older Blocks"
83 def test_show_invalid_paged
84 user = create(:moderator_user)
86 %w[-1 0 fred].each do |id|
87 get user_issued_blocks_path(user, :before => id)
88 assert_redirected_to :controller => "/errors", :action => :bad_request
90 get user_issued_blocks_path(user, :after => id)
91 assert_redirected_to :controller => "/errors", :action => :bad_request