From af57fea63396ddf7196604e9e09b6803cdc6aa24 Mon Sep 17 00:00:00 2001 From: Chris Blanchard Date: Thu, 20 Aug 2015 15:57:29 +0100 Subject: [PATCH] Add initial tests for posts --- spec/factories/post.rb | 7 +++++++ spec/models/post_spec.rb | 30 ++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 spec/factories/post.rb create mode 100644 spec/models/post_spec.rb diff --git a/spec/factories/post.rb b/spec/factories/post.rb new file mode 100644 index 0000000..ec0de0b --- /dev/null +++ b/spec/factories/post.rb @@ -0,0 +1,7 @@ +FactoryGirl.define do + factory :post do + sequence(:text) { |n| "Post Body #{n}" } + topic + user + end +end \ No newline at end of file diff --git a/spec/models/post_spec.rb b/spec/models/post_spec.rb new file mode 100644 index 0000000..9ef6175 --- /dev/null +++ b/spec/models/post_spec.rb @@ -0,0 +1,30 @@ +# == Schema Information +# +# Table name: posts +# +# id :integer not null, primary key +# text :text +# topic_id :integer +# user_id :integer +# created_at :datetime +# updated_at :datetime +# text_parsed :text +# + +require "spec_helper" + +describe Post do + let!(:user) { create :user } + + describe "create" do + let(:post) { build :post } + + it "creates a new post" do + # expect(post.valid?).to eq(true) + post.topic = create :topic + expect do + post.save! + end.to change(Post, :count).by(1) + end + end +end