More refactorings and specs

This commit is contained in:
Marc Remolt
2011-06-05 13:38:39 +02:00
parent ddb65040a7
commit 76830ec51c
6 changed files with 94 additions and 22 deletions

View File

@@ -1,8 +1,7 @@
require 'spec_helper'
describe Refinery::WordPress::Dump, :type => :model do
let(:file_name) { File.realpath(File.join(File.dirname(__FILE__), '../../fixtures/wordpress_dump.xml')) }
let(:dump) { Refinery::WordPress::Dump.new(file_name) }
let(:dump) { test_dump }
it "should create a Dump object given a xml file" do
dump.should be_a Refinery::WordPress::Dump
@@ -46,6 +45,10 @@ describe Refinery::WordPress::Dump, :type => :model do
it "should return all included pages" do
dump.pages.should have(3).pages
end
it "should return only published pages with only_published=true" do
dump.pages(true).should have(2).pages
end
end
describe "#authors" do
@@ -58,5 +61,9 @@ describe Refinery::WordPress::Dump, :type => :model do
it "should return all posts" do
dump.posts.should have(3).posts
end
it "should return only published posts with only_published=true" do
dump.posts(true).should have(2).posts
end
end
end

View File

@@ -39,5 +39,67 @@ describe Refinery::WordPress::Page, :type => :model do
@page.parts.first.body.should == "#{simple_format(page.content)}"
end
end
describe "#format_paragraphs" do
let(:sample_text) do
text = <<-EOT
This is sample text.
Even more text.
But this time no paragraph.
EOT
end
before do
@result = page.send(:format_paragraphs, sample_text)
end
it "should add paragraphs to the sample text" do
@result.should include('<p>')
@result.should include('</p>')
end
end
describe "#format_syntax_highlighter" do
let(:sample_text) do
text = <<-EOT
This is sample text.
[ruby]
p "this is ruby code"
[/ruby]
This is more sample text.
EOT
end
before do
@result = page.send(:format_syntax_highlighter, sample_text)
end
it "should reformat the [ruby] tag to a pre with correct class" do
@result.should match(/<pre class="brush: ruby">/)
@result.should include('</pre>')
end
context "without correct code tags" do
let(:sample_text) do
text = <<-EOT
This is sample text.
[ruby]
p "this is ruby code"
[/php]
This is more sample text.
EOT
end
it "should not reformat the [ruby] tag" do
@result.should == sample_text
end
end
end
end

View File

@@ -1,7 +1,7 @@
require 'spec_helper'
describe Refinery::WordPress::Post, :type => :model do
let(:post) { test_dump.posts.last }
let(:post) { test_dump.posts.last }
it { post.title.should == 'Third blog post' }
it { post.content.should include('Lorem ipsum dolor sit') }