Skip to content

Commit

Permalink
Move core to frontend
Browse files Browse the repository at this point in the history
Models will soon become the new 'core'

rename models to core
  • Loading branch information
radar committed Feb 7, 2013
1 parent 2f7abb0 commit ed7ef8f
Show file tree
Hide file tree
Showing 29 changed files with 176 additions and 78 deletions.
1 change: 0 additions & 1 deletion api/.rspec

This file was deleted.

26 changes: 0 additions & 26 deletions core/LICENSE

This file was deleted.

1 change: 1 addition & 0 deletions core/app/models/spree/address.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class Address < ActiveRecord::Base

validates :firstname, :lastname, :address1, :city, :zipcode, :country, :presence => true
validates :phone, :presence => true, :if => :require_phone?

validate :state_validate

attr_accessible :firstname, :lastname, :address1, :address2,
Expand Down
1 change: 1 addition & 0 deletions core/app/models/spree/image.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class Image < Asset
:url => '/spree/products/:id/:style/:basename.:extension',
:path => ':rails_root/public/spree/products/:id/:style/:basename.:extension',
:convert_options => { :all => '-strip -auto-orient' }

# save the w,h of the original image (from which others can be calculated)
# we need to look at the write-queue for images which have not been saved yet
after_post_process :find_dimensions
Expand Down
5 changes: 2 additions & 3 deletions core/app/models/spree/payment/processing.rb
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,8 @@ def gateway_options

options.merge!({ :shipping => order.ship_total * 100,
:tax => order.tax_total * 100,
:subtotal => order.item_total * 100 })

options.merge!({ :currency => currency })
:subtotal => order.item_total * 100,
:currency => currency })

options.merge!({ :billing_address => order.bill_address.try(:active_merchant_hash),
:shipping_address => order.ship_address.try(:active_merchant_hash) })
Expand Down
1 change: 0 additions & 1 deletion core/app/models/spree/preference.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,4 @@ def value
def raw_value
self[:value]
end

end
1 change: 0 additions & 1 deletion core/app/models/spree/product.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ class Product < ActiveRecord::Base
after_create :add_properties_and_option_types_from_prototype
after_create :build_variants_from_option_values_hash, :if => :option_values_hash
before_save :recalculate_count_on_hand

after_save :save_master
after_save :set_master_on_hand_to_zero_when_product_has_variants

Expand Down
2 changes: 2 additions & 0 deletions core/app/models/spree/property.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ class Property < ActiveRecord::Base

validates :name, :presentation, :presence => true

scope :sorted, lambda { order(:name) }

def self.find_all_by_prototype(prototype)
id = prototype
if prototype.class == Prototype
Expand Down
1 change: 1 addition & 0 deletions core/app/models/spree/shipment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ def display_cost
shipment.determine_state(shipment.order) == 'ready'
}
end

event :pend do
transition :from => 'ready', :to => 'pending'
end
Expand Down
8 changes: 8 additions & 0 deletions core/app/models/spree/variant.rb
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,14 @@ def parse_price(price)
price.to_d
end

# Ensures a new variant takes the product master price when price is not supplied
def check_price
if price.nil?
raise 'Must supply price for variant or master.price for product.' if self == product.master
self.price = product.master.price
end
end

def recalculate_product_on_hand
on_hand = product.on_hand
if Spree::Config[:track_inventory_levels] && on_hand != (1.0 / 0) # Infinity
Expand Down
4 changes: 0 additions & 4 deletions core/config/routes.rb

This file was deleted.

84 changes: 78 additions & 6 deletions core/spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@

require 'database_cleaner'

require 'spree/core/testing_support/factories'
require 'spree/core/testing_support/capybara_ext'
require 'spree/core/testing_support/controller_requests'
require 'spree/core/testing_support/authorization_helpers'
require 'spree/core/testing_support/preferences'
require 'spree/core/testing_support/flash'
require 'spree/testing_support/factories'
require 'spree/testing_support/preferences'

require 'spree/testing_support/controller_requests'
require 'spree/testing_support/authorization_helpers'
require 'spree/testing_support/flash'
require 'spree/testing_support/url_helpers'
require 'spree/testing_support/capybara_ext'

require 'paperclip/matchers'

Expand Down Expand Up @@ -50,9 +52,79 @@
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

config.include Paperclip::Shoulda::Matchers
end

