Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvements for search test coverage #1513

Draft
wants to merge 14 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions app/helpers/search_helper.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
module SearchHelper
def check_posts_permissions
(current_user&.is_moderator || current_user&.is_admin ? Post : Post.undeleted)
# @param user [User] user to check
def get_accessible_posts(user)
Oaphi marked this conversation as resolved.
Show resolved Hide resolved
(user&.is_moderator || user&.is_admin ? Post : Post.undeleted)
.qa_only.list_includes
end

def search_posts
posts = check_posts_permissions

posts = get_accessible_posts(current_user)
qualifiers = params_to_qualifiers
search_string = params[:search]

Expand Down
18 changes: 18 additions & 0 deletions test/helpers/search_helper_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,22 @@ class SearchHelperTest < ActionView::TestCase
assert_equal expect, date_value_sql(input)
end
end

test 'get_accessible_posts should correctly check access' do
admin_user = users(:admin)
mod_user = users(:moderator)
standard_user = users(:standard_user)

admin_posts = get_accessible_posts(admin_user)
mod_posts = get_accessible_posts(mod_user)
user_posts = get_accessible_posts(standard_user)

can_admin_get_deleted_posts = admin_posts.any?(&:deleted)
can_mod_get_deleted_posts = mod_posts.any?(&:deleted)
can_user_get_deleted_posts = user_posts.any?(&:deleted)

assert_equal can_admin_get_deleted_posts, true
assert_equal can_mod_get_deleted_posts, true
assert_equal can_user_get_deleted_posts, false
end
end
Loading