mirror of
https://github.com/discourse/discourse.git
synced 2025-05-31 01:27:15 +08:00
DEV: Apply syntax_tree formatting to spec/*
This commit is contained in:
@ -15,7 +15,6 @@ RSpec.describe TopicUser do
|
||||
|
||||
describe "#unwatch_categories!" do
|
||||
it "correctly unwatches categories" do
|
||||
|
||||
op_topic = Fabricate(:topic)
|
||||
another_topic = Fabricate(:topic)
|
||||
tracked_topic = Fabricate(:topic)
|
||||
@ -24,7 +23,12 @@ RSpec.describe TopicUser do
|
||||
|
||||
TopicUser.change(user.id, op_topic, notification_level: watching)
|
||||
TopicUser.change(user.id, another_topic, notification_level: watching)
|
||||
TopicUser.change(user.id, tracked_topic, notification_level: watching, total_msecs_viewed: SiteSetting.default_other_auto_track_topics_after_msecs + 1)
|
||||
TopicUser.change(
|
||||
user.id,
|
||||
tracked_topic,
|
||||
notification_level: watching,
|
||||
total_msecs_viewed: SiteSetting.default_other_auto_track_topics_after_msecs + 1,
|
||||
)
|
||||
|
||||
TopicUser.unwatch_categories!(user, [Fabricate(:category).id, Fabricate(:category).id])
|
||||
expect(TopicUser.get(another_topic, user).notification_level).to eq(watching)
|
||||
@ -35,14 +39,11 @@ RSpec.describe TopicUser do
|
||||
expect(TopicUser.get(another_topic, user).notification_level).to eq(regular)
|
||||
expect(TopicUser.get(tracked_topic, user).notification_level).to eq(tracking)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe '#notification_levels' do
|
||||
describe "#notification_levels" do
|
||||
context "when verifying enum sequence" do
|
||||
before do
|
||||
@notification_levels = TopicUser.notification_levels
|
||||
end
|
||||
before { @notification_levels = TopicUser.notification_levels }
|
||||
|
||||
it "'muted' should be at 0 position" do
|
||||
expect(@notification_levels[:muted]).to eq(0)
|
||||
@ -54,11 +55,9 @@ RSpec.describe TopicUser do
|
||||
end
|
||||
end
|
||||
|
||||
describe '#notification_reasons' do
|
||||
describe "#notification_reasons" do
|
||||
context "when verifying enum sequence" do
|
||||
before do
|
||||
@notification_reasons = TopicUser.notification_reasons
|
||||
end
|
||||
before { @notification_reasons = TopicUser.notification_reasons }
|
||||
|
||||
it "'created_topic' should be at 1st position" do
|
||||
expect(@notification_reasons[:created_topic]).to eq(1)
|
||||
@ -75,19 +74,19 @@ RSpec.describe TopicUser do
|
||||
|
||||
fab!(:user) { Fabricate(:user) }
|
||||
|
||||
let(:topic) {
|
||||
let(:topic) do
|
||||
u = Fabricate(:user)
|
||||
guardian = Guardian.new(u)
|
||||
TopicCreator.create(u, guardian, title: "this is my topic title")
|
||||
}
|
||||
end
|
||||
let(:topic_user) { TopicUser.get(topic, user) }
|
||||
let(:topic_creator_user) { TopicUser.get(topic, topic.user) }
|
||||
|
||||
let(:new_user) {
|
||||
let(:new_user) do
|
||||
u = Fabricate(:user)
|
||||
u.user_option.update_columns(auto_track_topics_after_msecs: 1000)
|
||||
u
|
||||
}
|
||||
end
|
||||
|
||||
let(:topic_new_user) { TopicUser.get(topic, new_user) }
|
||||
let(:yesterday) { DateTime.now.yesterday }
|
||||
@ -103,14 +102,18 @@ RSpec.describe TopicUser do
|
||||
end
|
||||
end
|
||||
|
||||
describe 'notifications' do
|
||||
it 'should trigger the right DiscourseEvent' do
|
||||
describe "notifications" do
|
||||
it "should trigger the right DiscourseEvent" do
|
||||
called = false
|
||||
blk = Proc.new { called = true }
|
||||
begin
|
||||
DiscourseEvent.on(:topic_notification_level_changed, &blk)
|
||||
|
||||
TopicUser.change(user.id, topic.id, notification_level: TopicUser.notification_levels[:tracking])
|
||||
TopicUser.change(
|
||||
user.id,
|
||||
topic.id,
|
||||
notification_level: TopicUser.notification_levels[:tracking],
|
||||
)
|
||||
|
||||
expect(called).to eq(true)
|
||||
ensure
|
||||
@ -118,13 +121,15 @@ RSpec.describe TopicUser do
|
||||
end
|
||||
end
|
||||
|
||||
it 'should be set to tracking if auto_track_topics is enabled' do
|
||||
it "should be set to tracking if auto_track_topics is enabled" do
|
||||
user.user_option.update_column(:auto_track_topics_after_msecs, 0)
|
||||
ensure_topic_user
|
||||
expect(TopicUser.get(topic, user).notification_level).to eq(TopicUser.notification_levels[:tracking])
|
||||
expect(TopicUser.get(topic, user).notification_level).to eq(
|
||||
TopicUser.notification_levels[:tracking],
|
||||
)
|
||||
end
|
||||
|
||||
it 'should reset regular topics to tracking topics if auto track is changed' do
|
||||
it "should reset regular topics to tracking topics if auto track is changed" do
|
||||
ensure_topic_user
|
||||
user.user_option.auto_track_topics_after_msecs = 0
|
||||
user.user_option.save
|
||||
@ -133,43 +138,55 @@ RSpec.describe TopicUser do
|
||||
|
||||
it 'should be set to "regular" notifications, by default on non creators' do
|
||||
ensure_topic_user
|
||||
expect(TopicUser.get(topic, user).notification_level).to eq(TopicUser.notification_levels[:regular])
|
||||
expect(TopicUser.get(topic, user).notification_level).to eq(
|
||||
TopicUser.notification_levels[:regular],
|
||||
)
|
||||
end
|
||||
|
||||
it 'reason should reset when changed' do
|
||||
it "reason should reset when changed" do
|
||||
topic.notify_muted!(topic.user)
|
||||
expect(TopicUser.get(topic, topic.user).notifications_reason_id).to eq(TopicUser.notification_reasons[:user_changed])
|
||||
expect(TopicUser.get(topic, topic.user).notifications_reason_id).to eq(
|
||||
TopicUser.notification_reasons[:user_changed],
|
||||
)
|
||||
end
|
||||
|
||||
it 'should have the correct reason for a user change when watched' do
|
||||
it "should have the correct reason for a user change when watched" do
|
||||
topic.notify_watch!(user)
|
||||
expect(topic_user.notification_level).to eq(TopicUser.notification_levels[:watching])
|
||||
expect(topic_user.notifications_reason_id).to eq(TopicUser.notification_reasons[:user_changed])
|
||||
expect(topic_user.notifications_reason_id).to eq(
|
||||
TopicUser.notification_reasons[:user_changed],
|
||||
)
|
||||
expect(topic_user.notifications_changed_at).not_to eq(nil)
|
||||
end
|
||||
|
||||
it 'should have the correct reason for a user change when set to regular' do
|
||||
it "should have the correct reason for a user change when set to regular" do
|
||||
topic.notify_regular!(user)
|
||||
expect(topic_user.notification_level).to eq(TopicUser.notification_levels[:regular])
|
||||
expect(topic_user.notifications_reason_id).to eq(TopicUser.notification_reasons[:user_changed])
|
||||
expect(topic_user.notifications_reason_id).to eq(
|
||||
TopicUser.notification_reasons[:user_changed],
|
||||
)
|
||||
expect(topic_user.notifications_changed_at).not_to eq(nil)
|
||||
end
|
||||
|
||||
it 'should have the correct reason for a user change when set to regular' do
|
||||
it "should have the correct reason for a user change when set to regular" do
|
||||
topic.notify_muted!(user)
|
||||
expect(topic_user.notification_level).to eq(TopicUser.notification_levels[:muted])
|
||||
expect(topic_user.notifications_reason_id).to eq(TopicUser.notification_reasons[:user_changed])
|
||||
expect(topic_user.notifications_reason_id).to eq(
|
||||
TopicUser.notification_reasons[:user_changed],
|
||||
)
|
||||
expect(topic_user.notifications_changed_at).not_to eq(nil)
|
||||
end
|
||||
|
||||
it 'should watch topics a user created' do
|
||||
it "should watch topics a user created" do
|
||||
expect(topic_creator_user.notification_level).to eq(TopicUser.notification_levels[:watching])
|
||||
expect(topic_creator_user.notifications_reason_id).to eq(TopicUser.notification_reasons[:created_topic])
|
||||
expect(topic_creator_user.notifications_reason_id).to eq(
|
||||
TopicUser.notification_reasons[:created_topic],
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'visited at' do
|
||||
it 'set upon initial visit' do
|
||||
describe "visited at" do
|
||||
it "set upon initial visit" do
|
||||
freeze_time yesterday
|
||||
|
||||
TopicUser.track_visit!(topic.id, user.id)
|
||||
@ -178,7 +195,7 @@ RSpec.describe TopicUser do
|
||||
expect(topic_user.last_visited_at.to_i).to eq(yesterday.to_i)
|
||||
end
|
||||
|
||||
it 'updates upon repeat visit' do
|
||||
it "updates upon repeat visit" do
|
||||
freeze_time yesterday
|
||||
|
||||
TopicUser.track_visit!(topic.id, user.id)
|
||||
@ -193,11 +210,11 @@ RSpec.describe TopicUser do
|
||||
end
|
||||
end
|
||||
|
||||
describe 'read tracking' do
|
||||
describe "read tracking" do
|
||||
context "without auto tracking" do
|
||||
let(:topic_user) { TopicUser.get(topic, user) }
|
||||
|
||||
it 'should create a new record for a visit' do
|
||||
it "should create a new record for a visit" do
|
||||
freeze_time yesterday
|
||||
|
||||
TopicUser.update_last_read(user, topic.id, 1, 1, 0)
|
||||
@ -207,8 +224,7 @@ RSpec.describe TopicUser do
|
||||
expect(topic_user.first_visited_at.to_i).to eq(yesterday.to_i)
|
||||
end
|
||||
|
||||
it 'should update the record for repeat visit' do
|
||||
|
||||
it "should update the record for repeat visit" do
|
||||
today = Time.zone.now
|
||||
freeze_time Time.zone.now
|
||||
|
||||
@ -220,9 +236,8 @@ RSpec.describe TopicUser do
|
||||
Fabricate(:post, topic: topic, user: user)
|
||||
channel = TopicTrackingState.unread_channel_key(user.id)
|
||||
|
||||
messages = MessageBus.track_publish(channel) do
|
||||
TopicUser.update_last_read(user, topic.id, 2, 1, 0)
|
||||
end
|
||||
messages =
|
||||
MessageBus.track_publish(channel) { TopicUser.update_last_read(user, topic.id, 2, 1, 0) }
|
||||
|
||||
expect(messages.blank?).to eq(false)
|
||||
|
||||
@ -234,60 +249,58 @@ RSpec.describe TopicUser do
|
||||
end
|
||||
end
|
||||
|
||||
context 'with private messages' do
|
||||
context "with private messages" do
|
||||
fab!(:target_user) { Fabricate(:user) }
|
||||
|
||||
let(:post) do
|
||||
create_post(
|
||||
archetype: Archetype.private_message,
|
||||
target_usernames: target_user.username
|
||||
)
|
||||
create_post(archetype: Archetype.private_message, target_usernames: target_user.username)
|
||||
end
|
||||
|
||||
let(:topic) { post.topic }
|
||||
|
||||
it 'should ensure recipients and senders are watching' do
|
||||
expect(TopicUser.get(topic, post.user).notification_level)
|
||||
.to eq(TopicUser.notification_levels[:watching])
|
||||
it "should ensure recipients and senders are watching" do
|
||||
expect(TopicUser.get(topic, post.user).notification_level).to eq(
|
||||
TopicUser.notification_levels[:watching],
|
||||
)
|
||||
|
||||
expect(TopicUser.get(topic, target_user).notification_level)
|
||||
.to eq(TopicUser.notification_levels[:watching])
|
||||
expect(TopicUser.get(topic, target_user).notification_level).to eq(
|
||||
TopicUser.notification_levels[:watching],
|
||||
)
|
||||
end
|
||||
|
||||
it 'should ensure invited user is watching once visited' do
|
||||
it "should ensure invited user is watching once visited" do
|
||||
another_user = Fabricate(:user)
|
||||
topic.invite(target_user, another_user.username)
|
||||
TopicUser.track_visit!(topic.id, another_user.id)
|
||||
|
||||
expect(TopicUser.get(topic, another_user).notification_level)
|
||||
.to eq(TopicUser.notification_levels[:watching])
|
||||
expect(TopicUser.get(topic, another_user).notification_level).to eq(
|
||||
TopicUser.notification_levels[:watching],
|
||||
)
|
||||
|
||||
another_user = Fabricate(:user)
|
||||
TopicUser.track_visit!(topic.id, another_user.id)
|
||||
|
||||
expect(TopicUser.get(topic, another_user).notification_level)
|
||||
.to eq(TopicUser.notification_levels[:regular])
|
||||
expect(TopicUser.get(topic, another_user).notification_level).to eq(
|
||||
TopicUser.notification_levels[:regular],
|
||||
)
|
||||
end
|
||||
|
||||
it 'should publish the right message_bus message' do
|
||||
it "should publish the right message_bus message" do
|
||||
TopicUser.update_last_read(user, topic.id, 1, 1, 0)
|
||||
|
||||
Fabricate(:post, topic: topic, user: user)
|
||||
|
||||
channel = PrivateMessageTopicTrackingState.user_channel(user.id)
|
||||
|
||||
messages = MessageBus.track_publish(channel) do
|
||||
TopicUser.update_last_read(user, topic.id, 2, 1, 0)
|
||||
end
|
||||
messages =
|
||||
MessageBus.track_publish(channel) { TopicUser.update_last_read(user, topic.id, 2, 1, 0) }
|
||||
|
||||
expect(messages.blank?).to eq(false)
|
||||
end
|
||||
|
||||
describe 'inviting a group' do
|
||||
describe "inviting a group" do
|
||||
let(:group) do
|
||||
Fabricate(:group,
|
||||
default_notification_level: NotificationLevels.topic_levels[:tracking]
|
||||
)
|
||||
Fabricate(:group, default_notification_level: NotificationLevels.topic_levels[:tracking])
|
||||
end
|
||||
|
||||
it "should use group's default notification level" do
|
||||
@ -297,98 +310,161 @@ RSpec.describe TopicUser do
|
||||
Jobs.run_immediately!
|
||||
topic.invite_group(target_user, group)
|
||||
|
||||
expect(TopicUser.get(topic, another_user).notification_level)
|
||||
.to eq(TopicUser.notification_levels[:tracking])
|
||||
expect(TopicUser.get(topic, another_user).notification_level).to eq(
|
||||
TopicUser.notification_levels[:tracking],
|
||||
)
|
||||
|
||||
another_user = Fabricate(:user)
|
||||
topic.invite(target_user, another_user.username)
|
||||
TopicUser.track_visit!(topic.id, another_user.id)
|
||||
|
||||
expect(TopicUser.get(topic, another_user).notification_level)
|
||||
.to eq(TopicUser.notification_levels[:watching])
|
||||
expect(TopicUser.get(topic, another_user).notification_level).to eq(
|
||||
TopicUser.notification_levels[:watching],
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'with auto tracking' do
|
||||
let(:post_creator) { PostCreator.new(new_user, raw: Fabricate.build(:post).raw, topic_id: topic.id) }
|
||||
|
||||
before do
|
||||
TopicUser.update_last_read(new_user, topic.id, 2, 2, 0)
|
||||
context "with auto tracking" do
|
||||
let(:post_creator) do
|
||||
PostCreator.new(new_user, raw: Fabricate.build(:post).raw, topic_id: topic.id)
|
||||
end
|
||||
|
||||
it 'should automatically track topics you reply to' do
|
||||
before { TopicUser.update_last_read(new_user, topic.id, 2, 2, 0) }
|
||||
|
||||
it "should automatically track topics you reply to" do
|
||||
post_creator.create
|
||||
expect(topic_new_user.notification_level).to eq(TopicUser.notification_levels[:tracking])
|
||||
expect(topic_new_user.notifications_reason_id).to eq(TopicUser.notification_reasons[:created_post])
|
||||
expect(topic_new_user.notifications_reason_id).to eq(
|
||||
TopicUser.notification_reasons[:created_post],
|
||||
)
|
||||
end
|
||||
|
||||
it 'should update tracking state when you reply' do
|
||||
it "should update tracking state when you reply" do
|
||||
new_user.user_option.update_column(:notification_level_when_replying, 3)
|
||||
post_creator.create
|
||||
DB.exec("UPDATE topic_users set notification_level=2
|
||||
DB.exec(
|
||||
"UPDATE topic_users set notification_level=2
|
||||
WHERE topic_id = :topic_id AND user_id = :user_id",
|
||||
topic_id: topic_new_user.topic_id, user_id: topic_new_user.user_id)
|
||||
topic_id: topic_new_user.topic_id,
|
||||
user_id: topic_new_user.user_id,
|
||||
)
|
||||
|
||||
TopicUser.auto_notification(topic_new_user.user_id, topic_new_user.topic_id, TopicUser.notification_reasons[:created_post], TopicUser.notification_levels[:watching])
|
||||
TopicUser.auto_notification(
|
||||
topic_new_user.user_id,
|
||||
topic_new_user.topic_id,
|
||||
TopicUser.notification_reasons[:created_post],
|
||||
TopicUser.notification_levels[:watching],
|
||||
)
|
||||
|
||||
tu = TopicUser.find_by(user_id: topic_new_user.user_id, topic_id: topic_new_user.topic_id)
|
||||
expect(tu.notification_level).to eq(TopicUser.notification_levels[:watching])
|
||||
end
|
||||
|
||||
it 'should not update tracking state when you reply' do
|
||||
it "should not update tracking state when you reply" do
|
||||
new_user.user_option.update_column(:notification_level_when_replying, 3)
|
||||
post_creator.create
|
||||
DB.exec("UPDATE topic_users set notification_level=3
|
||||
WHERE topic_id = :topic_id AND user_id = :user_id", topic_id: topic_new_user.topic_id, user_id: topic_new_user.user_id)
|
||||
TopicUser.auto_notification(topic_new_user.user_id, topic_new_user.topic_id, TopicUser.notification_reasons[:created_post], TopicUser.notification_levels[:tracking])
|
||||
DB.exec(
|
||||
"UPDATE topic_users set notification_level=3
|
||||
WHERE topic_id = :topic_id AND user_id = :user_id",
|
||||
topic_id: topic_new_user.topic_id,
|
||||
user_id: topic_new_user.user_id,
|
||||
)
|
||||
TopicUser.auto_notification(
|
||||
topic_new_user.user_id,
|
||||
topic_new_user.topic_id,
|
||||
TopicUser.notification_reasons[:created_post],
|
||||
TopicUser.notification_levels[:tracking],
|
||||
)
|
||||
|
||||
tu = TopicUser.find_by(user_id: topic_new_user.user_id, topic_id: topic_new_user.topic_id)
|
||||
expect(tu.notification_level).to eq(TopicUser.notification_levels[:watching])
|
||||
end
|
||||
|
||||
it 'should not update tracking state when state manually set to normal you reply' do
|
||||
it "should not update tracking state when state manually set to normal you reply" do
|
||||
new_user.user_option.update_column(:notification_level_when_replying, 3)
|
||||
post_creator.create
|
||||
DB.exec("UPDATE topic_users set notification_level=1
|
||||
WHERE topic_id = :topic_id AND user_id = :user_id", topic_id: topic_new_user.topic_id, user_id: topic_new_user.user_id)
|
||||
TopicUser.auto_notification(topic_new_user.user_id, topic_new_user.topic_id, TopicUser.notification_reasons[:created_post], TopicUser.notification_levels[:tracking])
|
||||
DB.exec(
|
||||
"UPDATE topic_users set notification_level=1
|
||||
WHERE topic_id = :topic_id AND user_id = :user_id",
|
||||
topic_id: topic_new_user.topic_id,
|
||||
user_id: topic_new_user.user_id,
|
||||
)
|
||||
TopicUser.auto_notification(
|
||||
topic_new_user.user_id,
|
||||
topic_new_user.topic_id,
|
||||
TopicUser.notification_reasons[:created_post],
|
||||
TopicUser.notification_levels[:tracking],
|
||||
)
|
||||
|
||||
tu = TopicUser.find_by(user_id: topic_new_user.user_id, topic_id: topic_new_user.topic_id)
|
||||
expect(tu.notification_level).to eq(TopicUser.notification_levels[:regular])
|
||||
end
|
||||
|
||||
it 'should not update tracking state when state manually set to muted you reply' do
|
||||
it "should not update tracking state when state manually set to muted you reply" do
|
||||
new_user.user_option.update_column(:notification_level_when_replying, 3)
|
||||
post_creator.create
|
||||
DB.exec("UPDATE topic_users set notification_level=0
|
||||
WHERE topic_id = :topic_id AND user_id = :user_id", topic_id: topic_new_user.topic_id, user_id: topic_new_user.user_id)
|
||||
TopicUser.auto_notification(topic_new_user.user_id, topic_new_user.topic_id, TopicUser.notification_reasons[:created_post], TopicUser.notification_levels[:tracking])
|
||||
DB.exec(
|
||||
"UPDATE topic_users set notification_level=0
|
||||
WHERE topic_id = :topic_id AND user_id = :user_id",
|
||||
topic_id: topic_new_user.topic_id,
|
||||
user_id: topic_new_user.user_id,
|
||||
)
|
||||
TopicUser.auto_notification(
|
||||
topic_new_user.user_id,
|
||||
topic_new_user.topic_id,
|
||||
TopicUser.notification_reasons[:created_post],
|
||||
TopicUser.notification_levels[:tracking],
|
||||
)
|
||||
|
||||
tu = TopicUser.find_by(user_id: topic_new_user.user_id, topic_id: topic_new_user.topic_id)
|
||||
expect(tu.notification_level).to eq(TopicUser.notification_levels[:muted])
|
||||
end
|
||||
|
||||
it 'should not automatically track topics you reply to and have set state manually' do
|
||||
it "should not automatically track topics you reply to and have set state manually" do
|
||||
post_creator.create
|
||||
TopicUser.change(new_user, topic, notification_level: TopicUser.notification_levels[:regular])
|
||||
TopicUser.change(
|
||||
new_user,
|
||||
topic,
|
||||
notification_level: TopicUser.notification_levels[:regular],
|
||||
)
|
||||
expect(topic_new_user.notification_level).to eq(TopicUser.notification_levels[:regular])
|
||||
expect(topic_new_user.notifications_reason_id).to eq(TopicUser.notification_reasons[:user_changed])
|
||||
expect(topic_new_user.notifications_reason_id).to eq(
|
||||
TopicUser.notification_reasons[:user_changed],
|
||||
)
|
||||
end
|
||||
|
||||
it 'should automatically track topics after they are read for long enough' do
|
||||
it "should automatically track topics after they are read for long enough" do
|
||||
expect(topic_new_user.notification_level).to eq(TopicUser.notification_levels[:regular])
|
||||
TopicUser.update_last_read(new_user, topic.id, 2, 2, SiteSetting.default_other_auto_track_topics_after_msecs + 1)
|
||||
expect(TopicUser.get(topic, new_user).notification_level).to eq(TopicUser.notification_levels[:tracking])
|
||||
TopicUser.update_last_read(
|
||||
new_user,
|
||||
topic.id,
|
||||
2,
|
||||
2,
|
||||
SiteSetting.default_other_auto_track_topics_after_msecs + 1,
|
||||
)
|
||||
expect(TopicUser.get(topic, new_user).notification_level).to eq(
|
||||
TopicUser.notification_levels[:tracking],
|
||||
)
|
||||
end
|
||||
|
||||
it 'should not automatically track topics after they are read for long enough if changed manually' do
|
||||
TopicUser.change(new_user, topic, notification_level: TopicUser.notification_levels[:regular])
|
||||
TopicUser.update_last_read(new_user, topic, 2, 2, SiteSetting.default_other_auto_track_topics_after_msecs + 1)
|
||||
it "should not automatically track topics after they are read for long enough if changed manually" do
|
||||
TopicUser.change(
|
||||
new_user,
|
||||
topic,
|
||||
notification_level: TopicUser.notification_levels[:regular],
|
||||
)
|
||||
TopicUser.update_last_read(
|
||||
new_user,
|
||||
topic,
|
||||
2,
|
||||
2,
|
||||
SiteSetting.default_other_auto_track_topics_after_msecs + 1,
|
||||
)
|
||||
expect(topic_new_user.notification_level).to eq(TopicUser.notification_levels[:regular])
|
||||
end
|
||||
|
||||
it 'should not automatically track PMs' do
|
||||
it "should not automatically track PMs" do
|
||||
new_user.user_option.update!(auto_track_topics_after_msecs: 0)
|
||||
|
||||
another_user = Fabricate(:user)
|
||||
@ -398,15 +474,17 @@ RSpec.describe TopicUser do
|
||||
|
||||
TopicUser.track_visit!(pm.id, new_user.id)
|
||||
TopicUser.update_last_read(new_user, pm.id, 2, 2, 1000)
|
||||
expect(TopicUser.get(pm, new_user).notification_level).to eq(TopicUser.notification_levels[:watching])
|
||||
expect(TopicUser.get(pm, new_user).notification_level).to eq(
|
||||
TopicUser.notification_levels[:watching],
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'change a flag' do
|
||||
describe "change a flag" do
|
||||
it "only inserts a row once, even on repeated calls" do
|
||||
|
||||
topic; user
|
||||
topic
|
||||
user
|
||||
|
||||
expect {
|
||||
TopicUser.change(user, topic.id, total_msecs_viewed: 1)
|
||||
@ -415,25 +493,35 @@ RSpec.describe TopicUser do
|
||||
}.to change(TopicUser, :count).by(1)
|
||||
end
|
||||
|
||||
describe 'after creating a row' do
|
||||
before do
|
||||
ensure_topic_user
|
||||
end
|
||||
describe "after creating a row" do
|
||||
before { ensure_topic_user }
|
||||
|
||||
it 'has a lookup' do
|
||||
it "has a lookup" do
|
||||
expect(TopicUser.lookup_for(user, [topic])).to be_present
|
||||
end
|
||||
|
||||
it 'has a key in the lookup for this forum topic' do
|
||||
it "has a key in the lookup for this forum topic" do
|
||||
expect(TopicUser.lookup_for(user, [topic]).has_key?(topic.id)).to eq(true)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
it "can scope by tracking" do
|
||||
TopicUser.create!(user_id: 1, topic_id: 1, notification_level: TopicUser.notification_levels[:tracking])
|
||||
TopicUser.create!(user_id: 2, topic_id: 1, notification_level: TopicUser.notification_levels[:watching])
|
||||
TopicUser.create!(user_id: 3, topic_id: 1, notification_level: TopicUser.notification_levels[:regular])
|
||||
TopicUser.create!(
|
||||
user_id: 1,
|
||||
topic_id: 1,
|
||||
notification_level: TopicUser.notification_levels[:tracking],
|
||||
)
|
||||
TopicUser.create!(
|
||||
user_id: 2,
|
||||
topic_id: 1,
|
||||
notification_level: TopicUser.notification_levels[:watching],
|
||||
)
|
||||
TopicUser.create!(
|
||||
user_id: 3,
|
||||
topic_id: 1,
|
||||
notification_level: TopicUser.notification_levels[:regular],
|
||||
)
|
||||
|
||||
expect(TopicUser.tracking(1).count).to eq(2)
|
||||
expect(TopicUser.tracking(10).count).to eq(0)
|
||||
@ -444,18 +532,26 @@ RSpec.describe TopicUser do
|
||||
p2 = Fabricate(:post, user: p1.user, topic: p1.topic, post_number: 2)
|
||||
p1.topic.notifier.watch_topic!(p1.user_id)
|
||||
|
||||
DB.exec("UPDATE topic_users set last_read_post_number=0
|
||||
WHERE topic_id = :topic_id AND user_id = :user_id", topic_id: p1.topic_id, user_id: p1.user_id)
|
||||
DB.exec(
|
||||
"UPDATE topic_users set last_read_post_number=0
|
||||
WHERE topic_id = :topic_id AND user_id = :user_id",
|
||||
topic_id: p1.topic_id,
|
||||
user_id: p1.user_id,
|
||||
)
|
||||
|
||||
[p1, p2].each do |p|
|
||||
PostTiming.create(topic_id: p.topic_id, post_number: p.post_number, user_id: p.user_id, msecs: 100)
|
||||
PostTiming.create(
|
||||
topic_id: p.topic_id,
|
||||
post_number: p.post_number,
|
||||
user_id: p.user_id,
|
||||
msecs: 100,
|
||||
)
|
||||
end
|
||||
|
||||
TopicUser.ensure_consistency!
|
||||
|
||||
tu = TopicUser.find_by(user_id: p1.user_id, topic_id: p1.topic_id)
|
||||
expect(tu.last_read_post_number).to eq(p2.post_number)
|
||||
|
||||
end
|
||||
|
||||
describe "mailing_list_mode" do
|
||||
@ -494,10 +590,10 @@ RSpec.describe TopicUser do
|
||||
|
||||
called = 0
|
||||
visits = []
|
||||
user_first_visit = -> (topic_id, user_id) do
|
||||
user_first_visit = ->(topic_id, user_id) {
|
||||
visits << "#{topic_id}-#{user_id}"
|
||||
called += 1
|
||||
end
|
||||
}
|
||||
|
||||
DiscourseEvent.on(:topic_first_visited_by_user, &user_first_visit)
|
||||
|
||||
|
Reference in New Issue
Block a user