mirror of
https://github.com/discourse/discourse.git
synced 2024-11-23 19:01:52 +08:00
6261339da9
Note: All of this functionality is hidden behind a hidden, default false, site setting called `enable_bookmarks_with_reminders`. Also, any feedback on Ember code would be greatly appreciated! This is part 1 of the bookmark improvements. The next PR will address the backend logic to send reminder notifications for bookmarked posts to users. This PR adds the following functionality: * We are adding a new `bookmarks` table and `Bookmark` model to make the bookmarks a first-class citizen and to allow attaching reminders to them. * Posts now have a new button in their actions menu that has the icon of an actual book * Clicking the button opens the new bookmark modal. * Both name and the reminder type are optional. * If you close the modal without doing anything, the bookmark is saved with no reminder. * If you click the Cancel button, no bookmark is saved at all. * All of the reminder type tiles are dynamic and the times they show will be based on your user timezone set in your profile (this should already be set for you). * If for some reason a user does not have their timezone set they will not be able to set a reminder, but they will still be able to create a bookmark. * A bookmark can be deleted by clicking on the book icon again which will be red if the post is bookmarked. This PR does NOT do anything to migrate or change existing bookmarks in the form of `PostActions`, the two features live side-by-side here. Also this does nothing to the topic bookmarking.
48 lines
1.3 KiB
Ruby
48 lines
1.3 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
require 'rails_helper'
|
|
|
|
describe BookmarksController do
|
|
let(:current_user) { Fabricate(:user) }
|
|
let(:bookmark_post) { Fabricate(:post) }
|
|
|
|
before do
|
|
sign_in(current_user)
|
|
end
|
|
|
|
describe "#create" do
|
|
context "if the user already has bookmarked the post" do
|
|
before do
|
|
Fabricate(:bookmark, post: bookmark_post, user: current_user)
|
|
end
|
|
|
|
it "returns failed JSON with a 422 error" do
|
|
post "/bookmarks.json", params: {
|
|
post_id: bookmark_post.id,
|
|
reminder_type: "tomorrow",
|
|
reminder_at: (Time.now.utc + 1.day).iso8601
|
|
}
|
|
|
|
expect(response.status).to eq(422)
|
|
expect(JSON.parse(response.body)['errors']).to include(
|
|
I18n.t("bookmarks.errors.already_bookmarked_post")
|
|
)
|
|
end
|
|
end
|
|
|
|
context "if the user provides a reminder type that needs a reminder_at that is missing" do
|
|
it "returns failed JSON with a 400 error" do
|
|
post "/bookmarks.json", params: {
|
|
post_id: bookmark_post.id,
|
|
reminder_type: "tomorrow"
|
|
}
|
|
|
|
expect(response.status).to eq(400)
|
|
expect(JSON.parse(response.body)['errors'].first).to include(
|
|
I18n.t("bookmarks.errors.time_must_be_provided", reminder_type: I18n.t("bookmarks.reminders.at_desktop"))
|
|
)
|
|
end
|
|
end
|
|
end
|
|
end
|