* Initial automatic cleanup with rubocop * Fix syntax error introduced by rubocop * Cleanup seeds file * Cleanup lib folder * Exclude bin folder because it contains auto generated files * Make Rubocop a little bit more chatty * Block length should not include comments in the count * Cleanup config folder * Cleanup specs * Updated Rubocop version and generated a todo file * Fix broken ArticlesApi spec * Fix tests * Restored rubocop pre-commit hook
78 lines
2.6 KiB
Ruby
78 lines
2.6 KiB
Ruby
# rubocop:disable RSpec/ExampleLength, RSpec/MultipleExpectations
|
|
require "rails_helper"
|
|
|
|
RSpec.describe Mention, type: :model do
|
|
let(:user) { create(:user) }
|
|
let(:article) { create(:article, user_id: user.id) }
|
|
let(:comment) { create(:comment, user_id: user.id, commentable_id: article.id) }
|
|
let(:comment2) do
|
|
create(
|
|
:comment,
|
|
body_markdown: "Hello @#{user.username}, you are cool.",
|
|
user_id: user.id,
|
|
commentable_id: article.id,
|
|
)
|
|
end
|
|
|
|
before do
|
|
# Run workers synchronously
|
|
# Delayed::Worker.delay_jobs = false
|
|
end
|
|
|
|
it "creates mention if there is a user mentioned" do
|
|
comment.body_markdown = "Hello @#{user.username}, you are cool."
|
|
comment.save
|
|
Mention.create_all_without_delay(comment)
|
|
expect(Mention.all.size).to eq(1)
|
|
end
|
|
|
|
it "deletes mention if deleted from comment" do
|
|
comment.body_markdown = "Hello @#{user.username}, you are cool."
|
|
comment.save
|
|
Mention.create_all_without_delay(comment)
|
|
expect(Mention.all.size).to eq(1)
|
|
comment.body_markdown = "Hello, you are cool."
|
|
comment.save
|
|
Mention.create_all_without_delay(comment)
|
|
expect(Mention.all.size).to eq(0)
|
|
end
|
|
|
|
it "creates one mention even if multiple mentions of same user" do
|
|
comment.body_markdown = "Hello @#{user.username} @#{user.username} @#{user.username}, you rock."
|
|
comment.save
|
|
Mention.create_all_without_delay(comment)
|
|
expect(Mention.all.size).to eq(1)
|
|
end
|
|
|
|
it "creates multiple mentions for multiple users" do
|
|
user2 = create(:user)
|
|
comment.body_markdown = "Hello @#{user.username} @#{user2.username}, you are cool."
|
|
comment.save
|
|
Mention.create_all_without_delay(comment)
|
|
expect(Mention.all.size).to eq(2)
|
|
end
|
|
|
|
it "deletes one of multiple mentions if one of multiple is deleted" do
|
|
user2 = create(:user)
|
|
comment.body_markdown = "Hello @#{user.username} @#{user2.username}, you are cool."
|
|
comment.save
|
|
Mention.create_all_without_delay(comment)
|
|
expect(Mention.all.size).to eq(2)
|
|
comment.body_markdown = "Hello @#{user2.username}, you are cool."
|
|
comment.save
|
|
Mention.create_all_without_delay(comment)
|
|
expect(Mention.all.size).to eq(1)
|
|
end
|
|
|
|
it "creates mention on creation of comment (in addition to update)" do
|
|
Mention.create_all_without_delay(comment2)
|
|
expect(Mention.all.size).to eq(1)
|
|
end
|
|
|
|
it "can only be created with valid mentionable" do
|
|
comment2.update_column(:body_markdown, "")
|
|
Mention.create_all_without_delay(comment2)
|
|
expect(Mention.all.size).to eq(0)
|
|
end
|
|
end
|
|
# rubocop:enable RSpec/ExampleLength, RSpec/MultipleExpectations
|