discourse/spec/services/anonymous_shadow_creator_spec.rb
Arthur Neves b8cbe51026
Convert specs to RSpec 2.99.2 syntax with Transpec
This conversion is done by Transpec 3.1.0 with the following command:
    transpec

* 424 conversions
    from: obj.should
      to: expect(obj).to

* 325 conversions
    from: == expected
      to: eq(expected)

* 38 conversions
    from: obj.should_not
      to: expect(obj).not_to

* 15 conversions
    from: =~ /pattern/
      to: match(/pattern/)

* 9 conversions
    from: it { should ... }
      to: it { is_expected.to ... }

* 5 conversions
    from: lambda { }.should_not
      to: expect { }.not_to

* 4 conversions
    from: lambda { }.should
      to: expect { }.to

* 2 conversions
    from: -> { }.should
      to: expect { }.to

* 2 conversions
    from: -> { }.should_not
      to: expect { }.not_to

* 1 conversion
    from: === expected
      to: be === expected

* 1 conversion
    from: =~ [1, 2]
      to: match_array([1, 2])

For more details: https://github.com/yujinakayama/transpec#supported-conversions
2015-04-25 11:18:35 -04:00

57 lines
1.5 KiB
Ruby

require 'spec_helper'
describe AnonymousShadowCreator do
it "returns no shadow by default" do
expect(AnonymousShadowCreator.get(Fabricate.build(:user))).to eq(nil)
end
it "returns no shadow if trust level is not met" do
SiteSetting.allow_anonymous_posting = true
expect(AnonymousShadowCreator.get(Fabricate.build(:user, trust_level: 0))).to eq(nil)
end
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)
expect(shadow.id).to eq(shadow2.id)
create_post(user: shadow)
freeze_time 4.minutes.from_now
shadow3 = AnonymousShadowCreator.get(user)
expect(shadow2.id).not_to eq(shadow3.id)
end
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)
expect(shadow.id).to eq(shadow2.id)
expect(shadow.trust_level).to eq(1)
expect(shadow.username).to eq("anonymous")
expect(shadow.created_at).not_to eq(user.created_at)
p = create_post
expect(Guardian.new(shadow).post_can_act?(p, :like)).to eq(false)
expect(Guardian.new(user).post_can_act?(p, :like)).to eq(true)
expect(user.anonymous?).to eq(false)
expect(shadow.anonymous?).to eq(true)
end
end