mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
DEV: Apply syntax_tree formatting to spec/*
This commit is contained in:
@@ -5,10 +5,10 @@ RSpec.describe AdminPluginSerializer do
|
||||
|
||||
subject { described_class.new(instance) }
|
||||
|
||||
describe 'enabled_setting' do
|
||||
it 'should return the right value' do
|
||||
instance.enabled_site_setting('test')
|
||||
expect(subject.enabled_setting).to eq('test')
|
||||
describe "enabled_setting" do
|
||||
it "should return the right value" do
|
||||
instance.enabled_site_setting("test")
|
||||
expect(subject.enabled_setting).to eq("test")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -5,14 +5,10 @@ RSpec.describe AdminUserListSerializer do
|
||||
fab!(:admin) { Fabricate(:admin) }
|
||||
let(:guardian) { Guardian.new(admin) }
|
||||
|
||||
let(:serializer) do
|
||||
AdminUserListSerializer.new(user, scope: guardian, root: false)
|
||||
end
|
||||
let(:serializer) { AdminUserListSerializer.new(user, scope: guardian, root: false) }
|
||||
|
||||
context "when totp enabled" do
|
||||
before do
|
||||
Fabricate(:user_second_factor_totp, user: user)
|
||||
end
|
||||
before { Fabricate(:user_second_factor_totp, user: user) }
|
||||
it "returns the right values" do
|
||||
json = serializer.as_json
|
||||
|
||||
@@ -21,9 +17,7 @@ RSpec.describe AdminUserListSerializer do
|
||||
end
|
||||
|
||||
context "when security keys enabled" do
|
||||
before do
|
||||
Fabricate(:user_security_key, user: user)
|
||||
end
|
||||
before { Fabricate(:user_security_key, user: user) }
|
||||
it "returns the right values" do
|
||||
json = serializer.as_json
|
||||
|
||||
@@ -41,7 +35,7 @@ RSpec.describe AdminUserListSerializer do
|
||||
user,
|
||||
scope: Guardian.new(viewed_by),
|
||||
root: false,
|
||||
emails_desired: opts && opts[:emails_desired]
|
||||
emails_desired: opts && opts[:emails_desired],
|
||||
).as_json
|
||||
end
|
||||
|
||||
|
||||
@@ -5,97 +5,91 @@ RSpec.describe BasicGroupSerializer do
|
||||
fab!(:group) { Fabricate(:group) }
|
||||
subject { described_class.new(group, scope: guardian, root: false) }
|
||||
|
||||
describe '#display_name' do
|
||||
describe 'automatic group' do
|
||||
describe "#display_name" do
|
||||
describe "automatic group" do
|
||||
let(:group) { Group.find(1) }
|
||||
|
||||
it 'should include the display name' do
|
||||
expect(subject.display_name).to eq(I18n.t('groups.default_names.admins'))
|
||||
it "should include the display name" do
|
||||
expect(subject.display_name).to eq(I18n.t("groups.default_names.admins"))
|
||||
end
|
||||
end
|
||||
|
||||
describe 'normal group' do
|
||||
describe "normal group" do
|
||||
fab!(:group) { Fabricate(:group) }
|
||||
|
||||
it 'should not include the display name' do
|
||||
it "should not include the display name" do
|
||||
expect(subject.display_name).to eq(nil)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#bio_raw' do
|
||||
fab!(:group) { Fabricate(:group, bio_raw: 'testing :slightly_smiling_face:') }
|
||||
describe "#bio_raw" do
|
||||
fab!(:group) { Fabricate(:group, bio_raw: "testing :slightly_smiling_face:") }
|
||||
|
||||
subject do
|
||||
described_class.new(group, scope: guardian, root: false, owner_group_ids: [group.id])
|
||||
end
|
||||
|
||||
describe 'group owner' do
|
||||
it 'should include bio_raw' do
|
||||
expect(subject.as_json[:bio_raw]).to eq('testing :slightly_smiling_face:')
|
||||
expect(subject.as_json[:bio_excerpt]).to start_with('testing <img')
|
||||
describe "group owner" do
|
||||
it "should include bio_raw" do
|
||||
expect(subject.as_json[:bio_raw]).to eq("testing :slightly_smiling_face:")
|
||||
expect(subject.as_json[:bio_excerpt]).to start_with("testing <img")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#has_messages' do
|
||||
describe "#has_messages" do
|
||||
fab!(:group) { Fabricate(:group, has_messages: true) }
|
||||
|
||||
before do
|
||||
Group.refresh_automatic_groups!
|
||||
end
|
||||
before { Group.refresh_automatic_groups! }
|
||||
|
||||
describe 'for a staff user' do
|
||||
describe "for a staff user" do
|
||||
let(:guardian) { Guardian.new(Fabricate(:moderator)) }
|
||||
|
||||
it 'should be present' do
|
||||
it "should be present" do
|
||||
Group.refresh_automatic_groups!
|
||||
expect(subject.as_json[:has_messages]).to eq(true)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'for a group user' do
|
||||
describe "for a group user" do
|
||||
fab!(:user) { Fabricate(:user) }
|
||||
let(:guardian) { Guardian.new(user) }
|
||||
|
||||
before do
|
||||
group.add(user)
|
||||
end
|
||||
before { group.add(user) }
|
||||
|
||||
it 'should be present' do
|
||||
it "should be present" do
|
||||
expect(subject.as_json[:has_messages]).to eq(true)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'for a normal user' do
|
||||
describe "for a normal user" do
|
||||
let(:guardian) { Guardian.new(Fabricate(:user)) }
|
||||
|
||||
it 'should not be present' do
|
||||
it "should not be present" do
|
||||
expect(subject.as_json[:has_messages]).to eq(nil)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#can_see_members' do
|
||||
describe "#can_see_members" do
|
||||
fab!(:group) { Fabricate(:group, members_visibility_level: Group.visibility_levels[:members]) }
|
||||
|
||||
describe 'for a group user' do
|
||||
describe "for a group user" do
|
||||
fab!(:user) { Fabricate(:user) }
|
||||
let(:guardian) { Guardian.new(user) }
|
||||
|
||||
before do
|
||||
group.add(user)
|
||||
end
|
||||
before { group.add(user) }
|
||||
|
||||
it 'should be true' do
|
||||
it "should be true" do
|
||||
expect(subject.as_json[:can_see_members]).to eq(true)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'for a normal user' do
|
||||
describe "for a normal user" do
|
||||
let(:guardian) { Guardian.new(Fabricate(:user)) }
|
||||
|
||||
it 'should be false' do
|
||||
it "should be false" do
|
||||
expect(subject.as_json[:can_see_members]).to eq(false)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -4,30 +4,20 @@ RSpec.describe BasicGroupUserSerializer do
|
||||
fab!(:group) { Fabricate(:group) }
|
||||
fab!(:user) { Fabricate(:user) }
|
||||
|
||||
before do
|
||||
group.add(user)
|
||||
end
|
||||
before { group.add(user) }
|
||||
|
||||
describe '#owner' do
|
||||
describe 'when scoped to the user' do
|
||||
it 'should be false' do
|
||||
json = described_class.new(
|
||||
GroupUser.last,
|
||||
scope: Guardian.new(user),
|
||||
root: false
|
||||
).as_json
|
||||
describe "#owner" do
|
||||
describe "when scoped to the user" do
|
||||
it "should be false" do
|
||||
json = described_class.new(GroupUser.last, scope: Guardian.new(user), root: false).as_json
|
||||
|
||||
expect(json[:owner]).to eq(false)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'when not scoped to the user' do
|
||||
it 'should be nil' do
|
||||
json = described_class.new(
|
||||
GroupUser.last,
|
||||
scope: Guardian.new,
|
||||
root: false
|
||||
).as_json
|
||||
describe "when not scoped to the user" do
|
||||
it "should be nil" do
|
||||
json = described_class.new(GroupUser.last, scope: Guardian.new, root: false).as_json
|
||||
|
||||
expect(json[:owner]).to eq(nil)
|
||||
end
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
RSpec.describe BasicPostSerializer do
|
||||
|
||||
describe "#name" do
|
||||
let(:user) { Fabricate.build(:user) }
|
||||
let(:post) { Fabricate.build(:post, user: user) }
|
||||
|
||||
@@ -5,7 +5,11 @@ describe BasicReviewableFlaggedPostSerializer do
|
||||
fab!(:post) { Fabricate(:post, topic: topic) }
|
||||
|
||||
fab!(:reviewable) do
|
||||
ReviewableFlaggedPost.needs_review!(target: post, topic: topic, created_by: Discourse.system_user)
|
||||
ReviewableFlaggedPost.needs_review!(
|
||||
target: post,
|
||||
topic: topic,
|
||||
created_by: Discourse.system_user,
|
||||
)
|
||||
end
|
||||
|
||||
subject { described_class.new(reviewable, root: false).as_json }
|
||||
|
||||
@@ -6,7 +6,10 @@ describe BasicReviewableQueuedPostSerializer do
|
||||
ReviewableQueuedPost.create!(
|
||||
created_by: Discourse.system_user,
|
||||
topic_id: topic.id,
|
||||
payload: { raw: "new post 123", title: "unsafe title <a>" }
|
||||
payload: {
|
||||
raw: "new post 123",
|
||||
title: "unsafe title <a>",
|
||||
},
|
||||
)
|
||||
end
|
||||
|
||||
|
||||
@@ -12,8 +12,8 @@ describe BasicReviewableUserSerializer do
|
||||
name: user.name,
|
||||
email: user.email,
|
||||
bio: "blah whatever",
|
||||
website: "ff.website.com"
|
||||
}
|
||||
website: "ff.website.com",
|
||||
},
|
||||
)
|
||||
end
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
RSpec.describe BasicUserSerializer do
|
||||
describe '#as_json' do
|
||||
describe "#as_json" do
|
||||
let(:user) { Fabricate.build(:user) }
|
||||
let(:serializer) { BasicUserSerializer.new(user, scope: Guardian.new(user), root: false) }
|
||||
let(:json) { serializer.as_json }
|
||||
@@ -12,9 +12,11 @@ RSpec.describe BasicUserSerializer do
|
||||
expect(json[:avatar_template]).to eq(user.avatar_template)
|
||||
end
|
||||
|
||||
describe 'extended serializers' do
|
||||
describe "extended serializers" do
|
||||
let(:post_action) { Fabricate(:post_action, user: user) }
|
||||
let(:serializer) { PostActionUserSerializer.new(post_action, scope: Guardian.new(user), root: false) }
|
||||
let(:serializer) do
|
||||
PostActionUserSerializer.new(post_action, scope: Guardian.new(user), root: false)
|
||||
end
|
||||
it "returns the user correctly" do
|
||||
expect(serializer.user.username).to eq(user.username)
|
||||
end
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
RSpec.describe CategoryDetailedSerializer do
|
||||
|
||||
describe "counts" do
|
||||
it "works for categories with no subcategories" do
|
||||
no_subcats = Fabricate(:category, topics_year: 10, topics_month: 5, topics_day: 2)
|
||||
@@ -13,12 +12,18 @@ RSpec.describe CategoryDetailedSerializer do
|
||||
|
||||
it "includes counts from subcategories" do
|
||||
parent = Fabricate(:category, topics_year: 10, topics_month: 5, topics_day: 2)
|
||||
subcategory = Fabricate(:category, parent_category_id: parent.id, topics_year: 1, topics_month: 1, topics_day: 1)
|
||||
subcategory =
|
||||
Fabricate(
|
||||
:category,
|
||||
parent_category_id: parent.id,
|
||||
topics_year: 1,
|
||||
topics_month: 1,
|
||||
topics_day: 1,
|
||||
)
|
||||
json = CategoryDetailedSerializer.new(parent, scope: Guardian.new, root: false).as_json
|
||||
expect(json[:topics_year]).to eq(11)
|
||||
expect(json[:topics_month]).to eq(6)
|
||||
expect(json[:topics_day]).to eq(3)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -36,23 +36,29 @@ RSpec.describe CategorySerializer do
|
||||
|
||||
describe "user notification level" do
|
||||
it "includes the user's notification level" do
|
||||
CategoryUser.set_notification_level_for_category(user, NotificationLevels.all[:watching], category.id)
|
||||
CategoryUser.set_notification_level_for_category(
|
||||
user,
|
||||
NotificationLevels.all[:watching],
|
||||
category.id,
|
||||
)
|
||||
json = described_class.new(category, scope: Guardian.new(user), root: false).as_json
|
||||
expect(json[:notification_level]).to eq(NotificationLevels.all[:watching])
|
||||
end
|
||||
end
|
||||
|
||||
describe '#group_permissions' do
|
||||
fab!(:private_group) { Fabricate(:group, visibility_level: Group.visibility_levels[:staff], name: 'bbb') }
|
||||
describe "#group_permissions" do
|
||||
fab!(:private_group) do
|
||||
Fabricate(:group, visibility_level: Group.visibility_levels[:staff], name: "bbb")
|
||||
end
|
||||
|
||||
fab!(:user_group) do
|
||||
Fabricate(:group, visibility_level: Group.visibility_levels[:members], name: 'ccc').tap do |g|
|
||||
Fabricate(:group, visibility_level: Group.visibility_levels[:members], name: "ccc").tap do |g|
|
||||
g.add(user)
|
||||
end
|
||||
end
|
||||
|
||||
before do
|
||||
group.update!(name: 'aaa')
|
||||
group.update!(name: "aaa")
|
||||
|
||||
category.set_permissions(
|
||||
:everyone => :readonly,
|
||||
@@ -82,12 +88,17 @@ RSpec.describe CategorySerializer do
|
||||
|
||||
json = described_class.new(category, scope: Guardian.new(user), root: false).as_json
|
||||
|
||||
expect(json[:group_permissions]).to eq([
|
||||
{ permission_type: CategoryGroup.permission_types[:readonly], group_name: group.name },
|
||||
{ permission_type: CategoryGroup.permission_types[:full], group_name: private_group.name },
|
||||
{ permission_type: CategoryGroup.permission_types[:full], group_name: user_group.name },
|
||||
{ permission_type: CategoryGroup.permission_types[:readonly], group_name: 'everyone' },
|
||||
])
|
||||
expect(json[:group_permissions]).to eq(
|
||||
[
|
||||
{ permission_type: CategoryGroup.permission_types[:readonly], group_name: group.name },
|
||||
{
|
||||
permission_type: CategoryGroup.permission_types[:full],
|
||||
group_name: private_group.name,
|
||||
},
|
||||
{ permission_type: CategoryGroup.permission_types[:full], group_name: user_group.name },
|
||||
{ permission_type: CategoryGroup.permission_types[:readonly], group_name: "everyone" },
|
||||
],
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -99,7 +110,7 @@ RSpec.describe CategorySerializer do
|
||||
|
||||
it "included for an admin" do
|
||||
json = described_class.new(category, scope: Guardian.new(admin), root: false).as_json
|
||||
expect(json[:available_groups]).to eq(Group.order(:name).pluck(:name) - ['everyone'])
|
||||
expect(json[:available_groups]).to eq(Group.order(:name).pluck(:name) - ["everyone"])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,13 +1,11 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
RSpec.describe CategoryUploadSerializer do
|
||||
|
||||
fab!(:upload) { Fabricate(:upload) }
|
||||
let(:subject) { described_class.new(upload, root: false) }
|
||||
|
||||
it 'should include width and height' do
|
||||
it "should include width and height" do
|
||||
expect(subject.width).to eq(upload.width)
|
||||
expect(subject.height).to eq(upload.height)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -16,7 +16,7 @@ RSpec.describe CurrentUserSerializer do
|
||||
context "when SSO is enabled" do
|
||||
let :user do
|
||||
user = Fabricate(:user)
|
||||
SingleSignOnRecord.create!(user_id: user.id, external_id: '12345', last_payload: '')
|
||||
SingleSignOnRecord.create!(user_id: user.id, external_id: "12345", last_payload: "")
|
||||
user
|
||||
end
|
||||
|
||||
@@ -41,17 +41,23 @@ RSpec.describe CurrentUserSerializer do
|
||||
|
||||
it "should include correct id in top_category_ids array" do
|
||||
_category = Category.first
|
||||
CategoryUser.create!(user_id: user.id,
|
||||
category_id: category1.id,
|
||||
notification_level: CategoryUser.notification_levels[:tracking])
|
||||
CategoryUser.create!(
|
||||
user_id: user.id,
|
||||
category_id: category1.id,
|
||||
notification_level: CategoryUser.notification_levels[:tracking],
|
||||
)
|
||||
|
||||
CategoryUser.create!(user_id: user.id,
|
||||
category_id: category2.id,
|
||||
notification_level: CategoryUser.notification_levels[:watching])
|
||||
CategoryUser.create!(
|
||||
user_id: user.id,
|
||||
category_id: category2.id,
|
||||
notification_level: CategoryUser.notification_levels[:watching],
|
||||
)
|
||||
|
||||
CategoryUser.create!(user_id: user.id,
|
||||
category_id: category3.id,
|
||||
notification_level: CategoryUser.notification_levels[:regular])
|
||||
CategoryUser.create!(
|
||||
user_id: user.id,
|
||||
category_id: category3.id,
|
||||
notification_level: CategoryUser.notification_levels[:regular],
|
||||
)
|
||||
|
||||
payload = serializer.as_json
|
||||
expect(payload[:top_category_ids]).to eq([category2.id, category1.id])
|
||||
@@ -65,11 +71,11 @@ RSpec.describe CurrentUserSerializer do
|
||||
TagUser.create!(
|
||||
user_id: user.id,
|
||||
notification_level: TagUser.notification_levels[:muted],
|
||||
tag_id: tag.id
|
||||
tag_id: tag.id,
|
||||
)
|
||||
end
|
||||
|
||||
it 'includes muted tag names' do
|
||||
it "includes muted tag names" do
|
||||
payload = serializer.as_json
|
||||
expect(payload[:muted_tags]).to eq([tag.name])
|
||||
end
|
||||
@@ -84,9 +90,7 @@ RSpec.describe CurrentUserSerializer do
|
||||
end
|
||||
|
||||
context "when totp enabled" do
|
||||
before do
|
||||
User.any_instance.stubs(:totp_enabled?).returns(true)
|
||||
end
|
||||
before { User.any_instance.stubs(:totp_enabled?).returns(true) }
|
||||
|
||||
it "is true" do
|
||||
expect(json[:second_factor_enabled]).to eq(true)
|
||||
@@ -94,9 +98,7 @@ RSpec.describe CurrentUserSerializer do
|
||||
end
|
||||
|
||||
context "when security_keys enabled" do
|
||||
before do
|
||||
User.any_instance.stubs(:security_keys_enabled?).returns(true)
|
||||
end
|
||||
before { User.any_instance.stubs(:security_keys_enabled?).returns(true) }
|
||||
|
||||
it "is true" do
|
||||
expect(json[:second_factor_enabled]).to eq(true)
|
||||
@@ -108,7 +110,12 @@ RSpec.describe CurrentUserSerializer do
|
||||
it "should only show visible groups" do
|
||||
Fabricate.build(:group, visibility_level: Group.visibility_levels[:public])
|
||||
hidden_group = Fabricate.build(:group, visibility_level: Group.visibility_levels[:owners])
|
||||
public_group = Fabricate.build(:group, visibility_level: Group.visibility_levels[:public], name: "UppercaseGroupName")
|
||||
public_group =
|
||||
Fabricate.build(
|
||||
:group,
|
||||
visibility_level: Group.visibility_levels[:public],
|
||||
name: "UppercaseGroupName",
|
||||
)
|
||||
hidden_group.add(user)
|
||||
hidden_group.save!
|
||||
public_group.add(user)
|
||||
@@ -116,7 +123,7 @@ RSpec.describe CurrentUserSerializer do
|
||||
payload = serializer.as_json
|
||||
|
||||
expect(payload[:groups]).to contain_exactly(
|
||||
{ id: public_group.id, name: public_group.name, has_messages: false }
|
||||
{ id: public_group.id, name: public_group.name, has_messages: false },
|
||||
)
|
||||
end
|
||||
end
|
||||
@@ -141,7 +148,6 @@ RSpec.describe CurrentUserSerializer do
|
||||
payload = serializer.as_json
|
||||
expect(payload).not_to have_key(:has_topic_draft)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe "#can_review" do
|
||||
@@ -222,21 +228,30 @@ RSpec.describe CurrentUserSerializer do
|
||||
|
||||
describe "#likes_notifications_disabled" do
|
||||
it "is true if the user disables likes notifications" do
|
||||
user.user_option.update!(like_notification_frequency: UserOption.like_notification_frequency_type[:never])
|
||||
user.user_option.update!(
|
||||
like_notification_frequency: UserOption.like_notification_frequency_type[:never],
|
||||
)
|
||||
expect(serializer.as_json[:user_option][:likes_notifications_disabled]).to eq(true)
|
||||
end
|
||||
|
||||
it "is false if the user doesn't disable likes notifications" do
|
||||
user.user_option.update!(like_notification_frequency: UserOption.like_notification_frequency_type[:always])
|
||||
user.user_option.update!(
|
||||
like_notification_frequency: UserOption.like_notification_frequency_type[:always],
|
||||
)
|
||||
expect(serializer.as_json[:user_option][:likes_notifications_disabled]).to eq(false)
|
||||
user.user_option.update!(like_notification_frequency: UserOption.like_notification_frequency_type[:first_time_and_daily])
|
||||
user.user_option.update!(
|
||||
like_notification_frequency:
|
||||
UserOption.like_notification_frequency_type[:first_time_and_daily],
|
||||
)
|
||||
expect(serializer.as_json[:user_option][:likes_notifications_disabled]).to eq(false)
|
||||
user.user_option.update!(like_notification_frequency: UserOption.like_notification_frequency_type[:first_time])
|
||||
user.user_option.update!(
|
||||
like_notification_frequency: UserOption.like_notification_frequency_type[:first_time],
|
||||
)
|
||||
expect(serializer.as_json[:user_option][:likes_notifications_disabled]).to eq(false)
|
||||
end
|
||||
end
|
||||
|
||||
describe '#redesigned_user_page_nav_enabled' do
|
||||
describe "#redesigned_user_page_nav_enabled" do
|
||||
fab!(:group) { Fabricate(:group) }
|
||||
fab!(:group2) { Fabricate(:group) }
|
||||
|
||||
@@ -244,13 +259,13 @@ RSpec.describe CurrentUserSerializer do
|
||||
expect(serializer.as_json[:redesigned_user_page_nav_enabled]).to eq(false)
|
||||
end
|
||||
|
||||
it 'is false if user does not belong to any of the configured groups in the enable_new_user_profile_nav_groups site setting' do
|
||||
it "is false if user does not belong to any of the configured groups in the enable_new_user_profile_nav_groups site setting" do
|
||||
SiteSetting.enable_new_user_profile_nav_groups = "#{group.id}|#{group2.id}"
|
||||
|
||||
expect(serializer.as_json[:redesigned_user_page_nav_enabled]).to eq(false)
|
||||
end
|
||||
|
||||
it 'is true if user belongs one of the configured groups in the enable_new_user_profile_nav_groups site setting' do
|
||||
it "is true if user belongs one of the configured groups in the enable_new_user_profile_nav_groups site setting" do
|
||||
SiteSetting.enable_new_user_profile_nav_groups = "#{group.id}|#{group2.id}"
|
||||
group.add(user)
|
||||
|
||||
@@ -258,23 +273,37 @@ RSpec.describe CurrentUserSerializer do
|
||||
end
|
||||
end
|
||||
|
||||
describe '#associated_account_ids' do
|
||||
describe "#associated_account_ids" do
|
||||
before do
|
||||
UserAssociatedAccount.create(user_id: user.id, provider_name: "twitter", provider_uid: "1", info: { nickname: "sam" })
|
||||
UserAssociatedAccount.create(
|
||||
user_id: user.id,
|
||||
provider_name: "twitter",
|
||||
provider_uid: "1",
|
||||
info: {
|
||||
nickname: "sam",
|
||||
},
|
||||
)
|
||||
end
|
||||
|
||||
it 'should not include associated account ids by default' do
|
||||
it "should not include associated account ids by default" do
|
||||
expect(serializer.as_json[:associated_account_ids]).to be_nil
|
||||
end
|
||||
|
||||
it 'should include associated account ids when site setting enabled' do
|
||||
it "should include associated account ids when site setting enabled" do
|
||||
SiteSetting.include_associated_account_ids = true
|
||||
expect(serializer.as_json[:associated_account_ids]).to eq({ "twitter" => "1" })
|
||||
end
|
||||
end
|
||||
|
||||
describe "#new_personal_messages_notifications_count" do
|
||||
fab!(:notification) { Fabricate(:notification, user: user, read: false, notification_type: Notification.types[:private_message]) }
|
||||
fab!(:notification) do
|
||||
Fabricate(
|
||||
:notification,
|
||||
user: user,
|
||||
read: false,
|
||||
notification_type: Notification.types[:private_message],
|
||||
)
|
||||
end
|
||||
|
||||
it "isn't included when navigation menu is legacy" do
|
||||
SiteSetting.navigation_menu = "legacy"
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
RSpec.describe DetailedUserBadgeSerializer do
|
||||
describe '#topic_id and #topic_title attributes' do
|
||||
describe "#topic_id and #topic_title attributes" do
|
||||
fab!(:user) { Fabricate(:user) }
|
||||
fab!(:admin) { Fabricate(:admin) }
|
||||
fab!(:post) { Fabricate(:post) }
|
||||
@@ -9,78 +9,88 @@ RSpec.describe DetailedUserBadgeSerializer do
|
||||
fab!(:user_badge) { Fabricate(:user_badge, badge: badge, post_id: post.id) }
|
||||
let(:guardian) { Guardian.new(user_badge.user) }
|
||||
|
||||
it 'does not include attributes in serialized object when badge has not been configured to show posts' do
|
||||
it "does not include attributes in serialized object when badge has not been configured to show posts" do
|
||||
badge.update!(show_posts: false)
|
||||
|
||||
guardian = Guardian.new
|
||||
|
||||
serialized = described_class.new(user_badge,
|
||||
scope: guardian,
|
||||
allowed_user_badge_topic_ids: guardian.can_see_topic_ids(topic_ids: [post.topic_id]),
|
||||
root: false,
|
||||
).as_json
|
||||
serialized =
|
||||
described_class.new(
|
||||
user_badge,
|
||||
scope: guardian,
|
||||
allowed_user_badge_topic_ids: guardian.can_see_topic_ids(topic_ids: [post.topic_id]),
|
||||
root: false,
|
||||
).as_json
|
||||
|
||||
expect(serialized[:topic_id]).to eq(nil)
|
||||
expect(serialized[:topic_title]).to eq(nil)
|
||||
end
|
||||
|
||||
it 'does not include attributes in serialized object when user badge is not associated with a post' do
|
||||
it "does not include attributes in serialized object when user badge is not associated with a post" do
|
||||
user_badge.update!(post_id: nil)
|
||||
|
||||
serialized = described_class.new(user_badge,
|
||||
scope: guardian,
|
||||
allowed_user_badge_topic_ids: guardian.can_see_topic_ids(topic_ids: [post.topic_id]),
|
||||
root: false
|
||||
).as_json
|
||||
serialized =
|
||||
described_class.new(
|
||||
user_badge,
|
||||
scope: guardian,
|
||||
allowed_user_badge_topic_ids: guardian.can_see_topic_ids(topic_ids: [post.topic_id]),
|
||||
root: false,
|
||||
).as_json
|
||||
|
||||
expect(serialized[:topic_id]).to eq(nil)
|
||||
expect(serialized[:topic_title]).to eq(nil)
|
||||
end
|
||||
|
||||
it 'does not include attributes in serialized object when user badge is not associated with a topic' do
|
||||
it "does not include attributes in serialized object when user badge is not associated with a topic" do
|
||||
post.topic.destroy!
|
||||
|
||||
serialized = described_class.new(user_badge,
|
||||
scope: guardian,
|
||||
allowed_user_badge_topic_ids: guardian.can_see_topic_ids(topic_ids: [post.topic_id]),
|
||||
root: false
|
||||
).as_json
|
||||
serialized =
|
||||
described_class.new(
|
||||
user_badge,
|
||||
scope: guardian,
|
||||
allowed_user_badge_topic_ids: guardian.can_see_topic_ids(topic_ids: [post.topic_id]),
|
||||
root: false,
|
||||
).as_json
|
||||
|
||||
expect(serialized[:topic_id]).to eq(nil)
|
||||
expect(serialized[:topic_title]).to eq(nil)
|
||||
end
|
||||
|
||||
it 'does not include attributes in serialized object when allowed_user_badge_topic_ids option is not provided' do
|
||||
it "does not include attributes in serialized object when allowed_user_badge_topic_ids option is not provided" do
|
||||
serialized = described_class.new(user_badge, scope: guardian, root: false).as_json
|
||||
|
||||
expect(serialized[:topic_id]).to eq(nil)
|
||||
expect(serialized[:topic_title]).to eq(nil)
|
||||
end
|
||||
|
||||
it 'does not included attributes in serialized object when topic id is not present in allowed_user_badge_topic_ids option' do
|
||||
serialized = described_class.new(user_badge,
|
||||
scope: guardian,
|
||||
allowed_user_badge_topic_ids: guardian.can_see_topic_ids(topic_ids: [post.topic_id + 1]),
|
||||
root: false
|
||||
).as_json
|
||||
it "does not included attributes in serialized object when topic id is not present in allowed_user_badge_topic_ids option" do
|
||||
serialized =
|
||||
described_class.new(
|
||||
user_badge,
|
||||
scope: guardian,
|
||||
allowed_user_badge_topic_ids: guardian.can_see_topic_ids(topic_ids: [post.topic_id + 1]),
|
||||
root: false,
|
||||
).as_json
|
||||
|
||||
expect(serialized[:topic_id]).to eq(nil)
|
||||
expect(serialized[:topic_title]).to eq(nil)
|
||||
end
|
||||
|
||||
it 'includes attributes in serialized object for admin scope even if allowed_user_badge_topic_ids option is not provided' do
|
||||
it "includes attributes in serialized object for admin scope even if allowed_user_badge_topic_ids option is not provided" do
|
||||
serialized = described_class.new(user_badge, scope: Guardian.new(admin), root: false).as_json
|
||||
|
||||
expect(serialized[:topic_id]).to eq(post.topic_id)
|
||||
expect(serialized[:topic_title]).to eq(post.topic.title)
|
||||
end
|
||||
|
||||
it 'includes attributes in serialized object when topic id is present in allowed_user_badge_topic_ids option' do
|
||||
serialized = described_class.new(user_badge,
|
||||
scope: guardian,
|
||||
allowed_user_badge_topic_ids: guardian.can_see_topic_ids(topic_ids: [post.topic_id]),
|
||||
root: false
|
||||
).as_json
|
||||
it "includes attributes in serialized object when topic id is present in allowed_user_badge_topic_ids option" do
|
||||
serialized =
|
||||
described_class.new(
|
||||
user_badge,
|
||||
scope: guardian,
|
||||
allowed_user_badge_topic_ids: guardian.can_see_topic_ids(topic_ids: [post.topic_id]),
|
||||
root: false,
|
||||
).as_json
|
||||
|
||||
expect(serialized[:topic_id]).to eq(post.topic_id)
|
||||
expect(serialized[:topic_title]).to eq(post.topic.title)
|
||||
|
||||
@@ -3,12 +3,11 @@
|
||||
RSpec.describe DirectoryItemSerializer do
|
||||
fab!(:user) { Fabricate(:user) }
|
||||
|
||||
before do
|
||||
DirectoryItem.refresh!
|
||||
end
|
||||
before { DirectoryItem.refresh! }
|
||||
|
||||
let :serializer do
|
||||
directory_item = DirectoryItem.find_by(user: user, period_type: DirectoryItem.period_types[:all])
|
||||
directory_item =
|
||||
DirectoryItem.find_by(user: user, period_type: DirectoryItem.period_types[:all])
|
||||
DirectoryItemSerializer.new(directory_item, { attributes: DirectoryColumn.active_column_names })
|
||||
end
|
||||
|
||||
|
||||
@@ -1,34 +1,28 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
RSpec.describe EmojiSerializer do
|
||||
fab!(:custom_emoji) do
|
||||
CustomEmoji.create!(name: 'trout', upload: Fabricate(:upload))
|
||||
end
|
||||
fab!(:custom_emoji) { CustomEmoji.create!(name: "trout", upload: Fabricate(:upload)) }
|
||||
|
||||
describe '#url' do
|
||||
fab!(:emoji) do
|
||||
Emoji.load_custom.first
|
||||
end
|
||||
describe "#url" do
|
||||
fab!(:emoji) { Emoji.load_custom.first }
|
||||
subject { described_class.new(emoji, root: false) }
|
||||
|
||||
it 'returns a valid URL' do
|
||||
expect(subject.url).to start_with('/uploads/')
|
||||
it "returns a valid URL" do
|
||||
expect(subject.url).to start_with("/uploads/")
|
||||
end
|
||||
|
||||
it 'works with a CDN' do
|
||||
set_cdn_url('https://cdn.com')
|
||||
expect(subject.url).to start_with('https://cdn.com')
|
||||
it "works with a CDN" do
|
||||
set_cdn_url("https://cdn.com")
|
||||
expect(subject.url).to start_with("https://cdn.com")
|
||||
end
|
||||
end
|
||||
|
||||
describe "missing uploads" do
|
||||
before do
|
||||
custom_emoji.upload.destroy!
|
||||
end
|
||||
before { custom_emoji.upload.destroy! }
|
||||
|
||||
it "doesn't raise an error with a missing upload and a CDN" do
|
||||
emoji = Emoji.load_custom.first
|
||||
set_cdn_url('https://cdn.com')
|
||||
set_cdn_url("https://cdn.com")
|
||||
result = described_class.new(Emoji.load_custom.first, root: false).as_json
|
||||
expect(result[:url]).to be_blank
|
||||
end
|
||||
|
||||
@@ -4,7 +4,7 @@ RSpec.describe FoundUserSerializer do
|
||||
fab!(:user) { Fabricate(:user) }
|
||||
let(:serializer) { described_class.new(user, root: false) }
|
||||
|
||||
describe '#name' do
|
||||
describe "#name" do
|
||||
it "returns name if enabled in site settings" do
|
||||
SiteSetting.enable_names = true
|
||||
json = serializer.as_json
|
||||
|
||||
@@ -4,11 +4,11 @@ RSpec.describe GroupShowSerializer do
|
||||
fab!(:user) { Fabricate(:user) }
|
||||
fab!(:group) { Fabricate(:group) }
|
||||
|
||||
context 'with an admin user' do
|
||||
context "with an admin user" do
|
||||
fab!(:user) { Fabricate(:admin) }
|
||||
fab!(:group) { Fabricate(:group, users: [user]) }
|
||||
|
||||
it 'should return the right attributes' do
|
||||
it "should return the right attributes" do
|
||||
json = GroupShowSerializer.new(group, scope: Guardian.new(user)).as_json
|
||||
|
||||
expect(json[:group_show][:is_group_owner]).to eq(nil)
|
||||
@@ -16,12 +16,10 @@ RSpec.describe GroupShowSerializer do
|
||||
end
|
||||
end
|
||||
|
||||
context 'with a group owner' do
|
||||
before do
|
||||
group.add_owner(user)
|
||||
end
|
||||
context "with a group owner" do
|
||||
before { group.add_owner(user) }
|
||||
|
||||
it 'should return the right attributes' do
|
||||
it "should return the right attributes" do
|
||||
json = GroupShowSerializer.new(group, scope: Guardian.new(user)).as_json
|
||||
|
||||
expect(json[:group_show][:is_group_owner]).to eq(true)
|
||||
@@ -29,10 +27,10 @@ RSpec.describe GroupShowSerializer do
|
||||
end
|
||||
end
|
||||
|
||||
describe '#mentionable' do
|
||||
describe "#mentionable" do
|
||||
fab!(:group) { Fabricate(:group, mentionable_level: Group::ALIAS_LEVELS[:everyone]) }
|
||||
|
||||
it 'should return the right value' do
|
||||
it "should return the right value" do
|
||||
json = GroupShowSerializer.new(group, scope: Guardian.new).as_json
|
||||
|
||||
expect(json[:group_show][:mentionable]).to eq(nil)
|
||||
@@ -43,40 +41,42 @@ RSpec.describe GroupShowSerializer do
|
||||
end
|
||||
end
|
||||
|
||||
describe '#automatic_membership_email_domains' do
|
||||
fab!(:group) { Fabricate(:group, automatic_membership_email_domains: 'ilovediscourse.com') }
|
||||
describe "#automatic_membership_email_domains" do
|
||||
fab!(:group) { Fabricate(:group, automatic_membership_email_domains: "ilovediscourse.com") }
|
||||
let(:admin_guardian) { Guardian.new(Fabricate(:admin)) }
|
||||
|
||||
it 'should include email domains for admin' do
|
||||
subject = described_class.new(group, scope: admin_guardian, root: false, owner_group_ids: [group.id])
|
||||
expect(subject.as_json[:automatic_membership_email_domains]).to eq('ilovediscourse.com')
|
||||
it "should include email domains for admin" do
|
||||
subject =
|
||||
described_class.new(group, scope: admin_guardian, root: false, owner_group_ids: [group.id])
|
||||
expect(subject.as_json[:automatic_membership_email_domains]).to eq("ilovediscourse.com")
|
||||
end
|
||||
|
||||
it 'should not include email domains for other users' do
|
||||
subject = described_class.new(group, scope: Guardian.new, root: false, owner_group_ids: [group.id])
|
||||
it "should not include email domains for other users" do
|
||||
subject =
|
||||
described_class.new(group, scope: Guardian.new, root: false, owner_group_ids: [group.id])
|
||||
expect(subject.as_json[:automatic_membership_email_domains]).to eq(nil)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'admin only fields' do
|
||||
fab!(:group) { Fabricate(:group, email_username: 'foo@bar.com', email_password: 'pa$$w0rd') }
|
||||
describe "admin only fields" do
|
||||
fab!(:group) { Fabricate(:group, email_username: "foo@bar.com", email_password: "pa$$w0rd") }
|
||||
subject { described_class.new(group, scope: guardian, root: false) }
|
||||
|
||||
context 'for a user' do
|
||||
context "for a user" do
|
||||
let(:guardian) { Guardian.new(Fabricate(:user)) }
|
||||
|
||||
it 'are not visible' do
|
||||
it "are not visible" do
|
||||
expect(subject.as_json[:email_username]).to be_nil
|
||||
expect(subject.as_json[:email_password]).to be_nil
|
||||
end
|
||||
end
|
||||
|
||||
context 'for an admin' do
|
||||
context "for an admin" do
|
||||
let(:guardian) { Guardian.new(Fabricate(:admin)) }
|
||||
|
||||
it 'are visible' do
|
||||
expect(subject.as_json[:email_username]).to eq('foo@bar.com')
|
||||
expect(subject.as_json[:email_password]).to eq('pa$$w0rd')
|
||||
it "are visible" do
|
||||
expect(subject.as_json[:email_username]).to eq("foo@bar.com")
|
||||
expect(subject.as_json[:email_password]).to eq("pa$$w0rd")
|
||||
expect(subject.as_json[:message_count]).to eq(0)
|
||||
end
|
||||
end
|
||||
@@ -95,22 +95,22 @@ RSpec.describe GroupShowSerializer do
|
||||
GroupCategoryNotificationDefault.create!(
|
||||
group: group,
|
||||
category: category1,
|
||||
notification_level: GroupCategoryNotificationDefault.notification_levels[:watching]
|
||||
notification_level: GroupCategoryNotificationDefault.notification_levels[:watching],
|
||||
)
|
||||
GroupCategoryNotificationDefault.create!(
|
||||
group: group,
|
||||
category: category2,
|
||||
notification_level: GroupCategoryNotificationDefault.notification_levels[:tracking]
|
||||
notification_level: GroupCategoryNotificationDefault.notification_levels[:tracking],
|
||||
)
|
||||
GroupTagNotificationDefault.create!(
|
||||
group: group,
|
||||
tag: tag1,
|
||||
notification_level: GroupTagNotificationDefault.notification_levels[:watching]
|
||||
notification_level: GroupTagNotificationDefault.notification_levels[:watching],
|
||||
)
|
||||
GroupTagNotificationDefault.create!(
|
||||
group: group,
|
||||
tag: tag2,
|
||||
notification_level: GroupTagNotificationDefault.notification_levels[:tracking]
|
||||
notification_level: GroupTagNotificationDefault.notification_levels[:tracking],
|
||||
)
|
||||
end
|
||||
|
||||
@@ -142,7 +142,9 @@ RSpec.describe GroupShowSerializer do
|
||||
|
||||
it "doesn't include tag fields if tags are disabled" do
|
||||
SiteSetting.tagging_enabled = false
|
||||
expect(subject.as_json.keys.select { |k| k.to_s.ends_with?("_category_ids") }.length).to eq(5)
|
||||
expect(subject.as_json.keys.select { |k| k.to_s.ends_with?("_category_ids") }.length).to eq(
|
||||
5,
|
||||
)
|
||||
expect(subject.as_json.keys.select { |k| k.to_s.ends_with?("_tags") }).to be_empty
|
||||
end
|
||||
end
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
RSpec.describe GroupUserSerializer do
|
||||
let(:serializer) { described_class.new(user, scope: Guardian.new(user), root: false) }
|
||||
|
||||
describe '#status' do
|
||||
describe "#status" do
|
||||
fab!(:user_status) { Fabricate(:user_status) }
|
||||
fab!(:user) { Fabricate(:user, user_status: user_status) }
|
||||
|
||||
|
||||
@@ -2,36 +2,25 @@
|
||||
RSpec.describe ListableTopicSerializer do
|
||||
fab!(:topic) { Fabricate(:topic) }
|
||||
|
||||
describe '#excerpt' do
|
||||
it 'can be extended by theme modifiers' do
|
||||
payload = TopicListItemSerializer.new(topic,
|
||||
scope: Guardian.new,
|
||||
root: false
|
||||
).as_json
|
||||
describe "#excerpt" do
|
||||
it "can be extended by theme modifiers" do
|
||||
payload = TopicListItemSerializer.new(topic, scope: Guardian.new, root: false).as_json
|
||||
|
||||
expect(payload[:excerpt]).to eq(nil)
|
||||
|
||||
theme = Fabricate(:theme)
|
||||
|
||||
child_theme = Fabricate(:theme, component: true).tap do |t|
|
||||
theme.add_relative_theme!(:child, t)
|
||||
end
|
||||
child_theme =
|
||||
Fabricate(:theme, component: true).tap { |t| theme.add_relative_theme!(:child, t) }
|
||||
|
||||
child_theme.theme_modifier_set.serialize_topic_excerpts = true
|
||||
child_theme.save!
|
||||
|
||||
request = ActionController::TestRequest.new(
|
||||
{ resolved_theme_id: theme.id },
|
||||
nil,
|
||||
nil
|
||||
)
|
||||
request = ActionController::TestRequest.new({ resolved_theme_id: theme.id }, nil, nil)
|
||||
|
||||
guardian = Guardian.new(nil, request)
|
||||
|
||||
payload = TopicListItemSerializer.new(topic,
|
||||
scope: guardian,
|
||||
root: false
|
||||
).as_json
|
||||
payload = TopicListItemSerializer.new(topic, scope: guardian, root: false).as_json
|
||||
|
||||
expect(payload[:excerpt]).to eq(topic.excerpt)
|
||||
end
|
||||
|
||||
@@ -1,15 +1,14 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
RSpec.describe NewPostResultSerializer do
|
||||
|
||||
it "includes the message and route_to if present" do
|
||||
result = NewPostResult.new(:custom, true)
|
||||
result.message = 'hello :)'
|
||||
result.message = "hello :)"
|
||||
result.route_to = "/cool-route"
|
||||
|
||||
serializer = described_class.new(result)
|
||||
expect(serializer.success).to eq(true)
|
||||
expect(serializer.message).to eq('hello :)')
|
||||
expect(serializer.route_to).to eq('/cool-route')
|
||||
expect(serializer.message).to eq("hello :)")
|
||||
expect(serializer.route_to).to eq("/cool-route")
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
RSpec.describe NotificationSerializer do
|
||||
describe '#as_json' do
|
||||
describe "#as_json" do
|
||||
fab!(:user) { Fabricate(:user) }
|
||||
let(:notification) { Fabricate(:notification, user: user) }
|
||||
let(:serializer) { NotificationSerializer.new(notification) }
|
||||
@@ -16,10 +16,10 @@ RSpec.describe NotificationSerializer do
|
||||
end
|
||||
end
|
||||
|
||||
describe '#sso_enabled' do
|
||||
describe "#sso_enabled" do
|
||||
let :user do
|
||||
user = Fabricate(:user)
|
||||
SingleSignOnRecord.create!(user_id: user.id, external_id: '12345', last_payload: '')
|
||||
SingleSignOnRecord.create!(user_id: user.id, external_id: "12345", last_payload: "")
|
||||
user
|
||||
end
|
||||
let(:notification) { Fabricate(:notification, user: user) }
|
||||
|
||||
@@ -22,7 +22,7 @@ RSpec.describe PendingPostSerializer do
|
||||
title: post.payload["title"],
|
||||
topic_id: nil,
|
||||
topic_url: nil,
|
||||
username: author.username
|
||||
username: author.username,
|
||||
}
|
||||
end
|
||||
|
||||
@@ -46,7 +46,7 @@ RSpec.describe PendingPostSerializer do
|
||||
title: topic.title,
|
||||
topic_id: topic.id,
|
||||
topic_url: topic.url,
|
||||
username: author.username
|
||||
username: author.username,
|
||||
}
|
||||
end
|
||||
|
||||
|
||||
@@ -3,25 +3,39 @@
|
||||
RSpec.describe PostRevisionSerializer do
|
||||
fab!(:post) { Fabricate(:post, version: 2) }
|
||||
|
||||
context 'with hidden tags' do
|
||||
fab!(:public_tag) { Fabricate(:tag, name: 'public') }
|
||||
fab!(:public_tag2) { Fabricate(:tag, name: 'visible') }
|
||||
fab!(:hidden_tag) { Fabricate(:tag, name: 'hidden') }
|
||||
fab!(:hidden_tag2) { Fabricate(:tag, name: 'secret') }
|
||||
context "with hidden tags" do
|
||||
fab!(:public_tag) { Fabricate(:tag, name: "public") }
|
||||
fab!(:public_tag2) { Fabricate(:tag, name: "visible") }
|
||||
fab!(:hidden_tag) { Fabricate(:tag, name: "hidden") }
|
||||
fab!(:hidden_tag2) { Fabricate(:tag, name: "secret") }
|
||||
|
||||
let(:staff_tag_group) { Fabricate(:tag_group, permissions: { "staff" => 1 }, tag_names: [hidden_tag.name, hidden_tag2.name]) }
|
||||
let(:staff_tag_group) do
|
||||
Fabricate(
|
||||
:tag_group,
|
||||
permissions: {
|
||||
"staff" => 1,
|
||||
},
|
||||
tag_names: [hidden_tag.name, hidden_tag2.name],
|
||||
)
|
||||
end
|
||||
|
||||
let(:post_revision) do
|
||||
Fabricate(:post_revision,
|
||||
Fabricate(
|
||||
:post_revision,
|
||||
post: post,
|
||||
modifications: { 'tags' => [['public', 'hidden'], ['visible', 'hidden']] }
|
||||
modifications: {
|
||||
"tags" => [%w[public hidden], %w[visible hidden]],
|
||||
},
|
||||
)
|
||||
end
|
||||
|
||||
let(:post_revision2) do
|
||||
Fabricate(:post_revision,
|
||||
Fabricate(
|
||||
:post_revision,
|
||||
post: post,
|
||||
modifications: { 'tags' => [['visible', 'hidden', 'secret'], ['visible', 'hidden']] }
|
||||
modifications: {
|
||||
"tags" => [%w[visible hidden secret], %w[visible hidden]],
|
||||
},
|
||||
)
|
||||
end
|
||||
|
||||
@@ -31,22 +45,37 @@ RSpec.describe PostRevisionSerializer do
|
||||
post.topic.tags = [public_tag2, hidden_tag]
|
||||
end
|
||||
|
||||
it 'returns all tag changes to staff' do
|
||||
json = PostRevisionSerializer.new(post_revision, scope: Guardian.new(Fabricate(:admin)), root: false).as_json
|
||||
it "returns all tag changes to staff" do
|
||||
json =
|
||||
PostRevisionSerializer.new(
|
||||
post_revision,
|
||||
scope: Guardian.new(Fabricate(:admin)),
|
||||
root: false,
|
||||
).as_json
|
||||
expect(json[:tags_changes][:previous]).to include(public_tag.name)
|
||||
expect(json[:tags_changes][:previous]).to include(hidden_tag.name)
|
||||
expect(json[:tags_changes][:current]).to include(public_tag2.name)
|
||||
expect(json[:tags_changes][:current]).to include(hidden_tag.name)
|
||||
end
|
||||
|
||||
it 'does not return hidden tags to non-staff' do
|
||||
json = PostRevisionSerializer.new(post_revision, scope: Guardian.new(Fabricate(:user)), root: false).as_json
|
||||
it "does not return hidden tags to non-staff" do
|
||||
json =
|
||||
PostRevisionSerializer.new(
|
||||
post_revision,
|
||||
scope: Guardian.new(Fabricate(:user)),
|
||||
root: false,
|
||||
).as_json
|
||||
expect(json[:tags_changes][:previous]).to eq([public_tag.name])
|
||||
expect(json[:tags_changes][:current]).to eq([public_tag2.name])
|
||||
end
|
||||
|
||||
it 'does not show tag modifications if changes are not visible to the user' do
|
||||
json = PostRevisionSerializer.new(post_revision2, scope: Guardian.new(Fabricate(:user)), root: false).as_json
|
||||
it "does not show tag modifications if changes are not visible to the user" do
|
||||
json =
|
||||
PostRevisionSerializer.new(
|
||||
post_revision2,
|
||||
scope: Guardian.new(Fabricate(:user)),
|
||||
root: false,
|
||||
).as_json
|
||||
expect(json[:tags_changes]).to_not be_present
|
||||
end
|
||||
end
|
||||
|
||||
@@ -3,59 +3,53 @@
|
||||
RSpec.describe PostSerializer do
|
||||
fab!(:post) { Fabricate(:post) }
|
||||
|
||||
before do
|
||||
Group.refresh_automatic_groups!
|
||||
end
|
||||
before { Group.refresh_automatic_groups! }
|
||||
|
||||
context "with a post with lots of actions" do
|
||||
fab!(:actor) { Fabricate(:user) }
|
||||
fab!(:admin) { Fabricate(:admin) }
|
||||
let(:acted_ids) {
|
||||
PostActionType.public_types.values
|
||||
.concat([:notify_user, :spam].map { |k| PostActionType.types[k] })
|
||||
}
|
||||
let(:acted_ids) do
|
||||
PostActionType.public_types.values.concat(
|
||||
%i[notify_user spam].map { |k| PostActionType.types[k] },
|
||||
)
|
||||
end
|
||||
|
||||
def visible_actions_for(user)
|
||||
serializer = PostSerializer.new(post, scope: Guardian.new(user), root: false)
|
||||
# NOTE this is messy, we should extract all this logic elsewhere
|
||||
serializer.post_actions = PostAction.counts_for([post], actor)[post.id] if user.try(:id) == actor.id
|
||||
serializer.post_actions = PostAction.counts_for([post], actor)[post.id] if user.try(:id) ==
|
||||
actor.id
|
||||
actions = serializer.as_json[:actions_summary]
|
||||
lookup = PostActionType.types.invert
|
||||
actions.keep_if { |a| (a[:count] || 0) > 0 }.map { |a| lookup[a[:id]] }
|
||||
end
|
||||
|
||||
before do
|
||||
acted_ids.each do |id|
|
||||
PostActionCreator.new(actor, post, id).perform
|
||||
end
|
||||
acted_ids.each { |id| PostActionCreator.new(actor, post, id).perform }
|
||||
post.reload
|
||||
end
|
||||
|
||||
it "displays the correct info" do
|
||||
expect(visible_actions_for(actor).sort).to eq([:like, :notify_user, :spam])
|
||||
expect(visible_actions_for(actor).sort).to eq(%i[like notify_user spam])
|
||||
expect(visible_actions_for(post.user).sort).to eq([:like])
|
||||
expect(visible_actions_for(nil).sort).to eq([:like])
|
||||
expect(visible_actions_for(admin).sort).to eq([:like, :notify_user, :spam])
|
||||
expect(visible_actions_for(admin).sort).to eq(%i[like notify_user spam])
|
||||
end
|
||||
|
||||
it "can't flag your own post to notify yourself" do
|
||||
serializer = PostSerializer.new(post, scope: Guardian.new(post.user), root: false)
|
||||
notify_user_action = serializer.actions_summary.find { |a| a[:id] == PostActionType.types[:notify_user] }
|
||||
notify_user_action =
|
||||
serializer.actions_summary.find { |a| a[:id] == PostActionType.types[:notify_user] }
|
||||
expect(notify_user_action).to be_blank
|
||||
end
|
||||
|
||||
it "should not allow user to flag post and notify non human user" do
|
||||
post.update!(user: Discourse.system_user)
|
||||
|
||||
serializer = PostSerializer.new(
|
||||
post,
|
||||
scope: Guardian.new(actor),
|
||||
root: false
|
||||
)
|
||||
serializer = PostSerializer.new(post, scope: Guardian.new(actor), root: false)
|
||||
|
||||
notify_user_action = serializer.actions_summary.find do |a|
|
||||
a[:id] == PostActionType.types[:notify_user]
|
||||
end
|
||||
notify_user_action =
|
||||
serializer.actions_summary.find { |a| a[:id] == PostActionType.types[:notify_user] }
|
||||
|
||||
expect(notify_user_action).to eq(nil)
|
||||
end
|
||||
@@ -65,7 +59,8 @@ RSpec.describe PostSerializer do
|
||||
let!(:reviewable) { PostActionCreator.spam(Fabricate(:user), post).reviewable }
|
||||
|
||||
it "includes the reviewable data" do
|
||||
json = PostSerializer.new(post, scope: Guardian.new(Fabricate(:moderator)), root: false).as_json
|
||||
json =
|
||||
PostSerializer.new(post, scope: Guardian.new(Fabricate(:moderator)), root: false).as_json
|
||||
expect(json[:reviewable_id]).to eq(reviewable.id)
|
||||
expect(json[:reviewable_score_count]).to eq(1)
|
||||
expect(json[:reviewable_score_pending_count]).to eq(1)
|
||||
@@ -73,22 +68,17 @@ RSpec.describe PostSerializer do
|
||||
end
|
||||
|
||||
context "with a post by a nuked user" do
|
||||
before do
|
||||
post.update!(
|
||||
user_id: nil,
|
||||
deleted_at: Time.zone.now
|
||||
)
|
||||
before { post.update!(user_id: nil, deleted_at: Time.zone.now) }
|
||||
|
||||
subject do
|
||||
PostSerializer.new(post, scope: Guardian.new(Fabricate(:admin)), root: false).as_json
|
||||
end
|
||||
|
||||
subject { PostSerializer.new(post, scope: Guardian.new(Fabricate(:admin)), root: false).as_json }
|
||||
|
||||
it "serializes correctly" do
|
||||
[:name, :username, :display_username, :avatar_template, :user_title, :trust_level].each do |attr|
|
||||
%i[name username display_username avatar_template user_title trust_level].each do |attr|
|
||||
expect(subject[attr]).to be_nil
|
||||
end
|
||||
[:moderator, :staff, :yours].each do |attr|
|
||||
expect(subject[attr]).to eq(false)
|
||||
end
|
||||
%i[moderator staff yours].each { |attr| expect(subject[attr]).to eq(false) }
|
||||
end
|
||||
end
|
||||
|
||||
@@ -100,9 +90,7 @@ RSpec.describe PostSerializer do
|
||||
it "serializes correctly" do
|
||||
expect(subject[:user_suspended]).to be_nil
|
||||
|
||||
post.user.update!(
|
||||
suspended_till: 1.month.from_now,
|
||||
)
|
||||
post.user.update!(suspended_till: 1.month.from_now)
|
||||
|
||||
expect(subject[:user_suspended]).to eq(true)
|
||||
|
||||
@@ -130,7 +118,7 @@ RSpec.describe PostSerializer do
|
||||
|
||||
context "with a hidden post with add_raw enabled" do
|
||||
let(:user) { Fabricate(:user) }
|
||||
let(:raw) { "Raw contents of the post." }
|
||||
let(:raw) { "Raw contents of the post." }
|
||||
|
||||
context "with a public post" do
|
||||
let(:post) { Fabricate(:post, raw: raw, user: user) }
|
||||
@@ -143,7 +131,15 @@ RSpec.describe PostSerializer do
|
||||
end
|
||||
|
||||
context "with a hidden post" do
|
||||
let(:post) { Fabricate(:post, raw: raw, user: user, hidden: true, hidden_reason_id: Post.hidden_reasons[:flag_threshold_reached]) }
|
||||
let(:post) do
|
||||
Fabricate(
|
||||
:post,
|
||||
raw: raw,
|
||||
user: user,
|
||||
hidden: true,
|
||||
hidden_reason_id: Post.hidden_reasons[:flag_threshold_reached],
|
||||
)
|
||||
end
|
||||
|
||||
it "shows the raw post only if authorized to see it" do
|
||||
expect(serialized_post_for_user(nil)[:raw]).to eq(nil)
|
||||
@@ -165,13 +161,13 @@ RSpec.describe PostSerializer do
|
||||
end
|
||||
|
||||
context "with a hidden revised post" do
|
||||
fab!(:post) { Fabricate(:post, raw: 'Hello world!', hidden: true) }
|
||||
fab!(:post) { Fabricate(:post, raw: "Hello world!", hidden: true) }
|
||||
|
||||
before do
|
||||
SiteSetting.editing_grace_period_max_diff = 1
|
||||
|
||||
revisor = PostRevisor.new(post)
|
||||
revisor.revise!(post.user, raw: 'Hello, everyone!')
|
||||
revisor.revise!(post.user, raw: "Hello, everyone!")
|
||||
end
|
||||
|
||||
it "will not leak version to users" do
|
||||
@@ -196,15 +192,16 @@ RSpec.describe PostSerializer do
|
||||
end
|
||||
|
||||
context "with a hidden wiki post" do
|
||||
let(:post) {
|
||||
let(:post) do
|
||||
Fabricate(
|
||||
:post,
|
||||
raw: raw,
|
||||
user: user,
|
||||
wiki: true,
|
||||
hidden: true,
|
||||
hidden_reason_id: Post.hidden_reasons[:flag_threshold_reached])
|
||||
}
|
||||
hidden_reason_id: Post.hidden_reasons[:flag_threshold_reached],
|
||||
)
|
||||
end
|
||||
|
||||
it "can view edit history only if authorized" do
|
||||
expect(serialized_post_for_user(nil)[:can_view_edit_history]).to eq(false)
|
||||
@@ -214,7 +211,6 @@ RSpec.describe PostSerializer do
|
||||
expect(serialized_post_for_user(Fabricate(:admin))[:can_view_edit_history]).to eq(true)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
context "with a post with notices" do
|
||||
@@ -222,12 +218,15 @@ RSpec.describe PostSerializer do
|
||||
fab!(:user_tl1) { Fabricate(:user, trust_level: 1) }
|
||||
fab!(:user_tl2) { Fabricate(:user, trust_level: 2) }
|
||||
|
||||
let(:post) {
|
||||
let(:post) do
|
||||
post = Fabricate(:post, user: user)
|
||||
post.custom_fields[Post::NOTICE] = { type: Post.notices[:returning_user], last_posted_at: 1.day.ago }
|
||||
post.custom_fields[Post::NOTICE] = {
|
||||
type: Post.notices[:returning_user],
|
||||
last_posted_at: 1.day.ago,
|
||||
}
|
||||
post.save_custom_fields
|
||||
post
|
||||
}
|
||||
end
|
||||
|
||||
def json_for_user(user)
|
||||
PostSerializer.new(post, scope: Guardian.new(user), root: false).as_json
|
||||
@@ -258,7 +257,9 @@ RSpec.describe PostSerializer do
|
||||
end
|
||||
|
||||
context "when a Bookmark record exists for the user on the post" do
|
||||
let!(:bookmark) { Fabricate(:bookmark_next_business_day_reminder, user: current_user, bookmarkable: post) }
|
||||
let!(:bookmark) do
|
||||
Fabricate(:bookmark_next_business_day_reminder, user: current_user, bookmarkable: post)
|
||||
end
|
||||
|
||||
context "with bookmarks with reminders" do
|
||||
it "returns true" do
|
||||
@@ -290,7 +291,6 @@ RSpec.describe PostSerializer do
|
||||
post.update!(user: group_user.user)
|
||||
expect(serialized_post_for_user(nil)[:group_moderator]).to eq(true)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
context "with a post with small action" do
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
RSpec.describe ReviewableFlaggedPostSerializer do
|
||||
|
||||
fab!(:admin) { Fabricate(:admin) }
|
||||
|
||||
it "includes the user fields for review" do
|
||||
p0 = Fabricate(:post)
|
||||
reviewable = PostActionCreator.spam(Fabricate(:user), p0).reviewable
|
||||
json = ReviewableFlaggedPostSerializer.new(reviewable, scope: Guardian.new(admin), root: nil).as_json
|
||||
json =
|
||||
ReviewableFlaggedPostSerializer.new(reviewable, scope: Guardian.new(admin), root: nil).as_json
|
||||
expect(json[:cooked]).to eq(p0.cooked)
|
||||
expect(json[:raw]).to eq(p0.raw)
|
||||
expect(json[:target_url]).to eq(Discourse.base_url + p0.url)
|
||||
@@ -18,8 +18,8 @@ RSpec.describe ReviewableFlaggedPostSerializer do
|
||||
reviewable.topic.update(deleted_at: Time.now)
|
||||
reviewable.reload
|
||||
|
||||
json = ReviewableQueuedPostSerializer.new(reviewable, scope: Guardian.new(admin), root: nil).as_json
|
||||
json =
|
||||
ReviewableQueuedPostSerializer.new(reviewable, scope: Guardian.new(admin), root: nil).as_json
|
||||
expect(json[:id]).to be_present
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -7,31 +7,36 @@ RSpec.describe ReviewableQueuedPostSerializer do
|
||||
fab!(:reviewable) { Fabricate(:reviewable_queued_post_topic) }
|
||||
|
||||
it "allows us to edit category / title" do
|
||||
json = ReviewableQueuedPostSerializer.new(reviewable, scope: Guardian.new(admin), root: nil).as_json
|
||||
json =
|
||||
ReviewableQueuedPostSerializer.new(
|
||||
reviewable,
|
||||
scope: Guardian.new(admin),
|
||||
root: nil,
|
||||
).as_json
|
||||
|
||||
payload = json[:payload]
|
||||
expect(payload['raw']).to eq('hello world post contents.')
|
||||
expect(payload['title']).to eq('queued post title')
|
||||
expect(payload['tags']).to eq(['cool', 'neat'])
|
||||
expect(payload["raw"]).to eq("hello world post contents.")
|
||||
expect(payload["title"]).to eq("queued post title")
|
||||
expect(payload["tags"]).to eq(%w[cool neat])
|
||||
expect(json[:topic_id]).to be_blank
|
||||
expect(json[:can_edit]).to eq(true)
|
||||
|
||||
fields = json[:editable_fields]
|
||||
expect(fields).to be_present
|
||||
|
||||
category_field = fields.find { |f| f[:id] == 'category_id' }
|
||||
category_field = fields.find { |f| f[:id] == "category_id" }
|
||||
expect(category_field).to be_present
|
||||
expect(category_field[:type]).to eq(:category)
|
||||
|
||||
title_field = fields.find { |f| f[:id] == 'payload.title' }
|
||||
title_field = fields.find { |f| f[:id] == "payload.title" }
|
||||
expect(title_field).to be_present
|
||||
expect(title_field[:type]).to eq(:text)
|
||||
|
||||
raw_field = fields.find { |f| f[:id] == 'payload.raw' }
|
||||
raw_field = fields.find { |f| f[:id] == "payload.raw" }
|
||||
expect(raw_field).to be_present
|
||||
expect(raw_field[:type]).to eq(:editor)
|
||||
|
||||
tags_field = fields.find { |f| f[:id] == 'payload.tags' }
|
||||
tags_field = fields.find { |f| f[:id] == "payload.tags" }
|
||||
expect(tags_field).to be_present
|
||||
expect(tags_field[:type]).to eq(:tags)
|
||||
end
|
||||
@@ -41,14 +46,19 @@ RSpec.describe ReviewableQueuedPostSerializer do
|
||||
fab!(:reviewable) { Fabricate(:reviewable_queued_post) }
|
||||
|
||||
it "includes correct user fields" do
|
||||
json = ReviewableQueuedPostSerializer.new(reviewable, scope: Guardian.new(admin), root: nil).as_json
|
||||
json =
|
||||
ReviewableQueuedPostSerializer.new(
|
||||
reviewable,
|
||||
scope: Guardian.new(admin),
|
||||
root: nil,
|
||||
).as_json
|
||||
|
||||
payload = json[:payload]
|
||||
|
||||
expect(payload['raw']).to eq('hello world post contents.')
|
||||
expect(payload['title']).to be_blank
|
||||
expect(payload['via_email']).to eq(true)
|
||||
expect(payload['raw_email']).to eq('store_me')
|
||||
expect(payload["raw"]).to eq("hello world post contents.")
|
||||
expect(payload["title"]).to be_blank
|
||||
expect(payload["via_email"]).to eq(true)
|
||||
expect(payload["raw_email"]).to eq("store_me")
|
||||
expect(json[:topic_id]).to eq(reviewable.topic_id)
|
||||
expect(json[:topic_url]).to eq(reviewable.topic.url)
|
||||
expect(json[:can_edit]).to eq(true)
|
||||
@@ -56,10 +66,10 @@ RSpec.describe ReviewableQueuedPostSerializer do
|
||||
fields = json[:editable_fields]
|
||||
expect(fields).to be_present
|
||||
|
||||
expect(fields.any? { |f| f[:id] == 'payload.title' }).to eq(false)
|
||||
expect(fields.any? { |f| f[:id] == 'category_id' }).to eq(false)
|
||||
expect(fields.any? { |f| f[:id] == "payload.title" }).to eq(false)
|
||||
expect(fields.any? { |f| f[:id] == "category_id" }).to eq(false)
|
||||
|
||||
raw_field = fields.find { |f| f[:id] == 'payload.raw' }
|
||||
raw_field = fields.find { |f| f[:id] == "payload.raw" }
|
||||
expect(raw_field).to be_present
|
||||
expect(raw_field[:type]).to eq(:editor)
|
||||
end
|
||||
|
||||
@@ -4,39 +4,51 @@ RSpec.describe ReviewableScoreSerializer do
|
||||
fab!(:reviewable) { Fabricate(:reviewable_flagged_post) }
|
||||
fab!(:admin) { Fabricate(:admin) }
|
||||
|
||||
describe '#reason' do
|
||||
context 'with regular links' do
|
||||
it 'adds a link for watched words' do
|
||||
serialized = serialized_score('watched_word')
|
||||
describe "#reason" do
|
||||
context "with regular links" do
|
||||
it "adds a link for watched words" do
|
||||
serialized = serialized_score("watched_word")
|
||||
link_url = "#{Discourse.base_url}/admin/customize/watched_words"
|
||||
watched_words_link = "<a href=\"#{link_url}\">#{I18n.t('reviewables.reasons.links.watched_word')}</a>"
|
||||
watched_words_link =
|
||||
"<a href=\"#{link_url}\">#{I18n.t("reviewables.reasons.links.watched_word")}</a>"
|
||||
|
||||
expect(serialized.reason).to include(watched_words_link)
|
||||
end
|
||||
|
||||
it 'adds a link for category settings' do
|
||||
category = Fabricate(:category, name: 'Reviewable Category', slug: 'reviewable-category')
|
||||
it "adds a link for category settings" do
|
||||
category = Fabricate(:category, name: "Reviewable Category", slug: "reviewable-category")
|
||||
reviewable.category = category
|
||||
serialized = serialized_score('category')
|
||||
serialized = serialized_score("category")
|
||||
link_url = "#{Discourse.base_url}/c/#{category.slug}/edit/settings"
|
||||
category_link = "<a href=\"#{link_url}\">#{I18n.t('reviewables.reasons.links.category')}</a>"
|
||||
category_link =
|
||||
"<a href=\"#{link_url}\">#{I18n.t("reviewables.reasons.links.category")}</a>"
|
||||
|
||||
expect(serialized.reason).to include(category_link)
|
||||
end
|
||||
end
|
||||
|
||||
context 'with site setting links' do
|
||||
context "with site setting links" do
|
||||
reasons = %w[
|
||||
post_count trust_level new_topics_unless_trust_level fast_typer auto_silence_regex
|
||||
staged must_approve_users invite_only email_spam suspect_user contains_media
|
||||
post_count
|
||||
trust_level
|
||||
new_topics_unless_trust_level
|
||||
fast_typer
|
||||
auto_silence_regex
|
||||
staged
|
||||
must_approve_users
|
||||
invite_only
|
||||
email_spam
|
||||
suspect_user
|
||||
contains_media
|
||||
]
|
||||
|
||||
reasons.each do |r|
|
||||
it "addd a link to a site setting for the #{r} reason" do
|
||||
serialized = serialized_score(r)
|
||||
setting_name = described_class::REASONS_AND_SETTINGS[r.to_sym]
|
||||
link_url = "#{Discourse.base_url}/admin/site_settings/category/all_results?filter=#{setting_name}"
|
||||
link = "<a href=\"#{link_url}\">#{setting_name.gsub('_', ' ')}</a>"
|
||||
link_url =
|
||||
"#{Discourse.base_url}/admin/site_settings/category/all_results?filter=#{setting_name}"
|
||||
link = "<a href=\"#{link_url}\">#{setting_name.gsub("_", " ")}</a>"
|
||||
|
||||
expect(serialized.reason).to include(link)
|
||||
end
|
||||
@@ -44,16 +56,16 @@ RSpec.describe ReviewableScoreSerializer do
|
||||
end
|
||||
end
|
||||
|
||||
describe '#setting_name_for_reason' do
|
||||
describe "#setting_name_for_reason" do
|
||||
after { DiscoursePluginRegistry.reset_register!(:reviewable_score_links) }
|
||||
|
||||
describe 'when a plugin adds a setting name to linkify' do
|
||||
it 'gets the setting name from the registry' do
|
||||
describe "when a plugin adds a setting name to linkify" do
|
||||
it "gets the setting name from the registry" do
|
||||
reason = :plugin_reason
|
||||
setting_name = 'max_username_length'
|
||||
setting_name = "max_username_length"
|
||||
DiscoursePluginRegistry.register_reviewable_score_link(
|
||||
{ reason: reason, setting: setting_name },
|
||||
Plugin::Instance.new
|
||||
Plugin::Instance.new,
|
||||
)
|
||||
|
||||
score = serialized_score(reason)
|
||||
@@ -64,10 +76,7 @@ RSpec.describe ReviewableScoreSerializer do
|
||||
end
|
||||
|
||||
def serialized_score(reason)
|
||||
score = ReviewableScore.new(
|
||||
reviewable: reviewable,
|
||||
reason: reason
|
||||
)
|
||||
score = ReviewableScore.new(reviewable: reviewable, reason: reason)
|
||||
|
||||
described_class.new(score, scope: Guardian.new(admin), root: nil)
|
||||
end
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
RSpec.describe ReviewableSerializer do
|
||||
|
||||
fab!(:reviewable) { Fabricate(:reviewable_queued_post) }
|
||||
fab!(:admin) { Fabricate(:admin) }
|
||||
|
||||
@@ -18,7 +17,7 @@ RSpec.describe ReviewableSerializer do
|
||||
expect(json[:removed_topic_id]).to be_nil
|
||||
end
|
||||
|
||||
it 'Includes the removed topic id when the topis was deleted' do
|
||||
it "Includes the removed topic id when the topis was deleted" do
|
||||
reviewable.topic.trash!(admin)
|
||||
json = described_class.new(reviewable.reload, scope: Guardian.new(admin), root: nil).as_json
|
||||
expect(json[:removed_topic_id]).to eq reviewable.topic_id
|
||||
@@ -26,12 +25,12 @@ RSpec.describe ReviewableSerializer do
|
||||
|
||||
it "will not throw an error when the payload is `nil`" do
|
||||
reviewable.payload = nil
|
||||
json = ReviewableQueuedPostSerializer.new(reviewable, scope: Guardian.new(admin), root: nil).as_json
|
||||
expect(json['payload']).to be_blank
|
||||
json =
|
||||
ReviewableQueuedPostSerializer.new(reviewable, scope: Guardian.new(admin), root: nil).as_json
|
||||
expect(json["payload"]).to be_blank
|
||||
end
|
||||
|
||||
describe "urls" do
|
||||
|
||||
it "links to the flagged post" do
|
||||
fp = Fabricate(:reviewable_flagged_post)
|
||||
json = described_class.new(fp, scope: Guardian.new(admin), root: nil).as_json
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
RSpec.describe ReviewableUserSerializer do
|
||||
|
||||
let(:user) { Fabricate(:user) }
|
||||
let(:admin) { Fabricate(:admin) }
|
||||
|
||||
@@ -12,10 +11,9 @@ RSpec.describe ReviewableUserSerializer do
|
||||
|
||||
json = ReviewableUserSerializer.new(reviewable, scope: Guardian.new(admin), root: nil).as_json
|
||||
expect(json[:user_id]).to eq(reviewable.target_id)
|
||||
expect(json[:payload]['username']).to eq(user.username)
|
||||
expect(json[:payload]['email']).to eq(user.email)
|
||||
expect(json[:payload]['name']).to eq(user.name)
|
||||
expect(json[:payload]["username"]).to eq(user.username)
|
||||
expect(json[:payload]["email"]).to eq(user.email)
|
||||
expect(json[:payload]["name"]).to eq(user.name)
|
||||
expect(json[:topic_url]).to be_blank
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -3,7 +3,12 @@
|
||||
RSpec.describe SingleSignOnRecordSerializer do
|
||||
fab!(:user) { Fabricate(:user) }
|
||||
let :sso do
|
||||
SingleSignOnRecord.create!(user_id: user.id, external_id: '12345', external_email: user.email, last_payload: 'foobar')
|
||||
SingleSignOnRecord.create!(
|
||||
user_id: user.id,
|
||||
external_id: "12345",
|
||||
external_email: user.email,
|
||||
last_payload: "foobar",
|
||||
)
|
||||
end
|
||||
|
||||
context "with an admin" do
|
||||
@@ -15,7 +20,7 @@ RSpec.describe SingleSignOnRecordSerializer do
|
||||
it "should include user sso info" do
|
||||
payload = serializer.as_json
|
||||
expect(payload[:user_id]).to eq(user.id)
|
||||
expect(payload[:external_id]).to eq('12345')
|
||||
expect(payload[:external_id]).to eq("12345")
|
||||
expect(payload[:external_email]).to be_nil
|
||||
end
|
||||
end
|
||||
@@ -29,7 +34,7 @@ RSpec.describe SingleSignOnRecordSerializer do
|
||||
it "should not include user sso payload" do
|
||||
payload = serializer.as_json
|
||||
expect(payload[:user_id]).to eq(user.id)
|
||||
expect(payload[:external_id]).to eq('12345')
|
||||
expect(payload[:external_id]).to eq("12345")
|
||||
expect(payload[:last_payload]).to be_nil
|
||||
end
|
||||
end
|
||||
|
||||
@@ -4,19 +4,17 @@ RSpec.describe SiteSerializer do
|
||||
let(:guardian) { Guardian.new }
|
||||
let(:category) { Fabricate(:category) }
|
||||
|
||||
after do
|
||||
Site.clear_cache
|
||||
end
|
||||
after { Site.clear_cache }
|
||||
|
||||
describe '#user_tips' do
|
||||
it 'is included if enable_user_tips' do
|
||||
describe "#user_tips" do
|
||||
it "is included if enable_user_tips" do
|
||||
SiteSetting.enable_user_tips = true
|
||||
|
||||
serialized = described_class.new(Site.new(guardian), scope: guardian, root: false).as_json
|
||||
expect(serialized[:user_tips]).to eq(User.user_tips)
|
||||
end
|
||||
|
||||
it 'is not included if enable_user_tips is disabled' do
|
||||
it "is not included if enable_user_tips is disabled" do
|
||||
serialized = described_class.new(Site.new(guardian), scope: guardian, root: false).as_json
|
||||
expect(serialized[:user_tips]).to eq(nil)
|
||||
end
|
||||
@@ -49,7 +47,11 @@ RSpec.describe SiteSerializer do
|
||||
|
||||
category.tags << tag
|
||||
category.tag_groups << tag_group
|
||||
category.update!(category_required_tag_groups: [CategoryRequiredTagGroup.new(tag_group: tag_group_2, min_count: 1)])
|
||||
category.update!(
|
||||
category_required_tag_groups: [
|
||||
CategoryRequiredTagGroup.new(tag_group: tag_group_2, min_count: 1),
|
||||
],
|
||||
)
|
||||
|
||||
serialized = described_class.new(Site.new(guardian), scope: guardian, root: false).as_json
|
||||
c1 = serialized[:categories].find { |c| c[:id] == category.id }
|
||||
@@ -63,7 +65,7 @@ RSpec.describe SiteSerializer do
|
||||
tag = Fabricate(:tag)
|
||||
tag_group = Fabricate(:tag_group)
|
||||
crtg = CategoryRequiredTagGroup.new(tag_group: tag_group, min_count: 1)
|
||||
category.update!(category_required_tag_groups: [ crtg ])
|
||||
category.update!(category_required_tag_groups: [crtg])
|
||||
|
||||
tag_group.delete # Bypassing hooks like this should never happen in the app
|
||||
|
||||
@@ -109,25 +111,25 @@ RSpec.describe SiteSerializer do
|
||||
scheme = ColorScheme.last
|
||||
SiteSetting.default_dark_mode_color_scheme_id = scheme.id
|
||||
serialized = described_class.new(Site.new(guardian), scope: guardian, root: false).as_json
|
||||
default_dark_scheme =
|
||||
expect(serialized[:default_dark_color_scheme]["name"]).to eq(scheme.name)
|
||||
default_dark_scheme = expect(serialized[:default_dark_color_scheme]["name"]).to eq(scheme.name)
|
||||
|
||||
SiteSetting.default_dark_mode_color_scheme_id = -1
|
||||
serialized = described_class.new(Site.new(guardian), scope: guardian, root: false).as_json
|
||||
expect(serialized[:default_dark_color_scheme]).to eq(nil)
|
||||
end
|
||||
|
||||
it 'does not include shared_drafts_category_id if the category is Uncategorized' do
|
||||
it "does not include shared_drafts_category_id if the category is Uncategorized" do
|
||||
admin = Fabricate(:admin)
|
||||
admin_guardian = Guardian.new(admin)
|
||||
|
||||
SiteSetting.shared_drafts_category = SiteSetting.uncategorized_category_id
|
||||
|
||||
serialized = described_class.new(Site.new(admin_guardian), scope: admin_guardian, root: false).as_json
|
||||
serialized =
|
||||
described_class.new(Site.new(admin_guardian), scope: admin_guardian, root: false).as_json
|
||||
expect(serialized[:shared_drafts_category_id]).to eq(nil)
|
||||
end
|
||||
|
||||
it 'includes show_welcome_topic_banner' do
|
||||
it "includes show_welcome_topic_banner" do
|
||||
admin = Fabricate(:admin)
|
||||
admin_guardian = Guardian.new(admin)
|
||||
UserAuthToken.generate!(user_id: admin.id)
|
||||
@@ -135,16 +137,19 @@ RSpec.describe SiteSerializer do
|
||||
first_post = Fabricate(:post, created_at: 25.days.ago)
|
||||
SiteSetting.welcome_topic_id = first_post.topic.id
|
||||
|
||||
serialized = described_class.new(Site.new(admin_guardian), scope: admin_guardian, root: false).as_json
|
||||
serialized =
|
||||
described_class.new(Site.new(admin_guardian), scope: admin_guardian, root: false).as_json
|
||||
expect(serialized[:show_welcome_topic_banner]).to eq(true)
|
||||
end
|
||||
|
||||
describe '#anonymous_default_sidebar_tags' do
|
||||
describe "#anonymous_default_sidebar_tags" do
|
||||
fab!(:user) { Fabricate(:user) }
|
||||
fab!(:tag) { Fabricate(:tag, name: 'dev') }
|
||||
fab!(:tag2) { Fabricate(:tag, name: 'random') }
|
||||
fab!(:tag) { Fabricate(:tag, name: "dev") }
|
||||
fab!(:tag2) { Fabricate(:tag, name: "random") }
|
||||
fab!(:hidden_tag) { Fabricate(:tag, name: "secret") }
|
||||
fab!(:staff_tag_group) { Fabricate(:tag_group, permissions: { "staff" => 1 }, tag_names: [hidden_tag.name]) }
|
||||
fab!(:staff_tag_group) do
|
||||
Fabricate(:tag_group, permissions: { "staff" => 1 }, tag_names: [hidden_tag.name])
|
||||
end
|
||||
|
||||
before do
|
||||
SiteSetting.navigation_menu = "sidebar"
|
||||
@@ -152,7 +157,7 @@ RSpec.describe SiteSerializer do
|
||||
SiteSetting.default_sidebar_tags = "#{tag.name}|#{tag2.name}|#{hidden_tag.name}"
|
||||
end
|
||||
|
||||
it 'is not included in the serialised object when tagging is not enabled' do
|
||||
it "is not included in the serialised object when tagging is not enabled" do
|
||||
SiteSetting.tagging_enabled = false
|
||||
guardian = Guardian.new(user)
|
||||
|
||||
@@ -160,57 +165,53 @@ RSpec.describe SiteSerializer do
|
||||
expect(serialized[:anonymous_default_sidebar_tags]).to eq(nil)
|
||||
end
|
||||
|
||||
it 'is not included in the serialised object when navigation menu is legacy' do
|
||||
it "is not included in the serialised object when navigation menu is legacy" do
|
||||
SiteSetting.navigation_menu = "legacy"
|
||||
|
||||
serialized = described_class.new(Site.new(guardian), scope: guardian, root: false).as_json
|
||||
expect(serialized[:anonymous_default_sidebar_tags]).to eq(nil)
|
||||
end
|
||||
|
||||
it 'is not included in the serialised object when user is not anonymous' do
|
||||
it "is not included in the serialised object when user is not anonymous" do
|
||||
guardian = Guardian.new(user)
|
||||
|
||||
serialized = described_class.new(Site.new(guardian), scope: guardian, root: false).as_json
|
||||
expect(serialized[:anonymous_default_sidebar_tags]).to eq(nil)
|
||||
end
|
||||
|
||||
it 'is not included in the serialisd object when default sidebar tags have not been configured' do
|
||||
it "is not included in the serialisd object when default sidebar tags have not been configured" do
|
||||
SiteSetting.default_sidebar_tags = ""
|
||||
|
||||
serialized = described_class.new(Site.new(guardian), scope: guardian, root: false).as_json
|
||||
expect(serialized[:anonymous_default_sidebar_tags]).to eq(nil)
|
||||
end
|
||||
|
||||
it 'includes only tags user can see in the serialised object when user is anonymous' do
|
||||
it "includes only tags user can see in the serialised object when user is anonymous" do
|
||||
serialized = described_class.new(Site.new(guardian), scope: guardian, root: false).as_json
|
||||
expect(serialized[:anonymous_default_sidebar_tags]).to eq(["dev", "random"])
|
||||
expect(serialized[:anonymous_default_sidebar_tags]).to eq(%w[dev random])
|
||||
end
|
||||
end
|
||||
|
||||
describe '#top_tags' do
|
||||
describe "#top_tags" do
|
||||
fab!(:tag) { Fabricate(:tag) }
|
||||
|
||||
describe 'when tagging is not enabled' do
|
||||
before do
|
||||
SiteSetting.tagging_enabled = false
|
||||
end
|
||||
describe "when tagging is not enabled" do
|
||||
before { SiteSetting.tagging_enabled = false }
|
||||
|
||||
it 'is not included in the serialised object' do
|
||||
it "is not included in the serialised object" do
|
||||
serialized = described_class.new(Site.new(guardian), scope: guardian, root: false).as_json
|
||||
|
||||
expect(serialized[:top_tags]).to eq(nil)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'when tagging is enabled' do
|
||||
describe "when tagging is enabled" do
|
||||
fab!(:tag2) { Fabricate(:tag) }
|
||||
fab!(:tag3) { Fabricate(:tag) }
|
||||
|
||||
before do
|
||||
SiteSetting.tagging_enabled = true
|
||||
end
|
||||
before { SiteSetting.tagging_enabled = true }
|
||||
|
||||
it 'is not included in the serialised object when there are no tags' do
|
||||
it "is not included in the serialised object when there are no tags" do
|
||||
tag.destroy!
|
||||
|
||||
serialized = described_class.new(Site.new(guardian), scope: guardian, root: false).as_json
|
||||
@@ -218,15 +219,27 @@ RSpec.describe SiteSerializer do
|
||||
expect(serialized[:top_tags]).to eq([])
|
||||
end
|
||||
|
||||
it 'is included in the serialised object containing the top tags' do
|
||||
it "is included in the serialised object containing the top tags" do
|
||||
tag2 = Fabricate(:tag)
|
||||
tag2 = Fabricate(:tag)
|
||||
|
||||
SiteSetting.max_tags_in_filter_list = 1
|
||||
|
||||
CategoryTagStat.create!(category_id: SiteSetting.uncategorized_category_id, tag_id: tag2.id, topic_count: 2)
|
||||
CategoryTagStat.create!(category_id: SiteSetting.uncategorized_category_id, tag_id: tag.id, topic_count: 1)
|
||||
CategoryTagStat.create!(category_id: SiteSetting.uncategorized_category_id, tag_id: tag3.id, topic_count: 5)
|
||||
CategoryTagStat.create!(
|
||||
category_id: SiteSetting.uncategorized_category_id,
|
||||
tag_id: tag2.id,
|
||||
topic_count: 2,
|
||||
)
|
||||
CategoryTagStat.create!(
|
||||
category_id: SiteSetting.uncategorized_category_id,
|
||||
tag_id: tag.id,
|
||||
topic_count: 1,
|
||||
)
|
||||
CategoryTagStat.create!(
|
||||
category_id: SiteSetting.uncategorized_category_id,
|
||||
tag_id: tag3.id,
|
||||
topic_count: 5,
|
||||
)
|
||||
|
||||
serialized = described_class.new(Site.new(guardian), scope: guardian, root: false).as_json
|
||||
|
||||
@@ -235,42 +248,57 @@ RSpec.describe SiteSerializer do
|
||||
end
|
||||
end
|
||||
|
||||
describe '#whispers_allowed_groups_names' do
|
||||
describe "#whispers_allowed_groups_names" do
|
||||
fab!(:admin) { Fabricate(:admin) }
|
||||
fab!(:allowed_user) { Fabricate(:user) }
|
||||
fab!(:not_allowed_user) { Fabricate(:user) }
|
||||
fab!(:group1) { Fabricate(:group, name: 'whisperers1', users: [allowed_user]) }
|
||||
fab!(:group2) { Fabricate(:group, name: 'whisperers2', users: [allowed_user]) }
|
||||
fab!(:group1) { Fabricate(:group, name: "whisperers1", users: [allowed_user]) }
|
||||
fab!(:group2) { Fabricate(:group, name: "whisperers2", users: [allowed_user]) }
|
||||
|
||||
it "returns correct group names for created groups" do
|
||||
admin_guardian = Guardian.new(admin)
|
||||
SiteSetting.whispers_allowed_groups = "#{group1.id}|#{group2.id}"
|
||||
|
||||
serialized = described_class.new(Site.new(admin_guardian), scope: admin_guardian, root: false).as_json
|
||||
expect(serialized[:whispers_allowed_groups_names]).to contain_exactly("whisperers1", "whisperers2")
|
||||
serialized =
|
||||
described_class.new(Site.new(admin_guardian), scope: admin_guardian, root: false).as_json
|
||||
expect(serialized[:whispers_allowed_groups_names]).to contain_exactly(
|
||||
"whisperers1",
|
||||
"whisperers2",
|
||||
)
|
||||
end
|
||||
|
||||
it "returns correct group names for automatic groups" do
|
||||
admin_guardian = Guardian.new(admin)
|
||||
SiteSetting.whispers_allowed_groups = "#{Group::AUTO_GROUPS[:staff]}|#{Group::AUTO_GROUPS[:trust_level_4]}"
|
||||
SiteSetting.whispers_allowed_groups =
|
||||
"#{Group::AUTO_GROUPS[:staff]}|#{Group::AUTO_GROUPS[:trust_level_4]}"
|
||||
|
||||
serialized = described_class.new(Site.new(admin_guardian), scope: admin_guardian, root: false).as_json
|
||||
expect(serialized[:whispers_allowed_groups_names]).to contain_exactly("trust_level_4", "staff")
|
||||
serialized =
|
||||
described_class.new(Site.new(admin_guardian), scope: admin_guardian, root: false).as_json
|
||||
expect(serialized[:whispers_allowed_groups_names]).to contain_exactly(
|
||||
"trust_level_4",
|
||||
"staff",
|
||||
)
|
||||
end
|
||||
|
||||
it "returns group names when user is allowed to whisper" do
|
||||
user_guardian = Guardian.new(allowed_user)
|
||||
SiteSetting.whispers_allowed_groups = "#{group1.id}|#{group2.id}"
|
||||
|
||||
serialized = described_class.new(Site.new(user_guardian), scope: user_guardian, root: false).as_json
|
||||
expect(serialized[:whispers_allowed_groups_names]).to contain_exactly("whisperers1", "whisperers2")
|
||||
serialized =
|
||||
described_class.new(Site.new(user_guardian), scope: user_guardian, root: false).as_json
|
||||
expect(serialized[:whispers_allowed_groups_names]).to contain_exactly(
|
||||
"whisperers1",
|
||||
"whisperers2",
|
||||
)
|
||||
end
|
||||
|
||||
it "returns nil when user is not allowed to whisper" do
|
||||
user_guardian = Guardian.new(not_allowed_user)
|
||||
SiteSetting.whispers_allowed_groups = "#{Group::AUTO_GROUPS[:staff]}|#{Group::AUTO_GROUPS[:trust_level_4]}"
|
||||
SiteSetting.whispers_allowed_groups =
|
||||
"#{Group::AUTO_GROUPS[:staff]}|#{Group::AUTO_GROUPS[:trust_level_4]}"
|
||||
|
||||
serialized = described_class.new(Site.new(user_guardian), scope: user_guardian, root: false).as_json
|
||||
serialized =
|
||||
described_class.new(Site.new(user_guardian), scope: user_guardian, root: false).as_json
|
||||
expect(serialized[:whispers_allowed_groups_names]).to eq(nil)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -4,40 +4,48 @@ RSpec.describe SuggestedTopicSerializer do
|
||||
let(:user) { Fabricate(:user) }
|
||||
let(:admin) { Fabricate(:admin) }
|
||||
|
||||
describe '#featured_link and #featured_link_root_domain' do
|
||||
let(:featured_link) { 'http://meta.discourse.org' }
|
||||
let(:topic) { Fabricate(:topic, featured_link: featured_link, category: Fabricate(:category, topic_featured_link_allowed: true)) }
|
||||
subject(:json) { SuggestedTopicSerializer.new(topic, scope: Guardian.new(user), root: false).as_json }
|
||||
describe "#featured_link and #featured_link_root_domain" do
|
||||
let(:featured_link) { "http://meta.discourse.org" }
|
||||
let(:topic) do
|
||||
Fabricate(
|
||||
:topic,
|
||||
featured_link: featured_link,
|
||||
category: Fabricate(:category, topic_featured_link_allowed: true),
|
||||
)
|
||||
end
|
||||
subject(:json) do
|
||||
SuggestedTopicSerializer.new(topic, scope: Guardian.new(user), root: false).as_json
|
||||
end
|
||||
|
||||
context 'when topic featured link is disable' do
|
||||
context "when topic featured link is disable" do
|
||||
before do
|
||||
SiteSetting.topic_featured_link_enabled = true
|
||||
topic
|
||||
SiteSetting.topic_featured_link_enabled = false
|
||||
end
|
||||
|
||||
it 'should not return featured link attrs' do
|
||||
it "should not return featured link attrs" do
|
||||
expect(json[:featured_link]).to eq(nil)
|
||||
expect(json[:featured_link_root_domain]).to eq(nil)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when topic featured link is enabled' do
|
||||
before do
|
||||
SiteSetting.topic_featured_link_enabled = true
|
||||
end
|
||||
context "when topic featured link is enabled" do
|
||||
before { SiteSetting.topic_featured_link_enabled = true }
|
||||
|
||||
it 'should return featured link attrs' do
|
||||
it "should return featured link attrs" do
|
||||
expect(json[:featured_link]).to eq(featured_link)
|
||||
expect(json[:featured_link_root_domain]).to eq('discourse.org')
|
||||
expect(json[:featured_link_root_domain]).to eq("discourse.org")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'hidden tags' do
|
||||
describe "hidden tags" do
|
||||
let(:topic) { Fabricate(:topic) }
|
||||
let(:hidden_tag) { Fabricate(:tag, name: 'hidden') }
|
||||
let(:staff_tag_group) { Fabricate(:tag_group, permissions: { "staff" => 1 }, tag_names: [hidden_tag.name]) }
|
||||
let(:hidden_tag) { Fabricate(:tag, name: "hidden") }
|
||||
let(:staff_tag_group) do
|
||||
Fabricate(:tag_group, permissions: { "staff" => 1 }, tag_names: [hidden_tag.name])
|
||||
end
|
||||
|
||||
before do
|
||||
SiteSetting.tagging_enabled = true
|
||||
@@ -45,12 +53,12 @@ RSpec.describe SuggestedTopicSerializer do
|
||||
topic.tags << hidden_tag
|
||||
end
|
||||
|
||||
it 'returns hidden tag to staff' do
|
||||
it "returns hidden tag to staff" do
|
||||
json = SuggestedTopicSerializer.new(topic, scope: Guardian.new(admin), root: false).as_json
|
||||
expect(json[:tags]).to eq([hidden_tag.name])
|
||||
end
|
||||
|
||||
it 'does not return hidden tag to non-staff' do
|
||||
it "does not return hidden tag to non-staff" do
|
||||
json = SuggestedTopicSerializer.new(topic, scope: Guardian.new(user), root: false).as_json
|
||||
expect(json[:tags]).to eq([])
|
||||
end
|
||||
|
||||
@@ -1,16 +1,14 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
RSpec.describe TagGroupSerializer do
|
||||
|
||||
it "doesn't translate automatic group names in permissions" do
|
||||
staff_group = Group.find(Group::AUTO_GROUPS[:staff])
|
||||
staff_group.update_columns(name: "custom")
|
||||
|
||||
tag_group = Fabricate(:tag_group)
|
||||
tag_group.permissions = [[
|
||||
Group::AUTO_GROUPS[:staff],
|
||||
TagGroupPermission.permission_types[:full]
|
||||
]]
|
||||
tag_group.permissions = [
|
||||
[Group::AUTO_GROUPS[:staff], TagGroupPermission.permission_types[:full]],
|
||||
]
|
||||
tag_group.save!
|
||||
|
||||
serialized = TagGroupSerializer.new(tag_group, root: false).as_json
|
||||
@@ -25,5 +23,4 @@ RSpec.describe TagGroupSerializer do
|
||||
serialized = TagGroupSerializer.new(tag_group, root: false).as_json
|
||||
expect(serialized[:tag_names]).to eq([tag.name])
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -2,16 +2,19 @@
|
||||
|
||||
RSpec.describe ThemeSerializer do
|
||||
describe "load theme settings" do
|
||||
it 'should add error message when settings format is invalid' do
|
||||
it "should add error message when settings format is invalid" do
|
||||
theme = Fabricate(:theme)
|
||||
Theme.any_instance.stubs(:settings).raises(ThemeSettingsParser::InvalidYaml, I18n.t("themes.settings_errors.invalid_yaml"))
|
||||
Theme
|
||||
.any_instance
|
||||
.stubs(:settings)
|
||||
.raises(ThemeSettingsParser::InvalidYaml, I18n.t("themes.settings_errors.invalid_yaml"))
|
||||
serialized = ThemeSerializer.new(theme).as_json[:theme]
|
||||
expect(serialized[:settings]).to be_nil
|
||||
expect(serialized[:errors].count).to eq(1)
|
||||
expect(serialized[:errors][0]).to eq(I18n.t("themes.settings_errors.invalid_yaml"))
|
||||
end
|
||||
|
||||
it 'should add errors messages from theme fields' do
|
||||
it "should add errors messages from theme fields" do
|
||||
error = "error when compiling theme field"
|
||||
theme = Fabricate(:theme)
|
||||
theme_field = Fabricate(:theme_field, error: error, theme: theme)
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
RSpec.describe TopicLinkSerializer do
|
||||
|
||||
it "correctly serializes the topic link" do
|
||||
post = Fabricate(:post, raw: 'https://meta.discourse.org/')
|
||||
post = Fabricate(:post, raw: "https://meta.discourse.org/")
|
||||
TopicLink.extract_from(post)
|
||||
serialized = described_class.new(post.topic_links.first, root: false).as_json
|
||||
|
||||
|
||||
@@ -4,10 +4,11 @@ RSpec.describe TopicListItemSerializer do
|
||||
let(:topic) do
|
||||
date = Time.zone.now
|
||||
|
||||
Fabricate(:topic,
|
||||
title: 'This is a test topic title',
|
||||
Fabricate(
|
||||
:topic,
|
||||
title: "This is a test topic title",
|
||||
created_at: date - 2.minutes,
|
||||
bumped_at: date
|
||||
bumped_at: date,
|
||||
)
|
||||
end
|
||||
|
||||
@@ -20,21 +21,19 @@ RSpec.describe TopicListItemSerializer do
|
||||
expect(serialized[:featured_link]).to eq(nil)
|
||||
expect(serialized[:featured_link_root_domain]).to eq(nil)
|
||||
|
||||
featured_link = 'http://meta.discourse.org'
|
||||
featured_link = "http://meta.discourse.org"
|
||||
topic.featured_link = featured_link
|
||||
serialized = TopicListItemSerializer.new(topic, scope: Guardian.new, root: false).as_json
|
||||
|
||||
expect(serialized[:featured_link]).to eq(featured_link)
|
||||
expect(serialized[:featured_link_root_domain]).to eq('discourse.org')
|
||||
expect(serialized[:featured_link_root_domain]).to eq("discourse.org")
|
||||
end
|
||||
|
||||
describe 'when topic featured link is disable' do
|
||||
before do
|
||||
SiteSetting.topic_featured_link_enabled = false
|
||||
end
|
||||
describe "when topic featured link is disable" do
|
||||
before { SiteSetting.topic_featured_link_enabled = false }
|
||||
|
||||
it "should not include the topic's featured link" do
|
||||
topic.featured_link = 'http://meta.discourse.org'
|
||||
topic.featured_link = "http://meta.discourse.org"
|
||||
serialized = TopicListItemSerializer.new(topic, scope: Guardian.new, root: false).as_json
|
||||
|
||||
expect(serialized[:featured_link]).to eq(nil)
|
||||
@@ -42,11 +41,13 @@ RSpec.describe TopicListItemSerializer do
|
||||
end
|
||||
end
|
||||
|
||||
describe 'hidden tags' do
|
||||
describe "hidden tags" do
|
||||
let(:admin) { Fabricate(:admin) }
|
||||
let(:user) { Fabricate(:user) }
|
||||
let(:hidden_tag) { Fabricate(:tag, name: 'hidden') }
|
||||
let(:staff_tag_group) { Fabricate(:tag_group, permissions: { "staff" => 1 }, tag_names: [hidden_tag.name]) }
|
||||
let(:hidden_tag) { Fabricate(:tag, name: "hidden") }
|
||||
let(:staff_tag_group) do
|
||||
Fabricate(:tag_group, permissions: { "staff" => 1 }, tag_names: [hidden_tag.name])
|
||||
end
|
||||
|
||||
before do
|
||||
SiteSetting.tagging_enabled = true
|
||||
@@ -54,40 +55,38 @@ RSpec.describe TopicListItemSerializer do
|
||||
topic.tags << hidden_tag
|
||||
end
|
||||
|
||||
it 'returns hidden tag to staff' do
|
||||
json = TopicListItemSerializer.new(topic,
|
||||
scope: Guardian.new(admin),
|
||||
root: false
|
||||
).as_json
|
||||
it "returns hidden tag to staff" do
|
||||
json = TopicListItemSerializer.new(topic, scope: Guardian.new(admin), root: false).as_json
|
||||
|
||||
expect(json[:tags]).to eq([hidden_tag.name])
|
||||
end
|
||||
|
||||
it 'does not return hidden tag to non-staff' do
|
||||
json = TopicListItemSerializer.new(topic,
|
||||
scope: Guardian.new(user),
|
||||
root: false
|
||||
).as_json
|
||||
it "does not return hidden tag to non-staff" do
|
||||
json = TopicListItemSerializer.new(topic, scope: Guardian.new(user), root: false).as_json
|
||||
|
||||
expect(json[:tags]).to eq([])
|
||||
end
|
||||
|
||||
it 'accepts an option to remove hidden tags' do
|
||||
json = TopicListItemSerializer.new(topic,
|
||||
scope: Guardian.new(user),
|
||||
hidden_tag_names: [hidden_tag.name],
|
||||
root: false
|
||||
).as_json
|
||||
it "accepts an option to remove hidden tags" do
|
||||
json =
|
||||
TopicListItemSerializer.new(
|
||||
topic,
|
||||
scope: Guardian.new(user),
|
||||
hidden_tag_names: [hidden_tag.name],
|
||||
root: false,
|
||||
).as_json
|
||||
|
||||
expect(json[:tags]).to eq([])
|
||||
end
|
||||
|
||||
it 'return posters' do
|
||||
json = TopicListItemSerializer.new(topic,
|
||||
scope: Guardian.new(user),
|
||||
hidden_tag_names: [hidden_tag.name],
|
||||
root: false
|
||||
).as_json
|
||||
it "return posters" do
|
||||
json =
|
||||
TopicListItemSerializer.new(
|
||||
topic,
|
||||
scope: Guardian.new(user),
|
||||
hidden_tag_names: [hidden_tag.name],
|
||||
root: false,
|
||||
).as_json
|
||||
|
||||
expect(json[:posters].length).to eq(1)
|
||||
end
|
||||
|
||||
@@ -3,18 +3,12 @@
|
||||
RSpec.describe TopicListSerializer do
|
||||
fab!(:user) { Fabricate(:user) }
|
||||
|
||||
let(:topic) do
|
||||
Fabricate(:topic).tap do |t|
|
||||
t.allowed_user_ids = [t.user_id]
|
||||
end
|
||||
end
|
||||
let(:topic) { Fabricate(:topic).tap { |t| t.allowed_user_ids = [t.user_id] } }
|
||||
|
||||
it 'should return the right payload' do
|
||||
it "should return the right payload" do
|
||||
topic_list = TopicList.new(nil, user, [topic])
|
||||
|
||||
serialized = described_class.new(topic_list,
|
||||
scope: Guardian.new(user)
|
||||
).as_json
|
||||
serialized = described_class.new(topic_list, scope: Guardian.new(user)).as_json
|
||||
|
||||
expect(serialized[:users].first[:id]).to eq(topic.user_id)
|
||||
expect(serialized[:primary_groups]).to eq([])
|
||||
|
||||
@@ -9,7 +9,7 @@ RSpec.describe TopicTrackingStateSerializer do
|
||||
SiteSetting.chat_enabled = false if defined?(::Chat)
|
||||
end
|
||||
|
||||
it 'serializes topic tracking state reports' do
|
||||
it "serializes topic tracking state reports" do
|
||||
report = TopicTrackingState.report(user)
|
||||
serialized = described_class.new(report[0], scope: Guardian.new(user), root: false).as_json
|
||||
|
||||
@@ -31,7 +31,7 @@ RSpec.describe TopicTrackingStateSerializer do
|
||||
DiscourseTagging.tag_topic_by_names(
|
||||
post.topic,
|
||||
Guardian.new(Discourse.system_user),
|
||||
['bananas', 'apples']
|
||||
%w[bananas apples],
|
||||
)
|
||||
|
||||
report = TopicTrackingState.report(user)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
RSpec.describe TopicViewDetailsSerializer do
|
||||
describe '#allowed_users' do
|
||||
describe "#allowed_users" do
|
||||
it "add the current user to the allowed user's list even if they are an allowed group member" do
|
||||
participant = Fabricate(:user)
|
||||
another_participant = Fabricate(:user)
|
||||
@@ -10,15 +10,18 @@ RSpec.describe TopicViewDetailsSerializer do
|
||||
participant_group.add(participant)
|
||||
participant_group.add(another_participant)
|
||||
|
||||
pm = Fabricate(:private_message_topic,
|
||||
topic_allowed_users: [
|
||||
Fabricate.build(:topic_allowed_user, user: participant),
|
||||
Fabricate.build(:topic_allowed_user, user: another_participant)
|
||||
],
|
||||
topic_allowed_groups: [Fabricate.build(:topic_allowed_group, group: participant_group)]
|
||||
)
|
||||
pm =
|
||||
Fabricate(
|
||||
:private_message_topic,
|
||||
topic_allowed_users: [
|
||||
Fabricate.build(:topic_allowed_user, user: participant),
|
||||
Fabricate.build(:topic_allowed_user, user: another_participant),
|
||||
],
|
||||
topic_allowed_groups: [Fabricate.build(:topic_allowed_group, group: participant_group)],
|
||||
)
|
||||
|
||||
serializer = described_class.new(TopicView.new(pm, participant), scope: Guardian.new(participant))
|
||||
serializer =
|
||||
described_class.new(TopicView.new(pm, participant), scope: Guardian.new(participant))
|
||||
allowed_users = serializer.as_json.dig(:topic_view_details, :allowed_users).map { |u| u[:id] }
|
||||
|
||||
expect(allowed_users).to contain_exactly(participant.id)
|
||||
@@ -27,14 +30,10 @@ RSpec.describe TopicViewDetailsSerializer do
|
||||
|
||||
describe "#can_permanently_delete" do
|
||||
let(:post) do
|
||||
Fabricate(:post).tap do |post|
|
||||
PostDestroyer.new(Discourse.system_user, post).destroy
|
||||
end
|
||||
Fabricate(:post).tap { |post| PostDestroyer.new(Discourse.system_user, post).destroy }
|
||||
end
|
||||
|
||||
before do
|
||||
SiteSetting.can_permanently_delete = true
|
||||
end
|
||||
before { SiteSetting.can_permanently_delete = true }
|
||||
|
||||
it "is true for admins" do
|
||||
admin = Fabricate(:admin)
|
||||
@@ -46,7 +45,8 @@ RSpec.describe TopicViewDetailsSerializer do
|
||||
it "is not present for moderators" do
|
||||
moderator = Fabricate(:moderator)
|
||||
|
||||
serializer = described_class.new(TopicView.new(post.topic, moderator), scope: Guardian.new(moderator))
|
||||
serializer =
|
||||
described_class.new(TopicView.new(post.topic, moderator), scope: Guardian.new(moderator))
|
||||
expect(serializer.as_json.dig(:topic_view_details, :can_permanently_delete)).to eq(nil)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,28 +1,35 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
RSpec.describe TopicViewPostsSerializer do
|
||||
|
||||
let(:user) { Fabricate(:user) }
|
||||
let(:post) { Fabricate(:post) }
|
||||
let(:topic) { post.topic }
|
||||
let!(:reviewable) { Fabricate(:reviewable_flagged_post,
|
||||
created_by: user,
|
||||
target: post,
|
||||
topic: topic,
|
||||
reviewable_scores: [
|
||||
Fabricate(:reviewable_score, reviewable_score_type: 0, status: ReviewableScore.statuses[:pending]),
|
||||
Fabricate(:reviewable_score, reviewable_score_type: 0, status: ReviewableScore.statuses[:ignored])
|
||||
]
|
||||
)}
|
||||
let!(:reviewable) do
|
||||
Fabricate(
|
||||
:reviewable_flagged_post,
|
||||
created_by: user,
|
||||
target: post,
|
||||
topic: topic,
|
||||
reviewable_scores: [
|
||||
Fabricate(
|
||||
:reviewable_score,
|
||||
reviewable_score_type: 0,
|
||||
status: ReviewableScore.statuses[:pending],
|
||||
),
|
||||
Fabricate(
|
||||
:reviewable_score,
|
||||
reviewable_score_type: 0,
|
||||
status: ReviewableScore.statuses[:ignored],
|
||||
),
|
||||
],
|
||||
)
|
||||
end
|
||||
|
||||
it 'should return the right attributes' do
|
||||
it "should return the right attributes" do
|
||||
topic_view = TopicView.new(topic, user, post_ids: [post.id])
|
||||
|
||||
serializer = TopicViewPostsSerializer.new(
|
||||
topic_view,
|
||||
scope: Guardian.new(Fabricate(:admin)),
|
||||
root: false
|
||||
)
|
||||
serializer =
|
||||
TopicViewPostsSerializer.new(topic_view, scope: Guardian.new(Fabricate(:admin)), root: false)
|
||||
|
||||
body = JSON.parse(serializer.to_json)
|
||||
|
||||
@@ -37,6 +44,5 @@ RSpec.describe TopicViewPostsSerializer do
|
||||
expect(body["post_stream"]["stream"]).to eq(nil)
|
||||
expect(body["post_stream"]["timeline_lookup"]).to eq(nil)
|
||||
expect(body["post_stream"]["gaps"]).to eq(nil)
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
@@ -3,7 +3,8 @@
|
||||
RSpec.describe TopicViewSerializer do
|
||||
def serialize_topic(topic, user_arg)
|
||||
topic_view = TopicView.new(topic.id, user_arg)
|
||||
serializer = TopicViewSerializer.new(topic_view, scope: Guardian.new(user_arg), root: false).as_json
|
||||
serializer =
|
||||
TopicViewSerializer.new(topic_view, scope: Guardian.new(user_arg), root: false).as_json
|
||||
JSON.parse(MultiJson.dump(serializer)).deep_symbolize_keys!
|
||||
end
|
||||
|
||||
@@ -17,11 +18,11 @@ RSpec.describe TopicViewSerializer do
|
||||
fab!(:user_2) { Fabricate(:user) }
|
||||
fab!(:admin) { Fabricate(:admin) }
|
||||
|
||||
describe '#featured_link and #featured_link_root_domain' do
|
||||
fab!(:featured_link) { 'http://meta.discourse.org' }
|
||||
describe "#featured_link and #featured_link_root_domain" do
|
||||
fab!(:featured_link) { "http://meta.discourse.org" }
|
||||
|
||||
describe 'when topic featured link is disable' do
|
||||
it 'should return the right attributes' do
|
||||
describe "when topic featured link is disable" do
|
||||
it "should return the right attributes" do
|
||||
topic.update!(featured_link: featured_link)
|
||||
SiteSetting.topic_featured_link_enabled = false
|
||||
|
||||
@@ -32,62 +33,61 @@ RSpec.describe TopicViewSerializer do
|
||||
end
|
||||
end
|
||||
|
||||
describe 'when topic featured link is enabled' do
|
||||
it 'should return the right attributes' do
|
||||
describe "when topic featured link is enabled" do
|
||||
it "should return the right attributes" do
|
||||
topic.update!(featured_link: featured_link)
|
||||
|
||||
json = serialize_topic(topic, user)
|
||||
|
||||
expect(json[:featured_link]).to eq(featured_link)
|
||||
expect(json[:featured_link_root_domain]).to eq('discourse.org')
|
||||
expect(json[:featured_link_root_domain]).to eq("discourse.org")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#external_id' do
|
||||
describe 'when a topic has an external_id' do
|
||||
before { topic.update!(external_id: '42-asdf') }
|
||||
describe "#external_id" do
|
||||
describe "when a topic has an external_id" do
|
||||
before { topic.update!(external_id: "42-asdf") }
|
||||
|
||||
it 'should return the external_id' do
|
||||
it "should return the external_id" do
|
||||
json = serialize_topic(topic, user)
|
||||
expect(json[:external_id]).to eq('42-asdf')
|
||||
expect(json[:external_id]).to eq("42-asdf")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#image_url' do
|
||||
describe "#image_url" do
|
||||
fab!(:image_upload) { Fabricate(:image_upload, width: 5000, height: 5000) }
|
||||
|
||||
describe 'when a topic has an image' do
|
||||
describe "when a topic has an image" do
|
||||
before { topic.update!(image_upload_id: image_upload.id) }
|
||||
|
||||
it 'should return the image url' do
|
||||
it "should return the image url" do
|
||||
json = serialize_topic(topic, user)
|
||||
|
||||
expect(json[:image_url]).to end_with(image_upload.url)
|
||||
end
|
||||
|
||||
it 'should have thumbnail jobs enqueued' do
|
||||
it "should have thumbnail jobs enqueued" do
|
||||
SiteSetting.create_thumbnails = true
|
||||
|
||||
Discourse.redis.del(topic.thumbnail_job_redis_key([]))
|
||||
json = nil
|
||||
|
||||
expect do
|
||||
json = serialize_topic(topic, user)
|
||||
end.to change { Jobs::GenerateTopicThumbnails.jobs.size }.by(1)
|
||||
expect do json = serialize_topic(topic, user) end.to change {
|
||||
Jobs::GenerateTopicThumbnails.jobs.size
|
||||
}.by(1)
|
||||
|
||||
topic.generate_thumbnails!
|
||||
|
||||
expect do
|
||||
json = serialize_topic(topic, user)
|
||||
end.not_to change { Jobs::GenerateTopicThumbnails.jobs.size }
|
||||
expect do json = serialize_topic(topic, user) end.not_to change {
|
||||
Jobs::GenerateTopicThumbnails.jobs.size
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
describe 'when a topic does not contain an image' do
|
||||
it 'should return a nil image url' do
|
||||
|
||||
describe "when a topic does not contain an image" do
|
||||
it "should return a nil image url" do
|
||||
json = serialize_topic(topic, user)
|
||||
|
||||
expect(json.has_key? :image_url).to eq(true)
|
||||
@@ -96,30 +96,26 @@ RSpec.describe TopicViewSerializer do
|
||||
end
|
||||
end
|
||||
|
||||
describe '#suggested_topics' do
|
||||
before do
|
||||
Group.refresh_automatic_groups!
|
||||
end
|
||||
describe "#suggested_topics" do
|
||||
before { Group.refresh_automatic_groups! }
|
||||
|
||||
fab!(:topic2) { Fabricate(:topic) }
|
||||
|
||||
before do
|
||||
TopicUser.update_last_read(user, topic2.id, 0, 0, 0)
|
||||
end
|
||||
before { TopicUser.update_last_read(user, topic2.id, 0, 0, 0) }
|
||||
|
||||
describe 'when loading last chunk' do
|
||||
it 'should include suggested topics' do
|
||||
describe "when loading last chunk" do
|
||||
it "should include suggested topics" do
|
||||
json = serialize_topic(topic, user)
|
||||
|
||||
expect(json[:suggested_topics].first[:id]).to eq(topic2.id)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'when not loading last chunk' do
|
||||
describe "when not loading last chunk" do
|
||||
fab!(:post) { Fabricate(:post, topic: topic) }
|
||||
fab!(:post2) { Fabricate(:post, topic: topic) }
|
||||
|
||||
it 'should not include suggested topics' do
|
||||
it "should not include suggested topics" do
|
||||
post
|
||||
post2
|
||||
topic_view = TopicView.new(topic.id, user, post_ids: [post.id])
|
||||
@@ -130,37 +126,37 @@ RSpec.describe TopicViewSerializer do
|
||||
end
|
||||
end
|
||||
|
||||
describe 'with private messages' do
|
||||
before do
|
||||
Group.refresh_automatic_groups!
|
||||
end
|
||||
describe "with private messages" do
|
||||
before { Group.refresh_automatic_groups! }
|
||||
|
||||
fab!(:topic) do
|
||||
Fabricate(:private_message_topic,
|
||||
Fabricate(
|
||||
:private_message_topic,
|
||||
highest_post_number: 1,
|
||||
topic_allowed_users: [
|
||||
Fabricate.build(:topic_allowed_user, user: user)
|
||||
]
|
||||
topic_allowed_users: [Fabricate.build(:topic_allowed_user, user: user)],
|
||||
)
|
||||
end
|
||||
|
||||
fab!(:topic2) do
|
||||
Fabricate(:private_message_topic,
|
||||
Fabricate(
|
||||
:private_message_topic,
|
||||
highest_post_number: 1,
|
||||
topic_allowed_users: [
|
||||
Fabricate.build(:topic_allowed_user, user: user)
|
||||
]
|
||||
topic_allowed_users: [Fabricate.build(:topic_allowed_user, user: user)],
|
||||
)
|
||||
end
|
||||
|
||||
it 'includes suggested topics' do
|
||||
TopicUser.change(user, topic2.id, notification_level: TopicUser.notification_levels[:tracking])
|
||||
it "includes suggested topics" do
|
||||
TopicUser.change(
|
||||
user,
|
||||
topic2.id,
|
||||
notification_level: TopicUser.notification_levels[:tracking],
|
||||
)
|
||||
|
||||
json = serialize_topic(topic, user)
|
||||
expect(json[:suggested_topics].map { |t| t[:id] }).to contain_exactly(topic2.id)
|
||||
end
|
||||
|
||||
it 'does not include suggested topics if all PMs are read' do
|
||||
it "does not include suggested topics if all PMs are read" do
|
||||
TopicUser.update_last_read(user, topic2.id, 1, 1, 0)
|
||||
|
||||
json = serialize_topic(topic, user)
|
||||
@@ -169,21 +165,19 @@ RSpec.describe TopicViewSerializer do
|
||||
end
|
||||
end
|
||||
|
||||
describe '#suggested_group_name' do
|
||||
describe "#suggested_group_name" do
|
||||
fab!(:pm) { Fabricate(:private_message_post).topic }
|
||||
fab!(:group) { Fabricate(:group) }
|
||||
|
||||
before do
|
||||
Group.refresh_automatic_groups!
|
||||
end
|
||||
before { Group.refresh_automatic_groups! }
|
||||
|
||||
it 'is nil for a regular topic' do
|
||||
it "is nil for a regular topic" do
|
||||
json = serialize_topic(topic, user)
|
||||
|
||||
expect(json[:suggested_group_name]).to eq(nil)
|
||||
end
|
||||
|
||||
it 'is nil if user is an allowed user of the private message' do
|
||||
it "is nil if user is an allowed user of the private message" do
|
||||
pm.allowed_users << user
|
||||
|
||||
json = serialize_topic(pm, user)
|
||||
@@ -191,7 +185,7 @@ RSpec.describe TopicViewSerializer do
|
||||
expect(json[:suggested_group_name]).to eq(nil)
|
||||
end
|
||||
|
||||
it 'returns the right group name if user is part of allowed group in the private message' do
|
||||
it "returns the right group name if user is part of allowed group in the private message" do
|
||||
pm.allowed_groups << group
|
||||
group.add(user)
|
||||
|
||||
@@ -201,22 +195,30 @@ RSpec.describe TopicViewSerializer do
|
||||
end
|
||||
end
|
||||
|
||||
describe 'when tags added to private message topics' do
|
||||
describe "when tags added to private message topics" do
|
||||
fab!(:moderator) { Fabricate(:moderator) }
|
||||
fab!(:tag) { Fabricate(:tag) }
|
||||
fab!(:pm) do
|
||||
Fabricate(:private_message_topic, tags: [tag], topic_allowed_users: [
|
||||
Fabricate.build(:topic_allowed_user, user: moderator),
|
||||
Fabricate.build(:topic_allowed_user, user: user)
|
||||
])
|
||||
Fabricate(
|
||||
:private_message_topic,
|
||||
tags: [tag],
|
||||
topic_allowed_users: [
|
||||
Fabricate.build(:topic_allowed_user, user: moderator),
|
||||
Fabricate.build(:topic_allowed_user, user: user),
|
||||
],
|
||||
)
|
||||
end
|
||||
|
||||
fab!(:group) { Fabricate(:group) }
|
||||
fab!(:pm_between_reg_users) do
|
||||
Fabricate(:private_message_topic, tags: [tag], topic_allowed_users: [
|
||||
Fabricate.build(:topic_allowed_user, user: user),
|
||||
Fabricate.build(:topic_allowed_user, user: user_2)
|
||||
])
|
||||
Fabricate(
|
||||
:private_message_topic,
|
||||
tags: [tag],
|
||||
topic_allowed_users: [
|
||||
Fabricate.build(:topic_allowed_user, user: user),
|
||||
Fabricate.build(:topic_allowed_user, user: user_2),
|
||||
],
|
||||
)
|
||||
end
|
||||
|
||||
before do
|
||||
@@ -257,29 +259,29 @@ RSpec.describe TopicViewSerializer do
|
||||
end
|
||||
end
|
||||
|
||||
describe 'with hidden tags' do
|
||||
fab!(:hidden_tag) { Fabricate(:tag, name: 'hidden') }
|
||||
fab!(:staff_tag_group) { Fabricate(:tag_group, permissions: { "staff" => 1 }, tag_names: [hidden_tag.name]) }
|
||||
|
||||
before do
|
||||
topic.tags << hidden_tag
|
||||
describe "with hidden tags" do
|
||||
fab!(:hidden_tag) { Fabricate(:tag, name: "hidden") }
|
||||
fab!(:staff_tag_group) do
|
||||
Fabricate(:tag_group, permissions: { "staff" => 1 }, tag_names: [hidden_tag.name])
|
||||
end
|
||||
|
||||
it 'returns hidden tag to staff' do
|
||||
before { topic.tags << hidden_tag }
|
||||
|
||||
it "returns hidden tag to staff" do
|
||||
json = serialize_topic(topic, admin)
|
||||
expect(json[:tags]).to eq([hidden_tag.name])
|
||||
end
|
||||
|
||||
it 'does not return hidden tag to non-staff' do
|
||||
it "does not return hidden tag to non-staff" do
|
||||
json = serialize_topic(topic, user)
|
||||
expect(json[:tags]).to eq([])
|
||||
end
|
||||
end
|
||||
|
||||
describe 'tags order' do
|
||||
fab!(:tag1) { Fabricate(:tag, name: 'ctag', description: "c description", topic_count: 5) }
|
||||
fab!(:tag2) { Fabricate(:tag, name: 'btag', description: "b description", topic_count: 9) }
|
||||
fab!(:tag3) { Fabricate(:tag, name: 'atag', description: "a description", topic_count: 3) }
|
||||
describe "tags order" do
|
||||
fab!(:tag1) { Fabricate(:tag, name: "ctag", description: "c description", topic_count: 5) }
|
||||
fab!(:tag2) { Fabricate(:tag, name: "btag", description: "b description", topic_count: 9) }
|
||||
fab!(:tag3) { Fabricate(:tag, name: "atag", description: "a description", topic_count: 3) }
|
||||
|
||||
before do
|
||||
topic.tags << tag1
|
||||
@@ -287,16 +289,18 @@ RSpec.describe TopicViewSerializer do
|
||||
topic.tags << tag3
|
||||
end
|
||||
|
||||
it 'tags are automatically sorted by tag popularity' do
|
||||
it "tags are automatically sorted by tag popularity" do
|
||||
json = serialize_topic(topic, user)
|
||||
expect(json[:tags]).to eq(%w(btag ctag atag))
|
||||
expect(json[:tags_descriptions]).to eq({ btag: "b description", ctag: "c description", atag: "a description" })
|
||||
expect(json[:tags]).to eq(%w[btag ctag atag])
|
||||
expect(json[:tags_descriptions]).to eq(
|
||||
{ btag: "b description", ctag: "c description", atag: "a description" },
|
||||
)
|
||||
end
|
||||
|
||||
it 'tags can be sorted alphabetically' do
|
||||
it "tags can be sorted alphabetically" do
|
||||
SiteSetting.tags_sort_alphabetically = true
|
||||
json = serialize_topic(topic, user)
|
||||
expect(json[:tags]).to eq(%w(atag btag ctag))
|
||||
expect(json[:tags]).to eq(%w[atag btag ctag])
|
||||
end
|
||||
end
|
||||
|
||||
@@ -323,15 +327,15 @@ RSpec.describe TopicViewSerializer do
|
||||
|
||||
describe "pending posts" do
|
||||
context "when the queue is enabled" do
|
||||
before do
|
||||
SiteSetting.approve_post_count = 1
|
||||
end
|
||||
before { SiteSetting.approve_post_count = 1 }
|
||||
|
||||
fab!(:queued_post) do
|
||||
ReviewableQueuedPost.needs_review!(
|
||||
topic: topic,
|
||||
payload: { raw: "hello my raw contents" },
|
||||
created_by: user
|
||||
payload: {
|
||||
raw: "hello my raw contents",
|
||||
},
|
||||
created_by: user,
|
||||
)
|
||||
end
|
||||
|
||||
@@ -362,7 +366,12 @@ RSpec.describe TopicViewSerializer do
|
||||
context "with details" do
|
||||
it "returns the details object" do
|
||||
PostCreator.create!(user, topic_id: topic.id, raw: "this is my post content")
|
||||
topic.topic_links.create!(user: user, url: 'https://discourse.org', domain: 'discourse.org', clicks: 100)
|
||||
topic.topic_links.create!(
|
||||
user: user,
|
||||
url: "https://discourse.org",
|
||||
domain: "discourse.org",
|
||||
clicks: 100,
|
||||
)
|
||||
json = serialize_topic(topic, admin)
|
||||
|
||||
details = json[:details]
|
||||
@@ -388,7 +397,7 @@ RSpec.describe TopicViewSerializer do
|
||||
GroupUser.create(group: group2, user: user)
|
||||
|
||||
pm = Fabricate(:private_message_topic)
|
||||
pm.update(archetype: 'private_message')
|
||||
pm.update(archetype: "private_message")
|
||||
pm.topic_allowed_groups.create!(group: group)
|
||||
pm.topic_allowed_groups.create!(group: group2)
|
||||
|
||||
@@ -436,11 +445,9 @@ RSpec.describe TopicViewSerializer do
|
||||
fab!(:topic) { Fabricate(:topic, category: category) }
|
||||
let(:user) { group_user.user }
|
||||
|
||||
before do
|
||||
SiteSetting.enable_category_group_moderation = true
|
||||
end
|
||||
before { SiteSetting.enable_category_group_moderation = true }
|
||||
|
||||
it 'explicitly returns can_edit' do
|
||||
it "explicitly returns can_edit" do
|
||||
json = serialize_topic(topic, user)
|
||||
expect(json[:details][:can_edit]).to eq(true)
|
||||
|
||||
@@ -456,9 +463,7 @@ RSpec.describe TopicViewSerializer do
|
||||
fab!(:published_page) { Fabricate(:published_page, topic: topic) }
|
||||
|
||||
context "when page publishing is disabled" do
|
||||
before do
|
||||
SiteSetting.enable_page_publishing = false
|
||||
end
|
||||
before { SiteSetting.enable_page_publishing = false }
|
||||
|
||||
it "doesn't return the published page if not enabled" do
|
||||
json = serialize_topic(topic, admin)
|
||||
@@ -467,9 +472,7 @@ RSpec.describe TopicViewSerializer do
|
||||
end
|
||||
|
||||
context "when page publishing is enabled" do
|
||||
before do
|
||||
SiteSetting.enable_page_publishing = true
|
||||
end
|
||||
before { SiteSetting.enable_page_publishing = true }
|
||||
|
||||
context "when not staff" do
|
||||
it "doesn't return the published page" do
|
||||
@@ -502,16 +505,17 @@ RSpec.describe TopicViewSerializer do
|
||||
|
||||
context "when viewing private messages when enable_category_group_moderation is enabled" do
|
||||
fab!(:pm_topic) do
|
||||
Fabricate(:private_message_topic, topic_allowed_users: [
|
||||
Fabricate.build(:topic_allowed_user, user: user),
|
||||
Fabricate.build(:topic_allowed_user, user: admin)
|
||||
])
|
||||
Fabricate(
|
||||
:private_message_topic,
|
||||
topic_allowed_users: [
|
||||
Fabricate.build(:topic_allowed_user, user: user),
|
||||
Fabricate.build(:topic_allowed_user, user: admin),
|
||||
],
|
||||
)
|
||||
end
|
||||
fab!(:post) { Fabricate(:post, topic: pm_topic) }
|
||||
|
||||
before do
|
||||
SiteSetting.enable_category_group_moderation = true
|
||||
end
|
||||
before { SiteSetting.enable_category_group_moderation = true }
|
||||
|
||||
# Ensure having enable_category_group_moderation turned on doesn't break private messages
|
||||
it "should return posts" do
|
||||
@@ -520,9 +524,9 @@ RSpec.describe TopicViewSerializer do
|
||||
end
|
||||
end
|
||||
|
||||
describe '#user_last_posted_at' do
|
||||
context 'when the slow mode is disabled' do
|
||||
it 'returns nil' do
|
||||
describe "#user_last_posted_at" do
|
||||
context "when the slow mode is disabled" do
|
||||
it "returns nil" do
|
||||
Fabricate(:topic_user, user: user, topic: topic, last_posted_at: 6.hours.ago)
|
||||
|
||||
json = serialize_topic(topic, user)
|
||||
@@ -531,10 +535,10 @@ RSpec.describe TopicViewSerializer do
|
||||
end
|
||||
end
|
||||
|
||||
context 'when the slow mode is enabled' do
|
||||
context "when the slow mode is enabled" do
|
||||
before { topic.update!(slow_mode_seconds: 1000) }
|
||||
|
||||
it 'returns nil if no user is given' do
|
||||
it "returns nil if no user is given" do
|
||||
json = serialize_topic(topic, nil)
|
||||
|
||||
expect(json[:user_last_posted_at]).to be_nil
|
||||
@@ -546,7 +550,7 @@ RSpec.describe TopicViewSerializer do
|
||||
expect(json[:user_last_posted_at]).to be_nil
|
||||
end
|
||||
|
||||
it 'returns the last time the user posted' do
|
||||
it "returns the last time the user posted" do
|
||||
Fabricate(:topic_user, user: user, topic: topic, last_posted_at: 6.hours.ago)
|
||||
json = serialize_topic(topic, user)
|
||||
|
||||
@@ -555,11 +559,11 @@ RSpec.describe TopicViewSerializer do
|
||||
end
|
||||
end
|
||||
|
||||
describe '#requested_group_name' do
|
||||
describe "#requested_group_name" do
|
||||
fab!(:pm) { Fabricate(:private_message_post).topic }
|
||||
fab!(:group) { Fabricate(:group) }
|
||||
|
||||
it 'should return the right group name when PM is a group membership request' do
|
||||
it "should return the right group name when PM is a group membership request" do
|
||||
pm.custom_fields[:requested_group_id] = group.id
|
||||
pm.save!
|
||||
|
||||
@@ -570,40 +574,41 @@ RSpec.describe TopicViewSerializer do
|
||||
expect(json[:requested_group_name]).to eq(group.name)
|
||||
end
|
||||
|
||||
it 'should not include the attribute for a non group membership request PM' do
|
||||
it "should not include the attribute for a non group membership request PM" do
|
||||
json = serialize_topic(pm, pm.first_post.user)
|
||||
|
||||
expect(json[:requested_group_name]).to eq(nil)
|
||||
end
|
||||
end
|
||||
|
||||
describe '#topic_timer' do
|
||||
it 'does not include the attribute when topic does not have a topic timer' do
|
||||
describe "#topic_timer" do
|
||||
it "does not include the attribute when topic does not have a topic timer" do
|
||||
json = serialize_topic(topic, user)
|
||||
|
||||
expect(json[:topic_timer]).to eq(nil)
|
||||
end
|
||||
|
||||
it 'includes the attribute when topic has a public topic timer' do
|
||||
topic_timer = Fabricate(:topic_timer, topic: topic, execute_at: Time.utc(2022, 4, 6, 16, 23, 56))
|
||||
it "includes the attribute when topic has a public topic timer" do
|
||||
topic_timer =
|
||||
Fabricate(:topic_timer, topic: topic, execute_at: Time.utc(2022, 4, 6, 16, 23, 56))
|
||||
json = serialize_topic(topic, user)
|
||||
|
||||
expect(json[:topic_timer][:id]).to eq(topic_timer.id)
|
||||
expect(json[:topic_timer][:based_on_last_post]).to eq(false)
|
||||
expect(json[:topic_timer][:category_id]).to eq(nil)
|
||||
expect(json[:topic_timer][:duration_minutes]).to eq(nil)
|
||||
expect(json[:topic_timer][:execute_at]).to eq('2022-04-06T16:23:56.000Z')
|
||||
expect(json[:topic_timer][:execute_at]).to eq("2022-04-06T16:23:56.000Z")
|
||||
expect(json[:topic_timer][:status_type]).to eq("close")
|
||||
end
|
||||
|
||||
it 'does not include the attribute for category topic timer where category is restricted to user' do
|
||||
it "does not include the attribute for category topic timer where category is restricted to user" do
|
||||
category = Fabricate(:category, read_restricted: true)
|
||||
|
||||
Fabricate(:topic_timer,
|
||||
Fabricate(
|
||||
:topic_timer,
|
||||
topic: topic,
|
||||
category_id: category.id,
|
||||
status_type:
|
||||
TopicTimer.types[:publish_to_category]
|
||||
status_type: TopicTimer.types[:publish_to_category],
|
||||
)
|
||||
|
||||
json = serialize_topic(topic, user)
|
||||
@@ -611,15 +616,16 @@ RSpec.describe TopicViewSerializer do
|
||||
expect(json[:topic_timer]).to eq(nil)
|
||||
end
|
||||
|
||||
it 'includes the attribute for category topic timer where category is not restricted to user' do
|
||||
it "includes the attribute for category topic timer where category is not restricted to user" do
|
||||
category = Fabricate(:category, read_restricted: false)
|
||||
|
||||
topic_timer = Fabricate(:topic_timer,
|
||||
topic: topic,
|
||||
category_id: category.id,
|
||||
status_type:
|
||||
TopicTimer.types[:publish_to_category]
|
||||
)
|
||||
topic_timer =
|
||||
Fabricate(
|
||||
:topic_timer,
|
||||
topic: topic,
|
||||
category_id: category.id,
|
||||
status_type: TopicTimer.types[:publish_to_category],
|
||||
)
|
||||
|
||||
json = serialize_topic(topic, user)
|
||||
|
||||
|
||||
@@ -4,15 +4,15 @@ RSpec.describe UploadSerializer do
|
||||
fab!(:upload) { Fabricate(:upload) }
|
||||
let(:subject) { UploadSerializer.new(upload, root: false) }
|
||||
|
||||
it 'should render without errors' do
|
||||
it "should render without errors" do
|
||||
json_data = JSON.parse(subject.to_json)
|
||||
|
||||
expect(json_data['id']).to eql upload.id
|
||||
expect(json_data['width']).to eql upload.width
|
||||
expect(json_data['height']).to eql upload.height
|
||||
expect(json_data['thumbnail_width']).to eql upload.thumbnail_width
|
||||
expect(json_data['thumbnail_height']).to eql upload.thumbnail_height
|
||||
expect(json_data['short_path']).to eql upload.short_path
|
||||
expect(json_data["id"]).to eql upload.id
|
||||
expect(json_data["width"]).to eql upload.width
|
||||
expect(json_data["height"]).to eql upload.height
|
||||
expect(json_data["thumbnail_width"]).to eql upload.thumbnail_width
|
||||
expect(json_data["thumbnail_height"]).to eql upload.thumbnail_height
|
||||
expect(json_data["short_path"]).to eql upload.short_path
|
||||
end
|
||||
|
||||
context "when the upload is secure" do
|
||||
|
||||
@@ -1,23 +1,20 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
RSpec.describe UserAuthTokenSerializer do
|
||||
|
||||
fab!(:user) { Fabricate(:moderator) }
|
||||
let(:token) { UserAuthToken.generate!(user_id: user.id, client_ip: '2a02:ea00::', staff: true) }
|
||||
let(:token) { UserAuthToken.generate!(user_id: user.id, client_ip: "2a02:ea00::", staff: true) }
|
||||
|
||||
before(:each) do
|
||||
DiscourseIpInfo.open_db(File.join(Rails.root, 'spec', 'fixtures', 'mmdb'))
|
||||
before(:each) { DiscourseIpInfo.open_db(File.join(Rails.root, "spec", "fixtures", "mmdb")) }
|
||||
|
||||
it "serializes user auth tokens with respect to user locale" do
|
||||
I18n.locale = "de"
|
||||
json = UserAuthTokenSerializer.new(token, scope: Guardian.new(user), root: false).as_json
|
||||
expect(json[:location]).to include("Schweiz")
|
||||
end
|
||||
|
||||
it 'serializes user auth tokens with respect to user locale' do
|
||||
I18n.locale = 'de'
|
||||
it "correctly translates Discourse locale to MaxMindDb locale" do
|
||||
I18n.locale = "zh_CN"
|
||||
json = UserAuthTokenSerializer.new(token, scope: Guardian.new(user), root: false).as_json
|
||||
expect(json[:location]).to include('Schweiz')
|
||||
end
|
||||
|
||||
it 'correctly translates Discourse locale to MaxMindDb locale' do
|
||||
I18n.locale = 'zh_CN'
|
||||
json = UserAuthTokenSerializer.new(token, scope: Guardian.new(user), root: false).as_json
|
||||
expect(json[:location]).to include('瑞士')
|
||||
expect(json[:location]).to include("瑞士")
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
RSpec.describe UserBadgeSerializer do
|
||||
describe '#topic' do
|
||||
describe "#topic" do
|
||||
fab!(:user) { Fabricate(:user) }
|
||||
fab!(:admin) { Fabricate(:admin) }
|
||||
fab!(:post) { Fabricate(:post) }
|
||||
@@ -9,57 +9,65 @@ RSpec.describe UserBadgeSerializer do
|
||||
fab!(:user_badge) { Fabricate(:user_badge, badge: badge, post_id: post.id) }
|
||||
let(:guardian) { Guardian.new(user_badge.user) }
|
||||
|
||||
it 'is not included in serialized object when badge has not been configured to show posts' do
|
||||
it "is not included in serialized object when badge has not been configured to show posts" do
|
||||
badge.update!(show_posts: false)
|
||||
|
||||
guardian = Guardian.new
|
||||
|
||||
serialized = described_class.new(user_badge,
|
||||
scope: guardian,
|
||||
allowed_user_badge_topic_ids: guardian.can_see_topic_ids(topic_ids: [post.topic_id])
|
||||
).as_json
|
||||
serialized =
|
||||
described_class.new(
|
||||
user_badge,
|
||||
scope: guardian,
|
||||
allowed_user_badge_topic_ids: guardian.can_see_topic_ids(topic_ids: [post.topic_id]),
|
||||
).as_json
|
||||
|
||||
expect(serialized[:topics]).to eq(nil)
|
||||
end
|
||||
|
||||
it 'is not included in serialized object when user badge is not associated with a post' do
|
||||
it "is not included in serialized object when user badge is not associated with a post" do
|
||||
user_badge.update!(post_id: nil)
|
||||
|
||||
serialized = described_class.new(user_badge,
|
||||
scope: guardian,
|
||||
allowed_user_badge_topic_ids: guardian.can_see_topic_ids(topic_ids: [post.topic_id])
|
||||
).as_json
|
||||
serialized =
|
||||
described_class.new(
|
||||
user_badge,
|
||||
scope: guardian,
|
||||
allowed_user_badge_topic_ids: guardian.can_see_topic_ids(topic_ids: [post.topic_id]),
|
||||
).as_json
|
||||
|
||||
expect(serialized[:topics]).to eq(nil)
|
||||
end
|
||||
|
||||
it 'is not included in serialized object when user badge is not associated with a topic' do
|
||||
it "is not included in serialized object when user badge is not associated with a topic" do
|
||||
post.topic.destroy!
|
||||
|
||||
serialized = described_class.new(user_badge,
|
||||
scope: guardian,
|
||||
allowed_user_badge_topic_ids: guardian.can_see_topic_ids(topic_ids: [post.topic_id])
|
||||
).as_json
|
||||
serialized =
|
||||
described_class.new(
|
||||
user_badge,
|
||||
scope: guardian,
|
||||
allowed_user_badge_topic_ids: guardian.can_see_topic_ids(topic_ids: [post.topic_id]),
|
||||
).as_json
|
||||
|
||||
expect(serialized[:topics]).to eq(nil)
|
||||
end
|
||||
|
||||
it 'is not included in serialized object when allowed_user_badge_topic_ids option is not provided' do
|
||||
it "is not included in serialized object when allowed_user_badge_topic_ids option is not provided" do
|
||||
serialized = described_class.new(user_badge, scope: guardian).as_json
|
||||
|
||||
expect(serialized[:topics]).to eq(nil)
|
||||
end
|
||||
|
||||
it 'is not included in serialized object when topic id is not present in allowed_user_badge_topic_ids option' do
|
||||
serialized = described_class.new(user_badge,
|
||||
scope: guardian,
|
||||
allowed_user_badge_topic_ids: guardian.can_see_topic_ids(topic_ids: [post.topic_id + 1])
|
||||
).as_json
|
||||
it "is not included in serialized object when topic id is not present in allowed_user_badge_topic_ids option" do
|
||||
serialized =
|
||||
described_class.new(
|
||||
user_badge,
|
||||
scope: guardian,
|
||||
allowed_user_badge_topic_ids: guardian.can_see_topic_ids(topic_ids: [post.topic_id + 1]),
|
||||
).as_json
|
||||
|
||||
expect(serialized[:topics]).to eq(nil)
|
||||
end
|
||||
|
||||
it 'is included in serialized object for admin scope even if allowed_user_badge_topic_ids option is not provided' do
|
||||
it "is included in serialized object for admin scope even if allowed_user_badge_topic_ids option is not provided" do
|
||||
serialized = described_class.new(user_badge, scope: Guardian.new(admin)).as_json
|
||||
|
||||
serialized_topic = serialized[:topics][0]
|
||||
@@ -71,11 +79,13 @@ RSpec.describe UserBadgeSerializer do
|
||||
expect(serialized_topic[:posts_count]).to eq(post.topic.reload.posts_count)
|
||||
end
|
||||
|
||||
it 'is included in serialized object when topic id is present in allowed_user_badge_topic_ids option' do
|
||||
serialized = described_class.new(user_badge,
|
||||
scope: guardian,
|
||||
allowed_user_badge_topic_ids: guardian.can_see_topic_ids(topic_ids: [post.topic_id])
|
||||
).as_json
|
||||
it "is included in serialized object when topic id is present in allowed_user_badge_topic_ids option" do
|
||||
serialized =
|
||||
described_class.new(
|
||||
user_badge,
|
||||
scope: guardian,
|
||||
allowed_user_badge_topic_ids: guardian.can_see_topic_ids(topic_ids: [post.topic_id]),
|
||||
).as_json
|
||||
|
||||
serialized_topic = serialized[:topics][0]
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
RSpec.describe UserBookmarkListSerializer do
|
||||
|
||||
fab!(:user) { Fabricate(:user) }
|
||||
|
||||
context "for polymorphic bookmarks" do
|
||||
@@ -24,7 +23,9 @@ RSpec.describe UserBookmarkListSerializer do
|
||||
|
||||
it "chooses the correct class of serializer for all the bookmarkable types" do
|
||||
serializer = run_serializer
|
||||
expect(serializer.bookmarks.map(&:class).map(&:to_s)).to match_array(["UserTestBookmarkSerializer", "UserTopicBookmarkSerializer", "UserPostBookmarkSerializer"])
|
||||
expect(serializer.bookmarks.map(&:class).map(&:to_s)).to match_array(
|
||||
%w[UserTestBookmarkSerializer UserTopicBookmarkSerializer UserPostBookmarkSerializer],
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -66,7 +66,6 @@ RSpec.describe UserCardSerializer do
|
||||
expect(json[:pending_posts_count]).to eq 0
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe "#status" do
|
||||
|
||||
@@ -4,14 +4,12 @@ RSpec.describe UserPostBookmarkSerializer do
|
||||
let(:user) { Fabricate(:user) }
|
||||
let(:topic) { Fabricate(:topic) }
|
||||
let(:post) { Fabricate(:post, user: user, topic: topic) }
|
||||
let!(:bookmark) { Fabricate(:bookmark, name: 'Test', user: user, bookmarkable: post) }
|
||||
let!(:bookmark) { Fabricate(:bookmark, name: "Test", user: user, bookmarkable: post) }
|
||||
|
||||
describe "#highest_post_number" do
|
||||
let(:whisperers_group) { Fabricate(:group) }
|
||||
|
||||
before do
|
||||
SiteSetting.whispers_allowed_groups = "#{whisperers_group.id}"
|
||||
end
|
||||
before { SiteSetting.whispers_allowed_groups = "#{whisperers_group.id}" }
|
||||
|
||||
it "uses the correct highest_post_number column based on whether the user is whisperer" do
|
||||
Fabricate(:post, topic: topic)
|
||||
|
||||
@@ -6,7 +6,18 @@ RSpec.describe UserSerializer do
|
||||
context "with a TL0 user seen as anonymous" do
|
||||
let(:serializer) { UserSerializer.new(user, scope: Guardian.new, root: false) }
|
||||
let(:json) { serializer.as_json }
|
||||
let(:untrusted_attributes) { %i{bio_raw bio_cooked bio_excerpt location website website_name profile_background card_background} }
|
||||
let(:untrusted_attributes) do
|
||||
%i[
|
||||
bio_raw
|
||||
bio_cooked
|
||||
bio_excerpt
|
||||
location
|
||||
website
|
||||
website_name
|
||||
profile_background
|
||||
card_background
|
||||
]
|
||||
end
|
||||
|
||||
it "doesn't serialize untrusted attributes" do
|
||||
untrusted_attributes.each { |attr| expect(json).not_to have_key(attr) }
|
||||
@@ -20,11 +31,8 @@ RSpec.describe UserSerializer do
|
||||
|
||||
context "as moderator" do
|
||||
it "serializes correctly" do
|
||||
json = UserSerializer.new(
|
||||
user,
|
||||
scope: Guardian.new(Fabricate(:moderator)),
|
||||
root: false
|
||||
).as_json
|
||||
json =
|
||||
UserSerializer.new(user, scope: Guardian.new(Fabricate(:moderator)), root: false).as_json
|
||||
|
||||
expect(json[:group_users]).to eq(nil)
|
||||
expect(json[:second_factor_enabled]).to eq(nil)
|
||||
@@ -70,14 +78,46 @@ RSpec.describe UserSerializer do
|
||||
category2 = Fabricate(:category)
|
||||
category3 = Fabricate(:category)
|
||||
category4 = Fabricate(:category)
|
||||
CategoryUser.create(category: category1, user: user, notification_level: CategoryUser.notification_levels[:muted])
|
||||
CategoryUser.create(category: Fabricate(:category), user: admin_user, notification_level: CategoryUser.notification_levels[:muted])
|
||||
CategoryUser.create(category: category2, user: user, notification_level: CategoryUser.notification_levels[:tracking])
|
||||
CategoryUser.create(category: Fabricate(:category), user: admin_user, notification_level: CategoryUser.notification_levels[:tracking])
|
||||
CategoryUser.create(category: category3, user: user, notification_level: CategoryUser.notification_levels[:watching])
|
||||
CategoryUser.create(category: Fabricate(:category), user: admin_user, notification_level: CategoryUser.notification_levels[:watching])
|
||||
CategoryUser.create(category: category4, user: user, notification_level: CategoryUser.notification_levels[:regular])
|
||||
CategoryUser.create(category: Fabricate(:category), user: admin_user, notification_level: CategoryUser.notification_levels[:regular])
|
||||
CategoryUser.create(
|
||||
category: category1,
|
||||
user: user,
|
||||
notification_level: CategoryUser.notification_levels[:muted],
|
||||
)
|
||||
CategoryUser.create(
|
||||
category: Fabricate(:category),
|
||||
user: admin_user,
|
||||
notification_level: CategoryUser.notification_levels[:muted],
|
||||
)
|
||||
CategoryUser.create(
|
||||
category: category2,
|
||||
user: user,
|
||||
notification_level: CategoryUser.notification_levels[:tracking],
|
||||
)
|
||||
CategoryUser.create(
|
||||
category: Fabricate(:category),
|
||||
user: admin_user,
|
||||
notification_level: CategoryUser.notification_levels[:tracking],
|
||||
)
|
||||
CategoryUser.create(
|
||||
category: category3,
|
||||
user: user,
|
||||
notification_level: CategoryUser.notification_levels[:watching],
|
||||
)
|
||||
CategoryUser.create(
|
||||
category: Fabricate(:category),
|
||||
user: admin_user,
|
||||
notification_level: CategoryUser.notification_levels[:watching],
|
||||
)
|
||||
CategoryUser.create(
|
||||
category: category4,
|
||||
user: user,
|
||||
notification_level: CategoryUser.notification_levels[:regular],
|
||||
)
|
||||
CategoryUser.create(
|
||||
category: Fabricate(:category),
|
||||
user: admin_user,
|
||||
notification_level: CategoryUser.notification_levels[:regular],
|
||||
)
|
||||
|
||||
expect(json[:muted_category_ids]).to eq([category1.id])
|
||||
expect(json[:tracked_category_ids]).to eq([category2.id])
|
||||
@@ -90,14 +130,46 @@ RSpec.describe UserSerializer do
|
||||
tag2 = Fabricate(:tag)
|
||||
tag3 = Fabricate(:tag)
|
||||
tag4 = Fabricate(:tag)
|
||||
TagUser.create(tag: tag1, user: user, notification_level: TagUser.notification_levels[:muted])
|
||||
TagUser.create(tag: Fabricate(:tag), user: admin_user, notification_level: TagUser.notification_levels[:muted])
|
||||
TagUser.create(tag: tag2, user: user, notification_level: TagUser.notification_levels[:tracking])
|
||||
TagUser.create(tag: Fabricate(:tag), user: admin_user, notification_level: TagUser.notification_levels[:tracking])
|
||||
TagUser.create(tag: tag3, user: user, notification_level: TagUser.notification_levels[:watching])
|
||||
TagUser.create(tag: Fabricate(:tag), user: admin_user, notification_level: TagUser.notification_levels[:watching])
|
||||
TagUser.create(tag: tag4, user: user, notification_level: TagUser.notification_levels[:watching_first_post])
|
||||
TagUser.create(tag: Fabricate(:tag), user: admin_user, notification_level: TagUser.notification_levels[:watching_first_post])
|
||||
TagUser.create(
|
||||
tag: tag1,
|
||||
user: user,
|
||||
notification_level: TagUser.notification_levels[:muted],
|
||||
)
|
||||
TagUser.create(
|
||||
tag: Fabricate(:tag),
|
||||
user: admin_user,
|
||||
notification_level: TagUser.notification_levels[:muted],
|
||||
)
|
||||
TagUser.create(
|
||||
tag: tag2,
|
||||
user: user,
|
||||
notification_level: TagUser.notification_levels[:tracking],
|
||||
)
|
||||
TagUser.create(
|
||||
tag: Fabricate(:tag),
|
||||
user: admin_user,
|
||||
notification_level: TagUser.notification_levels[:tracking],
|
||||
)
|
||||
TagUser.create(
|
||||
tag: tag3,
|
||||
user: user,
|
||||
notification_level: TagUser.notification_levels[:watching],
|
||||
)
|
||||
TagUser.create(
|
||||
tag: Fabricate(:tag),
|
||||
user: admin_user,
|
||||
notification_level: TagUser.notification_levels[:watching],
|
||||
)
|
||||
TagUser.create(
|
||||
tag: tag4,
|
||||
user: user,
|
||||
notification_level: TagUser.notification_levels[:watching_first_post],
|
||||
)
|
||||
TagUser.create(
|
||||
tag: Fabricate(:tag),
|
||||
user: admin_user,
|
||||
notification_level: TagUser.notification_levels[:watching_first_post],
|
||||
)
|
||||
|
||||
expect(json[:muted_tags]).to eq([tag1.name])
|
||||
expect(json[:tracked_tags]).to eq([tag2.name])
|
||||
@@ -107,9 +179,7 @@ RSpec.describe UserSerializer do
|
||||
end
|
||||
|
||||
context "with `enable_names` true" do
|
||||
before do
|
||||
SiteSetting.enable_names = true
|
||||
end
|
||||
before { SiteSetting.enable_names = true }
|
||||
|
||||
it "has a name" do
|
||||
expect(json[:name]).to be_present
|
||||
@@ -117,9 +187,7 @@ RSpec.describe UserSerializer do
|
||||
end
|
||||
|
||||
context "with `enable_names` false" do
|
||||
before do
|
||||
SiteSetting.enable_names = false
|
||||
end
|
||||
before { SiteSetting.enable_names = false }
|
||||
|
||||
it "has a name" do
|
||||
expect(json[:name]).to be_blank
|
||||
@@ -140,68 +208,58 @@ RSpec.describe UserSerializer do
|
||||
|
||||
context "with filled out website" do
|
||||
context "when website has a path" do
|
||||
before do
|
||||
user.user_profile.website = 'http://example.com/user'
|
||||
end
|
||||
before { user.user_profile.website = "http://example.com/user" }
|
||||
|
||||
it "has a website with a path" do
|
||||
expect(json[:website]).to eq 'http://example.com/user'
|
||||
expect(json[:website]).to eq "http://example.com/user"
|
||||
end
|
||||
|
||||
it "returns complete website name with path" do
|
||||
expect(json[:website_name]).to eq 'example.com/user'
|
||||
expect(json[:website_name]).to eq "example.com/user"
|
||||
end
|
||||
end
|
||||
|
||||
context "when website has a subdomain" do
|
||||
before do
|
||||
user.user_profile.website = 'http://subdomain.example.com/user'
|
||||
end
|
||||
before { user.user_profile.website = "http://subdomain.example.com/user" }
|
||||
|
||||
it "has a website with a subdomain" do
|
||||
expect(json[:website]).to eq 'http://subdomain.example.com/user'
|
||||
expect(json[:website]).to eq "http://subdomain.example.com/user"
|
||||
end
|
||||
|
||||
it "returns website name with the subdomain" do
|
||||
expect(json[:website_name]).to eq 'subdomain.example.com/user'
|
||||
expect(json[:website_name]).to eq "subdomain.example.com/user"
|
||||
end
|
||||
end
|
||||
|
||||
context "when website has www" do
|
||||
before do
|
||||
user.user_profile.website = 'http://www.example.com/user'
|
||||
end
|
||||
before { user.user_profile.website = "http://www.example.com/user" }
|
||||
|
||||
it "has a website with the www" do
|
||||
expect(json[:website]).to eq 'http://www.example.com/user'
|
||||
expect(json[:website]).to eq "http://www.example.com/user"
|
||||
end
|
||||
|
||||
it "returns website name without the www" do
|
||||
expect(json[:website_name]).to eq 'example.com/user'
|
||||
expect(json[:website_name]).to eq "example.com/user"
|
||||
end
|
||||
end
|
||||
|
||||
context "when website includes query parameters" do
|
||||
before do
|
||||
user.user_profile.website = 'http://example.com/user?ref=payme'
|
||||
end
|
||||
before { user.user_profile.website = "http://example.com/user?ref=payme" }
|
||||
|
||||
it "has a website with query params" do
|
||||
expect(json[:website]).to eq 'http://example.com/user?ref=payme'
|
||||
expect(json[:website]).to eq "http://example.com/user?ref=payme"
|
||||
end
|
||||
|
||||
it "has a website name without query params" do
|
||||
expect(json[:website_name]).to eq 'example.com/user'
|
||||
expect(json[:website_name]).to eq "example.com/user"
|
||||
end
|
||||
end
|
||||
|
||||
context "when website is not a valid url" do
|
||||
before do
|
||||
user.user_profile.website = 'invalid-url'
|
||||
end
|
||||
before { user.user_profile.website = "invalid-url" }
|
||||
|
||||
it "has a website with the invalid url" do
|
||||
expect(json[:website]).to eq 'invalid-url'
|
||||
expect(json[:website]).to eq "invalid-url"
|
||||
end
|
||||
|
||||
it "has a nil website name" do
|
||||
@@ -212,16 +270,16 @@ RSpec.describe UserSerializer do
|
||||
|
||||
context "with filled out bio" do
|
||||
before do
|
||||
user.user_profile.bio_raw = 'my raw bio'
|
||||
user.user_profile.bio_cooked = 'my cooked bio'
|
||||
user.user_profile.bio_raw = "my raw bio"
|
||||
user.user_profile.bio_cooked = "my cooked bio"
|
||||
end
|
||||
|
||||
it "has a bio" do
|
||||
expect(json[:bio_raw]).to eq 'my raw bio'
|
||||
expect(json[:bio_raw]).to eq "my raw bio"
|
||||
end
|
||||
|
||||
it "has a cooked bio" do
|
||||
expect(json[:bio_cooked]).to eq 'my cooked bio'
|
||||
expect(json[:bio_cooked]).to eq "my cooked bio"
|
||||
end
|
||||
end
|
||||
|
||||
@@ -232,9 +290,7 @@ RSpec.describe UserSerializer do
|
||||
end
|
||||
|
||||
context "when totp enabled" do
|
||||
before do
|
||||
User.any_instance.stubs(:totp_enabled?).returns(true)
|
||||
end
|
||||
before { User.any_instance.stubs(:totp_enabled?).returns(true) }
|
||||
|
||||
it "is true" do
|
||||
expect(json[:second_factor_enabled]).to eq(true)
|
||||
@@ -242,9 +298,7 @@ RSpec.describe UserSerializer do
|
||||
end
|
||||
|
||||
context "when security_keys enabled" do
|
||||
before do
|
||||
User.any_instance.stubs(:security_keys_enabled?).returns(true)
|
||||
end
|
||||
before { User.any_instance.stubs(:security_keys_enabled?).returns(true) }
|
||||
|
||||
it "is true" do
|
||||
expect(json[:second_factor_enabled]).to eq(true)
|
||||
@@ -256,35 +310,34 @@ RSpec.describe UserSerializer do
|
||||
fab!(:viewing_user) { Fabricate(:user) }
|
||||
let(:scope) { Guardian.new(viewing_user) }
|
||||
|
||||
it 'returns false values for muted and ignored' do
|
||||
it "returns false values for muted and ignored" do
|
||||
expect(json[:ignored]).to eq(false)
|
||||
expect(json[:muted]).to eq(false)
|
||||
end
|
||||
|
||||
context 'when ignored' do
|
||||
context "when ignored" do
|
||||
before do
|
||||
Fabricate(:ignored_user, user: viewing_user, ignored_user: user)
|
||||
viewing_user.reload
|
||||
end
|
||||
|
||||
it 'returns true for ignored' do
|
||||
it "returns true for ignored" do
|
||||
expect(json[:ignored]).to eq(true)
|
||||
expect(json[:muted]).to eq(false)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when muted' do
|
||||
context "when muted" do
|
||||
before do
|
||||
Fabricate(:muted_user, user: viewing_user, muted_user: user)
|
||||
viewing_user.reload
|
||||
end
|
||||
|
||||
it 'returns true for muted' do
|
||||
it "returns true for muted" do
|
||||
expect(json[:muted]).to eq(true)
|
||||
expect(json[:ignored]).to eq(false)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
@@ -293,8 +346,8 @@ RSpec.describe UserSerializer do
|
||||
let(:json) { UserSerializer.new(user, scope: Guardian.new, root: false).as_json }
|
||||
|
||||
before do
|
||||
user.custom_fields['secret_field'] = 'Only for me to know'
|
||||
user.custom_fields['public_field'] = 'Everyone look here'
|
||||
user.custom_fields["secret_field"] = "Only for me to know"
|
||||
user.custom_fields["public_field"] = "Everyone look here"
|
||||
user.save
|
||||
end
|
||||
|
||||
@@ -304,9 +357,9 @@ RSpec.describe UserSerializer do
|
||||
end
|
||||
|
||||
it "serializes the fields listed in public_user_custom_fields site setting" do
|
||||
SiteSetting.public_user_custom_fields = 'public_field'
|
||||
expect(json[:custom_fields]['public_field']).to eq(user.custom_fields['public_field'])
|
||||
expect(json[:custom_fields]['secret_field']).to eq(nil)
|
||||
SiteSetting.public_user_custom_fields = "public_field"
|
||||
expect(json[:custom_fields]["public_field"]).to eq(user.custom_fields["public_field"])
|
||||
expect(json[:custom_fields]["secret_field"]).to eq(nil)
|
||||
end
|
||||
|
||||
context "with user custom field" do
|
||||
@@ -315,13 +368,11 @@ RSpec.describe UserSerializer do
|
||||
plugin.allow_public_user_custom_field :public_field
|
||||
end
|
||||
|
||||
after do
|
||||
DiscoursePluginRegistry.reset!
|
||||
end
|
||||
after { DiscoursePluginRegistry.reset! }
|
||||
|
||||
it "serializes the fields listed in public_user_custom_fields" do
|
||||
expect(json[:custom_fields]['public_field']).to eq(user.custom_fields['public_field'])
|
||||
expect(json[:custom_fields]['secret_field']).to eq(nil)
|
||||
expect(json[:custom_fields]["public_field"]).to eq(user.custom_fields["public_field"])
|
||||
expect(json[:custom_fields]["secret_field"]).to eq(nil)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -335,20 +386,25 @@ RSpec.describe UserSerializer do
|
||||
Fabricate(:user_field),
|
||||
Fabricate(:user_field, show_on_profile: true),
|
||||
Fabricate(:user_field, show_on_user_card: true),
|
||||
Fabricate(:user_field, show_on_user_card: true, show_on_profile: true)
|
||||
Fabricate(:user_field, show_on_user_card: true, show_on_profile: true),
|
||||
]
|
||||
end
|
||||
|
||||
let(:other_user_json) { UserSerializer.new(user, scope: Guardian.new(Fabricate(:user)), root: false).as_json }
|
||||
let(:other_user_json) do
|
||||
UserSerializer.new(user, scope: Guardian.new(Fabricate(:user)), root: false).as_json
|
||||
end
|
||||
let(:self_json) { UserSerializer.new(user, scope: Guardian.new(user), root: false).as_json }
|
||||
let(:admin_json) { UserSerializer.new(user, scope: Guardian.new(Fabricate(:admin)), root: false).as_json }
|
||||
let(:admin_json) do
|
||||
UserSerializer.new(user, scope: Guardian.new(Fabricate(:admin)), root: false).as_json
|
||||
end
|
||||
|
||||
it "includes the correct fields for each audience" do
|
||||
expect(admin_json[:user_fields].keys).to contain_exactly(*fields.map { |f| f.id.to_s })
|
||||
expect(other_user_json[:user_fields].keys).to contain_exactly(*fields[2..5].map { |f| f.id.to_s })
|
||||
expect(other_user_json[:user_fields].keys).to contain_exactly(
|
||||
*fields[2..5].map { |f| f.id.to_s },
|
||||
)
|
||||
expect(self_json[:user_fields].keys).to contain_exactly(*fields.map { |f| f.id.to_s })
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
context "with user_api_keys" do
|
||||
@@ -357,10 +413,22 @@ RSpec.describe UserSerializer do
|
||||
it "sorts keys by last used time" do
|
||||
freeze_time
|
||||
|
||||
user_api_key_0 = Fabricate(:readonly_user_api_key, user: user, last_used_at: 2.days.ago, revoked_at: Time.zone.now)
|
||||
user_api_key_0 =
|
||||
Fabricate(
|
||||
:readonly_user_api_key,
|
||||
user: user,
|
||||
last_used_at: 2.days.ago,
|
||||
revoked_at: Time.zone.now,
|
||||
)
|
||||
user_api_key_1 = Fabricate(:readonly_user_api_key, user: user, last_used_at: 7.days.ago)
|
||||
user_api_key_2 = Fabricate(:readonly_user_api_key, user: user, last_used_at: 1.days.ago)
|
||||
user_api_key_3 = Fabricate(:readonly_user_api_key, user: user, last_used_at: 4.days.ago, revoked_at: Time.zone.now)
|
||||
user_api_key_3 =
|
||||
Fabricate(
|
||||
:readonly_user_api_key,
|
||||
user: user,
|
||||
last_used_at: 4.days.ago,
|
||||
revoked_at: Time.zone.now,
|
||||
)
|
||||
user_api_key_4 = Fabricate(:readonly_user_api_key, user: user, last_used_at: 3.days.ago)
|
||||
|
||||
json = UserSerializer.new(user, scope: Guardian.new(user), root: false).as_json
|
||||
@@ -372,7 +440,7 @@ RSpec.describe UserSerializer do
|
||||
end
|
||||
end
|
||||
|
||||
context 'for user sidebar attributes' do
|
||||
context "for user sidebar attributes" do
|
||||
include_examples "User Sidebar Serializer Attributes", described_class
|
||||
|
||||
it "does not include attributes when scoped to user that cannot edit user" do
|
||||
|
||||
@@ -32,11 +32,14 @@ RSpec.describe UserSummarySerializer do
|
||||
topic = Fabricate(:topic)
|
||||
post = Fabricate(:post_with_external_links, user: topic.user, topic: topic)
|
||||
TopicLink.extract_from(post)
|
||||
TopicLink.where(topic_id: topic.id).order(domain: :asc, url: :asc).each_with_index do |link, index|
|
||||
index.times do |i|
|
||||
TopicLinkClick.create(topic_link: link, ip_address: "192.168.1.#{i + 1}")
|
||||
TopicLink
|
||||
.where(topic_id: topic.id)
|
||||
.order(domain: :asc, url: :asc)
|
||||
.each_with_index do |link, index|
|
||||
index.times do |i|
|
||||
TopicLinkClick.create(topic_link: link, ip_address: "192.168.1.#{i + 1}")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
guardian = Guardian.new
|
||||
summary = UserSummary.new(topic.user, guardian)
|
||||
|
||||
@@ -8,7 +8,7 @@ RSpec.describe WebHookPostSerializer do
|
||||
WebHookPostSerializer.new(post, scope: Guardian.new(u), root: false).as_json
|
||||
end
|
||||
|
||||
it 'should only include the required keys' do
|
||||
it "should only include the required keys" do
|
||||
expect(serialized_for_user(admin).keys).to contain_exactly(
|
||||
:id,
|
||||
:name,
|
||||
@@ -52,7 +52,7 @@ RSpec.describe WebHookPostSerializer do
|
||||
:topic_posts_count,
|
||||
:topic_filtered_posts_count,
|
||||
:topic_archetype,
|
||||
:category_slug
|
||||
:category_slug,
|
||||
)
|
||||
end
|
||||
|
||||
@@ -60,7 +60,7 @@ RSpec.describe WebHookPostSerializer do
|
||||
expect(serialized_for_user(admin)[:category_id]).to eq(post.topic.category_id)
|
||||
end
|
||||
|
||||
it 'should only include deleted topic title for staffs' do
|
||||
it "should only include deleted topic title for staffs" do
|
||||
topic = post.topic
|
||||
PostDestroyer.new(Discourse.system_user, post).destroy
|
||||
post.reload
|
||||
|
||||
@@ -5,18 +5,13 @@ RSpec.describe WebHookTopicViewSerializer do
|
||||
fab!(:topic) { Fabricate(:topic) }
|
||||
|
||||
let(:serializer) do
|
||||
WebHookTopicViewSerializer.new(TopicView.new(topic),
|
||||
scope: Guardian.new(admin),
|
||||
root: false
|
||||
)
|
||||
WebHookTopicViewSerializer.new(TopicView.new(topic), scope: Guardian.new(admin), root: false)
|
||||
end
|
||||
|
||||
before do
|
||||
SiteSetting.tagging_enabled = true
|
||||
end
|
||||
before { SiteSetting.tagging_enabled = true }
|
||||
|
||||
it 'should only include the keys that are sent out in the webhook' do
|
||||
expected_keys = %i{
|
||||
it "should only include the keys that are sent out in the webhook" do
|
||||
expected_keys = %i[
|
||||
id
|
||||
title
|
||||
fancy_title
|
||||
@@ -50,13 +45,13 @@ RSpec.describe WebHookTopicViewSerializer do
|
||||
tags
|
||||
tags_descriptions
|
||||
thumbnails
|
||||
}
|
||||
]
|
||||
|
||||
keys = serializer.as_json.keys
|
||||
|
||||
expect(serializer.as_json.keys).to contain_exactly(*expected_keys)
|
||||
|
||||
topic.external_id = 'external_id'
|
||||
topic.external_id = "external_id"
|
||||
expected_keys << :external_id
|
||||
expect(serializer.as_json.keys).to contain_exactly(*expected_keys)
|
||||
end
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
RSpec.describe WebHookUserSerializer do
|
||||
let(:user) do
|
||||
user = Fabricate(:user)
|
||||
SingleSignOnRecord.create!(user_id: user.id, external_id: '12345', last_payload: '')
|
||||
SingleSignOnRecord.create!(user_id: user.id, external_id: "12345", last_payload: "")
|
||||
user
|
||||
end
|
||||
|
||||
@@ -21,10 +21,10 @@ RSpec.describe WebHookUserSerializer do
|
||||
it "should include relevant user info" do
|
||||
payload = serializer.as_json
|
||||
expect(payload[:email]).to eq(user.email)
|
||||
expect(payload[:external_id]).to eq('12345')
|
||||
expect(payload[:external_id]).to eq("12345")
|
||||
end
|
||||
|
||||
it 'should only include the required keys' do
|
||||
it "should only include the required keys" do
|
||||
expect(serializer.as_json.keys).to contain_exactly(
|
||||
:id,
|
||||
:username,
|
||||
@@ -78,7 +78,7 @@ RSpec.describe WebHookUserSerializer do
|
||||
:featured_user_badge_ids,
|
||||
:invited_by,
|
||||
:groups,
|
||||
:user_option
|
||||
:user_option,
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -3,9 +3,7 @@
|
||||
RSpec.describe WizardSerializer do
|
||||
let(:admin) { Fabricate(:admin) }
|
||||
|
||||
after do
|
||||
ColorScheme.hex_cache.clear
|
||||
end
|
||||
after { ColorScheme.hex_cache.clear }
|
||||
|
||||
describe "color scheme" do
|
||||
it "works with base colors" do
|
||||
@@ -15,12 +13,19 @@ RSpec.describe WizardSerializer do
|
||||
serializer = WizardSerializer.new(wizard, scope: Guardian.new(admin))
|
||||
json = MultiJson.load(MultiJson.dump(serializer.as_json))
|
||||
|
||||
expect(json['wizard']['current_color_scheme'][0]['name']).to eq('primary')
|
||||
expect(json['wizard']['current_color_scheme'][0]['hex']).to eq('222222')
|
||||
expect(json["wizard"]["current_color_scheme"][0]["name"]).to eq("primary")
|
||||
expect(json["wizard"]["current_color_scheme"][0]["hex"]).to eq("222222")
|
||||
end
|
||||
|
||||
it "should provide custom colors correctly" do
|
||||
colors = ColorScheme.create_from_base(name: 'Customized', colors: { header_background: '00FF00', header_primary: '20CCFF' })
|
||||
colors =
|
||||
ColorScheme.create_from_base(
|
||||
name: "Customized",
|
||||
colors: {
|
||||
header_background: "00FF00",
|
||||
header_primary: "20CCFF",
|
||||
},
|
||||
)
|
||||
theme = Fabricate(:theme, color_scheme_id: colors.id)
|
||||
|
||||
SiteSetting.default_theme_id = theme.id
|
||||
@@ -31,7 +36,9 @@ RSpec.describe WizardSerializer do
|
||||
# serializer.as_json leaves in Ruby objects, force to true json
|
||||
json = MultiJson.load(MultiJson.dump(serializer.as_json))
|
||||
|
||||
expect(json['wizard']['current_color_scheme'].to_s).to include('{"name"=>"header_background", "hex"=>"00FF00"}')
|
||||
expect(json["wizard"]["current_color_scheme"].to_s).to include(
|
||||
'{"name"=>"header_background", "hex"=>"00FF00"}',
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -45,22 +52,22 @@ RSpec.describe WizardSerializer do
|
||||
SiteSetting.must_approve_users = true
|
||||
|
||||
json = MultiJson.load(MultiJson.dump(serializer.as_json))
|
||||
steps = json['wizard']['steps']
|
||||
steps = json["wizard"]["steps"]
|
||||
|
||||
expect(steps.first['id']).to eq('introduction')
|
||||
expect(steps.last['id']).to eq('corporate')
|
||||
expect(steps.first["id"]).to eq("introduction")
|
||||
expect(steps.last["id"]).to eq("corporate")
|
||||
|
||||
privacy_step = steps.find { |s| s['id'] == 'privacy' }
|
||||
privacy_step = steps.find { |s| s["id"] == "privacy" }
|
||||
expect(privacy_step).to_not be_nil
|
||||
|
||||
login_required_field = privacy_step['fields'].find { |f| f['id'] == 'login_required' }
|
||||
expect(login_required_field['value']).to eq(true)
|
||||
login_required_field = privacy_step["fields"].find { |f| f["id"] == "login_required" }
|
||||
expect(login_required_field["value"]).to eq(true)
|
||||
|
||||
invite_only_field = privacy_step['fields'].find { |f| f['id'] == 'invite_only' }
|
||||
expect(invite_only_field['value']).to eq(true)
|
||||
invite_only_field = privacy_step["fields"].find { |f| f["id"] == "invite_only" }
|
||||
expect(invite_only_field["value"]).to eq(true)
|
||||
|
||||
must_approve_users_field = privacy_step['fields'].find { |f| f['id'] == 'must_approve_users' }
|
||||
expect(must_approve_users_field['value']).to eq(true)
|
||||
must_approve_users_field = privacy_step["fields"].find { |f| f["id"] == "must_approve_users" }
|
||||
expect(must_approve_users_field["value"]).to eq(true)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user