mirror of
https://github.com/discourse/discourse.git
synced 2024-11-27 00:23:41 +08:00
628ba9d1e2
The main thrust of this PR is to take all the conditional checks based on the `enable_bookmarks_with_reminders` away and only keep the code from the `true` path, making bookmarks with reminders the core bookmarks feature. There is also a migration to create `Bookmark` records out of `PostAction` bookmarks for a site. ### Summary * Remove logic based on whether enable_bookmarks_with_reminders is true. This site setting is now obsolete, the old bookmark functionality is being removed. Retain the setting and set the value to `true` in a migration. * Use the code from the rake task to create a database migration that creates bookmarks from post actions. * Change the bookmark report to read from the new table. * Get rid of old endpoints for bookmarks * Link to the new bookmarks list from the user summary page
58 lines
1.6 KiB
Ruby
58 lines
1.6 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
require 'rails_helper'
|
|
|
|
RSpec.describe "bookmarks tasks" do
|
|
let(:user1) { Fabricate(:user) }
|
|
let(:user2) { Fabricate(:user) }
|
|
let(:user3) { Fabricate(:user) }
|
|
let(:post1) { Fabricate(:post) }
|
|
let(:post2) { Fabricate(:post) }
|
|
let(:post3) { Fabricate(:post) }
|
|
|
|
before do
|
|
Rake::Task.clear
|
|
Discourse::Application.load_tasks
|
|
|
|
create_post_actions_and_existing_bookmarks
|
|
end
|
|
|
|
def invoke_task(args = nil)
|
|
capture_stdout do
|
|
Rake::Task['bookmarks:sync_to_table'].invoke(args)
|
|
end
|
|
end
|
|
|
|
it "migrates all PostActions" do
|
|
invoke_task
|
|
|
|
expect(Bookmark.all.count).to eq(3)
|
|
end
|
|
|
|
it "does not create bookmarks that already exist in the bookmarks table for a user" do
|
|
Fabricate(:bookmark, user: user1, post: post1)
|
|
|
|
invoke_task
|
|
|
|
expect(Bookmark.all.count).to eq(3)
|
|
expect(Bookmark.where(post: post1, user: user1).count).to eq(1)
|
|
end
|
|
|
|
it "skips post actions where the post topic no longer exists and does not error" do
|
|
post1.topic.delete
|
|
post1.reload
|
|
expect { invoke_task }.not_to raise_error
|
|
end
|
|
|
|
it "skips post actions where the post no longer exists and does not error" do
|
|
post1.delete
|
|
expect { invoke_task }.not_to raise_error
|
|
end
|
|
|
|
def create_post_actions_and_existing_bookmarks
|
|
Fabricate(:post_action, user: user1, post: post1, post_action_type_id: PostActionType.types[:bookmark])
|
|
Fabricate(:post_action, user: user2, post: post2, post_action_type_id: PostActionType.types[:bookmark])
|
|
Fabricate(:post_action, user: user3, post: post3, post_action_type_id: PostActionType.types[:bookmark])
|
|
end
|
|
end
|