Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
814c7b4ca8 | ||
|
|
c7c76a709b | ||
|
|
76830ec51c | ||
|
|
ddb65040a7 | ||
|
|
e1c60163e4 | ||
|
|
dacd503d8f | ||
|
|
96a81d7b01 | ||
|
|
a97c2968ab |
@@ -51,7 +51,7 @@ GEM
|
|||||||
orm_adapter (~> 0.0.3)
|
orm_adapter (~> 0.0.3)
|
||||||
warden (~> 1.0.3)
|
warden (~> 1.0.3)
|
||||||
diff-lcs (1.1.2)
|
diff-lcs (1.1.2)
|
||||||
dragonfly (0.9.2)
|
dragonfly (0.9.3)
|
||||||
rack
|
rack
|
||||||
erubis (2.6.6)
|
erubis (2.6.6)
|
||||||
abstract (>= 1.0.0)
|
abstract (>= 1.0.0)
|
||||||
@@ -125,7 +125,7 @@ GEM
|
|||||||
will_paginate (~> 3.0.pre)
|
will_paginate (~> 3.0.pre)
|
||||||
refinerycms-dashboard (1.0.0)
|
refinerycms-dashboard (1.0.0)
|
||||||
refinerycms-core (= 1.0.0)
|
refinerycms-core (= 1.0.0)
|
||||||
refinerycms-generators (1.0.1)
|
refinerycms-generators (1.0.2)
|
||||||
refinerycms-images (1.0.0)
|
refinerycms-images (1.0.0)
|
||||||
dragonfly (~> 0.9.0)
|
dragonfly (~> 0.9.0)
|
||||||
rack-cache (>= 0.5.3)
|
rack-cache (>= 0.5.3)
|
||||||
|
|||||||
56
README.rdoc
56
README.rdoc
@@ -2,19 +2,31 @@
|
|||||||
|
|
||||||
This litte project is an importer for WordPress XML dumps into refinerycms(-blog).
|
This litte project is an importer for WordPress XML dumps into refinerycms(-blog).
|
||||||
|
|
||||||
So far, only blog-relevant data gets imported, I'm working on the cms pages part.
|
|
||||||
|
|
||||||
You can find the source code on github: https://github.com/mremolt/refinerycms-wordpress-import
|
You can find the source code on github: https://github.com/mremolt/refinerycms-wordpress-import
|
||||||
|
|
||||||
|
Keep in mind, this gem imports blog posts and pages, NOT the media files, as they are not
|
||||||
|
part of the XML dump! You have to manually readd them to Refinery.
|
||||||
|
|
||||||
|
The same goes for links to other pages on your site. WordPress exports them just as <a>-Tags.
|
||||||
|
If your site (blog) structure uses new urls, the links WILL break! For example, if you used
|
||||||
|
the popular WP blog url structure "YYYY-MM/slug", be warned that Refinery just uses "blog/slug".
|
||||||
|
So your inner site links will point to the old WP url.
|
||||||
|
|
||||||
|
|
||||||
== Prerequisites
|
== Prerequisites
|
||||||
|
|
||||||
As refinerycms-wordpress-import is an addon for RefineryCMS, is shares the prerequisites with it.
|
As refinerycms-wordpress-import is an addon for RefineryCMS, is shares the prerequisites with it.
|
||||||
So you'll first need a running installation of refinerycms and refinerycms-blog. Make sure
|
So you'll first need a running installation of refinerycms and refinerycms-blog. Make sure
|
||||||
the site is running, all migrations are run and you created the first refinery user.
|
the site is running, all migrations are run and you created the first refinery user.
|
||||||
|
|
||||||
|
|
||||||
== Installation
|
== Installation
|
||||||
|
|
||||||
As there is no official release out yet, just add this repos to your projects Gemfile:
|
Just add the gem to your projects Gemfile:
|
||||||
|
|
||||||
|
gem 'refinerycms-wordpress-import'
|
||||||
|
|
||||||
|
Or if you want to stay on the bleeding edge:
|
||||||
|
|
||||||
gem 'refinerycms-wordpress-import', :git => 'git://github.com/mremolt/refinerycms-wordpress-import.git'
|
gem 'refinerycms-wordpress-import', :git => 'git://github.com/mremolt/refinerycms-wordpress-import.git'
|
||||||
|
|
||||||
@@ -22,9 +34,10 @@ and run
|
|||||||
|
|
||||||
bundle
|
bundle
|
||||||
|
|
||||||
|
|
||||||
== Usage
|
== Usage
|
||||||
|
|
||||||
Importing the XML dump is done via 3 rake tasks:
|
Importing the XML dump is done via rake tasks:
|
||||||
|
|
||||||
rake wordpress:reset_blog
|
rake wordpress:reset_blog
|
||||||
|
|
||||||
@@ -49,6 +62,41 @@ The task will then skip all posts that are not published.
|
|||||||
|
|
||||||
This one combines the two previous tasks.
|
This one combines the two previous tasks.
|
||||||
|
|
||||||
|
If you also want to import the cms part of WordPress, three more rake tasks manage
|
||||||
|
the import into RefineryCMS Pages:
|
||||||
|
|
||||||
|
rake wordpress:reset_pages
|
||||||
|
|
||||||
|
This task deletes all data from the cms tables, ensuring a clean import. Otherwise existing
|
||||||
|
pages could break the import because of duplicate IDs.
|
||||||
|
|
||||||
|
rake wordpress:import_pages[file_name]
|
||||||
|
|
||||||
|
This task imports all the WordPress pages into Refinery. The page structure (parent - child)
|
||||||
|
is preserved.
|
||||||
|
|
||||||
|
If you want to skip the draft pages, add the ONLY_PUBLISHED parameter to this task,
|
||||||
|
just like with wordpress:import_blog.
|
||||||
|
|
||||||
|
rake wordpress:import_pages[file_name] ONLY_PUBLISHED=true
|
||||||
|
|
||||||
|
If you want to clean the tables and import in one task:
|
||||||
|
|
||||||
|
rake wordpress:reset_and_import_pages[file_name]
|
||||||
|
|
||||||
|
|
||||||
|
== Usage on ZSH
|
||||||
|
|
||||||
|
One more hint for users of zsh (like myself):
|
||||||
|
|
||||||
|
The square brackets following the rake task need to be escaped on zsh, as they have a
|
||||||
|
special meaning there. So the syntax is:
|
||||||
|
|
||||||
|
rake wordpress:reset_and_import_blog\[file_name\]
|
||||||
|
|
||||||
|
Ugly, but it works. This is the case for all rake tasks by the way, not just mine.
|
||||||
|
|
||||||
|
|
||||||
== Feedback
|
== Feedback
|
||||||
|
|
||||||
This is still a very new gem. It manages to import my own blog and a standard WordPress 3.1 dump with some sample posts.
|
This is still a very new gem. It manages to import my own blog and a standard WordPress 3.1 dump with some sample posts.
|
||||||
|
|||||||
@@ -5,7 +5,8 @@ namespace :wordpress do
|
|||||||
task :reset_blog do
|
task :reset_blog do
|
||||||
Rake::Task["environment"].invoke
|
Rake::Task["environment"].invoke
|
||||||
|
|
||||||
%w(taggings tags blog_comments blog_categories blog_categories_blog_posts blog_posts).each do |table_name|
|
%w(taggings tags blog_comments blog_categories blog_categories_blog_posts
|
||||||
|
blog_posts).each do |table_name|
|
||||||
p "Truncating #{table_name} ..."
|
p "Truncating #{table_name} ..."
|
||||||
ActiveRecord::Base.connection.execute "DELETE FROM #{table_name}"
|
ActiveRecord::Base.connection.execute "DELETE FROM #{table_name}"
|
||||||
end
|
end
|
||||||
@@ -22,12 +23,13 @@ namespace :wordpress do
|
|||||||
only_published = ENV['ONLY_PUBLISHED'] == 'true' ? true : false
|
only_published = ENV['ONLY_PUBLISHED'] == 'true' ? true : false
|
||||||
dump.posts(only_published).each(&:to_refinery)
|
dump.posts(only_published).each(&:to_refinery)
|
||||||
|
|
||||||
|
Refinery::WordPress::Post.create_blog_page_if_necessary
|
||||||
|
|
||||||
ENV["MODEL"] = 'BlogPost'
|
ENV["MODEL"] = 'BlogPost'
|
||||||
Rake::Task["friendly_id:redo_slugs"].invoke
|
Rake::Task["friendly_id:redo_slugs"].invoke
|
||||||
ENV.delete("MODEL")
|
ENV.delete("MODEL")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
desc "reset blog tables and then import blog data from a Refinery::WordPress XML dump"
|
desc "reset blog tables and then import blog data from a Refinery::WordPress XML dump"
|
||||||
task :reset_and_import_blog, :file_name do |task, params|
|
task :reset_and_import_blog, :file_name do |task, params|
|
||||||
Rake::Task["environment"].invoke
|
Rake::Task["environment"].invoke
|
||||||
@@ -35,4 +37,45 @@ namespace :wordpress do
|
|||||||
Rake::Task["wordpress:import_blog"].invoke(params[:file_name])
|
Rake::Task["wordpress:import_blog"].invoke(params[:file_name])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
desc "Reset the cms relevant tables for a clean import"
|
||||||
|
task :reset_pages do
|
||||||
|
Rake::Task["environment"].invoke
|
||||||
|
|
||||||
|
%w(page_part_translations page_translations page_parts pages).each do |table_name|
|
||||||
|
p "Truncating #{table_name} ..."
|
||||||
|
ActiveRecord::Base.connection.execute "DELETE FROM #{table_name}"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
desc "import cms data from a Refinery::WordPress XML dump"
|
||||||
|
task :import_pages, :file_name do |task, params|
|
||||||
|
Rake::Task["environment"].invoke
|
||||||
|
dump = Refinery::WordPress::Dump.new(params[:file_name])
|
||||||
|
|
||||||
|
only_published = ENV['ONLY_PUBLISHED'] == 'true' ? true : false
|
||||||
|
dump.pages(only_published).each(&:to_refinery)
|
||||||
|
|
||||||
|
# After all pages are persisted we can now create the parent - child
|
||||||
|
# relationships. This is necessary, as WordPress doesn't dump the pages in
|
||||||
|
# a correct order.
|
||||||
|
dump.pages(only_published).each do |dump_page|
|
||||||
|
page = ::Page.find(dump_page.post_id)
|
||||||
|
page.parent_id = dump_page.parent_id
|
||||||
|
page.save!
|
||||||
|
end
|
||||||
|
|
||||||
|
Refinery::WordPress::Post.create_blog_page_if_necessary
|
||||||
|
|
||||||
|
ENV["MODEL"] = 'Page'
|
||||||
|
Rake::Task["friendly_id:redo_slugs"].invoke
|
||||||
|
ENV.delete("MODEL")
|
||||||
|
end
|
||||||
|
|
||||||
|
desc "reset cms tables and then import cms data from a Refinery::WordPress XML dump"
|
||||||
|
task :reset_and_import_pages, :file_name do |task, params|
|
||||||
|
Rake::Task["environment"].invoke
|
||||||
|
Rake::Task["wordpress:reset_pages"].invoke
|
||||||
|
Rake::Task["wordpress:import_pages"].invoke(params[:file_name])
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -19,10 +19,13 @@ module Refinery
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def pages
|
def pages(only_published=false)
|
||||||
doc.xpath("//item[wp:post_type = 'page']").collect do |page|
|
pages = doc.xpath("//item[wp:post_type = 'page']").collect do |page|
|
||||||
Page.new(page)
|
Page.new(page)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
pages = pages.select(&:published?) if only_published
|
||||||
|
pages
|
||||||
end
|
end
|
||||||
|
|
||||||
def posts(only_published=false)
|
def posts(only_published=false)
|
||||||
|
|||||||
@@ -23,23 +23,10 @@ module Refinery
|
|||||||
end
|
end
|
||||||
|
|
||||||
def content_formatted
|
def content_formatted
|
||||||
# WordPress doesn't export <p>-Tags, so let's run a simple_format over
|
formatted = format_syntax_highlighter(format_paragraphs(content))
|
||||||
# the content. As we trust ourselves, no sanatize.
|
|
||||||
formatted = simple_format(content, {}, { :sanitize => false })
|
|
||||||
|
|
||||||
# Support for SyntaxHighlighter (http://alexgorbatchev.com/SyntaxHighlighter/):
|
|
||||||
# In WordPress you can (via a plugin) enclose code in [lang][/lang]
|
|
||||||
# blocks, which are converted to a <pre>-tag with a class corresponding
|
|
||||||
# to the language.
|
|
||||||
#
|
|
||||||
# Example:
|
|
||||||
# [ruby]p "Hello World"[/ruby]
|
|
||||||
# -> <pre class="brush: ruby">p "Hello world"</pre>
|
|
||||||
formatted.gsub!(/\[(\w+)\]/, '<pre class="brush: \1">')
|
|
||||||
formatted.gsub!(/\[\/\w+\]/, '</pre>')
|
|
||||||
|
|
||||||
# remove all tags inside <pre> that simple_format created
|
# remove all tags inside <pre> that simple_format created
|
||||||
# TODO: replace simple_format with a method, that ignores pre-tags
|
# TODO: replace format_paragraphs with a method, that ignores pre-tags
|
||||||
formatted.gsub!(/(<pre.*?>)(.+?)(<\/pre>)/m) do |match|
|
formatted.gsub!(/(<pre.*?>)(.+?)(<\/pre>)/m) do |match|
|
||||||
"#{$1}#{strip_tags($2)}#{$3}"
|
"#{$1}#{strip_tags($2)}#{$3}"
|
||||||
end
|
end
|
||||||
@@ -60,7 +47,8 @@ module Refinery
|
|||||||
end
|
end
|
||||||
|
|
||||||
def parent_id
|
def parent_id
|
||||||
node.xpath("wp:post_parent").text.to_i
|
dump_id = node.xpath("wp:post_parent").text.to_i
|
||||||
|
dump_id == 0 ? nil : dump_id
|
||||||
end
|
end
|
||||||
|
|
||||||
def status
|
def status
|
||||||
@@ -80,12 +68,40 @@ module Refinery
|
|||||||
end
|
end
|
||||||
|
|
||||||
def to_refinery
|
def to_refinery
|
||||||
page = ::Page.create!(:title => title, :created_at => post_date,
|
page = ::Page.create!(:id => post_id, :title => title,
|
||||||
:draft => draft?, :parent_id => parent_id)
|
:created_at => post_date, :draft => draft?)
|
||||||
|
|
||||||
page.parts.create(:title => 'Body', :body => content_formatted)
|
page.parts.create(:title => 'Body', :body => content_formatted)
|
||||||
page
|
page
|
||||||
end
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def format_paragraphs(text, html_options={})
|
||||||
|
# WordPress doesn't export <p>-Tags, so let's run a simple_format over
|
||||||
|
# the content. As we trust ourselves, no sanatize. This code is heavily
|
||||||
|
# inspired by the simple_format rails helper
|
||||||
|
text = ''.html_safe if text.nil?
|
||||||
|
start_tag = tag('p', html_options, true)
|
||||||
|
|
||||||
|
text.gsub!(/\r\n?/, "\n") # \r\n and \r -> \n
|
||||||
|
text.gsub!(/\n\n+/, "</p>\n\n#{start_tag}") # 2+ newline -> paragraph
|
||||||
|
text.insert 0, start_tag
|
||||||
|
|
||||||
|
text.html_safe.safe_concat("</p>")
|
||||||
|
end
|
||||||
|
|
||||||
|
def format_syntax_highlighter(text)
|
||||||
|
# Support for SyntaxHighlighter (http://alexgorbatchev.com/SyntaxHighlighter/):
|
||||||
|
# In WordPress you can (via a plugin) enclose code in [lang][/lang]
|
||||||
|
# blocks, which are converted to a <pre>-tag with a class corresponding
|
||||||
|
# to the language.
|
||||||
|
#
|
||||||
|
# Example:
|
||||||
|
# [ruby]p "Hello World"[/ruby]
|
||||||
|
# -> <pre class="brush: ruby">p "Hello world"</pre>
|
||||||
|
text.gsub(/\[(\w+)\](.+?)\[\/\1\]/m, '<pre class="brush: \1">\2</pre>')
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -61,6 +61,25 @@ module Refinery
|
|||||||
|
|
||||||
post
|
post
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.create_blog_page_if_necessary
|
||||||
|
# refinerycms wants a page at /blog, so let's make sure there is one
|
||||||
|
# taken from the original db seeds from refinery-blog
|
||||||
|
unless ::Page.where("link_url = ?", '/blog').exists?
|
||||||
|
page = ::Page.create(
|
||||||
|
:title => "Blog",
|
||||||
|
:link_url => "/blog",
|
||||||
|
:deletable => false,
|
||||||
|
:position => ((::Page.maximum(:position, :conditions => {:parent_id => nil}) || -1)+1),
|
||||||
|
:menu_match => "^/blogs?(\/|\/.+?|)$"
|
||||||
|
)
|
||||||
|
|
||||||
|
::Page.default_parts.each do |default_page_part|
|
||||||
|
page.parts.create(:title => default_page_part, :body => nil)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -3,9 +3,9 @@
|
|||||||
Gem::Specification.new do |s|
|
Gem::Specification.new do |s|
|
||||||
s.name = "refinerycms-wordpress-import"
|
s.name = "refinerycms-wordpress-import"
|
||||||
s.summary = "Import WordPress XML dumps into refinerycms(-blog)."
|
s.summary = "Import WordPress XML dumps into refinerycms(-blog)."
|
||||||
s.description = "This gem imports a WordPress XML dump into refinerycms (Page [soon], User) and refinerycms-blog (BlogPost, BlogCategory, Tag, BlogComment)"
|
s.description = "This gem imports a WordPress XML dump into refinerycms (Page, User) and refinerycms-blog (BlogPost, BlogCategory, Tag, BlogComment)"
|
||||||
s.version = "0.1.0"
|
s.version = "0.2.0"
|
||||||
s.date = "2011-06-03"
|
s.date = "2011-06-05"
|
||||||
|
|
||||||
s.authors = ['Marc Remolt']
|
s.authors = ['Marc Remolt']
|
||||||
s.email = 'marc.remolt@googlemail.com'
|
s.email = 'marc.remolt@googlemail.com'
|
||||||
|
|||||||
@@ -1,3 +1,6 @@
|
|||||||
|
require 'yaml'
|
||||||
|
YAML::ENGINE.yamler= 'syck'
|
||||||
|
|
||||||
require 'rubygems'
|
require 'rubygems'
|
||||||
gemfile = File.expand_path('../../../../Gemfile', __FILE__)
|
gemfile = File.expand_path('../../../../Gemfile', __FILE__)
|
||||||
|
|
||||||
|
|||||||
4
spec/fixtures/wordpress_dump.xml
vendored
4
spec/fixtures/wordpress_dump.xml
vendored
@@ -62,7 +62,7 @@
|
|||||||
<wp:comment_status>open</wp:comment_status>
|
<wp:comment_status>open</wp:comment_status>
|
||||||
<wp:ping_status>open</wp:ping_status>
|
<wp:ping_status>open</wp:ping_status>
|
||||||
<wp:post_name>hello-world</wp:post_name>
|
<wp:post_name>hello-world</wp:post_name>
|
||||||
<wp:status>publish</wp:status>
|
<wp:status>draft</wp:status>
|
||||||
<wp:post_parent>0</wp:post_parent>
|
<wp:post_parent>0</wp:post_parent>
|
||||||
<wp:menu_order>0</wp:menu_order>
|
<wp:menu_order>0</wp:menu_order>
|
||||||
<wp:post_type>post</wp:post_type>
|
<wp:post_type>post</wp:post_type>
|
||||||
@@ -107,7 +107,7 @@ As a new WordPress user, you should go to <a href="http://localhost/wordpress/wp
|
|||||||
<wp:comment_status>open</wp:comment_status>
|
<wp:comment_status>open</wp:comment_status>
|
||||||
<wp:ping_status>open</wp:ping_status>
|
<wp:ping_status>open</wp:ping_status>
|
||||||
<wp:post_name>sample-page</wp:post_name>
|
<wp:post_name>sample-page</wp:post_name>
|
||||||
<wp:status>publish</wp:status>
|
<wp:status>draft</wp:status>
|
||||||
<wp:post_parent>0</wp:post_parent>
|
<wp:post_parent>0</wp:post_parent>
|
||||||
<wp:menu_order>0</wp:menu_order>
|
<wp:menu_order>0</wp:menu_order>
|
||||||
<wp:post_type>page</wp:post_type>
|
<wp:post_type>page</wp:post_type>
|
||||||
|
|||||||
28
spec/lib/wordpress/author_spec.rb
Normal file
28
spec/lib/wordpress/author_spec.rb
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
require 'spec_helper'
|
||||||
|
|
||||||
|
describe Refinery::WordPress::Author, :type => :model do
|
||||||
|
let(:author) { test_dump.authors.first }
|
||||||
|
|
||||||
|
it { author.login.should == 'admin' }
|
||||||
|
it { author.email.should == 'admin@example.com' }
|
||||||
|
|
||||||
|
describe "#to_refinery" do
|
||||||
|
before do
|
||||||
|
@user = author.to_refinery
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should create a User object" do
|
||||||
|
User.should have(1).record
|
||||||
|
@user.should be_a(User)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "the @user should be persisted" do
|
||||||
|
@user.should be_persisted
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should have copied the attributes from Refinery::WordPress::Author" do
|
||||||
|
author.login.should == @user.username
|
||||||
|
author.email.should == @user.email
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
29
spec/lib/wordpress/category_spec.rb
Normal file
29
spec/lib/wordpress/category_spec.rb
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
require 'spec_helper'
|
||||||
|
|
||||||
|
describe Refinery::WordPress::Category, :type => :model do
|
||||||
|
let(:category) { Refinery::WordPress::Category.new('Rant') }
|
||||||
|
|
||||||
|
describe "#name" do
|
||||||
|
specify { category.name.should == 'Rant' }
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "#==" do
|
||||||
|
specify { category.should == Refinery::WordPress::Category.new('Rant') }
|
||||||
|
specify { category.should_not == Refinery::WordPress::Category.new('Tutorials') }
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "#to_refinery" do
|
||||||
|
before do
|
||||||
|
@category = category.to_refinery
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should create a BlogCategory" do
|
||||||
|
BlogCategory.should have(1).record
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should copy the name over to the BlogCategory object" do
|
||||||
|
@category.title.should == category.name
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
@@ -1,8 +1,7 @@
|
|||||||
require 'spec_helper'
|
require 'spec_helper'
|
||||||
|
|
||||||
describe Refinery::WordPress::Dump, :type => :model do
|
describe Refinery::WordPress::Dump, :type => :model do
|
||||||
let(:file_name) { File.realpath(File.join(File.dirname(__FILE__), '../../fixtures/wordpress_dump.xml')) }
|
let(:dump) { test_dump }
|
||||||
let(:dump) { Refinery::WordPress::Dump.new(file_name) }
|
|
||||||
|
|
||||||
it "should create a Dump object given a xml file" do
|
it "should create a Dump object given a xml file" do
|
||||||
dump.should be_a Refinery::WordPress::Dump
|
dump.should be_a Refinery::WordPress::Dump
|
||||||
@@ -18,29 +17,13 @@ describe Refinery::WordPress::Dump, :type => :model do
|
|||||||
Refinery::WordPress::Tag.new('php'), Refinery::WordPress::Tag.new('ruby')]
|
Refinery::WordPress::Tag.new('php'), Refinery::WordPress::Tag.new('ruby')]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
specify { dump.tags.count == 4 }
|
||||||
|
|
||||||
it "should return all included tags" do
|
it "should return all included tags" do
|
||||||
tags.each do |tag|
|
tags.each do |tag|
|
||||||
dump.tags.should include(tag)
|
dump.tags.should include(tag)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context "the last tag" do
|
|
||||||
let(:tag) { dump.tags.last }
|
|
||||||
|
|
||||||
describe "#to_refinery" do
|
|
||||||
before do
|
|
||||||
@tag = tag.to_refinery
|
|
||||||
end
|
|
||||||
|
|
||||||
it "should create a ActsAsTaggableOn::Tag" do
|
|
||||||
::ActsAsTaggableOn::Tag.should have(1).record
|
|
||||||
end
|
|
||||||
|
|
||||||
it "should copy the name over to the Tag object" do
|
|
||||||
@tag.name.should == tag.name
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "#categories" do
|
describe "#categories" do
|
||||||
@@ -49,30 +32,13 @@ describe Refinery::WordPress::Dump, :type => :model do
|
|||||||
Refinery::WordPress::Category.new('Uncategorized') ]
|
Refinery::WordPress::Category.new('Uncategorized') ]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
specify { dump.categories.count == 4 }
|
||||||
|
|
||||||
it "should return all included categories" do
|
it "should return all included categories" do
|
||||||
categories.each do |cat|
|
categories.each do |cat|
|
||||||
dump.categories.should include(cat)
|
dump.categories.should include(cat)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context "the last category" do
|
|
||||||
let(:category) { dump.categories.last }
|
|
||||||
|
|
||||||
describe "#to_refinery" do
|
|
||||||
before do
|
|
||||||
@category = category.to_refinery
|
|
||||||
end
|
|
||||||
|
|
||||||
it "should create a BlogCategory" do
|
|
||||||
BlogCategory.should have(1).record
|
|
||||||
end
|
|
||||||
|
|
||||||
it "should copy the name over to the BlogCategory object" do
|
|
||||||
@category.title.should == category.name
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "#pages" do
|
describe "#pages" do
|
||||||
@@ -80,43 +46,8 @@ describe Refinery::WordPress::Dump, :type => :model do
|
|||||||
dump.pages.should have(3).pages
|
dump.pages.should have(3).pages
|
||||||
end
|
end
|
||||||
|
|
||||||
context "the About me page" do
|
it "should return only published pages with only_published=true" do
|
||||||
let(:page) { dump.pages.last }
|
dump.pages(true).should have(2).pages
|
||||||
|
|
||||||
it { page.title.should == 'About me' }
|
|
||||||
it { page.content.should include('Lorem ipsum dolor sit') }
|
|
||||||
it { page.creator.should == 'admin' }
|
|
||||||
it { page.post_date.should == DateTime.new(2011, 5, 21, 12, 25, 42) }
|
|
||||||
it { page.post_id.should == 10 }
|
|
||||||
it { page.parent_id.should == 8 }
|
|
||||||
|
|
||||||
it { page.should == dump.pages.last }
|
|
||||||
it { page.should_not == dump.pages.first }
|
|
||||||
|
|
||||||
describe "#to_refinery" do
|
|
||||||
include ::ActionView::Helpers::TagHelper
|
|
||||||
include ::ActionView::Helpers::TextHelper
|
|
||||||
|
|
||||||
before do
|
|
||||||
# "About me" has a parent page with id 8 in the XML dump,
|
|
||||||
# would otherwise fails creation
|
|
||||||
Page.create! :id => 8, :title => 'About'
|
|
||||||
|
|
||||||
@count = Page.count
|
|
||||||
@page = page.to_refinery
|
|
||||||
end
|
|
||||||
|
|
||||||
it "should create a Page object" do
|
|
||||||
Page.should have(@count + 1).record
|
|
||||||
end
|
|
||||||
|
|
||||||
it "should copy the attributes from Refinery::WordPress::Page" do
|
|
||||||
@page.title.should == page.title
|
|
||||||
@page.draft.should == page.draft?
|
|
||||||
@page.created_at.should == page.post_date
|
|
||||||
@page.parts.first.body.should == "#{simple_format(page.content)}"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -124,33 +55,6 @@ describe Refinery::WordPress::Dump, :type => :model do
|
|||||||
it "should return all authors" do
|
it "should return all authors" do
|
||||||
dump.authors.should have(1).author
|
dump.authors.should have(1).author
|
||||||
end
|
end
|
||||||
|
|
||||||
context "the first author" do
|
|
||||||
let(:author) { dump.authors.first }
|
|
||||||
|
|
||||||
it { author.login.should == 'admin' }
|
|
||||||
it { author.email.should == 'admin@example.com' }
|
|
||||||
|
|
||||||
describe "#to_refinery" do
|
|
||||||
before do
|
|
||||||
@user = author.to_refinery
|
|
||||||
end
|
|
||||||
|
|
||||||
it "should create a User object" do
|
|
||||||
User.should have(1).record
|
|
||||||
@user.should be_a(User)
|
|
||||||
end
|
|
||||||
|
|
||||||
it "the @user should be persisted" do
|
|
||||||
@user.should be_persisted
|
|
||||||
end
|
|
||||||
|
|
||||||
it "should have copied the attributes from Refinery::WordPress::Author" do
|
|
||||||
author.login.should == @user.username
|
|
||||||
author.email.should == @user.email
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "#posts" do
|
describe "#posts" do
|
||||||
@@ -158,121 +62,8 @@ describe Refinery::WordPress::Dump, :type => :model do
|
|||||||
dump.posts.should have(3).posts
|
dump.posts.should have(3).posts
|
||||||
end
|
end
|
||||||
|
|
||||||
context "the last post" do
|
it "should return only published posts with only_published=true" do
|
||||||
let(:post) { dump.posts.last }
|
dump.posts(true).should have(2).posts
|
||||||
|
|
||||||
it { post.title.should == 'Third blog post' }
|
|
||||||
it { post.content.should include('Lorem ipsum dolor sit') }
|
|
||||||
it { post.creator.should == 'admin' }
|
|
||||||
it { post.post_date.should == DateTime.new(2011, 5, 21, 12, 24, 45) }
|
|
||||||
it { post.post_id.should == 6 }
|
|
||||||
it { post.parent_id.should == 0 }
|
|
||||||
it { post.status.should == 'publish' }
|
|
||||||
|
|
||||||
it { post.should == dump.posts.last }
|
|
||||||
it { post.should_not == dump.posts.first }
|
|
||||||
|
|
||||||
describe "#categories" do
|
|
||||||
it { post.categories.should have(1).category }
|
|
||||||
it { post.categories.first.should == Refinery::WordPress::Category.new('Rant') }
|
|
||||||
end
|
|
||||||
|
|
||||||
describe "#tags" do
|
|
||||||
it { post.tags.should have(3).tags }
|
|
||||||
|
|
||||||
it { post.tags.should include(Refinery::WordPress::Tag.new('css')) }
|
|
||||||
it { post.tags.should include(Refinery::WordPress::Tag.new('html')) }
|
|
||||||
it { post.tags.should include(Refinery::WordPress::Tag.new('php')) }
|
|
||||||
end
|
|
||||||
|
|
||||||
it { 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 }
|
|
||||||
|
|
||||||
it { comment.author.should == 'admin' }
|
|
||||||
it { comment.email.should == 'admin@example.com' }
|
|
||||||
it { comment.url.should == 'http://www.example.com/' }
|
|
||||||
it { comment.date.should == DateTime.new(2011, 5, 21, 12, 26, 30) }
|
|
||||||
it { comment.content.should include('Another one!') }
|
|
||||||
it { comment.should be_approved }
|
|
||||||
|
|
||||||
it { 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
|
|
||||||
|
|
||||||
it { 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
|
|
||||||
|
|
||||||
it { 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
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
105
spec/lib/wordpress/page_spec.rb
Normal file
105
spec/lib/wordpress/page_spec.rb
Normal file
@@ -0,0 +1,105 @@
|
|||||||
|
require 'spec_helper'
|
||||||
|
|
||||||
|
describe Refinery::WordPress::Page, :type => :model do
|
||||||
|
let(:dump) { test_dump }
|
||||||
|
|
||||||
|
let(:page) { test_dump.pages.last }
|
||||||
|
|
||||||
|
it { page.title.should == 'About me' }
|
||||||
|
it { page.content.should include('Lorem ipsum dolor sit') }
|
||||||
|
it { page.creator.should == 'admin' }
|
||||||
|
it { page.post_date.should == DateTime.new(2011, 5, 21, 12, 25, 42) }
|
||||||
|
it { page.post_id.should == 10 }
|
||||||
|
it { page.parent_id.should == 8 }
|
||||||
|
|
||||||
|
it { page.should == dump.pages.last }
|
||||||
|
it { page.should_not == dump.pages.first }
|
||||||
|
|
||||||
|
describe "#to_refinery" do
|
||||||
|
include ::ActionView::Helpers::TagHelper
|
||||||
|
include ::ActionView::Helpers::TextHelper
|
||||||
|
|
||||||
|
before do
|
||||||
|
# "About me" has a parent page with id 8 in the XML dump,
|
||||||
|
# would otherwise fails creation
|
||||||
|
Page.create! :id => 8, :title => 'About'
|
||||||
|
|
||||||
|
@count = Page.count
|
||||||
|
@page = page.to_refinery
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should create a Page object" do
|
||||||
|
Page.should have(@count + 1).record
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should copy the attributes from Refinery::WordPress::Page" do
|
||||||
|
@page.title.should == page.title
|
||||||
|
@page.draft.should == page.draft?
|
||||||
|
@page.created_at.should == page.post_date
|
||||||
|
@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
|
||||||
|
|
||||||
116
spec/lib/wordpress/post_spec.rb
Normal file
116
spec/lib/wordpress/post_spec.rb
Normal file
@@ -0,0 +1,116 @@
|
|||||||
|
require 'spec_helper'
|
||||||
|
|
||||||
|
describe Refinery::WordPress::Post, :type => :model do
|
||||||
|
let(:post) { test_dump.posts.last }
|
||||||
|
|
||||||
|
it { post.title.should == 'Third blog post' }
|
||||||
|
it { post.content.should include('Lorem ipsum dolor sit') }
|
||||||
|
it { post.content_formatted.should include('Lorem ipsum dolor sit') }
|
||||||
|
it { post.creator.should == 'admin' }
|
||||||
|
it { post.post_date.should == DateTime.new(2011, 5, 21, 12, 24, 45) }
|
||||||
|
it { post.post_id.should == 6 }
|
||||||
|
it { post.parent_id.should == nil }
|
||||||
|
it { post.status.should == 'publish' }
|
||||||
|
|
||||||
|
it { post.should == test_dump.posts.last }
|
||||||
|
it { post.should_not == test_dump.posts.first }
|
||||||
|
|
||||||
|
describe "#categories" do
|
||||||
|
it { post.categories.should have(1).category }
|
||||||
|
it { post.categories.first.should == Refinery::WordPress::Category.new('Rant') }
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "#tags" do
|
||||||
|
it { post.tags.should have(3).tags }
|
||||||
|
|
||||||
|
it { post.tags.should include(Refinery::WordPress::Tag.new('css')) }
|
||||||
|
it { post.tags.should include(Refinery::WordPress::Tag.new('html')) }
|
||||||
|
it { post.tags.should include(Refinery::WordPress::Tag.new('php')) }
|
||||||
|
end
|
||||||
|
|
||||||
|
it { 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 }
|
||||||
|
|
||||||
|
it { comment.author.should == 'admin' }
|
||||||
|
it { comment.email.should == 'admin@example.com' }
|
||||||
|
it { comment.url.should == 'http://www.example.com/' }
|
||||||
|
it { comment.date.should == DateTime.new(2011, 5, 21, 12, 26, 30) }
|
||||||
|
it { comment.content.should include('Another one!') }
|
||||||
|
it { comment.should be_approved }
|
||||||
|
|
||||||
|
it { 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
|
||||||
|
|
||||||
|
it { 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
|
||||||
|
|
||||||
|
it { 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
|
||||||
30
spec/lib/wordpress/tag_spec.rb
Normal file
30
spec/lib/wordpress/tag_spec.rb
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
require 'spec_helper'
|
||||||
|
|
||||||
|
describe Refinery::WordPress::Tag, :type => :model do
|
||||||
|
let(:tag) { Refinery::WordPress::Tag.new('ruby') }
|
||||||
|
|
||||||
|
describe "#name" do
|
||||||
|
specify { tag.name.should == 'ruby' }
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "#==" do
|
||||||
|
specify { tag.should == Refinery::WordPress::Tag.new('ruby') }
|
||||||
|
specify { tag.should_not == Refinery::WordPress::Tag.new('php') }
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "#to_refinery" do
|
||||||
|
before do
|
||||||
|
@tag = tag.to_refinery
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should create a ActsAsTaggableOn::Tag" do
|
||||||
|
::ActsAsTaggableOn::Tag.should have(1).record
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should copy the name over to the Tag object" do
|
||||||
|
@tag.name.should == tag.name
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
11
spec/support/helpers.rb
Normal file
11
spec/support/helpers.rb
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
module Refinery::WordPress::SpecHelpers
|
||||||
|
def test_dump
|
||||||
|
file_name = File.realpath(File.join(File.dirname(__FILE__), '../fixtures/wordpress_dump.xml'))
|
||||||
|
Refinery::WordPress::Dump.new(file_name)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
RSpec.configure do |config|
|
||||||
|
config.include Refinery::WordPress::SpecHelpers
|
||||||
|
end
|
||||||
|
|
||||||
Reference in New Issue
Block a user