From 1c1e6ca58ed8c2c09b37e6a826c9c323165fcf2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Trung=20L=C3=AA?= Date: Thu, 22 Sep 2011 00:16:54 +1000 Subject: [PATCH] Ported to work with Spree 0.70.x --- LICENSE | 26 +++++++++ README.markdown => README.md | 16 +++-- Rakefile | 58 +++++++------------ Versionfile | 1 + .../add_email_to_friend_link_to_products.rb | 2 +- app/views/email_sender/send_mail.html.erb | 8 +-- lib/spree/captcha/config.rb | 4 +- lib/spree_email_to_friend.rb | 22 +------ lib/spree_email_to_friend/engine.rb | 21 +++++++ script/rails | 9 +++ .../email_sender_controller_spec.rb | 1 - spec/spec_helper.rb | 21 ++++--- spree_email_to_friend.gemspec | 13 +++-- 13 files changed, 114 insertions(+), 88 deletions(-) create mode 100644 LICENSE rename README.markdown => README.md (57%) create mode 100644 lib/spree_email_to_friend/engine.rb create mode 100644 script/rails diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..9739fca --- /dev/null +++ b/LICENSE @@ -0,0 +1,26 @@ +Copyright (c) 2011 Jorge Calás Lozano, Roman Smirnov, Trung Lê +All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, +are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + * Neither the name Spree nor the names of its contributors may be used to + endorse or promote products derived from this software without specific + prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR +CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR +PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/README.markdown b/README.md similarity index 57% rename from README.markdown rename to README.md index dca0da9..e6d91fa 100644 --- a/README.markdown +++ b/README.md @@ -1,13 +1,17 @@ -# Spree Email to Friend extension +Spree Email to Friend +===================== The Spree Email to Friend extension enables you to send the product reference to your friend via email. -## Installation +Installation +------------ -1. Add the following to your Gemfile +Add the following to your Gemfile -
     gem 'spree_email_to_friend', :git => 'git://github.com/spree/spree_email_to_friend.git'
-
-2. Run `bundle install` \ No newline at end of file +Run + + bundle install + + \ No newline at end of file diff --git a/Rakefile b/Rakefile index 4ff93d2..2460002 100644 --- a/Rakefile +++ b/Rakefile @@ -1,49 +1,31 @@ -require 'rubygems' require 'rake' require 'rake/testtask' - -desc "Default Task" -task :default => [ :spec ] - +require 'rake/packagetask' +require 'rubygems/package_task' require 'rspec/core/rake_task' +require 'cucumber/rake/task' +require 'spree_core/testing_support/common_rake' + RSpec::Core::RakeTask.new +Cucumber::Rake::Task.new -require 'cucumber/rake/task' -Cucumber::Rake::Task.new do |t| - t.cucumber_opts = %w{--format pretty} -end +task :default => [:spec, :cucumber ] -desc "Regenerates a rails 3 app for testing" -task :test_app do - SPREE_PATH = ENV['SPREE_PATH'] - raise "SPREE_PATH should be specified" unless SPREE_PATH - require File.join(SPREE_PATH, 'lib/generators/spree/test_app_generator') - class AuthTestAppGenerator < Spree::Generators::TestAppGenerator - def tweak_gemfile - append_file 'Gemfile' do -<<-gems -gem 'spree_core', :path => '#{File.join(SPREE_PATH, 'core')}' -gem 'spree_auth', :path => '#{File.join(SPREE_PATH, 'auth')}' -gem 'spree_email_to_friend', :path => '#{File.dirname(__FILE__)}' -gems - end - end +spec = eval(File.read('spree_email_to_friend.gemspec')) - def install_gems - system("cd spec/test_app && rake spree_core:install") - system("cd spec/test_app && rake spree_auth:install") - end +Gem::PackageTask.new(spec) do |p| + p.gem_spec = spec +end - def migrate_db - run_migrations - end - end - AuthTestAppGenerator.start +desc "Release to gemcutter" +task :release => :package do + require 'rake/gemcutter' + Rake::Gemcutter::Tasks.new(spec).define + Rake::Task['gem:push'].invoke end -namespace :test_app do - desc 'Rebuild test and cucumber databases' - task :rebuild_dbs do - system("cd spec/test_app && rake db:drop db:migrate RAILS_ENV=test && rake db:drop db:migrate RAILS_ENV=cucumber") - end +desc "Generates a dummy app for testing" +task :test_app do + ENV['LIB_NAME'] = 'spree_email_to_friend' + Rake::Task['common:test_app'].invoke end diff --git a/Versionfile b/Versionfile index 7440d1d..d7906be 100644 --- a/Versionfile +++ b/Versionfile @@ -1,3 +1,4 @@ +"0.70.x" => { :branch => 'master' } "0.60.x" => { :version => '1.1', :ref => '34e52d987be882f6cba783144a9ebfff30b90e15' } "0.50.x" => { :version => '1.1', :ref => '34e52d987be882f6cba783144a9ebfff30b90e15' } "0.40.x" => { :tag => "v1.0.0", :version => "1.0.0" } diff --git a/app/overrides/add_email_to_friend_link_to_products.rb b/app/overrides/add_email_to_friend_link_to_products.rb index 15d6d15..a10d461 100644 --- a/app/overrides/add_email_to_friend_link_to_products.rb +++ b/app/overrides/add_email_to_friend_link_to_products.rb @@ -2,6 +2,6 @@ :name => "converted_product_description_351026984", :insert_bottom => "[data-hook='product_description'], #product_description[data-hook]", :text => "

