From 99d2e56846fac36d43c6d6c9c2444b413b90c129 Mon Sep 17 00:00:00 2001 From: Chris Blanchard Date: Thu, 20 Aug 2015 15:49:42 +0100 Subject: [PATCH] Add initial topic tests --- spec/factories/topic.rb | 5 +++++ spec/models/topic_spec.rb | 30 ++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 spec/factories/topic.rb create mode 100644 spec/models/topic_spec.rb diff --git a/spec/factories/topic.rb b/spec/factories/topic.rb new file mode 100644 index 0000000..159059b --- /dev/null +++ b/spec/factories/topic.rb @@ -0,0 +1,5 @@ +FactoryGirl.define do + factory :topic do + sequence(:title) { |n| "Forum Title #{n}" } + end +end \ No newline at end of file diff --git a/spec/models/topic_spec.rb b/spec/models/topic_spec.rb new file mode 100644 index 0000000..5cd81d1 --- /dev/null +++ b/spec/models/topic_spec.rb @@ -0,0 +1,30 @@ +# == Schema Information +# +# Table name: topics +# +# id :integer not null, primary key +# title :string(255) +# user_id :integer +# forum_id :integer +# created_at :datetime +# updated_at :datetime +# state :integer default(0), not null +# + +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 +end