2016-04-05 15:12:02 -04:00
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
describe UserFirst do
|
|
|
|
|
|
|
|
let(:user) { Fabricate(:user) }
|
|
|
|
|
|
|
|
context "#create_for" do
|
|
|
|
it "doesn't raise an error on duplicate" do
|
|
|
|
expect(UserFirst.create_for(user.id, :used_emoji)).to eq(true)
|
|
|
|
expect(UserFirst.create_for(user.id, :used_emoji)).to eq(false)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-04-06 12:02:18 -04:00
|
|
|
context "emoji" do
|
|
|
|
it "logs a user first" do
|
|
|
|
post = PostCreator.create(user, title: "this topic is about candy", raw: "time to eat some sweet :candy: mmmm")
|
|
|
|
|
|
|
|
uf = UserFirst.where(user_id: user.id, first_type: UserFirst.types[:used_emoji]).first
|
|
|
|
expect(uf).to be_present
|
|
|
|
expect(uf.post_id).to eq(post.id)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "doesn't log a user first when in a quote" do
|
|
|
|
PostCreator.create(user,
|
|
|
|
title: "this topic is about candy",
|
|
|
|
raw: "time to eat some sweet [quote]:candy:[/quote] mmmm")
|
|
|
|
|
|
|
|
uf = UserFirst.where(user_id: user.id, first_type: UserFirst.types[:used_emoji]).first
|
|
|
|
expect(uf).to be_blank
|
|
|
|
end
|
2016-04-05 15:12:02 -04:00
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'mentioning' do
|
|
|
|
let(:codinghorror) { Fabricate(:codinghorror) }
|
|
|
|
|
|
|
|
it "creates one the first time a user mentions another" do
|
|
|
|
post = PostCreator.create(user, title: "gonna mention another user", raw: "what is up @codinghorror?")
|
|
|
|
uf = UserFirst.where(user_id: user.id, first_type: UserFirst.types[:mentioned_user]).first
|
|
|
|
expect(uf).to be_present
|
|
|
|
expect(uf.post_id).to eq(post.id)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-04-05 16:13:10 -04:00
|
|
|
context "privacy" do
|
|
|
|
let(:codinghorror) { Fabricate(:codinghorror) }
|
|
|
|
|
|
|
|
it "doesn't create the userfirst on private posts" do
|
2016-04-06 12:02:18 -04:00
|
|
|
PostCreator.create(user,
|
|
|
|
archetype: Archetype.private_message,
|
|
|
|
target_usernames: ['codinghorror'],
|
|
|
|
title: "this topic is about candy",
|
|
|
|
raw: "time to eat some sweet :candy: mmmm")
|
2016-04-05 16:13:10 -04:00
|
|
|
|
|
|
|
uf = UserFirst.where(user_id: user.id, first_type: UserFirst.types[:used_emoji]).first
|
|
|
|
expect(uf).to be_blank
|
|
|
|
end
|
|
|
|
end
|
2016-04-05 15:12:02 -04:00
|
|
|
end
|