Image import working

* bundle update
* replacement of image URLs now considers wordpress thumbnails (like -150x150)
* added Guard for autotesting
This commit is contained in:
Marc Remolt 2011-06-13 15:02:40 +02:00
parent 7265d31f62
commit a24ea686fa
11 changed files with 139 additions and 25 deletions

3
.gitignore vendored
View File

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

View File

@ -3,9 +3,17 @@ source "http://rubygems.org"
gem "rails", "3.0.7" gem "rails", "3.0.7"
#gem "capybara", ">= 1.0.0.beta1" #gem "capybara", ">= 1.0.0.beta1"
gem "sqlite3" gem "sqlite3"
gem "rmagick"
group :development, :test do
gem "rspec-rails", ">= 2.6.0" gem "rspec-rails", ">= 2.6.0"
gem "database_cleaner" 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+) # To use debugger (ruby-debug for Ruby 1.8.7+, ruby-debug19 for Ruby 1.9.2+)
# gem 'ruby-debug' # gem 'ruby-debug'

View File

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

@ -43,7 +43,12 @@ module Refinery
def replace_image_url_in_blog_posts def replace_image_url_in_blog_posts
::BlogPost.all.each do |post| ::BlogPost.all.each do |post|
if post.body.include? url if post.body.include? url
post.body = post.body.gsub(url, refinery_image.image.url) url_parts = url.split('.')
extension = url_parts.pop
url_without_extension = url_parts.join('.')
pattern = /#{url_without_extension}(-\d+x\d+)?\.#{extension}/
post.body = post.body.gsub(pattern, refinery_image.image.url)
post.save! post.save!
end end
end end

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,9 +1,12 @@
User.find(:all).each do |user| ::User.find(:all).each do |user|
if user.plugins.where(:name => 'refinerycms_blog').blank?
user.plugins.create(:name => "refinerycms_blog", user.plugins.create(:name => "refinerycms_blog",
:position => (user.plugins.maximum(:position) || -1) +1) :position => (user.plugins.maximum(:position) || -1) +1)
end end
end if defined?(::User)
page = Page.create( if defined?(::Page)
page = ::Page.create(
:title => "Blog", :title => "Blog",
:link_url => "/blog", :link_url => "/blog",
:deletable => false, :deletable => false,
@ -11,6 +14,7 @@ page = Page.create(
:menu_match => "^/blogs?(\/|\/.+?|)$" :menu_match => "^/blogs?(\/|\/.+?|)$"
) )
Page.default_parts.each do |default_page_part| ::Page.default_parts.each do |default_page_part|
page.parts.create(:title => default_page_part, :body => nil) page.parts.create(:title => default_page_part, :body => nil)
end 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. --> <!-- 7. WordPress will then import each of the posts, pages, comments, categories, etc. -->
<!-- contained in this file into your site. --> <!-- contained in this file into your site. -->
<!-- generator="WordPress/3.1.2" created="2011-06-06 17:36" --> <!-- generator="WordPress/3.1.2" created="2011-06-06 18:42" -->
<rss version="2.0" <rss version="2.0"
xmlns:excerpt="http://wordpress.org/export/1.1/excerpt/" xmlns:excerpt="http://wordpress.org/export/1.1/excerpt/"
xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:content="http://purl.org/rss/1.0/modules/content/"
@ -29,7 +29,7 @@
<title>My test blog</title> <title>My test blog</title>
<link>http://localhost/wordpress</link> <link>http://localhost/wordpress</link>
<description>Just another WordPress site</description> <description>Just another WordPress site</description>
<pubDate>Mon, 06 Jun 2011 17:36:50 +0000</pubDate> <pubDate>Mon, 06 Jun 2011 18:42:09 +0000</pubDate>
<language>en</language> <language>en</language>
<wp:wxr_version>1.1</wp:wxr_version> <wp:wxr_version>1.1</wp:wxr_version>
<wp:base_site_url>http://localhost/wordpress</wp:base_site_url> <wp:base_site_url>http://localhost/wordpress</wp:base_site_url>
@ -163,6 +163,8 @@ In hac habitasse platea dictumst. Nunc quis tortor sed libero hendrerit dapibu
<description></description> <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. <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. 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> <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>

View File

@ -28,6 +28,8 @@ describe Refinery::WordPress::Attachment, :type => :model do
end end
describe "#replace_image_url" do describe "#replace_image_url" do
let(:post) { BlogPost.first }
before do before do
test_dump.authors.each(&:to_refinery) test_dump.authors.each(&:to_refinery)
test_dump.posts.each(&:to_refinery) test_dump.posts.each(&:to_refinery)
@ -36,11 +38,15 @@ describe Refinery::WordPress::Attachment, :type => :model do
attachment.replace_image_url_in_blog_posts attachment.replace_image_url_in_blog_posts
end 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 it "should replace attachment urls in the generated BlogPosts" do
BlogPost.first.body.should_not include(attachment.url) post.body.should include(@image.image.url)
BlogPost.first.body.should include(@image.image.url)
end end
end end
end end
@ -52,5 +58,11 @@ describe Refinery::WordPress::Attachment, :type => :model do
specify { attachment.file_name.should == 'cv.txt' } specify { attachment.file_name.should == 'cv.txt' }
specify { attachment.post_date.should == DateTime.new(2011, 6, 6, 17, 27, 50) } specify { attachment.post_date.should == DateTime.new(2011, 6, 6, 17, 27, 50) }
specify { attachment.should_not be_an_image } specify { attachment.should_not be_an_image }
describe '#to_refinery' do
it "should raise an exception for now" do
lambda { attachment.to_refinery }.should raise_error
end
end
end end
end end

View File

@ -5,6 +5,18 @@ require File.expand_path("../dummy/config/environment.rb", __FILE__)
require "rails/test_help" require "rails/test_help"
require "rspec/rails" require "rspec/rails"
require "database_cleaner" require "database_cleaner"
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")
ActionMailer::Base.delivery_method = :test ActionMailer::Base.delivery_method = :test
ActionMailer::Base.perform_deliveries = true ActionMailer::Base.perform_deliveries = true