- <%= link_to(t('email_to_friend.send_to_friend'), email_to_friend_url('product', @product)) %> + <%= link_to t('email_to_friend.send_to_friend'), email_to_friend_url('product', @product) %>

", :disabled => false) \ No newline at end of file diff --git a/app/views/email_sender/send_mail.html.erb b/app/views/email_sender/send_mail.html.erb index 11e418e..bf4b70e 100644 --- a/app/views/email_sender/send_mail.html.erb +++ b/app/views/email_sender/send_mail.html.erb @@ -1,7 +1,7 @@

<%= t('email_to_friend.tell_about', :product => @object.name) %>

-<%= form_for(@mail_to_friend, :url => "") do |f| -%> - <%= render "shared/error_messages", :target => @mail_to_friend %> +<%= form_for(@mail_to_friend, :url => '') do |f| -%> + <%= render 'shared/error_messages', :target => @mail_to_friend %> <%= hook :send_mail_fields, {:f => f} do %>

<%= f.label(:sender_name, t('email_to_friend.sender_name')) %>
@@ -28,6 +28,6 @@ <%= recaptcha_tags :public_key => Spree::Captcha::Config[:public_key], :display => {:theme => Spree::Captcha::Config[:theme]} %> <% end %>

- <%= f.submit(t('email_to_friend.send_message')) %> + <%= f.submit t('email_to_friend.send_message') %>

