mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-12-02 20:07:52 -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.
51 lines
1.6 KiB
Ruby
51 lines
1.6 KiB
Ruby
# encoding: UTF-8
|
|
|
|
require 'rails_helper'
|
|
require_dependency 'post_destroyer'
|
|
|
|
describe TopicStatusUpdate do
|
|
|
|
let(:user) { Fabricate(:user) }
|
|
let(:admin) { Fabricate(:admin) }
|
|
|
|
it "avoids notifying on automatically closed topics" do
|
|
# TODO: TopicStatusUpdate should supress message bus updates from the users it "pretends to read"
|
|
post = PostCreator.create(user,
|
|
raw: "this is a test post 123 this is a test post",
|
|
title: "hello world title",
|
|
)
|
|
# TODO needed so counts sync up, PostCreator really should not give back out-of-date Topic
|
|
post.topic.reload
|
|
|
|
TopicStatusUpdate.new(post.topic, admin).update!("autoclosed", true)
|
|
|
|
expect(post.topic.posts.count).to eq(2)
|
|
|
|
tu = TopicUser.find_by(user_id: user.id)
|
|
expect(tu.last_read_post_number).to eq(2)
|
|
end
|
|
|
|
it "adds an autoclosed message" do
|
|
topic = create_topic
|
|
|
|
TopicStatusUpdate.new(topic, admin).update!("autoclosed", true)
|
|
|
|
last_post = topic.posts.last
|
|
expect(last_post.post_type).to eq(Post.types[:small_action])
|
|
expect(last_post.action_code).to eq('autoclosed.enabled')
|
|
expect(last_post.raw).to eq(I18n.t("topic_statuses.autoclosed_enabled_minutes", count: 0))
|
|
end
|
|
|
|
it "adds an autoclosed message based on last post" do
|
|
topic = create_topic
|
|
topic.auto_close_based_on_last_post = true
|
|
|
|
TopicStatusUpdate.new(topic, admin).update!("autoclosed", true)
|
|
|
|
last_post = topic.posts.last
|
|
expect(last_post.post_type).to eq(Post.types[:small_action])
|
|
expect(last_post.action_code).to eq('autoclosed.enabled')
|
|
expect(last_post.raw).to eq(I18n.t("topic_statuses.autoclosed_enabled_lastpost_minutes", count: 0))
|
|
end
|
|
|
|
end
|