A platform for community discussion. Free, open, simple.
DEV: Add delegated Group#human_users scope (#25398)
Ted Johansson32e2a1fd4a92
diff --git a/app/models/group.rb b/app/models/group.rbindex e1d47537fc7..0357e98695c 100644--- a/app/models/group.rb+++ b/app/models/group.rb@@ -24,6 +24,7 @@ class Group < ActiveRecord::Basehas_many :categories, through: :category_groupshas_many :users, through: :group_users+ has_many :human_users, -> { human_users }, through: :group_users, source: :userhas_many :requesters, through: :group_requests, source: :userhas_many :group_histories, dependent: :destroyhas_many :category_reviews,diff --git a/spec/models/group_spec.rb b/spec/models/group_spec.rbindex 83611eb8ee7..13cebcdb879 100644--- a/spec/models/group_spec.rb+++ b/spec/models/group_spec.rb@@ -57,6 +57,14 @@ RSpec.describe Group doendend+ describe ".human_users" do+ before { group.users << user << Discourse.system_user }++ it "returns only human users" do+ expect(group.human_users).to contain_exactly(user)+ end+ end+describe "#posts_for" doit "returns the post in the group" dop = Fabricate(:post)@@ -197,18 +205,6 @@ RSpec.describe Group doendend- def real_admins- Group[:admins].user_ids.reject { |id| id < 0 }- end-- def real_moderators- Group[:moderators].user_ids.reject { |id| id < 0 }- end-- def real_staff- Group[:staff].user_ids.reject { |id| id < 0 }- end-describe "#primary_group=" dobefore { group.add(user) }@@ -424,33 +420,33 @@ RSpec.describe Group doGroup.refresh_automatic_groups!(:admins, :staff, :moderators)- expect(real_admins).to eq [admin.id]- expect(real_moderators).to eq [moderator.id]- expect(real_staff.sort).to eq [moderator.id, admin.id].sort+ expect(Group[:admins].human_users).to contain_exactly(admin)+ expect(Group[:moderators].human_users).to contain_exactly(moderator)+ expect(Group[:staff].human_users).to contain_exactly(moderator, admin)admin.admin = falseadmin.saveGroup.refresh_automatic_group!(:admins)- expect(real_admins).to be_empty+ expect(Group[:admins].human_users).to be_emptymoderator.revoke_moderation!admin.grant_admin!- expect(real_admins).to eq [admin.id]- expect(real_staff).to eq [admin.id]+ expect(Group[:admins].human_users).to contain_exactly(admin)+ expect(Group[:staff].human_users).to contain_exactly(admin)admin.revoke_admin!- expect(real_admins).to be_empty- expect(real_staff).to be_empty+ expect(Group[:admins].human_users).to be_empty+ expect(Group[:staff].human_users).to be_emptyadmin.grant_moderation!- expect(real_moderators).to eq [admin.id]- expect(real_staff).to eq [admin.id]+ expect(Group[:moderators].human_users).to contain_exactly(admin)+ expect(Group[:staff].human_users).to contain_exactly(admin)admin.revoke_moderation!- expect(real_admins).to be_empty- expect(real_staff).to eq []+ expect(Group[:admins].human_users).to be_empty+ expect(Group[:staff].human_users).to be_empty# we need some work to set min username to 6