9 Commits

Author SHA1 Message Date
Marc Remolt
32bb8a528a Typo 2011-06-13 19:03:52 +02:00
Marc Remolt
309ec660b9 Preparing for release 0.3.0 2011-06-13 19:02:25 +02:00
Marc Remolt
90665484c7 Resource import working
* added rake tasks
2011-06-13 18:48:17 +02:00
Marc Remolt
a24ea686fa Image import working
* bundle update
* replacement of image URLs now considers wordpress thumbnails (like -150x150)
* added Guard for autotesting
2011-06-13 15:02:40 +02:00
Marc Remolt
7265d31f62 Some specs for file Attachment 2011-06-06 19:45:34 +02:00
Marc Remolt
2581895c7c Updated test dump and adapted specs
* We now have a second attachment, a simple text file
2011-06-06 19:39:27 +02:00
Marc Remolt
7550dfa164 First shot at attachment import
* only images for now
* only blog posts for now
* thumbnailed images are not yet replaced in blog posts body
2011-06-05 19:14:52 +02:00
Marc Remolt
9a2b5acef6 Spec improvements
* replaced it with specify on {...} blocks
2011-06-05 17:55:00 +02:00
Marc Remolt
772cfdc25b Started on attachment import
* created Attachment
* created Dump#attachments
* specs
* replaced require with autoload
2011-06-05 17:43:30 +02:00
20 changed files with 575 additions and 88 deletions

3
.gitignore vendored
View File

