From e632db25917f5ddbe07e854b2ed3418aad7ed0f1 Mon Sep 17 00:00:00 2001 From: Dominik Masur Date: Tue, 30 Nov 2010 17:59:42 +0100 Subject: [PATCH 1/5] rails3 changes --- README.markdown | 3 - Rakefile | 129 +++--------------- app/controllers/wished_products_controller.rb | 3 +- app/controllers/wishlists_controller.rb | 14 +- app/views/wishlists/_accessibility.html.erb | 2 +- app/views/wishlists/show.html.erb | 6 +- config/locales/en-US.yml | 11 ++ config/routes.rb | 12 +- lib/tasks/wishlist_extension_tasks.rake | 28 ---- public/javascripts/wishlist.js | 1 + spec/spec_helper.rb | 60 ++++---- wishlist_extension.rb | 50 ------- wishlist_hooks.rb | 11 -- 13 files changed, 85 insertions(+), 245 deletions(-) delete mode 100644 README.markdown delete mode 100644 lib/tasks/wishlist_extension_tasks.rake delete mode 100644 wishlist_extension.rb delete mode 100644 wishlist_hooks.rb diff --git a/README.markdown b/README.markdown deleted file mode 100644 index 76684b9..0000000 --- a/README.markdown +++ /dev/null @@ -1,3 +0,0 @@ -= Wishlist - -Description goes here \ No newline at end of file diff --git a/Rakefile b/Rakefile index 164c3a9..ebdaab8 100644 --- a/Rakefile +++ b/Rakefile @@ -1,120 +1,31 @@ -# I think this is the one that should be moved to the extension Rakefile template - -# In rails 1.2, plugins aren't available in the path until they're loaded. -# Check to see if the rspec plugin is installed first and require -# it if it is. If not, use the gem version. - -# Determine where the RSpec plugin is by loading the boot -unless defined? SPREE_ROOT - ENV["RAILS_ENV"] = "test" - case - when ENV["SPREE_ENV_FILE"] - require File.dirname(ENV["SPREE_ENV_FILE"]) + "/boot" - when File.dirname(__FILE__) =~ %r{vendor/SPREE/vendor/extensions} - require "#{File.expand_path(File.dirname(__FILE__) + "/../../../../../")}/config/boot" - else - require "#{File.expand_path(File.dirname(__FILE__) + "/../../../")}/config/boot" - end -end +require File.expand_path('../../config/application', __FILE__) +require 'rubygems' require 'rake' -require 'rake/rdoctask' require 'rake/testtask' +require 'rake/packagetask' +require 'rake/gempackagetask' -rspec_base = File.expand_path(SPREE_ROOT + '/vendor/plugins/rspec/lib') -$LOAD_PATH.unshift(rspec_base) if File.exist?(rspec_base) -require 'spec/rake/spectask' -# require 'spec/translator' - -# Cleanup the SPREE_ROOT constant so specs will load the environment -Object.send(:remove_const, :SPREE_ROOT) - -extension_root = File.expand_path(File.dirname(__FILE__)) - -task :default => :spec -task :stats => "spec:statsetup" +spec = eval(File.read('wishlist.gemspec')) -desc "Run all specs in spec directory" -Spec::Rake::SpecTask.new(:spec) do |t| - t.spec_opts = ['--options', "\"#{extension_root}/spec/spec.opts\""] - t.spec_files = FileList["#{extension_root}/spec/**/*_spec.rb"] +Rake::GemPackageTask.new(spec) do |p| + p.gem_spec = spec end -namespace :spec do - desc "Run all specs in spec directory with RCov" - Spec::Rake::SpecTask.new(:rcov) do |t| - t.spec_opts = ['--options', "\"#{extension_root}/spec/spec.opts\""] - t.spec_files = FileList['spec/**/*_spec.rb'] - t.rcov = true - t.rcov_opts = ['--exclude', 'spec', '--rails'] - end - - desc "Print Specdoc for all specs" - Spec::Rake::SpecTask.new(:doc) do |t| - t.spec_opts = ["--format", "specdoc", "--dry-run"] - t.spec_files = FileList['spec/**/*_spec.rb'] - end - - [:models, :controllers, :views, :helpers].each do |sub| - desc "Run the specs under spec/#{sub}" - Spec::Rake::SpecTask.new(sub) do |t| - t.spec_opts = ['--options', "\"#{extension_root}/spec/spec.opts\""] - t.spec_files = FileList["spec/#{sub}/**/*_spec.rb"] - end - end - - # Hopefully no one has written their extensions in pre-0.9 style - # desc "Translate specs from pre-0.9 to 0.9 style" - # task :translate do - # translator = ::Spec::Translator.new - # dir = RAILS_ROOT + '/spec' - # translator.translate(dir, dir) - # end - - # Setup specs for stats - task :statsetup do - require 'code_statistics' - ::STATS_DIRECTORIES << %w(Model\ specs spec/models) - ::STATS_DIRECTORIES << %w(View\ specs spec/views) - ::STATS_DIRECTORIES << %w(Controller\ specs spec/controllers) - ::STATS_DIRECTORIES << %w(Helper\ specs spec/views) - ::CodeStatistics::TEST_TYPES << "Model specs" - ::CodeStatistics::TEST_TYPES << "View specs" - ::CodeStatistics::TEST_TYPES << "Controller specs" - ::CodeStatistics::TEST_TYPES << "Helper specs" - ::STATS_DIRECTORIES.delete_if {|a| a[0] =~ /test/} - end - - namespace :db do - namespace :fixtures do - desc "Load fixtures (from spec/fixtures) into the current environment's database. Load specific fixtures using FIXTURES=x,y" - task :load => :environment do - require 'active_record/fixtures' - ActiveRecord::Base.establish_connection(RAILS_ENV.to_sym) - (ENV['FIXTURES'] ? ENV['FIXTURES'].split(/,/) : Dir.glob(File.join(RAILS_ROOT, 'spec', 'fixtures', '*.{yml,csv}'))).each do |fixture_file| - Fixtures.create_fixtures('spec/fixtures', File.basename(fixture_file, '.*')) - end - end - end - end +desc "Release to gemcutter" +task :release => :package do + require 'rake/gemcutter' + Rake::Gemcutter::Tasks.new(spec).define + Rake::Task['gem:push'].invoke end -desc 'Generate documentation for the wishlist extension.' -Rake::RDocTask.new(:rdoc) do |rdoc| - rdoc.rdoc_dir = 'rdoc' - rdoc.title = 'WishlistExtension' - rdoc.options << '--line-numbers' << '--inline-source' - rdoc.rdoc_files.include('README') - rdoc.rdoc_files.include('lib/**/*.rb') -end +desc "Default Task" +task :default => [ :spec ] -# For extensions that are in transition -desc 'Test the wishlist extension.' -Rake::TestTask.new(:test) do |t| - t.libs << 'lib' - t.pattern = 'test/**/*_test.rb' - t.verbose = true -end +require 'rspec/core/rake_task' +RSpec::Core::RakeTask.new -# Load any custom rakefiles for extension -Dir[File.dirname(__FILE__) + '/tasks/*.rake'].sort.each { |f| require f } \ No newline at end of file +# require 'cucumber/rake/task' +# Cucumber::Rake::Task.new do |t| +# t.cucumber_opts = %w{--format pretty} +# end \ No newline at end of file diff --git a/app/controllers/wished_products_controller.rb b/app/controllers/wished_products_controller.rb index 093eede..e20450e 100644 --- a/app/controllers/wished_products_controller.rb +++ b/app/controllers/wished_products_controller.rb @@ -1,6 +1,5 @@ -class WishedProductsController < ApplicationController +class WishedProductsController < Spree::BaseController resource_controller - # I'm sorry for this hack, but it is simplest way to make adding to wishlist after user logged in, # because redirect_to can not make POST requests def index diff --git a/app/controllers/wishlists_controller.rb b/app/controllers/wishlists_controller.rb index 1ebba43..13dc8c3 100644 --- a/app/controllers/wishlists_controller.rb +++ b/app/controllers/wishlists_controller.rb @@ -1,4 +1,4 @@ -class WishlistsController < ApplicationController +class WishlistsController < Spree::BaseController resource_controller helper :products @@ -11,6 +11,18 @@ class WishlistsController < ApplicationController render :js => "alert('#{t :updated_successfully}');" } + def email_to_friend + @wishlist = object + if request.post? + if params[:email].blank? + flash[:error] = t('email_address_missing') + else + WishlistMailer.email_wishlist_to_friend(current_user, @wishlist, params).deliver + flash[:notice] = t('wishlist_email_sent') + redirect_to wishlist_path(@wishlist) + end + end + end private def object diff --git a/app/views/wishlists/_accessibility.html.erb b/app/views/wishlists/_accessibility.html.erb index 5d6fb13..24d10bd 100644 --- a/app/views/wishlists/_accessibility.html.erb +++ b/app/views/wishlists/_accessibility.html.erb @@ -1,4 +1,4 @@ -<% form_for @wishlist, :html => {:class => 'ajax_form', :id => 'change_wishlist_accessibility'} do |f| %> +<%= form_for @wishlist, :html => {:class => 'ajax_form', :id => 'change_wishlist_accessibility'} do |f| %> <%= f.radio_button :is_private, true %> <%= t(:private) %> <%= f.radio_button :is_private, false %> <%= t(:public) %> <% end -%> diff --git a/app/views/wishlists/show.html.erb b/app/views/wishlists/show.html.erb index 8956445..5e689cc 100644 --- a/app/views/wishlists/show.html.erb +++ b/app/views/wishlists/show.html.erb @@ -30,12 +30,12 @@ <% if @wishlist.user == current_user %> <%= link_to t("remove_from_wishlist"), wish, :method => :delete %> - <% form_for :order, :url => orders_url do |f| %> + <%= form_for :order, :url => populate_orders_url do |f| %> <%= hidden_field_tag "variants[#{variant.id}]", 1, :size => 3 %> <%= link_to t(:add_to_cart), '#', :onclick => "$(this).parent().submit(); return false;" %> <% end -%> <%= t("move_to_another_wishlist") %>: - <% form_for wish do |f| %> + <%= form_for wish do |f| %> <%= f.select :wishlist_id, current_user.wishlists.map{|wl| [wl.name, wl.id]} %> <%= f.submit t(:move) %> <% end -%> @@ -72,7 +72,7 @@ <% end -%> -<% hook :wishlist_footer_links do %> +<%= hook :wishlist_footer_links do %>