From b31124c3f48eb5213ef82593715396c67c3fcc3c Mon Sep 17 00:00:00 2001 From: Ryan Bigg Date: Thu, 1 Nov 2012 16:01:23 +1100 Subject: [PATCH] Reshuffle frontend and core This is a combination of 27 commits. * Move search base fron frontend to core * Move Spree::Money from frontend to core * move mailers to core * Move mailer views to core * Require core not models in frontend gemspec * Fix require in product_filter_spec * frontend stuff now lives at lib/spree/frontend * Core engine is now once again for isolating the engine namespace * Move user class extensions to core * Move UserBanners to Core * Frontend now prepends routes to core * Rename Core references in Frontend to Frontend * Fix spree_frontend gemspec * Fix spree_core.gemspec * Remove unnecessary scopes file * Rename spree/core.rb inside frontend to spree/frontend.rb * Fix ControllerHelpers reference in Spree::BaseController * Fix require to action_callbacks withn Admin::ResourceController * Fix module reference for ControllerHelpers inside Spree::StoreController * Fix testing_support requires within spec_helper * Fix requires in frontend.rb * Moved ControllerHelpers back into Core. * This is because API no longer depends on frontend * Move SSL requirement into core from frontend * Add require for cancan inside core.rb * Add frontend to travis * Add spree_core.rb * Add frontend to Rakefile --- Rakefile | 18 ++++- api/Gemfile | 1 - .../app/mailers/spree/order_mailer.rb | 0 .../app/mailers/spree/shipment_mailer.rb | 0 .../app/mailers/spree/test_mailer.rb | 0 core/app/models/spree/taxon.rb | 4 +- .../spree/order_mailer/cancel_email.text.erb | 0 .../spree/order_mailer/confirm_email.text.erb | 0 .../shipment_mailer/shipped_email.text.erb | 0 .../spree/test_mailer/test_email.text.erb | 0 .../initializers/user_class_extensions.rb | 0 core/config/routes.rb | 4 ++ .../app/assets/javascripts/admin/all.js | 2 +- .../app/assets/javascripts/store/all.js | 2 +- .../app/assets/stylesheets/admin/all.css | 2 +- .../app/assets/stylesheets/store/all.css | 2 +- core/lib/spree/core.rb | 3 + .../lib/spree/core/controller_helpers/auth.rb | 2 + .../spree/core/controller_helpers/common.rb | 0 .../spree/core/controller_helpers/order.rb | 0 .../lib/spree/core/custom_fixtures.rb | 0 core/lib/spree/core/engine.rb | 7 +- .../lib/spree/core/search/base.rb | 0 .../lib/spree/core/ssl_requirement.rb | 0 .../lib/spree/core/user_banners.rb | 0 {frontend => core}/lib/spree/money.rb | 0 {frontend => core}/lib/spree_core.rb | 0 .../spec/mailers/order_mailer_spec.rb | 0 .../spec/mailers/shipment_mailer_spec.rb | 0 core/spec/models/spree/product_filter_spec.rb | 2 +- core/spec/models/spree/product_spec.rb | 26 ++++++- core/spec/spec_helper.rb | 69 ------------------ core/spree_core.gemspec | 7 +- frontend/Gemfile | 2 +- .../{spree_core.js => spree_frontend.js} | 0 .../assets/stylesheets/store/spree_core.css | 4 +- .../spree/admin/resource_controller.rb | 2 +- frontend/config/routes.rb | 2 +- frontend/lib/spree/core/scopes.rb | 65 ----------------- frontend/lib/spree/{core.rb => frontend.rb} | 14 ++-- .../{core => frontend}/action_callbacks.rb | 0 .../lib/spree/frontend/custom_fixtures.rb | 70 +++++++++++++++++++ .../lib/spree/{core => frontend}/engine.rb | 6 +- .../middleware/redirect_legacy_product_url.rb | 0 .../middleware/seo_assist.rb | 2 +- .../{core => frontend}/preference_rescue.rb | 0 .../lib/spree/{core => frontend}/responder.rb | 0 .../spree/{core => frontend}/store_helpers.rb | 0 frontend/lib/spree_frontend.rb | 1 + frontend/spec/lib/search/base_spec.rb | 2 +- frontend/spec/spec_helper.rb | 12 ++-- ...ee_core.gemspec => spree_frontend.gemspec} | 9 ++- .../assets/javascripts/admin/spree_promo.js | 1 + .../assets/javascripts/store/spree_promo.js | 2 +- .../assets/stylesheets/admin/spree_promo.css | 2 +- .../assets/stylesheets/store/spree_promo.css | 2 +- 56 files changed, 160 insertions(+), 189 deletions(-) rename {frontend => core}/app/mailers/spree/order_mailer.rb (100%) rename {frontend => core}/app/mailers/spree/shipment_mailer.rb (100%) rename {frontend => core}/app/mailers/spree/test_mailer.rb (100%) rename {frontend => core}/app/views/spree/order_mailer/cancel_email.text.erb (100%) rename {frontend => core}/app/views/spree/order_mailer/confirm_email.text.erb (100%) rename {frontend => core}/app/views/spree/shipment_mailer/shipped_email.text.erb (100%) rename {frontend => core}/app/views/spree/test_mailer/test_email.text.erb (100%) rename {frontend => core}/config/initializers/user_class_extensions.rb (100%) create mode 100644 core/config/routes.rb rename {frontend => core}/lib/spree/core/controller_helpers/auth.rb (98%) rename {frontend => core}/lib/spree/core/controller_helpers/common.rb (100%) rename {frontend => core}/lib/spree/core/controller_helpers/order.rb (100%) rename {frontend => core}/lib/spree/core/custom_fixtures.rb (100%) rename {frontend => core}/lib/spree/core/search/base.rb (100%) rename {frontend => core}/lib/spree/core/ssl_requirement.rb (100%) rename {frontend => core}/lib/spree/core/user_banners.rb (100%) rename {frontend => core}/lib/spree/money.rb (100%) rename {frontend => core}/lib/spree_core.rb (100%) rename {frontend => core}/spec/mailers/order_mailer_spec.rb (100%) rename {frontend => core}/spec/mailers/shipment_mailer_spec.rb (100%) rename frontend/app/assets/javascripts/store/{spree_core.js => spree_frontend.js} (100%) delete mode 100644 frontend/lib/spree/core/scopes.rb rename frontend/lib/spree/{core.rb => frontend.rb} (87%) rename frontend/lib/spree/{core => frontend}/action_callbacks.rb (100%) create mode 100644 frontend/lib/spree/frontend/custom_fixtures.rb rename frontend/lib/spree/{core => frontend}/engine.rb (93%) rename frontend/lib/spree/{core => frontend}/middleware/redirect_legacy_product_url.rb (100%) rename frontend/lib/spree/{core => frontend}/middleware/seo_assist.rb (98%) rename frontend/lib/spree/{core => frontend}/preference_rescue.rb (100%) rename frontend/lib/spree/{core => frontend}/responder.rb (100%) rename frontend/lib/spree/{core => frontend}/store_helpers.rb (100%) create mode 100644 frontend/lib/spree_frontend.rb rename frontend/{spree_core.gemspec => spree_frontend.gemspec} (81%) diff --git a/Rakefile b/Rakefile index 799de40bdeb..50a45152b38 100644 --- a/Rakefile +++ b/Rakefile @@ -15,8 +15,8 @@ end desc "Generates a dummy app for testing for every Spree engine" task :test_app do - require File.expand_path('../models/lib/generators/spree/install/install_generator', __FILE__) - %w(api core dash promo models).each do |engine| + require File.expand_path('../core/lib/generators/spree/install/install_generator', __FILE__) + %w(api core dash frontend promo).each do |engine| ENV['LIB_NAME'] = File.join('spree', engine) ENV['DUMMY_PATH'] = File.expand_path("../#{engine}/spec/dummy", __FILE__) Rake::Task['common:test_app'].execute @@ -30,7 +30,7 @@ task :clean do puts "Deleting pkg directory.." FileUtils.rm_rf("pkg") - %w(api cmd core dash promo models).each do |gem_name| + %w(api cmd core dash frontend promo).each do |gem_name| puts "Cleaning #{gem_name}:" puts " Deleting #{gem_name}/Gemfile" FileUtils.rm_f("#{gem_name}/Gemfile") @@ -46,7 +46,11 @@ end namespace :gem do desc "run rake gem for all gems" task :build do +<<<<<<< HEAD %w(core api dash promo sample cmd models testing_support).each do |gem_name| +======= + %w(core api dash frontend promo sample cmd).each do |gem_name| +>>>>>>> ee4b70b... Add frontend to Rakefile puts "########################### #{gem_name} #########################" puts "Deleting #{gem_name}/pkg" FileUtils.rm_rf("#{gem_name}/pkg") @@ -63,7 +67,11 @@ namespace :gem do task :install do version = File.read(File.expand_path("../SPREE_VERSION", __FILE__)).strip +<<<<<<< HEAD %w(core api dash promo sample cmd models testing_support).each do |gem_name| +======= + %w(core api dash frontend promo sample cmd).each do |gem_name| +>>>>>>> ee4b70b... Add frontend to Rakefile puts "########################### #{gem_name} #########################" puts "Deleting #{gem_name}/pkg" FileUtils.rm_rf("#{gem_name}/pkg") @@ -82,7 +90,11 @@ namespace :gem do task :release do version = File.read(File.expand_path("../SPREE_VERSION", __FILE__)).strip +<<<<<<< HEAD %w(core api dash promo sample cmd models testing_support).each do |gem_name| +======= + %w(core api dash frontend promo sample cmd).each do |gem_name| +>>>>>>> ee4b70b... Add frontend to Rakefile puts "########################### #{gem_name} #########################" cmd = "cd #{gem_name}/pkg && gem push spree_#{gem_name}-#{version}.gem"; puts cmd; system cmd end diff --git a/api/Gemfile b/api/Gemfile index fd44dcb5089..f0986c44cad 100644 --- a/api/Gemfile +++ b/api/Gemfile @@ -1,6 +1,5 @@ eval(File.read(File.dirname(__FILE__) + '/../common_spree_dependencies.rb')) -gem 'spree_models', :path => "../models" gem 'spree_core', :path => "../core" gemspec diff --git a/frontend/app/mailers/spree/order_mailer.rb b/core/app/mailers/spree/order_mailer.rb similarity index 100% rename from frontend/app/mailers/spree/order_mailer.rb rename to core/app/mailers/spree/order_mailer.rb diff --git a/frontend/app/mailers/spree/shipment_mailer.rb b/core/app/mailers/spree/shipment_mailer.rb similarity index 100% rename from frontend/app/mailers/spree/shipment_mailer.rb rename to core/app/mailers/spree/shipment_mailer.rb diff --git a/frontend/app/mailers/spree/test_mailer.rb b/core/app/mailers/spree/test_mailer.rb similarity index 100% rename from frontend/app/mailers/spree/test_mailer.rb rename to core/app/mailers/spree/test_mailer.rb diff --git a/core/app/models/spree/taxon.rb b/core/app/models/spree/taxon.rb index 546db615b61..8c67a23cfe2 100644 --- a/core/app/models/spree/taxon.rb +++ b/core/app/models/spree/taxon.rb @@ -30,8 +30,8 @@ def applicable_filters # fs << ProductFilters.taxons_below(self) ## unless it's a root taxon? left open for demo purposes - fs << ProductFilters.price_filter if ProductFilters.respond_to?(:price_filter) - fs << ProductFilters.brand_filter if ProductFilters.respond_to?(:brand_filter) + fs << Spree::Core::ProductFilters.price_filter if Spree::Core::ProductFilters.respond_to?(:price_filter) + fs << Spree::Core::ProductFilters.brand_filter if Spree::Core::ProductFilters.respond_to?(:brand_filter) fs end diff --git a/frontend/app/views/spree/order_mailer/cancel_email.text.erb b/core/app/views/spree/order_mailer/cancel_email.text.erb similarity index 100% rename from frontend/app/views/spree/order_mailer/cancel_email.text.erb rename to core/app/views/spree/order_mailer/cancel_email.text.erb diff --git a/frontend/app/views/spree/order_mailer/confirm_email.text.erb b/core/app/views/spree/order_mailer/confirm_email.text.erb similarity index 100% rename from frontend/app/views/spree/order_mailer/confirm_email.text.erb rename to core/app/views/spree/order_mailer/confirm_email.text.erb diff --git a/frontend/app/views/spree/shipment_mailer/shipped_email.text.erb b/core/app/views/spree/shipment_mailer/shipped_email.text.erb similarity index 100% rename from frontend/app/views/spree/shipment_mailer/shipped_email.text.erb rename to core/app/views/spree/shipment_mailer/shipped_email.text.erb diff --git a/frontend/app/views/spree/test_mailer/test_email.text.erb b/core/app/views/spree/test_mailer/test_email.text.erb similarity index 100% rename from frontend/app/views/spree/test_mailer/test_email.text.erb rename to core/app/views/spree/test_mailer/test_email.text.erb diff --git a/frontend/config/initializers/user_class_extensions.rb b/core/config/initializers/user_class_extensions.rb similarity index 100% rename from frontend/config/initializers/user_class_extensions.rb rename to core/config/initializers/user_class_extensions.rb diff --git a/core/config/routes.rb b/core/config/routes.rb new file mode 100644 index 00000000000..ce5b290e500 --- /dev/null +++ b/core/config/routes.rb @@ -0,0 +1,4 @@ +Spree::Core::Engine.routes.draw do + # These routes now come from the Spree::Frontend component. + # Look in frontend/config/routes.rb for the routes. +end diff --git a/core/lib/generators/spree/install/templates/app/assets/javascripts/admin/all.js b/core/lib/generators/spree/install/templates/app/assets/javascripts/admin/all.js index 590b2a0fba0..1aea0062614 100644 --- a/core/lib/generators/spree/install/templates/app/assets/javascripts/admin/all.js +++ b/core/lib/generators/spree/install/templates/app/assets/javascripts/admin/all.js @@ -7,7 +7,7 @@ //= require jquery //= require jquery_ujs <% if options[:lib_name] == 'spree' %> -//= require admin/spree_core +//= require admin/spree_frontend //= require admin/spree_promo <% else %> //= require admin/<%= options[:lib_name].gsub("/", "_") %> diff --git a/core/lib/generators/spree/install/templates/app/assets/javascripts/store/all.js b/core/lib/generators/spree/install/templates/app/assets/javascripts/store/all.js index 3512a2a08f0..a8fcfc5c85d 100644 --- a/core/lib/generators/spree/install/templates/app/assets/javascripts/store/all.js +++ b/core/lib/generators/spree/install/templates/app/assets/javascripts/store/all.js @@ -7,7 +7,7 @@ //= require jquery //= require jquery_ujs <% if options[:lib_name] == 'spree' %> -//= require store/spree_core +//= require store/spree_frontend //= require store/spree_promo <% else %> //= require store/<%= options[:lib_name].gsub("/", "_") %> diff --git a/core/lib/generators/spree/install/templates/app/assets/stylesheets/admin/all.css b/core/lib/generators/spree/install/templates/app/assets/stylesheets/admin/all.css index 86e4e5d5e10..4969d89bb8d 100644 --- a/core/lib/generators/spree/install/templates/app/assets/stylesheets/admin/all.css +++ b/core/lib/generators/spree/install/templates/app/assets/stylesheets/admin/all.css @@ -4,7 +4,7 @@ * the top of the compiled file, but it's generally better to create a new file per style scope. * <% if options[:lib_name] == 'spree' %> - *= require admin/spree_core + *= require admin/spree_frontend *= require admin/spree_promo <% else %> *= require admin/<%= options[:lib_name].gsub("/", "_") %> diff --git a/core/lib/generators/spree/install/templates/app/assets/stylesheets/store/all.css b/core/lib/generators/spree/install/templates/app/assets/stylesheets/store/all.css index a361ef2e865..9ca6df8d93b 100644 --- a/core/lib/generators/spree/install/templates/app/assets/stylesheets/store/all.css +++ b/core/lib/generators/spree/install/templates/app/assets/stylesheets/store/all.css @@ -4,7 +4,7 @@ * the top of the compiled file, but it's generally better to create a new file per style scope. * <% if options[:lib_name] == 'spree' %> - *= require store/spree_core + *= require store/spree_frontend *= require store/spree_promo <% else %> *= require store/<%= options[:lib_name].gsub("/", "_") %> diff --git a/core/lib/spree/core.rb b/core/lib/spree/core.rb index a9e294c47e9..4f079caaf4e 100644 --- a/core/lib/spree/core.rb +++ b/core/lib/spree/core.rb @@ -1,4 +1,5 @@ require 'rails/all' +require 'cancan' require 'state_machine' require 'paperclip' require 'kaminari' @@ -37,6 +38,8 @@ def self.config(&block) require 'spree/core/version' require 'spree/core/engine' +require 'spree/money' + require 'spree/core/delegate_belongs_to' require 'spree/core/ext/active_record' require 'spree/core/permalinks' diff --git a/frontend/lib/spree/core/controller_helpers/auth.rb b/core/lib/spree/core/controller_helpers/auth.rb similarity index 98% rename from frontend/lib/spree/core/controller_helpers/auth.rb rename to core/lib/spree/core/controller_helpers/auth.rb index 7ff9a054d35..53fd373f334 100644 --- a/frontend/lib/spree/core/controller_helpers/auth.rb +++ b/core/lib/spree/core/controller_helpers/auth.rb @@ -1,3 +1,5 @@ +require 'spree/core/ssl_requirement' + module Spree module Core module ControllerHelpers diff --git a/frontend/lib/spree/core/controller_helpers/common.rb b/core/lib/spree/core/controller_helpers/common.rb similarity index 100% rename from frontend/lib/spree/core/controller_helpers/common.rb rename to core/lib/spree/core/controller_helpers/common.rb diff --git a/frontend/lib/spree/core/controller_helpers/order.rb b/core/lib/spree/core/controller_helpers/order.rb similarity index 100% rename from frontend/lib/spree/core/controller_helpers/order.rb rename to core/lib/spree/core/controller_helpers/order.rb diff --git a/frontend/lib/spree/core/custom_fixtures.rb b/core/lib/spree/core/custom_fixtures.rb similarity index 100% rename from frontend/lib/spree/core/custom_fixtures.rb rename to core/lib/spree/core/custom_fixtures.rb diff --git a/core/lib/spree/core/engine.rb b/core/lib/spree/core/engine.rb index 877379d8f0d..a223c6a54ce 100644 --- a/core/lib/spree/core/engine.rb +++ b/core/lib/spree/core/engine.rb @@ -1,13 +1,10 @@ require 'rabl' module Spree - def self.table_name_prefix - "spree_" - end - module Core class Engine < ::Rails::Engine - engine_name 'spree_core' + isolate_namespace Spree + engine_name 'spree' config.autoload_paths += %W(#{config.root}/lib) diff --git a/frontend/lib/spree/core/search/base.rb b/core/lib/spree/core/search/base.rb similarity index 100% rename from frontend/lib/spree/core/search/base.rb rename to core/lib/spree/core/search/base.rb diff --git a/frontend/lib/spree/core/ssl_requirement.rb b/core/lib/spree/core/ssl_requirement.rb similarity index 100% rename from frontend/lib/spree/core/ssl_requirement.rb rename to core/lib/spree/core/ssl_requirement.rb diff --git a/frontend/lib/spree/core/user_banners.rb b/core/lib/spree/core/user_banners.rb similarity index 100% rename from frontend/lib/spree/core/user_banners.rb rename to core/lib/spree/core/user_banners.rb diff --git a/frontend/lib/spree/money.rb b/core/lib/spree/money.rb similarity index 100% rename from frontend/lib/spree/money.rb rename to core/lib/spree/money.rb diff --git a/frontend/lib/spree_core.rb b/core/lib/spree_core.rb similarity index 100% rename from frontend/lib/spree_core.rb rename to core/lib/spree_core.rb diff --git a/frontend/spec/mailers/order_mailer_spec.rb b/core/spec/mailers/order_mailer_spec.rb similarity index 100% rename from frontend/spec/mailers/order_mailer_spec.rb rename to core/spec/mailers/order_mailer_spec.rb diff --git a/frontend/spec/mailers/shipment_mailer_spec.rb b/core/spec/mailers/shipment_mailer_spec.rb similarity index 100% rename from frontend/spec/mailers/shipment_mailer_spec.rb rename to core/spec/mailers/shipment_mailer_spec.rb diff --git a/core/spec/models/spree/product_filter_spec.rb b/core/spec/models/spree/product_filter_spec.rb index 39f6b536d0e..0f1de509f66 100644 --- a/core/spec/models/spree/product_filter_spec.rb +++ b/core/spec/models/spree/product_filter_spec.rb @@ -1,5 +1,5 @@ require 'spec_helper' -require 'spree/models/product_filters' +require 'spree/core/product_filters' describe 'product filters' do # Regression test for #1709 diff --git a/core/spec/models/spree/product_spec.rb b/core/spec/models/spree/product_spec.rb index 0bf7d4aa1d9..fe22adfbd49 100644 --- a/core/spec/models/spree/product_spec.rb +++ b/core/spec/models/spree/product_spec.rb @@ -326,8 +326,32 @@ end context "when prototype with option types is supplied" do + def build_option_type_with_values(name, values) + ot = FactoryGirl.create(:option_type, :name => name) + values.each do |val| + ot.option_values.create({:name => val.downcase, :presentation => val}, :without_protection => true) + end + ot + end + + let(:product_attributes) do + # FactoryGirl.attributes_for is un-deprecated! + # https://github.com/thoughtbot/factory_girl/issues/274#issuecomment-3592054 + FactoryGirl.attributes_for(:simple_product) + end - include_context "product prototype" + let(:prototype) do + size = build_option_type_with_values("size", %w(Small Medium Large)) + FactoryGirl.create(:prototype, :name => "Size", :option_types => [ size ]) + end + + let(:option_values_hash) do + hash = {} + prototype.option_types.each do |i| + hash[i.id.to_s] = i.option_value_ids + end + hash + end before { @product.prototype_id = prototype.id } diff --git a/core/spec/spec_helper.rb b/core/spec/spec_helper.rb index 5a5e4a2b340..5e3ba8ca90d 100644 --- a/core/spec/spec_helper.rb +++ b/core/spec/spec_helper.rb @@ -56,72 +56,3 @@ config.include Paperclip::Shoulda::Matchers end - -shared_context "custom products" do - before(:each) do - configure_spree_preferences do |config| - config.allow_backorders = true - end - - taxonomy = FactoryGirl.create(:taxonomy, :name => 'Categories') - root = taxonomy.root - clothing_taxon = FactoryGirl.create(:taxon, :name => 'Clothing', :parent_id => root.id) - bags_taxon = FactoryGirl.create(:taxon, :name => 'Bags', :parent_id => root.id) - mugs_taxon = FactoryGirl.create(:taxon, :name => 'Mugs', :parent_id => root.id) - - taxonomy = FactoryGirl.create(:taxonomy, :name => 'Brands') - root = taxonomy.root - apache_taxon = FactoryGirl.create(:taxon, :name => 'Apache', :parent_id => root.id) - rails_taxon = FactoryGirl.create(:taxon, :name => 'Ruby on Rails', :parent_id => root.id) - ruby_taxon = FactoryGirl.create(:taxon, :name => 'Ruby', :parent_id => root.id) - - FactoryGirl.create(:custom_product, :name => 'Ruby on Rails Ringer T-Shirt', :price => '19.99', :taxons => [rails_taxon, clothing_taxon]) - FactoryGirl.create(:custom_product, :name => 'Ruby on Rails Mug', :price => '15.99', :taxons => [rails_taxon, mugs_taxon]) - FactoryGirl.create(:custom_product, :name => 'Ruby on Rails Tote', :price => '15.99', :taxons => [rails_taxon, bags_taxon]) - FactoryGirl.create(:custom_product, :name => 'Ruby on Rails Bag', :price => '22.99', :taxons => [rails_taxon, bags_taxon]) - FactoryGirl.create(:custom_product, :name => 'Ruby on Rails Baseball Jersey', :price => '19.99', :taxons => [rails_taxon, clothing_taxon]) - FactoryGirl.create(:custom_product, :name => 'Ruby on Rails Stein', :price => '16.99', :taxons => [rails_taxon, mugs_taxon]) - FactoryGirl.create(:custom_product, :name => 'Ruby on Rails Jr. Spaghetti', :price => '19.99', :taxons => [rails_taxon, clothing_taxon]) - FactoryGirl.create(:custom_product, :name => 'Ruby Baseball Jersey', :price => '19.99', :taxons => [ruby_taxon, clothing_taxon]) - FactoryGirl.create(:custom_product, :name => 'Apache Baseball Jersey', :price => '19.99', :taxons => [apache_taxon, clothing_taxon]) - end -end - - - -shared_context "product prototype" do - - def build_option_type_with_values(name, values) - ot = FactoryGirl.create(:option_type, :name => name) - values.each do |val| - ot.option_values.create({:name => val.downcase, :presentation => val}, :without_protection => true) - end - ot - end - - let(:product_attributes) do - # FactoryGirl.attributes_for is un-deprecated! - # https://github.com/thoughtbot/factory_girl/issues/274#issuecomment-3592054 - FactoryGirl.attributes_for(:base_product) - end - - let(:prototype) do - size = build_option_type_with_values("size", %w(Small Medium Large)) - FactoryGirl.create(:prototype, :name => "Size", :option_types => [ size ]) - end - - let(:option_values_hash) do - hash = {} - prototype.option_types.each do |i| - hash[i.id.to_s] = i.option_value_ids - end - hash - end - -end - - - -PAYMENT_STATES = Spree::Payment.state_machine.states.keys unless defined? PAYMENT_STATES -SHIPMENT_STATES = Spree::Shipment.state_machine.states.keys unless defined? SHIPMENT_STATES -ORDER_STATES = Spree::Order.state_machine.states.keys unless defined? ORDER_STATES diff --git a/core/spree_core.gemspec b/core/spree_core.gemspec index ce7aea11694..f2a24d56571 100644 --- a/core/spree_core.gemspec +++ b/core/spree_core.gemspec @@ -3,17 +3,16 @@ version = File.read(File.expand_path("../../SPREE_VERSION", __FILE__)).strip Gem::Specification.new do |s| s.platform = Gem::Platform::RUBY - s.name = 'spree_models' + s.name = 'spree_core' s.version = version - s.summary = 'ActiveRecord models for Spree.' - s.description = 'Required dependency for Spree' + s.summary = 'The barebones necessary for Spree.' + s.description = 'The barebones necessary for Spree.' s.required_ruby_version = '>= 1.8.7' s.author = 'Sean Schofield' s.email = 'sean@spreecommerce.com' s.homepage = 'http://spreecommerce.com' s.license = %q{BSD-3} - s.rubyforge_project = 'spree_core' s.files = Dir['LICENSE', 'README.md', 'app/**/*', 'config/**/*', 'lib/**/*', 'db/**/*', 'vendor/**/*'] s.require_path = 'lib' diff --git a/frontend/Gemfile b/frontend/Gemfile index 708eca0b511..49bfb5b7790 100644 --- a/frontend/Gemfile +++ b/frontend/Gemfile @@ -1,6 +1,6 @@ eval(File.read(File.dirname(__FILE__) + '/../common_spree_dependencies.rb')) -gem 'spree_models', :path => '../models' +gem 'spree_core', :path => '../core' gem 'spree_api', :path => '../api' gemspec diff --git a/frontend/app/assets/javascripts/store/spree_core.js b/frontend/app/assets/javascripts/store/spree_frontend.js similarity index 100% rename from frontend/app/assets/javascripts/store/spree_core.js rename to frontend/app/assets/javascripts/store/spree_frontend.js diff --git a/frontend/app/assets/stylesheets/store/spree_core.css b/frontend/app/assets/stylesheets/store/spree_core.css index dd2700da15c..26787798540 100644 --- a/frontend/app/assets/stylesheets/store/spree_core.css +++ b/frontend/app/assets/stylesheets/store/spree_core.css @@ -1,6 +1,6 @@ /* -* This is a manifest file that includes stylesheets for spree_core +* This is a manifest file that includes stylesheets for spree_frontend *= require normalize *= require skeleton *= require store/screen -*/ \ No newline at end of file +*/ diff --git a/frontend/app/controllers/spree/admin/resource_controller.rb b/frontend/app/controllers/spree/admin/resource_controller.rb index cf796d6b54d..94cb56aa3ba 100644 --- a/frontend/app/controllers/spree/admin/resource_controller.rb +++ b/frontend/app/controllers/spree/admin/resource_controller.rb @@ -1,4 +1,4 @@ -require 'spree/core/action_callbacks' +require 'spree/frontend/action_callbacks' class Spree::Admin::ResourceController < Spree::Admin::BaseController helper_method :new_object_url, :edit_object_url, :object_url, :collection_url diff --git a/frontend/config/routes.rb b/frontend/config/routes.rb index 8461157e0d3..d53d14a346c 100755 --- a/frontend/config/routes.rb +++ b/frontend/config/routes.rb @@ -1,4 +1,4 @@ -Spree::Core::Engine.routes.draw do +Spree::Core::Engine.routes.prepend do root :to => 'home#index' diff --git a/frontend/lib/spree/core/scopes.rb b/frontend/lib/spree/core/scopes.rb deleted file mode 100644 index 32e9799edb2..00000000000 --- a/frontend/lib/spree/core/scopes.rb +++ /dev/null @@ -1,65 +0,0 @@ -module Spree - module Core - # This module contains all custom scopes created for selecting products. - # - # All usable scopes *should* be included in SCOPES constant, it represents - # all scopes that are selectable from user interface, extensions can extend - # and modify it, but should provide corresponding translations. - # - # Format of constant is following: - # - # { - # :namespace/grouping => { - # :name_of_the_scope => [:list, :of, :arguments] - # } - # } - # - # This values are used in translation file, to describe them in the interface. - # So for each scope you define here you have to provide following entry in translation file - # product_scopes: - # name_of_the_group: - # name: Translated name of the group - # description: Longer description of what this scope group does, inluding - # any possible help user may need - # scopes: - # name_of_the_scope: - # name: Short name of the scope - # description: What does this scope does exactly - # arguments: - # arg1: Description of argument - # arg2: Description of second Argument - # - module Scopes - module_function - - def generate_translation(all_scopes) - result = {"groups" => {}, "scopes" => {}} - all_scopes.dup.each_pair do |group_name, scopes| - result["groups"][group_name.to_s] = { - 'name' => group_name.to_s.humanize, - 'description' => "Scopes for selecting products based on #{group_name.to_s}", - } - - scopes.each_pair do |scope_name, targs| - hashed_args = {} - targs.each{|v| hashed_args[v.to_s] = v.to_s.humanize} - - result['scopes'][scope_name.to_s] = { - 'name' => scope_name.to_s.humanize, - 'description' => "", - 'args' => hashed_args.dup - } - end - end - result - end - - def generate_translations - require 'ya2yaml' - { - 'product_scopes' => generate_translation(Spree::ProductScope.all_scopes) - }.ya2yaml - end - end - end -end diff --git a/frontend/lib/spree/core.rb b/frontend/lib/spree/frontend.rb similarity index 87% rename from frontend/lib/spree/core.rb rename to frontend/lib/spree/frontend.rb index b9885029b51..3340e9785a3 100644 --- a/frontend/lib/spree/core.rb +++ b/frontend/lib/spree/frontend.rb @@ -30,12 +30,10 @@ require 'rails/generators' require 'jquery-rails' require 'deface' -require 'cancan' require 'select2-rails' -require 'spree/money' require 'rabl' -require 'spree/models' +require 'spree/core' require 'spree/core/delegate_belongs_to' @@ -44,14 +42,12 @@ require 'spree/core/store_helpers' require 'spree/core/mail_settings' require 'spree/core/mail_interceptor' -require 'spree/core/middleware/redirect_legacy_product_url' -require 'spree/core/middleware/seo_assist' -require 'spree/core/s3_support' -require 'spree/core/version' +require 'spree/frontend/responder' +require 'spree/frontend/store_helpers' +require 'spree/frontend/middleware/seo_assist' -require 'spree/core/engine' -require 'generators/spree/dummy/dummy_generator' +require 'spree/frontend/engine' if defined?(ActionView) require 'awesome_nested_set/helper' diff --git a/frontend/lib/spree/core/action_callbacks.rb b/frontend/lib/spree/frontend/action_callbacks.rb similarity index 100% rename from frontend/lib/spree/core/action_callbacks.rb rename to frontend/lib/spree/frontend/action_callbacks.rb diff --git a/frontend/lib/spree/frontend/custom_fixtures.rb b/frontend/lib/spree/frontend/custom_fixtures.rb new file mode 100644 index 00000000000..effb17c013a --- /dev/null +++ b/frontend/lib/spree/frontend/custom_fixtures.rb @@ -0,0 +1,70 @@ +require 'active_record/fixtures' + +module Spree + module Frontend + class Fixtures < ActiveRecord::Fixtures + # Replace this method to prevent the table being emptied on each call. Needed + # when both core & auth have user fixtures, see below for code commented out. + # + def self.create_fixtures(fixtures_directory, table_names, class_names = {}) + table_names = [table_names].flatten.map { |n| n.to_s } + table_names.each { |n| + class_names[n.tr('/', '_').to_sym] = n.classify if n.include?('/') + } + + # FIXME: Apparently JK uses this. + connection = block_given? ? yield : ActiveRecord::Base.connection + + files_to_read = table_names.reject { |table_name| + fixture_is_cached?(connection, table_name) + } + + unless files_to_read.empty? + connection.disable_referential_integrity do + fixtures_map = {} + + fixture_files = files_to_read.map do |path| + table_name = path.tr '/', '_' + + fixtures_map[path] = ActiveRecord::Fixtures.new( + connection, + table_name, + class_names[table_name.to_sym] || table_name.classify, + ::File.join(fixtures_directory, path)) + end + + all_loaded_fixtures.update(fixtures_map) + + connection.transaction(:requires_new => true) do + fixture_files.each do |ff| + conn = ff.model_class.respond_to?(:connection) ? ff.model_class.connection : connection + table_rows = ff.table_rows + + # REMOVED BY SPREE + # table_rows.keys.each do |table| + # conn.delete "DELETE FROM #{conn.quote_table_name(table)}", 'Fixture Delete' + # end + + table_rows.each do |table_name,rows| + rows.each do |row| + conn.insert_fixture(row, table_name) + end + end + end + + # Cap primary key sequences to max(pk). + if connection.respond_to?(:reset_pk_sequence!) + table_names.each do |table_name| + connection.reset_pk_sequence!(table_name.tr('/', '_')) + end + end + end + + cache_fixtures(connection, fixtures_map) + end + end + cached_fixtures(connection, table_names) + end + end + end +end diff --git a/frontend/lib/spree/core/engine.rb b/frontend/lib/spree/frontend/engine.rb similarity index 93% rename from frontend/lib/spree/core/engine.rb rename to frontend/lib/spree/frontend/engine.rb index d62e0f434d3..68bbe7a8bbd 100644 --- a/frontend/lib/spree/core/engine.rb +++ b/frontend/lib/spree/frontend/engine.rb @@ -1,5 +1,5 @@ module Spree - module Core + module Frontend class Engine < ::Rails::Engine isolate_namespace Spree engine_name 'spree' @@ -10,8 +10,8 @@ class Engine < ::Rails::Engine config.autoload_paths += %W(#{config.root}/lib) # We need to reload the routes here due to how Spree sets them up. - # The different facets of Spree (auth, promo, etc.) append/prepend routes to Core - # *after* Core has been loaded. + # The different facets of Spree (auth, promo, etc.) append/prepend routes to Frontend + # *after* Frontend has been loaded. # # So we wait until after initialization is complete to do one final reload. # This then makes the appended/prepended routes available to the application. diff --git a/frontend/lib/spree/core/middleware/redirect_legacy_product_url.rb b/frontend/lib/spree/frontend/middleware/redirect_legacy_product_url.rb similarity index 100% rename from frontend/lib/spree/core/middleware/redirect_legacy_product_url.rb rename to frontend/lib/spree/frontend/middleware/redirect_legacy_product_url.rb diff --git a/frontend/lib/spree/core/middleware/seo_assist.rb b/frontend/lib/spree/frontend/middleware/seo_assist.rb similarity index 98% rename from frontend/lib/spree/core/middleware/seo_assist.rb rename to frontend/lib/spree/frontend/middleware/seo_assist.rb index 712172bbab6..6795e87db11 100644 --- a/frontend/lib/spree/core/middleware/seo_assist.rb +++ b/frontend/lib/spree/frontend/middleware/seo_assist.rb @@ -1,6 +1,6 @@ # Make redirects for SEO needs module Spree - module Core + module Frontend module Middleware class SeoAssist def initialize(app) diff --git a/frontend/lib/spree/core/preference_rescue.rb b/frontend/lib/spree/frontend/preference_rescue.rb similarity index 100% rename from frontend/lib/spree/core/preference_rescue.rb rename to frontend/lib/spree/frontend/preference_rescue.rb diff --git a/frontend/lib/spree/core/responder.rb b/frontend/lib/spree/frontend/responder.rb similarity index 100% rename from frontend/lib/spree/core/responder.rb rename to frontend/lib/spree/frontend/responder.rb diff --git a/frontend/lib/spree/core/store_helpers.rb b/frontend/lib/spree/frontend/store_helpers.rb similarity index 100% rename from frontend/lib/spree/core/store_helpers.rb rename to frontend/lib/spree/frontend/store_helpers.rb diff --git a/frontend/lib/spree_frontend.rb b/frontend/lib/spree_frontend.rb new file mode 100644 index 00000000000..46fe1ff18a0 --- /dev/null +++ b/frontend/lib/spree_frontend.rb @@ -0,0 +1 @@ +require 'spree/frontend' diff --git a/frontend/spec/lib/search/base_spec.rb b/frontend/spec/lib/search/base_spec.rb index 753c0d1bb9e..3515d7042af 100644 --- a/frontend/spec/lib/search/base_spec.rb +++ b/frontend/spec/lib/search/base_spec.rb @@ -3,7 +3,7 @@ describe Spree::Core::Search::Base do before do - include Spree::Models::ProductFilters + include Spree::Core::ProductFilters @product1 = create(:product, :name => "RoR Mug", :price => 9.00, :on_hand => 1) @product2 = create(:product, :name => "RoR Shirt", :price => 11.00, :on_hand => 1) end diff --git a/frontend/spec/spec_helper.rb b/frontend/spec/spec_helper.rb index 19bd650bf4b..d0e2322ff17 100644 --- a/frontend/spec/spec_helper.rb +++ b/frontend/spec/spec_helper.rb @@ -10,15 +10,12 @@ require 'database_cleaner' -require 'spree/models/testing_support/preferences' -require 'spree/models/testing_support/factories' - -require 'spree/testing_support/env' +require 'spree/testing_support/preferences' +require 'spree/testing_support/factories' require 'spree/testing_support/controller_requests' require 'spree/testing_support/authorization_helpers' require 'spree/testing_support/flash' - -require 'spree/core/url_helpers' +require 'spree/testing_support/url_helpers' require 'paperclip/matchers' RSpec.configure do |config| @@ -49,9 +46,10 @@ DatabaseCleaner.clean end - config.include Spree::Models::TestingSupport::Preferences config.include FactoryGirl::Syntax::Methods + + config.include Spree::TestingSupport::Preferences config.include Spree::TestingSupport::UrlHelpers config.include Spree::TestingSupport::ControllerRequests config.include Spree::TestingSupport::Flash diff --git a/frontend/spree_core.gemspec b/frontend/spree_frontend.gemspec similarity index 81% rename from frontend/spree_core.gemspec rename to frontend/spree_frontend.gemspec index 038032880c3..eeec8fc3bce 100644 --- a/frontend/spree_core.gemspec +++ b/frontend/spree_frontend.gemspec @@ -3,22 +3,22 @@ version = File.read(File.expand_path("../../SPREE_VERSION", __FILE__)).strip Gem::Specification.new do |s| s.platform = Gem::Platform::RUBY - s.name = 'spree_core' + s.name = 'spree_frontend' s.version = version - s.summary = 'Core e-commerce functionality for the Spree project.' + s.summary = 'Frontend e-commerce functionality for the Spree project.' s.description = 'Required dependency for Spree' s.required_ruby_version = '>= 1.8.7' s.author = 'Sean Schofield' s.email = 'sean@spreecommerce.com' s.homepage = 'http://spreecommerce.com' - s.rubyforge_project = 'spree_core' + s.rubyforge_project = 'spree_frontend' s.files = Dir['LICENSE', 'README.md', 'app/**/*', 'config/**/*', 'lib/**/*', 'db/**/*', 'vendor/**/*'] s.require_path = 'lib' s.requirements << 'none' - s.add_dependency 'spree_models', version + s.add_dependency 'spree_core', version s.add_dependency 'spree_api', version s.add_dependency 'jquery-rails', '~> 2.1.4' @@ -27,7 +27,6 @@ Gem::Specification.new do |s| s.add_dependency 'rails', '~> 3.2.8' s.add_dependency 'deface', '>= 0.9.0' s.add_dependency 'stringex', '~> 1.3.2' - s.add_dependency 'cancan', '1.6.7' s.add_dependency 'money', '5.0.0' s.add_dependency 'rabl', '0.7.2' diff --git a/promo/app/assets/javascripts/admin/spree_promo.js b/promo/app/assets/javascripts/admin/spree_promo.js index 48567b9b922..c69be0541f4 100644 --- a/promo/app/assets/javascripts/admin/spree_promo.js +++ b/promo/app/assets/javascripts/admin/spree_promo.js @@ -1,4 +1,5 @@ //= require admin/spree_core //= require admin/user_picker //= require admin/product_picker +//= require admin/spree_frontend //= require_tree . diff --git a/promo/app/assets/javascripts/store/spree_promo.js b/promo/app/assets/javascripts/store/spree_promo.js index d5cb5c754f8..d10fba7fac3 100644 --- a/promo/app/assets/javascripts/store/spree_promo.js +++ b/promo/app/assets/javascripts/store/spree_promo.js @@ -1 +1 @@ -//= require store/spree_core +//= require store/spree_frontend diff --git a/promo/app/assets/stylesheets/admin/spree_promo.css b/promo/app/assets/stylesheets/admin/spree_promo.css index 21ef02a685b..f65820594bc 100644 --- a/promo/app/assets/stylesheets/admin/spree_promo.css +++ b/promo/app/assets/stylesheets/admin/spree_promo.css @@ -1,3 +1,3 @@ /* - *= require admin/spree_core + *= require admin/spree_frontend */ diff --git a/promo/app/assets/stylesheets/store/spree_promo.css b/promo/app/assets/stylesheets/store/spree_promo.css index 562fe091048..61486ee3f57 100644 --- a/promo/app/assets/stylesheets/store/spree_promo.css +++ b/promo/app/assets/stylesheets/store/spree_promo.css @@ -1,5 +1,5 @@ /* - *= require store/spree_core + *= require store/spree_frontend *= require_self */