forked from hackorum-dev/hackorum
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnote_builder_spec.rb
More file actions
48 lines (39 loc) · 1.84 KB
/
note_builder_spec.rb
File metadata and controls
48 lines (39 loc) · 1.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
require "rails_helper"
RSpec.describe NoteBuilder do
let(:topic) { create(:topic) }
let(:message) { create(:message, topic: topic) }
let(:author) { create(:user, username: "alice") }
it "creates notes with mentions, tags, and activities" do
mentioned_user = create(:user, username: "bob")
team = create(:team, name: "team-two")
team_member = create(:user, username: "carl")
create(:team_member, team:, user: team_member)
note = described_class.new(author: author).create!(
topic:,
message:,
body: "Ping for review",
tags: %w[foo bar],
mention_names: %w[bob team-two]
)
expect(note.note_tags.pluck(:tag)).to match_array(%w[foo bar])
expect(note.note_mentions.map(&:mentionable)).to match_array([mentioned_user, team])
activity_users = Activity.where(subject: note).pluck(:user_id)
expect(activity_users).to include(author.id, mentioned_user.id, team_member.id)
expect(Activity.find_by(user: author, subject: note).activity_type).to eq("note_created")
expect(Activity.find_by(user: mentioned_user, subject: note).activity_type).to eq("note_mentioned")
end
it "updates mentions and hides removed recipients" do
bob = create(:user, username: "bob")
devs = create(:team, name: "devs")
dev_member = create(:user, username: "dave")
create(:team_member, team: devs, user: dev_member)
carol = create(:user, username: "carol")
builder = described_class.new(author: author)
note = builder.create!(topic:, message:, body: "Hi team", mention_names: %w[bob devs])
builder.update!(note:, body: "Hi friends", mention_names: %w[bob carol])
old_activity = Activity.find_by(user: dev_member, subject: note)
new_activity = Activity.find_by(user: carol, subject: note)
expect(old_activity.hidden).to eq(true)
expect(new_activity).to be_present
end
end