@@ -4,3 +4,6 @@ pkg/
spec/dummy/db/*.sqlite3
spec/dummy/log/*.log
spec/dummy/tmp/
*.un~
refinerycms-wordpress-import-*.gem
*.swp

12
Gemfile
View File

@@ -3,9 +3,17 @@ source "http://rubygems.org"
gem "rails", "3.0.7"
#gem "capybara", ">= 1.0.0.beta1"
gem "sqlite3"
gem "rmagick"
gem "rspec-rails", ">= 2.6.0"
gem "database_cleaner"
group :development, :test do
gem "rspec-rails", ">= 2.6.0"
gem "database_cleaner"
gem 'guard-rspec'
gem 'ffi'
gem 'guard-bundler'
gem 'libnotify' if RUBY_PLATFORM =~ /linux/i
gem 'fakeweb'
end
# To use debugger (ruby-debug for Ruby 1.8.7+, ruby-debug19 for Ruby 1.9.2+)
# gem 'ruby-debug'

View File

@@ -1,7 +1,7 @@
PATH
remote: ./
specs:
refinerycms-wordpress-import (0.1.0)
refinerycms-wordpress-import (0.3.0)
bundler (~> 1.0)
nokogiri (~> 1.4.4)
refinerycms (~> 1.0.0)
@@ -42,7 +42,7 @@ GEM
arel (2.0.10)
awesome_nested_set (2.0.0)
activerecord (>= 3.0.0)
babosa (0.3.4)
babosa (0.3.5)
bcrypt-ruby (2.1.4)
builder (2.1.2)
database_cleaner (0.6.7)
@@ -51,17 +51,27 @@ GEM
orm_adapter (~> 0.0.3)
warden (~> 1.0.3)
diff-lcs (1.1.2)
dragonfly (0.9.3)
dragonfly (0.9.4)
rack
erubis (2.6.6)
abstract (>= 1.0.0)
fakeweb (1.3.0)
ffi (1.0.9)
filters_spam (0.3)
friendly_id_globalize3 (3.2.1.3)
babosa (~> 0.3.0)
globalize3 (0.1.0)
activemodel (>= 3.0.0)
activerecord (>= 3.0.0)
guard (0.4.2)
thor (~> 0.14.6)
guard-bundler (0.1.3)
bundler (>= 1.0.0)
guard (>= 0.2.2)
guard-rspec (0.4.0)
guard (>= 0.4.0)
i18n (0.5.0)
libnotify (0.5.5)
mail (2.2.19)
activesupport (>= 2.3.6)
i18n (>= 0.4.0)
@@ -91,7 +101,7 @@ GEM
activesupport (= 3.0.7)
rake (>= 0.8.7)
thor (~> 0.14.4)
rake (0.9.1)
rake (0.9.2)
refinerycms (1.0.0)
bundler (~> 1.0)
refinerycms-authentication (= 1.0.0)
@@ -142,11 +152,12 @@ GEM
refinerycms-core (= 1.0.0)
refinerycms-settings (1.0.0)
refinerycms-base (= 1.0.0)
rmagick (2.13.1)
rspec (2.6.0)
rspec-core (~> 2.6.0)
rspec-expectations (~> 2.6.0)
rspec-mocks (~> 2.6.0)
rspec-core (2.6.3)
rspec-core (2.6.4)
rspec-expectations (2.6.0)
diff-lcs (~> 1.1.2)
rspec-mocks (2.6.0)
@@ -172,9 +183,15 @@ PLATFORMS
DEPENDENCIES
database_cleaner
fakeweb
ffi
guard-bundler
guard-rspec
libnotify
rails (= 3.0.7)
refinerycms
refinerycms-blog
refinerycms-wordpress-import!
rmagick
rspec-rails (>= 2.6.0)
sqlite3

26
Guardfile Normal file
View File

@@ -0,0 +1,26 @@
# A sample Guardfile
# More info at https://github.com/guard/guard#readme
guard 'rspec', :version => 2 do
watch(%r{^spec/.+_spec\.rb$})
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
watch('spec/spec_helper.rb') { "spec" }
# Rails example
watch(%r{^spec/.+_spec\.rb$})
watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
watch('spec/spec_helper.rb') { "spec" }
watch('config/routes.rb') { "spec/routing" }
watch('app/controllers/application_controller.rb') { "spec/controllers" }
# Capybara request specs
watch(%r{^app/views/(.+)/.*\.(erb|haml)$}) { |m| "spec/requests/#{m[1]}_spec.rb" }
end
guard 'bundler' do
watch('Gemfile')
# Uncomment next line if Gemfile contain `gemspec' command
watch(/^.+\.gemspec/)
end

View File

@@ -4,10 +4,7 @@ This litte project is an importer for WordPress XML dumps into refinerycms(-blog
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.
Keep in mind that links to other pages of your blog are just copied, as WordPress exports them 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.
@@ -84,6 +81,39 @@ If you want to clean the tables and import in one task:
rake wordpress:reset_and_import_pages[file_name]
Finally, if you want to reset and import all data including media (see below):
rake wordpress:full_import[file_name]
== Importing media files
The WP XML dump contains absolute links to media files linked inside posts, like:
www.mysite.com/wordpress/wp-content/uploads/2011/05/cv.txt
The dump does NOT contain the files itself! To get them imported, this gem downloads the files
from the given URL and imports them to refinery. So for a working media import the old site with
the media URLs must still be online.
After importing the files, this gem replaces the old links in pages and blog posts with the
new generated ones. It parses all existing records searching for the right pattern. That
means, you have to import pages and posts FIRST to get the URLs replaced.
Now to the rake tasks for media import:
rake wordpress:reset_media
This task deletes all data from the media tables (images and resources), ensuring a clean import.
rake wordpress:import_and_replace_media[file_name]
This task imports all the WordPress media into Refinery. After the import it parses all
pages and blog posts, replacing the legacy links with the current refinery ones.
If you want to clean the tables and import in one task:
rake wordpress:reset_import_and_replace_media[file_name]
== Usage on ZSH

View File

@@ -48,7 +48,7 @@ namespace :wordpress do
end
end
desc "import cms data from a Refinery::WordPress XML dump"
desc "import cms data from a WordPress XML dump"
task :import_pages, :file_name do |task, params|
Rake::Task["environment"].invoke
dump = Refinery::WordPress::Dump.new(params[:file_name])
@@ -72,10 +72,50 @@ namespace :wordpress do
ENV.delete("MODEL")
end
desc "reset cms tables and then import cms data from a Refinery::WordPress XML dump"
desc "reset cms tables and then import cms data from a 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
desc "Reset the media relevant tables for a clean import"
task :reset_media do
Rake::Task["environment"].invoke
%w(images resources).each do |table_name|
p "Truncating #{table_name} ..."
ActiveRecord::Base.connection.execute "DELETE FROM #{table_name}"
end
end
desc "import media data (images and files) from a WordPress XML dump and replace target URLs in pages and posts"
task :import_and_replace_media, :file_name do |task, params|
Rake::Task["environment"].invoke
dump = Refinery::WordPress::Dump.new(params[:file_name])
attachments = dump.attachments.each(&:to_refinery)
# parse all created BlogPost and Page bodys and replace the old wordpress media uls
# with the newly created ones
attachments.each do |attachment|
attachment.replace_url
end
end
desc "reset media tables and then import media data from a WordPress XML dump"
task :reset_import_and_replace_media, :file_name do |task, params|
Rake::Task["environment"].invoke
Rake::Task["wordpress:reset_media"].invoke
Rake::Task["wordpress:import_and_replace_media"].invoke(params[:file_name])
end
desc "reset and import all data (see the other tasks)"
task :full_import, :file_name do |task, params|
Rake::Task["environment"].invoke
Rake::Task["wordpress:reset_and_import_blog"].invoke(params[:file_name])
Rake::Task["wordpress:reset_and_import_pages"].invoke(params[:file_name])
Rake::Task["wordpress:reset_import_and_replace_media"].invoke(params[:file_name])
end
end

View File

@@ -1,15 +1,16 @@
require 'nokogiri'
require "wordpress/railtie"
module Refinery
module WordPress
autoload :Author, 'wordpress/author'
autoload :Tag, 'wordpress/tag'
autoload :Category, 'wordpress/category'
autoload :Page, 'wordpress/page'
autoload :Post, 'wordpress/post'
autoload :Comment, 'wordpress/comment'
autoload :Dump, 'wordpress/dump'
autoload :Attachment, 'wordpress/attachment'
end
end
require 'nokogiri'
require 'wordpress/author'
require 'wordpress/tag'
require 'wordpress/category'
require 'wordpress/page'
require 'wordpress/post'
require 'wordpress/comment'
require 'wordpress/dump'
require "wordpress/railtie"

130
lib/wordpress/attachment.rb Normal file
View File

@@ -0,0 +1,130 @@
module Refinery
module WordPress
class Attachment
attr_reader :node
attr_reader :refinery_image
attr_reader :refinery_resource
def initialize(node)
@node = node
end
def title
node.xpath("title").text
end
def description
node.xpath("description").text
end
def file_name
url.split('/').last
end
def post_date
DateTime.parse node.xpath("wp:post_date").text
end
def url
node.xpath("wp:attachment_url").text
end
def url_pattern
url_parts = url.split('.')
extension = url_parts.pop
url_without_extension = url_parts.join('.')
/#{url_without_extension}(-\d+x\d+)?\.#{extension}/
end
def image?
url.match /\.(png|jpg|jpeg|gif)$/
end
def to_refinery
if image?
to_image
else
to_resource
end
end
def replace_url
if image?
replace_image_url
else
replace_resource_url
end
end
private
def to_image
image = ::Image.new
image.created_at = post_date
image.image_url = url
image.save!
@refinery_image = image
image
end
def to_resource
resource = ::Resource.new
resource.created_at = post_date
resource.file_url = url
resource.save!
@refinery_resource = resource
resource
end
def replace_image_url
replace_image_url_in_blog_posts
replace_image_url_in_pages
end
def replace_resource_url
replace_resource_url_in_blog_posts
replace_resource_url_in_pages
end
def replace_image_url_in_blog_posts
replace_url_in_blog_posts(refinery_image.image.url)
end
def replace_image_url_in_pages
replace_url_in_pages(refinery_image.image.url)
end
def replace_resource_url_in_blog_posts
replace_url_in_blog_posts(refinery_resource.file.url)
end
def replace_resource_url_in_pages
replace_url_in_pages(refinery_resource.file.url)
end
def replace_url_in_blog_posts(new_url)
::BlogPost.all.each do |post|
if (! post.body.empty?) && post.body.include?(url)
post.body = post.body.gsub(url_pattern, new_url)
post.save!
end
end
end
def replace_url_in_pages(new_url)
::Page.all.each do |page|
page.parts.each do |part|
if (! part.body.to_s.blank?) && part.body.include?(url)
part.body = part.body.gsub(url_pattern, new_url)
part.save!
end
end
end
end
end
end
end

View File

@@ -47,6 +47,12 @@ module Refinery
Category.new(category.text)
end
end
def attachments
doc.xpath("//item[wp:post_type = 'attachment']").collect do |attachment|
Attachment.new(attachment)
end
end
end
end
end

View File

@@ -4,8 +4,8 @@ Gem::Specification.new do |s|
s.name = "refinerycms-wordpress-import"
s.summary = "Import WordPress XML dumps into refinerycms(-blog)."
s.description = "This gem imports a WordPress XML dump into refinerycms (Page, User) and refinerycms-blog (BlogPost, BlogCategory, Tag, BlogComment)"
s.version = "0.2.0"
s.date = "2011-06-05"
s.version = "0.3.0"
s.date = "2011-06-13"
s.authors = ['Marc Remolt']
s.email = 'marc.remolt@googlemail.com'

View File

@@ -0,0 +1,25 @@
class CreateSeoMetaForBlog < ActiveRecord::Migration
def self.up
unless ::SeoMetum.table_exists?
create_table ::SeoMetum.table_name do |t|
t.integer :seo_meta_id
t.string :seo_meta_type
t.string :browser_title
t.string :meta_keywords
t.text :meta_description
t.timestamps
end
add_index ::SeoMetum.table_name, :id
add_index ::SeoMetum.table_name, [:seo_meta_id, :seo_meta_type]
end
end
def self.down
# can't drop the table because someone else might be using it.
end
end

View File

@@ -1,16 +1,20 @@
User.find(:all).each do |user|
user.plugins.create(:name => "refinerycms_blog",
:position => (user.plugins.maximum(:position) || -1) +1)
end
::User.find(:all).each do |user|
if user.plugins.where(:name => 'refinerycms_blog').blank?
user.plugins.create(:name => "refinerycms_blog",
:position => (user.plugins.maximum(:position) || -1) +1)
end
end if defined?(::User)
page = Page.create(
:title => "Blog",
:link_url => "/blog",
:deletable => false,
:position => ((Page.maximum(:position, :conditions => {:parent_id => nil}) || -1)+1),
:menu_match => "^/blogs?(\/|\/.+?|)$"
)
if defined?(::Page)
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)
::Page.default_parts.each do |default_page_part|
page.parts.create(:title => default_page_part, :body => nil)
end
end

BIN
spec/fixtures/200px-Tux.svg_.png vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

View File

@@ -16,7 +16,7 @@
<!-- 7. WordPress will then import each of the posts, pages, comments, categories, etc. -->
<!-- contained in this file into your site. -->
<!-- generator="WordPress/3.1.2" created="2011-05-21 12:27" -->
<!-- generator="WordPress/3.1.2" created="2011-06-06 18:42" -->
<rss version="2.0"
xmlns:excerpt="http://wordpress.org/export/1.1/excerpt/"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
@@ -29,7 +29,7 @@
<title>My test blog</title>
<link>http://localhost/wordpress</link>
<description>Just another WordPress site</description>
<pubDate>Sat, 21 May 2011 12:27:19 +0000</pubDate>
<pubDate>Mon, 06 Jun 2011 18:42:09 +0000</pubDate>
<language>en</language>
<wp:wxr_version>1.1</wp:wxr_version>
<wp:base_site_url>http://localhost/wordpress</wp:base_site_url>
@@ -69,6 +69,10 @@
<wp:post_password></wp:post_password>
<wp:is_sticky>0</wp:is_sticky>
<category domain="category" nicename="uncategorized"><![CDATA[Uncategorized]]></category>
<wp:postmeta>
<wp:meta_key>_edit_last</wp:meta_key>
<wp:meta_value><![CDATA[1]]></wp:meta_value>
</wp:postmeta>
<wp:comment>
<wp:comment_id>1</wp:comment_id>
<wp:comment_author><![CDATA[Mr WordPress]]></wp:comment_author>
@@ -92,13 +96,9 @@
<guid isPermaLink="false">http://localhost/wordpress/?page_id=2</guid>
<description></description>
<content:encoded><![CDATA[This is an example page. It's different from a blog post because it will stay in one place and will show up in your site navigation (in most themes). Most people start with an About page that introduces them to potential site visitors. It might say something like this:
<blockquote>Hi there! I'm a bike messenger by day, aspiring actor by night, and this is my blog. I live in Los Angeles, have a great dog named Jack, and I like pi&#241;a coladas. (And gettin' caught in the rain.)</blockquote>
<blockquote>Hi there! I'm a bike messenger by day, aspiring actor by night, and this is my blog. I live in Los Angeles, have a great dog named Jack, and I like piña coladas. (And gettin' caught in the rain.)</blockquote>
...or something like this:
<blockquote>The XYZ Doohickey Company was founded in 1971, and has been providing quality doohickies to the public ever since. Located in Gotham City, XYZ employs over 2,000 people and does all kinds of awesome things for the Gotham community.</blockquote>
As a new WordPress user, you should go to <a href="http://localhost/wordpress/wp-admin/">your dashboard</a> to delete this page and create new pages for your content. Have fun!]]></content:encoded>
<excerpt:encoded><![CDATA[]]></excerpt:encoded>
<wp:post_id>2</wp:post_id>
@@ -117,6 +117,10 @@ As a new WordPress user, you should go to <a href="http://localhost/wordpress/wp
<wp:meta_key>_wp_page_template</wp:meta_key>
<wp:meta_value><![CDATA[default]]></wp:meta_value>
</wp:postmeta>
<wp:postmeta>
<wp:meta_key>_edit_last</wp:meta_key>
<wp:meta_value><![CDATA[1]]></wp:meta_value>
</wp:postmeta>
</item>
<item>
<title>Second blog post </title>
@@ -159,8 +163,12 @@ In hac habitasse platea dictumst. Nunc quis tortor sed libero hendrerit dapibu
<description></description>
<content:encoded><![CDATA[This is just a standard text page example. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin metus dolor, hendrerit sit amet, aliquet nec, posuere sed, purus. Nullam et velit iaculis odio sagittis placerat. Duis metus tellus, pellentesque ut, luctus id, egestas a, lorem. Praesent vitae mauris. Aliquam sed nulla. Sed id nunc vitae leo suscipit viverra. Proin at leo ut lacus consequat rhoncus. In hac habitasse platea dictumst. Nunc quis tortor sed libero hendrerit dapibus.
<a href="http://localhost/wordpress/wp-content/uploads/2011/05/200px-Tux.svg_.png"><img class="alignnone size-thumbnail wp-image-13" title="200px-Tux.svg" src="http://localhost/wordpress/wp-content/uploads/2011/05/200px-Tux.svg_-150x150.png" alt="Tux, the Linux mascot" width="150" height="150" /></a>
Integer interdum purus id erat. Duis nec velit vitae dolor mattis euismod. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Suspendisse pellentesque dignissim lacus.
<a href="http://localhost/wordpress/wp-content/uploads/2011/05/200px-Tux.svg_.png"><img class="alignnone size-full wp-image-13" title="200px-Tux.svg" src="http://localhost/wordpress/wp-content/uploads/2011/05/200px-Tux.svg_.png" alt="" width="200" height="235" /></a>
Nulla semper euismod arcu. Suspendisse egestas, erat a consectetur dapibus, felis orci cursus eros, et sollicitudin purus urna et metus. Integer eget est sed nunc euismod vestibulum. Integer nulla dui, tristique in, euismod et, interdum imperdiet, enim. Mauris at lectus. Sed egestas tortor nec mi.]]></content:encoded>
<excerpt:encoded><![CDATA[]]></excerpt:encoded>
<wp:post_id>6</wp:post_id>
@@ -182,12 +190,12 @@ Nulla semper euismod arcu. Suspendisse egestas, erat a consectetur dapibus, fel
<wp:postmeta>
<wp:meta_key>_edit_last</wp:meta_key>
<wp:meta_value><![CDATA[1]]></wp:meta_value>
</wp:postmeta>
</wp:postmeta>
<wp:comment>
<wp:comment_id>2</wp:comment_id>
<wp:comment_author><![CDATA[admin]]></wp:comment_author>
<wp:comment_author_email>admin@example.com</wp:comment_author_email>
<wp:comment_author_url></wp:comment_author_url>
<wp:comment_author_url>http://www.example.com/</wp:comment_author_url>
<wp:comment_author_IP>127.0.0.1</wp:comment_author_IP>
<wp:comment_date>2011-05-21 12:26:24</wp:comment_date>
<wp:comment_date_gmt>2011-05-21 12:26:24</wp:comment_date_gmt>
@@ -201,7 +209,7 @@ Nulla semper euismod arcu. Suspendisse egestas, erat a consectetur dapibus, fel
<wp:comment_id>3</wp:comment_id>
<wp:comment_author><![CDATA[admin]]></wp:comment_author>
<wp:comment_author_email>admin@example.com</wp:comment_author_email>
<wp:comment_author_url>http://www.example.com/</wp:comment_author_url>
<wp:comment_author_url>http://www.example.com/</wp:comment_author_url>
<wp:comment_author_IP>127.0.0.1</wp:comment_author_IP>
<wp:comment_date>2011-05-21 12:26:30</wp:comment_date>
<wp:comment_date_gmt>2011-05-21 12:26:30</wp:comment_date_gmt>
@@ -253,6 +261,8 @@ In hac habitasse platea dictumst. Nunc quis tortor sed libero hendrerit dapibu
<description></description>
<content:encoded><![CDATA[This is just a standard text page example. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin metus dolor, hendrerit sit amet, aliquet nec, posuere sed, purus. Nullam et velit iaculis odio sagittis placerat.
<a href="http://localhost/wordpress/wp-content/uploads/2011/05/cv.txt">This is my CV</a>, please download!
Duis metus tellus, pellentesque ut, luctus id, egestas a, lorem. Praesent vitae mauris. Aliquam sed nulla. Sed id nunc vitae leo suscipit <strong>viverra</strong>. Proin at leo ut lacus consequat rhoncus. In hac habitasse platea dictumst. Nunc quis tortor sed libero hendrerit dapibus. Integer interdum purus id erat. Duis nec velit vitae dolor mattis euismod.
Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Suspendisse pellentesque dignissim lacus. Nulla semper euismod arcu. Suspendisse egestas, erat a consectetur dapibus, felis orci cursus eros, et sollicitudin purus urna et metus. Integer eget est sed nunc euismod vestibulum. Integer nulla dui, tristique in, euismod et, interdum imperdiet, enim. Mauris at lectus. Sed egestas tortor nec mi.]]></content:encoded>
@@ -278,5 +288,71 @@ Class aptent taciti sociosqu ad litora torquent per conubia nostra, per incepto
<wp:meta_value><![CDATA[default]]></wp:meta_value>
</wp:postmeta>
</item>
<item>
<title>200px-Tux.svg</title>
<link>http://localhost/wordpress/?attachment_id=13</link>
<pubDate>Sun, 05 Jun 2011 15:26:51 +0000</pubDate>
<dc:creator>admin</dc:creator>
<guid isPermaLink="false">http://localhost/wordpress/wp-content/uploads/2011/05/200px-Tux.svg_.png</guid>
<description></description>
<content:encoded><![CDATA[]]></content:encoded>
<excerpt:encoded><![CDATA[]]></excerpt:encoded>
<wp:post_id>13</wp:post_id>
<wp:post_date>2011-06-05 15:26:51</wp:post_date>
<wp:post_date_gmt>2011-06-05 15:26:51</wp:post_date_gmt>
<wp:comment_status>open</wp:comment_status>
<wp:ping_status>open</wp:ping_status>
<wp:post_name>200px-tux-svg</wp:post_name>
<wp:status>inherit</wp:status>
<wp:post_parent>6</wp:post_parent>
<wp:menu_order>0</wp:menu_order>
<wp:post_type>attachment</wp:post_type>
<wp:post_password></wp:post_password>
<wp:is_sticky>0</wp:is_sticky>
<wp:attachment_url>http://localhost/wordpress/wp-content/uploads/2011/05/200px-Tux.svg_.png</wp:attachment_url>
<wp:postmeta>
<wp:meta_key>_wp_attached_file</wp:meta_key>
<wp:meta_value><![CDATA[2011/05/200px-Tux.svg_.png]]></wp:meta_value>
</wp:postmeta>
<wp:postmeta>
<wp:meta_key>_wp_attachment_metadata</wp:meta_key>
<wp:meta_value><![CDATA[a:6:{s:5:"width";s:3:"200";s:6:"height";s:3:"235";s:14:"hwstring_small";s:22:"height='96' width='81'";s:4:"file";s:26:"2011/05/200px-Tux.svg_.png";s:5:"sizes";a:2:{s:9:"thumbnail";a:3:{s:4:"file";s:26:"200px-Tux.svg_-150x150.png";s:5:"width";s:3:"150";s:6:"height";s:3:"150";}s:14:"post-thumbnail";a:3:{s:4:"file";s:26:"200px-Tux.svg_-200x198.png";s:5:"width";s:3:"200";s:6:"height";s:3:"198";}}s:10:"image_meta";a:10:{s:8:"aperture";s:1:"0";s:6:"credit";s:0:"";s:6:"camera";s:0:"";s:7:"caption";s:0:"";s:17:"created_timestamp";s:1:"0";s:9:"copyright";s:0:"";s:12:"focal_length";s:1:"0";s:3:"iso";s:1:"0";s:13:"shutter_speed";s:1:"0";s:5:"title";s:0:"";}}]]></wp:meta_value>
</wp:postmeta>
<wp:postmeta>
<wp:meta_key>_wp_attachment_image_alt</wp:meta_key>
<wp:meta_value><![CDATA[Tux, the Linux mascot]]></wp:meta_value>
</wp:postmeta>
</item>
<item>
<title>cv</title>
<link>http://localhost/wordpress/?attachment_id=18</link>
<pubDate>Mon, 06 Jun 2011 17:27:50 +0000</pubDate>
<dc:creator>admin</dc:creator>
<guid isPermaLink="false">http://localhost/wordpress/wp-content/uploads/2011/05/cv.txt</guid>
<description></description>
<content:encoded><![CDATA[]]></content:encoded>
<excerpt:encoded><![CDATA[My CV]]></excerpt:encoded>
<wp:post_id>18</wp:post_id>
<wp:post_date>2011-06-06 17:27:50</wp:post_date>
<wp:post_date_gmt>2011-06-06 17:27:50</wp:post_date_gmt>
<wp:comment_status>open</wp:comment_status>
<wp:ping_status>open</wp:ping_status>
<wp:post_name>cv</wp:post_name>
<wp:status>inherit</wp:status>
<wp:post_parent>10</wp:post_parent>
<wp:menu_order>0</wp:menu_order>
<wp:post_type>attachment</wp:post_type>
<wp:post_password></wp:post_password>
<wp:is_sticky>0</wp:is_sticky>
<wp:attachment_url>http://localhost/wordpress/wp-content/uploads/2011/05/cv.txt</wp:attachment_url>
<wp:postmeta>
<wp:meta_key>_wp_attached_file</wp:meta_key>
<wp:meta_value><![CDATA[2011/05/cv.txt]]></wp:meta_value>
</wp:postmeta>
<wp:postmeta>
<wp:meta_key>_wp_attachment_metadata</wp:meta_key>
<wp:meta_value><![CDATA[a:0:{}]]></wp:meta_value>
</wp:postmeta>
</item>
</channel>
</rss>

View File

@@ -0,0 +1,93 @@
require 'spec_helper'
describe Refinery::WordPress::Attachment, :type => :model do
context "an image attchment" do
let(:attachment) { test_dump.attachments.first }
specify { attachment.title.should == '200px-Tux.svg' }
# doesn't get exported atm. for some reason
specify { attachment.description.should == '' }
specify { attachment.url.should == 'http://localhost/wordpress/wp-content/uploads/2011/05/200px-Tux.svg_.png' }
specify { attachment.file_name.should == '200px-Tux.svg_.png' }
specify { attachment.post_date.should == DateTime.new(2011, 6, 5, 15, 26, 51) }
specify { attachment.should be_an_image }
describe "#to_refinery" do
before do
@image = attachment.to_refinery
end
it "should create an Image from the Attachment" do
@image.should be_a(Image)
end
it "should copy the attributes from Attachment" do
@image.created_at.should == attachment.post_date
@image.image.url.end_with?(attachment.file_name).should be_true
end
end
describe "#replace_url" do
let(:post) { BlogPost.first }
before do
test_dump.authors.each(&:to_refinery)
test_dump.posts.each(&:to_refinery)
@image = attachment.to_refinery
attachment.replace_url
end
specify { post.body.should_not include attachment.url }
specify { post.body.should_not include '200px-Tux.svg_-150x150.png' }
specify { post.body.should_not include 'wp-content' }
it "should replace attachment urls in the generated BlogPosts" do
post.body.should include(@image.image.url)
end
end
end
context "a file attachment" do
let(:attachment) { test_dump.attachments.last }
specify { attachment.title.should == 'cv' }
specify { attachment.url.should == 'http://localhost/wordpress/wp-content/uploads/2011/05/cv.txt' }
specify { attachment.file_name.should == 'cv.txt' }
specify { attachment.post_date.should == DateTime.new(2011, 6, 6, 17, 27, 50) }
specify { attachment.should_not be_an_image }
describe '#to_refinery' do
before do
@resource = attachment.to_refinery
end
specify { Resource.should have(1).record }
specify { @resource.should be_a(Resource) }
it "should copy the attributes from Attachment" do
@resource.created_at.should == attachment.post_date
@resource.file.url.end_with?(attachment.file_name).should be_true
end
end
describe '#replace_resource_url' do
let(:page_part) { Page.last.parts.first }
before do
test_dump.pages.each(&:to_refinery)
@resource = attachment.to_refinery
attachment.replace_url
end
specify { page_part.body.should_not include attachment.url }
specify { page_part.body.should_not include 'wp-content' }
it "should replace attachment urls in the generated BlogPosts" do
page_part.body.should include(@resource.file.url)
end
end
end
end

View File

@@ -3,8 +3,8 @@ 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' }
specify { author.login.should == 'admin' }
specify { author.email.should == 'admin@example.com' }
describe "#to_refinery" do
before do

View File

@@ -18,6 +18,7 @@ describe Refinery::WordPress::Dump, :type => :model do
end
specify { dump.tags.count == 4 }
specify { dump.tags.first.should be_a(Refinery::WordPress::Tag) }
it "should return all included tags" do
tags.each do |tag|
@@ -33,6 +34,7 @@ describe Refinery::WordPress::Dump, :type => :model do
end
specify { dump.categories.count == 4 }
specify { dump.categories.first.should be_a(Refinery::WordPress::Category) }
it "should return all included categories" do
categories.each do |cat|
@@ -46,6 +48,8 @@ describe Refinery::WordPress::Dump, :type => :model do
dump.pages.should have(3).pages
end
specify { dump.pages.first.should be_a(Refinery::WordPress::Page) }
it "should return only published pages with only_published=true" do
dump.pages(true).should have(2).pages
end
@@ -55,6 +59,8 @@ describe Refinery::WordPress::Dump, :type => :model do
it "should return all authors" do
dump.authors.should have(1).author
end
specify { dump.authors.first.should be_a(Refinery::WordPress::Author) }
end
describe "#posts" do
@@ -62,8 +68,18 @@ describe Refinery::WordPress::Dump, :type => :model do
dump.posts.should have(3).posts
end
specify { dump.posts.first.should be_a(Refinery::WordPress::Post) }
it "should return only published posts with only_published=true" do
dump.posts(true).should have(2).posts
end
end
describe "#attachments" do
it "should return all attachments" do
dump.attachments.should have(2).attachments
end
specify { dump.attachments.first.should be_a(Refinery::WordPress::Attachment) }
end
end

View File

@@ -5,15 +5,15 @@ describe Refinery::WordPress::Page, :type => :model do
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 }
specify { page.title.should == 'About me' }
specify { page.content.should include('Lorem ipsum dolor sit') }
specify { page.creator.should == 'admin' }
specify { page.post_date.should == DateTime.new(2011, 5, 21, 12, 25, 42) }
specify { page.post_id.should == 10 }
specify { page.parent_id.should == 8 }
it { page.should == dump.pages.last }
it { page.should_not == dump.pages.first }
specify { page.should == dump.pages.last }
specify { page.should_not == dump.pages.first }
describe "#to_refinery" do
include ::ActionView::Helpers::TagHelper

View File

@@ -3,32 +3,32 @@ 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' }
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' }
it { post.should == test_dump.posts.last }
it { post.should_not == test_dump.posts.first }
specify { post.should == test_dump.posts.last }
specify { 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') }
specify { post.categories.should have(1).category }
specify { post.categories.first.should == Refinery::WordPress::Category.new('Rant') }
end
describe "#tags" do
it { post.tags.should have(3).tags }
specify { 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')) }
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
it { post.tag_list.should == 'css,html,php' }
specify { post.tag_list.should == 'css,html,php' }
describe "#comments" do
it "should return all attached comments" do
@@ -38,14 +38,14 @@ describe Refinery::WordPress::Post, :type => :model do
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 }
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 }
it { comment.should == post.comments.last }
specify { comment.should == post.comments.last }
describe "#to_refinery" do
before do
@@ -79,7 +79,7 @@ describe Refinery::WordPress::Post, :type => :model do
@post = post.to_refinery
end
it { BlogPost.should have(1).record }
specify { BlogPost.should have(1).record }
it "should copy the attributes from Refinery::WordPress::Post" do
@post.title.should == post.title
@@ -106,7 +106,7 @@ describe Refinery::WordPress::Post, :type => :model do
end
it { BlogPost.should have(2).records }
specify { BlogPost.should have(2).records }
it "should create the BlogPost with #post_id attached" do
@post.title.should == "#{post.title}-#{post.post_id}"

12
spec/support/fakeweb.rb Normal file
View File

@@ -0,0 +1,12 @@
require "fakeweb"
FakeWeb.allow_net_connect = false
# Simulating download of wordpress file attachments. The dump expects the files
# to be at the given URLs
FakeWeb.register_uri(:get,
"http://localhost/wordpress/wp-content/uploads/2011/05/200px-Tux.svg_.png",
:body => File.new('spec/fixtures/200px-Tux.svg_.png').read,
:content_type => "image/png")
FakeWeb.register_uri(:get, "http://localhost/wordpress/wp-content/uploads/2011/05/cv.txt", :body => "Hello World!", :content_type => "text/plain")