Skip to content

Commit

Permalink
feat: 🎸 fetch users on spam management dashboard (#1811)
Browse files Browse the repository at this point in the history
  • Loading branch information
PeculiarE authored Aug 9, 2022
1 parent 51e082c commit cc2c14a
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 2 deletions.
14 changes: 14 additions & 0 deletions app/controllers/spam_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -155,4 +155,18 @@ def filter_maps
paginate_results(Map.order('updated_at DESC'))
end
end

def filter_users
@users = case params[:type]
when 'banned'
paginate_results(User.where(status: 0).order('created_at DESC'))
when 'moderator'
paginate_results(User.where(role: 'moderator').order('created_at DESC'))
when 'admin'
paginate_results(User.where(role: 'admin').order('created_at DESC'))
else
paginate_results(User.where(status: 1).order('created_at DESC'))
end
puts @users.inspect
end
end
2 changes: 1 addition & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@
delete action + '/:ids', action: action, as: action
end

%w(filter_maps).each do |action|
%w(filter_maps filter_users).each do |action|
get action + '/:type', action: action, as: action
end
end
Expand Down
46 changes: 46 additions & 0 deletions test/controllers/spam_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -537,4 +537,50 @@ def users_custom_setup(ban_users: true)
assert_equal 5, Map.count
assert_equal 1, @maps.length
end

test 'should filter users and show only active users' do
@user.ban

assert_equal User::Status::BANNED, @user.status
assert_equal 'quentin', @user.login

session[:user_id] = 2
post(:filter_users, params: { type: 'active' })
@users = assigns(:users)

assert_equal 4, User.count
assert_equal 3, @users.length
assert @users.all? { |user| user.status == User::Status::NORMAL }
assert @users.collect(&:login).exclude?('quentin')
end

test 'should filter users and show only banned users' do
@user.ban

session[:user_id] = 2
post(:filter_users, params: { type: 'banned' })
@users = assigns(:users)

assert_equal 4, User.count
assert_equal 1, @users.length
assert @users.all? { |user| user.status == User::Status::BANNED && user.login == 'quentin'}
end

test 'should filter users and show only moderators' do
session[:user_id] = 2
post(:filter_users, params: { type: 'moderator', limit: 5 })
@users = assigns(:users)

assert_equal 4, User.count
assert_equal 0, @users.length
end

test 'should filter users and show only admins' do
session[:user_id] = 2
post(:filter_users, params: { type: 'admin', limit: 5 })
@users = assigns(:users)

assert_equal 4, User.count
assert_equal 1, @users.length
end
end
6 changes: 5 additions & 1 deletion test/integration/routes_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ class RoutesTest < ActionDispatch::IntegrationTest
end

test "test filter-maps route" do
assert_routing({ path: '/moderate/filter_maps/created', method: :get }, { controller: 'spam', action: 'filter_maps', type: 'created' })
assert_routing({ path: '/moderate/filter_maps/updated', method: :get }, { controller: 'spam', action: 'filter_maps', type: 'updated' })
end

test "test filter-users route" do
assert_routing({ path: '/moderate/filter_users/active', method: :get }, { controller: 'spam', action: 'filter_users', type: 'active' })
end
end

0 comments on commit cc2c14a

Please sign in to comment.