mirror of
https://github.com/discourse/discourse.git
synced 2024-11-25 09:37:16 +08: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.
58 lines
1.7 KiB
Ruby
58 lines
1.7 KiB
Ruby
require 'rails_helper'
|
|
require 'pinned_check'
|
|
|
|
describe PinnedCheck do
|
|
|
|
let(:pinned_at) { 12.hours.ago }
|
|
let(:unpinned_topic) { Fabricate.build(:topic) }
|
|
let(:pinned_topic) { Fabricate.build(:topic, pinned_at: pinned_at) }
|
|
|
|
context "without a topic_user record (either anonymous or never been in the topic)" do
|
|
|
|
it "returns false if the topic is not pinned" do
|
|
expect(PinnedCheck.pinned?(unpinned_topic)).to eq(false)
|
|
end
|
|
|
|
it "returns true if the topic is pinned" do
|
|
expect(PinnedCheck.pinned?(unpinned_topic)).to eq(false)
|
|
end
|
|
|
|
end
|
|
|
|
context "with a topic_user record" do
|
|
let(:user) { Fabricate.build(:user) }
|
|
let(:unpinned_topic_user) { Fabricate.build(:topic_user, user: user, topic: unpinned_topic) }
|
|
|
|
describe "unpinned topic" do
|
|
let(:topic_user) { TopicUser.new(topic: unpinned_topic, user: user) }
|
|
|
|
it "returns false" do
|
|
expect(PinnedCheck.pinned?(unpinned_topic, topic_user)).to eq(false)
|
|
end
|
|
|
|
end
|
|
|
|
describe "pinned topic" do
|
|
let(:topic_user) { TopicUser.new(topic: pinned_topic, user: user) }
|
|
|
|
it "is pinned if the topic_user's cleared_pinned_at is blank" do
|
|
expect(PinnedCheck.pinned?(pinned_topic, topic_user)).to eq(true)
|
|
end
|
|
|
|
it "is not pinned if the topic_user's cleared_pinned_at is later than when it was pinned_at" do
|
|
topic_user.cleared_pinned_at = (pinned_at + 1.hour)
|
|
expect(PinnedCheck.pinned?(pinned_topic, topic_user)).to eq(false)
|
|
end
|
|
|
|
it "is pinned if the topic_user's cleared_pinned_at is earlier than when it was pinned_at" do
|
|
topic_user.cleared_pinned_at = (pinned_at - 3.hours)
|
|
expect(PinnedCheck.pinned?(pinned_topic, topic_user)).to eq(true)
|
|
end
|
|
end
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|