diff --git a/.gitignore b/.gitignore index 8b7bf944..00481b75 100644 --- a/.gitignore +++ b/.gitignore @@ -8,11 +8,7 @@ .loadpath .project *.swp -public/dispatch.cgi -public/dispatch.fcgi -public/dispatch.rb -httpd -pgsql +spec/dummy config/*-public.asc config/database.yml config/mongrel_cluster.yml @@ -20,26 +16,14 @@ db/*.sql db/*.sqlite3* db/schema.rb doc/**/* -lib/products_index_profiler.rb log/*.log -pkg public/assets -public/attachments -public/blank_iframe.html public/images public/javascripts public/stylesheets -public/ckeditora -spree.gemspec -spree_dev -spree_test tmp vendor/rails vendor/extensions/google_base public/google_base.xml public/template_google_base.xml coverage/* -var -TAGS -nbproject -vendor/extensions/theme_default/app/stylesheets/*.css diff --git a/.rspec b/.rspec new file mode 100644 index 00000000..7ab5f55c --- /dev/null +++ b/.rspec @@ -0,0 +1,4 @@ +--color +--format +progress +--backtrace diff --git a/Gemfile b/Gemfile new file mode 100644 index 00000000..af4e3ace --- /dev/null +++ b/Gemfile @@ -0,0 +1,13 @@ +source 'http://rubygems.org' + +gem 'rails' + +if RUBY_VERSION < "1.9" + gem "ruby-debug" +else + gem "ruby-debug19" +end + +gemspec +gem 'spree' +gem 'ffaker' diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 00000000..47338063 --- /dev/null +++ b/Gemfile.lock @@ -0,0 +1,243 @@ +PATH + remote: . + specs: + spree_multi_domain (1.3.05) + spree_core (~> 1.0.3) + +GEM + remote: http://rubygems.org/ + specs: + actionmailer (3.1.4) + actionpack (= 3.1.4) + mail (~> 2.3.0) + actionpack (3.1.4) + activemodel (= 3.1.4) + activesupport (= 3.1.4) + builder (~> 3.0.0) + erubis (~> 2.7.0) + i18n (~> 0.6) + rack (~> 1.3.6) + rack-cache (~> 1.1) + rack-mount (~> 0.8.2) + rack-test (~> 0.6.1) + sprockets (~> 2.0.3) + active_utils (1.0.3) + activesupport (>= 2.3.11) + i18n + activemerchant (1.20.1) + active_utils (>= 1.0.1) + activesupport (>= 2.3.11) + braintree (>= 2.0.0) + builder (>= 2.0.0) + i18n + json (>= 1.5.1) + money (<= 3.7.1) + activemodel (3.1.4) + activesupport (= 3.1.4) + builder (~> 3.0.0) + i18n (~> 0.6) + activerecord (3.1.4) + activemodel (= 3.1.4) + activesupport (= 3.1.4) + arel (~> 2.2.3) + tzinfo (~> 0.3.29) + activeresource (3.1.4) + activemodel (= 3.1.4) + activesupport (= 3.1.4) + activesupport (3.1.4) + multi_json (~> 1.0) + acts_as_list (0.1.4) + archive-tar-minitar (0.5.2) + arel (2.2.3) + bcrypt-ruby (3.0.1) + braintree (2.14.0) + builder (>= 2.0.0) + builder (3.0.0) + cancan (1.6.7) + capybara (1.0.1) + mime-types (>= 1.16) + nokogiri (>= 1.3.3) + rack (>= 1.0.0) + rack-test (>= 0.5.4) + selenium-webdriver (~> 2.0) + xpath (~> 0.1.4) + childprocess (0.3.1) + ffi (~> 1.0.6) + cocaine (0.2.1) + columnize (0.3.6) + deface (0.8.0) + nokogiri (~> 1.5.0) + rails (>= 3.0.9) + devise (1.4.8) + bcrypt-ruby (~> 3.0) + orm_adapter (~> 0.0.3) + warden (~> 1.0.3) + diff-lcs (1.1.3) + erubis (2.7.0) + factory_girl (2.6.4) + activesupport (>= 2.3.9) + ffaker (1.12.1) + ffi (1.0.11) + highline (1.6.8) + hike (1.2.1) + i18n (0.6.0) + jquery-rails (1.0.19) + railties (~> 3.0) + thor (~> 0.14) + json (1.6.5) + kaminari (0.13.0) + actionpack (>= 3.0.0) + activesupport (>= 3.0.0) + railties (>= 3.0.0) + linecache19 (0.5.12) + ruby_core_source (>= 0.1.4) + mail (2.3.3) + i18n (>= 0.4.0) + mime-types (~> 1.16) + treetop (~> 1.4.8) + meta_search (1.1.1) + actionpack (~> 3.1.0) + activerecord (~> 3.1.0) + activesupport (~> 3.1.0) + polyamorous (~> 0.5.0) + mime-types (1.18) + money (3.7.1) + i18n (~> 0.4) + multi_json (1.1.0) + nested_set (1.6.8) + activerecord (>= 3.0.0) + railties (>= 3.0.0) + nokogiri (1.5.2) + orm_adapter (0.0.6) + paperclip (2.5.0) + activerecord (>= 2.3.0) + activesupport (>= 2.3.2) + cocaine (>= 0.0.2) + mime-types + polyamorous (0.5.0) + activerecord (~> 3.0) + polyglot (0.3.3) + rack (1.3.6) + rack-cache (1.2) + rack (>= 0.4) + rack-mount (0.8.3) + rack (>= 1.0.0) + rack-ssl (1.3.2) + rack + rack-test (0.6.1) + rack (>= 1.0) + rails (3.1.4) + actionmailer (= 3.1.4) + actionpack (= 3.1.4) + activerecord (= 3.1.4) + activeresource (= 3.1.4) + activesupport (= 3.1.4) + bundler (~> 1.0) + railties (= 3.1.4) + railties (3.1.4) + actionpack (= 3.1.4) + activesupport (= 3.1.4) + rack-ssl (~> 1.3.2) + rake (>= 0.8.7) + rdoc (~> 3.4) + thor (~> 0.14.6) + rake (0.9.2.2) + rdoc (3.12) + json (~> 1.4) + rspec (2.9.0) + rspec-core (~> 2.9.0) + rspec-expectations (~> 2.9.0) + rspec-mocks (~> 2.9.0) + rspec-core (2.9.0) + rspec-expectations (2.9.0) + diff-lcs (~> 1.1.3) + rspec-mocks (2.9.0) + rspec-rails (2.9.0) + actionpack (>= 3.0) + activesupport (>= 3.0) + railties (>= 3.0) + rspec (~> 2.9.0) + ruby-debug-base19 (0.11.25) + columnize (>= 0.3.1) + linecache19 (>= 0.5.11) + ruby_core_source (>= 0.1.4) + ruby-debug19 (0.11.6) + columnize (>= 0.3.1) + linecache19 (>= 0.5.11) + ruby-debug-base19 (>= 0.11.19) + ruby_core_source (0.1.5) + archive-tar-minitar (>= 0.5.2) + rubyzip (0.9.6.1) + selenium-webdriver (2.20.0) + childprocess (>= 0.2.5) + ffi (~> 1.0) + multi_json (~> 1.0) + rubyzip + spree (1.0.3) + spree_api (= 1.0.3) + spree_auth (= 1.0.3) + spree_cmd (= 1.0.3) + spree_core (= 1.0.3) + spree_dash (= 1.0.3) + spree_promo (= 1.0.3) + spree_sample (= 1.0.3) + spree_api (1.0.3) + spree_auth (= 1.0.3) + spree_core (= 1.0.3) + spree_auth (1.0.3) + cancan (= 1.6.7) + devise (= 1.4.8) + spree_core (= 1.0.3) + spree_cmd (1.0.3) + spree_core (1.0.3) + activemerchant (= 1.20.1) + acts_as_list (= 0.1.4) + deface (>= 0.7.2) + ffaker (~> 1.12.0) + highline (= 1.6.8) + jquery-rails (>= 1.0.18, <= 1.0.19) + kaminari (>= 0.13.0) + meta_search (= 1.1.1) + nested_set (= 1.6.8) + paperclip (= 2.5.0) + rails (>= 3.1.1, <= 3.1.4) + state_machine (= 1.1.1) + stringex (~> 1.3.0) + spree_dash (1.0.3) + spree_core (= 1.0.3) + spree_promo (1.0.3) + spree_auth (= 1.0.3) + spree_core (= 1.0.3) + spree_sample (1.0.3) + spree_core (= 1.0.3) + sprockets (2.0.3) + hike (~> 1.2) + rack (~> 1.0) + tilt (~> 1.1, != 1.3.0) + sqlite3 (1.3.5) + state_machine (1.1.1) + stringex (1.3.2) + thor (0.14.6) + tilt (1.3.3) + treetop (1.4.10) + polyglot + polyglot (>= 0.3.1) + tzinfo (0.3.32) + warden (1.0.6) + rack (>= 1.0) + xpath (0.1.4) + nokogiri (~> 1.3) + +PLATFORMS + ruby + +DEPENDENCIES + capybara (= 1.0.1) + factory_girl + ffaker + rails + rspec-rails (~> 2.7) + ruby-debug19 + spree + spree_multi_domain! + sqlite3 diff --git a/Rakefile b/Rakefile index 53c9f745..c433257c 100644 --- a/Rakefile +++ b/Rakefile @@ -1,12 +1,20 @@ -require 'rubygems' +# encoding: utf-8 +ENV['LIB_NAME'] = 'spree_multi_domain' + require 'rake' require 'rake/testtask' require 'rake/packagetask' -require 'rake/gempackagetask' +require 'rubygems/package_task' +require 'rspec/core/rake_task' +require 'spree/core/testing_support/common_rake' + +RSpec::Core::RakeTask.new + +task :default => [:spec] spec = eval(File.read('spree_multi_domain.gemspec')) -Rake::GemPackageTask.new(spec) do |p| +Gem::PackageTask.new(spec) do |p| p.gem_spec = spec end @@ -15,4 +23,10 @@ task :release => :package do require 'rake/gemcutter' Rake::Gemcutter::Tasks.new(spec).define Rake::Task['gem:push'].invoke -end \ No newline at end of file +end + +desc "Generates a dummy app for testing" +task :test_app do + ENV['LIB_NAME'] = 'spree_multi_domain' + Rake::Task['common:test_app'].invoke +end diff --git a/Versionfile b/Versionfile index 8ce599ae..3214b0ec 100644 --- a/Versionfile +++ b/Versionfile @@ -1,5 +1,6 @@ -"0.30.x" => { :branch => "0-30-x" } -"0.40.x" => { :branch => "0-40-stable" } -"0.50.x" => { :branch => "0-40-stable" } +"1.0.x" => { :branch => "master"} +"0.70.x" => { :branch => "0-60-stable" } "0.60.x" => { :branch => "0-60-stable" } -"0.70.x" => { :branch => "master" } +"0.50.x" => { :branch => "0-40-stable" } +"0.40.x" => { :branch => "0-40-stable" } +"0.30.x" => { :branch => "0-30-x" } diff --git a/app/controllers/admin/stores_controller.rb b/app/controllers/admin/stores_controller.rb deleted file mode 100644 index 64ce7f3e..00000000 --- a/app/controllers/admin/stores_controller.rb +++ /dev/null @@ -1,8 +0,0 @@ -class Admin::StoresController < Admin::BaseController - resource_controller - ssl_required - - update.wants.html { redirect_to collection_url } - create.wants.html { redirect_to collection_url } - destroy.success.wants.js { render_js_for_destroy } -end diff --git a/app/controllers/products_controller_decorator.rb b/app/controllers/products_controller_decorator.rb deleted file mode 100644 index 4c9895d5..00000000 --- a/app/controllers/products_controller_decorator.rb +++ /dev/null @@ -1,12 +0,0 @@ -ProductsController.class_eval do - before_filter :can_show_product, :only => :show - - private - def can_show_product - @product ||= Product.find_by_permalink!(params[:id]) - if @product.stores.empty? || @product.stores.include?(@site) - render :file => "public/404.html", :status => 404 - end - end - -end diff --git a/app/controllers/admin/products_controller_decorator.rb b/app/controllers/spree/admin/products_controller_decorator.rb similarity index 56% rename from app/controllers/admin/products_controller_decorator.rb rename to app/controllers/spree/admin/products_controller_decorator.rb index a92f36e7..e642e575 100644 --- a/app/controllers/admin/products_controller_decorator.rb +++ b/app/controllers/spree/admin/products_controller_decorator.rb @@ -1,13 +1,9 @@ -Admin::ProductsController.class_eval do +Spree::Admin::ProductsController.class_eval do update.before :set_stores - create.before :add_to_all_stores - private def set_stores @product.store_ids = nil unless params[:product].key? :store_ids end - def add_to_all_stores - end end diff --git a/app/controllers/spree/admin/stores_controller.rb b/app/controllers/spree/admin/stores_controller.rb new file mode 100644 index 00000000..9a25d2f5 --- /dev/null +++ b/app/controllers/spree/admin/stores_controller.rb @@ -0,0 +1,3 @@ +class Spree::Admin::StoresController < Spree::Admin::ResourceController + +end diff --git a/app/controllers/spree/products_controller_decorator.rb b/app/controllers/spree/products_controller_decorator.rb new file mode 100644 index 00000000..137948db --- /dev/null +++ b/app/controllers/spree/products_controller_decorator.rb @@ -0,0 +1,12 @@ +Spree::ProductsController.class_eval do + before_filter :can_show_product, :only => :show + + private + def can_show_product + @product ||= Spree::Product.find_by_permalink!(params[:id]) + if @product.stores.empty? || @product.stores.include?(@site) + render :file => "#{::Rails.root}/public/404.html", :status => 404 + end + end + +end diff --git a/app/mailers/order_mailer.rb b/app/mailers/spree/order_mailer.rb similarity index 93% rename from app/mailers/order_mailer.rb rename to app/mailers/spree/order_mailer.rb index 9b758988..a07ab658 100644 --- a/app/mailers/order_mailer.rb +++ b/app/mailers/spree/order_mailer.rb @@ -1,4 +1,4 @@ -class OrderMailer < ActionMailer::Base +class Spree::OrderMailer < ActionMailer::Base helper "spree/base" def confirm_email(order, resend=false) diff --git a/app/mailers/shipment_mailer.rb b/app/mailers/spree/shipment_mailer.rb similarity index 89% rename from app/mailers/shipment_mailer.rb rename to app/mailers/spree/shipment_mailer.rb index a2be6a26..b749d4a1 100644 --- a/app/mailers/shipment_mailer.rb +++ b/app/mailers/spree/shipment_mailer.rb @@ -1,4 +1,4 @@ -class ShipmentMailer < ActionMailer::Base +class Spree::ShipmentMailer < ActionMailer::Base helper "spree/base" def shipped_email(shipment, resend=false) diff --git a/app/models/models_decorator.rb b/app/models/models_decorator.rb deleted file mode 100644 index f90b7347..00000000 --- a/app/models/models_decorator.rb +++ /dev/null @@ -1,22 +0,0 @@ -Product.class_eval do - has_and_belongs_to_many :stores - scope :by_store, lambda {|store| joins(:stores).where("products_stores.store_id = ?", store)} -end - -Order.class_eval do - belongs_to :store - scope :by_store, lambda { |store| where(:store_id => store.id) } -end - -Taxonomy.class_eval do - belongs_to :store -end - -Tracker.class_eval do - belongs_to :store - - def self.current(domain) - trackers = Tracker.find(:all, :conditions => {:active => true, :environment => ENV['RAILS_ENV']}) - trackers.select { |t| t.store_id == Store.current(domain).try(:id) }.first - end -end diff --git a/app/models/spree/order_decorator.rb b/app/models/spree/order_decorator.rb new file mode 100644 index 00000000..71f08906 --- /dev/null +++ b/app/models/spree/order_decorator.rb @@ -0,0 +1,4 @@ +Spree::Order.class_eval do + belongs_to :store + scope :by_store, lambda { |store| where(:store_id => store.id) } +end diff --git a/app/models/spree/product_decorator.rb b/app/models/spree/product_decorator.rb new file mode 100644 index 00000000..63013d2f --- /dev/null +++ b/app/models/spree/product_decorator.rb @@ -0,0 +1,4 @@ +Spree::Product.class_eval do + has_and_belongs_to_many :stores, :join_table => 'spree_products_stores' + scope :by_store, lambda {|store| joins(:stores).where("spree_products_stores.store_id = ?", store)} +end diff --git a/app/models/spree/store.rb b/app/models/spree/store.rb new file mode 100644 index 00000000..8efdc87c --- /dev/null +++ b/app/models/spree/store.rb @@ -0,0 +1,21 @@ +module Spree + class Store < ActiveRecord::Base + has_and_belongs_to_many :products + has_many :taxonomies + has_many :orders + + validates_presence_of :name, :code, :domains + + scope :default, where(:default => true) + scope :by_domain, lambda { |domain| where("domains like ?", "%#{domain}%") } + + def self.current(domain = nil) + current_store = domain ? Store.by_domain(domain).first : nil + current_store || first_found_default + end + + def self.first_found_default + @cached_default ||= Store.default.first + end + end +end diff --git a/app/models/spree/taxonomy_decorator.rb b/app/models/spree/taxonomy_decorator.rb new file mode 100644 index 00000000..2bd427e2 --- /dev/null +++ b/app/models/spree/taxonomy_decorator.rb @@ -0,0 +1,3 @@ +Spree::Taxonomy.class_eval do + belongs_to :store +end diff --git a/app/models/spree/tracker_decorator.rb b/app/models/spree/tracker_decorator.rb new file mode 100644 index 00000000..70482617 --- /dev/null +++ b/app/models/spree/tracker_decorator.rb @@ -0,0 +1,7 @@ +Spree::Tracker.class_eval do + belongs_to :store + + def self.current(domain) + Spree::Tracker.where(:active => true, :environment => ENV['RAILS_ENV']).joins(:store).where("spree_stores.domains LIKE '%#{domain}%'").first + end +end diff --git a/app/models/store.rb b/app/models/store.rb deleted file mode 100644 index c6bc37dc..00000000 --- a/app/models/store.rb +++ /dev/null @@ -1,15 +0,0 @@ -class Store < ActiveRecord::Base - has_and_belongs_to_many :products - has_many :taxonomies - has_many :orders - - validates_presence_of :name, :code, :domains - - scope :default, where(:default => true) - scope :by_domain, lambda { |domain| where("domains like ?", "%#{domain}%") } - - def self.current(domain = nil) - current_store = domain ? Store.by_domain(domain).first : nil - current_store || Store.default.first - end -end diff --git a/app/overrides/decorate_admin_configurations_index.rb b/app/overrides/decorate_admin_configurations_index.rb new file mode 100644 index 00000000..ff0e98f1 --- /dev/null +++ b/app/overrides/decorate_admin_configurations_index.rb @@ -0,0 +1,6 @@ +Deface::Override.new( + :virtual_path => "spree/admin/configurations/index", + :name => "multi_domain_admin_configurations_menu", + :insert_bottom => "[data-hook='admin_configurations_menu']", + :text => "<%= configurations_menu_item(I18n.t('stores_admin'), admin_stores_url, I18n.t('manage_stores')) %>", + :disabled => false) diff --git a/app/overrides/decorate_admin_products_form.rb b/app/overrides/decorate_admin_products_form.rb new file mode 100644 index 00000000..11d03f16 --- /dev/null +++ b/app/overrides/decorate_admin_products_form.rb @@ -0,0 +1,6 @@ +Deface::Override.new( + :virtual_path => "spree/admin/products/_form", + :name => "multi_domain_admin_product_form_meta", + :insert_bottom => "[data-hook='admin_product_form_meta']", + :partial => "spree/admin/products/stores", + :disabled => false) diff --git a/app/overrides/decorate_admin_products_index.rb b/app/overrides/decorate_admin_products_index.rb new file mode 100644 index 00000000..b8ba7a54 --- /dev/null +++ b/app/overrides/decorate_admin_products_index.rb @@ -0,0 +1,20 @@ +Deface::Override.new( + :virtual_path => "spree/admin/products/index", + :name => "multi_domain_admin_products_index_headers", + :insert_before => "[data-hook='admin_products_index_header_actions']", + :partial => "spree/admin/products/index_headers", + :disabled => false) + +Deface::Override.new( + :virtual_path => "spree/admin/products/index", + :name => "multi_domain_admin_products_index_rows", + :insert_before => "[data-hook='admin_products_index_row_actions']", + :partial => "spree/admin/products/index_rows", + :disabled => false) + +Deface::Override.new( + :virtual_path => "spree/admin/products/index", + :name => "multi_domain_admin_products_index_search", + :insert_top => "[data-hook='admin_products_index_search']", + :partial => "spree/admin/products/index_search_fields", + :disabled => false) diff --git a/app/overrides/decorate_admin_trackers_form.rb b/app/overrides/decorate_admin_trackers_form.rb new file mode 100644 index 00000000..3f7cc316 --- /dev/null +++ b/app/overrides/decorate_admin_trackers_form.rb @@ -0,0 +1,6 @@ +Deface::Override.new( + :virtual_path => "spree/admin/trackers/_form", + :name => "multi_domain_additional_tracker_fields", + :replace => "[data-hook='additional_tracker_fields']", + :partial => "spree/admin/trackers/store", + :disabled => false) diff --git a/app/overrides/decorate_admin_trackers_index.rb b/app/overrides/decorate_admin_trackers_index.rb new file mode 100644 index 00000000..b1459779 --- /dev/null +++ b/app/overrides/decorate_admin_trackers_index.rb @@ -0,0 +1,13 @@ +Deface::Override.new( + :virtual_path => "spree/admin/trackers/index", + :name => "multi_domain_admin_trackers_index_headers", + :insert_before => "[data-hook='admin_trackers_index_headers'] th:last", + :text => "
-
- <%= f.select :stores_id_equals, Store.all.collect {|s| [s.name, s.id ] }, {:include_blank => true} %>
+
+ <%= f.select :stores_id_equals, Spree::Store.all.collect {|s| [s.name, s.id ] }, {:include_blank => true} %>