ensl.org/spec/models/topic_spec.rb
Ari Timonen e59e8ac8e7 Lots of rails 4 updates
- Add .params to models and update controllers
- Add afk time to gather
- Reannotate models
- Fix rspec problem by using latest rspec plugins from github
2020-03-18 05:38:17 +02:00

55 lines
1.3 KiB
Ruby

# == Schema Information
#
# Table name: topics
#
# id :integer not null, primary key
# state :integer default("0"), not null
# title :string(255)
# created_at :datetime
# updated_at :datetime
# forum_id :integer
# user_id :integer
#
# Indexes
#
# index_topics_on_forum_id (forum_id)
# index_topics_on_user_id (user_id)
#
require "spec_helper"
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
describe ".recent_topics" do
it "returns 5 unique, most recently posted topics" do
topics = []
10.times do
topic = create :topic, first_post: "Foo"
topics.push(topic)
end
recent_topics = Topic.recent_topics
topics.last(5).each do |topic|
expect(recent_topics).to include(topic)
end
end
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
end
end