2015-08-20 14:49:42 +00:00
|
|
|
# == Schema Information
|
|
|
|
#
|
|
|
|
# Table name: topics
|
|
|
|
#
|
|
|
|
# id :integer not null, primary key
|
2020-03-18 03:38:17 +00:00
|
|
|
# state :integer default("0"), not null
|
2015-08-20 14:49:42 +00:00
|
|
|
# title :string(255)
|
|
|
|
# created_at :datetime
|
|
|
|
# updated_at :datetime
|
2020-03-18 03:38:17 +00:00
|
|
|
# forum_id :integer
|
|
|
|
# user_id :integer
|
|
|
|
#
|
|
|
|
# Indexes
|
|
|
|
#
|
|
|
|
# index_topics_on_forum_id (forum_id)
|
|
|
|
# index_topics_on_user_id (user_id)
|
2015-08-20 14:49:42 +00:00
|
|
|
#
|
|
|
|
|
2020-03-23 02:10:31 +00:00
|
|
|
require "rails_helper"
|
2015-08-20 14:49:42 +00:00
|
|
|
|
|
|
|
describe Topic do
|
|
|
|
let!(:user) { create :user }
|
|
|
|
let!(:forum) { create :forum }
|
|
|
|
|
|
|
|
describe "create" do
|
|
|
|
let(:topic) { build :topic, user: user, forum: forum }
|
|
|
|
|
|
|
|
it "creates a new topic" do
|
|
|
|
topic.first_post = "Foo"
|
|
|
|
expect do
|
|
|
|
topic.save!
|
|
|
|
end.to change(Topic, :count).by(1)
|
|
|
|
end
|
|
|
|
end
|
2015-08-20 15:20:40 +00:00
|
|
|
|
|
|
|
describe ".recent_topics" do
|
2020-03-23 03:15:27 +00:00
|
|
|
# FIXME: this tests the wrong thing. The model returns by recent 5 posts
|
|
|
|
it "returns 5 unique, most recently posted topics" do
|
|
|
|
skip
|
|
|
|
topics = []
|
|
|
|
10.times do
|
|
|
|
topic = create :topic, first_post: "Foo"
|
|
|
|
topics.push(topic)
|
|
|
|
end
|
2020-03-25 01:13:38 +00:00
|
|
|
recent_topics = Topic.recent_topics
|
2020-03-23 03:15:27 +00:00
|
|
|
topics.last(5).each do |topic|
|
|
|
|
expect(recent_topics).to include(topic)
|
|
|
|
end
|
|
|
|
end
|
2020-03-23 02:10:31 +00:00
|
|
|
|
2015-08-20 18:33:22 +00:00
|
|
|
it "does not return posts from restricted forums" do
|
|
|
|
restricted_topic = create :topic, title: "Restricted"
|
|
|
|
create :forumer, forum: restricted_topic.forum
|
|
|
|
create :post, topic: restricted_topic
|
|
|
|
expect(Topic.recent_topics).to_not include(restricted_topic)
|
|
|
|
end
|
2015-08-20 15:20:40 +00:00
|
|
|
end
|
2015-08-20 14:49:42 +00:00
|
|
|
end
|