shared_context "custom products" do
before(:each) do
reset_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(:simple_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
13 changes: 0 additions & 13 deletions dash/Guardfile

This file was deleted.

1 change: 0 additions & 1 deletion frontend/.rspec

This file was deleted.

3 changes: 0 additions & 3 deletions frontend/Gemfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
eval(File.read(File.dirname(__FILE__) + '/../common_spree_dependencies.rb'))

gem 'spree_core', :path => '../core'
gem 'spree_api', :path => '../api'

gemspec
13 changes: 0 additions & 13 deletions frontend/Guardfile

This file was deleted.

6 changes: 3 additions & 3 deletions frontend/Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,21 @@ require 'spree/testing_support/common_rake'
Bundler::GemHelper.install_tasks
RSpec::Core::RakeTask.new

spec = eval(File.read('spree_frontend.gemspec'))
spec = eval(File.read('spree_core.gemspec'))
Gem::PackageTask.new(spec) do |p|
p.gem_spec = spec
end

desc "Release to gemcutter"
task :release do
version = File.read(File.expand_path("../../SPREE_VERSION", __FILE__)).strip
cmd = "cd pkg && gem push spree_frontend-#{version}.gem"; puts cmd; system cmd
cmd = "cd pkg && gem push spree_core-#{version}.gem"; puts cmd; system cmd
end

task :default => :spec

desc "Generates a dummy app for testing"
task :test_app do
ENV['LIB_NAME'] = 'spree/frontend'
ENV['LIB_NAME'] = 'spree/core'
Rake::Task['common:test_app'].invoke
end
25 changes: 25 additions & 0 deletions frontend/config/initializers/user_class_extensions.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
Spree::Core::Engine.config.to_prepare do
if Spree.user_class
Spree.user_class.class_eval do
include Spree::Core::UserBanners
has_and_belongs_to_many :spree_roles,
:join_table => 'spree_roles_users',
:foreign_key => "user_id",
:class_name => "Spree::Role"

has_many :spree_orders, :foreign_key => "user_id", :class_name => "Spree::Order"

belongs_to :ship_address, :class_name => 'Spree::Address'
belongs_to :bill_address, :class_name => 'Spree::Address'

# has_spree_role? simply needs to return true or false whether a user has a role or not.
def has_spree_role?(role_in_question)
spree_roles.where(:name => role_in_question.to_s).any?
end

def last_incomplete_spree_order
spree_orders.incomplete.order('created_at DESC').last
end
end
end
end
Empty file modified frontend/config/routes.rb
100755 → 100644
Empty file.
19 changes: 19 additions & 0 deletions frontend/lib/spree/money.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
require 'money'

module Spree
class Money
def initialize(amount, options={})
@money = ::Money.parse([amount, Spree::Config[:currency]].join)
@options = {}
@options[:with_currency] = true if Spree::Config[:display_currency]
@options[:symbol_position] = Spree::Config[:currency_symbol_position].to_sym
@options.merge!(options)
# Must be a symbol because the Money gem doesn't do the conversion
@options[:symbol_position] = @options[:symbol_position].to_sym
end

def to_s
@money.format(@options)
end
end
end
33 changes: 33 additions & 0 deletions frontend/lib/spree/scopes/dynamic.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
module Spree
module Scopes
# This module is extended by ProductScope
module Dynamic
module_function

# Sample dynamic scope generating from set of products
# generates 0 or (2..scope_limit) scopes for prices, based
# on number of products (uses Math.log, to guess number of scopes)
def price_scopes_for(products, scope_limit=5)
scopes = []

# Price based scopes
all_prices = products.map(&:price).sort

ranges = [Math.log(products.length).floor, scope_limit].max

if ranges >= 2
l = all_prices.length / ranges
scopes << ProductScope.new({:name => "master_price_lte", :arguments => [all_prices[l]] })

(ranges - 2).times do |x|
scopes << ProductScope.new({:name => "price_between",
:arguments => [ all_prices[l*(x+1)+1], all_prices[l*(x+2)] ] })
end
scopes << ProductScope.new({:name => "master_price_gte", :arguments => [all_prices[l*(ranges-1)+1]] })
end

scopes
end
end
end
end
File renamed without changes.
File renamed without changes.
File renamed without changes.
6 changes: 3 additions & 3 deletions frontend/spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,19 @@

require 'database_cleaner'

require 'spree/testing_support/preferences'
require 'spree/testing_support/factories'
require 'spree/testing_support/preferences'
require 'spree/testing_support/controller_requests'
require 'spree/testing_support/authorization_helpers'
require 'spree/testing_support/flash'
require 'spree/testing_support/url_helpers'

require 'paperclip/matchers'

RSpec.configure do |config|
config.mock_with :rspec

config.fixture_path = "#{::Rails.root}/spec/fixtures"
config.fixture_path = File.join(File.expand_path(File.dirname(__FILE__)), "fixtures")

#config.include Devise::TestHelpers, :type => :controller
# If you're not using ActiveRecord, or you'd prefer not to run each of your
Expand All @@ -46,7 +47,6 @@
DatabaseCleaner.clean
end


config.include FactoryGirl::Syntax::Methods

config.include Spree::TestingSupport::Preferences
Expand Down

0 comments on commit ed7ef8f

Please sign in to comment.