wordpress-import/spec/lib/wordpress/post_spec.rb
Marc Remolt 9a2b5acef6 Spec improvements
* replaced it with specify on {...} blocks
2011-06-05 17:55:00 +02:00

117 lines
3.8 KiB
Ruby

require 'spec_helper'
describe Refinery::WordPress::Post, :type => :model do
let(:post) { test_dump.posts.last }
specify { post.title.should == 'Third blog post' }
specify { post.content.should include('Lorem ipsum dolor sit') }
specify { post.content_formatted.should include('Lorem ipsum dolor sit') }
specify { post.creator.should == 'admin' }
specify { post.post_date.should == DateTime.new(2011, 5, 21, 12, 24, 45) }
specify { post.post_id.should == 6 }
specify { post.parent_id.should == nil }
specify { post.status.should == 'publish' }
specify { post.should == test_dump.posts.last }
specify { post.should_not == test_dump.posts.first }
describe "#categories" do
specify { post.categories.should have(1).category }
specify { post.categories.first.should == Refinery::WordPress::Category.new('Rant') }
end
describe "#tags" do
specify { post.tags.should have(3).tags }
specify { post.tags.should include(Refinery::WordPress::Tag.new('css')) }
specify { post.tags.should include(Refinery::WordPress::Tag.new('html')) }
specify { post.tags.should include(Refinery::WordPress::Tag.new('php')) }
end
specify { post.tag_list.should == 'css,html,php' }
describe "#comments" do
it "should return all attached comments" do
post.comments.should have(2).comments
end
context "the last comment" do
let(:comment) { post.comments.last }
specify { comment.author.should == 'admin' }
specify { comment.email.should == 'admin@example.com' }
specify { comment.url.should == 'http://www.example.com/' }
specify { comment.date.should == DateTime.new(2011, 5, 21, 12, 26, 30) }
specify { comment.content.should include('Another one!') }
specify { comment.should be_approved }
specify { comment.should == post.comments.last }
describe "#to_refinery" do
before do
@comment = comment.to_refinery
end
it "should not save the comment, only initialize it" do
BlogComment.should have(0).records
@comment.should be_new_record
end
it "should copy the attributes from Refinery::WordPress::Comment" do
@comment.name.should == comment.author
@comment.email.should == comment.email
@comment.body.should == comment.content
@comment.state.should == 'approved'
@comment.created_at.should == comment.date
end
end
end
end
describe "#to_refinery" do
before do
@user = User.create! :username => 'admin', :email => 'admin@example.com',
:password => 'password', :password_confirmation => 'password'
end
context "with a unique title" do
before do
@post = post.to_refinery
end
specify { BlogPost.should have(1).record }
it "should copy the attributes from Refinery::WordPress::Post" do
@post.title.should == post.title
@post.body.should == post.content_formatted
@post.draft.should == post.draft?
@post.published_at.should == post.post_date
@post.created_at.should == post.post_date
@post.author.username.should == post.creator
end
it "should assign a category for each Refinery::WordPress::Category" do
@post.categories.should have(post.categories.count).records
end
it "should assign a comment for each Refinery::WordPress::Comment" do
@post.comments.should have(post.comments.count).records
end
end
context "with a duplicate title" do
before do
BlogPost.create! :title => post.title, :body => 'Lorem', :author => @user
@post = post.to_refinery
end
specify { BlogPost.should have(2).records }
it "should create the BlogPost with #post_id attached" do
@post.title.should == "#{post.title}-#{post.post_id}"
end
end
end
end