diff --git a/.gitignore b/.gitignore index decc337..bf4b0d6 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,6 @@ pkg/ spec/dummy/db/*.sqlite3 spec/dummy/log/*.log spec/dummy/tmp/ +*.un~ +refinerycms-wordpress-import-*.gem +*.swp diff --git a/Gemfile b/Gemfile index d6489a1..1297d72 100644 --- a/Gemfile +++ b/Gemfile @@ -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' diff --git a/Gemfile.lock b/Gemfile.lock index 1f3e0ff..82e738e 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -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 diff --git a/Guardfile b/Guardfile new file mode 100644 index 0000000..7d89890 --- /dev/null +++ b/Guardfile @@ -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 diff --git a/lib/wordpress/attachment.rb b/lib/wordpress/attachment.rb index f4f898d..3026163 100644 --- a/lib/wordpress/attachment.rb +++ b/lib/wordpress/attachment.rb @@ -43,7 +43,12 @@ module Refinery def replace_image_url_in_blog_posts ::BlogPost.all.each do |post| 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! end end diff --git a/spec/dummy/db/migrate/20110613120139_create_seo_meta_for_blog.rb b/spec/dummy/db/migrate/20110613120139_create_seo_meta_for_blog.rb new file mode 100644 index 0000000..baf81a4 --- /dev/null +++ b/spec/dummy/db/migrate/20110613120139_create_seo_meta_for_blog.rb @@ -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 diff --git a/spec/dummy/db/seeds/refinerycms_blog.rb b/spec/dummy/db/seeds/refinerycms_blog.rb index f958fab..0be2a06 100644 --- a/spec/dummy/db/seeds/refinerycms_blog.rb +++ b/spec/dummy/db/seeds/refinerycms_blog.rb @@ -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) -end + ::Page.default_parts.each do |default_page_part| + page.parts.create(:title => default_page_part, :body => nil) + end +end \ No newline at end of file diff --git a/spec/fixtures/200px-Tux.svg_.png b/spec/fixtures/200px-Tux.svg_.png new file mode 100644 index 0000000..75993e2 Binary files /dev/null and b/spec/fixtures/200px-Tux.svg_.png differ diff --git a/spec/fixtures/wordpress_dump.xml b/spec/fixtures/wordpress_dump.xml index 3951383..bffad6b 100644 --- a/spec/fixtures/wordpress_dump.xml +++ b/spec/fixtures/wordpress_dump.xml @@ -16,7 +16,7 @@ - + My test blog http://localhost/wordpress Just another WordPress site - Mon, 06 Jun 2011 17:36:50 +0000 + Mon, 06 Jun 2011 18:42:09 +0000 en 1.1 http://localhost/wordpress @@ -163,6 +163,8 @@ In hac habitasse platea dictumst. Nunc quis tortor sed libero hendrerit dapibu Tux, the Linux mascot + 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. diff --git a/spec/lib/wordpress/attachment_spec.rb b/spec/lib/wordpress/attachment_spec.rb index e77870b..bb08ee6 100644 --- a/spec/lib/wordpress/attachment_spec.rb +++ b/spec/lib/wordpress/attachment_spec.rb @@ -28,6 +28,8 @@ describe Refinery::WordPress::Attachment, :type => :model do end describe "#replace_image_url" do + let(:post) { BlogPost.first } + before do test_dump.authors.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 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 - BlogPost.first.body.should_not include(attachment.url) - BlogPost.first.body.should include(@image.image.url) + post.body.should include(@image.image.url) end + end end @@ -52,5 +58,11 @@ describe Refinery::WordPress::Attachment, :type => :model do 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 + it "should raise an exception for now" do + lambda { attachment.to_refinery }.should raise_error + end + end end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index de25430..c5a4018 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -5,6 +5,18 @@ require File.expand_path("../dummy/config/environment.rb", __FILE__) require "rails/test_help" require "rspec/rails" 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.perform_deliveries = true