mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-27 09:36:19 -05:00
3e50313fdc
Since rspec-rails 3, the default installation creates two helper files: * `spec_helper.rb` * `rails_helper.rb` `spec_helper.rb` is intended as a way of running specs that do not require Rails, whereas `rails_helper.rb` loads Rails (as Discourse's current `spec_helper.rb` does). For more information: https://www.relishapp.com/rspec/rspec-rails/docs/upgrade#default-helper-files In this commit, I've simply replaced all instances of `spec_helper` with `rails_helper`, and renamed the original `spec_helper.rb`. This brings the Discourse project closer to the standard usage of RSpec in a Rails app. At present, every spec relies on loading Rails, but there are likely many that don't need to. In a future pull request, I hope to introduce a separate, minimal `spec_helper.rb` which can be used in tests which don't rely on Rails.
65 lines
1.7 KiB
Ruby
65 lines
1.7 KiB
Ruby
require 'rails_helper'
|
|
|
|
describe AnonymousShadowCreator do
|
|
|
|
it "returns no shadow by default" do
|
|
expect(AnonymousShadowCreator.get(Fabricate.build(:user))).to eq(nil)
|
|
end
|
|
|
|
context "Anonymous posting is enabled" do
|
|
|
|
before { SiteSetting.allow_anonymous_posting = true }
|
|
|
|
let(:user) { Fabricate(:user, trust_level: 3) }
|
|
|
|
it "returns no shadow if trust level is not met" do
|
|
expect(AnonymousShadowCreator.get(Fabricate.build(:user, trust_level: 0))).to eq(nil)
|
|
end
|
|
|
|
it "returns a new shadow once time expires" do
|
|
SiteSetting.anonymous_account_duration_minutes = 1
|
|
|
|
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
|
|
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
|
|
|
|
it "works even when names are required" do
|
|
SiteSetting.full_name_required = true
|
|
|
|
expect { AnonymousShadowCreator.get(user) }.to_not raise_error
|
|
end
|
|
|
|
end
|
|
|
|
end
|