2015-04-07 04:02:10 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe AnonymousShadowCreator do
|
|
|
|
|
|
|
|
it "returns no shadow by default" do
|
2015-04-25 11:18:35 -04:00
|
|
|
expect(AnonymousShadowCreator.get(Fabricate.build(:user))).to eq(nil)
|
2015-04-07 04:02:10 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "returns no shadow if trust level is not met" do
|
|
|
|
SiteSetting.allow_anonymous_posting = true
|
2015-04-25 11:18:35 -04:00
|
|
|
expect(AnonymousShadowCreator.get(Fabricate.build(:user, trust_level: 0))).to eq(nil)
|
2015-04-07 04:02:10 -04:00
|
|
|
end
|
|
|
|
|
2015-04-07 22:29:43 -04:00
|
|
|
it "returns a new shadow once time expires" do
|
|
|
|
SiteSetting.allow_anonymous_posting = true
|
|
|
|
SiteSetting.anonymous_account_duration_minutes = 1
|
|
|
|
|
|
|
|
user = Fabricate(:user, trust_level: 3)
|
|
|
|
shadow = AnonymousShadowCreator.get(user)
|
|
|
|
|
|
|
|
freeze_time 2.minutes.from_now
|
|
|
|
shadow2 = AnonymousShadowCreator.get(user)
|
|
|
|
|
2015-04-25 11:18:35 -04:00
|
|
|
expect(shadow.id).to eq(shadow2.id)
|
2015-04-07 22:29:43 -04:00
|
|
|
create_post(user: shadow)
|
|
|
|
|
|
|
|
freeze_time 4.minutes.from_now
|
|
|
|
shadow3 = AnonymousShadowCreator.get(user)
|
|
|
|
|
2015-04-25 11:18:35 -04:00
|
|
|
expect(shadow2.id).not_to eq(shadow3.id)
|
2015-04-07 22:29:43 -04:00
|
|
|
|
|
|
|
end
|
|
|
|
|
2015-04-07 04:02:10 -04:00
|
|
|
it "returns a shadow for a legit user" do
|
|
|
|
SiteSetting.allow_anonymous_posting = true
|
|
|
|
user = Fabricate(:user, trust_level: 3)
|
|
|
|
|
|
|
|
shadow = AnonymousShadowCreator.get(user)
|
|
|
|
shadow2 = AnonymousShadowCreator.get(user)
|
|
|
|
|
2015-04-25 11:18:35 -04:00
|
|
|
expect(shadow.id).to eq(shadow2.id)
|
2015-04-07 04:02:10 -04:00
|
|
|
|
2015-04-25 11:18:35 -04:00
|
|
|
expect(shadow.trust_level).to eq(1)
|
|
|
|
expect(shadow.username).to eq("anonymous")
|
2015-04-07 04:02:10 -04:00
|
|
|
|
2015-04-25 11:18:35 -04:00
|
|
|
expect(shadow.created_at).not_to eq(user.created_at)
|
2015-04-07 22:29:43 -04:00
|
|
|
|
|
|
|
|
|
|
|
p = create_post
|
2015-04-25 11:18:35 -04:00
|
|
|
expect(Guardian.new(shadow).post_can_act?(p, :like)).to eq(false)
|
|
|
|
expect(Guardian.new(user).post_can_act?(p, :like)).to eq(true)
|
2015-04-07 22:29:43 -04:00
|
|
|
|
2015-04-25 11:18:35 -04:00
|
|
|
expect(user.anonymous?).to eq(false)
|
|
|
|
expect(shadow.anonymous?).to eq(true)
|
2015-04-07 04:02:10 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|