Deleted by <%= user_link post.deleted_by %> on <%= post.deleted_at.strftime('%b %e, %Y at %H:%M') %>
- The author of this post decided to delete it. It can only be seen by users with the Curate privilege. + The author of this post decided to delete it. It can only be seen by users with the Curate ability.
<% else %>- This post was deleted and can only be seen by users with the Curate privilege. + This post was deleted and can only be seen by users with the Curate ability.
<% end %> - -Users with the Curate privilege may vote to restore this post if it has been deleted incorrectly.
+Users with the Curate ability may vote to restore this post if it has been deleted incorrectly.
This post MUST be positively scored (> 0.5) to count towards the score
+ tags_cache: + - post + tags: + - post + score: 0.7 + user: post_scorer + community: sample + category: main + license: cc_by_sa diff --git a/test/fixtures/suggested_edits.yml b/test/fixtures/suggested_edits.yml index 5f79e9b6d..e020f860a 100644 --- a/test/fixtures/suggested_edits.yml +++ b/test/fixtures/suggested_edits.yml @@ -72,3 +72,16 @@ pending_high_trust: comment: High trust only active: true accepted: false + +approved_edit_scorer: + post: question_one + user: edit_scorer + community: sample + body: this is used to get consistent edit score for tests + body_markdown:this is used to get consistent edit score for tests
+ comment: working towards the Edit Posts ability + active: false + accepted: true + decided_at: 2000-01-01T00:00:00.000000Z + decided_by: editor + title: approved suggested edit by the user used for edit score tests diff --git a/test/fixtures/user_abilities.yml b/test/fixtures/user_abilities.yml index 0b6c586d4..094a95ec5 100644 --- a/test/fixtures/user_abilities.yml +++ b/test/fixtures/user_abilities.yml @@ -14,6 +14,18 @@ d_eo: community_user: sample_deleter ability: everyone +pe_eo: + community_user: sample_edit_scorer + ability: everyone + +pf_eo: + community_user: sample_flag_scorer + ability: everyone + +pp_eo: + community_user: sample_post_scorer + ability: everyone + stu_ur: community_user: sample_standard_user ability: unrestricted @@ -30,6 +42,18 @@ d_ur: community_user: sample_deleter ability: unrestricted +pe_ur: + community_user: sample_edit_scorer + ability: unrestricted + +pf_ur: + community_user: sample_flag_scorer + ability: unrestricted + +pp_ur: + community_user: sample_post_scorer + ability: unrestricted + c_fc: community_user: sample_closer ability: flag_close diff --git a/test/fixtures/users.yml b/test/fixtures/users.yml index 4f20ce3dc..140caa683 100644 --- a/test/fixtures/users.yml +++ b/test/fixtures/users.yml @@ -163,3 +163,24 @@ spammer: is_global_admin: false is_global_moderator: false confirmed_at: 2020-01-01T00:00:00.000000Z + +edit_scorer: + email: edit-scorer@example.com + encrypted_password: '$2a$11$roUHXKxecjyQ72Qn7DWs3.9eRCCoRn176kX/UNb/xiue3aGqf7xEW' + sign_in_count: 1337 + username: edit_scorer + confirmed_at: 2020-01-01T00:00:00.000000Z + +flag_scorer: + email: flag-scorer@example.com + encrypted_password: '$2a$11$roUHXKxecjyQ72Qn7DWs3.9eRCCoRn176kX/UNb/xiue3aGqf7xEW' + sign_in_count: 1337 + username: flag_scorer + confirmed_at: 2020-01-01T00:00:00.000000Z + +post_scorer: + email: post-scorer@example.com + encrypted_password: '$2a$11$roUHXKxecjyQ72Qn7DWs3.9eRCCoRn176kX/UNb/xiue3aGqf7xEW' + sign_in_count: 1337 + username: post_scorer + confirmed_at: 2020-01-01T00:00:00.000000Z diff --git a/test/models/ability_test.rb b/test/models/ability_test.rb index 610503f05..2a4fd3eed 100644 --- a/test/models/ability_test.rb +++ b/test/models/ability_test.rb @@ -1,7 +1,56 @@ require 'test_helper' class AbilityTest < ActiveSupport::TestCase - # test "the truth" do - # assert true - # end + test 'score_percent_for methods should return 0 for missing users' do + [:edit, :flag, :post].each do |type| + abilities.each do |ability| + assert_equal 0, ability.send("#{type}_score_percent_for", nil) + end + end + end + + test 'score_percent_for methods should return 0 for unrelated abilities' do + std = users(:standard_user) + + [:edit, :flag, :post].each do |type| + abilities.each do |ability| + next unless ability.send("#{type}_score_threshold").nil? + + assert_equal 0, ability.send("#{type}_score_percent_for", std) + end + end + end + + test 'score_percent_for methods should return 100 for abilities 0 thresholds' do + std = users(:standard_user) + + [:edit, :flag, :post].each do |type| + abilities.each do |ability| + next unless ability.send("#{type}_score_threshold")&.zero? + + assert_equal 100, ability.send("#{type}_score_percent_for", std) + end + end + end + + test 'edit_score_percent_for should correctly calculate percent for a given user' do + user = users(:edit_scorer) + ability = abilities(:edit_posts) + + assert_equal 2, ability.edit_score_percent_for(user) + end + + test 'flag_score_percent_for should correctly calculate percent for a given user' do + user = users(:flag_scorer) + ability = abilities(:flag_curate) + + assert_equal 6, ability.flag_score_percent_for(user) + end + + test 'post_score_percent_for should correctly calculate percent for a given user' do + user = users(:post_scorer) + ability = abilities(:flag_close) + + assert_equal 6, ability.post_score_percent_for(user) + end end diff --git a/test/models/post_test.rb b/test/models/post_test.rb index 92633c61f..7b2d9342f 100644 --- a/test/models/post_test.rb +++ b/test/models/post_test.rb @@ -130,4 +130,10 @@ class PostTest < ActiveSupport::TestCase end end end + + test 'deleted_by_owner? should correctly determine if the post is deleted by its owner' do + posts.reject(&:deleted).each do |post| + assert_not post.deleted_by_owner? + end + end end diff --git a/test/models/user_test.rb b/test/models/user_test.rb index 6e6536269..db21566f6 100644 --- a/test/models/user_test.rb +++ b/test/models/user_test.rb @@ -217,7 +217,7 @@ class UserTest < ActiveSupport::TestCase end end - test 'ability_on? should return true for every undeleted user with profile on a community' do + test "ability_on? should correctly check the 'everyone' ability" do everyone = abilities(:everyone) communities.each do |community| @@ -230,19 +230,26 @@ class UserTest < ActiveSupport::TestCase end end - test 'ability_on? should correctly check for unrestricted ability' do + test "ability_on? should correctly check the 'unrestricted' ability" do + ability = abilities(:unrestricted) community = communities(:sample) basic = users(:basic_user) system = users(:system) - unrestricted = abilities(:unrestricted) + restricted_users = [basic, system] - [basic, system].each do |user| - assert_equal user.ability_on?(community.id, unrestricted.internal_id), false + restricted_users.each do |user| + assert_not user.ability_on?(community.id, ability.internal_id), + "Expected user '#{user.name}' not to have the ability" end - CommunityUser.unscoped.undeleted.where(community_id: community.id).where.not(user_id: [basic.id, system.id]).each do |cu| - assert_equal cu.user.ability_on?(community.id, unrestricted.internal_id), !cu.user.deleted + users.each do |user| + next unless user.profile_on?(community.id) && !user.community_user.deleted? + next if restricted_users.any? { |u| u.same_as?(user) } + + assert_equal user.ability_on?(community.id, ability.internal_id), + !user.deleted?, + "Expected user '#{user.name}' #{'not ' if user.deleted?}to have the ability" end end