Converted to factory_girl use, a little refactored

This commit is contained in:
Joe Sak 2010-08-09 14:05:16 -05:00
parent 4a25cde49f
commit be4c8c3836
6 changed files with 59 additions and 10 deletions

View file

@ -0,0 +1,4 @@
Factory.define(:blog_category) do |f|
f.title "Shopping"
f.posts {|p| [p.association :post]}
end

View file

@ -0,0 +1,10 @@
Factory.sequence :email do |n|
"person#{n}@example.com"
end
Factory.define(:blog_comment) do |f|
f.name "Joe Commenter"
f.email { Factory.next(:email) }
f.body "Which one is the best for picking up new shoes?"
f.association :post
end

View file

@ -0,0 +1,4 @@
Factory.define(:post, :class => BlogPost) do |f|
f.title "Top Ten Shopping Centers in Chicago"
f.body "These are the top ten shopping centers in Chicago. You're going to read a long blog post about them. Come to peace with it."
end

View file

@ -1,8 +1,20 @@
require 'spec_helper' require 'spec_helper'
describe BlogCategory do describe BlogCategory do
it "initializes" do context "wiring up" do
blog = BlogCategory.new
blog.should_not be_nil before(:each) do
@category = Factory(:blog_category)
end
it "saves" do
@category.should_not be_nil
end
it "has a blog post" do
BlogPost.last.categories.should include(@category)
end
end end
end end

View file

@ -1,8 +1,20 @@
require 'spec_helper' require 'spec_helper'
describe BlogComment do describe BlogComment do
it "initializes" do
blog = BlogComment.new context "wiring up" do
blog.should_not be_nil
before(:each) do
@comment = Factory(:blog_comment)
end
it "saves" do
@comment.should_not be_nil
end
it "has a blog post" do
@comment.post.should_not be_nil
end
end end
end end

View file

@ -1,8 +1,15 @@
require 'spec_helper' require 'spec_helper'
describe BlogPost do describe BlogPost do
it "initializes" do context "wiring up" do
blog = BlogPost.new
blog.should_not be_nil before(:each) do
end @post = Factory(:post)
end
it "saves to the database" do
@post.should_not be_nil
end
end
end end