-<% end -%> +<% end -%> \ No newline at end of file diff --git a/lib/spree/captcha/config.rb b/lib/spree/captcha/config.rb index b74eec6..a6e9b9c 100644 --- a/lib/spree/captcha/config.rb +++ b/lib/spree/captcha/config.rb @@ -3,8 +3,8 @@ class Config < Spree::Config class << self def instance return nil unless ActiveRecord::Base.connection.tables.include?('configurations') - CaptchaConfiguration.find_or_create_by_name("Captcha configuration") + CaptchaConfiguration.find_or_create_by_name('Captcha configuration') end end end -end +end \ No newline at end of file diff --git a/lib/spree_email_to_friend.rb b/lib/spree_email_to_friend.rb index cc60fd3..c07cf7f 100644 --- a/lib/spree_email_to_friend.rb +++ b/lib/spree_email_to_friend.rb @@ -1,22 +1,2 @@ require 'spree_core' -require 'recaptcha/rails' - -module SpreeEmailToFriend - class Engine < Rails::Engine - engine_name 'spree_email_to_friend' - - config.autoload_paths += %W(#{config.root}/lib) - - def self.activate - Dir.glob(File.join(File.dirname(__FILE__), "../app/**/*_decorator*.rb")) do |c| - Rails.application.config.cache_classes ? require(c) : load(c) - end - - Dir.glob(File.join(File.dirname(__FILE__), "../app/overrides/**/*.rb")) do |c| - Rails.application.config.cache_classes ? require(c) : load(c) - end - end - - config.to_prepare &method(:activate).to_proc - end -end +require 'spree_email_to_friend/engine' \ No newline at end of file diff --git a/lib/spree_email_to_friend/engine.rb b/lib/spree_email_to_friend/engine.rb new file mode 100644 index 0000000..93ac1ca --- /dev/null +++ b/lib/spree_email_to_friend/engine.rb @@ -0,0 +1,21 @@ +require 'recaptcha/rails' + +module SpreeEmailToFriend + class Engine < Rails::Engine + engine_name 'spree_email_to_friend' + + config.autoload_paths += %W(#{config.root}/lib) + + def self.activate + Dir.glob(File.join(File.dirname(__FILE__), "../../app/**/*_decorator*.rb")) do |c| + Rails.application.config.cache_classes ? require(c) : load(c) + end + + Dir.glob(File.join(File.dirname(__FILE__), "../../app/overrides/*.rb")) do |c| + Rails.application.config.cache_classes ? require(c) : load(c) + end + end + + config.to_prepare &method(:activate).to_proc + end +end \ No newline at end of file diff --git a/script/rails b/script/rails new file mode 100644 index 0000000..ef2a53b --- /dev/null +++ b/script/rails @@ -0,0 +1,9 @@ +#!/usr/bin/env ruby +# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application. + + +ENGINE_PATH = File.expand_path('../..', __FILE__) +APP_PATH = File.expand_path('../../../config/application', __FILE__) +require File.expand_path('../../../config/boot', __FILE__) +require 'rails/commands' + diff --git a/spec/controllers/email_sender_controller_spec.rb b/spec/controllers/email_sender_controller_spec.rb index 77a16a0..ba4e68b 100644 --- a/spec/controllers/email_sender_controller_spec.rb +++ b/spec/controllers/email_sender_controller_spec.rb @@ -2,7 +2,6 @@ describe EmailSenderController do - #Delete this example and add some real ones it "should use EmailSenderController" do controller.should be_an_instance_of(EmailSenderController) end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index c82b72d..cc1bc1c 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,12 +1,15 @@ -# This file is copied to ~/spec when you run 'ruby script/generate rspec' -# from the project root directory. -ENV["RAILS_ENV"] ||= 'test' -require File.expand_path("../test_app/config/environment", __FILE__) +# Configure Rails Environment +ENV["RAILS_ENV"] = "test" + + +require File.expand_path("../../../config/environment.rb", __FILE__) + + require 'rspec/rails' -# Requires supporting files with custom matchers and macros, etc, -# in ./support/ and its subdirectories. -Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f} +# Requires supporting ruby files with custom matchers and macros, etc, +# in spec/support/ and its subdirectories. +Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f} RSpec.configure do |config| # == Mock Framework @@ -18,11 +21,11 @@ # config.mock_with :rr config.mock_with :rspec + # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures config.fixture_path = "#{::Rails.root}/spec/fixtures" # If you're not using ActiveRecord, or you'd prefer not to run each of your - # examples within a transaction, comment the following line or assign false + # examples within a transaction, remove the following line or assign false # instead of true. config.use_transactional_fixtures = true end - diff --git a/spree_email_to_friend.gemspec b/spree_email_to_friend.gemspec index a1f0d1e..9ce9488 100644 --- a/spree_email_to_friend.gemspec +++ b/spree_email_to_friend.gemspec @@ -4,18 +4,19 @@ Gem::Specification.new do |s| s.name = 'spree_email_to_friend' s.version = '1.2' s.summary = 'Spree extension to send product recommendations to friends' - s.homepage = 'https://github.com/spree/spree_email_to_friend' + s.description = 'Spree extension to send product recommendations to friends' s.required_ruby_version = '>= 1.8.7' s.author = 'Jorge Calás Lozano, Roman Smirnov, Trung Lê' - s.required_ruby_version = '>= 1.8.7' - s.rubygems_version = '1.3.6' + s.homepage = 'https://github.com/spree/spree_email_to_friend' s.files = `git ls-files`.split("\n") s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n") s.require_paths = ["lib"] + s.requirements << 'none' - s.add_dependency('spree_core', '>= 0.30.1') - s.add_dependency('spree_auth', '>= 0.30.1') - s.add_dependency('recaptcha', '>= 0.3.1') + s.add_dependency 'spree_core', '>= 0.70.RC1' + s.add_dependency 'spree_auth', '>= 0.70.RC1' + s.add_dependency 'recaptcha', '>= 0.3.1' + s.add_development_dependency 'rspec-rails' end