Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Started update to work with Spree 0.30.x & Rails3

Special thanks to TBAA
  • Loading branch information...
commit 9aed5a200f173613bb385378994ca2e11d18e917 1 parent c066fe2
@romul romul authored
View
23 LICENSE
@@ -0,0 +1,23 @@
+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 of the Rails Dog LLC 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.
View
0  README.markdown → README.md
File renamed without changes
View
129 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 }
+# require 'cucumber/rake/task'
+# Cucumber::Rake::Task.new do |t|
+# t.cucumber_opts = %w{--format pretty}
+# end
View
3  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
View
2  app/controllers/wishlists_controller.rb
@@ -1,4 +1,4 @@
-class WishlistsController < ApplicationController
+class WishlistsController < Spree::BaseController
resource_controller
helper :products
View
11 app/models/user_decorator.rb
@@ -0,0 +1,11 @@
+User.class_eval do
+ has_many :wishlists
+
+ def wishlist
+ default_wishlist = self.wishlists.first(:conditions => ["is_default = ?", true])
+ default_wishlist ||= self.wishlists.first
+ default_wishlist ||= self.wishlists.create(:name => "My wishlist", :is_default => true)
+ default_wishlist.update_attribute(:is_default, true) unless default_wishlist.is_default?
+ default_wishlist
+ end
+end
View
2  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 %>&nbsp;<%= t(:private) %>
<%= f.radio_button :is_private, false %>&nbsp;<%= t(:public) %>
<% end -%>
View
6 app/views/wishlists/show.html.erb
@@ -30,12 +30,12 @@
<% if @wishlist.user == current_user %>
<td>
<%= 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 -%>
</tbody>
</table>
-<% hook :wishlist_footer_links do %>
+<%= hook :wishlist_footer_links do %>
<div class='footer_links'>
<% if @wishlist.user == current_user %>
<%= link_to t("create_new_wishlist"), new_wishlist_path %>
View
3  config/locales/en-US.yml
@@ -22,3 +22,6 @@ en:
remove_from_wishlist: "Remove from wishlist"
wishlist_actions: "Actions"
your_wishlist_is_empty: "Your wishlist is empty"
+ update_quantity: "Update quantity"
+ item_added_to_wishlist: "Item added to wishlist"
+
View
10 config/routes.rb
@@ -1,5 +1,5 @@
-# Put your extension routes here.
-
-map.resources :wishlists
-map.resources :wished_products
-map.default_wishlist '/wishlist', :controller => :wishlists, :action => 'show'
+Rails.application.routes.draw do
+ resources :wishlists
+ resources :wished_products
+ match '/wishlist' => "wishlists#show", :as => "default_wishlist"
+end
View
17 lib/spree_wishlist.rb
@@ -0,0 +1,17 @@
+require 'spree_core'
+require 'spree_wishlist_hooks'
+
+module SpreeWishlist
+ class Engine < Rails::Engine
+
+ config.autoload_paths += %W(#{config.root}/lib)
+
+ def self.activate
+ Dir.glob(File.join(File.dirname(__FILE__), "../app/**/*_decorator*.rb")) do |c|
+ Rails.env.production? ? require(c) : load(c)
+ end
+ end
+
+ config.to_prepare &method(:activate).to_proc
+ end
+end
View
8 wishlist_hooks.rb → lib/spree_wishlist_hooks.rb
@@ -1,11 +1,9 @@
-class WishlistHooks < Spree::ThemeSupport::HookListener
-
+class SpreeWishlistHooks < Spree::ThemeSupport::HookListener
insert_after :cart_form, 'products/wishlist_form'
insert_after :account_my_orders, 'users/wishlists'
insert_after :wishlist_footer_links do
%(<div id="email_to_friend">
- <%= link_to(t('email_to_friend.send_to_friend'), email_to_friend_url('wishlist', @wishlist)) %>
+ <%= link_to(t('email_to_friend'), email_to_friend_url('wishlist', @wishlist)) %>
</div>)
end
-
-end
+end
View
28 lib/tasks/wishlist_extension_tasks.rake
@@ -1,28 +0,0 @@
-namespace :db do
- desc "Bootstrap your database for Spree."
- task :bootstrap => :environment do
- # load initial database fixtures (in db/sample/*.yml) into the current environment's database
- ActiveRecord::Base.establish_connection(RAILS_ENV.to_sym)
- Dir.glob(File.join(WishlistExtension.root, "db", 'sample', '*.{yml,csv}')).each do |fixture_file|
- Fixtures.create_fixtures("#{WishlistExtension.root}/db/sample", File.basename(fixture_file, '.*'))
- end
- end
-end
-
-namespace :spree do
- namespace :extensions do
- namespace :wishlist do
- desc "Copies public assets of the Wishlist to the instance public/ directory."
- task :update => :environment do
- is_svn_git_or_dir = proc {|path| path =~ /\.svn/ || path =~ /\.git/ || File.directory?(path) }
- Dir[WishlistExtension.root + "/public/**/*"].reject(&is_svn_git_or_dir).each do |file|
- path = file.sub(WishlistExtension.root, '')
- directory = File.dirname(path)
- puts "Copying #{path}..."
- mkdir_p RAILS_ROOT + directory
- cp file, RAILS_ROOT + path
- end
- end
- end
- end
-end
View
60 spec/spec_helper.rb
@@ -1,37 +1,31 @@
-unless defined? SPREE_ROOT
- ENV["RAILS_ENV"] = "test"
- case
- when ENV["SPREE_ENV_FILE"]
- require ENV["SPREE_ENV_FILE"]
- when File.dirname(__FILE__) =~ %r{vendor/SPREE/vendor/extensions}
- require "#{File.expand_path(File.dirname(__FILE__) + "/../../../../../../")}/config/environment"
- else
- require "#{File.expand_path(File.dirname(__FILE__) + "/../../../../")}/config/environment"
- end
-end
-require "#{SPREE_ROOT}/spec/spec_helper"
+# 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("../../../config/environment", __FILE__)
+require 'rspec/rails'
+require 'fabrication'
-if File.directory?(File.dirname(__FILE__) + "/scenarios")
- Scenario.load_paths.unshift File.dirname(__FILE__) + "/scenarios"
-end
-if File.directory?(File.dirname(__FILE__) + "/matchers")
- Dir[File.dirname(__FILE__) + "/matchers/*.rb"].each {|file| require file }
-end
+# Requires supporting files with custom matchers and macros, etc,
+# in ./support/ and its subdirectories.
+Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
-Spec::Runner.configure do |config|
- # config.use_transactional_fixtures = true
- # config.use_instantiated_fixtures = false
- # config.fixture_path = RAILS_ROOT + '/spec/fixtures'
-
- # You can declare fixtures for each behaviour like this:
- # describe "...." do
- # fixtures :table_a, :table_b
- #
- # Alternatively, if you prefer to declare them only once, you can
- # do so here, like so ...
+RSpec.configure do |config|
+ # == Mock Framework
#
- # config.global_fixtures = :table_a, :table_b
+ # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
#
- # If you declare global fixtures, be aware that they will be declared
- # for all of your examples, even those that don't use them.
-end
+ # config.mock_with :mocha
+ # config.mock_with :flexmock
+ # config.mock_with :rr
+ config.mock_with :rspec
+
+ config.fixture_path = "#{::Rails.root}/spec/fixtures"
+
+ #config.include Devise::TestHelpers, :type => :controller
+ # 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
+ # instead of true.
+ config.use_transactional_fixtures = true
+end
+
+@configuration ||= AppConfiguration.find_or_create_by_name("Default configuration")
View
23 spree_wishlist.gemspec
@@ -0,0 +1,23 @@
+Gem::Specification.new do |s|
+ s.platform = Gem::Platform::RUBY
+ s.name = 'spree_wishlist'
+ s.version = '0.30.0.beta2'
+ s.summary = 'Add wishlists to Spree'
+ #s.description = 'Add (optional) gem description here'
+ s.required_ruby_version = '>= 1.8.7'
+
+ s.author = 'Roman Smirnov'
+ # s.email = 'david@loudthinking.com'
+ # s.homepage = 'http://www.rubyonrails.org'
+ # s.rubyforge_project = 'actionmailer'
+
+ s.files = Dir['CHANGELOG', 'README.md', 'LICENSE', 'lib/**/*', 'app/**/*']
+ s.require_path = 'lib'
+ s.requirements << 'none'
+
+ s.has_rdoc = true
+
+ s.add_dependency('spree_core', '>= 0.30.0')
+ s.add_dependency('spree_auth', '>= 0.30.0')
+ s.add_dependency('spree_email_to_friend', '>= 0.30.0.beta2')
+end
View
50 wishlist_extension.rb
@@ -1,50 +0,0 @@
-# Uncomment this if you reference any of your controllers in activate
-# require_dependency 'application'
-
-class WishlistExtension < Spree::Extension
- version "1.0"
- description "Describe your extension here"
- url "http://yourwebsite.com/wishlist"
-
- # Please use wishlist/config/routes.rb instead for extension routes.
-
- # def self.require_gems(config)
- # config.gem "gemname-goes-here", :version => '1.2.3'
- # end
-
- def activate
-
- User.class_eval do
- has_many :wishlists
-
- def wishlist
- default_wishlist = self.wishlists.first(:conditions => ["is_default = ?", true])
- default_wishlist ||= self.wishlists.first
- default_wishlist ||= self.wishlists.create(:name => "My wishlist", :is_default => true)
- default_wishlist.update_attribute(:is_default, true) unless default_wishlist.is_default?
- default_wishlist
- end
- end
-
- # Add your extension tab to the admin.
- # Requires that you have defined an admin controller:
- # app/controllers/admin/yourextension_controller
- # and that you mapped your admin in config/routes
-
- #Admin::BaseController.class_eval do
- # before_filter :add_yourextension_tab
- #
- # def add_yourextension_tab
- # # add_extension_admin_tab takes an array containing the same arguments expected
- # # by the tab helper method:
- # # [ :extension_name, { :label => "Your Extension", :route => "/some/non/standard/route" } ]
- # add_extension_admin_tab [ :yourextension ]
- # end
- #end
-
- # make your helper avaliable in all views
- # Spree::BaseController.class_eval do
- # helper YourHelper
- # end
- end
-end

0 comments on commit 9aed5a2

Please sign in to comment.
Something went wrong with that request. Please try again.