From ac23dfd6519d3c7af7752607919e313294b1ed5b Mon Sep 17 00:00:00 2001
From: kei
Date: Mon, 6 Aug 2012 18:50:21 +0900
Subject: [PATCH 001/346] add :ignore_types option to flash_messages
Fixes #1835
---
core/app/helpers/spree/base_helper.rb | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/core/app/helpers/spree/base_helper.rb b/core/app/helpers/spree/base_helper.rb
index 9100b53c30d..3f11387a261 100644
--- a/core/app/helpers/spree/base_helper.rb
+++ b/core/app/helpers/spree/base_helper.rb
@@ -95,7 +95,11 @@ def logo(image_path=Spree::Config[:logo])
link_to image_tag(image_path), root_path
end
- def flash_messages
+ def flash_messages(opts = {})
+ flash.reject do |msg_type, text|
+ opts[:ignore_types] && opts[:ignore_types].include?(msg_type)
+ end
+
flash.each do |msg_type, text|
concat(content_tag :div, text, :class => "flash #{msg_type}") unless msg_type == :commerce_tracking
end
From 7634d7b160709b8ff1d80ee867e9394654fc6557 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Trung=20L=C3=AA?=
Date: Fri, 10 Aug 2012 10:56:30 +1000
Subject: [PATCH 002/346] Bump rails to 3.2.8
---
README.md | 4 ++--
core/spree_core.gemspec | 2 +-
2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/README.md b/README.md
index 2851fd10356..08ab009d559 100644
--- a/README.md
+++ b/README.md
@@ -32,9 +32,9 @@ Installation
The fastest way to get started is by using the spree command line tool
available in the spree gem which will add Spree to an existing Rails application.
- $ gem install rails -v 3.2.7
+ $ gem install rails -v 3.2.8
$ gem install spree
- $ rails _3.2.7_ new my_store
+ $ rails _3.2.8_ new my_store
$ spree install my_store
This will add the Spree gem to your Gemfile, create initializers, copy migrations and
diff --git a/core/spree_core.gemspec b/core/spree_core.gemspec
index b02cb719c44..3c7da93c3d5 100644
--- a/core/spree_core.gemspec
+++ b/core/spree_core.gemspec
@@ -31,7 +31,7 @@ Gem::Specification.new do |s|
s.add_dependency 'aws-sdk', '~> 1.3.4'
s.add_dependency 'ransack', '~> 0.6.0'
s.add_dependency 'activemerchant', '= 1.20.4'
- s.add_dependency 'rails', '~> 3.2.7'
+ s.add_dependency 'rails', '~> 3.2.8'
s.add_dependency 'kaminari', '>= 0.13.0'
s.add_dependency 'deface', '>= 0.9.0'
s.add_dependency 'stringex', '~> 1.3.2'
From 736fb7c633cfe5d8bd667f28b7c1ad71f629ab49 Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Fri, 10 Aug 2012 10:14:44 +1000
Subject: [PATCH 003/346] Add 1-2-stable to Travis
---
.travis.yml | 1 +
1 file changed, 1 insertion(+)
diff --git a/.travis.yml b/.travis.yml
index b9b187ea6a8..b77e5121e51 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -25,6 +25,7 @@ branches:
only:
- 1-0-stable
- 1-1-stable
+ - 1-2-stable
- master
rvm:
- 1.8.7
From 0a2eb58a36a2178bb1416f0aa940ac215ad4b96f Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Fri, 10 Aug 2012 10:43:52 +1000
Subject: [PATCH 004/346] Allow -v or --version to get back the version
---
cmd/lib/spree_cmd.rb | 23 ++++++++++++-----------
1 file changed, 12 insertions(+), 11 deletions(-)
diff --git a/cmd/lib/spree_cmd.rb b/cmd/lib/spree_cmd.rb
index 69c8eae1f73..96a8c3295e1 100644
--- a/cmd/lib/spree_cmd.rb
+++ b/cmd/lib/spree_cmd.rb
@@ -4,16 +4,17 @@
module SpreeCmd
class Command
- if ARGV.first == 'version'
- puts Gem.loaded_specs['spree_cmd'].version
- elsif ARGV.first == 'extension'
- ARGV.shift
- require 'spree_cmd/extension'
- SpreeCmd::Extension.start
- else
- ARGV.shift
- require 'spree_cmd/installer'
- SpreeCmd::Installer.start
+ case ARGV.first
+ when 'version' || '-v' || '--version'
+ puts Gem.loaded_specs['spree_cmd'].version
+ when 'extension'
+ ARGV.shift
+ require 'spree_cmd/extension'
+ SpreeCmd::Extension.start
+ else
+ ARGV.shift
+ require 'spree_cmd/installer'
+ SpreeCmd::Installer.start
end
end
-end
\ No newline at end of file
+end
From 295b1c8f89fa2a3cd95d404edc38368bb3ffb370 Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Fri, 10 Aug 2012 12:13:30 +1000
Subject: [PATCH 005/346] Don't show output for imagemagick check
---
cmd/lib/spree_cmd/installer.rb | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/cmd/lib/spree_cmd/installer.rb b/cmd/lib/spree_cmd/installer.rb
index 6cd6fbea8e2..799afb10bb1 100644
--- a/cmd/lib/spree_cmd/installer.rb
+++ b/cmd/lib/spree_cmd/installer.rb
@@ -181,10 +181,16 @@ def windows?
end
def image_magick_installed?
+ cmd = 'identify -version'
+ if RUBY_PLATFORM =~ /mswin/ #windows
+ cmd += " >nul"
+ else
+ cmd += " >/dev/null"
+ end
# true if command executed succesfully
# false for non zero exit status
# nil if command execution fails
- system('identify -version')
+ system(cmd)
end
end
end
From c8ce22d5353a8ad2c175279aef9f4223f05f4b39 Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Fri, 10 Aug 2012 13:17:42 +1000
Subject: [PATCH 006/346] Remove sample users
---
sample/db/sample/spree/users.yml | 8 --------
1 file changed, 8 deletions(-)
delete mode 100644 sample/db/sample/spree/users.yml
diff --git a/sample/db/sample/spree/users.yml b/sample/db/sample/spree/users.yml
deleted file mode 100644
index 5bd748e2638..00000000000
--- a/sample/db/sample/spree/users.yml
+++ /dev/null
@@ -1,8 +0,0 @@
-<%
-1.upto(100) do |i|
-%>
-user_<%= i %>:
- email: <%= Faker::Internet.email %>
- ship_address: ship_address_<%= i %>
- bill_address: bill_address_<%= i %>
-<% end %>
\ No newline at end of file
From 0e0b37849efb5de245bc5b93944b50eda4d190d4 Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Fri, 10 Aug 2012 13:46:01 +1000
Subject: [PATCH 007/346] If a user elects to not use the default
authentication system, then we must prompt for the user class
The user class argument will be configured in config/initializers/spree.rb, rather than it defaulting to Spree::LegacyUser and you having to manually change it
---
cmd/lib/spree_cmd/installer.rb | 8 ++++++++
core/lib/generators/spree/install/install_generator.rb | 1 +
.../spree/install/templates/config/initializers/spree.rb | 2 +-
3 files changed, 10 insertions(+), 1 deletion(-)
diff --git a/cmd/lib/spree_cmd/installer.rb b/cmd/lib/spree_cmd/installer.rb
index 799afb10bb1..5db177fd5b9 100644
--- a/cmd/lib/spree_cmd/installer.rb
+++ b/cmd/lib/spree_cmd/installer.rb
@@ -1,4 +1,5 @@
require 'rbconfig'
+require 'active_support/core_ext/string'
module SpreeCmd
@@ -64,6 +65,12 @@ def prepare_options
def ask_questions
@install_default_gateways = ask_with_default('Would you like to install the default gateways?')
@install_default_auth = ask_with_default('Would you like to install the default authentication system?')
+ unless @install_default_auth
+ @user_class = ask("What is the name of the class representing users within your application? [User]")
+ if @user_class.blank?
+ @user_class = "User"
+ end
+ end
if options[:skip_install_data]
@run_migrations = false
@@ -106,6 +113,7 @@ def initialize_spree
spree_options << "--migrate=#{@run_migrations}"
spree_options << "--seed=#{@load_seed_data}"
spree_options << "--sample=#{@load_sample_data}"
+ spree_options << "--user_class=#{@user_class}"
spree_options << "--auto_accept" if options[:auto_accept]
inside @app_path do
diff --git a/core/lib/generators/spree/install/install_generator.rb b/core/lib/generators/spree/install/install_generator.rb
index 9d7d8731fbf..0727f77aabc 100644
--- a/core/lib/generators/spree/install/install_generator.rb
+++ b/core/lib/generators/spree/install/install_generator.rb
@@ -9,6 +9,7 @@ class InstallGenerator < Rails::Generators::Base
class_option :seed, :type => :boolean, :default => true, :banner => 'load seed data (migrations must be run)'
class_option :sample, :type => :boolean, :default => true, :banner => 'load sample data (migrations must be run)'
class_option :auto_accept, :type => :boolean
+ class_option :user_class, :type => :string
class_option :admin_email, :type => :string
class_option :admin_password, :type => :string
class_option :lib_name, :type => :string, :default => 'spree'
diff --git a/core/lib/generators/spree/install/templates/config/initializers/spree.rb b/core/lib/generators/spree/install/templates/config/initializers/spree.rb
index 3c8249af012..a4867e884ff 100644
--- a/core/lib/generators/spree/install/templates/config/initializers/spree.rb
+++ b/core/lib/generators/spree/install/templates/config/initializers/spree.rb
@@ -11,4 +11,4 @@
# config.site_name = "Spree Demo Site"
end
-Spree.user_class = "Spree::LegacyUser"
+Spree.user_class = <%= (options[:user_class] || "Spree::LegacyUser").inspect %>
From d6005732da43f97026c7e9d397b43b515022467b Mon Sep 17 00:00:00 2001
From: Peter Berkenbosch
Date: Sat, 11 Aug 2012 15:56:12 +0200
Subject: [PATCH 008/346] use the official spree repository for
spree_auth_devise [ci-skip]
[Fixes #1849]
---
cmd/lib/spree_cmd/installer.rb | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/cmd/lib/spree_cmd/installer.rb b/cmd/lib/spree_cmd/installer.rb
index 5db177fd5b9..f90c48e68ac 100644
--- a/cmd/lib/spree_cmd/installer.rb
+++ b/cmd/lib/spree_cmd/installer.rb
@@ -101,7 +101,7 @@ def add_gems
end
if @install_default_auth
- gem :spree_auth_devise, :git => "git://github.com/radar/spree_auth_devise"
+ gem :spree_auth_devise, :git => "git://github.com/spree/spree_auth_devise"
end
run 'bundle install', :capture => true
From a7c938f07cbccade5a550f23dad871995c79b88d Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Mon, 13 Aug 2012 11:25:26 +1000
Subject: [PATCH 009/346] Use Spree.user_class in user_factory, rather than a
hard-coded class
---
core/lib/spree/core/testing_support/factories/user_factory.rb | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/core/lib/spree/core/testing_support/factories/user_factory.rb b/core/lib/spree/core/testing_support/factories/user_factory.rb
index d022da3d48f..ede76b713df 100644
--- a/core/lib/spree/core/testing_support/factories/user_factory.rb
+++ b/core/lib/spree/core/testing_support/factories/user_factory.rb
@@ -3,12 +3,12 @@
"xxxx#{Time.now.to_i}#{rand(1000)}#{n}xxxxxxxxxxxxx"
end
- factory :user, :class => Spree::LegacyUser do
+ factory :user, :class => Spree.user_class do
email { Faker::Internet.email }
login { email }
password 'secret'
password_confirmation 'secret'
- authentication_token { FactoryGirl.generate(:user_authentication_token) } if Spree::LegacyUser.attribute_method? :authentication_token
+ authentication_token { FactoryGirl.generate(:user_authentication_token) } if Spree.user_class.attribute_method? :authentication_token
end
factory :admin_user, :parent => :user do
From a6522f8991c43c9aac55cd5f152c7cd31c7d94a8 Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Mon, 13 Aug 2012 11:24:52 +1000
Subject: [PATCH 010/346] Allow user class name to be passed to common:test_app
rake task
---
core/lib/spree/core/testing_support/common_rake.rb | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/core/lib/spree/core/testing_support/common_rake.rb b/core/lib/spree/core/testing_support/common_rake.rb
index ec560a0d61b..54400382eb9 100644
--- a/core/lib/spree/core/testing_support/common_rake.rb
+++ b/core/lib/spree/core/testing_support/common_rake.rb
@@ -4,11 +4,12 @@
desc "Generates a dummy app for testing"
namespace :common do
- task :test_app do
+ task :test_app, :user_class do |t, args|
+ args.with_defaults(:user_class => "Spree::LegacyUser")
require "#{ENV['LIB_NAME']}"
Spree::DummyGenerator.start ["--lib_name=#{ENV['LIB_NAME']}", "--database=#{ENV['DB_NAME']}", "--quiet"]
- Spree::InstallGenerator.start ["--lib_name=#{ENV['LIB_NAME']}", "--auto-accept", "--migrate=false", "--seed=false", "--sample=false", "--quiet"]
+ Spree::InstallGenerator.start ["--lib_name=#{ENV['LIB_NAME']}", "--auto-accept", "--migrate=false", "--seed=false", "--sample=false", "--quiet", "--user_class=#{args[:user_class]}"]
puts "Setting up dummy database..."
cmd = "bundle exec rake db:drop db:create db:migrate db:test:prepare"
From 11b196ee9353f40e4c15d3b49fbdb8c74dfd9994 Mon Sep 17 00:00:00 2001
From: Sean Schofield
Date: Mon, 13 Aug 2012 21:13:55 -0400
Subject: [PATCH 011/346] Version bump
---
SPREE_VERSION | 2 +-
cmd/lib/spree_cmd/extension.rb | 2 +-
core/lib/spree/core/version.rb | 2 +-
3 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/SPREE_VERSION b/SPREE_VERSION
index a5b53b3152e..3a9164e4092 100644
--- a/SPREE_VERSION
+++ b/SPREE_VERSION
@@ -1 +1 @@
-1.2.0.rc1
+1.2.0.rc2
diff --git a/cmd/lib/spree_cmd/extension.rb b/cmd/lib/spree_cmd/extension.rb
index 2044dd0d88d..fdaaee1d7bd 100644
--- a/cmd/lib/spree_cmd/extension.rb
+++ b/cmd/lib/spree_cmd/extension.rb
@@ -51,7 +51,7 @@ def class_name
end
def spree_version
- '1.2.0.rc1'
+ '1.2.0.rc2'
end
def use_prefix(prefix)
diff --git a/core/lib/spree/core/version.rb b/core/lib/spree/core/version.rb
index a7682f8a19d..d5154e87d16 100644
--- a/core/lib/spree/core/version.rb
+++ b/core/lib/spree/core/version.rb
@@ -1,5 +1,5 @@
module Spree
def self.version
- "1.2.0.rc1"
+ "1.2.0.rc2"
end
end
From 1e67a6406001424d4073d72d17ad66efe647bbb1 Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Tue, 14 Aug 2012 11:16:34 +1000
Subject: [PATCH 012/346] associate_user needs to be callable from
OrdersController
This is because on the OrdersController#edit page, we need to check to see if this order can potentially be associated with a user before rendering the page, so that orders can be merged together from different sign in sessions
---
.../controllers/spree/checkout_controller.rb | 18 ------------------
.../app/controllers/spree/orders_controller.rb | 1 +
core/lib/spree/core/controller_helpers.rb | 18 ++++++++++++++++++
3 files changed, 19 insertions(+), 18 deletions(-)
diff --git a/core/app/controllers/spree/checkout_controller.rb b/core/app/controllers/spree/checkout_controller.rb
index 148e09cf2e5..471ee2a48e2 100644
--- a/core/app/controllers/spree/checkout_controller.rb
+++ b/core/app/controllers/spree/checkout_controller.rb
@@ -56,24 +56,6 @@ def load_order
state_callback(:before)
end
- def associate_user
- if try_spree_current_user && @order
- if @order.user.blank? || @order.email.blank?
- @order.associate_user!(try_spree_current_user)
- end
- end
-
- # This will trigger any "first order" promotions to be triggered
- # Assuming of course that this session variable was set correctly in
- # the authentication provider's registrations controller
- if session[:spree_user_signup]
- fire_event('spree.user.signup', :user => try_spree_current_user, :order => current_order(true))
- end
-
- session[:guest_token] = nil
- session[:spree_user_signup] = nil
- end
-
# Provides a route to redirect after order completion
def completion_route
order_path(@order)
diff --git a/core/app/controllers/spree/orders_controller.rb b/core/app/controllers/spree/orders_controller.rb
index 2ff308100ac..d4999858417 100644
--- a/core/app/controllers/spree/orders_controller.rb
+++ b/core/app/controllers/spree/orders_controller.rb
@@ -24,6 +24,7 @@ def update
# Shows the current incomplete order from the session
def edit
@order = current_order(true)
+ associate_user
end
# Adds a new item to the order (creating a new order if none already exists)
diff --git a/core/lib/spree/core/controller_helpers.rb b/core/lib/spree/core/controller_helpers.rb
index ef7037a3575..a7540568cd0 100644
--- a/core/lib/spree/core/controller_helpers.rb
+++ b/core/lib/spree/core/controller_helpers.rb
@@ -48,6 +48,24 @@ def title
end
end
+ def associate_user
+ if try_spree_current_user && @order
+ if @order.user.blank? || @order.email.blank?
+ @order.associate_user!(try_spree_current_user)
+ end
+ end
+
+ # This will trigger any "first order" promotions to be triggered
+ # Assuming of course that this session variable was set correctly in
+ # the authentication provider's registrations controller
+ if session[:spree_user_signup]
+ fire_event('spree.user.signup', :user => try_spree_current_user, :order => current_order(true))
+ end
+
+ session[:guest_token] = nil
+ session[:spree_user_signup] = nil
+ end
+
protected
def set_current_order
From 651372d2a9d1ba1440b13919294fb6ec33d40fff Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Tue, 14 Aug 2012 11:16:48 +1000
Subject: [PATCH 013/346] Use Spree.user_class inside ability
---
core/app/models/spree/ability.rb | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/core/app/models/spree/ability.rb b/core/app/models/spree/ability.rb
index 3b8ff4e49e3..7a9fc2c9af0 100644
--- a/core/app/models/spree/ability.rb
+++ b/core/app/models/spree/ability.rb
@@ -36,13 +36,13 @@ def initialize(user)
can :manage, :all
else
#############################
- can :read, LegacyUser do |resource|
+ can :read, Spree.user_class do |resource|
resource == user
end
- can :update, LegacyUser do |resource|
+ can :update, Spree.user_class do |resource|
resource == user
end
- can :create, LegacyUser
+ can :create, Spree.user_class
#############################
can :read, Order do |order, token|
order.user == user || order.token && token == order.token
From 697149dff0c2426391704bc12b54acb29726f6bd Mon Sep 17 00:00:00 2001
From: Jeff Dutil
Date: Mon, 13 Aug 2012 14:36:18 -0400
Subject: [PATCH 014/346] Refactor to have a default :ignore_types list.
Fixes #1853
---
core/app/helpers/spree/base_helper.rb | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/core/app/helpers/spree/base_helper.rb b/core/app/helpers/spree/base_helper.rb
index 3f11387a261..b6aba6baf76 100644
--- a/core/app/helpers/spree/base_helper.rb
+++ b/core/app/helpers/spree/base_helper.rb
@@ -96,12 +96,14 @@ def logo(image_path=Spree::Config[:logo])
end
def flash_messages(opts = {})
+ opts[:ignore_types] = [:commerce_tracking].concat(opts[:ignore_types] || [])
+
flash.reject do |msg_type, text|
- opts[:ignore_types] && opts[:ignore_types].include?(msg_type)
+ opts[:ignore_types].include?(msg_type)
end
flash.each do |msg_type, text|
- concat(content_tag :div, text, :class => "flash #{msg_type}") unless msg_type == :commerce_tracking
+ concat(content_tag :div, text, :class => "flash #{msg_type}")
end
nil
end
From e83aa16bb4d2478a41a6d565d55a5727209e8281 Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Tue, 14 Aug 2012 16:08:28 +1000
Subject: [PATCH 015/346] Add large noimage placeholder
Fixes #1828
---
core/app/assets/images/noimage/large.png | Bin 0 -> 13425 bytes
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 core/app/assets/images/noimage/large.png
diff --git a/core/app/assets/images/noimage/large.png b/core/app/assets/images/noimage/large.png
new file mode 100644
index 0000000000000000000000000000000000000000..1caf12fea9f5ad5ec1ef28e4547cee77be7293ab
GIT binary patch
literal 13425
zcmc(GWpErzvaXmcCW|#1F*CEp%*@QpY=OnhU@_xJ_6Te-GfNg(7Bh@2W<8(XJ$vts
z*tqZCdmYhTSrz$ZW_^|YqpGuGRF!4WP>4{VprFv?WF^)Av=@KfNCToNuDY;5m+1knayIX1aD{ET#
zJ6P~r0!2jtLcRij3^-YNngM*B9GyJ`e1(Dkuq*IK{%e>O2>6GJr-Lx?pF!y=sRATi
z+^qoIENsjcY&>iL9(ERXPA*p2Qxdb04Ik48ynzX7x0facS~yl
zbxG-e`TEln2HJXhx(cwe`uO;;_;9kgxZAL@^YionWrKr*`Hu#(ho7^jnJ=@m2j$-u
zB&|Fw-0fUF?OdDze_1p$ck%KR2L6fkpHpyhRZ{x5VP}tj5%q^MR$nt$R(2LPRwt*w
z=JgM44^MTg{|e(jYI|t-yQv>_$L|xNf!$*Co5-9
zIZ0vQpAi;IJ4*o`2|m6L9DHn&Y~ml-*`?S%aIterNb!qvd|>0?5NGH48!PAR;c4b<
zVf8oG?%!Bm>HifgAmMIh=IP?D>Ehz}_v)$Ix_G*H*t)m^Bs91IN@f;z&VTj)qV`{r
zTDjYKTUkoGyEp;>SeU;u8E4Y#)IC
z!dU*d`Tk!qtbd%d{v>~{Z?#-U<|=1@>1n67wCl1W+JDr^TUow)$%
zyhgV3Ah^bup`odXTp&acv0!Zh#e(RrZ9^iWutfqe2|0XQ6k_72W%4wt8k=T_l6_Fd
zcYrJiMcjsizaXC(o9&h^xm@RC9__gcI~)dgUd+984787IJ(cg(w;KAWJ-{_kO!Z$g
zE4ut>@G^a@19F7-R%zfp%93ORnP(V3WVk*^wNo$s^xi72P?Ycnvqm^JM$ov
zeneq*Pz6w3#K#v-Y+75epv-u}!PMcUuetL$Sy8k3f!RWsT
z{U3z<&102-{kP&b6*i-2JE01^Z0Ejf`IrZCq%G|MPPiUGut>y_DEnE>k9WTtP=>n1
zOo5KH6&SWlB8f)~idp9R8hxBJ7Wyb=_xVUV)d#A&1qEMX7|TC~imRLYt{_>YSIxll
z9)_#{Tq1I^&xbtqXZskBNg|KX!#l97cdokC{AZvkia{Z$jwixUM1z1k;E=HcEF{U!
zdF)Qc;ycd#8j5@$p*?1H#^qPWj0hIA$%K~+_37e^)x?;Yp^xUGa&tL
zXm}4PnatZHbGGt?oj+Oi!hQ}}xNJ3?vsm@h{i8*3NMlL>rp5Jgj{;d2>JWurW%qA*
zzTis+g0%(2AlON}R>xkjUiCLS-!%2`jRZTJAr~Lh+#0I8CbGd_iAQ^17#x|p-i~!D
z`(nL@%OlgQ*p3r>RGj#T&Xl2(>hhsw$iUFQxUake{7u%Vmt~)NE
zk2n=|VP6yV(Pb1@3E-MqWOp6Z4utVUr!Rd6h&AQ=WB6mAnedMk$~86np-#`qVMUFD
zu^gAZWs8E?2ufpnDufj^=*O2PKhpA&z;ddU2OFH=xGwabgq`F{2II{SVop678~6J>
z!O{rGZ%eIvQv>~1A-R)`W(Ngs7yY7!Fe=@FxVc#E-wxQMc|(yU;Zh~tRg0APU<;OA
znLa;PRBkz@k7&?z!NAJyz9x@=EFO_6OicY{(0-k`DQ11tr<;o|a~c9S`-JE&aS|GD
z2#Wy9yRXlpXn&B8?^>N2!STchMMnhPf5K_}suD$*rqjl2CS1}cv
z-{n)jBw0c8+#ZS0%d4eEkIO_a+dnVl9qn%JF~96
zP2Hbbj=C{4kHuHS7)wUxeOacoWd}WLurvTXNzmFg=qdO
zW`k}m{*YMP`7;5MPG^En1uAo{Ub(u9*09^hQh*^puU0d>QdxJzk>AZThfsvYVt{g#
ztJw_S;;-w15Y6eD7TQZpr1!*9XFrQpZ>4UYv!ru-WXv3xB#jNJY%v-HtPSmlOJq2?
zIH)dI*Z+ukrO&+?*+xXu}cdXl6=$B0JQB|Tmb8pU3NaMb8QCPFvfZExRN
z#XTfK01tR}uNW0~rcL^mhdHmTif<%nOj<((TGB+8%7Yvv<^?FAV<*ZAM1as+cE#$L
z{Q8UTES9oA7p8I%rq*#Y0v2z*})6YGz9hf9Uv35yGswMl?0&07d9LwB
zU$MkMMp%A*2U33gxelh^KdUszJVz91r{Qd_6H@B498V|epS&nLfEy_s*<(ApW)$A&`zSUH)ScP4!h
zlTqwyJFib0-8zwwkcfqiY4xn$=8HJ!XWjUaAUUG^HI73p+r?ixY(eS~FSI$Wx96)H
z;r9nV7t`In4%M*V;>cE?RNo$HCk~uilz}&o_)S9X>_!P$neqy(Ywqh(duu(qAG?u9
z7$Xf-$1G*QxCIL_-3bjU1oQ7O>iLn$&PCV(pZmzT)mf+L5E6v6yMoM=eQX1DWK+sTh+EqnS<^5sbmG;F%wavC@}%
zfkV1>LIzo=-+9Ce<=ul|x{ILQz2RX;HYE5qLLyk;!@Eoa=-I(b-_;^R396neEroW@
zvV#-+f*F7yCsX#A(t`PqZ_nS5;Col_?vuJ=^?oq|l#M&5krYa69qRA>7=wey`*E40
zdUT;7aRQR*5ud<`W{=@);3++X+C1lwOVY;uX5J%*Iysm??D>R5;LN*jUUgwxz1_@w
z#J*{rE(x!m;>xsyyPRSyogujrfd%R=!F!J{(E>x=3^yy9nvt&{S_R^yVbQJz%~c^M
zF2t*L;(5ibZQHWY_wop;%IpTdhYi^Lq>aqUNIB+NH4ZDv=unph%
z(5+%2S(+8=gTv=&p{=)=4hV@q+iG3=41O2dXlr}7-W~qD(SjSkslPry)DKgHw;IRz
zt_yw+SszgknvNEW)Nh>8nGP*O4B9l(&+J`Td{7;wUYKrOWLqN3(3ZQNA*4Y=VN{vgbyxj_z1yL|7c85AHIvg7l4!u@af
z@vA8cV(nx~#R1LRtx)}eGZp9|$oA6k*84Z~;5;Ybv*545z2vvyd>=)eW?L|p@-VUL
z6>h>gK0{QG&q;z4UJD1TLr5a
zU`O4e%zMsC)T*FlI!oKPVM-h^%n&X7aBB(;IXjGK;u0#ep&`n66ODj|tBY)~Z*^3P+1lwG6_s)jY-zhgb
z+9$fn_iEA?LJ@P@nkS=!)|sXFqm{?iaX6#}13@}0i3iv6LJEY6WBaiZ}
zm5yPNy~wOe{rEwF(TPX9JuLI2(!c%vkU^~$xrBbqM9*5p9rf<2fqx36h^*(j-N15=q!qL2cYlp?Cb|ycjOkTIc
z4N@t+irNVei-2B%Y6S@)dfz5Y#Iu*b3&WWRw#8E^ZGXCr9r%d^J}*97|crA-ah6tn)%yOgbf&?CJ&gl
z3|5`TilGviAwD7^Z~R87vPO#;Z13MfV$T;ik(6GljC4;`J{8hcF0`iWfsOsl=xb0?
z&agWUtR&cy!;fn9$uy++v@BcCq%K6>kIg8yD|K!l+vG5i6Uxni|_f(M34(ko)+$^5NP+bT}}%?g*@5I
zW1Xw=94>|PtGlDenC4zsF$)5xp_4VQjy%x33H_%7IC5huFj#w@+ARi%8#Kn=K%{qb
zK39hO!b;R;kDAhgX-60Q&+7+DcPZ9ghCp|?db;n}wI&H{E&N}T80gO~15;a_5>d~}
z&CGeuBKI6@dceFLxRUn(dch+21P4bF)RC8op&zbI2-Q=g?)kV_^gIwci-az927@le
z5m$I+M~b*UdFq?M3pu6($%#|pnrA`TdKe40Pnp7g-w#m6!Jp>h_hrhid-RD=*$PeO
zVl~G-r~PVhTv~qyXai8oiv1$yp8PKiUZhhmL--f2kjuWwB{WA~JTl!6zc)#+DiM*V
z86?Odxo1hf~
zu;00A@b-s_B7QMY{j}$KA0H`ePRL_f=ovt+bZthKg_uum7~cc~F`_=*N7~}6K2?qz
z{b0Yt4BQ|gsD9+#nk-zPoG%05w;X;GIZ0_g#e}Phh_l^TDku*N
zZP1q2w?w|S>#bPqNuU?L7ESY-=lqHdQPjd_Vdp(M^tmfT+gz<5mbz_{^)8qSvwWb4
zV9ayWP~&uh8-i2}lPL82B7j_&N~Q=NCNSL;6lwRdF^bKDRGwe^fp)6%Z@);ebmxEA
z$OcfV{%me1>5AhLV(o|LJUFsa4c~0)($X4prYbG*X0VC*wyy;;{QfL%AR@U;cgr>S
z12{KFTRj2J%ssUjwy(b1d70b~Lz58xPT7xN3sH)Orke0Z=v0|&D7zd2H!sN{JCe!dYdscx3gT0?RD*Neg
z3^!%Dq#5iMYW>go)~AcsHt+9T*l$p#;YFp_g`xMab#z73?Bz`rXb&~x7H|^lis50g
z8wM848;&`I7u3djboc0*%
zm&*$F%WF@NRPK9}wNm(I*Yzf{#vyH|m;TvRM6SOP;Usm+%t>A!q1E-rUMaGcp}-hZ
z0=;qylT1NxQ7&8;hQg)i<}7Df|4cO5)OsiRyoMBEydMcwsqZ}c5oKRc_D1+|xV8^-
z*N_tKV^OJkQX1M3AAm&{Prc4Ci47Sx+oYhAyazEoHnDC*3mJbD+^s9m
zAUWMUBFvVrOpvJ?+Vzj#VUboRa^LOM*sttBC(Z1NQWv9ianqzDT%
z@C%Of-THhS#&VozsJ9g-H|%UQGSOfixEmU=Du?S3{!^9NkSx_SNpt0d(}_V0Ev~+Db@bBz`Uw|0u@W^A^n;(r
zide(b+or}9~%;0GPuVzvWu=%NvYCxc$KnEO4ivZHPfe~99E8fbU(Gls5va*Q+k>L21mzZesNK!NT7|Aw*
zRSX7L$dzn($HbDkUw7zUDJdre$E@gEcpbwn8%^>{;$1%atiDN}5fQ(nJX7O0UB
zRu;9g&Y&PCUr?bm+2w^t)T&sc6hT2inrYLrZX|N$Ipt_OjO|m+gl}*Mdgka1G+}M+
z00WQNMCjTJJZN(-%3*t840^Rkx!tjAlZgJt&zzzenKvrdR)ETIikL9cY6a>B_Delo
z_RF+o+jJ&=p{J=hMuszp&WYnq##Qo^t1}-)NGJ!G*Ae5l#5J6DuC$1RK%L4boxA1p
z3kU8~TCa0M4W)K#|0?hkTvt$;fTl!3!PWHg<}^*m7as0@u!T}<=b-l2RVfP(Om!r|3fZ)SX4i
zW60d;x#c<)-46+OfBx*&x5VQa*8P%{NGKOGqdKebP`UK+7PVA>*{&WO&HEXwD1kJe
z>4ml`Cxg#i)%O0%KHQu=(jh_V-rbUXz9cJ)G!g5V>dFx|5-y69)uQOPR&fvlbYoQ{
zwh*Fh3MGT>>UjYJZz|cVG~W;hKMd_A_u_?~gCs#vF`kKMs>Ub>&vv-PCCmV$X02sv
zN9~yHtUR&g?ujmV;ws#?pS9GhbqISwV*#9-K6ftlscoI%T}|B_9>eI~cq%%l^q9Gu
z+gEwVwhxwsgbH>kU+|elu!>Yy$F*y_erP_iQ$|P57(vXNGE1v(>sas{H&e5{vAi4l
z7fN22oI1yrp}Dmy28gBrc2?D2B^K3>X02RJW!$w3EJ}YkJrxp6!*n1OY_|1TIBF64G&^h=N?o9T{E4m2{Q2oZg(C>v
z?N()Sg5FI33kS?NwmP9@CcE(TE38^$4|hh#?fA~8a-2ggTkluNiIa;v9qYxWQi;wb
zSA^rzJ&%Si!1Yn%<;g|Pi04e_dQBi#!h&I_Dj;E}he?K9_s2=?9nEEMRo@+D+Lxwd
zI2J72gY2-VSzuJs5oI=SXx~N(;-x!QgLg@C(N{A|@vCMoTG>1te6c2_=Y!$C7S!4i
z1K`aHzUQwG+Q98650NKBMRN9ofDC#0c{i11s`R6dOVxP~9D=JL>1<^kVSFL(W^S54^3W6^vc0DbC{tU6
z-h-gQZo7v~ko&HbnToSoQ^pM~Q-6o8WZeyW32uH`3j$AVWZ6~L$dxiRRC6BF@**zfKUobEA+`pRq#&+Xob190BeT-E@&o|^{QEgTAqQIq
z0{h0t!+uDY)ztXv4{-Yr(kv)_?eD!LqUrcz#0K~hbTMDS1s1l5B#S;D!m%#ACk|k(
z;cIQKEgoA3)cE^Fpiq7(pS*4yu?GewmxOGaAfAMm6R~wiycMeAAsZG$E9c*Pd@oD>
zexTlGi6sqwYm{osF4BNX^zkFJB8Yl;`#?ZghF@g5F>i6Z;#%A$iUoi6XwyYuh1dA_@L!2Yr0wR+FO?35TB=PX-lE-G=7j%=MYsM2mtj2&>#Ax
zeRGxe00$AXzOpDi(roJ;P&LVHl%P?BusX7LYI!D_ipPHx#n~#7GvJ_4HZ26+%#LkI
zR%(#gqD_(E2iDkqu!V^4&(dC;=y5nB%J`}2?g(o7mK$ik1t|TFU%1jpPufCVvzN@E
z_>@Bgscqf^x_&|@6SzNtx*EZV25s_dd7TOqN-XDmx0!u5*bA~(gL&^e>2x26vUzJQ
z<5&H=VJMLP^y~!aNb;pue*zt{oGBd;!P_3MaJ1~$Q2m3d_)s$}ZjriX!+OoIUCwv`
zfd_$@qihj2&lEIEIDT%xyFJ~23ha#DEq0X$C=NOlmO>qi8OZf>M&&udc3Q!&kv;D;
zq#vXqOANP&nA(GeK1$VGKhy|mE}``yZS3ej#Ssd}7v`O)eR6I*pPNa1)8r`}i8ZBT
z#xh|NRFgzov?bc>wl_#fS9MUk9KG1>#6Kx^81?DoO#VnXr?9b3$uvia6|FpQGKrO1
zA<8!;*~4fzu5fc!{z0r+Xm+-AH8ku>hVfw{e0*nB2KEp!ByOPB%{reIjxxFnez&ri
z()CGcvbRnn!-tbDBq>_Ke{HG;?fxOl&mNQsM}x8NeU$87^Hn&kFo^6bqWgznUb)7s
zQ8%b5Nac47$cqIHdlbQ&8HeQfGthTB>5wSKt81R`l#$U{Ya;mT^3*XTpTqO?r=88I
zYHBixkP$`2SdTwpL8>dpK!3abB$9&=LnF&U7qsZ>>{rx$%t)zoZXbfd{YmEIbV4$n
z`3_s!Ijdw&MQ3JYMf7N5QnwOu(q_MU8)M6z4!U^dTJGig?2R4D#<#n1@Ck!J0)?AE
z>B8-6?vrHN?kl@-A!nI@#2D~xm(~uh-CRSd?~BT!(5?GDuce^6&0~tvA~#p2Na_rF
zf~iqP-@S96d-B;Uti~7pW}g&$^0Q(M-VDDqM9<^F0QSxzmlmi-2>cIj&UJ5XQ9u0d
zq8-oIWP|$2lYttxS;MmsBqzPxW8C%ZUx=^0XLRw0c=wl#3A!KBX`PmyGzej0%TRu!
zO@yKs8^_*Skn0L$Y!R@RAIejEjS@e`8eH&eUSF6A!XD%xp`$1?3nq|Ca!o&z5*C#C
zf)rwjV=OPcn#8H~?*U=qjh%#_JuU)`7I8@ZE|a_1`!pRUT}4+P-wWv9IF5*DFTh`3
zXe{6f=O$zq
zax#>4me)n`jaPnQ2i{`vzztV%aihaoB9l^}_4ZnMip)V<`1JkOctvvIf7bI2o=>?L
zcs%;^-8OTRIgcnz9B`kf%ubS?!1nQuYqrT>seP;HrKK-|y&WaXW2YtDEC3SR>&B9S
zt{Y3m#mr^|UsxGg;WZgFc79Y*O)ZWd|D2SabZ12FF%?lX_y+FTlbXZ{!i|V>Ag``S
zt_tIsVF1J$A((F97KZmUCF(EW(wiX?_&wXy+y#Z_+EHAc?rkn-yDly&Uy&*R8VlY}
zw$13tFZ@8HBOkJUPE^E+#kmW6_*nus#ht(fi7&_F$COKTJ`;xGfn+0{w35L%v?@k=
z8DL0#QA8T)*jP4V+w0LW8`@oTJta0lQl_OMi3;i7Ih5JTQL4X~7%B}5Xr<_lZbM95
z`^RVE3dNsrQK#M1Z8mcePSB%qZK_1SyS#K8^2oYy{k=&sKN}gsL^CDTYPOZO{ru9`
zyu^{XXo?Kze!p#%aZcXLAp|dFk$)h`0+R-=b@WVkorxghv+SOPmP2IguJ3&6uQ+o-
zD!b^F?SUOWN0OCHZ3A`tRcRzToPU~6)J3jT4#GBu!vHhakUcyHc2rY3S=NP3~@eUM^@5E#rZ$Gv%+MZ6#N<=d}c@1)O%OW@q>acrsRP&AIN*Yxnnfz
zg?BmT?Hr&xkp+9Q?9a#>k-HzRs>dkrd&3^)yuTTsU1E<2zBswl?5^lK5BVLhOHc(9
zHu#g~J_d@HY(v!ClVGU601s#o7;V0U)rwO~H-qI86o|AUkbPk!*TCykXb@xN!aOBTy
zrLo%-rxqbw)mRhSF}fer=xn2qGSd1AcJV@M$Ev8@)0-8S(K%^Bkx|;yVNFUwUZo-m
zvZCf?C{Clxh+4L*QIB~rR+MXg92Md3l6@#i71X6kSmnd-r)LpCQbz_dMkZ9PV0w2H
z@=MNJb{HK~1@&lbedV?aX-KnH^{T_Th7EkY_$cGCf_FV0@Eak34@bUdKXr+W^VSSm
zv1rc%Om^4HAR47jtfreb*NXF_?_IvbU1EfwT2L?mi!`idXm%)qVHnH&)Bp~FIy7d$
zb4HIFy{u&L-evfDZT1HyydT&oBJ@fm$u0-!px;jZ+~H^Q9a{XrC@Q$@h#0d$s~m0N
zeWq!uaLf@A(n0zi_l&^Fi7QlFBDXn>E3IBuMq*_<2qu`vR~%p5c-QRNsXb+&RauR2*%75EXW%a65iD)|
z4kfiFKG4us=M13LZV0hut%>43eyfKc`%Jq&&ESdcQ6r20Ar5##v`DWnH163g|MeLB
zOMl_%-qabdKy-;+HJ!p~sfs5r&BC<+bZ!6@KqwuK*3lMQb9qTZy8a{Q9JKjrzvDhV
zWpoQzIIc>|L^-K3TJ&*%_hYIv4>54ptv^{m9TULsOttY8&UylYY(l
z*Yy3l42^j?O4hw*#S|Rytv%-i>tis_u7~{%!Gkp#y5c6P9B+F>2Ywl5ie{YyN&YU;
z;+E4c>({`HqG7tVJ$kqTtuO?2$>Zrsxy?a(*fSv+W3_63HZ}^HS}!BOeWMTcCT>4;e{d
zf5SM}bQbm)p=;Haiysm*DV@5tpnZxs*zfTPb5oVw1zMX(UcRY1gZIupZq`FXr(ycP=hd@z_oq9Z#s9
zWnO4ca?>GxfWb4r2%zp`b&;5OoqB<@Y(}_BLeh==%4VA@-
z?egkOaT7)JNd6SKdpfk=z$?$B6
zK3N&VJ>U=7C|
zNo*AP=&0e>F2s$wG*-u>b->7^zqCl7t5Sw`n&$o67LBnT+?UcIlaQIQS~nX!i|1vm
zV^uTVP+cm7-XX>Bv^6C_MwQcpCp%k!A{Y2+tg^kQ^PQRJDW_59JP!*nC;+fwY`!$c
zlx0tr@jzAOIPDHD%yZhrZt9z*_=35T-@qKk>MPQ%QSP0gV<1m^tR8V#m&)baTcX#I
zte#o2I+hwX?cyfX9xV`@V8LdqKxq2ijPK$Dq9vl*q4tYIPE_oMM%atK2b#Dny~Ayz
z8ul`2dhD`27b--&-eiIUVI9i_qz~`yvfbj7_;cM5trX$ubaTvxlKtORrvDKBN0sVd
z<*NU&y7C|8s-g=g-XBob%$;vyrDjn^vo&$?X`3C8M&8@{bo|x9~TxUIIXVeNoYxwEDbHP9l_=luZm#3!a>E3#$j
zqQmCI;fb%aWmK!bP&?Tc2d{vcul(@7sILBn
zo>Qhnmcc3rQTiNLcH=5JZsIA)AI7IlR`i%_$zb6mF@DH1#WqnKsADtfZanE;m95Zx
zY2rfY+YtIFS~hOIq(GY&D3ygK#PEjv@@Bexps-M|Jrg^BXV8f;|
zeR2&J4$?He^5a=+Un}LbUYW?}r!wd)rnC?mZ0?MZG}f&_&@E1D3FCzR@@j?Z5b9Zhw@3u{x8UKS9J3gogl<7BV3
zWriods2%7W9@5#fY7;j+9BYraH&=8Rkjc!WGz#8Y_g=VxtPAycU~YH?ho4S4;m)gO
z%*3+u#5ZL*TJ#Inw<%tN5c7F1OzN;!;?}*SHxtu+ra0*iC>l=;jlX+`6ET5W!G86~
zKL;5+Tk5qmV{P`njPt^Igyjpd9#0l9I*3a%rnfilAjoW(#j}Nue}0}`t(rN?
zQOP`8L)fbyyjdap*4iTTEA*3^4V?2Q_a%hsX5n8rD_$SCWq;R_#6|XfTPrS<=kewjdCKEYw*JlUCrB$+Y;75eCfj}$}B>T
zwf-_&ElB1PZ}CQV4|~tI2_};O@VW=!8_}116~DeyT(mt-2BcH{iA|gvpn8-O<5zr3
zO(Jf8pV-dNQf1%h6ZUEgOdtffW6q}?bJMrZ>jjcW2v1{mwywvwfQ!D*dq%qt?b;Vt
zU%}~yl}63LdD*I&GgYQzsZ6Dl(oEJdfKO(wGqLA)Mmmobdq1qUio{Fsa4J#Pn$RX1
z8m0UudXzwx&8wqYVn>jyrsuJ(Tp~yN=>-qLH>G1cuS^+6S2RnjNSu;qP*sNg7+g!g
z)jSi!OtumKr3$6mtkP4;aW(F
n9@EDE_x1kqUoJ#pP@x{^0Qzk=0dRl)1SBV=EZOkEH0=KX>i}(>
literal 0
HcmV?d00001
From 95a488f5bd157da542ac25b5d9c25b208673d460 Mon Sep 17 00:00:00 2001
From: Les Cochrane
Date: Wed, 15 Aug 2012 18:00:32 +0100
Subject: [PATCH 016/346] Change variant price fields to handle locale values
properly
Fixes #1856
---
core/app/views/spree/admin/variants/_form.html.erb | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/core/app/views/spree/admin/variants/_form.html.erb b/core/app/views/spree/admin/variants/_form.html.erb
index 6a8bdb0aa3d..f848989e490 100644
--- a/core/app/views/spree/admin/variants/_form.html.erb
+++ b/core/app/views/spree/admin/variants/_form.html.erb
@@ -21,10 +21,10 @@
<%= f.text_field :sku %>
<%= f.label :price, t(:price) %>:
- <%= f.text_field :price, :value => number_with_precision(@variant.price, :precision => 2) %>
+ <%= f.text_field :price, :value => number_to_currency(@variant.price, :unit => '') %>
<%= f.label :cost_price, t(:cost_price) %>:
- <%= f.text_field :cost_price, :value => number_with_precision(@variant.cost_price, :precision => 2) %>
+ <%= f.text_field :cost_price, :value => number_to_currency(@variant.cost_price, :unit => '') %>
<% if Spree::Config[:track_inventory_levels] %>
<%= f.label :on_hand, t(:on_hand) %>:
From 0f6a8ee672c979807fc64d7cec795a051b4c5fad Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Trung=20L=C3=AA?=
Date: Thu, 16 Aug 2012 09:26:27 +1000
Subject: [PATCH 017/346] Refactor Spree::Product#images
---
core/app/models/spree/product.rb | 11 ++++-------
1 file changed, 4 insertions(+), 7 deletions(-)
diff --git a/core/app/models/spree/product.rb b/core/app/models/spree/product.rb
index 4bbfe5d293a..46858f92529 100755
--- a/core/app/models/spree/product.rb
+++ b/core/app/models/spree/product.rb
@@ -33,6 +33,8 @@ class Product < ActiveRecord::Base
:class_name => "Spree::Variant",
:conditions => { :is_master => true }
+ has_many :images, :through => :master
+
delegate_belongs_to :master, :sku, :price, :weight, :height, :width, :depth, :is_master
delegate_belongs_to :master, :cost_price if Variant.table_exists? && Variant.column_names.include?('cost_price')
@@ -61,15 +63,10 @@ class Product < ActiveRecord::Base
accepts_nested_attributes_for :variants, :allow_destroy => true
def variant_images
- Image.joins("LEFT JOIN #{Variant.quoted_table_name} ON #{Variant.quoted_table_name}.id = #{Spree::Asset.quoted_table_name}.viewable_id").
- where("(#{Spree::Asset.quoted_table_name}.viewable_type = ? AND #{Spree::Asset.quoted_table_name}.viewable_id = ?) OR
- (#{Spree::Asset.quoted_table_name}.viewable_type = ? AND #{Spree::Asset.quoted_table_name}.viewable_id = ?)", Variant.name, self.master.id, Product.name, self.id).
- order("#{Spree::Asset.quoted_table_name}.position").
- extend(Spree::Core::RelationSerialization)
+ ActiveSupport::Deprecation.warn("[SPREE] Spree::Product#variant_images will be deprecated in Spree 1.3. Please use Spree::Product#images.")
+ self.images
end
- alias_method :images, :variant_images
-
validates :name, :price, :permalink, :presence => true
attr_accessor :option_values_hash
From 3cb2d45b0c7f725190ebcb39a5d80c9dfe9b4ac5 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Trung=20L=C3=AA?=
Date: Thu, 16 Aug 2012 10:16:14 +1000
Subject: [PATCH 018/346] Remove defunct ProductsHelper#variant_images_hash
---
core/app/helpers/spree/products_helper.rb | 4 ----
1 file changed, 4 deletions(-)
diff --git a/core/app/helpers/spree/products_helper.rb b/core/app/helpers/spree/products_helper.rb
index a2bf7e3c413..f12694059fa 100644
--- a/core/app/helpers/spree/products_helper.rb
+++ b/core/app/helpers/spree/products_helper.rb
@@ -17,10 +17,6 @@ def product_description(product)
raw(product.description.gsub(/(.*?)\r?\n\r?\n/m, '\1
'))
end
- def variant_images_hash(product)
- product.variant_images.inject({}) { |h, img| (h[img.viewable_id] ||= []) << img; h }
- end
-
def line_item_description(variant)
description = variant.product.description
if description.present?
From dbc2d97ca12f1bae32e08fbad14294a48df06f1f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Trung=20L=C3=AA?=
Date: Thu, 16 Aug 2012 10:17:52 +1000
Subject: [PATCH 019/346] Remove defunct Spree::Core::RelationSerialization
module
---
core/lib/spree/core/relation_serialization.rb | 9 ---------
1 file changed, 9 deletions(-)
delete mode 100644 core/lib/spree/core/relation_serialization.rb
diff --git a/core/lib/spree/core/relation_serialization.rb b/core/lib/spree/core/relation_serialization.rb
deleted file mode 100644
index d6ade62254f..00000000000
--- a/core/lib/spree/core/relation_serialization.rb
+++ /dev/null
@@ -1,9 +0,0 @@
-module Spree
- module Core
- module RelationSerialization
- def serializable_hash(options = nil)
- self.map { |a| a.serializable_hash(options) }
- end
- end
- end
-end
\ No newline at end of file
From c0b51245882f7766a853525b31c4d52c7abb11c1 Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Thu, 16 Aug 2012 10:30:55 +1000
Subject: [PATCH 020/346] Order images by position
---
core/app/models/spree/product.rb | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/core/app/models/spree/product.rb b/core/app/models/spree/product.rb
index 46858f92529..477a4061832 100755
--- a/core/app/models/spree/product.rb
+++ b/core/app/models/spree/product.rb
@@ -33,7 +33,7 @@ class Product < ActiveRecord::Base
:class_name => "Spree::Variant",
:conditions => { :is_master => true }
- has_many :images, :through => :master
+ has_many :images, :through => :master, :order => "position ASC"
delegate_belongs_to :master, :sku, :price, :weight, :height, :width, :depth, :is_master
delegate_belongs_to :master, :cost_price if Variant.table_exists? && Variant.column_names.include?('cost_price')
From d8eefb1442526f9d3c620e20bb5e90cfca46f561 Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Thu, 16 Aug 2012 10:40:08 +1000
Subject: [PATCH 021/346] Run sandbox script with a clean Bundler env so it
doesn't interfere
---
Rakefile | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/Rakefile b/Rakefile
index 5e1df6ac5a7..8ca3d1053f5 100644
--- a/Rakefile
+++ b/Rakefile
@@ -87,5 +87,7 @@ end
desc "Creates a sandbox application for simulating the Spree code in a deployed Rails app"
task :sandbox do
- exec("lib/sandbox.sh")
+ Bundler.with_clean_env do
+ exec("lib/sandbox.sh")
+ end
end
From b2445b0ecda68e46a822c2383c805fc80e945c24 Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Thu, 16 Aug 2012 16:23:15 +1000
Subject: [PATCH 022/346] Do not precompile assets during install
This is due to the problem outlined in #1854
---
cmd/lib/spree_cmd/installer.rb | 14 --------------
1 file changed, 14 deletions(-)
diff --git a/cmd/lib/spree_cmd/installer.rb b/cmd/lib/spree_cmd/installer.rb
index f90c48e68ac..b5e642e68da 100644
--- a/cmd/lib/spree_cmd/installer.rb
+++ b/cmd/lib/spree_cmd/installer.rb
@@ -25,9 +25,6 @@ class Installer < Thor::Group
class_option :branch, :type => :string, :desc => 'Spree gem git branch'
class_option :tag, :type => :string, :desc => 'Spree gem git tag'
- class_option :precompile_assets, :type => :boolean, :default => true,
- :desc => 'Precompile spree assets to public/assets'
-
def verify_rails
unless rails_project?
say "#{@app_path} is not a rails project."
@@ -86,8 +83,6 @@ def ask_questions
@load_sample_data = false
end
end
-
- @precompile_assets = options[:precompile_assets] && ask_with_default('Would you like to precompile assets?')
end
def add_gems
@@ -121,15 +116,6 @@ def initialize_spree
end
end
- def precompile_assets
- if @precompile_assets
- say_status :precompiling, 'assets'
- inside @app_path do
- run 'bundle exec rake assets:precompile', :verbose => false
- end
- end
- end
-
private
def gem(name, gem_options={})
From c6c16f6c3b678f5e9ce9eef369447d77f6bd0b68 Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Thu, 16 Aug 2012 16:24:07 +1000
Subject: [PATCH 023/346] Never accept a blank user class option in
config/initializers/spree.rb template
---
.../spree/install/templates/config/initializers/spree.rb | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/core/lib/generators/spree/install/templates/config/initializers/spree.rb b/core/lib/generators/spree/install/templates/config/initializers/spree.rb
index a4867e884ff..c00d49f2faf 100644
--- a/core/lib/generators/spree/install/templates/config/initializers/spree.rb
+++ b/core/lib/generators/spree/install/templates/config/initializers/spree.rb
@@ -11,4 +11,4 @@
# config.site_name = "Spree Demo Site"
end
-Spree.user_class = <%= (options[:user_class] || "Spree::LegacyUser").inspect %>
+Spree.user_class = <%= (options[:user_class].blank? ? "Spree::LegacyUser" : options[:user_class]).inspect %>
From 82139026ab919194cf90f96002b52190e2a9e4f3 Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Fri, 17 Aug 2012 09:33:28 +1000
Subject: [PATCH 024/346] Add linebreaks between gems in sandbox. Also specify
correct --user_class option
---
lib/sandbox.sh | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/lib/sandbox.sh b/lib/sandbox.sh
index b4a79f206e3..c807cb496df 100755
--- a/lib/sandbox.sh
+++ b/lib/sandbox.sh
@@ -3,8 +3,7 @@
rm -rf sandbox
rails new sandbox --skip-bundle
cd sandbox
-echo "gem 'spree', :path => '..'" >> Gemfile
-echo "gem 'spree_auth_devise', :git => 'git://github.com/spree/spree_auth_devise'" >> Gemfile
+echo "gem 'spree', :path => '..'\n" >> Gemfile
+echo "gem 'spree_auth_devise', :git => 'git://github.com/spree/spree_auth_devise'\n" >> Gemfile
bundle install --gemfile Gemfile
-rails g spree:install --auto-accept
-rake assets:precompile
+rails g spree:install --auto-accept --user_class=Spree::User
From 41c2cf6540c033127a061eb09d6a0a60c6a14a9e Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Fri, 17 Aug 2012 10:42:50 +1000
Subject: [PATCH 025/346] Bump Ransack to 0.7.0
---
core/spree_core.gemspec | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/core/spree_core.gemspec b/core/spree_core.gemspec
index 3c7da93c3d5..b24e16f1df7 100644
--- a/core/spree_core.gemspec
+++ b/core/spree_core.gemspec
@@ -29,7 +29,7 @@ Gem::Specification.new do |s|
s.add_dependency 'ffaker', '~> 1.12.0'
s.add_dependency 'paperclip', '~> 2.7'
s.add_dependency 'aws-sdk', '~> 1.3.4'
- s.add_dependency 'ransack', '~> 0.6.0'
+ s.add_dependency 'ransack', '~> 0.7.0'
s.add_dependency 'activemerchant', '= 1.20.4'
s.add_dependency 'rails', '~> 3.2.8'
s.add_dependency 'kaminari', '>= 0.13.0'
From 310080ed05c7f81c5a41d8d41d3bcff8411e738a Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Fri, 17 Aug 2012 11:59:58 +1000
Subject: [PATCH 026/346] Clear cached checkout steps when calling
define_state_machine
---
core/app/models/spree/order/checkout.rb | 1 +
1 file changed, 1 insertion(+)
diff --git a/core/app/models/spree/order/checkout.rb b/core/app/models/spree/order/checkout.rb
index 51d1d00ddb3..b9391879cd0 100644
--- a/core/app/models/spree/order/checkout.rb
+++ b/core/app/models/spree/order/checkout.rb
@@ -18,6 +18,7 @@ def self.checkout_flow(&block)
def self.define_state_machine!
self.checkout_steps = []
+ @checkout_steps = {}
self.next_event_transitions = []
self.previous_states = [:cart]
instance_eval(&checkout_flow)
From 5f58680a0d42f3d2ea1cecb399758b3261f74cfc Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Fri, 17 Aug 2012 12:11:43 +1000
Subject: [PATCH 027/346] Remove useless == check in
CheckoutController#ensure_valid_state
---
core/app/controllers/spree/checkout_controller.rb | 1 -
1 file changed, 1 deletion(-)
diff --git a/core/app/controllers/spree/checkout_controller.rb b/core/app/controllers/spree/checkout_controller.rb
index 471ee2a48e2..395d631a1d6 100644
--- a/core/app/controllers/spree/checkout_controller.rb
+++ b/core/app/controllers/spree/checkout_controller.rb
@@ -41,7 +41,6 @@ def update
def ensure_valid_state
if params[:state] && params[:state] != 'cart' &&
!@order.checkout_steps.include?(params[:state])
- params[:state] == 'cart'
@order.state = 'cart'
redirect_to checkout_path
end
From e56724fa7da9047233f4a71b5a292375dd90b6b4 Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Fri, 17 Aug 2012 12:12:24 +1000
Subject: [PATCH 028/346] Move order email out to checkout/edit
This is because the email field is required for orders, but address may not be a state that is ever shown in the checkout process
---
core/app/views/spree/checkout/_address.html.erb | 6 ------
core/app/views/spree/checkout/edit.html.erb | 6 ++++++
2 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/core/app/views/spree/checkout/_address.html.erb b/core/app/views/spree/checkout/_address.html.erb
index 12192089805..dfd5370e2ff 100644
--- a/core/app/views/spree/checkout/_address.html.erb
+++ b/core/app/views/spree/checkout/_address.html.erb
@@ -1,10 +1,4 @@
-<% unless @order.email? %>
-
- <%= form.label :email %>
- <%= form.text_field :email %>
-
-<% end %>
<%= form.fields_for :bill_address do |bill_form| %>
<%= t(:billing_address) %>
diff --git a/core/app/views/spree/checkout/edit.html.erb b/core/app/views/spree/checkout/edit.html.erb
index ed5339cc0c5..3b6c35b20a6 100644
--- a/core/app/views/spree/checkout/edit.html.erb
+++ b/core/app/views/spree/checkout/edit.html.erb
@@ -12,6 +12,12 @@
<%= form_for @order, :url => update_checkout_path(@order.state), :html => { :id => "checkout_form_#{@order.state}" } do |form| %>
+ <% unless @order.email? %>
+
+ <%= form.label :email %>
+ <%= form.text_field :email %>
+
+ <% end %>
<%= render @order.state, :form => form %>
<% end %>
From ee1e2dc4d48b1b583594936635310098e7ff0682 Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Fri, 17 Aug 2012 12:15:53 +1000
Subject: [PATCH 029/346] Redirect to the first checkout step if an invalid
state is requested in CheckoutController
---
core/app/controllers/spree/checkout_controller.rb | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/core/app/controllers/spree/checkout_controller.rb b/core/app/controllers/spree/checkout_controller.rb
index 395d631a1d6..fa6c7f71784 100644
--- a/core/app/controllers/spree/checkout_controller.rb
+++ b/core/app/controllers/spree/checkout_controller.rb
@@ -39,10 +39,10 @@ def update
private
def ensure_valid_state
- if params[:state] && params[:state] != 'cart' &&
- !@order.checkout_steps.include?(params[:state])
+ if (params[:state] && !@order.checkout_steps.include?(params[:state])) ||
+ (!params[:state] && !@order.checkout_steps.include?(@order.state))
@order.state = 'cart'
- redirect_to checkout_path
+ redirect_to checkout_state_path(@order.checkout_steps.first)
end
end
From d21228568ca6f3d8acf0ca949e8b5a34fd1889ce Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Fri, 17 Aug 2012 12:16:46 +1000
Subject: [PATCH 030/346] Checkout button will now send customer to first order
state, determined by Order#checkout_steps, rather than forcing address state
Fixes #1844
---
core/app/views/spree/orders/edit.html.erb | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/core/app/views/spree/orders/edit.html.erb b/core/app/views/spree/orders/edit.html.erb
index ba057fd8823..615aa8c93fa 100644
--- a/core/app/views/spree/orders/edit.html.erb
+++ b/core/app/views/spree/orders/edit.html.erb
@@ -26,7 +26,7 @@
<%= button_tag :class => 'primary', :id => 'update-button' do %>
<%= t(:update) %>
<% end %>
- <%= link_to t(:checkout), checkout_path, :class => 'button checkout primary', :id => 'checkout-link' %>
+ <%= link_to t(:checkout), checkout_state_path(@order.checkout_steps.first), :class => 'button checkout primary', :id => 'checkout-link' %>
From 2ed6c5d6eed1ed285d19a25fccf03498ba7d2ccf Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Fri, 17 Aug 2012 12:17:06 +1000
Subject: [PATCH 031/346] Don't show address information in order_details
template if order does not have address state
---
.../spree/shared/_order_details.html.erb | 34 ++++++++++---------
1 file changed, 18 insertions(+), 16 deletions(-)
diff --git a/core/app/views/spree/shared/_order_details.html.erb b/core/app/views/spree/shared/_order_details.html.erb
index 8f870a52459..8d6255d9785 100644
--- a/core/app/views/spree/shared/_order_details.html.erb
+++ b/core/app/views/spree/shared/_order_details.html.erb
@@ -1,26 +1,28 @@
-
-
<%= t(:shipping_address) %> <%= link_to "(#{t(:edit)})", checkout_state_path(:address) unless @order.completed? %>
-
- <%= order.ship_address %>
+ <% if order.has_step?("address") %>
+
+
<%= t(:shipping_address) %> <%= link_to "(#{t(:edit)})", checkout_state_path(:address) unless @order.completed? %>
+
+ <%= order.ship_address %>
+
-
-
-
<%= t(:billing_address) %> <%= link_to "(#{t(:edit)})", checkout_state_path(:address) unless @order.completed? %>
-
- <%= order.bill_address %>
-
-
-
- <% if @order.has_step?("delivery") %>
-
<%= t(:shipping_method) %> <%= link_to "(#{t(:edit)})", checkout_state_path(:delivery) unless @order.completed? %>
-
- <%= order.shipping_method.name %>
+
<%= t(:billing_address) %> <%= link_to "(#{t(:edit)})", checkout_state_path(:address) unless @order.completed? %>
+
+ <%= order.bill_address %>
+
+ <% if @order.has_step?("delivery") %>
+
+
<%= t(:shipping_method) %> <%= link_to "(#{t(:edit)})", checkout_state_path(:delivery) unless @order.completed? %>
+
+ <%= order.shipping_method.name %>
+
+
+ <% end %>
<% end %>
From ab6c9bba75349b9fd613b6ae295eaa55253baf83 Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Fri, 17 Aug 2012 12:17:16 +1000
Subject: [PATCH 032/346] Do not force address state in /checkout route
Related to #1844
---
core/config/routes.rb | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/core/config/routes.rb b/core/config/routes.rb
index 2f88478eef9..98ee165f5aa 100755
--- a/core/config/routes.rb
+++ b/core/config/routes.rb
@@ -13,7 +13,7 @@
# non-restful checkout stuff
put '/checkout/update/:state', :to => 'checkout#update', :as => :update_checkout
get '/checkout/:state', :to => 'checkout#edit', :as => :checkout_state
- get '/checkout', :to => 'checkout#edit', :state => 'address', :as => :checkout
+ get '/checkout', :to => 'checkout#edit' , :as => :checkout
resources :orders do
post :populate, :on => :collection
From 2131ab8739204e58c8e61ea667b4d83fc1d004cf Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Fri, 17 Aug 2012 13:39:01 +1000
Subject: [PATCH 033/346] @checkout_steps needs to be an OrderedHash to have
deterministic ordering across different versions of Ruby
---
core/app/models/spree/order/checkout.rb | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/core/app/models/spree/order/checkout.rb b/core/app/models/spree/order/checkout.rb
index b9391879cd0..ef473096166 100644
--- a/core/app/models/spree/order/checkout.rb
+++ b/core/app/models/spree/order/checkout.rb
@@ -18,7 +18,7 @@ def self.checkout_flow(&block)
def self.define_state_machine!
self.checkout_steps = []
- @checkout_steps = {}
+ @checkout_steps = ActiveSupport::OrderedHash.new
self.next_event_transitions = []
self.previous_states = [:cart]
instance_eval(&checkout_flow)
From 1310e05171bee743ff673414265cb26bace1cbf7 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Trung=20L=C3=AA?=
Date: Fri, 17 Aug 2012 21:27:26 +1000
Subject: [PATCH 034/346] Move Spree::Product#ensure_master to private group
---
core/app/models/spree/product.rb | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/core/app/models/spree/product.rb b/core/app/models/spree/product.rb
index 477a4061832..0c9722c9c7d 100755
--- a/core/app/models/spree/product.rb
+++ b/core/app/models/spree/product.rb
@@ -88,11 +88,6 @@ def variant_images
after_initialize :ensure_master
- def ensure_master
- return unless new_record?
- self.master ||= Variant.new
- end
-
def to_param
permalink.present? ? permalink : (permalink_was || name.to_s.to_url)
end
@@ -257,6 +252,11 @@ def set_master_variant_defaults
def save_master
master.save if master && (master.changed? || master.new_record?)
end
+
+ def ensure_master
+ return unless new_record?
+ self.master ||= Variant.new
+ end
end
end
From 169a4badbbe9a014f0b0abb3cb8159c64f26f676 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Trung=20L=C3=AA?=
Date: Fri, 17 Aug 2012 21:28:46 +1000
Subject: [PATCH 035/346] Introduce new API for retrieving images of product:
Spree::Product#master_images and #images returns images of master variants
Spree::Product#variant_images returns images of all variants including master
---
core/app/models/spree/product.rb | 11 ++++-------
1 file changed, 4 insertions(+), 7 deletions(-)
diff --git a/core/app/models/spree/product.rb b/core/app/models/spree/product.rb
index 0c9722c9c7d..6fc88ddc306 100755
--- a/core/app/models/spree/product.rb
+++ b/core/app/models/spree/product.rb
@@ -33,8 +33,6 @@ class Product < ActiveRecord::Base
:class_name => "Spree::Variant",
:conditions => { :is_master => true }
- has_many :images, :through => :master, :order => "position ASC"
-
delegate_belongs_to :master, :sku, :price, :weight, :height, :width, :depth, :is_master
delegate_belongs_to :master, :cost_price if Variant.table_exists? && Variant.column_names.include?('cost_price')
@@ -60,12 +58,11 @@ class Product < ActiveRecord::Base
:conditions => { :is_master => true, :deleted_at => nil },
:dependent => :destroy
- accepts_nested_attributes_for :variants, :allow_destroy => true
+ has_many :master_images, :source => :images, :through => :master, :order => :position
+ has_many :variant_images, :source => :images, :through => :variants_including_master, :order => :position
+ alias_method :images, :master_images
- def variant_images
- ActiveSupport::Deprecation.warn("[SPREE] Spree::Product#variant_images will be deprecated in Spree 1.3. Please use Spree::Product#images.")
- self.images
- end
+ accepts_nested_attributes_for :variants, :allow_destroy => true
validates :name, :price, :permalink, :presence => true
From c04aa232837f700ef3a4b401f2e5b4fef915eb61 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Trung=20L=C3=AA?=
Date: Fri, 17 Aug 2012 21:32:46 +1000
Subject: [PATCH 036/346] Refactor Spree::Product
---
core/app/models/spree/product.rb | 30 +++++++++++++++---------------
1 file changed, 15 insertions(+), 15 deletions(-)
diff --git a/core/app/models/spree/product.rb b/core/app/models/spree/product.rb
index 6fc88ddc306..ec016c04d1f 100755
--- a/core/app/models/spree/product.rb
+++ b/core/app/models/spree/product.rb
@@ -30,34 +30,34 @@ class Product < ActiveRecord::Base
belongs_to :shipping_category
has_one :master,
- :class_name => "Spree::Variant",
+ :class_name => 'Spree::Variant',
:conditions => { :is_master => true }
- delegate_belongs_to :master, :sku, :price, :weight, :height, :width, :depth, :is_master
- delegate_belongs_to :master, :cost_price if Variant.table_exists? && Variant.column_names.include?('cost_price')
-
- after_create :set_master_variant_defaults
- 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
-
has_many :variants,
- :class_name => "Spree::Variant",
+ :class_name => 'Spree::Variant',
:conditions => { :is_master => false, :deleted_at => nil },
- :order => 'position ASC'
+ :order => :position
has_many :variants_including_master,
- :class_name => "Spree::Variant",
+ :class_name => 'Spree::Variant',
:conditions => { :deleted_at => nil },
:dependent => :destroy
has_many :variants_with_only_master,
- :class_name => "Spree::Variant",
+ :class_name => 'Spree::Variant',
:conditions => { :is_master => true, :deleted_at => nil },
:dependent => :destroy
+ delegate_belongs_to :master, :sku, :price, :weight, :height, :width, :depth, :is_master
+ delegate_belongs_to :master, :cost_price if Variant.table_exists? && Variant.column_names.include?('cost_price')
+
+ after_create :set_master_variant_defaults
+ 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
+
has_many :master_images, :source => :images, :through => :master, :order => :position
has_many :variant_images, :source => :images, :through => :variants_including_master, :order => :position
alias_method :images, :master_images
From 3bade73d0312bdc4f2f1af7253df83d02161706f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Trung=20L=C3=AA?=
Date: Fri, 17 Aug 2012 21:34:05 +1000
Subject: [PATCH 037/346] Use #any? for Spree::Product#has_variants since
variants returns a Relation
---
core/app/models/spree/product.rb | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/core/app/models/spree/product.rb b/core/app/models/spree/product.rb
index ec016c04d1f..d2d00202de6 100755
--- a/core/app/models/spree/product.rb
+++ b/core/app/models/spree/product.rb
@@ -91,7 +91,7 @@ def to_param
# returns true if the product has any variants (the master variant is not a member of the variants array)
def has_variants?
- variants.exists?
+ variants.any?
end
# returns the number of inventory units "on_hand" for this product
From 1717bf3a75f4daa6654170aaeed46dfca9ce3edc Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Trung=20L=C3=AA?=
Date: Fri, 17 Aug 2012 21:09:00 +1000
Subject: [PATCH 038/346] Bump selenium-webdriver to 2.25.0
---
common_spree_dependencies.rb | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/common_spree_dependencies.rb b/common_spree_dependencies.rb
index 259a631c20c..1e07f07b06a 100644
--- a/common_spree_dependencies.rb
+++ b/common_spree_dependencies.rb
@@ -25,7 +25,7 @@
gem 'ffaker'
gem 'shoulda-matchers', '~> 1.0.0'
gem 'capybara'
- gem 'selenium-webdriver', '2.22.2'
+ gem 'selenium-webdriver', '2.25.0'
gem 'database_cleaner', '0.7.1'
gem 'launchy'
# gem 'debugger'
From 0cf1e2f781c10fe9289e7b13cca9694eb2d32ea3 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Trung=20L=C3=AA?=
Date: Fri, 17 Aug 2012 21:36:49 +1000
Subject: [PATCH 039/346] Cut trailing space
---
core/spec/models/product_spec.rb | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/core/spec/models/product_spec.rb b/core/spec/models/product_spec.rb
index 75f28f483a8..d7abecf8c68 100644
--- a/core/spec/models/product_spec.rb
+++ b/core/spec/models/product_spec.rb
@@ -210,7 +210,7 @@
@product.option_type_ids.should == prototype.option_type_ids
end
- it "should create product option types based on the prototype" do
+ it "should create product option types based on the prototype" do
@product.save
@product.product_option_types.map(&:option_type_id).should == prototype.option_type_ids
end
From 69033b603f90fe1ba73b26dfecda64c91447be17 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Trung=20L=C3=AA?=
Date: Mon, 20 Aug 2012 12:50:04 +1000
Subject: [PATCH 040/346] Convert admin/zone.js to coffeescript
---
core/app/assets/javascripts/admin/zone.js | 29 --------------
.../assets/javascripts/admin/zone.js.coffee | 39 +++++++++++++++++++
2 files changed, 39 insertions(+), 29 deletions(-)
delete mode 100644 core/app/assets/javascripts/admin/zone.js
create mode 100644 core/app/assets/javascripts/admin/zone.js.coffee
diff --git a/core/app/assets/javascripts/admin/zone.js b/core/app/assets/javascripts/admin/zone.js
deleted file mode 100644
index 1249ad586b1..00000000000
--- a/core/app/assets/javascripts/admin/zone.js
+++ /dev/null
@@ -1,29 +0,0 @@
-$(function() {
- if ($('#country_based').is(':checked')) {
- show_country();
- } else {
- show_state();
- }
- $('#country_based').click(function() { show_country();} );
- $('#state_based').click(function() { show_state();} );
-})
-
-var show_country = function() {
- $('#state_members :input').each(function() { $(this).prop("disabled", true); })
- $('#state_members').hide();
- $('#zone_members :input').each(function() { $(this).prop("disabled", true); })
- $('#zone_members').hide();
- $('#country_members :input').each(function() { $(this).prop("disabled", false); })
- $('#country_members').show();
-};
-
-var show_state = function() {
- $('#country_members :input').each(function() { $(this).prop("disabled", true);
- })
- $('#country_members').hide();
- $('#zone_members :input').each(function() { $(this).prop("disabled", true);
- })
- $('#zone_members').hide();
- $('#state_members :input').each(function() { $(this).prop("disabled", false); })
- $('#state_members').show();
-};
diff --git a/core/app/assets/javascripts/admin/zone.js.coffee b/core/app/assets/javascripts/admin/zone.js.coffee
new file mode 100644
index 00000000000..2c70c78828a
--- /dev/null
+++ b/core/app/assets/javascripts/admin/zone.js.coffee
@@ -0,0 +1,39 @@
+$ ->
+ if ($ '#country_based').is(':checked')
+ show_country()
+ else
+ show_state()
+ ($ '#country_based').click ->
+ show_country()
+
+ ($ '#state_based').click ->
+ show_state()
+
+
+show_country = ->
+ ($ '#state_members :input').each ->
+ ($ this).prop 'disabled', true
+
+ ($ '#state_members').hide()
+ ($ '#zone_members :input').each ->
+ ($ this).prop 'disabled', true
+
+ ($ '#zone_members').hide()
+ ($ '#country_members :input').each ->
+ ($ this).prop 'disabled', false
+
+ ($ '#country_members').show()
+
+show_state = ->
+ ($ '#country_members :input').each ->
+ ($ this).prop 'disabled', true
+
+ ($ '#country_members').hide()
+ ($ '#zone_members :input').each ->
+ ($ this).prop 'disabled', true
+
+ ($ '#zone_members').hide()
+ ($ '#state_members :input').each ->
+ ($ this).prop 'disabled', false
+
+ ($ '#state_members').show()
\ No newline at end of file
From 8276906fc0f9dc08dfe7d47c6c539875ceb2dcc0 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Trung=20L=C3=AA?=
Date: Tue, 21 Aug 2012 01:24:35 +1000
Subject: [PATCH 041/346] Convert admin/shipping_method.js to coffeescript
---
.../assets/javascripts/admin/shipping_methods.js | 15 ---------------
.../javascripts/admin/shipping_methods.js.coffee | 10 ++++++++++
2 files changed, 10 insertions(+), 15 deletions(-)
delete mode 100644 core/app/assets/javascripts/admin/shipping_methods.js
create mode 100644 core/app/assets/javascripts/admin/shipping_methods.js.coffee
diff --git a/core/app/assets/javascripts/admin/shipping_methods.js b/core/app/assets/javascripts/admin/shipping_methods.js
deleted file mode 100644
index 75fb201afe7..00000000000
--- a/core/app/assets/javascripts/admin/shipping_methods.js
+++ /dev/null
@@ -1,15 +0,0 @@
-$(document).ready(function() {
- if ($(".categories input:checked").length > 0) {
- $('input[type=checkbox]:not(:checked)').attr('disabled', true);
- }
-
- categoryCheckboxes = '.categories input[type=checkbox]';
- $(categoryCheckboxes).change(function(){
- if($(this).is(':checked')) {
- $(categoryCheckboxes + ':not(:checked)').attr('disabled', true);
- $(this).removeAttr('disabled');
- } else {
- $('input[type=checkbox]').removeAttr('disabled');
- }
- });
-});
diff --git a/core/app/assets/javascripts/admin/shipping_methods.js.coffee b/core/app/assets/javascripts/admin/shipping_methods.js.coffee
new file mode 100644
index 00000000000..c6b63332087
--- /dev/null
+++ b/core/app/assets/javascripts/admin/shipping_methods.js.coffee
@@ -0,0 +1,10 @@
+$ ->
+ ($ 'input[type=checkbox]:not(:checked)').attr 'disabled', true if ($ '.categories input:checked').length > 0
+ categoryCheckboxes = '.categories input[type=checkbox]'
+ $(categoryCheckboxes).change ->
+ if ($ this).is(':checked')
+ ($ categoryCheckboxes + ':not(:checked)').attr 'disabled', true
+ ($ this).removeAttr 'disabled'
+ else
+ ($ 'input[type=checkbox]').removeAttr 'disabled'
+
From 482242c2baa5d8bc5116c3f648210b3446080bda Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Trung=20L=C3=AA?=
Date: Tue, 21 Aug 2012 01:24:58 +1000
Subject: [PATCH 042/346] Refactor JS
---
core/app/assets/javascripts/store/cart.js.coffee | 9 ++++-----
core/app/assets/javascripts/store/product.js.coffee | 3 +--
2 files changed, 5 insertions(+), 7 deletions(-)
diff --git a/core/app/assets/javascripts/store/cart.js.coffee b/core/app/assets/javascripts/store/cart.js.coffee
index ba6aef320ba..242a51fa153 100644
--- a/core/app/assets/javascripts/store/cart.js.coffee
+++ b/core/app/assets/javascripts/store/cart.js.coffee
@@ -1,7 +1,6 @@
$ ->
if ($ 'form#update-cart').is('*')
- ($ 'form#update-cart a.delete').show().on 'click', (e) ->
- $(this).parents('.line-item').first().find('input.line_item_quantity').val 0
- $(this).parents('form').first().submit()
- e.preventDefault()
- return
\ No newline at end of file
+ ($ 'form#update-cart a.delete').show().on 'click' ->
+ ($ this).parents('.line-item').first().find('input.line_item_quantity').val 0
+ ($ this).parents('form').first().submit()
+ false
\ No newline at end of file
diff --git a/core/app/assets/javascripts/store/product.js.coffee b/core/app/assets/javascripts/store/product.js.coffee
index 6b60e5cb6c1..1960888a949 100644
--- a/core/app/assets/javascripts/store/product.js.coffee
+++ b/core/app/assets/javascripts/store/product.js.coffee
@@ -7,7 +7,6 @@ add_image_handlers = ->
($ this).mouseout ->
($ 'ul.thumbnails li').removeClass 'selected'
($ event.currentTarget).parent('li').addClass 'selected'
-
false
($ 'ul.thumbnails li').on 'mouseenter', (event) ->
@@ -31,6 +30,6 @@ show_variant_images = (variant_id) ->
$ ->
add_image_handlers()
- show_variant_images ($ '#product-variants input[type="radio"]').eq(0).attr('value') if ($ '#product-variants input[type=radio]').length > 0
+ show_variant_images ($ '#product-variants input[type="radio"]').eq(0).attr('value') if ($ '#product-variants input[type="radio"]').length > 0
($ '#product-variants input[type="radio"]').click (event) ->
show_variant_images @value
\ No newline at end of file
From eec54c9d1ac88baec395834b9b5cc508cc1781db Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Mon, 20 Aug 2012 11:38:49 +0400
Subject: [PATCH 043/346] When calling checkout_flow, call
define_state_machine! also
This means that calling define_state_machine! after calling checkout_flow is no longer necessary
---
core/app/models/spree/order/checkout.rb | 1 +
core/lib/spree/core/engine.rb | 1 -
2 files changed, 1 insertion(+), 1 deletion(-)
diff --git a/core/app/models/spree/order/checkout.rb b/core/app/models/spree/order/checkout.rb
index ef473096166..551cc9cf779 100644
--- a/core/app/models/spree/order/checkout.rb
+++ b/core/app/models/spree/order/checkout.rb
@@ -11,6 +11,7 @@ def self.included(klass)
def self.checkout_flow(&block)
if block_given?
@checkout_flow = block
+ define_state_machine!
else
@checkout_flow
end
diff --git a/core/lib/spree/core/engine.rb b/core/lib/spree/core/engine.rb
index 09014497a00..e9b2589e044 100644
--- a/core/lib/spree/core/engine.rb
+++ b/core/lib/spree/core/engine.rb
@@ -10,7 +10,6 @@ class Engine < ::Rails::Engine
config.autoload_paths += %W(#{config.root}/lib)
def self.activate
- Spree::Order.define_state_machine!
end
config.to_prepare &method(:activate).to_proc
From c768988193a11f0aea5417d173b7f43d666ce27a Mon Sep 17 00:00:00 2001
From: Mark Johnson
Date: Mon, 20 Aug 2012 17:29:18 -0400
Subject: [PATCH 044/346] Fixed a problem with the
image_settings_controller_spec setting the storage type for Image which
breaks the product_spec [Fixes #1864]
Fixes #1865
---
.../spree/admin/image_settings_controller_spec.rb | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/core/spec/controllers/spree/admin/image_settings_controller_spec.rb b/core/spec/controllers/spree/admin/image_settings_controller_spec.rb
index 96f41a769fc..bb1e28ea5db 100644
--- a/core/spec/controllers/spree/admin/image_settings_controller_spec.rb
+++ b/core/spec/controllers/spree/admin/image_settings_controller_spec.rb
@@ -29,6 +29,10 @@
end
context "amazon s3" do
+ after(:all) do
+ Spree::Image.attachment_definitions[:attachment].delete :storage
+ end
+
it "should be able to update s3 settings" do
spree_put :update, { :preferences => {
"use_s3" => "1",
@@ -42,16 +46,16 @@
Spree::Config[:s3_secret].should == "a_secret"
Spree::Config[:s3_bucket].should == "some_bucket"
end
-
+
context "headers" do
before(:each) { Spree::Config[:use_s3] = true }
-
+
it "should be able to update the s3 headers" do
spree_put :update, { :preferences => { "use_s3" => "1" }, "s3_headers" => { "Cache-Control" => "max-age=1111" } }
headers = ActiveSupport::JSON.decode(Spree::Config[:s3_headers])
headers["Cache-Control"].should == "max-age=1111"
end
-
+
it "should be able to add a new header" do
spree_put :update, { "s3_headers" => { }, "new_s3_headers" => { "1" => { "name" => "Charset", "value" => "utf-8" } } }
headers = ActiveSupport::JSON.decode(Spree::Config[:s3_headers])
From ae6cd3b75da0164657017c0174573ce8c4a18f6f Mon Sep 17 00:00:00 2001
From: Laurens Nienhaus
Date: Fri, 10 Aug 2012 17:03:00 +0200
Subject: [PATCH 045/346] Check for empty keywords moved to implementation of
get_products_conditions_for
Fixes #1846
---
core/lib/spree/core/search/base.rb | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/core/lib/spree/core/search/base.rb b/core/lib/spree/core/search/base.rb
index 6cbfffa6002..19f09b1d694 100644
--- a/core/lib/spree/core/search/base.rb
+++ b/core/lib/spree/core/search/base.rb
@@ -28,7 +28,7 @@ def method_missing(name)
def get_base_scope
base_scope = Spree::Product.active
base_scope = base_scope.in_taxon(taxon) unless taxon.blank?
- base_scope = get_products_conditions_for(base_scope, keywords) unless keywords.blank?
+ base_scope = get_products_conditions_for(base_scope, keywords)
base_scope = base_scope.on_hand unless Spree::Config[:show_zero_stock_products]
base_scope = add_search_scopes(base_scope)
base_scope
@@ -48,7 +48,10 @@ def add_search_scopes(base_scope)
# method should return new scope based on base_scope
def get_products_conditions_for(base_scope, query)
- base_scope.like_any([:name, :description], query.split)
+ unless query.blank?
+ base_scope = base_scope.like_any([:name, :description], query.split)
+ end
+ base_scope
end
def prepare(params)
From 387f85b991781eb08b952771ecb9262be35fd299 Mon Sep 17 00:00:00 2001
From: Diego Fernandez Fernandez
Date: Fri, 17 Aug 2012 14:19:10 +0200
Subject: [PATCH 046/346] Updating a prototype should allow to empty its
properties.
Fixes #1859
---
.../spree/admin/prototypes_controller.rb | 4 +--
.../admin/products/prototypes_spec.rb | 31 +++++++++++++++++++
2 files changed, 33 insertions(+), 2 deletions(-)
diff --git a/core/app/controllers/spree/admin/prototypes_controller.rb b/core/app/controllers/spree/admin/prototypes_controller.rb
index 8bb14102235..95aa6343916 100644
--- a/core/app/controllers/spree/admin/prototypes_controller.rb
+++ b/core/app/controllers/spree/admin/prototypes_controller.rb
@@ -29,8 +29,8 @@ def select
private
def set_habtm_associations
- @prototype.property_ids = params[:property][:id] if params[:property]
- @prototype.option_type_ids = params[:option_type][:id] if params[:option_type]
+ @prototype.property_ids = params[:option_type].blank? ? [] : params[:property][:id]
+ @prototype.option_type_ids = params[:option_type].blank? ? [] : params[:option_type][:id]
end
end
end
diff --git a/core/spec/requests/admin/products/prototypes_spec.rb b/core/spec/requests/admin/products/prototypes_spec.rb
index a977784c50f..da513125a0e 100644
--- a/core/spec/requests/admin/products/prototypes_spec.rb
+++ b/core/spec/requests/admin/products/prototypes_spec.rb
@@ -59,4 +59,35 @@
page.should have_content("Shirt 99")
end
end
+
+ context "editing a prototype" do
+ it "should allow to empty its properties" do
+ create(:property, :name => "model", :presentation => "Model")
+ create(:property, :name => "brand", :presentation => "Brand")
+
+ shirt_prototype = create(:prototype, :name => "Shirt", :properties => [])
+ %w( brand model ).each do |prop|
+ shirt_prototype.properties << Spree::Property.find_by_name(prop)
+ end
+
+ visit spree.admin_path
+ click_link "Products"
+ click_link "Prototypes"
+
+ click_on "Edit"
+
+ page.should have_checked_field('brand')
+ page.should have_checked_field('model')
+
+ page.uncheck('brand')
+ page.uncheck('model')
+
+ click_button 'Update'
+
+ click_on "Edit"
+
+ page.should have_unchecked_field('brand')
+ page.should have_unchecked_field('model')
+ end
+ end
end
From 7e3fb15c194b56d01159124944fce309678ad75e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Trung=20L=C3=AA?=
Date: Wed, 22 Aug 2012 09:11:38 +1000
Subject: [PATCH 047/346] Cut whitespaces
---
README.md | 2 +-
common_spree_dependencies.rb | 2 +-
install.rb | 4 +-
sample/db/sample/spree/assets.yml | 90 +++++++++++++++----------------
4 files changed, 49 insertions(+), 49 deletions(-)
diff --git a/README.md b/README.md
index 08ab009d559..58d342524c3 100644
--- a/README.md
+++ b/README.md
@@ -134,7 +134,7 @@ Use Dedicated Spree Devise Authentication
Add the following to your Gemfile
$ gem 'spree_auth_devise', :git => 'git://github.com/spree/spree_auth_devise'
-
+
Then run `bundle install`. Authentication will then work exactly as it did in previous versions of Spree.
If you're installing this in a new Spree 1.2+ application, you'll need to install and run the migrations with
diff --git a/common_spree_dependencies.rb b/common_spree_dependencies.rb
index 1e07f07b06a..cdbb0710cbf 100644
--- a/common_spree_dependencies.rb
+++ b/common_spree_dependencies.rb
@@ -1,4 +1,4 @@
-# By placing all of Spree's shared dependencies in this file and then loading
+# By placing all of Spree's shared dependencies in this file and then loading
# it for each component's Gemfile, we can be sure that we're only testing just
# the one component of Spree.
source 'http://rubygems.org'
diff --git a/install.rb b/install.rb
index 72c64ef5364..3a8ad36260c 100644
--- a/install.rb
+++ b/install.rb
@@ -4,13 +4,13 @@
%w( core api dash promo sample ).each do |framework|
puts "Installing #{framework}..."
-
+
Dir.chdir(framework) do
`gem build spree_#{framework}.gemspec`
`gem install spree_#{framework}-#{version}.gem --no-ri --no-rdoc`
FileUtils.remove "spree_#{framework}-#{version}.gem"
end
-
+
end
puts "Installing Spree..."
diff --git a/sample/db/sample/spree/assets.yml b/sample/db/sample/spree/assets.yml
index 39b957cf69b..9cb29da60b6 100644
--- a/sample/db/sample/spree/assets.yml
+++ b/sample/db/sample/spree/assets.yml
@@ -6,7 +6,7 @@ img_tote:
attachment_file_name: ror_tote.jpeg
attachment_width: 360
attachment_height: 360
- type: Spree::Image
+ type: Spree::Image
position: 1
img_tote_back:
id: 2
@@ -16,7 +16,7 @@ img_tote_back:
attachment_file_name: ror_tote_back.jpeg
attachment_width: 360
attachment_height: 360
- type: Spree::Image
+ type: Spree::Image
position: 2
img_bag:
id: 3
@@ -26,8 +26,8 @@ img_bag:
attachment_file_name: ror_bag.jpeg
attachment_width: 360
attachment_height: 360
- type: Spree::Image
- position: 1
+ type: Spree::Image
+ position: 1
img_baseball:
id: 4
viewable: ror_baseball_jersey_v
@@ -36,7 +36,7 @@ img_baseball:
attachment_file_name: ror_baseball.jpeg
attachment_width: 360
attachment_height: 360
- type: Spree::Image
+ type: Spree::Image
position: 1
img_baseball_back:
id: 5
@@ -46,7 +46,7 @@ img_baseball_back:
attachment_file_name: ror_baseball_back.jpeg
attachment_width: 360
attachment_height: 360
- type: Spree::Image
+ type: Spree::Image
position: 2
img_jr_spaghetti:
id: 6
@@ -56,7 +56,7 @@ img_jr_spaghetti:
attachment_file_name: ror_jr_spaghetti.jpeg
attachment_width: 360
attachment_height: 360
- type: Spree::Image
+ type: Spree::Image
position: 1
img_mug:
id: 7
@@ -66,7 +66,7 @@ img_mug:
attachment_file_name: ror_mug.jpeg
attachment_width: 360
attachment_height: 360
- type: Spree::Image
+ type: Spree::Image
position: 1
img_mug_back:
id: 8
@@ -76,7 +76,7 @@ img_mug_back:
attachment_file_name: ror_mug_back.jpeg
attachment_width: 360
attachment_height: 360
- type: Spree::Image
+ type: Spree::Image
position: 2
img_ringer:
id: 9
@@ -86,7 +86,7 @@ img_ringer:
attachment_file_name: ror_ringer.jpeg
attachment_width: 360
attachment_height: 360
- type: Spree::Image
+ type: Spree::Image
position: 1
img_ringer_back:
id: 10
@@ -96,8 +96,8 @@ img_ringer_back:
attachment_file_name: ror_ringer_back.jpeg
attachment_width: 360
attachment_height: 360
- type: Spree::Image
- position: 2
+ type: Spree::Image
+ position: 2
img_stein:
id: 11
viewable: ror_stein_v
@@ -136,8 +136,8 @@ img_ruby_baseball:
attachment_file_name: ruby_baseball.png
attachment_width: 495
attachment_height: 477
- type: Spree::Image
- position: 1
+ type: Spree::Image
+ position: 1
img_baseball_small_green:
id: 1009
viewable: small-green-baseball
@@ -146,7 +146,7 @@ img_baseball_small_green:
attachment_file_name: ror_baseball_jersey_green.png
attachment_width: 240
attachment_height: 240
- type: Spree::Image
+ type: Spree::Image
position: 1
img_baseball_small_green_back:
id: 1010
@@ -156,7 +156,7 @@ img_baseball_small_green_back:
attachment_file_name: ror_baseball_jersey_back_green.png
attachment_width: 240
attachment_height: 240
- type: Spree::Image
+ type: Spree::Image
position: 2
img_baseball_med_green:
id: 1011
@@ -166,7 +166,7 @@ img_baseball_med_green:
attachment_file_name: ror_baseball_jersey_green.png
attachment_width: 240
attachment_height: 240
- type: Spree::Image
+ type: Spree::Image
position: 1
img_baseball_med_green_back:
id: 1012
@@ -176,8 +176,8 @@ img_baseball_med_green_back:
attachment_file_name: ror_baseball_jersey_back_green.png
attachment_width: 240
attachment_height: 240
- type: Spree::Image
- position: 2
+ type: Spree::Image
+ position: 2
img_baseball_large_green:
id: 1013
viewable: large-green-baseball
@@ -186,7 +186,7 @@ img_baseball_large_green:
attachment_file_name: ror_baseball_jersey_green.png
attachment_width: 240
attachment_height: 240
- type: Spree::Image
+ type: Spree::Image
position: 1
img_baseball_large_green_back:
id: 1014
@@ -196,7 +196,7 @@ img_baseball_large_green_back:
attachment_file_name: ror_baseball_jersey_back_green.png
attachment_width: 240
attachment_height: 240
- type: Spree::Image
+ type: Spree::Image
position: 2
img_baseball_small_blue:
id: 1015
@@ -206,7 +206,7 @@ img_baseball_small_blue:
attachment_file_name: ror_baseball_jersey_blue.png
attachment_width: 240
attachment_height: 240
- type: Spree::Image
+ type: Spree::Image
position: 1
img_baseball_small_blue_back:
id: 1016
@@ -216,7 +216,7 @@ img_baseball_small_blue_back:
attachment_file_name: ror_baseball_jersey_back_blue.png
attachment_width: 240
attachment_height: 240
- type: Spree::Image
+ type: Spree::Image
position: 2
img_baseball_med_blue:
id: 1017
@@ -226,7 +226,7 @@ img_baseball_med_blue:
attachment_file_name: ror_baseball_jersey_blue.png
attachment_width: 240
attachment_height: 240
- type: Spree::Image
+ type: Spree::Image
position: 1
img_baseball_med_blue_back:
id: 1018
@@ -236,7 +236,7 @@ img_baseball_med_blue_back:
attachment_file_name: ror_baseball_jersey_back_blue.png
attachment_width: 240
attachment_height: 240
- type: Spree::Image
+ type: Spree::Image
position: 2
img_baseball_large_blue:
id: 1019
@@ -246,7 +246,7 @@ img_baseball_large_blue:
attachment_file_name: ror_baseball_jersey_blue.png
attachment_width: 240
attachment_height: 240
- type: Spree::Image
+ type: Spree::Image
position: 1
img_baseball_large_blue_back:
id: 1020
@@ -256,7 +256,7 @@ img_baseball_large_blue_back:
attachment_file_name: ror_baseball_jersey_back_blue.png
attachment_width: 240
attachment_height: 240
- type: Spree::Image
+ type: Spree::Image
position: 2
img_baseball_large_red:
id: 1021
@@ -266,7 +266,7 @@ img_baseball_large_red:
attachment_file_name: ror_baseball_jersey_red.png
attachment_width: 240
attachment_height: 240
- type: Spree::Image
+ type: Spree::Image
position: 1
img_baseball_large_red_back:
id: 1022
@@ -276,7 +276,7 @@ img_baseball_large_red_back:
attachment_file_name: ror_baseball_jersey_back_red.png
attachment_width: 240
attachment_height: 240
- type: Spree::Image
+ type: Spree::Image
position: 2
img_baseball_med_red:
id: 1023
@@ -286,7 +286,7 @@ img_baseball_med_red:
attachment_file_name: ror_baseball_jersey_red.png
attachment_width: 240
attachment_height: 240
- type: Spree::Image
+ type: Spree::Image
position: 1
img_baseball_med_red_back:
id: 1024
@@ -296,7 +296,7 @@ img_baseball_med_red_back:
attachment_file_name: ror_baseball_jersey_back_red.png
attachment_width: 240
attachment_height: 240
- type: Spree::Image
+ type: Spree::Image
position: 2
img_baseball_small_red:
id: 1025
@@ -306,7 +306,7 @@ img_baseball_small_red:
attachment_file_name: ror_baseball_jersey_red.png
attachment_width: 240
attachment_height: 240
- type: Spree::Image
+ type: Spree::Image
position: 1
img_baseball_small_red_back:
id: 1026
@@ -316,7 +316,7 @@ img_baseball_small_red_back:
attachment_file_name: ror_baseball_jersey_back_red.png
attachment_width: 240
attachment_height: 240
- type: Spree::Image
+ type: Spree::Image
position: 2
img_spree_bag:
id: 1027
@@ -326,8 +326,8 @@ img_spree_bag:
attachment_file_name: spree_bag.jpeg
attachment_width: 480
attachment_height: 480
- type: Spree::Image
- position: 1
+ type: Spree::Image
+ position: 1
img_spree_tote:
id: 1028
viewable: spree_tote_v
@@ -336,7 +336,7 @@ img_spree_tote:
attachment_file_name: spree_tote_front.jpeg
attachment_width: 480
attachment_height: 480
- type: Spree::Image
+ type: Spree::Image
position: 1
img_tote_back:
id: 1029
@@ -346,7 +346,7 @@ img_tote_back:
attachment_file_name: spree_tote_back.jpeg
attachment_width: 480
attachment_height: 480
- type: Spree::Image
+ type: Spree::Image
position: 2
img_spree_ringer:
id: 1030
@@ -356,7 +356,7 @@ img_spree_ringer:
attachment_file_name: spree_ringer_t.jpeg
attachment_width: 480
attachment_height: 480
- type: Spree::Image
+ type: Spree::Image
position: 1
img_spree_ringer_back:
id: 1031
@@ -366,8 +366,8 @@ img_spree_ringer_back:
attachment_file_name: spree_ringer_t_back.jpeg
attachment_width: 480
attachment_height: 480
- type: Spree::Image
- position: 2
+ type: Spree::Image
+ position: 2
img_spree_jr_spaghetti:
id: 1032
viewable: spree_jr_spaghetti_v
@@ -376,7 +376,7 @@ img_spree_jr_spaghetti:
attachment_file_name: spree_spaghetti.jpeg
attachment_width: 480
attachment_height: 480
- type: Spree::Image
+ type: Spree::Image
position: 1
img_spree_stein:
id: 1033
@@ -406,7 +406,7 @@ img_spree_mug:
attachment_file_name: spree_mug.jpeg
attachment_width: 360
attachment_height: 360
- type: Spree::Image
+ type: Spree::Image
position: 1
img_spree_mug_back:
id: 1036
@@ -416,7 +416,7 @@ img_spree_mug_back:
attachment_file_name: spree_mug_back.jpeg
attachment_width: 480
attachment_height: 480
- type: Spree::Image
+ type: Spree::Image
position: 2
img_spree_baseball:
id: 1037
@@ -426,7 +426,7 @@ img_spree_baseball:
attachment_file_name: spree_jersey.jpeg
attachment_width: 480
attachment_height: 480
- type: Spree::Image
+ type: Spree::Image
position: 1
img_spree_baseball_back:
id: 1038
@@ -436,5 +436,5 @@ img_spree_baseball_back:
attachment_file_name: spree_jersey_back.jpeg
attachment_width: 480
attachment_height: 480
- type: Spree::Image
+ type: Spree::Image
position: 2
From fe757066cffede342018feb42bac7b2bcbf3a56e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Trung=20L=C3=AA?=
Date: Wed, 22 Aug 2012 11:47:03 +1000
Subject: [PATCH 048/346] Refactor Spree::Product#master_images
By delegating #images to master variant, we could avoid the expensive
JOIN of :has_many association
---
core/app/models/spree/product.rb | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/core/app/models/spree/product.rb b/core/app/models/spree/product.rb
index d2d00202de6..254387d5953 100755
--- a/core/app/models/spree/product.rb
+++ b/core/app/models/spree/product.rb
@@ -58,10 +58,11 @@ class Product < ActiveRecord::Base
after_save :save_master
after_save :set_master_on_hand_to_zero_when_product_has_variants
- has_many :master_images, :source => :images, :through => :master, :order => :position
- has_many :variant_images, :source => :images, :through => :variants_including_master, :order => :position
+ delegate :images, :to => :master, :prefix => true
alias_method :images, :master_images
+ has_many :variant_images, :source => :images, :through => :variants_including_master, :order => :position
+
accepts_nested_attributes_for :variants, :allow_destroy => true
validates :name, :price, :permalink, :presence => true
From 312a475cc63ff86ba14ae59a5cef9ecc40e50051 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Trung=20L=C3=AA?=
Date: Wed, 22 Aug 2012 12:06:39 +1000
Subject: [PATCH 049/346] Minor tweak for README
---
README.md | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/README.md b/README.md
index 58d342524c3..732eebcccaf 100644
--- a/README.md
+++ b/README.md
@@ -100,21 +100,21 @@ The source code is essentially a collection of gems. Spree is meant to be run w
1. Clone the Git repo
- git clone git://github.com/spree/spree.git
- cd spree
+ $ git clone git://github.com/spree/spree.git
+ $ cd spree
2. Install the gem dependencies
- bundle install
+ $ bundle install
3. Create a sandbox Rails application for testing purposes (and automatically perform all necessary database setup)
- bundle exec rake sandbox
+ $ bundle exec rake sandbox
4. Start the server
- cd sandbox
- rails server
+ $ cd sandbox
+ $ rails server
Performance
-----------
From b58008a530f046a5d38cc9ef6b1225137098443d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Trung=20L=C3=AA?=
Date: Wed, 22 Aug 2012 12:18:18 +1000
Subject: [PATCH 050/346] Fix cart.js. Thanks @markj9 for pointing it out
---
core/app/assets/javascripts/store/cart.js.coffee | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/core/app/assets/javascripts/store/cart.js.coffee b/core/app/assets/javascripts/store/cart.js.coffee
index 242a51fa153..185d7341fd9 100644
--- a/core/app/assets/javascripts/store/cart.js.coffee
+++ b/core/app/assets/javascripts/store/cart.js.coffee
@@ -1,6 +1,6 @@
$ ->
if ($ 'form#update-cart').is('*')
- ($ 'form#update-cart a.delete').show().on 'click' ->
+ ($ 'form#update-cart a.delete').show().on 'click', ->
($ this).parents('.line-item').first().find('input.line_item_quantity').val 0
($ this).parents('form').first().submit()
false
\ No newline at end of file
From bb256002d3730e2639d237048a979d6155b6c03f Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Wed, 22 Aug 2012 11:14:53 +0100
Subject: [PATCH 051/346] Set content_type during an API request
Fixes #1866
---
api/app/controllers/spree/api/v1/base_controller.rb | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/api/app/controllers/spree/api/v1/base_controller.rb b/api/app/controllers/spree/api/v1/base_controller.rb
index 4881d401cbb..9a237b5b133 100644
--- a/api/app/controllers/spree/api/v1/base_controller.rb
+++ b/api/app/controllers/spree/api/v1/base_controller.rb
@@ -6,6 +6,7 @@ class BaseController < ActionController::Metal
attr_accessor :current_api_user
+ before_filter :set_content_type
before_filter :check_for_api_key
before_filter :authenticate_user
@@ -25,6 +26,16 @@ def map_nested_attributes_keys(klass, attributes)
private
+ def set_content_type
+ content_type = case params[:format]
+ when "json"
+ "application/json"
+ when "xml"
+ "text/xml"
+ end
+ headers["Content-Type"] = content_type
+ end
+
def check_for_api_key
render "spree/api/v1/errors/must_specify_api_key", :status => 401 and return if api_key.blank?
end
From bf3aa55b0c0225725a3d0afe13afc10d09cc7e05 Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Wed, 22 Aug 2012 12:06:38 +0100
Subject: [PATCH 052/346] Don't depend on spree/core/version for dependency
inside spree_cmd/installer
---
cmd/lib/spree_cmd/installer.rb | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/cmd/lib/spree_cmd/installer.rb b/cmd/lib/spree_cmd/installer.rb
index b5e642e68da..1db07f2a45c 100644
--- a/cmd/lib/spree_cmd/installer.rb
+++ b/cmd/lib/spree_cmd/installer.rb
@@ -54,8 +54,8 @@ def prepare_options
elsif options[:version]
@spree_gem_options[:version] = options[:version]
else
- require 'spree/core/version'
- @spree_gem_options[:version] = Spree.version
+ version = Gem.loaded_specs['spree_cmd'].version
+ @spree_gem_options[:version] = version.to_s
end
end
From 8267f348d62a853f92bc9685c2aa36311e56dcae Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Wed, 22 Aug 2012 12:11:01 +0100
Subject: [PATCH 053/346] Relax dependency on the jquery-rails gem to allow for
latest versions
---
core/spree_core.gemspec | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/core/spree_core.gemspec b/core/spree_core.gemspec
index b24e16f1df7..1963e215eb7 100644
--- a/core/spree_core.gemspec
+++ b/core/spree_core.gemspec
@@ -21,7 +21,7 @@ Gem::Specification.new do |s|
s.add_dependency 'acts_as_list', '= 0.1.4'
s.add_dependency 'nested_set', '= 1.7.0'
- s.add_dependency 'jquery-rails', '~> 2.0.0'
+ s.add_dependency 'jquery-rails', '~> 2.0'
s.add_dependency 'select2-rails', '0.0.9'
s.add_dependency 'highline', '= 1.6.11'
From dbbc31f78d910d553c9ab476eb64babf429ca236 Mon Sep 17 00:00:00 2001
From: Sean Schofield
Date: Wed, 22 Aug 2012 07:12:35 -0400
Subject: [PATCH 054/346] Version bump
---
SPREE_VERSION | 2 +-
cmd/lib/spree_cmd/extension.rb | 2 +-
core/lib/spree/core/version.rb | 2 +-
3 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/SPREE_VERSION b/SPREE_VERSION
index 3a9164e4092..26aaba0e866 100644
--- a/SPREE_VERSION
+++ b/SPREE_VERSION
@@ -1 +1 @@
-1.2.0.rc2
+1.2.0
diff --git a/cmd/lib/spree_cmd/extension.rb b/cmd/lib/spree_cmd/extension.rb
index fdaaee1d7bd..6ca9f901b44 100644
--- a/cmd/lib/spree_cmd/extension.rb
+++ b/cmd/lib/spree_cmd/extension.rb
@@ -51,7 +51,7 @@ def class_name
end
def spree_version
- '1.2.0.rc2'
+ '1.2.0'
end
def use_prefix(prefix)
diff --git a/core/lib/spree/core/version.rb b/core/lib/spree/core/version.rb
index d5154e87d16..be4a35390b7 100644
--- a/core/lib/spree/core/version.rb
+++ b/core/lib/spree/core/version.rb
@@ -1,5 +1,5 @@
module Spree
def self.version
- "1.2.0.rc2"
+ "1.2.0"
end
end
From b8e5b6c105a27effb0ec2b32f22469c8c2362953 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Trung=20L=C3=AA?=
Date: Wed, 22 Aug 2012 20:58:09 +1000
Subject: [PATCH 055/346] Cut trailing spaces
---
.../spree/admin/image_settings_controller_spec.rb | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/core/spec/controllers/spree/admin/image_settings_controller_spec.rb b/core/spec/controllers/spree/admin/image_settings_controller_spec.rb
index bb1e28ea5db..ab8d6a77dfe 100644
--- a/core/spec/controllers/spree/admin/image_settings_controller_spec.rb
+++ b/core/spec/controllers/spree/admin/image_settings_controller_spec.rb
@@ -32,7 +32,7 @@
after(:all) do
Spree::Image.attachment_definitions[:attachment].delete :storage
end
-
+
it "should be able to update s3 settings" do
spree_put :update, { :preferences => {
"use_s3" => "1",
@@ -46,16 +46,16 @@
Spree::Config[:s3_secret].should == "a_secret"
Spree::Config[:s3_bucket].should == "some_bucket"
end
-
+
context "headers" do
before(:each) { Spree::Config[:use_s3] = true }
-
+
it "should be able to update the s3 headers" do
spree_put :update, { :preferences => { "use_s3" => "1" }, "s3_headers" => { "Cache-Control" => "max-age=1111" } }
headers = ActiveSupport::JSON.decode(Spree::Config[:s3_headers])
headers["Cache-Control"].should == "max-age=1111"
end
-
+
it "should be able to add a new header" do
spree_put :update, { "s3_headers" => { }, "new_s3_headers" => { "1" => { "name" => "Charset", "value" => "utf-8" } } }
headers = ActiveSupport::JSON.decode(Spree::Config[:s3_headers])
From cd7d5082d5db095c713dfafd2b161cd65f390947 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Trung=20L=C3=AA?=
Date: Wed, 22 Aug 2012 20:58:46 +1000
Subject: [PATCH 056/346] Refactor Admin::ImageController
---
.../spree/api/v1/images_controller_spec.rb | 15 ++-------------
.../spree/admin/images_controller.rb | 18 +++++-------------
.../views/spree/admin/images/_form.html.erb | 12 ++++--------
3 files changed, 11 insertions(+), 34 deletions(-)
diff --git a/api/spec/controllers/spree/api/v1/images_controller_spec.rb b/api/spec/controllers/spree/api/v1/images_controller_spec.rb
index fc5da37b2ce..28076b3569c 100644
--- a/api/spec/controllers/spree/api/v1/images_controller_spec.rb
+++ b/api/spec/controllers/spree/api/v1/images_controller_spec.rb
@@ -13,21 +13,10 @@ module Spree
stub_authentication!
end
- it "can upload a new image for a product" do
- lambda do
- api_post :create,
- :image => { :attachment => upload_image("thinking-cat.jpg"),
- :viewable_type => 'Spree::Product',
- :viewable_id => product.id }
- response.status.should == 201
- json_response.should have_attributes(attributes)
- end.should change(Image, :count).by(1)
- end
-
it "can upload a new image for a variant" do
lambda do
api_post :create,
- :image => { :attachment => upload_image("thinking-cat.jpg"),
+ :image => { :attachment => upload_image('thinking-cat.jpg'),
:viewable_type => 'Spree::Variant',
:viewable_id => product.master.to_param }
response.status.should == 201
@@ -36,7 +25,7 @@ module Spree
end
context "working with an existing image" do
- let!(:product_image) { product.master.images.create!(:attachment => image("thinking-cat.jpg")) }
+ let!(:product_image) { product.master.images.create!(:attachment => image('thinking-cat.jpg')) }
it "can update image data" do
product_image.position.should == 1
diff --git a/core/app/controllers/spree/admin/images_controller.rb b/core/app/controllers/spree/admin/images_controller.rb
index 0d08d68b441..01fc66b2c16 100644
--- a/core/app/controllers/spree/admin/images_controller.rb
+++ b/core/app/controllers/spree/admin/images_controller.rb
@@ -19,30 +19,22 @@ def update_positions
private
-
+
def location_after_save
admin_product_images_url(@product)
end
def load_data
- @product = Product.find_by_permalink(params[:product_id])
+ @product = Product.where(:permalink => params[:product_id]).first
@variants = @product.variants.collect do |variant|
[variant.options_text, variant.id]
end
- @variants.insert(0, [I18n.t(:all), 'All'])
+ @variants.insert(0, [I18n.t(:all), @product.master.id])
end
def set_viewable
- if params[:image].has_key? :viewable_id
- if params[:image][:viewable_id] == 'All'
- @image.viewable = @product.master
- else
- @image.viewable_type = 'Spree::Variant'
- @image.viewable_id = params[:image][:viewable_id]
- end
- else
- @image.viewable = @product.master
- end
+ @image.viewable_type = 'Spree::Variant'
+ @image.viewable_id = params[:image][:viewable_id]
end
def destroy_before
diff --git a/core/app/views/spree/admin/images/_form.html.erb b/core/app/views/spree/admin/images/_form.html.erb
index 94c5db6071e..a7d9d84dc5d 100644
--- a/core/app/views/spree/admin/images/_form.html.erb
+++ b/core/app/views/spree/admin/images/_form.html.erb
@@ -3,14 +3,10 @@
<%= t(:filename) %>:
<%= f.file_field :attachment %>
- <% if @product.has_variants? %>
-
- <%= Spree::Variant.model_name.human %>:
- <%= f.select :viewable_id, @variants %>
-
- <% else %>
- <%= hidden_field_tag :product_id, @product.id %>
- <% end %>
+
+ <%= Spree::Variant.model_name.human %>:
+ <%= f.select :viewable_id, @variants %>
+
<%= t(:alt_text) %>:
<%= f.text_area :alt %>
From 5618de740bf2047d6c0628bf1aa88f07667d3642 Mon Sep 17 00:00:00 2001
From: zli
Date: Sun, 19 Aug 2012 06:25:51 -1000
Subject: [PATCH 057/346] Bump ActiveMerchant to version 1.27.0
[Fixes #1861]
---
core/spree_core.gemspec | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/core/spree_core.gemspec b/core/spree_core.gemspec
index 1963e215eb7..8be222fcf6b 100644
--- a/core/spree_core.gemspec
+++ b/core/spree_core.gemspec
@@ -30,7 +30,7 @@ Gem::Specification.new do |s|
s.add_dependency 'paperclip', '~> 2.7'
s.add_dependency 'aws-sdk', '~> 1.3.4'
s.add_dependency 'ransack', '~> 0.7.0'
- s.add_dependency 'activemerchant', '= 1.20.4'
+ s.add_dependency 'activemerchant', '= 1.27.0'
s.add_dependency 'rails', '~> 3.2.8'
s.add_dependency 'kaminari', '>= 0.13.0'
s.add_dependency 'deface', '>= 0.9.0'
From 249d780643577d750e538753541241acf149a87a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Trung=20L=C3=AA?=
Date: Wed, 22 Aug 2012 23:16:46 +1000
Subject: [PATCH 058/346] Replace deprecated ActiveMerchant #type? call
---
core/app/models/spree/credit_card.rb | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/core/app/models/spree/credit_card.rb b/core/app/models/spree/credit_card.rb
index bd850c170f5..431779f09f2 100644
--- a/core/app/models/spree/credit_card.rb
+++ b/core/app/models/spree/credit_card.rb
@@ -30,7 +30,7 @@ class << self
# sets self.cc_type while we still have the card number
def set_card_type
- self.cc_type ||= CardDetector.type?(number)
+ self.cc_type ||= CardDetector.brand?(number)
end
def name?
From bc93ce0160a51bede6dc64f743cf5164cd164149 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Trung=20L=C3=AA?=
Date: Wed, 22 Aug 2012 20:15:56 +1000
Subject: [PATCH 059/346] Introduce Spree::Product#delete that set deleted_at
value instead of deleting the object
---
.../spree/admin/products_controller.rb | 8 ++----
core/app/models/spree/product.rb | 7 ++++++
core/spec/models/product_spec.rb | 25 +++++++++++++++++++
3 files changed, 34 insertions(+), 6 deletions(-)
diff --git a/core/app/controllers/spree/admin/products_controller.rb b/core/app/controllers/spree/admin/products_controller.rb
index fc500601555..d2be9bafc2a 100644
--- a/core/app/controllers/spree/admin/products_controller.rb
+++ b/core/app/controllers/spree/admin/products_controller.rb
@@ -19,13 +19,9 @@ def index
end
end
- # override the destory method to set deleted_at value
- # instead of actually deleting the product.
def destroy
- @product = Product.find_by_permalink!(params[:id])
- @product.update_column(:deleted_at, Time.now)
-
- @product.variants_including_master.update_all(:deleted_at => Time.now)
+ @product = Product.where(:permalink => params[:id]).first!
+ @product.delete
flash.notice = I18n.t('notice_messages.product_deleted')
diff --git a/core/app/models/spree/product.rb b/core/app/models/spree/product.rb
index 254387d5953..3480ba45c3a 100755
--- a/core/app/models/spree/product.rb
+++ b/core/app/models/spree/product.rb
@@ -120,6 +120,13 @@ def tax_category
end
end
+ # override the delete method to set deleted_at value
+ # instead of actually deleting the product.
+ def delete
+ self.update_column(:deleted_at, Time.now)
+ variants_including_master.update_all(:deleted_at => Time.now)
+ end
+
# Adding properties and option types on creation based on a chosen prototype
attr_reader :prototype_id
def prototype_id=(value)
diff --git a/core/spec/models/product_spec.rb b/core/spec/models/product_spec.rb
index d7abecf8c68..47352e04841 100644
--- a/core/spec/models/product_spec.rb
+++ b/core/spec/models/product_spec.rb
@@ -36,6 +36,31 @@
end
end
+ context "product has no variants" do
+ context "#delete" do
+ it "should set deleted_at value" do
+ product.delete
+ product.reload
+ product.deleted_at.should_not be_nil
+ product.master.deleted_at.should_not be_nil
+ end
+ end
+ end
+
+ context "product has variants" do
+ before do
+ create(:variant, :product => product)
+ end
+
+ context "#delete" do
+ it "should set deleted_at value" do
+ product.delete
+ product.deleted_at.should_not be_nil
+ product.variants_including_master.all? { |v| !v.deleted_at.nil? }.should be_true
+ end
+ end
+ end
+
context "#on_hand" do
# Regression test for #898
context 'returns the correct number of products on hand' do
From 8dbadbc82dc154b0e965c5d49c730c03d21aa7a5 Mon Sep 17 00:00:00 2001
From: Andrew Hooker
Date: Thu, 23 Aug 2012 11:47:15 +0100
Subject: [PATCH 060/346] Refactoring state_text method eliminate nested
ternary makes it nice and easy to read
[Fixes #1875]
---
core/app/models/spree/address.rb | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/core/app/models/spree/address.rb b/core/app/models/spree/address.rb
index bc3cad421d0..ad090e80a1c 100644
--- a/core/app/models/spree/address.rb
+++ b/core/app/models/spree/address.rb
@@ -36,7 +36,7 @@ def full_name
end
def state_text
- state.nil? ? state_name : (state.abbr.blank? ? state.name : state.abbr)
+ state.try(:abbr) || state.try(:name) || state_name
end
def same_as?(other)
From 09f1739d0303b6747b2ebe50e5c741fad2f060ee Mon Sep 17 00:00:00 2001
From: Michael Bianco
Date: Fri, 27 Jul 2012 07:58:31 -0400
Subject: [PATCH 061/346] Adding missing GA trackTrans call
[Fixes #1809]
---
.../spree/shared/_google_analytics.html.erb | 31 ++++++++++---------
1 file changed, 16 insertions(+), 15 deletions(-)
diff --git a/core/app/views/spree/shared/_google_analytics.html.erb b/core/app/views/spree/shared/_google_analytics.html.erb
index 5436557f24e..03207eaa50a 100644
--- a/core/app/views/spree/shared/_google_analytics.html.erb
+++ b/core/app/views/spree/shared/_google_analytics.html.erb
@@ -6,27 +6,28 @@
_gaq.push(['_trackPageview']);
<% if flash[:commerce_tracking] %>
- // report e-commerce transaction information when applicable
+ <%# more info: https://developers.google.com/analytics/devguides/collection/gajs/methods/gaJSApiEcommerce %>
_gaq.push(['_addTrans',
- "<%= @order.number %>", // Order Number
- "", // Affiliation
- "<%= @order.total %>", // Order total
- "<%= @order.adjustments.tax.sum(:amount) %>", // Tax Amount
- "<%= @order.adjustments.shipping.sum(:amount) %>", // Ship Amount
- "", // City
- "", // State
- "" // Country
+ "<%= @order.number %>",
+ "",
+ "<%= @order.total %>",
+ "<%= @order.adjustments.tax.sum(:amount) %>",
+ "<%= @order.adjustments.shipping.sum(:amount) %>",
+ "<%= @order.bill_address.city %>",
+ "<%= @order.bill_address.state_text %>",
+ "<%= @order.bill_address.country.name %>"
]);
<% @order.line_items.each do |line_item| %>
_gaq.push(['_addItem',
- "<%= @order.number %>", // order ID - required
- "<%= line_item.variant.sku %>", // SKU/code - required
- "<%= line_item.variant.product.name %>", // product name
- "", // category or variation, Product Category
- "<%= line_item.price %>", // unit price - required
- "<%= line_item.quantity %>" // quantity - required
+ "<%= @order.number %>",
+ "<%= line_item.variant.sku %>",
+ "<%= line_item.variant.product.name %>",
+ "",
+ "<%= line_item.price %>",
+ "<%= line_item.quantity %>"
]);
<% end %>
+ _gaq.push(['_trackTrans']);
<% end %>
(function() {
From 5a3e4a507c7273f31dbccfa46359b31842b1540d Mon Sep 17 00:00:00 2001
From: Michael Bianco
Date: Tue, 21 Aug 2012 14:05:06 -0400
Subject: [PATCH 062/346] Fix for inaccurate shipment confirmation email.
Use Shipment#manifest instead of Shipment#line_items in shipment confirmation email for better representation of what was shipped
[Fixes #1867]
---
core/app/views/spree/shipment_mailer/shipped_email.text.erb | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/core/app/views/spree/shipment_mailer/shipped_email.text.erb b/core/app/views/spree/shipment_mailer/shipped_email.text.erb
index bd6b30f1c62..2fa632ea32c 100644
--- a/core/app/views/spree/shipment_mailer/shipped_email.text.erb
+++ b/core/app/views/spree/shipment_mailer/shipped_email.text.erb
@@ -5,7 +5,7 @@ Your order has been shipped
============================================================
Shipment Summary
============================================================
-<% @shipment.line_items.each do |item| %>
+<% @shipment.manifest.each do |item| %>
<%= item.variant.sku %> <%= item.variant.product.name %> <%= variant_options(item.variant, :include_style => false) %> (<%= item.quantity %>)
<% end %>
============================================================
From 24aa6cc6939bfeb5e31c639ed67f4a3ab2160346 Mon Sep 17 00:00:00 2001
From: soffolk zhu
Date: Fri, 24 Aug 2012 11:21:28 +0800
Subject: [PATCH 063/346] Fix sandbox Gemfile generation
[Fixes #1877]
---
lib/sandbox.sh | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/lib/sandbox.sh b/lib/sandbox.sh
index c807cb496df..7169a4eb573 100755
--- a/lib/sandbox.sh
+++ b/lib/sandbox.sh
@@ -3,7 +3,7 @@
rm -rf sandbox
rails new sandbox --skip-bundle
cd sandbox
-echo "gem 'spree', :path => '..'\n" >> Gemfile
-echo "gem 'spree_auth_devise', :git => 'git://github.com/spree/spree_auth_devise'\n" >> Gemfile
+echo "gem 'spree', :path => '..'" >> Gemfile
+echo "gem 'spree_auth_devise', :git => 'git://github.com/spree/spree_auth_devise'" >> Gemfile
bundle install --gemfile Gemfile
rails g spree:install --auto-accept --user_class=Spree::User
From dff09c2c2d2872857d38a863b64fafd6026008bf Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Trung=20L=C3=AA?=
Date: Fri, 24 Aug 2012 20:46:04 +1000
Subject: [PATCH 064/346] Deprecate Spree::Product#variants_with_only_master
---
core/app/models/spree/product.rb | 14 ++++++++------
core/app/models/spree/product/scopes.rb | 4 ++--
2 files changed, 10 insertions(+), 8 deletions(-)
diff --git a/core/app/models/spree/product.rb b/core/app/models/spree/product.rb
index 3480ba45c3a..e5337c73057 100755
--- a/core/app/models/spree/product.rb
+++ b/core/app/models/spree/product.rb
@@ -31,7 +31,8 @@ class Product < ActiveRecord::Base
has_one :master,
:class_name => 'Spree::Variant',
- :conditions => { :is_master => true }
+ :conditions => { :is_master => true },
+ :dependent => :destroy
has_many :variants,
:class_name => 'Spree::Variant',
@@ -43,11 +44,6 @@ class Product < ActiveRecord::Base
:conditions => { :deleted_at => nil },
:dependent => :destroy
- has_many :variants_with_only_master,
- :class_name => 'Spree::Variant',
- :conditions => { :is_master => true, :deleted_at => nil },
- :dependent => :destroy
-
delegate_belongs_to :master, :sku, :price, :weight, :height, :width, :depth, :is_master
delegate_belongs_to :master, :cost_price if Variant.table_exists? && Variant.column_names.include?('cost_price')
@@ -86,6 +82,12 @@ class Product < ActiveRecord::Base
after_initialize :ensure_master
+ def variants_with_only_master
+ ActiveSupport::Deprecation.warn("[SPREE] Spree::Product#variants_with_only_master will be deprecated in Spree 1.3. Please use Spree::Product#master instead.")
+ master
+ end
+
+
def to_param
permalink.present? ? permalink : (permalink_was || name.to_s.to_url)
end
diff --git a/core/app/models/spree/product/scopes.rb b/core/app/models/spree/product/scopes.rb
index 08b5e907485..6226b7c56a4 100644
--- a/core/app/models/spree/product/scopes.rb
+++ b/core/app/models/spree/product/scopes.rb
@@ -27,11 +27,11 @@ def self.simple_scopes
end
add_search_scope :ascend_by_master_price do
- joins(:variants_with_only_master).order("#{variant_table_name}.price ASC")
+ joins(:master).order("#{variant_table_name}.price ASC")
end
add_search_scope :descend_by_master_price do
- joins(:variants_with_only_master).order("#{variant_table_name}.price DESC")
+ joins(:master).order("#{variant_table_name}.price DESC")
end
add_search_scope :price_between do |low, high|
From b622352e49bd24f1f521e2a7753370814d4c97a7 Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Mon, 27 Aug 2012 15:49:20 +0100
Subject: [PATCH 065/346] Remove unnecessary Command module wrapping from
spree_cmd.rb
Also fix my #derp for when multiple matches (i.e. [a, b], not [a || b])
Fixes #1870
---
cmd/lib/spree_cmd.rb | 28 ++++++++++++----------------
1 file changed, 12 insertions(+), 16 deletions(-)
diff --git a/cmd/lib/spree_cmd.rb b/cmd/lib/spree_cmd.rb
index 96a8c3295e1..21a76ef9cc2 100644
--- a/cmd/lib/spree_cmd.rb
+++ b/cmd/lib/spree_cmd.rb
@@ -1,20 +1,16 @@
require 'thor'
require 'thor/group'
-module SpreeCmd
- class Command
-
- case ARGV.first
- when 'version' || '-v' || '--version'
- puts Gem.loaded_specs['spree_cmd'].version
- when 'extension'
- ARGV.shift
- require 'spree_cmd/extension'
- SpreeCmd::Extension.start
- else
- ARGV.shift
- require 'spree_cmd/installer'
- SpreeCmd::Installer.start
- end
- end
+case ARGV.first
+ when 'version', '-v', '--version'
+ puts "outputting version"
+ puts Gem.loaded_specs['spree_cmd'].version
+ when 'extension'
+ ARGV.shift
+ require 'spree_cmd/extension'
+ SpreeCmd::Extension.start
+ else
+ ARGV.shift
+ require 'spree_cmd/installer'
+ SpreeCmd::Installer.start
end
From d9bae481e5e2cb2cf57b7de44893039418f1c40c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Trung=20L=C3=AA?=
Date: Tue, 28 Aug 2012 12:03:07 +1000
Subject: [PATCH 066/346] Bump activemerchant to 1.28.0
---
core/spree_core.gemspec | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/core/spree_core.gemspec b/core/spree_core.gemspec
index 8be222fcf6b..f42d4a01a64 100644
--- a/core/spree_core.gemspec
+++ b/core/spree_core.gemspec
@@ -30,7 +30,7 @@ Gem::Specification.new do |s|
s.add_dependency 'paperclip', '~> 2.7'
s.add_dependency 'aws-sdk', '~> 1.3.4'
s.add_dependency 'ransack', '~> 0.7.0'
- s.add_dependency 'activemerchant', '= 1.27.0'
+ s.add_dependency 'activemerchant', '= 1.28.0'
s.add_dependency 'rails', '~> 3.2.8'
s.add_dependency 'kaminari', '>= 0.13.0'
s.add_dependency 'deface', '>= 0.9.0'
From 3ffb75edef54c32edd160ea7e2da350628f66fa6 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Trung=20L=C3=AA?=
Date: Tue, 28 Aug 2012 12:26:56 +1000
Subject: [PATCH 067/346] Refactor Spree::InventoryUnit
---
core/app/models/spree/inventory_unit.rb | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/core/app/models/spree/inventory_unit.rb b/core/app/models/spree/inventory_unit.rb
index 8eab2ad4b6c..14b5ba30ca8 100644
--- a/core/app/models/spree/inventory_unit.rb
+++ b/core/app/models/spree/inventory_unit.rb
@@ -107,7 +107,7 @@ def update_order
end
def restock_variant
- variant.on_hand = (variant.on_hand + 1)
+ variant.on_hand += 1
variant.save
end
end
From a189ef2b1f1d80c0811e6d69f95ae1d33ec7f51d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Trung=20L=C3=AA?=
Date: Wed, 29 Aug 2012 00:21:54 +1000
Subject: [PATCH 068/346] Use Persitence.increment for
Spree::InventoryUnit#restock_variant
---
core/app/models/spree/inventory_unit.rb | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/core/app/models/spree/inventory_unit.rb b/core/app/models/spree/inventory_unit.rb
index 14b5ba30ca8..7bcd9cef4ec 100644
--- a/core/app/models/spree/inventory_unit.rb
+++ b/core/app/models/spree/inventory_unit.rb
@@ -107,8 +107,7 @@ def update_order
end
def restock_variant
- variant.on_hand += 1
- variant.save
+ variant.increment(:on_hand)
end
end
end
From b26f369aed1598a54ba72303e6976d38ca328c97 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Trung=20L=C3=AA?=
Date: Wed, 29 Aug 2012 01:08:22 +1000
Subject: [PATCH 069/346] Fix Spree::LineItem#quantity_no_less_than_shipped
[Fixes #1893]
---
core/app/models/spree/line_item.rb | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/core/app/models/spree/line_item.rb b/core/app/models/spree/line_item.rb
index f481f6fdb54..91642862f9e 100644
--- a/core/app/models/spree/line_item.rb
+++ b/core/app/models/spree/line_item.rb
@@ -97,7 +97,7 @@ def stock_availability
end
def quantity_no_less_than_shipped
- already_shipped = order.shipments.reduce(0) { |acc,s| acc + s.inventory_units.count { |i| i.variant == variant } }
+ already_shipped = order.shipments.reduce(0) { |acc,s| acc + s.inventory_units.select { |i| i.variant == variant }.count }
unless quantity >= already_shipped
errors.add(:quantity, I18n.t('validation.cannot_be_less_than_shipped_units'))
end
From 483bcf72b4b7c683b0426aa726fd4e2518c89eb5 Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Tue, 28 Aug 2012 15:31:36 +0100
Subject: [PATCH 070/346] Expressly load spree/order/checkout so that Checkout
class defined in migrations does not conflict
---
core/app/models/spree/order.rb | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/core/app/models/spree/order.rb b/core/app/models/spree/order.rb
index ebb24d4a09e..5a1fb926460 100644
--- a/core/app/models/spree/order.rb
+++ b/core/app/models/spree/order.rb
@@ -1,8 +1,9 @@
require 'spree/core/validators/email'
+require 'spree/order/checkout'
module Spree
class Order < ActiveRecord::Base
- include Checkout
+ include Spree::Order::Checkout
checkout_flow do
go_to_state :address
go_to_state :delivery
From 6735e467bab7a35f1809814fcc01bd9b58677f59 Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Tue, 28 Aug 2012 16:12:10 +0100
Subject: [PATCH 071/346] Revert "Use Persitence.increment for
Spree::InventoryUnit#restock_variant"
This reverts commit be23488c7ae54ed685ec43a5facc4006d2bc2a68.
See this comment for why: https://github.com/spree/spree/commit/f07e55709cfb246aea062b57d36d4150f4f97301#commitcomment-1775846
---
core/app/models/spree/inventory_unit.rb | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/core/app/models/spree/inventory_unit.rb b/core/app/models/spree/inventory_unit.rb
index 7bcd9cef4ec..14b5ba30ca8 100644
--- a/core/app/models/spree/inventory_unit.rb
+++ b/core/app/models/spree/inventory_unit.rb
@@ -107,7 +107,8 @@ def update_order
end
def restock_variant
- variant.increment(:on_hand)
+ variant.on_hand += 1
+ variant.save
end
end
end
From 94d74116d690cd5eef7b7e956a14e068614ff3ac Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Trung=20L=C3=AA?=
Date: Wed, 29 Aug 2012 01:21:28 +1000
Subject: [PATCH 072/346] Optimize
Spree::InventoryUnit#quantity_no_less_than_shipped
---
core/app/models/spree/line_item.rb | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/core/app/models/spree/line_item.rb b/core/app/models/spree/line_item.rb
index 91642862f9e..3dc5ee30154 100644
--- a/core/app/models/spree/line_item.rb
+++ b/core/app/models/spree/line_item.rb
@@ -97,8 +97,7 @@ def stock_availability
end
def quantity_no_less_than_shipped
- already_shipped = order.shipments.reduce(0) { |acc,s| acc + s.inventory_units.select { |i| i.variant == variant }.count }
- unless quantity >= already_shipped
+ already_shipped = order.shipments.reduce(0) { |acc,s| acc + s.inventory_units.where(:variant_id => variant.id).count }
errors.add(:quantity, I18n.t('validation.cannot_be_less_than_shipped_units'))
end
end
From c43dbc8d5bcee856f4328f5a47eb1de860a5ade6 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Trung=20L=C3=AA?=
Date: Wed, 29 Aug 2012 01:24:51 +1000
Subject: [PATCH 073/346] My stupid text editor - re-add missing line
---
core/app/models/spree/line_item.rb | 1 +
1 file changed, 1 insertion(+)
diff --git a/core/app/models/spree/line_item.rb b/core/app/models/spree/line_item.rb
index 3dc5ee30154..97f46fd33e2 100644
--- a/core/app/models/spree/line_item.rb
+++ b/core/app/models/spree/line_item.rb
@@ -98,6 +98,7 @@ def stock_availability
def quantity_no_less_than_shipped
already_shipped = order.shipments.reduce(0) { |acc,s| acc + s.inventory_units.where(:variant_id => variant.id).count }
+ unless quantity >= already_shipped
errors.add(:quantity, I18n.t('validation.cannot_be_less_than_shipped_units'))
end
end
From e1c6f0ef643a2a9972894d3ddb9646a624ccee8d Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Tue, 28 Aug 2012 16:38:58 +0100
Subject: [PATCH 074/346] Re-define state machine before all
state_machine_specs
This is due to it being altered in the checkout_spec which runs before it
---
core/spec/models/order/state_machine_spec.rb | 2 ++
1 file changed, 2 insertions(+)
diff --git a/core/spec/models/order/state_machine_spec.rb b/core/spec/models/order/state_machine_spec.rb
index 3d3f13bbcb6..ff69dcbbfcd 100644
--- a/core/spec/models/order/state_machine_spec.rb
+++ b/core/spec/models/order/state_machine_spec.rb
@@ -3,6 +3,8 @@
describe Spree::Order do
let(:order) { Spree::Order.new }
before do
+ # Ensure state machine has been re-defined correctly
+ Spree::Order.define_state_machine!
# We don't care about this validation here
order.stub(:require_email)
end
From d7f386cf9663e907905d2c7daffa22ccf2cde358 Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Tue, 28 Aug 2012 17:39:37 +0100
Subject: [PATCH 075/346] Revert "Optimize
Spree::InventoryUnit#quantity_no_less_than_shipped"
This reverts commit df0740cdff3bcd824902c116d4dabfb9f9a94a21.
Conflicts:
core/app/models/spree/line_item.rb
---
core/app/models/spree/line_item.rb | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/core/app/models/spree/line_item.rb b/core/app/models/spree/line_item.rb
index 97f46fd33e2..91642862f9e 100644
--- a/core/app/models/spree/line_item.rb
+++ b/core/app/models/spree/line_item.rb
@@ -97,7 +97,7 @@ def stock_availability
end
def quantity_no_less_than_shipped
- already_shipped = order.shipments.reduce(0) { |acc,s| acc + s.inventory_units.where(:variant_id => variant.id).count }
+ already_shipped = order.shipments.reduce(0) { |acc,s| acc + s.inventory_units.select { |i| i.variant == variant }.count }
unless quantity >= already_shipped
errors.add(:quantity, I18n.t('validation.cannot_be_less_than_shipped_units'))
end
From 5506d054bda32872067ec42ef4dca1c2c186738b Mon Sep 17 00:00:00 2001
From: hazg
Date: Sun, 26 Aug 2012 16:25:37 +0400
Subject: [PATCH 076/346] Add "encoding: utf-8" magic comment to *.js.erb
Fixes #1883
---
core/app/assets/javascripts/admin/admin.js.erb | 2 ++
core/app/assets/javascripts/admin/product_autocomplete.js.erb | 2 ++
2 files changed, 4 insertions(+)
diff --git a/core/app/assets/javascripts/admin/admin.js.erb b/core/app/assets/javascripts/admin/admin.js.erb
index d2de82a07fa..a3ea5da45cb 100644
--- a/core/app/assets/javascripts/admin/admin.js.erb
+++ b/core/app/assets/javascripts/admin/admin.js.erb
@@ -1,3 +1,5 @@
+<%# encoding: UTF-8 %>
+
//= require_self
//= require admin/product_autocomplete
//= require select2
diff --git a/core/app/assets/javascripts/admin/product_autocomplete.js.erb b/core/app/assets/javascripts/admin/product_autocomplete.js.erb
index 5fe05e762f4..19b83d5745b 100644
--- a/core/app/assets/javascripts/admin/product_autocomplete.js.erb
+++ b/core/app/assets/javascripts/admin/product_autocomplete.js.erb
@@ -1,3 +1,5 @@
+<%# encoding: UTF-8 %>
+
// Product autocompletion
image_html = function(item){
return " ";
From a45449a07b5a5ffab7124e1e7d4ce868342dd269 Mon Sep 17 00:00:00 2001
From: Clemens Kofler
Date: Sun, 26 Aug 2012 18:24:16 +0200
Subject: [PATCH 077/346] Fix price parsing for localized prices
The existing code for parsing prices (see https://github.com/spree/spree/blob/master/core/app/models/spree/variant.rb#L55-66)
doesn't take into account entries for prices that use a different decimal separator than the full
stop ("."). This is true for almost all European and Latin American locales.
Example:
US: 15.99 = 15 dollars and 99 cents
Other: 15,99 = 15 dollars and 99 cents
If the product/variant edit form shows 15,99 (correct, because it uses `number_to_currency`) and
one presses save, the code linked above throws away the comma and saves it as 1599 and it gets
shown as 1.599,00 when the form is re-rendered (the full stop is the thousands delimiter here).
When one saves again, it gets saved as 1.60 (actually 1.599 but of course rounded).
This commit fixes the issues by taking into account locale settings for the decimal separator and
the thousand delimiter and replacing characters accordingly.
Fixes #1885
---
core/app/models/spree/variant.rb | 22 ++++++++++-------
core/spec/models/variant_spec.rb | 41 ++++++++++++++++++++++++++++++++
2 files changed, 55 insertions(+), 8 deletions(-)
diff --git a/core/app/models/spree/variant.rb b/core/app/models/spree/variant.rb
index aee12b30a3d..795487afcca 100644
--- a/core/app/models/spree/variant.rb
+++ b/core/app/models/spree/variant.rb
@@ -51,18 +51,12 @@ def on_hand=(new_level)
end
end
- # strips all non-price-like characters from the price.
def price=(price)
- if price.present?
- self[:price] = price.to_s.gsub(/[^0-9\.-]/, '').to_f
- end
+ self[:price] = parse_price(price) if price.present?
end
- # and cost_price
def cost_price=(price)
- if price.present?
- self[:cost_price] = price.to_s.gsub(/[^0-9\.-]/, '').to_f
- end
+ self[:cost_price] = parse_price(price) if price.present?
end
# returns number of units currently on backorder for this variant.
@@ -140,6 +134,18 @@ def option_value(opt_name)
private
+ # strips all non-price-like characters from the price, taking into account locale settings
+ def parse_price(price)
+ price = price.to_s
+
+ separator, delimiter = I18n.t([:'number.currency.format.separator', :'number.currency.format.delimiter'])
+ non_price_characters = /[^0-9\-#{separator}]/
+ price.gsub!(non_price_characters, '') # strip everything else first
+ price.gsub!(separator, '.') unless separator == '.' # then replace the locale-specific decimal separator with the standard separator if necessary
+
+ price.to_d
+ end
+
# Ensures a new variant takes the product master price when price is not supplied
def check_price
if price.nil?
diff --git a/core/spec/models/variant_spec.rb b/core/spec/models/variant_spec.rb
index d13e6bb514d..9c1e4bdb5c4 100644
--- a/core/spec/models/variant_spec.rb
+++ b/core/spec/models/variant_spec.rb
@@ -192,4 +192,45 @@
end
end
+
+ context "price parsing" do
+ before(:each) do
+ I18n.locale = I18n.default_locale
+ I18n.backend.store_translations(:de, { :number => { :currency => { :format => { :delimiter => '.', :separator => ',' } } } })
+ end
+
+ context "price=" do
+ context "with decimal point" do
+ it "captures the proper amount for a formatted price" do
+ variant.price = '1,599.99'
+ variant.price.should == 1599.99
+ end
+ end
+
+ context "with decimal comma" do
+ it "captures the proper amount for a formatted price" do
+ I18n.locale = :de
+ variant.price = '1.599,99'
+ variant.price.should == 1599.99
+ end
+ end
+ end
+
+ context "cost_price=" do
+ context "with decimal point" do
+ it "captures the proper amount for a formatted price" do
+ variant.cost_price = '1,599.99'
+ variant.cost_price.should == 1599.99
+ end
+ end
+
+ context "with decimal comma" do
+ it "captures the proper amount for a formatted price" do
+ I18n.locale = :de
+ variant.cost_price = '1.599,99'
+ variant.cost_price.should == 1599.99
+ end
+ end
+ end
+ end
end
From 615fe12ab04f72ead477f6f2bb5bca6d2e7f5c45 Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Wed, 29 Aug 2012 12:20:27 +0100
Subject: [PATCH 078/346] Must reset locale back to default locale after tests
---
core/spec/models/variant_spec.rb | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/core/spec/models/variant_spec.rb b/core/spec/models/variant_spec.rb
index 9c1e4bdb5c4..86791895c76 100644
--- a/core/spec/models/variant_spec.rb
+++ b/core/spec/models/variant_spec.rb
@@ -199,6 +199,10 @@
I18n.backend.store_translations(:de, { :number => { :currency => { :format => { :delimiter => '.', :separator => ',' } } } })
end
+ after do
+ I18n.locale = I18n.default_locale
+ end
+
context "price=" do
context "with decimal point" do
it "captures the proper amount for a formatted price" do
From 1a7e81feaf576b34692baccdc9c5fe922d30cb9d Mon Sep 17 00:00:00 2001
From: Peter Berkenbosch
Date: Wed, 29 Aug 2012 11:38:00 +0200
Subject: [PATCH 079/346] add information about using all gems from git, and
the need to change the Spree.user_class before generating the admin user.
Fixes #1897
---
README.md | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/README.md b/README.md
index 732eebcccaf..5f758b2300f 100644
--- a/README.md
+++ b/README.md
@@ -142,6 +142,14 @@ If you're installing this in a new Spree 1.2+ application, you'll need to instal
$ bundle exec rake spree_auth:install:migrations
$ bundle exec rake db:migrate
+change the following line in `config/initializers/spree.rb`
+```ruby
+Spree.user_class = "Spree::LegacyUser"
+```
+to
+```ruby
+Spree.user_class = "Spree::User"
+```
and then run `bundle exec rake spree_auth:admin:create` in order to set up the admin user for the application.
Running Tests
From 0ce04769a9edcbc8edbe60d21b98ca5f86941b99 Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Wed, 29 Aug 2012 13:02:16 +0100
Subject: [PATCH 080/346] Define state machine before callbacks spec to prevent
invalid state message
---
core/spec/models/order/callbacks_spec.rb | 3 +++
1 file changed, 3 insertions(+)
diff --git a/core/spec/models/order/callbacks_spec.rb b/core/spec/models/order/callbacks_spec.rb
index 2dd39c63865..f7f676a3257 100644
--- a/core/spec/models/order/callbacks_spec.rb
+++ b/core/spec/models/order/callbacks_spec.rb
@@ -2,6 +2,9 @@
describe Spree::Order do
let(:order) { stub_model(Spree::Order) }
+ before do
+ Spree::Order.define_state_machine!
+ end
context "validations" do
context "email validation" do
From 6987bd3ce80530474002adc3f2166b6ba4020e55 Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Wed, 29 Aug 2012 14:33:59 +0100
Subject: [PATCH 081/346] Revert "Add "encoding: utf-8" magic comment to
*.js.erb"
This reverts commit 00c04c4232904fe5341e92142ba55906c655815b.
As per my comment here: https://github.com/spree/spree/pull/1883#issuecomment-8125190
---
core/app/assets/javascripts/admin/admin.js.erb | 2 --
core/app/assets/javascripts/admin/product_autocomplete.js.erb | 2 --
2 files changed, 4 deletions(-)
diff --git a/core/app/assets/javascripts/admin/admin.js.erb b/core/app/assets/javascripts/admin/admin.js.erb
index a3ea5da45cb..d2de82a07fa 100644
--- a/core/app/assets/javascripts/admin/admin.js.erb
+++ b/core/app/assets/javascripts/admin/admin.js.erb
@@ -1,5 +1,3 @@
-<%# encoding: UTF-8 %>
-
//= require_self
//= require admin/product_autocomplete
//= require select2
diff --git a/core/app/assets/javascripts/admin/product_autocomplete.js.erb b/core/app/assets/javascripts/admin/product_autocomplete.js.erb
index 19b83d5745b..5fe05e762f4 100644
--- a/core/app/assets/javascripts/admin/product_autocomplete.js.erb
+++ b/core/app/assets/javascripts/admin/product_autocomplete.js.erb
@@ -1,5 +1,3 @@
-<%# encoding: UTF-8 %>
-
// Product autocompletion
image_html = function(item){
return " ";
From 7deaad29b7ba170d9b92796f5c476a40e9fa66ae Mon Sep 17 00:00:00 2001
From: "Steve Hoeksema feat. Ryan Bigg"
Date: Mon, 27 Aug 2012 12:30:12 +1200
Subject: [PATCH 082/346] Prevent multiple checkout flow transitions
The issue was that the previous state_machine definition was not correctly being removed, causing the callbacks for states to remain inplace, when really they should be reset every time checkout_flow is defined. There is now a test within spec/models/order/checkout_spec.rb which re-defines the checkout_flow within the Order class and then validates that the next event "branches" don't know anything about the states that shouldn't be there. This should be sufficient for testing that old states are removed.
This commit also fixes a number of other, related problems:
1) Subclasses of the Order class should not effect the parent class's state_machine definition. This was fixed by using class_attribute instead of using cattr_accessor. Really, I (Ryan) should've known better.
2) checkout_steps was being incorrectly defined as an array, when it should be an ActiveSupport::OrderedHash instead
3) Prevented method conflict errors by using StateMachine::Machine.ignore_method_conflicts. This was only needed due to changes from this commit.
---
core/app/models/spree/order/checkout.rb | 26 ++++++++++---
core/spec/models/order/checkout_spec.rb | 50 +++++++++++++++++++++++++
2 files changed, 70 insertions(+), 6 deletions(-)
diff --git a/core/app/models/spree/order/checkout.rb b/core/app/models/spree/order/checkout.rb
index 551cc9cf779..6d87430ccd6 100644
--- a/core/app/models/spree/order/checkout.rb
+++ b/core/app/models/spree/order/checkout.rb
@@ -3,10 +3,10 @@ class Order < ActiveRecord::Base
module Checkout
def self.included(klass)
klass.class_eval do
- cattr_accessor :next_event_transitions
- cattr_accessor :previous_states
- cattr_accessor :checkout_flow
- cattr_accessor :checkout_steps
+ class_attribute :next_event_transitions
+ class_attribute :previous_states
+ class_attribute :checkout_flow
+ class_attribute :checkout_steps
def self.checkout_flow(&block)
if block_given?
@@ -18,13 +18,27 @@ def self.checkout_flow(&block)
end
def self.define_state_machine!
- self.checkout_steps = []
- @checkout_steps = ActiveSupport::OrderedHash.new
+ # Needs to be an ordered hash to preserve flow order
+ self.checkout_steps = ActiveSupport::OrderedHash.new
self.next_event_transitions = []
self.previous_states = [:cart]
+
+ # Build the checkout flow using the checkout_flow defined either
+ # within the Order class, or a decorator for that class.
+ #
+ # This method may be called multiple times depending on if the
+ # checkout_flow is re-defined in a decorator or not.
instance_eval(&checkout_flow)
+
+ # Add complete state as the final state
+ # This removes the need to add it to checkout_flow definitions
klass = self
+ # To avoid a ton of warnings when the state machine is re-defined
+ StateMachine::Machine.ignore_method_conflicts = true
+ # To avoid multiple occurrences of the same transition being defined
+ # On first definition, state_machines will not be defined
+ state_machines.clear if respond_to?(:state_machines)
state_machine :state, :initial => :cart do
klass.next_event_transitions.each { |t| transition(t.merge(:on => :next)) }
diff --git a/core/spec/models/order/checkout_spec.rb b/core/spec/models/order/checkout_spec.rb
index d1a01298f81..d0ee98dca2d 100644
--- a/core/spec/models/order/checkout_spec.rb
+++ b/core/spec/models/order/checkout_spec.rb
@@ -2,6 +2,7 @@
describe Spree::Order do
let(:order) { Spree::Order.new }
+
context "with default state machine" do
it "has the following transitions" do
transitions = [
@@ -132,10 +133,59 @@
end
it "transitions to complete" do
+ order.should_receive(:process_payments!).once
order.next!
order.state.should == "complete"
end
end
end
end
+
+ context "subclassed order" do
+ # This causes another test above to fail, but fixing this test should make
+ # the other test pass
+ class SubclassedOrder < Spree::Order
+ checkout_flow do
+ go_to_state :payment
+ go_to_state :complete
+ end
+ end
+
+ it "should only call default transitions once when checkout_flow is redefined" do
+ order = SubclassedOrder.new
+ order.should_receive(:process_payments!).once
+ order.state = "payment"
+ order.next!
+ order.state.should == "complete"
+ end
+ end
+
+ context "re-define checkout flow" do
+ before do
+ @old_checkout_flow = Spree::Order.checkout_flow
+ Spree::Order.class_eval do
+ checkout_flow do
+ go_to_state :payment
+ go_to_state :complete
+ end
+ end
+ end
+
+ after do
+ Spree::Order.checkout_flow = @old_checkout_flow
+ end
+
+ it "should not keep old event transitions when checkout_flow is redefined" do
+ Spree::Order.next_event_transitions.should == [{:cart=>:payment}, {:payment=>:complete}]
+ end
+
+ it "should not keep old events when checkout_flow is redefined" do
+ state_machine = Spree::Order.state_machine
+ state_machine.states.any? { |s| s.name == :address }.should be_false
+ known_states = state_machine.events[:next].branches.map(&:known_states).flatten
+ known_states.should_not include(:address)
+ known_states.should_not include(:delivery)
+ known_states.should_not include(:confirm)
+ end
+ end
end
From c673901b6cb7867a1a83494e78e3ccb0b392b39e Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Mon, 27 Aug 2012 13:44:10 +0100
Subject: [PATCH 083/346] Remove comment that incorrectly says we add the
complete state in checkout.rb
[ci skip]
---
core/app/models/spree/order/checkout.rb | 2 --
1 file changed, 2 deletions(-)
diff --git a/core/app/models/spree/order/checkout.rb b/core/app/models/spree/order/checkout.rb
index 6d87430ccd6..d9c5845757f 100644
--- a/core/app/models/spree/order/checkout.rb
+++ b/core/app/models/spree/order/checkout.rb
@@ -30,8 +30,6 @@ def self.define_state_machine!
# checkout_flow is re-defined in a decorator or not.
instance_eval(&checkout_flow)
- # Add complete state as the final state
- # This removes the need to add it to checkout_flow definitions
klass = self
# To avoid a ton of warnings when the state machine is re-defined
From f68c2f3796d1fd07235927d054a0801ab1da96c1 Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Tue, 28 Aug 2012 16:23:13 +0100
Subject: [PATCH 084/346] Explain why we need to use fully-qualified name for
Checkout module
---
core/app/models/spree/order.rb | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/core/app/models/spree/order.rb b/core/app/models/spree/order.rb
index 5a1fb926460..191613ed011 100644
--- a/core/app/models/spree/order.rb
+++ b/core/app/models/spree/order.rb
@@ -3,6 +3,14 @@
module Spree
class Order < ActiveRecord::Base
+ # TODO:
+ # Need to use fully qualified name here because during sandbox migration
+ # there is a class called Checkout which conflicts if you use this:
+ #
+ # include Checkout
+ #
+ # rather than the qualified name. This will most likely be fixed with the
+ # 1.3 release.
include Spree::Order::Checkout
checkout_flow do
go_to_state :address
From a51c655723e5b57ecd875fdbba476ada12435bf9 Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Fri, 3 Aug 2012 12:59:07 +0930
Subject: [PATCH 085/346] Stop using number_to_currency everywhere, switch to
Money gem
Merges PR #1829
Conflicts:
core/app/views/spree/admin/general_settings/edit.html.erb
---
.../admin/general_settings_controller.rb | 2 +-
.../spree/admin/general_settings_helper.rb | 13 ++++++++++
core/app/helpers/spree/base_helper.rb | 25 ++++---------------
core/app/helpers/spree/products_helper.rb | 4 +--
core/app/models/spree/adjustment.rb | 4 +++
core/app/models/spree/app_configuration.rb | 2 ++
core/app/models/spree/order.rb | 4 +++
core/app/models/spree/product.rb | 4 +++
core/app/models/spree/shipping_rate.rb | 10 ++++++++
.../adjustments/_adjustments_table.html.erb | 2 +-
.../admin/general_settings/edit.html.erb | 21 +++++++++++-----
.../admin/general_settings/show.html.erb | 6 +++++
.../views/spree/admin/orders/_form.html.erb | 6 ++---
.../spree/admin/orders/_line_item.html.erb | 4 +--
.../views/spree/admin/orders/index.html.erb | 2 +-
.../views/spree/admin/payments/_list.html.erb | 2 +-
.../admin/payments/_transaction_list.html.erb | 24 ------------------
.../views/spree/admin/payments/index.html.erb | 2 +-
.../views/spree/admin/products/index.html.erb | 2 +-
.../spree/admin/reports/sales_total.html.erb | 6 ++---
.../return_authorizations/_form.html.erb | 2 +-
.../return_authorizations/index.html.erb | 2 +-
.../admin/shared/_order_details.html.erb | 12 ++++-----
.../spree/admin/shared/_order_tabs.html.erb | 2 +-
.../spree/admin/shared/_update_order_state.js | 2 +-
.../views/spree/admin/shipments/edit.html.erb | 2 +-
.../spree/admin/shipments/index.html.erb | 2 +-
.../views/spree/admin/variants/index.html.erb | 2 +-
.../views/spree/checkout/_delivery.html.erb | 6 +----
.../views/spree/checkout/_summary.html.erb | 8 +++---
.../spree/order_mailer/cancel_email.text.erb | 8 +++---
.../spree/order_mailer/confirm_email.text.erb | 8 +++---
.../views/spree/orders/_adjustments.html.erb | 2 +-
.../views/spree/orders/_line_item.html.erb | 4 +--
core/app/views/spree/orders/edit.html.erb | 2 +-
.../views/spree/products/_cart_form.html.erb | 2 +-
.../spree/shared/_order_details.html.erb | 12 ++++-----
.../app/views/spree/shared/_products.html.erb | 2 +-
core/config/locales/en.yml | 3 +++
core/lib/spree/core.rb | 1 +
core/lib/spree/money.rb | 16 ++++++++++++
core/lib/spree/product_filters.rb | 7 +++---
core/spec/models/adjustment_spec.rb | 18 +++++++++++++
core/spec/models/order_spec.rb | 20 +++++++++++++++
core/spec/models/product_spec.rb | 20 +++++++++++++++
core/spec/models/shipping_rate_spec.rb | 22 ++++++++++++++++
core/spree_core.gemspec | 1 +
47 files changed, 222 insertions(+), 111 deletions(-)
create mode 100644 core/app/helpers/spree/admin/general_settings_helper.rb
delete mode 100644 core/app/views/spree/admin/payments/_transaction_list.html.erb
create mode 100644 core/lib/spree/money.rb
create mode 100644 core/spec/models/shipping_rate_spec.rb
diff --git a/core/app/controllers/spree/admin/general_settings_controller.rb b/core/app/controllers/spree/admin/general_settings_controller.rb
index 41b90f97b3d..f9d9811baf4 100644
--- a/core/app/controllers/spree/admin/general_settings_controller.rb
+++ b/core/app/controllers/spree/admin/general_settings_controller.rb
@@ -10,7 +10,7 @@ def edit
@preferences = [:site_name, :default_seo_title, :default_meta_keywords,
:default_meta_description, :site_url, :allow_ssl_in_production,
:allow_ssl_in_staging, :allow_ssl_in_development_and_test,
- :check_for_spree_alerts]
+ :check_for_spree_alerts, :display_currency]
end
def update
diff --git a/core/app/helpers/spree/admin/general_settings_helper.rb b/core/app/helpers/spree/admin/general_settings_helper.rb
new file mode 100644
index 00000000000..9277f130e63
--- /dev/null
+++ b/core/app/helpers/spree/admin/general_settings_helper.rb
@@ -0,0 +1,13 @@
+module Spree
+ module Admin
+ module GeneralSettingsHelper
+ def currency_options
+ currencies = ::Money::Currency.table.map do |code, details|
+ iso = details[:iso_code]
+ [iso, "#{details[:name]} (#{iso})"]
+ end
+ options_from_collection_for_select(currencies, :first, :last)
+ end
+ end
+ end
+end
diff --git a/core/app/helpers/spree/base_helper.rb b/core/app/helpers/spree/base_helper.rb
index b6aba6baf76..06cb9bca9d4 100644
--- a/core/app/helpers/spree/base_helper.rb
+++ b/core/app/helpers/spree/base_helper.rb
@@ -22,22 +22,13 @@ def link_to_cart(text = nil)
text = "#{text}: (#{t('empty')})"
css_class = 'empty'
else
- text = "#{text}: (#{current_order.item_count}) #{order_subtotal(current_order)} ".html_safe
+ text = "#{text}: (#{current_order.item_count}) #{current_order.display_total} ".html_safe
css_class = 'full'
end
link_to text, cart_path, :class => css_class
end
- def order_subtotal(order, options={})
- options.assert_valid_keys(:format_as_currency, :show_vat_text)
- options.reverse_merge! :format_as_currency => true, :show_vat_text => true
-
- amount = order.total
-
- options.delete(:format_as_currency) ? number_to_currency(amount) : amount
- end
-
def todays_short_date
utc_to_local(Time.now.utc).to_ordinalized_s(:stub)
end
@@ -151,16 +142,6 @@ def available_countries
end.sort { |a, b| a.name <=> b.name }
end
- def format_price(price, options={})
- options.assert_valid_keys(:show_vat_text)
- formatted_price = number_to_currency price
- if options[:show_vat_text]
- I18n.t(:price_with_vat_included, :price => formatted_price)
- else
- formatted_price
- end
- end
-
# generates nested url to product based on supplied taxon
def seo_url(taxon, product = nil)
return spree.nested_taxons_path(taxon.permalink) if product.nil?
@@ -185,6 +166,10 @@ def gem_available?(name)
Gem.available?(name)
end
+ def money(amount)
+ Spree::Money.new(amount)
+ end
+
def method_missing(method_name, *args, &block)
if image_style = image_style_from_method_name(method_name)
define_image_method(image_style)
diff --git a/core/app/helpers/spree/products_helper.rb b/core/app/helpers/spree/products_helper.rb
index f12694059fa..24b281e9d3c 100644
--- a/core/app/helpers/spree/products_helper.rb
+++ b/core/app/helpers/spree/products_helper.rb
@@ -6,9 +6,9 @@ def variant_price_diff(variant)
diff = variant.price - variant.product.price
return nil if diff == 0
if diff > 0
- "(#{t(:add)}: #{number_to_currency diff.abs})"
+ "(#{t(:add)}: #{Spree::Money.new(diff.abs)})"
else
- "(#{t(:subtract)}: #{number_to_currency diff.abs})"
+ "(#{t(:subtract)}: #{Spree::Money.new(diff.abs)})"
end
end
diff --git a/core/app/models/spree/adjustment.rb b/core/app/models/spree/adjustment.rb
index db4083f09a2..a4d778ba60d 100644
--- a/core/app/models/spree/adjustment.rb
+++ b/core/app/models/spree/adjustment.rb
@@ -65,6 +65,10 @@ def update!(src = nil)
set_eligibility
end
+ def display_amount
+ Spree::Money.new(amount).to_s
+ end
+
private
def update_adjustable
diff --git a/core/app/models/spree/app_configuration.rb b/core/app/models/spree/app_configuration.rb
index bcc8d34be51..8884934f000 100644
--- a/core/app/models/spree/app_configuration.rb
+++ b/core/app/models/spree/app_configuration.rb
@@ -41,6 +41,8 @@ class AppConfiguration < Preferences::Configuration
preference :checkout_zone, :string, :default => nil # replace with the name of a zone if you would like to limit the countries
preference :company, :boolean, :default => false # Request company field for billing and shipping addr
preference :create_inventory_units, :boolean, :default => true # should only be false when track_inventory_levels is false, also disables RMA's
+ preference :currency, :string, :default => "USD"
+ preference :display_currency, :boolean, :default => false
preference :default_country_id, :integer, :default => 214
preference :default_locale, :string, :default => Rails.application.config.i18n.default_locale || :en
preference :default_meta_description, :string, :default => 'Spree demo site'
diff --git a/core/app/models/spree/order.rb b/core/app/models/spree/order.rb
index 191613ed011..f487ca99486 100644
--- a/core/app/models/spree/order.rb
+++ b/core/app/models/spree/order.rb
@@ -107,6 +107,10 @@ def amount
line_items.sum(&:amount)
end
+ def display_total
+ Spree::Money.new(total)
+ end
+
def to_param
number.to_s.to_url.upcase
end
diff --git a/core/app/models/spree/product.rb b/core/app/models/spree/product.rb
index e5337c73057..31c4350335c 100755
--- a/core/app/models/spree/product.rb
+++ b/core/app/models/spree/product.rb
@@ -214,6 +214,10 @@ def set_property(property_name, property_value)
end
end
+ def display_price
+ Spree::Money.new(price).to_s
+ end
+
private
# Builds variants from a hash of option types & values
diff --git a/core/app/models/spree/shipping_rate.rb b/core/app/models/spree/shipping_rate.rb
index aba92108a41..35668556af6 100644
--- a/core/app/models/spree/shipping_rate.rb
+++ b/core/app/models/spree/shipping_rate.rb
@@ -5,5 +5,15 @@ def initialize(attributes = {})
self.send("#{k}=", v)
end
end
+
+ def display_price
+ if Spree::Config[:shipment_inc_vat]
+ price = (1 + Spree::TaxRate.default) * cost
+ else
+ price = cost
+ end
+
+ Spree::Money.new(price)
+ end
end
end
diff --git a/core/app/views/spree/admin/adjustments/_adjustments_table.html.erb b/core/app/views/spree/admin/adjustments/_adjustments_table.html.erb
index 250f8a55ded..efd4257cbcd 100644
--- a/core/app/views/spree/admin/adjustments/_adjustments_table.html.erb
+++ b/core/app/views/spree/admin/adjustments/_adjustments_table.html.erb
@@ -12,7 +12,7 @@
<%= adjustment.created_at.to_s(:date_time24) %>
<%= adjustment.label %>
- <%= number_to_currency adjustment.amount %>
+ <%= adjustment.display_amount %>
<%= link_to_edit adjustment, :class => 'edit' %>
diff --git a/core/app/views/spree/admin/general_settings/edit.html.erb b/core/app/views/spree/admin/general_settings/edit.html.erb
index fdbe3423612..38f803e7dbc 100644
--- a/core/app/views/spree/admin/general_settings/edit.html.erb
+++ b/core/app/views/spree/admin/general_settings/edit.html.erb
@@ -4,15 +4,24 @@
<%= form_tag admin_general_settings_path, :method => :put do %>
- <% @preferences.each do |key|
- type = Spree::Config.preference_type(key) %>
- <%= label_tag(key, t(key) + ': ') + tag(:br) if type != :boolean %>
- <%= preference_field_tag(key, Spree::Config[key], :type => type) %>
- <%= label_tag(key, t(key)) + tag(:br) if type == :boolean %>
- <% end %>
+ <% @preferences.each do |key|
+ type = Spree::Config.preference_type(key) %>
+ <%= label_tag(key, t(key) + ': ') + tag(:br) if type != :boolean %>
+ <%= preference_field_tag(key, Spree::Config[key], :type => type) %>
+ <%= label_tag(key, t(key)) + tag(:br) if type == :boolean %>
+ <% end %>
+
+ <%= label_tag :currency, t(:currency) %>
+ <%= select_tag :currency, currency_options %>
+
+
<%= button t(:update) %>
<%= t(:or) %> <%= link_to t(:cancel), admin_general_settings_url %>
<% end %>
+
+
diff --git a/core/app/views/spree/admin/general_settings/show.html.erb b/core/app/views/spree/admin/general_settings/show.html.erb
index 3ccf279b619..b14d395e2ba 100644
--- a/core/app/views/spree/admin/general_settings/show.html.erb
+++ b/core/app/views/spree/admin/general_settings/show.html.erb
@@ -9,6 +9,12 @@
<%= Spree::Config[key] %>
<% end %>
+
+
+ <%= t(:dollar_amounts_displayed_as, :example => Spree::Money.new(20.99)) %>
+
+
+
<%= Spree::Config[:allow_ssl_in_production] ? t(:ssl_will_be_used_in_production_mode) : t(:ssl_will_not_be_used_in_production_mode) %>
diff --git a/core/app/views/spree/admin/orders/_form.html.erb b/core/app/views/spree/admin/orders/_form.html.erb
index bad7df4cf61..88529f29650 100644
--- a/core/app/views/spree/admin/orders/_form.html.erb
+++ b/core/app/views/spree/admin/orders/_form.html.erb
@@ -21,7 +21,7 @@
<%= t(:subtotal) %>:
- <%= number_to_currency @order.item_total %>
+ <%= money(@order.item_total) %>
@@ -29,7 +29,7 @@
<% @order.adjustments.each do |adjustment| %>
<%= adjustment.label %>
- <%= number_to_currency adjustment.amount %>
+ <%= adjustment.display_amount %>
<% end %>
@@ -37,7 +37,7 @@
<%= t(:order_total) %>:
- <%= number_to_currency @order.total %>
+ <%= @order.display_total %>
diff --git a/core/app/views/spree/admin/orders/_line_item.html.erb b/core/app/views/spree/admin/orders/_line_item.html.erb
index bc1d379ec15..c179fc88d9a 100644
--- a/core/app/views/spree/admin/orders/_line_item.html.erb
+++ b/core/app/views/spree/admin/orders/_line_item.html.erb
@@ -2,9 +2,9 @@
<%=f.object.variant.product.name%> <%= "(#{f.object.variant.options_text}))" unless f.object.variant.option_values.empty? %>
- <%= number_to_currency f.object.price %>
+ <%= money(f.object.price) %>
<%= f.number_field :quantity, :min => 0, :style => "width:30px;", :class => "qty" %>
- <%= number_to_currency (f.object.price * f.object.quantity) %>
+ <%= money(f.object.price * f.object.quantity) %>
<%= link_to_delete f.object, {:url => admin_order_line_item_url(@order.number, f.object) } %>
diff --git a/core/app/views/spree/admin/orders/index.html.erb b/core/app/views/spree/admin/orders/index.html.erb
index 6878a316a61..9371c8bdf14 100644
--- a/core/app/views/spree/admin/orders/index.html.erb
+++ b/core/app/views/spree/admin/orders/index.html.erb
@@ -32,7 +32,7 @@
<%= link_to t("payment_states.#{order.payment_state}"), admin_order_payments_path(order) if order.payment_state %>
<%= link_to t("shipment_states.#{order.shipment_state}"), admin_order_shipments_path(order) if order.shipment_state %>
<%= order.email %>
- <%= number_to_currency order.total %>
+ <%= order.display_total %>
<%= link_to_edit_url edit_admin_order_path(order), :title => "admin_edit_#{dom_id(order)}" %>
diff --git a/core/app/views/spree/admin/payments/_list.html.erb b/core/app/views/spree/admin/payments/_list.html.erb
index 8c1ffb52439..3959febed04 100644
--- a/core/app/views/spree/admin/payments/_list.html.erb
+++ b/core/app/views/spree/admin/payments/_list.html.erb
@@ -9,7 +9,7 @@
<% payments.each do |payment| %>
<%= payment.created_at.to_s(:date_time24) %>
- <%= number_to_currency payment.amount %>
+ <%= money(payment.amount) %>
<%= link_to payment_method_name(payment), admin_order_payment_path(@order, payment) %>
<%= t(payment.state, :scope => :payment_states, :default => payment.state.capitalize) %>
diff --git a/core/app/views/spree/admin/payments/_transaction_list.html.erb b/core/app/views/spree/admin/payments/_transaction_list.html.erb
deleted file mode 100644
index 0fe24fd76aa..00000000000
--- a/core/app/views/spree/admin/payments/_transaction_list.html.erb
+++ /dev/null
@@ -1,24 +0,0 @@
-
-
- <%= t(:transactions) %>
-
-
-
- <%= t(:type) %>
- <%= t('spree.date') %>
- <%= t(:amount) %>
- <%= t(:response_code) %>
-
- <% txns.each do |txn| %>
-
-
- <%= txn.txn_type_name %>
-
- <%= txn.created_at.to_date %>
- <%= number_to_currency txn.amount %>
- <%= txn.response_code %>
-
- <% end %>
-
-
-
diff --git a/core/app/views/spree/admin/payments/index.html.erb b/core/app/views/spree/admin/payments/index.html.erb
index 62573b61be6..09f760db8a2 100644
--- a/core/app/views/spree/admin/payments/index.html.erb
+++ b/core/app/views/spree/admin/payments/index.html.erb
@@ -12,7 +12,7 @@
<%= render :partial => 'spree/admin/shared/order_tabs', :locals => { :current => 'Payments' } %>
<% if @order.outstanding_balance? %>
- <%= @order.outstanding_balance < 0 ? t(:credit_owed) : t(:balance_due) %> <%= number_to_currency @order.outstanding_balance %>
+ <%= @order.outstanding_balance < 0 ? t(:credit_owed) : t(:balance_due) %> <%= money(@order.outstanding_balance) %>
<% end %>
<%= t(:payments) %>
diff --git a/core/app/views/spree/admin/products/index.html.erb b/core/app/views/spree/admin/products/index.html.erb
index 4e3077f6cb2..9f3261d7f88 100644
--- a/core/app/views/spree/admin/products/index.html.erb
+++ b/core/app/views/spree/admin/products/index.html.erb
@@ -24,7 +24,7 @@
id="<%= spree_dom_id product %>" data-hook="admin_products_index_rows">
<%= product.sku rescue '' %>
<%= link_to product.try(:name), edit_admin_product_path(product) %>
- <%= number_to_currency product.price rescue '' %>
+ <%= money(product.price) rescue '' %>
<%= link_to_edit product, :class => 'edit' unless product.deleted? %>
diff --git a/core/app/views/spree/admin/reports/sales_total.html.erb b/core/app/views/spree/admin/reports/sales_total.html.erb
index 05c8d00d9d5..c3bc3998759 100644
--- a/core/app/views/spree/admin/reports/sales_total.html.erb
+++ b/core/app/views/spree/admin/reports/sales_total.html.erb
@@ -4,15 +4,15 @@
<%= t(:item_total) %>:
- <%= number_to_currency @item_total %>
+ <%= money @item_total %>
<%= t(:adjustment_total) %>:
- <%= number_to_currency @adjustment_total %>
+ <%= money @adjustment_total %>
<%= t(:sales_total) %>:
- <%= number_to_currency @sales_total %>
+ <%= money @sales_total %>
diff --git a/core/app/views/spree/admin/return_authorizations/_form.html.erb b/core/app/views/spree/admin/return_authorizations/_form.html.erb
index b3c396fbfff..3570b700274 100644
--- a/core/app/views/spree/admin/return_authorizations/_form.html.erb
+++ b/core/app/views/spree/admin/return_authorizations/_form.html.erb
@@ -31,7 +31,7 @@
<%= f.field_container :amount do %>
<%= f.label :amount, t(:amount) %> *
<% if @return_authorization.received? %>
- <%= number_to_currency @return_authorization.amount %>
+ <%= money @return_authorization.amount %>
<% else %>
<%= f.text_field :amount, {:style => 'width:80px;'} %> <%= t(:rma_value) %>:
<%= f.error_message_on :amount %>
diff --git a/core/app/views/spree/admin/return_authorizations/index.html.erb b/core/app/views/spree/admin/return_authorizations/index.html.erb
index 141d0c62d24..bab94bab5f3 100644
--- a/core/app/views/spree/admin/return_authorizations/index.html.erb
+++ b/core/app/views/spree/admin/return_authorizations/index.html.erb
@@ -23,7 +23,7 @@
<%= return_authorization.number %>
<%= t(return_authorization.state.downcase) %>
- <%= number_to_currency return_authorization.amount %>
+ <%= money return_authorization.amount %>
<%= return_authorization.created_at.to_s(:date_time24) %>
<%= link_to_edit return_authorization %>
diff --git a/core/app/views/spree/admin/shared/_order_details.html.erb b/core/app/views/spree/admin/shared/_order_details.html.erb
index 49c59f6475b..e68fdd55552 100644
--- a/core/app/views/spree/admin/shared/_order_details.html.erb
+++ b/core/app/views/spree/admin/shared/_order_details.html.erb
@@ -10,16 +10,16 @@
<% @order.line_items.each do |item| %>
<%= item.variant.product.name %> <%= "(" + variant_options(item.variant) + ")" unless item.variant.option_values.empty? %>
- <%= number_to_currency item.price %>
+ <%= money item.price %>
<%= item.quantity %>
- <%= number_to_currency (item.price * item.quantity) %>
+ <%= money(item.price * item.quantity) %>
<% end %>
<%= t(:subtotal) %>:
- <%= number_to_currency @order.item_total %>
+ <%= money @order.item_total %>
@@ -27,14 +27,14 @@
<% next if (adjustment.originator_type == 'Spree::TaxRate') and (adjustment.amount == 0) %>
<%= adjustment.label %>:
- <%= number_to_currency adjustment.amount %>
+ <%= money adjustment.amount %>
<% end %>
<%= t(:order_total) %>:
- <%= number_to_currency @order.total %>
+ <%= money @order.total %>
<% if order.price_adjustment_totals.present? %>
@@ -42,7 +42,7 @@
<% @order.price_adjustment_totals.keys.each do |key| %>
<%= key %>
- <%= number_to_currency @order.price_adjustment_totals[key] %>
+ <%= money @order.price_adjustment_totals[key] %>
<% end %>
diff --git a/core/app/views/spree/admin/shared/_order_tabs.html.erb b/core/app/views/spree/admin/shared/_order_tabs.html.erb
index 9ed65743a36..1b9386ec463 100644
--- a/core/app/views/spree/admin/shared/_order_tabs.html.erb
+++ b/core/app/views/spree/admin/shared/_order_tabs.html.erb
@@ -4,7 +4,7 @@
<%= t(:order) %> #<%= @order.number%>
<%= t(:status) %>: <%= t(@order.state, :scope => :order_state) %>
-
<%= t(:total) %>: <%= number_to_currency @order.total %>
+
<%= t(:total) %>: <%= money @order.total %>
<% if @order.completed? %>
<%= t(:shipment) %>: <%= t(@order.shipment_state, :scope => :shipment_state, :default => [:missing, "none"]) %>
<%= t(:payment) %>: <%= t(@order.payment_state, :scope => :payment_states, :default => [:missing, "none"]) %>
diff --git a/core/app/views/spree/admin/shared/_update_order_state.js b/core/app/views/spree/admin/shared/_update_order_state.js
index 2469f92bff1..bb0994a77ab 100644
--- a/core/app/views/spree/admin/shared/_update_order_state.js
+++ b/core/app/views/spree/admin/shared/_update_order_state.js
@@ -1,5 +1,5 @@
$('#order_tab_summary h5#order_status').html('<%= j t(:status) %>: <%= j t(@order.state, :scope => :order_state) %>');
-$('#order_tab_summary h5#order_total').html('<%= j t(:total) %>: <%= j number_to_currency(@order.total) %>');
+$('#order_tab_summary h5#order_total').html('<%= j t(:total) %>: <%= j @order.display_total %>');
<% if @order.completed? %>
$('#order_tab_summary h5#payment_status').html('<%= j t(:payment) %>: <%= j t(@order.payment_state, :scope => :payment_states, :default => [:missing, "none"]) %>');
diff --git a/core/app/views/spree/admin/shipments/edit.html.erb b/core/app/views/spree/admin/shipments/edit.html.erb
index f203bf7f552..748e3a6f0a7 100644
--- a/core/app/views/spree/admin/shipments/edit.html.erb
+++ b/core/app/views/spree/admin/shipments/edit.html.erb
@@ -14,7 +14,7 @@
<%= t(:shipment) %> #<%= @shipment.number%> (<%= t(@shipment.state.to_sym, :scope => :state_names, :default => @shipment.state.to_s.humanize) %>)
<% if @shipment.cost %>
-
<%= t(:charges) %> <%= number_to_currency @shipment.cost %>
+
<%= t(:charges) %> <%= money @shipment.cost %>
<% end %>
<%= render :partial => 'spree/shared/error_messages', :locals => { :target => @shipment } %>
diff --git a/core/app/views/spree/admin/shipments/index.html.erb b/core/app/views/spree/admin/shipments/index.html.erb
index e8a2e23d9fc..4d79bdbb938 100644
--- a/core/app/views/spree/admin/shipments/index.html.erb
+++ b/core/app/views/spree/admin/shipments/index.html.erb
@@ -23,7 +23,7 @@
<%= shipment.number %>
<%= shipment.shipping_method.name if shipment.shipping_method %>
- <%= number_to_currency shipment.cost %>
+ <%= money shipment.cost %>
<%= shipment.tracking %>
<%= t(shipment.state.to_sym, :scope => :state_names, :default => shipment.state.to_s.humanize) %>
<%= shipment.shipped_at.to_s(:date_time24) if shipment.shipped_at %>
diff --git a/core/app/views/spree/admin/variants/index.html.erb b/core/app/views/spree/admin/variants/index.html.erb
index 9083e705345..f81fce2a8f7 100644
--- a/core/app/views/spree/admin/variants/index.html.erb
+++ b/core/app/views/spree/admin/variants/index.html.erb
@@ -16,7 +16,7 @@
<% next if variant.option_values.empty? %>
data-hook="variants_row">
<%= variant.options_text %>
- <%= number_to_currency variant.price %>
+ <%= money variant.price %>
<%= variant.sku %>
<%= variant.on_hand %>
diff --git a/core/app/views/spree/checkout/_delivery.html.erb b/core/app/views/spree/checkout/_delivery.html.erb
index 05c5608199b..a9d0f83f1aa 100644
--- a/core/app/views/spree/checkout/_delivery.html.erb
+++ b/core/app/views/spree/checkout/_delivery.html.erb
@@ -6,11 +6,7 @@
<% @order.rate_hash.each do |shipping_method| %>
<%= radio_button(:order, :shipping_method_id, shipping_method[:id]) %>
- <% if Spree::Config[:shipment_inc_vat] %>
- <%= shipping_method[:name] %> <%= format_price (1 + Spree::TaxRate.default) * shipping_method[:cost] %>
- <% else %>
- <%= shipping_method[:name] %> <%= number_to_currency shipping_method[:cost] %>
- <% end %>
+ <%= shipping_method.name %> <%= shipping_method.display_price %>
<% end %>
diff --git a/core/app/views/spree/checkout/_summary.html.erb b/core/app/views/spree/checkout/_summary.html.erb
index 1dfd612fde9..dd41c7daacb 100644
--- a/core/app/views/spree/checkout/_summary.html.erb
+++ b/core/app/views/spree/checkout/_summary.html.erb
@@ -4,27 +4,27 @@
<%= t(:item_total) %>:
- <%= number_to_currency order.item_total %>
+ <%= money order.item_total %>
<% order.adjustments.eligible.each do |adjustment| %>
<% next if (adjustment.originator_type == 'Spree::TaxRate') and (adjustment.amount == 0) %>
<%= adjustment.label %>:
- <%= number_to_currency adjustment.amount %>
+ <%= money adjustment.amount %>
<% end %>
<%= t(:order_total) %>:
- <%= number_to_currency @order.total %>
+ <%= money @order.total %>
<% if order.price_adjustment_totals.present? %>
<% @order.price_adjustment_totals.keys.each do |key| %>
<%= key %>
- <%= number_to_currency @order.price_adjustment_totals[key] %>
+ <%= money @order.price_adjustment_totals[key] %>
<% end %>
diff --git a/core/app/views/spree/order_mailer/cancel_email.text.erb b/core/app/views/spree/order_mailer/cancel_email.text.erb
index bc0171a1ff5..311d291a17e 100755
--- a/core/app/views/spree/order_mailer/cancel_email.text.erb
+++ b/core/app/views/spree/order_mailer/cancel_email.text.erb
@@ -6,11 +6,11 @@ Your order has been CANCELED. Please retain this cancellation information for y
Order Summary [CANCELED]
============================================================
<% @order.line_items.each do |item| %>
- <%= item.variant.sku %> <%= raw(item.variant.product.name) %> <%= raw(item.variant.options_text) -%> (<%=item.quantity%>) @ <%= number_to_currency item.price %> = <%= number_to_currency(item.price * item.quantity) %>
+ <%= item.variant.sku %> <%= raw(item.variant.product.name) %> <%= raw(item.variant.options_text) -%> (<%=item.quantity%>) @ <%= money item.price %> = <%= money(item.price * item.quantity) %>
<% end %>
============================================================
-Subtotal: <%= number_to_currency @order.item_total %>
+Subtotal: <%= money @order.item_total %>
<% @order.adjustments.eligible.each do |adjustment| %>
- <%= raw(adjustment.label) %> <%= number_to_currency(adjustment.amount) %>
+ <%= raw(adjustment.label) %> <%= money(adjustment.amount) %>
<% end %>
-Order Total: <%= number_to_currency(@order.total) %>
+Order Total: <%= money(@order.total) %>
diff --git a/core/app/views/spree/order_mailer/confirm_email.text.erb b/core/app/views/spree/order_mailer/confirm_email.text.erb
index 43d31452fca..48d69332aa7 100644
--- a/core/app/views/spree/order_mailer/confirm_email.text.erb
+++ b/core/app/views/spree/order_mailer/confirm_email.text.erb
@@ -6,14 +6,14 @@ Please review and retain the following order information for your records.
Order Summary
============================================================
<% @order.line_items.each do |item| %>
- <%= item.variant.sku %> <%= raw(item.variant.product.name) %> <%= raw(item.variant.options_text) -%> (<%=item.quantity%>) @ <%= number_to_currency item.price %> = <%= number_to_currency(item.price * item.quantity) %>
+ <%= item.variant.sku %> <%= raw(item.variant.product.name) %> <%= raw(item.variant.options_text) -%> (<%=item.quantity%>) @ <%= money item.price %> = <%= money(item.price * item.quantity) %>
<% end %>
============================================================
-Subtotal: <%= number_to_currency @order.item_total %>
+Subtotal: <%= money @order.item_total %>
<% @order.adjustments.eligible.each do |adjustment| %>
- <%= raw(adjustment.label) %> <%= number_to_currency(adjustment.amount) %>
+ <%= raw(adjustment.label) %> <%= money(adjustment.amount) %>
<% end %>
-Order Total: <%= number_to_currency(@order.total) %>
+Order Total: <%= money(@order.total) %>
Thank you for your business.
diff --git a/core/app/views/spree/orders/_adjustments.html.erb b/core/app/views/spree/orders/_adjustments.html.erb
index ad6d8156ea1..bb2d556722d 100644
--- a/core/app/views/spree/orders/_adjustments.html.erb
+++ b/core/app/views/spree/orders/_adjustments.html.erb
@@ -7,7 +7,7 @@
<% @order.adjustments.eligible.each do |adjustment| %>
<%= adjustment.label %>
- <%= number_to_currency(adjustment.amount) %>
+ <%= money(adjustment.amount) %>
<% end %>
diff --git a/core/app/views/spree/orders/_line_item.html.erb b/core/app/views/spree/orders/_line_item.html.erb
index 0a34f06ea54..91fc7e6e7e4 100644
--- a/core/app/views/spree/orders/_line_item.html.erb
+++ b/core/app/views/spree/orders/_line_item.html.erb
@@ -17,13 +17,13 @@
<%= line_item_description(variant) %>
- <%= number_to_currency line_item.price %>
+ <%= money line_item.price %>
<%= item_form.number_field :quantity, :min => 0, :class => "line_item_quantity", :size => 5 %>
- <%= number_to_currency(line_item.price * line_item.quantity) unless line_item.quantity.nil? %>
+ <%= money(line_item.price * line_item.quantity) unless line_item.quantity.nil? %>
<%= link_to image_tag('icons/delete.png'), '#', :class => 'delete', :id => "delete_#{dom_id(line_item)}" %>
diff --git a/core/app/views/spree/orders/edit.html.erb b/core/app/views/spree/orders/edit.html.erb
index 615aa8c93fa..3dcd125acbb 100644
--- a/core/app/views/spree/orders/edit.html.erb
+++ b/core/app/views/spree/orders/edit.html.erb
@@ -19,7 +19,7 @@
-
<%= t(:subtotal) %>: <%= order_subtotal(@order) %>
+ <%= t(:subtotal) %>: <%= @order.display_total %>
diff --git a/core/app/views/spree/products/_cart_form.html.erb b/core/app/views/spree/products/_cart_form.html.erb
index 8f0723241ee..c39b6eecc9d 100644
--- a/core/app/views/spree/products/_cart_form.html.erb
+++ b/core/app/views/spree/products/_cart_form.html.erb
@@ -31,7 +31,7 @@
<%= t(:price) %>
-
<%= number_to_currency @product.price %>
+
<%= money @product.price %>
diff --git a/core/app/views/spree/shared/_order_details.html.erb b/core/app/views/spree/shared/_order_details.html.erb
index 8d6255d9785..80a387f347d 100644
--- a/core/app/views/spree/shared/_order_details.html.erb
+++ b/core/app/views/spree/shared/_order_details.html.erb
@@ -77,16 +77,16 @@
<%= truncate(item.variant.product.description, :length => 100, :omission => "...") %>
<%= "(" + variant_options(item.variant) + ")" unless item.variant .option_values.empty? %>
-
<%= number_to_currency item.price %>
+
<%= money item.price %>
<%= item.quantity %>
-
<%= number_to_currency (item.price * item.quantity) %>
+
<%= money(item.price * item.quantity) %>
<% end %>
<%= t(:order_total) %>:
- <%= number_to_currency @order.total %>
+ <%= money @order.total %>
<% if order.price_adjustment_totals.present? %>
@@ -94,7 +94,7 @@
<% @order.price_adjustment_totals.keys.each do |key| %>
<%= key %>
- <%= number_to_currency @order.price_adjustment_totals[key] %>
+ <%= money @order.price_adjustment_totals[key] %>
<% end %>
@@ -102,7 +102,7 @@
<%= t(:subtotal) %>:
- <%= number_to_currency @order.item_total %>
+ <%= money @order.item_total %>
@@ -110,7 +110,7 @@
<% next if (adjustment.originator_type == 'Spree::TaxRate') and (adjustment.amount == 0) %>
<%= adjustment.label %>
- <%= number_to_currency adjustment.amount %>
+ <%= money adjustment.amount %>
<% end %>
diff --git a/core/app/views/spree/shared/_products.html.erb b/core/app/views/spree/shared/_products.html.erb
index 3dec40511ff..aa817d1c37c 100644
--- a/core/app/views/spree/shared/_products.html.erb
+++ b/core/app/views/spree/shared/_products.html.erb
@@ -18,7 +18,7 @@
<%= link_to small_image(product, :itemprop => "image"), product, :itemprop => 'url' %>
<%= link_to truncate(product.name, :length => 50), product, :class => 'info', :itemprop => "name", :title => product.name %>
-
<%= number_to_currency product.price %>
+
<%= product.display_price %>
<% end %>
<% end %>
diff --git a/core/config/locales/en.yml b/core/config/locales/en.yml
index 74178bc7b31..e5b0b816c80 100644
--- a/core/config/locales/en.yml
+++ b/core/config/locales/en.yml
@@ -334,6 +334,7 @@ en:
credit_cards: Credit Cards
credits: Credits
current: Current
+ currency: Currency
customer: Customer
customer_details: "Customer Details"
customer_details_updated: "The customer's details have been updated."
@@ -357,7 +358,9 @@ en:
didnt_receive_unlock_instructions: "Didn't receive unlock instructions?"
discount_amount: "Discount Amount"
display: Display
+ display_currency: "Display currency"
dismiss_banner: "No. Thanks! I'm not interested, do not display this message again"
+ dollar_amounts_displayed_as: "Dollar amounts displayed as %{example}"
edit: Edit
editing_billing_integration: Editing Billing Integration
editing_category: "Editing Category"
diff --git a/core/lib/spree/core.rb b/core/lib/spree/core.rb
index ddecf60101b..9526d2a129b 100644
--- a/core/lib/spree/core.rb
+++ b/core/lib/spree/core.rb
@@ -39,6 +39,7 @@
require 'deface'
require 'cancan'
require 'select2-rails'
+require 'spree/money'
module Spree
diff --git a/core/lib/spree/money.rb b/core/lib/spree/money.rb
new file mode 100644
index 00000000000..857658a773d
--- /dev/null
+++ b/core/lib/spree/money.rb
@@ -0,0 +1,16 @@
+require 'money'
+
+module Spree
+ class Money
+ def initialize(amount, options={})
+ @money = ::Money.new(amount * 100, Spree::Config[:currency])
+ @options = {}
+ @options[:with_currency] = true if Spree::Config[:display_currency]
+ @options.merge!(options)
+ end
+
+ def to_s
+ @money.format(@options)
+ end
+ end
+end
diff --git a/core/lib/spree/product_filters.rb b/core/lib/spree/product_filters.rb
index a070e05908b..e25c435a3de 100644
--- a/core/lib/spree/product_filters.rb
+++ b/core/lib/spree/product_filters.rb
@@ -46,9 +46,6 @@ module Spree
# happen until Taxon class is loaded. Ensure that Taxon class is loaded before
# you try something like Product.price_range_any
module ProductFilters
- extend ActionView::Helpers::NumberHelper
- extend Spree::BaseHelper
-
# Example: filtering by price
# The named scope just maps incoming labels onto their conditions, and builds the conjunction
# 'price' is in the base scope's context (ie, "select foo from products where ...") so
@@ -67,6 +64,10 @@ module ProductFilters
Spree::Product.joins(:master).where(scope)
end
+ def ProductFilters.format_price(amount)
+ Spree::Money.new(amount)
+ end
+
def ProductFilters.price_filter
v = Spree::Variant.arel_table
conds = [ [ I18n.t(:under_price, :price => format_price(10)) , v[:price].lteq(10)],
diff --git a/core/spec/models/adjustment_spec.rb b/core/spec/models/adjustment_spec.rb
index 256488f19ff..2410635e681 100644
--- a/core/spec/models/adjustment_spec.rb
+++ b/core/spec/models/adjustment_spec.rb
@@ -101,5 +101,23 @@
end
end
+ context "#display_amount" do
+ before { adjustment.amount = 10.55 }
+ context "with display_currency set to true" do
+ before { Spree::Config[:display_currency] = true }
+
+ it "shows the currency" do
+ adjustment.display_amount.should == "$10.55 USD"
+ end
+ end
+
+ context "with display_currency set to false" do
+ before { Spree::Config[:display_currency] = false }
+
+ it "does not include the currency" do
+ adjustment.display_amount.should == "$10.55"
+ end
+ end
+ end
end
diff --git a/core/spec/models/order_spec.rb b/core/spec/models/order_spec.rb
index 25b1721b92f..8249807e95a 100644
--- a/core/spec/models/order_spec.rb
+++ b/core/spec/models/order_spec.rb
@@ -554,4 +554,24 @@ def compute(computable)
order.empty!
end
end
+
+ context "#display_total" do
+ before { order.total = 10.55 }
+
+ context "with display_currency set to true" do
+ before { Spree::Config[:display_currency] = true }
+
+ it "shows the currency" do
+ order.display_total.to_s.should == "$10.55 USD"
+ end
+ end
+
+ context "with display_currency set to false" do
+ before { Spree::Config[:display_currency] = false }
+
+ it "does not include the currency" do
+ order.display_total.to_s.should == "$10.55"
+ end
+ end
+ end
end
diff --git a/core/spec/models/product_spec.rb b/core/spec/models/product_spec.rb
index 47352e04841..59b776b6523 100644
--- a/core/spec/models/product_spec.rb
+++ b/core/spec/models/product_spec.rb
@@ -79,6 +79,26 @@
product.price.should == 10.0
end
end
+
+ context "#display_price" do
+ before { product.price = 10.55 }
+
+ context "with display_currency set to true" do
+ before { Spree::Config[:display_currency] = true }
+
+ it "shows the currency" do
+ product.display_price.should == "$10.55 USD"
+ end
+ end
+
+ context "with display_currency set to false" do
+ before { Spree::Config[:display_currency] = false }
+
+ it "does not include the currency" do
+ product.display_price.should == "$10.55"
+ end
+ end
+ end
end
context "validations" do
diff --git a/core/spec/models/shipping_rate_spec.rb b/core/spec/models/shipping_rate_spec.rb
new file mode 100644
index 00000000000..f8028533247
--- /dev/null
+++ b/core/spec/models/shipping_rate_spec.rb
@@ -0,0 +1,22 @@
+require 'spec_helper'
+
+describe Spree::ShippingRate do
+ let(:shipping_rate) { Spree::ShippingRate.new(:cost => 10.55) }
+ before { Spree::TaxRate.stub(:default => 0.05) }
+
+ context "#display_price" do
+ context "when shipment includes VAT" do
+ before { Spree::Config[:shipment_inc_vat] = true }
+ it "displays the correct price" do
+ shipping_rate.display_price.to_s.should == "$11.08" # $10.55 * 1.05 == $11.08
+ end
+ end
+
+ context "when shipment does not include VAT" do
+ before { Spree::Config[:shipment_inc_vat] = false }
+ it "displays the correct price" do
+ shipping_rate.display_price.to_s.should == "$10.55"
+ end
+ end
+ end
+end
diff --git a/core/spree_core.gemspec b/core/spree_core.gemspec
index f42d4a01a64..27a80d793ad 100644
--- a/core/spree_core.gemspec
+++ b/core/spree_core.gemspec
@@ -36,4 +36,5 @@ Gem::Specification.new do |s|
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'
end
From 14bb58e33dfe4629d91893fddbd53b9aa081f24f Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Wed, 29 Aug 2012 17:50:03 +0100
Subject: [PATCH 086/346] Convert display_total to string so that rendering the
template doesn't bomb out
---
core/app/views/spree/admin/shared/_update_order_state.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/core/app/views/spree/admin/shared/_update_order_state.js b/core/app/views/spree/admin/shared/_update_order_state.js
index bb0994a77ab..6eb62993783 100644
--- a/core/app/views/spree/admin/shared/_update_order_state.js
+++ b/core/app/views/spree/admin/shared/_update_order_state.js
@@ -1,5 +1,5 @@
$('#order_tab_summary h5#order_status').html('<%= j t(:status) %>: <%= j t(@order.state, :scope => :order_state) %>');
-$('#order_tab_summary h5#order_total').html('<%= j t(:total) %>: <%= j @order.display_total %>');
+$('#order_tab_summary h5#order_total').html('<%= j t(:total) %>: <%= j @order.display_total.to_s %>');
<% if @order.completed? %>
$('#order_tab_summary h5#payment_status').html('<%= j t(:payment) %>: <%= j t(@order.payment_state, :scope => :payment_states, :default => [:missing, "none"]) %>');
From 9fdc5c39123a2bbbd79b74096789feb482ac5110 Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Thu, 30 Aug 2012 09:22:51 +0100
Subject: [PATCH 087/346] Currency is no longer determined by I18n values
Fixes order_details_spec
---
core/spec/requests/admin/orders/order_details_spec.rb | 11 ++++-------
1 file changed, 4 insertions(+), 7 deletions(-)
diff --git a/core/spec/requests/admin/orders/order_details_spec.rb b/core/spec/requests/admin/orders/order_details_spec.rb
index 9db1ae5b83a..3387f8d5dfa 100644
--- a/core/spec/requests/admin/orders/order_details_spec.rb
+++ b/core/spec/requests/admin/orders/order_details_spec.rb
@@ -51,17 +51,14 @@
I18n.backend.store_translations I18n.locale,
:shipment_state => { :missing => 'some text' },
- :payment_states => { :missing => 'other text' },
- :number => { :currency => { :format => {
- :format => "%n—%u",
- :unit => "£"
- }}}
+ :payment_states => { :missing => 'other text' }
+
+ Spree::Config[:currency] = "GBP"
visit spree.edit_admin_order_path(order)
within "#sidebar" do
- # beware - the dash before pound is really em dash character '—'
- find("#order_total").text.should == "#{I18n.t(:total)}: 0.00—£"
+ find("#order_total").text.should == "#{I18n.t(:total)}: £0.00"
find("#shipment_status").text.should == "#{I18n.t(:shipment)}: some text"
find("#payment_status").text.should == "#{I18n.t(:payment)}: other text"
end
From 83c5c866732e04ff398810f9281d1bf56c2f93a4 Mon Sep 17 00:00:00 2001
From: Rodrigo Pinto
Date: Sun, 26 Aug 2012 08:55:50 -0300
Subject: [PATCH 088/346] Translate order cancel + confirmation emails, as well
as shipped item email
Merges #1884
---
.../spree/order_mailer/cancel_email.text.erb | 10 ++--
.../spree/order_mailer/confirm_email.text.erb | 13 ++---
.../shipment_mailer/shipped_email.text.erb | 10 ++--
core/config/locales/en.yml | 16 ++++++
core/spec/mailers/order_mailer_spec.rb | 51 ++++++++++++++++++-
core/spec/mailers/shipment_mailer_spec.rb | 29 +++++++++++
6 files changed, 112 insertions(+), 17 deletions(-)
diff --git a/core/app/views/spree/order_mailer/cancel_email.text.erb b/core/app/views/spree/order_mailer/cancel_email.text.erb
index 311d291a17e..6ee3ae03fbe 100755
--- a/core/app/views/spree/order_mailer/cancel_email.text.erb
+++ b/core/app/views/spree/order_mailer/cancel_email.text.erb
@@ -1,16 +1,16 @@
-Dear Customer,
+<%= t('order_mailer.cancel_email.dear_customer') %>
-Your order has been CANCELED. Please retain this cancellation information for your records.
+<%= t('order_mailer.cancel_email.instructions') %>
============================================================
-Order Summary [CANCELED]
+<%= t('order_mailer.cancel_email.order_summary_canceled') %>
============================================================
<% @order.line_items.each do |item| %>
<%= item.variant.sku %> <%= raw(item.variant.product.name) %> <%= raw(item.variant.options_text) -%> (<%=item.quantity%>) @ <%= money item.price %> = <%= money(item.price * item.quantity) %>
<% end %>
============================================================
-Subtotal: <%= money @order.item_total %>
+<%= t('order_mailer.cancel_email.subtotal') %> <%= money @order.item_total %>
<% @order.adjustments.eligible.each do |adjustment| %>
<%= raw(adjustment.label) %> <%= money(adjustment.amount) %>
<% end %>
-Order Total: <%= money(@order.total) %>
+<%= t('order_mailer.cancel_email.total') %> <%= money(@order.total) %>
diff --git a/core/app/views/spree/order_mailer/confirm_email.text.erb b/core/app/views/spree/order_mailer/confirm_email.text.erb
index 48d69332aa7..a868b5250ff 100644
--- a/core/app/views/spree/order_mailer/confirm_email.text.erb
+++ b/core/app/views/spree/order_mailer/confirm_email.text.erb
@@ -1,19 +1,20 @@
-Dear Customer,
+<%= t('order_mailer.confirm_email.dear_customer') %>
-Please review and retain the following order information for your records.
+<%= t('order_mailer.confirm_email.instructions') %>
============================================================
-Order Summary
+<%= t('order_mailer.confirm_email.order_summary') %>
============================================================
<% @order.line_items.each do |item| %>
<%= item.variant.sku %> <%= raw(item.variant.product.name) %> <%= raw(item.variant.options_text) -%> (<%=item.quantity%>) @ <%= money item.price %> = <%= money(item.price * item.quantity) %>
<% end %>
============================================================
-Subtotal: <%= money @order.item_total %>
+<%= t('order_mailer.confirm_email.subtotal') %>: <%= money @order.item_total %>
+
<% @order.adjustments.eligible.each do |adjustment| %>
<%= raw(adjustment.label) %> <%= money(adjustment.amount) %>
<% end %>
-Order Total: <%= money(@order.total) %>
+<%= t('order_mailer.confirm_email.total') %>: <%= money(@order.total) %>
-Thank you for your business.
+<%= t('order_mailer.confirm_email.thanks') %>
diff --git a/core/app/views/spree/shipment_mailer/shipped_email.text.erb b/core/app/views/spree/shipment_mailer/shipped_email.text.erb
index 2fa632ea32c..59d90446d1b 100644
--- a/core/app/views/spree/shipment_mailer/shipped_email.text.erb
+++ b/core/app/views/spree/shipment_mailer/shipped_email.text.erb
@@ -1,15 +1,15 @@
-Dear Customer,
+<%= t('shipment_mailer.shipped_email.dear_customer') %>
-Your order has been shipped
+<%= t('shipment_mailer.shipped_email.instructions') %>
============================================================
-Shipment Summary
+<%= t('shipment_mailer.shipped_email.shipment_summary') %>
============================================================
<% @shipment.manifest.each do |item| %>
<%= item.variant.sku %> <%= item.variant.product.name %> <%= variant_options(item.variant, :include_style => false) %> (<%= item.quantity %>)
<% end %>
============================================================
-<%= "Tracking Information: #{@shipment.tracking}" if @shipment.tracking %>
+<%= t('shipment_mailer.shipped_email.track_information', :tracking => @shipment.tracking) if @shipment.tracking %>
-Thank you for your business.
+<%= t('shipment_mailer.shipped_email.thanks') %>
diff --git a/core/config/locales/en.yml b/core/config/locales/en.yml
index e5b0b816c80..5a8a9d0f2f6 100644
--- a/core/config/locales/en.yml
+++ b/core/config/locales/en.yml
@@ -609,8 +609,19 @@ en:
order_mailer:
confirm_email:
subject: "Order Confirmation"
+ dear_customer: "Dear Customer,"
+ instructions: "Please review and retain the following order information for your records."
+ order_summary: "Order Summary"
+ subtotal: "Subtotal:"
+ total: "Order Total:"
+ thanks: "Thank you for your business."
cancel_email:
subject: "Cancellation of Order"
+ dear_customer: "Dear Customer,"
+ instructions: "Your order has been CANCELED. Please retain this cancellation information for your records."
+ order_summary_canceled: "Order Summary [CANCELED]"
+ subtotal: "Subtotal:"
+ total: "Order Total:"
order_not_in_system: That order number is not valid on this site.
order_number: Order
order_operation_authorize: Authorize
@@ -899,6 +910,11 @@ en:
shipment_mailer:
shipped_email:
subject: "Shipment Notification"
+ dear_customer: "Dear Customer,"
+ instructions: "Your order has been shipped"
+ shipment_summary: "Shipment Summary"
+ track_information: "Tracking Information: %{tracking}"
+ thanks: "Thank you for your business."
shipment_number: "Shipment #"
shipment_state: Shipment State
shipment_states:
diff --git a/core/spec/mailers/order_mailer_spec.rb b/core/spec/mailers/order_mailer_spec.rb
index 51f06734090..f6ca6fe93fc 100644
--- a/core/spec/mailers/order_mailer_spec.rb
+++ b/core/spec/mailers/order_mailer_spec.rb
@@ -31,7 +31,7 @@
end
let!(:confirmation_email) { Spree::OrderMailer.confirm_email(order) }
- let!(:cancel_email) { Spree::OrderMailer.confirm_email(order) }
+ let!(:cancel_email) { Spree::OrderMailer.cancel_email(order) }
specify do
confirmation_email.body.should_not include("Ineligible Adjustment")
@@ -42,4 +42,53 @@
end
end
+ context "emails must be translatable" do
+ context "en locale" do
+ before do
+ en_confirm_mail = { :order_mailer => { :confirm_email => { :dear_customer => 'Dear Customer,' } } }
+ en_cancel_mail = { :order_mailer => { :cancel_email => { :order_summary_canceled => 'Order Summary [CANCELED]' } } }
+ I18n.backend.store_translations :en, en_confirm_mail
+ I18n.backend.store_translations :en, en_cancel_mail
+ I18n.locale = :en
+ end
+
+ context "confirm_email" do
+ specify do
+ confirmation_email = Spree::OrderMailer.confirm_email(order)
+ confirmation_email.body.should include("Dear Customer,")
+ end
+ end
+
+ context "cancel_email" do
+ specify do
+ cancel_email = Spree::OrderMailer.cancel_email(order)
+ cancel_email.body.should include("Order Summary [CANCELED]")
+ end
+ end
+ end
+
+ context "pt-BR locale" do
+ before do
+ pt_br_confirm_mail = { :order_mailer => { :confirm_email => { :dear_customer => 'Caro Cliente,' } } }
+ pt_br_cancel_mail = { :order_mailer => { :cancel_email => { :order_summary_canceled => 'Resumo da Pedido [CANCELADA]' } } }
+ I18n.backend.store_translations :'pt-BR', pt_br_confirm_mail
+ I18n.backend.store_translations :'pt-BR', pt_br_cancel_mail
+ I18n.locale = :'pt-BR'
+ end
+
+ context "confirm_email" do
+ specify do
+ confirmation_email = Spree::OrderMailer.confirm_email(order)
+ confirmation_email.body.should include("Caro Cliente,")
+ end
+ end
+
+ context "cancel_email" do
+ specify do
+ cancel_email = Spree::OrderMailer.cancel_email(order)
+ cancel_email.body.should include("Resumo da Pedido [CANCELADA]")
+ end
+ end
+ end
+ end
end
diff --git a/core/spec/mailers/shipment_mailer_spec.rb b/core/spec/mailers/shipment_mailer_spec.rb
index 6c368dd36f3..dcf10a58b14 100644
--- a/core/spec/mailers/shipment_mailer_spec.rb
+++ b/core/spec/mailers/shipment_mailer_spec.rb
@@ -21,4 +21,33 @@
shipment_email = Spree::ShipmentMailer.shipped_email(shipment)
shipment_email.body.should_not include(%Q{span class="out-of-stock"})
end
+
+ context "emails must be translatable" do
+ context "shipped_email" do
+ context "en locale" do
+ before do
+ en_shipped_email = { :shipment_mailer => { :shipped_email => { :dear_customer => 'Dear Customer,' } } }
+ I18n.backend.store_translations :en, en_shipped_email
+ I18n.locale = :en
+ end
+
+ specify do
+ shipped_email = Spree::ShipmentMailer.shipped_email(shipment)
+ shipped_email.body.should include("Dear Customer,")
+ end
+ end
+ context "pt-BR locale" do
+ before do
+ pt_br_shipped_email = { :shipment_mailer => { :shipped_email => { :dear_customer => 'Caro Cliente,' } } }
+ I18n.backend.store_translations :'pt-BR', pt_br_shipped_email
+ I18n.locale = :'pt-BR'
+ end
+
+ specify do
+ shipped_email = Spree::ShipmentMailer.shipped_email(shipment)
+ shipped_email.body.should include("Caro Cliente,")
+ end
+ end
+ end
+ end
end
From 4479f37b8ed519d8436cfaa851022890f8cb96d9 Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Thu, 30 Aug 2012 10:08:44 +0100
Subject: [PATCH 089/346] Prevent commerce_tracking flash message appearing on
checkout
Fixes #1428 (again)
Also stops a double iteration through all (max two) of the flash messages
---
core/app/helpers/spree/base_helper.rb | 8 +++-----
1 file changed, 3 insertions(+), 5 deletions(-)
diff --git a/core/app/helpers/spree/base_helper.rb b/core/app/helpers/spree/base_helper.rb
index 06cb9bca9d4..564fff99909 100644
--- a/core/app/helpers/spree/base_helper.rb
+++ b/core/app/helpers/spree/base_helper.rb
@@ -89,12 +89,10 @@ def logo(image_path=Spree::Config[:logo])
def flash_messages(opts = {})
opts[:ignore_types] = [:commerce_tracking].concat(opts[:ignore_types] || [])
- flash.reject do |msg_type, text|
- opts[:ignore_types].include?(msg_type)
- end
-
flash.each do |msg_type, text|
- concat(content_tag :div, text, :class => "flash #{msg_type}")
+ unless opts[:ignore_types].include?(msg_type)
+ concat(content_tag :div, text, :class => "flash #{msg_type}")
+ end
end
nil
end
From 4728b9cc603320ec0b9c7eadc306aa3dd3e8aafd Mon Sep 17 00:00:00 2001
From: Michael Bianco
Date: Wed, 22 Aug 2012 13:07:03 -0400
Subject: [PATCH 090/346] Unfulfilled order admin filter
Merges #1872
---
core/app/controllers/spree/admin/orders_controller.rb | 4 +++-
core/app/views/spree/admin/orders/index.html.erb | 4 ++++
core/config/locales/en.yml | 1 +
3 files changed, 8 insertions(+), 1 deletion(-)
diff --git a/core/app/controllers/spree/admin/orders_controller.rb b/core/app/controllers/spree/admin/orders_controller.rb
index 295e696a6fe..38af8fcca86 100644
--- a/core/app/controllers/spree/admin/orders_controller.rb
+++ b/core/app/controllers/spree/admin/orders_controller.rb
@@ -20,6 +20,8 @@ def index
created_at_gt = params[:q][:created_at_gt]
created_at_lt = params[:q][:created_at_lt]
+ params[:q].delete(:inventory_units_shipment_id_null) if params[:q][:inventory_units_shipment_id_null] == "0"
+
if !params[:q][:created_at_gt].blank?
params[:q][:created_at_gt] = Time.zone.parse(params[:q][:created_at_gt]).beginning_of_day rescue ""
end
@@ -34,7 +36,7 @@ def index
end
@search = Order.ransack(params[:q])
- @orders = @search.result.includes([:user, :shipments, :payments]).page(params[:page]).per(Spree::Config[:orders_per_page])
+ @orders = @search.result(:distinct => true).includes([:user, :shipments, :payments]).page(params[:page]).per(Spree::Config[:orders_per_page])
# Restore dates
params[:q][:created_at_gt] = created_at_gt
diff --git a/core/app/views/spree/admin/orders/index.html.erb b/core/app/views/spree/admin/orders/index.html.erb
index 9371c8bdf14..dd80fab4969 100644
--- a/core/app/views/spree/admin/orders/index.html.erb
+++ b/core/app/views/spree/admin/orders/index.html.erb
@@ -82,6 +82,10 @@
<%= f.check_box :completed_at_not_null, {:checked => @show_only_completed}, '1', '' %>
<%= label_tag nil, t(:show_only_complete_orders) %>
+
+ <%= f.check_box :inventory_units_shipment_id_null, { }, '1', '0' %>
+ <%= label_tag nil, t(:show_only_unfulfilled_orders) %>
+
diff --git a/core/config/locales/en.yml b/core/config/locales/en.yml
index 5a8a9d0f2f6..ef3c58b23bd 100644
--- a/core/config/locales/en.yml
+++ b/core/config/locales/en.yml
@@ -948,6 +948,7 @@ en:
show_incomplete_orders: "Show Incomplete Orders"
show_only_complete_orders: "Only show complete orders"
show_out_of_stock_products: "Show out-of-stock products"
+ show_only_unfulfilled_orders: "Show only unfulfilled orders"
showing_first_n: "Showing first %{n}"
sign_up: "Sign up"
site_name: "Site Name"
From 3d6b7116de53a03d6fc82d4d2ca504bcc7089db0 Mon Sep 17 00:00:00 2001
From: Michael Bianco
Date: Thu, 23 Aug 2012 13:42:22 -0400
Subject: [PATCH 091/346] Adding date completed display to orders#show
Merges #1876
---
core/app/views/spree/admin/shared/_order_tabs.html.erb | 1 +
core/config/locales/en.yml | 1 +
2 files changed, 2 insertions(+)
diff --git a/core/app/views/spree/admin/shared/_order_tabs.html.erb b/core/app/views/spree/admin/shared/_order_tabs.html.erb
index 1b9386ec463..9e9df67222f 100644
--- a/core/app/views/spree/admin/shared/_order_tabs.html.erb
+++ b/core/app/views/spree/admin/shared/_order_tabs.html.erb
@@ -8,6 +8,7 @@
<% if @order.completed? %>
<%= t(:shipment) %>: <%= t(@order.shipment_state, :scope => :shipment_state, :default => [:missing, "none"]) %>
<%= t(:payment) %>: <%= t(@order.payment_state, :scope => :payment_states, :default => [:missing, "none"]) %>
+ <%= t(:date_completed) %>: <%= I18n.l(@order.completed? ? @order.completed_at : @order.created_at) %>
<% end %>
diff --git a/core/config/locales/en.yml b/core/config/locales/en.yml
index ef3c58b23bd..63435257466 100644
--- a/core/config/locales/en.yml
+++ b/core/config/locales/en.yml
@@ -340,6 +340,7 @@ en:
customer_details_updated: "The customer's details have been updated."
customer_search: "Customer Search"
date_created: Date created
+ date_completed: Date Completed
date_range: "Date Range"
debit: Debit
default: Default
From eb9c6239ab8da058e05c194b8730bbbed13114ea Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Thu, 30 Aug 2012 10:46:49 +0100
Subject: [PATCH 092/346] Reset locale in shipment_mailer_spec
---
core/spec/mailers/shipment_mailer_spec.rb | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/core/spec/mailers/shipment_mailer_spec.rb b/core/spec/mailers/shipment_mailer_spec.rb
index dcf10a58b14..8e2bf84a50d 100644
--- a/core/spec/mailers/shipment_mailer_spec.rb
+++ b/core/spec/mailers/shipment_mailer_spec.rb
@@ -43,6 +43,10 @@
I18n.locale = :'pt-BR'
end
+ after do
+ I18n.locale = I18n.default_locale
+ end
+
specify do
shipped_email = Spree::ShipmentMailer.shipped_email(shipment)
shipped_email.body.should include("Caro Cliente,")
From 1a89c55377a2611d3bcc77ad224d9838ad066217 Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Thu, 30 Aug 2012 11:20:22 +0100
Subject: [PATCH 093/346] Reset the I18n.locale after order_mailer_spec
---
core/spec/mailers/order_mailer_spec.rb | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/core/spec/mailers/order_mailer_spec.rb b/core/spec/mailers/order_mailer_spec.rb
index f6ca6fe93fc..b9d7bb550a9 100644
--- a/core/spec/mailers/order_mailer_spec.rb
+++ b/core/spec/mailers/order_mailer_spec.rb
@@ -76,6 +76,10 @@
I18n.locale = :'pt-BR'
end
+ after do
+ I18n.locale = I18n.default_locale
+ end
+
context "confirm_email" do
specify do
confirmation_email = Spree::OrderMailer.confirm_email(order)
From e498b5ae2e99b79b9ee8db18e207f70a37c09208 Mon Sep 17 00:00:00 2001
From: hazg
Date: Sun, 26 Aug 2012 16:25:37 +0400
Subject: [PATCH 094/346] Add "encoding: utf-8" magic comment to *.js.erb
---
core/app/assets/javascripts/admin/admin.js.erb | 1 +
core/app/assets/javascripts/admin/product_autocomplete.js.erb | 1 +
2 files changed, 2 insertions(+)
diff --git a/core/app/assets/javascripts/admin/admin.js.erb b/core/app/assets/javascripts/admin/admin.js.erb
index d2de82a07fa..3470722f6b6 100644
--- a/core/app/assets/javascripts/admin/admin.js.erb
+++ b/core/app/assets/javascripts/admin/admin.js.erb
@@ -1,3 +1,4 @@
+//<%#encoding: UTF-8%>
//= require_self
//= require admin/product_autocomplete
//= require select2
diff --git a/core/app/assets/javascripts/admin/product_autocomplete.js.erb b/core/app/assets/javascripts/admin/product_autocomplete.js.erb
index 5fe05e762f4..08e399de3a1 100644
--- a/core/app/assets/javascripts/admin/product_autocomplete.js.erb
+++ b/core/app/assets/javascripts/admin/product_autocomplete.js.erb
@@ -1,3 +1,4 @@
+//<%#encoding: UTF-8%>
// Product autocompletion
image_html = function(item){
return " ";
From c83622c971ed65e7991d55093265b9c408735e77 Mon Sep 17 00:00:00 2001
From: Masahiro Saito
Date: Thu, 30 Aug 2012 20:09:49 +0900
Subject: [PATCH 095/346] fixed display roles bug.
Merges #1901
---
core/app/helpers/spree/admin/users_helper.rb | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/core/app/helpers/spree/admin/users_helper.rb b/core/app/helpers/spree/admin/users_helper.rb
index de30fbd901a..d656945443a 100644
--- a/core/app/helpers/spree/admin/users_helper.rb
+++ b/core/app/helpers/spree/admin/users_helper.rb
@@ -3,7 +3,7 @@ module Admin
module UsersHelper
def list_roles(user)
# while testing spree-core itself user model does not have method roles
- user.respond_to?(:roles) ? user.roles.collect { |role| role.name }.join(", ") : []
+ user.respond_to?(:spree_roles) ? user.spree_roles.collect { |role| role.name }.join(", ") : []
end
end
end
From 66caa8cb5a97f16982b67a7197b81d49548b0e16 Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Thu, 30 Aug 2012 14:24:58 +0100
Subject: [PATCH 096/346] Include analytics helper into layout specified with
Spree::Config[:layout]
Fixes #1887
Also set unauthorized to use defined layout
---
core/lib/spree/core/controller_helpers.rb | 2 +-
dash/app/overrides/analytics_header.rb | 4 ++--
2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/core/lib/spree/core/controller_helpers.rb b/core/lib/spree/core/controller_helpers.rb
index a7540568cd0..12877a00f3e 100644
--- a/core/lib/spree/core/controller_helpers.rb
+++ b/core/lib/spree/core/controller_helpers.rb
@@ -107,7 +107,7 @@ def unauthorized
format.html do
if try_spree_current_user
flash.now[:error] = t(:authorization_failure)
- render 'spree/shared/unauthorized', :layout => '/spree/layouts/spree_application', :status => 401
+ render 'spree/shared/unauthorized', :layout => Spree::Config[:layout], :status => 401
else
store_location
url = respond_to?(:spree_login_path) ? spree_login_path : root_path
diff --git a/dash/app/overrides/analytics_header.rb b/dash/app/overrides/analytics_header.rb
index a4682bf1ab8..af580f245c6 100644
--- a/dash/app/overrides/analytics_header.rb
+++ b/dash/app/overrides/analytics_header.rb
@@ -1,5 +1,5 @@
-Deface::Override.new(:virtual_path => "spree/layouts/spree_application",
+Deface::Override.new(:virtual_path => Spree::Config[:layout],
:name => "add_analytics_header",
- :insert_bottom => "[data-hook='inside_head']",
+ :insert_bottom => "head",
:partial => "spree/analytics/header",
:original => '6f23c8af6e863d0499835c00b3f2763cb98e1d75')
From bdabaf55c5be081ec950fdcc65111313f459c82d Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Thu, 30 Aug 2012 15:15:11 +0100
Subject: [PATCH 097/346] Remove debug from spree_cmd
---
cmd/lib/spree_cmd.rb | 1 -
1 file changed, 1 deletion(-)
diff --git a/cmd/lib/spree_cmd.rb b/cmd/lib/spree_cmd.rb
index 21a76ef9cc2..ef3ea40140b 100644
--- a/cmd/lib/spree_cmd.rb
+++ b/cmd/lib/spree_cmd.rb
@@ -3,7 +3,6 @@
case ARGV.first
when 'version', '-v', '--version'
- puts "outputting version"
puts Gem.loaded_specs['spree_cmd'].version
when 'extension'
ARGV.shift
From 915d841dec726bf7273c4a3676b26e1035d825c4 Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Thu, 30 Aug 2012 15:18:57 +0100
Subject: [PATCH 098/346] Set Spree::User to Spree.user_class when installing
---
cmd/lib/spree_cmd/installer.rb | 2 ++
1 file changed, 2 insertions(+)
diff --git a/cmd/lib/spree_cmd/installer.rb b/cmd/lib/spree_cmd/installer.rb
index 1db07f2a45c..fc0658b9cc8 100644
--- a/cmd/lib/spree_cmd/installer.rb
+++ b/cmd/lib/spree_cmd/installer.rb
@@ -67,6 +67,8 @@ def ask_questions
if @user_class.blank?
@user_class = "User"
end
+ else
+ @user_class = "Spree::User"
end
if options[:skip_install_data]
From 088a5ad66de45e1d97cdf2561446e281c8140bb7 Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Thu, 30 Aug 2012 15:30:55 +0100
Subject: [PATCH 099/346] No need for first slash in layout
---
core/app/models/spree/app_configuration.rb | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/core/app/models/spree/app_configuration.rb b/core/app/models/spree/app_configuration.rb
index 8884934f000..f4e2b29e699 100644
--- a/core/app/models/spree/app_configuration.rb
+++ b/core/app/models/spree/app_configuration.rb
@@ -50,7 +50,7 @@ class AppConfiguration < Preferences::Configuration
preference :default_seo_title, :string, :default => ''
preference :dismissed_spree_alerts, :string, :default => ''
preference :last_check_for_spree_alerts, :string, :default => nil
- preference :layout, :string, :default => '/spree/layouts/spree_application'
+ preference :layout, :string, :default => 'spree/layouts/spree_application'
preference :logo, :string, :default => 'admin/bg/spree_50.png'
preference :max_level_in_taxons_menu, :integer, :default => 1 # maximum nesting level in taxons menu
preference :orders_per_page, :integer, :default => 15
From 96925923f8543812967d82afa096487426b72e8d Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Thu, 30 Aug 2012 16:00:49 +0100
Subject: [PATCH 100/346] Add skip_state_validation? method so that
CheckoutController decorations can choose to skip the state validation
---
.../app/controllers/spree/checkout_controller.rb | 16 ++++++++++++----
1 file changed, 12 insertions(+), 4 deletions(-)
diff --git a/core/app/controllers/spree/checkout_controller.rb b/core/app/controllers/spree/checkout_controller.rb
index fa6c7f71784..53bdf1ea7c7 100644
--- a/core/app/controllers/spree/checkout_controller.rb
+++ b/core/app/controllers/spree/checkout_controller.rb
@@ -39,13 +39,21 @@ def update
private
def ensure_valid_state
- if (params[:state] && !@order.checkout_steps.include?(params[:state])) ||
- (!params[:state] && !@order.checkout_steps.include?(@order.state))
- @order.state = 'cart'
- redirect_to checkout_state_path(@order.checkout_steps.first)
+ unless skip_state_validation?
+ if (params[:state] && !@order.checkout_steps.include?(params[:state])) ||
+ (!params[:state] && !@order.checkout_steps.include?(@order.state))
+ @order.state = 'cart'
+ redirect_to checkout_state_path(@order.checkout_steps.first)
+ end
end
end
+ # Should be overriden if you have areas of your checkout that don't match
+ # up to a step within checkout_steps, such as a registration step
+ def skip_state_validation?
+ false
+ end
+
def load_order
@order = current_order
redirect_to cart_path and return unless @order and @order.checkout_allowed?
From 17d201bcbd36cda4161809f4f7cc3cb8a19b3f10 Mon Sep 17 00:00:00 2001
From: sail
Date: Fri, 31 Aug 2012 14:25:15 +0800
Subject: [PATCH 101/346] RUBY_PALTFORM problem
For some windows OS which RUBY_PALTFORM is like i386-mingw32.
Fixes #1903
---
cmd/lib/spree_cmd/installer.rb | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/cmd/lib/spree_cmd/installer.rb b/cmd/lib/spree_cmd/installer.rb
index fc0658b9cc8..8ab1c909606 100644
--- a/cmd/lib/spree_cmd/installer.rb
+++ b/cmd/lib/spree_cmd/installer.rb
@@ -178,7 +178,7 @@ def windows?
def image_magick_installed?
cmd = 'identify -version'
- if RUBY_PLATFORM =~ /mswin/ #windows
+ if RUBY_PLATFORM =~ /mingw|mswin/ #windows
cmd += " >nul"
else
cmd += " >/dev/null"
From 11c9f81992535a48f84af82537a91e967e75b688 Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Fri, 31 Aug 2012 11:15:15 +0100
Subject: [PATCH 102/346] Fix mis-spelling of prop in checkout.js
---
core/app/assets/javascripts/admin/checkouts/edit.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/core/app/assets/javascripts/admin/checkouts/edit.js b/core/app/assets/javascripts/admin/checkouts/edit.js
index 7324e8783b2..d5681d1f3af 100644
--- a/core/app/assets/javascripts/admin/checkouts/edit.js
+++ b/core/app/assets/javascripts/admin/checkouts/edit.js
@@ -81,7 +81,7 @@ $(document).ready(function(){
$('#user_id').val(ui.item.data['id']);
$('#guest_checkout_true').prop("checked", false);
$('#guest_checkout_false').prop("checked", true);
- $('#guest_checkout_false').prob("disabled", false);
+ $('#guest_checkout_false').prop("disabled", false);
return true;
}
}).data("autocomplete")._renderItem = function(ul, item) {
From faaa2df7706331b7d779ea7973b6c75747ac9d02 Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Fri, 31 Aug 2012 11:21:03 +0100
Subject: [PATCH 103/346] Decrease wait-time for customer autocomplete box
---
core/app/assets/javascripts/admin/checkouts/edit.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/core/app/assets/javascripts/admin/checkouts/edit.js b/core/app/assets/javascripts/admin/checkouts/edit.js
index d5681d1f3af..6d9c407de93 100644
--- a/core/app/assets/javascripts/admin/checkouts/edit.js
+++ b/core/app/assets/javascripts/admin/checkouts/edit.js
@@ -45,7 +45,7 @@ $(document).ready(function(){
if ($("#customer_search").length > 0) {
$("#customer_search").autocomplete({
minChars: 5,
- delay: 1500,
+ delay: 500,
source: function(request, response) {
var params = { q: $('#customer_search').val(),
authenticity_token: encodeURIComponent($('meta[name=csrf-token]').attr("content")) }
From 6cc3da52daa3ef57423c0ddbeb4211980ea3103d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Trung=20L=C3=AA?=
Date: Fri, 31 Aug 2012 07:04:19 +1000
Subject: [PATCH 104/346] Rename Spree::InventoryUnit.backorder to backordered
---
core/app/models/spree/inventory_unit.rb | 7 ++++++-
core/app/models/spree/order.rb | 2 +-
core/spec/models/order_spec.rb | 6 +++---
3 files changed, 10 insertions(+), 5 deletions(-)
diff --git a/core/app/models/spree/inventory_unit.rb b/core/app/models/spree/inventory_unit.rb
index 14b5ba30ca8..702cf9a9fab 100644
--- a/core/app/models/spree/inventory_unit.rb
+++ b/core/app/models/spree/inventory_unit.rb
@@ -5,7 +5,12 @@ class InventoryUnit < ActiveRecord::Base
belongs_to :shipment
belongs_to :return_authorization
- scope :backorder, where(:state => 'backordered')
+ scope :backordered, where(:state => 'backordered')
+
+ def self.backorder
+ warn "[SPREE] Spree::InventoryUnit.backorder will be deprecated in Spree 1.3. Please use Spree::Product.backordered instead."
+ backordered
+ end
attr_accessible :shipment
diff --git a/core/app/models/spree/order.rb b/core/app/models/spree/order.rb
index f487ca99486..2b976cd2a0d 100644
--- a/core/app/models/spree/order.rb
+++ b/core/app/models/spree/order.rb
@@ -144,7 +144,7 @@ def item_count
# Indicates whether there are any backordered InventoryUnits associated with the Order.
def backordered?
return false unless Spree::Config[:track_inventory_levels]
- inventory_units.backorder.present?
+ inventory_units.backordered.present?
end
# Returns the relevant zone (if any) to be used for taxation purposes. Uses default tax zone
diff --git a/core/spec/models/order_spec.rb b/core/spec/models/order_spec.rb
index 8249807e95a..fdbe7107a65 100644
--- a/core/spec/models/order_spec.rb
+++ b/core/spec/models/order_spec.rb
@@ -175,16 +175,16 @@ def compute(computable)
context "#backordered?" do
it "should indicate whether any units in the order are backordered" do
- order.stub_chain(:inventory_units, :backorder).and_return []
+ order.stub_chain(:inventory_units, :backordered).and_return []
order.backordered?.should be_false
- order.stub_chain(:inventory_units, :backorder).and_return [mock_model(Spree::InventoryUnit)]
+ order.stub_chain(:inventory_units, :backordered).and_return [mock_model(Spree::InventoryUnit)]
order.backordered?.should be_true
end
it "should always be false when inventory tracking is disabled" do
pending
Spree::Config.set :track_inventory_levels => false
- order.stub_chain(:inventory_units, :backorder).and_return [mock_model(Spree::InventoryUnit)]
+ order.stub_chain(:inventory_units, :backordered).and_return [mock_model(Spree::InventoryUnit)]
order.backordered?.should be_false
end
end
From 4653099f935e1b35085a69cf24f35340c2496cde Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Trung=20L=C3=AA?=
Date: Fri, 31 Aug 2012 09:38:45 +1000
Subject: [PATCH 105/346] We only care about shipped units in
Spree::LineItem#quantity_no_less_than_shipped
---
core/app/models/spree/inventory_unit.rb | 1 +
core/app/models/spree/line_item.rb | 2 +-
core/spec/models/line_item_spec.rb | 5 ++++-
3 files changed, 6 insertions(+), 2 deletions(-)
diff --git a/core/app/models/spree/inventory_unit.rb b/core/app/models/spree/inventory_unit.rb
index 702cf9a9fab..50f19e0e4c3 100644
--- a/core/app/models/spree/inventory_unit.rb
+++ b/core/app/models/spree/inventory_unit.rb
@@ -6,6 +6,7 @@ class InventoryUnit < ActiveRecord::Base
belongs_to :return_authorization
scope :backordered, where(:state => 'backordered')
+ scope :shipped, where(:state => 'shipped')
def self.backorder
warn "[SPREE] Spree::InventoryUnit.backorder will be deprecated in Spree 1.3. Please use Spree::Product.backordered instead."
diff --git a/core/app/models/spree/line_item.rb b/core/app/models/spree/line_item.rb
index 91642862f9e..c4eb9787174 100644
--- a/core/app/models/spree/line_item.rb
+++ b/core/app/models/spree/line_item.rb
@@ -97,7 +97,7 @@ def stock_availability
end
def quantity_no_less_than_shipped
- already_shipped = order.shipments.reduce(0) { |acc,s| acc + s.inventory_units.select { |i| i.variant == variant }.count }
+ already_shipped = order.shipments.reduce(0) { |acc,s| acc + s.inventory_units.shipped.select { |i| i.variant == variant }.count }
unless quantity >= already_shipped
errors.add(:quantity, I18n.t('validation.cannot_be_less_than_shipped_units'))
end
diff --git a/core/spec/models/line_item_spec.rb b/core/spec/models/line_item_spec.rb
index 005457f46bd..7bb004aa86f 100644
--- a/core/spec/models/line_item_spec.rb
+++ b/core/spec/models/line_item_spec.rb
@@ -186,9 +186,12 @@
shipping_method = mock_model(Spree::ShippingMethod, :calculator => mock(:calculator))
shipment = Spree::Shipment.new :order => order, :shipping_method => shipping_method
shipment.stub(:state => 'shipped')
- inventory_units = 5.times.map { Spree::InventoryUnit.new({:variant => line_item.variant}, :without_protection => true) }
+ shipped_inventory_units = 5.times.map { Spree::InventoryUnit.new({ :variant => line_item.variant, :state => 'shipped' }, :without_protection => true) }
+ unshipped_inventory_units = 2.times.map { Spree::InventoryUnit.new({ :variant => line_item.variant, :state => 'sold' }, :without_protection => true) }
+ inventory_units = shipped_inventory_units + unshipped_inventory_units
order.stub(:shipments => [shipment])
shipment.stub(:inventory_units => inventory_units)
+ shipment.stub_chain(:inventory_units, :shipped).and_return(shipped_inventory_units)
end
it 'should not allow quantity to be adjusted lower than already shipped units' do
From a21ad1b3da3a215c02aa0e7eeab352fb2c5ce04e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Trung=20L=C3=AA?=
Date: Fri, 31 Aug 2012 09:44:06 +1000
Subject: [PATCH 106/346] Add lambda to scopes, see reasons at
https://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/4960
---
core/app/models/spree/credit_card.rb | 2 +-
core/app/models/spree/inventory_unit.rb | 4 ++--
core/app/models/spree/payment.rb | 2 +-
core/app/models/spree/payment_method.rb | 2 +-
core/app/models/spree/preference.rb | 2 +-
core/app/models/spree/shipment.rb | 7 ++++---
core/app/models/spree/variant.rb | 4 ++--
7 files changed, 12 insertions(+), 11 deletions(-)
diff --git a/core/app/models/spree/credit_card.rb b/core/app/models/spree/credit_card.rb
index 431779f09f2..60ab085cb2f 100644
--- a/core/app/models/spree/credit_card.rb
+++ b/core/app/models/spree/credit_card.rb
@@ -63,7 +63,7 @@ def brand
cc_type
end
- scope :with_payment_profile, where('gateway_customer_profile_id IS NOT NULL')
+ scope :with_payment_profile, lambda { where('gateway_customer_profile_id IS NOT NULL') }
def actions
%w{capture void credit}
diff --git a/core/app/models/spree/inventory_unit.rb b/core/app/models/spree/inventory_unit.rb
index 50f19e0e4c3..c12905fe155 100644
--- a/core/app/models/spree/inventory_unit.rb
+++ b/core/app/models/spree/inventory_unit.rb
@@ -5,8 +5,8 @@ class InventoryUnit < ActiveRecord::Base
belongs_to :shipment
belongs_to :return_authorization
- scope :backordered, where(:state => 'backordered')
- scope :shipped, where(:state => 'shipped')
+ scope :backordered, lambda { where(:state => 'backordered') }
+ scope :shipped, lambda { where(:state => 'shipped') }
def self.backorder
warn "[SPREE] Spree::InventoryUnit.backorder will be deprecated in Spree 1.3. Please use Spree::Product.backordered instead."
diff --git a/core/app/models/spree/payment.rb b/core/app/models/spree/payment.rb
index 61fb0c72c7e..5d2b818465c 100644
--- a/core/app/models/spree/payment.rb
+++ b/core/app/models/spree/payment.rb
@@ -18,7 +18,7 @@ class Payment < ActiveRecord::Base
attr_accessible :amount, :payment_method_id, :source_attributes
- scope :from_credit_card, where(:source_type => 'Spree::CreditCard')
+ scope :from_credit_card, lambda { where(:source_type => 'Spree::CreditCard') }
scope :with_state, lambda { |s| where(:state => s) }
scope :completed, with_state('completed')
scope :pending, with_state('pending')
diff --git a/core/app/models/spree/payment_method.rb b/core/app/models/spree/payment_method.rb
index f74995214ad..3f3b32edeae 100644
--- a/core/app/models/spree/payment_method.rb
+++ b/core/app/models/spree/payment_method.rb
@@ -3,7 +3,7 @@ class PaymentMethod < ActiveRecord::Base
DISPLAY = [:both, :front_end, :back_end]
default_scope where(:deleted_at => nil)
- scope :production, where(:environment => 'production')
+ scope :production, lambda { where(:environment => 'production') }
attr_accessible :name, :description, :environment, :display_on, :active
diff --git a/core/app/models/spree/preference.rb b/core/app/models/spree/preference.rb
index 6e83f6cead7..ce555f088f8 100644
--- a/core/app/models/spree/preference.rb
+++ b/core/app/models/spree/preference.rb
@@ -4,7 +4,7 @@ class Spree::Preference < ActiveRecord::Base
validates :key, :presence => true
validates :value_type, :presence => true
- scope :valid, where(Spree::Preference.arel_table[:key].not_eq(nil)).where(Spree::Preference.arel_table[:value_type].not_eq(nil))
+ scope :valid, lambda { where(Spree::Preference.arel_table[:key].not_eq(nil)).where(Spree::Preference.arel_table[:value_type].not_eq(nil)) }
# The type conversions here should match
# the ones in spree::preferences::preferrable#convert_preference_value
diff --git a/core/app/models/spree/shipment.rb b/core/app/models/spree/shipment.rb
index 2c6b727061c..c91bafbe234 100644
--- a/core/app/models/spree/shipment.rb
+++ b/core/app/models/spree/shipment.rb
@@ -26,9 +26,10 @@ class Shipment < ActiveRecord::Base
make_permalink :field => :number
- scope :shipped, where(:state => 'shipped')
- scope :ready, where(:state => 'ready')
- scope :pending, where(:state => 'pending')
+ scope :with_state, lambda { |s| where(:state => s) }
+ scope :shipped, with_state('shipped')
+ scope :ready, with_state('ready')
+ scope :pending, with_state('pending')
def to_param
number if number
diff --git a/core/app/models/spree/variant.rb b/core/app/models/spree/variant.rb
index 795487afcca..20da446f7cc 100644
--- a/core/app/models/spree/variant.rb
+++ b/core/app/models/spree/variant.rb
@@ -24,8 +24,8 @@ class Variant < ActiveRecord::Base
after_save :recalculate_product_on_hand, :if => :is_master?
# default variant scope only lists non-deleted variants
- scope :active, where(:deleted_at => nil)
- scope :deleted, where('deleted_at IS NOT NULL')
+ scope :active, lambda { where(:deleted_at => nil) }
+ scope :deleted, lambda { where('deleted_at IS NOT NULL') }
# Returns number of inventory units for this variant (new records haven't been saved to database, yet)
def on_hand
From a7cf3e721da8963ef010584f795db72503f70bec Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Trung=20L=C3=AA?=
Date: Fri, 31 Aug 2012 22:32:45 +1000
Subject: [PATCH 107/346] Optimize
Spree::LineItem#quantity_no_less_than_shipped
---
core/app/models/spree/line_item.rb | 2 +-
core/spec/models/line_item_spec.rb | 3 ++-
2 files changed, 3 insertions(+), 2 deletions(-)
diff --git a/core/app/models/spree/line_item.rb b/core/app/models/spree/line_item.rb
index c4eb9787174..0585ddc75cb 100644
--- a/core/app/models/spree/line_item.rb
+++ b/core/app/models/spree/line_item.rb
@@ -97,7 +97,7 @@ def stock_availability
end
def quantity_no_less_than_shipped
- already_shipped = order.shipments.reduce(0) { |acc,s| acc + s.inventory_units.shipped.select { |i| i.variant == variant }.count }
+ already_shipped = order.shipments.reduce(0) { |acc, s| acc + s.inventory_units.shipped.where(:variant_id => variant_id).count }
unless quantity >= already_shipped
errors.add(:quantity, I18n.t('validation.cannot_be_less_than_shipped_units'))
end
diff --git a/core/spec/models/line_item_spec.rb b/core/spec/models/line_item_spec.rb
index 7bb004aa86f..3d3d23e8bf1 100644
--- a/core/spec/models/line_item_spec.rb
+++ b/core/spec/models/line_item_spec.rb
@@ -191,7 +191,8 @@
inventory_units = shipped_inventory_units + unshipped_inventory_units
order.stub(:shipments => [shipment])
shipment.stub(:inventory_units => inventory_units)
- shipment.stub_chain(:inventory_units, :shipped).and_return(shipped_inventory_units)
+ inventory_units.stub(:shipped => shipped_inventory_units)
+ shipped_inventory_units.stub(:where).with(:variant_id => line_item.variant_id).and_return(shipped_inventory_units)
end
it 'should not allow quantity to be adjusted lower than already shipped units' do
From 1a9b25c0a4232f02f25ab0d7bc80250e045bf8fa Mon Sep 17 00:00:00 2001
From: Brian Quinn
Date: Mon, 3 Sep 2012 19:32:17 +0100
Subject: [PATCH 108/346] Lock all adjustments (not just mandatory ones) on
checkout completion
---
core/app/models/spree/order.rb | 4 ++--
core/spec/models/order_spec.rb | 10 ++++++----
2 files changed, 8 insertions(+), 6 deletions(-)
diff --git a/core/app/models/spree/order.rb b/core/app/models/spree/order.rb
index 2b976cd2a0d..d53d8f9145d 100644
--- a/core/app/models/spree/order.rb
+++ b/core/app/models/spree/order.rb
@@ -350,8 +350,8 @@ def credit_cards
def finalize!
touch :completed_at
InventoryUnit.assign_opening_inventory(self)
- # lock any optional adjustments (coupon promotions, etc.)
- adjustments.optional.each { |adjustment| adjustment.update_column('locked', true) }
+ # lock all adjustments (coupon promotions, etc.)
+ adjustments.each { |adjustment| adjustment.update_column('locked', true) }
deliver_order_confirmation_email
self.state_changes.create({
diff --git a/core/spec/models/order_spec.rb b/core/spec/models/order_spec.rb
index fdbe7107a65..b099df405b5 100644
--- a/core/spec/models/order_spec.rb
+++ b/core/spec/models/order_spec.rb
@@ -106,11 +106,13 @@ def compute(computable)
order.finalize!
end
- it "should freeze optional adjustments" do
+ it "should freeze all adjustments" do
Spree::OrderMailer.stub_chain :confirm_email, :deliver
- adjustment = mock_model(Spree::Adjustment)
- order.stub_chain :adjustments, :optional => [adjustment]
- adjustment.should_receive(:update_column).with("locked", true)
+ adjustment1 = mock_model(Spree::Adjustment, :mandatory => true)
+ adjustment2 = mock_model(Spree::Adjustment, :mandatory => false)
+ order.stub :adjustments => [adjustment1, adjustment2]
+ adjustment1.should_receive(:update_column).with("locked", true)
+ adjustment2.should_receive(:update_column).with("locked", true)
order.finalize!
end
From a46455afd8e4691aaf789b4639da8967277f1916 Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Tue, 4 Sep 2012 12:43:23 +0100
Subject: [PATCH 109/346] Show currently selected currency in
general_settings/edit
---
core/app/helpers/spree/admin/general_settings_helper.rb | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/core/app/helpers/spree/admin/general_settings_helper.rb b/core/app/helpers/spree/admin/general_settings_helper.rb
index 9277f130e63..733c5be2547 100644
--- a/core/app/helpers/spree/admin/general_settings_helper.rb
+++ b/core/app/helpers/spree/admin/general_settings_helper.rb
@@ -6,7 +6,7 @@ def currency_options
iso = details[:iso_code]
[iso, "#{details[:name]} (#{iso})"]
end
- options_from_collection_for_select(currencies, :first, :last)
+ options_from_collection_for_select(currencies, :first, :last, Spree::Config[:currency])
end
end
end
From d7082eec2e37c342e0ed64f4259eb1758592a188 Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Sun, 2 Sep 2012 11:48:00 +0100
Subject: [PATCH 110/346] Remove ruby-debug and ruby-debug19 mentions from
common_spree_dependencies
---
common_spree_dependencies.rb | 8 --------
1 file changed, 8 deletions(-)
diff --git a/common_spree_dependencies.rb b/common_spree_dependencies.rb
index cdbb0710cbf..6dd7f708c66 100644
--- a/common_spree_dependencies.rb
+++ b/common_spree_dependencies.rb
@@ -31,14 +31,6 @@
# gem 'debugger'
end
-# platform :ruby_18 do
-# gem "ruby-debug"
-# end
-
-# platform :ruby_19 do
-# gem "ruby-debug19"
-# end
-
gemspec
From 575af696f39f9ea408fc9f4082bccff4e7fa4e05 Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Tue, 4 Sep 2012 12:19:29 +0100
Subject: [PATCH 111/346] Add :currency_symbol_position config setting
This will address the issue brought up #1911, where the currency symbol was incorrectly being placed before the amount
---
core/app/models/spree/app_configuration.rb | 1 +
core/lib/spree/money.rb | 1 +
core/spec/lib/money_spec.rb | 44 ++++++++++++++++++++++
3 files changed, 46 insertions(+)
create mode 100644 core/spec/lib/money_spec.rb
diff --git a/core/app/models/spree/app_configuration.rb b/core/app/models/spree/app_configuration.rb
index f4e2b29e699..3a355b11b29 100644
--- a/core/app/models/spree/app_configuration.rb
+++ b/core/app/models/spree/app_configuration.rb
@@ -42,6 +42,7 @@ class AppConfiguration < Preferences::Configuration
preference :company, :boolean, :default => false # Request company field for billing and shipping addr
preference :create_inventory_units, :boolean, :default => true # should only be false when track_inventory_levels is false, also disables RMA's
preference :currency, :string, :default => "USD"
+ preference :currency_symbol_position, :string, :default => "before"
preference :display_currency, :boolean, :default => false
preference :default_country_id, :integer, :default => 214
preference :default_locale, :string, :default => Rails.application.config.i18n.default_locale || :en
diff --git a/core/lib/spree/money.rb b/core/lib/spree/money.rb
index 857658a773d..ee4c4ae60d7 100644
--- a/core/lib/spree/money.rb
+++ b/core/lib/spree/money.rb
@@ -6,6 +6,7 @@ def initialize(amount, options={})
@money = ::Money.new(amount * 100, Spree::Config[:currency])
@options = {}
@options[:with_currency] = true if Spree::Config[:display_currency]
+ @options[:symbol_position] = Spree::Config[:currency_symbol_position].to_sym
@options.merge!(options)
end
diff --git a/core/spec/lib/money_spec.rb b/core/spec/lib/money_spec.rb
new file mode 100644
index 00000000000..be5ae552e0d
--- /dev/null
+++ b/core/spec/lib/money_spec.rb
@@ -0,0 +1,44 @@
+require 'spec_helper'
+
+module Spree
+ describe Money do
+ before do
+ reset_spree_preferences do |config|
+ config.currency = "USD"
+ config.currency_symbol_position = :before
+ config.display_currency = false
+ end
+ end
+
+ it "formats correctly" do
+ money = Spree::Money.new(10)
+ money.to_s.should == "$10.00"
+ end
+
+ context "with currency" do
+ it "passed in option" do
+ money = Spree::Money.new(10, :with_currency => true)
+ money.to_s.should == "$10.00 USD"
+ end
+
+ it "config option" do
+ Spree::Config[:display_currency] = true
+ money = Spree::Money.new(10)
+ money.to_s.should == "$10.00 USD"
+ end
+ end
+
+ context "symbol positioning" do
+ it "passed in option" do
+ money = Spree::Money.new(10, :symbol_position => :after)
+ money.to_s.should == "10.00 $"
+ end
+
+ it "config option" do
+ Spree::Config[:currency_symbol] = :after
+ money = Spree::Money.new(10)
+ money.to_s.should == "10.00 $"
+ end
+ end
+ end
+end
From 47a0719187bf7fbc813455d06c1c28927d7add36 Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Tue, 4 Sep 2012 12:43:34 +0100
Subject: [PATCH 112/346] Allow for currency_symbol_position to be customized
in admin settings
---
.../spree/admin/general_settings/edit.html.erb | 17 +++++++++++++----
core/config/locales/en.yml | 1 +
core/lib/spree/money.rb | 2 ++
core/spec/lib/money_spec.rb | 7 ++++++-
4 files changed, 22 insertions(+), 5 deletions(-)
diff --git a/core/app/views/spree/admin/general_settings/edit.html.erb b/core/app/views/spree/admin/general_settings/edit.html.erb
index 38f803e7dbc..eea52c8f202 100644
--- a/core/app/views/spree/admin/general_settings/edit.html.erb
+++ b/core/app/views/spree/admin/general_settings/edit.html.erb
@@ -10,10 +10,19 @@
<%= preference_field_tag(key, Spree::Config[key], :type => type) %>
<%= label_tag(key, t(key)) + tag(:br) if type == :boolean %>
<% end %>
-
- <%= label_tag :currency, t(:currency) %>
- <%= select_tag :currency, currency_options %>
-
+
+
+ <%= label_tag :currency, t(:currency) %>
+ <%= select_tag :currency, currency_options %>
+
+
+
+ <%= t(:currency_symbol_position) %>
+ <%= radio_button_tag :currency_symbol_position, "before" %>
+ <%= label_tag :currency_symbol_position_before, Spree::Money.new(10, :symbol_position => "before") %>
+ <%= radio_button_tag :currency_symbol_position, "after" %>
+ <%= label_tag :currency_symbol_position_after, Spree::Money.new(10, :symbol_position => "after") %>
+
diff --git a/core/config/locales/en.yml b/core/config/locales/en.yml
index 63435257466..095f8fee3cd 100644
--- a/core/config/locales/en.yml
+++ b/core/config/locales/en.yml
@@ -335,6 +335,7 @@ en:
credits: Credits
current: Current
currency: Currency
+ currency_symbol_position: "Put currency symbol before or after dollar amount?"
customer: Customer
customer_details: "Customer Details"
customer_details_updated: "The customer's details have been updated."
diff --git a/core/lib/spree/money.rb b/core/lib/spree/money.rb
index ee4c4ae60d7..17a5bbfdf4c 100644
--- a/core/lib/spree/money.rb
+++ b/core/lib/spree/money.rb
@@ -8,6 +8,8 @@ def initialize(amount, 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
diff --git a/core/spec/lib/money_spec.rb b/core/spec/lib/money_spec.rb
index be5ae552e0d..7da6c965438 100644
--- a/core/spec/lib/money_spec.rb
+++ b/core/spec/lib/money_spec.rb
@@ -34,8 +34,13 @@ module Spree
money.to_s.should == "10.00 $"
end
+ it "passed in option string" do
+ money = Spree::Money.new(10, :symbol_position => "after")
+ money.to_s.should == "10.00 $"
+ end
+
it "config option" do
- Spree::Config[:currency_symbol] = :after
+ Spree::Config[:currency_symbol_position] = :after
money = Spree::Money.new(10)
money.to_s.should == "10.00 $"
end
From 829bff85ea22d7274cbec0dc940531fda5548223 Mon Sep 17 00:00:00 2001
From: John Dyer
Date: Tue, 4 Sep 2012 10:35:23 -0400
Subject: [PATCH 113/346] Check for existence of variant_images in _thumbnails
partial
---
core/app/views/spree/products/_thumbnails.html.erb | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/core/app/views/spree/products/_thumbnails.html.erb b/core/app/views/spree/products/_thumbnails.html.erb
index f0013afae47..a1d471db7c7 100644
--- a/core/app/views/spree/products/_thumbnails.html.erb
+++ b/core/app/views/spree/products/_thumbnails.html.erb
@@ -1,5 +1,5 @@
-<% if product.images.size > 1 %>
+<% if product.images.size > 1 || product.variant_images.size > 0 %>
<% product.images.each do |i| %>
<%= link_to image_tag(i.attachment.url(:mini)), i.attachment.url(:product) %>
From bdf6f29e3ee2046cdc48d1982b980cbda74c14f9 Mon Sep 17 00:00:00 2001
From: alininja
Date: Sat, 1 Sep 2012 16:12:13 -1000
Subject: [PATCH 114/346] Target correct form class name in checkout.js
Fixes #1905
---
core/app/assets/javascripts/store/checkout.js.coffee | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/core/app/assets/javascripts/store/checkout.js.coffee b/core/app/assets/javascripts/store/checkout.js.coffee
index 6e0e8ad55e7..9d9d90a6989 100644
--- a/core/app/assets/javascripts/store/checkout.js.coffee
+++ b/core/app/assets/javascripts/store/checkout.js.coffee
@@ -1,5 +1,5 @@
disableSaveOnClick = ->
- ($ 'form.edit_spree_order').submit ->
+ ($ 'form.edit_order').submit ->
($ this).find(':submit, :image').attr('disabled', true).removeClass('primary').addClass 'disabled'
$ ->
From dbb0c56a60a91a6c080e9760399943c6f4466d05 Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Wed, 5 Sep 2012 13:26:46 +0100
Subject: [PATCH 115/346] Freeze to kaminari 0.13.0 until amatsuda/kaminari#280
is fixed
---
core/spree_core.gemspec | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/core/spree_core.gemspec b/core/spree_core.gemspec
index 27a80d793ad..655a3d2d138 100644
--- a/core/spree_core.gemspec
+++ b/core/spree_core.gemspec
@@ -32,7 +32,7 @@ Gem::Specification.new do |s|
s.add_dependency 'ransack', '~> 0.7.0'
s.add_dependency 'activemerchant', '= 1.28.0'
s.add_dependency 'rails', '~> 3.2.8'
- s.add_dependency 'kaminari', '>= 0.13.0'
+ s.add_dependency 'kaminari', '0.13.0'
s.add_dependency 'deface', '>= 0.9.0'
s.add_dependency 'stringex', '~> 1.3.2'
s.add_dependency 'cancan', '1.6.7'
From fc6510558e5df4eae7314438d907ab62884b7bba Mon Sep 17 00:00:00 2001
From: Felix Buenemann
Date: Sat, 1 Sep 2012 05:13:15 +0300
Subject: [PATCH 116/346] Fix postgres orphaned preferences SQL
Quoting fields/reserved keywords with backticks is only allowed in MySQL,
while single quotes are supported by both databases.
Fixes #1904
---
core/config/initializers/check_for_orphaned_preferences.rb | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/core/config/initializers/check_for_orphaned_preferences.rb b/core/config/initializers/check_for_orphaned_preferences.rb
index c0311dc4b62..2ae156879f7 100644
--- a/core/config/initializers/check_for_orphaned_preferences.rb
+++ b/core/config/initializers/check_for_orphaned_preferences.rb
@@ -1,5 +1,5 @@
begin
- ActiveRecord::Base.connection.execute("select owner_id, owner_type, name, value from spree_preferences where `key` is null").each do |pref|
+ ActiveRecord::Base.connection.execute("select owner_id, owner_type, name, value from spree_preferences where 'key' is null").each do |pref|
warn "[WARNING] Orphaned preference `#{pref[2]}` with value `#{pref[3]}` for #{pref[1]} with id of: #{pref[0]}, you should reset the preference value manually."
end
rescue
From 6c9d21fddcc2593e22011043e544c18e431e3963 Mon Sep 17 00:00:00 2001
From: Spencer Steffen
Date: Mon, 4 Jun 2012 12:43:45 -0700
Subject: [PATCH 117/346] add percent per item calculator to promotions
Fixes #1604
---
.../spree/calculator/percent_per_item.rb | 48 +++++++++++++++++++
promo/config/locales/en.yml | 1 +
promo/lib/spree/promo/engine.rb | 1 +
.../calculator/percent_per_item_spec.rb | 37 ++++++++++++++
4 files changed, 87 insertions(+)
create mode 100644 promo/app/models/spree/calculator/percent_per_item.rb
create mode 100644 promo/spec/models/calculator/percent_per_item_spec.rb
diff --git a/promo/app/models/spree/calculator/percent_per_item.rb b/promo/app/models/spree/calculator/percent_per_item.rb
new file mode 100644
index 00000000000..d49bfa2ae22
--- /dev/null
+++ b/promo/app/models/spree/calculator/percent_per_item.rb
@@ -0,0 +1,48 @@
+module Spree
+
+ # A calculator for promotions that calculates a percent-off discount
+ # for all matching products in an order. This should not be used as a
+ # shipping calculator since it would be the same thing as a flat percent
+ # off the entire order.
+
+ class Calculator::PercentPerItem < Calculator
+ preference :percent, :decimal, :default => 0
+
+ attr_accessible :preferred_percent
+
+ def self.description
+ I18n.t(:percent_per_item)
+ end
+
+ def compute(object=nil)
+ return 0 if object.nil?
+ object.line_items.reduce(0) do |sum, line_item|
+ sum += value_for_line_item(line_item)
+ end
+ end
+
+ private
+
+ # Returns all products that match the promotion's rule.
+ def matching_products
+ @matching_products ||= if compute_on_promotion?
+ self.calculable.promotion.rules.map(&:products).flatten
+ end
+ end
+
+ # Calculates the discount value of each line item. Returns zero
+ # unless the product is included in the promotion rules.
+ def value_for_line_item(line_item)
+ if compute_on_promotion?
+ return 0 unless matching_products.include?(line_item.product)
+ end
+ line_item.price * line_item.quantity * preferred_percent
+ end
+
+ # Determines wether or not the calculable object is a promotion
+ def compute_on_promotion?
+ @compute_on_promotion ||= self.calculable.respond_to?(:promotion)
+ end
+
+ end
+end
diff --git a/promo/config/locales/en.yml b/promo/config/locales/en.yml
index a39b162b620..195aead439e 100644
--- a/promo/config/locales/en.yml
+++ b/promo/config/locales/en.yml
@@ -34,6 +34,7 @@ en:
path: Path
new_promotion: New Promotion
no_rules_added: No rules added
+ percent_per_item: Percent Per Item
product_rule:
choose_products: Choose products
label: "Order must contain %{select} of these products"
diff --git a/promo/lib/spree/promo/engine.rb b/promo/lib/spree/promo/engine.rb
index d93dad44dac..2ce1ac1a148 100644
--- a/promo/lib/spree/promo/engine.rb
+++ b/promo/lib/spree/promo/engine.rb
@@ -33,6 +33,7 @@ def default_notification_payload
Spree::Calculator::FlatRate,
Spree::Calculator::FlexiRate,
Spree::Calculator::PerItem,
+ Spree::Calculator::PercentPerItem,
Spree::Calculator::FreeShipping
]
end
diff --git a/promo/spec/models/calculator/percent_per_item_spec.rb b/promo/spec/models/calculator/percent_per_item_spec.rb
new file mode 100644
index 00000000000..75b23e8da91
--- /dev/null
+++ b/promo/spec/models/calculator/percent_per_item_spec.rb
@@ -0,0 +1,37 @@
+require 'spec_helper'
+
+describe Spree::Calculator::PercentPerItem do
+ # Like an order object, but not quite...
+ let!(:product1) { double("Product") }
+ let!(:product2) { double("Product") }
+ let!(:line_items) { [double("LineItem", :quantity => 5, :product => product1, :price => 10), double("LineItem", :quantity => 1, :product => product2, :price => 10)] }
+ let!(:object) { double("Order", :line_items => line_items) }
+
+ let!(:promotion_calculable) { double("Calculable", :promotion => promotion) }
+
+ let!(:promotion) { double("Promotion", :rules => [double("Rule", :products => [product1])]) }
+
+ let!(:calculator) { Spree::Calculator::PercentPerItem.new(:preferred_percent => 0.25) }
+
+ it "has a translation for description" do
+ calculator.description.should_not include("translation missing")
+ calculator.description.should == I18n.t(:percent_per_item)
+ end
+
+ it "correctly calculates per item promotion" do
+ calculator.stub(:calculable => promotion_calculable)
+ calculator.compute(object).to_f.should == 12.5 # 5 x 10 x 0.25 since only product1 is included in the promotion rule
+ end
+
+ it "returns 0 when no object passed" do
+ calculator.stub(:calculable => promotion_calculable)
+ calculator.compute.should == 0
+ end
+
+ it "computes on promotion when promotion is present" do
+ calculator.send(:compute_on_promotion?).should_not be_true
+ calculator.stub(:calculable => promotion_calculable)
+ calculator.send(:compute_on_promotion?).should be_true
+ end
+
+end
From 72be9d18a5ac443caec8c036d3af3ecf244393d9 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Trung=20L=C3=AA?=
Date: Thu, 6 Sep 2012 08:55:33 +1000
Subject: [PATCH 118/346] Upcase SQL syntax
---
core/config/initializers/check_for_orphaned_preferences.rb | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/core/config/initializers/check_for_orphaned_preferences.rb b/core/config/initializers/check_for_orphaned_preferences.rb
index 2ae156879f7..5a3204bd249 100644
--- a/core/config/initializers/check_for_orphaned_preferences.rb
+++ b/core/config/initializers/check_for_orphaned_preferences.rb
@@ -1,5 +1,5 @@
begin
- ActiveRecord::Base.connection.execute("select owner_id, owner_type, name, value from spree_preferences where 'key' is null").each do |pref|
+ ActiveRecord::Base.connection.execute("SELECT owner_id, owner_type, name, value FROM spree_preferences WHERE 'key' IS NULL").each do |pref|
warn "[WARNING] Orphaned preference `#{pref[2]}` with value `#{pref[3]}` for #{pref[1]} with id of: #{pref[0]}, you should reset the preference value manually."
end
rescue
From 1e60ecd10538a869be75339dbc3bc146aaae749f Mon Sep 17 00:00:00 2001
From: Peter Berkenbosch
Date: Thu, 30 Aug 2012 19:38:01 +0200
Subject: [PATCH 119/346] move authorization_helpers to testing_support so
other extensions can stub the authorization. added the authorization_helpers
by default to the generated spec_helper for extensions.
Fixes #1902
---
.../extension/spec/spec_helper.rb.tt | 3 ++
.../testing_support}/authorization_helpers.rb | 2 +-
core/spec/spec_helper.rb | 2 ++
promo/spec/spec_helper.rb | 1 +
promo/spec/support/authorization_helpers.rb | 30 -------------------
5 files changed, 7 insertions(+), 31 deletions(-)
rename core/{spec/support => lib/spree/core/testing_support}/authorization_helpers.rb (99%)
delete mode 100644 promo/spec/support/authorization_helpers.rb
diff --git a/cmd/lib/spree_cmd/templates/extension/spec/spec_helper.rb.tt b/cmd/lib/spree_cmd/templates/extension/spec/spec_helper.rb.tt
index 8d6355dee89..2bc8b0923d4 100644
--- a/cmd/lib/spree_cmd/templates/extension/spec/spec_helper.rb.tt
+++ b/cmd/lib/spree_cmd/templates/extension/spec/spec_helper.rb.tt
@@ -12,6 +12,9 @@ Dir[File.join(File.dirname(__FILE__), 'support/**/*.rb')].each { |f| require f }
# Requires factories defined in spree_core
require 'spree/core/testing_support/factories'
+require 'spree/core/testing_support/env'
+require 'spree/core/testing_support/controller_requests'
+require 'spree/core/testing_support/authorization_helpers'
require 'spree/core/url_helpers'
RSpec.configure do |config|
diff --git a/core/spec/support/authorization_helpers.rb b/core/lib/spree/core/testing_support/authorization_helpers.rb
similarity index 99%
rename from core/spec/support/authorization_helpers.rb
rename to core/lib/spree/core/testing_support/authorization_helpers.rb
index 48fd74518a2..cb40b9c3bc0 100644
--- a/core/spec/support/authorization_helpers.rb
+++ b/core/lib/spree/core/testing_support/authorization_helpers.rb
@@ -27,4 +27,4 @@ def stub_authorization!
RSpec.configure do |config|
config.extend AuthorizationHelpers::Controller, :type => :controller
config.extend AuthorizationHelpers::Request, :type => :request
-end
+end
\ No newline at end of file
diff --git a/core/spec/spec_helper.rb b/core/spec/spec_helper.rb
index b9cf369b504..83505cd3360 100644
--- a/core/spec/spec_helper.rb
+++ b/core/spec/spec_helper.rb
@@ -12,6 +12,8 @@
require 'spree/core/testing_support/factories'
require 'spree/core/testing_support/env'
require 'spree/core/testing_support/controller_requests'
+require 'spree/core/testing_support/authorization_helpers'
+
require 'spree/core/url_helpers'
require 'paperclip/matchers'
diff --git a/promo/spec/spec_helper.rb b/promo/spec/spec_helper.rb
index 1ed7f954306..23f2c24e1b4 100644
--- a/promo/spec/spec_helper.rb
+++ b/promo/spec/spec_helper.rb
@@ -13,6 +13,7 @@
require 'spree/core/testing_support/factories'
require 'spree/core/testing_support/env'
+require 'spree/core/testing_support/authorization_helpers'
require 'factories'
require 'active_record/fixtures'
diff --git a/promo/spec/support/authorization_helpers.rb b/promo/spec/support/authorization_helpers.rb
deleted file mode 100644
index 48fd74518a2..00000000000
--- a/promo/spec/support/authorization_helpers.rb
+++ /dev/null
@@ -1,30 +0,0 @@
-module AuthorizationHelpers
- module Controller
- def stub_authorization!
- before do
- controller.should_receive(:authorize!).twice.and_return(true)
- end
- end
- end
-
- module Request
- class SuperAbility
- include CanCan::Ability
-
- def initialize(user)
- # allow anyone to perform index on Order
- can :manage, :all
- end
- end
-
- def stub_authorization!
- before(:all) { Spree::Ability.register_ability(AuthorizationHelpers::Request::SuperAbility) }
- after(:all) { Spree::Ability.remove_ability(AuthorizationHelpers::Request::SuperAbility) }
- end
- end
-end
-
-RSpec.configure do |config|
- config.extend AuthorizationHelpers::Controller, :type => :controller
- config.extend AuthorizationHelpers::Request, :type => :request
-end
From 3358d3ee7967213de28ea123a0625609a656a405 Mon Sep 17 00:00:00 2001
From: Nicholas Frandsen
Date: Thu, 6 Sep 2012 14:38:34 +0200
Subject: [PATCH 120/346] awesome_nested_set is an optimised replacement for
acts_as_nested_set. Upgrading to awesome_nested_set is backwards compatible
and it allows refinery (which uses awesome_nested_set) to be mounted
alongside spree
Fixes #1927
---
core/lib/spree/core.rb | 4 ++--
core/spree_core.gemspec | 2 +-
2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/core/lib/spree/core.rb b/core/lib/spree/core.rb
index 9526d2a129b..fece4c74547 100644
--- a/core/lib/spree/core.rb
+++ b/core/lib/spree/core.rb
@@ -31,7 +31,7 @@
require 'state_machine'
require 'paperclip'
require 'kaminari'
-require 'nested_set'
+require 'awesome_nested_set'
require 'acts_as_list'
require 'active_merchant'
require 'ransack'
@@ -105,7 +105,7 @@ def self.config(&block)
end
if defined?(ActionView)
- require 'nested_set/helper'
+ require 'awesome_nested_set/helper'
ActionView::Base.class_eval do
include CollectiveIdea::Acts::NestedSet::Helper
end
diff --git a/core/spree_core.gemspec b/core/spree_core.gemspec
index 655a3d2d138..8cbdd9f400d 100644
--- a/core/spree_core.gemspec
+++ b/core/spree_core.gemspec
@@ -19,7 +19,7 @@ Gem::Specification.new do |s|
s.requirements << 'none'
s.add_dependency 'acts_as_list', '= 0.1.4'
- s.add_dependency 'nested_set', '= 1.7.0'
+ s.add_dependency 'awesome_nested_set', '2.1.4'
s.add_dependency 'jquery-rails', '~> 2.0'
s.add_dependency 'select2-rails', '0.0.9'
From 0ba5fa4840b7bbee60c881dcaa1fd97359961ab9 Mon Sep 17 00:00:00 2001
From: Chris Wise
Date: Thu, 6 Sep 2012 15:27:53 -0400
Subject: [PATCH 121/346] corrected a typo in accurate_title method that was
introduced in commit cb19a45209
Fixes #1928
---
core/app/controllers/spree/orders_controller.rb | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/core/app/controllers/spree/orders_controller.rb b/core/app/controllers/spree/orders_controller.rb
index d4999858417..801b897861c 100644
--- a/core/app/controllers/spree/orders_controller.rb
+++ b/core/app/controllers/spree/orders_controller.rb
@@ -64,7 +64,7 @@ def empty
redirect_to spree.cart_path
end
- def accurate_titles
+ def accurate_title
@order && @order.completed? ? "#{Order.model_name.human} #{@order.number}" : t(:shopping_cart)
end
end
From ba4056952e6660ef1a221cd48d7f3cbea17f4833 Mon Sep 17 00:00:00 2001
From: Andrew Hooker
Date: Wed, 5 Sep 2012 14:33:16 -0500
Subject: [PATCH 122/346] Allow manually calling save_permalink with a value to
recalculate
Fixes #1920
---
core/lib/spree/core/permalinks.rb | 3 +--
core/spec/models/product_spec.rb | 23 +++++++++++++++++++++++
2 files changed, 24 insertions(+), 2 deletions(-)
diff --git a/core/lib/spree/core/permalinks.rb b/core/lib/spree/core/permalinks.rb
index fb8a2b45416..094223cfcce 100644
--- a/core/lib/spree/core/permalinks.rb
+++ b/core/lib/spree/core/permalinks.rb
@@ -39,8 +39,7 @@ def permalink_order
end
end
- def save_permalink
- permalink_value = self.to_param
+ def save_permalink(permalink_value=self.to_param)
field = self.class.permalink_field
# Do other links exist with this permalink?
other = self.class.where("#{field} LIKE ?", "#{permalink_value}%")
diff --git a/core/spec/models/product_spec.rb b/core/spec/models/product_spec.rb
index 59b776b6523..ca89005d616 100644
--- a/core/spec/models/product_spec.rb
+++ b/core/spec/models/product_spec.rb
@@ -199,6 +199,29 @@
end
end
+ context "manual permalink override" do
+ it "calling save_permalink with a parameter" do
+ @product = create(:product, :name => "foo")
+ @product.permalink.should == "foo"
+ @product.name = "foobar"
+ @product.save
+ @product.permalink.should == "foo"
+ @product.save_permalink(@product.name)
+ @product.permalink.should == "foobar"
+ end
+
+ it "should be incremented until not taken with a parameter" do
+ @product = create(:product, :name => "foo")
+ @product2 = create(:product, :name => "foobar")
+ @product.permalink.should == "foo"
+ @product.name = "foobar"
+ @product.save
+ @product.permalink.should == "foo"
+ @product.save_permalink(@product.name)
+ @product.permalink.should == "foobar-1"
+ end
+ end
+
context "properties" do
it "should properly assign properties" do
product = FactoryGirl.create :product
From c5194101a318c2fc8a5602bb3f0f0445ae730be7 Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Fri, 7 Sep 2012 12:53:43 +0100
Subject: [PATCH 123/346] Remove disclaimer for master branch from 1-2-stable's
README
---
README.md | 3 ---
1 file changed, 3 deletions(-)
diff --git a/README.md b/README.md
index 5f758b2300f..e3cbefaae9b 100644
--- a/README.md
+++ b/README.md
@@ -1,6 +1,3 @@
-**THIS README IS FOR THE MASTER BRANCH OF SPREE AND REFLECTS THE WORK CURRENTLY EXISTING ON THE MASTER BRANCH. IF YOU ARE WISHING TO USE A NON-MASTER BRANCH OF
-SPREE, PLEASE CONSULT THAT BRANCH'S README AND NOT THIS ONE.**
-
SUMMARY
-------
From 886f5635a51b8a17ffc113ceef3706e2c1c7384a Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Fri, 31 Aug 2012 15:12:03 +0100
Subject: [PATCH 124/346] Fixed order/customer_details_spec
This spec was failing due to the renamed Spree::User class (to Spree::LegacyUser)
respond_to is stupid and doesn't have an option to force the root node name, so we bring Rabl in to help us out there (see search/users.rabl template).
The test itself needed some cosmetic changes also, but nothing too major.
---
api/spree_api.gemspec | 1 -
.../javascripts/admin/checkouts/edit.js | 4 +-
.../spree/admin/search_controller.rb | 24 ---------
core/app/views/spree/admin/search/users.rabl | 32 ++++++++++++
.../views/spree/admin/shared/_head.html.erb | 2 +-
core/lib/spree/core.rb | 1 +
.../admin/orders/customer_details_spec.rb | 49 +++++++++++--------
core/spree_core.gemspec | 1 +
8 files changed, 65 insertions(+), 49 deletions(-)
create mode 100644 core/app/views/spree/admin/search/users.rabl
diff --git a/api/spree_api.gemspec b/api/spree_api.gemspec
index 3d42a469866..3596f6ee847 100644
--- a/api/spree_api.gemspec
+++ b/api/spree_api.gemspec
@@ -16,7 +16,6 @@ Gem::Specification.new do |gem|
gem.version = version
gem.add_dependency 'spree_core', version
- gem.add_dependency 'rabl', '0.6.5'
gem.add_development_dependency 'rspec-rails', '2.9.0'
gem.add_development_dependency 'database_cleaner'
diff --git a/core/app/assets/javascripts/admin/checkouts/edit.js b/core/app/assets/javascripts/admin/checkouts/edit.js
index 6d9c407de93..f89f72798a9 100644
--- a/core/app/assets/javascripts/admin/checkouts/edit.js
+++ b/core/app/assets/javascripts/admin/checkouts/edit.js
@@ -33,7 +33,7 @@ $(document).ready(function(){
}
prep_user_autocomplete_data = function(data){
- return $.map(eval(data), function(row) {
+ return $.map(eval(data['users']), function(row) {
return {
data: row['user'],
value: row['user']['email'],
@@ -48,7 +48,7 @@ $(document).ready(function(){
delay: 500,
source: function(request, response) {
var params = { q: $('#customer_search').val(),
- authenticity_token: encodeURIComponent($('meta[name=csrf-token]').attr("content")) }
+ authenticity_token: AUTH_TOKEN }
$.get(Spree.routes.user_search + '&' + jQuery.param(params), function(data) {
result = prep_user_autocomplete_data(data)
response(result);
diff --git a/core/app/controllers/spree/admin/search_controller.rb b/core/app/controllers/spree/admin/search_controller.rb
index f29f876aa4b..ed21d1538e5 100644
--- a/core/app/controllers/spree/admin/search_controller.rb
+++ b/core/app/controllers/spree/admin/search_controller.rb
@@ -16,30 +16,6 @@ def users
:bill_address_firstname_start => params[:q],
:bill_address_lastname_start => params[:q]
}).result.limit(params[:limit] || 100)
-
- respond_with(@users) do |format|
- format.json do
- address_fields = [:firstname, :lastname,
- :address1, :address2,
- :city, :zipcode,
- :phone, :state_name,
- :state_id, :country_id]
- includes = {
- :only => address_fields,
- :include => {
- :state => { :only => :name },
- :country => { :only => :name }
- }
- }
-
- json = @users.to_json({
- :only => [:id, :email],
- :include => { :bill_address => includes, :ship_address => includes }
- })
-
- render :json => json
- end
- end
end
end
end
diff --git a/core/app/views/spree/admin/search/users.rabl b/core/app/views/spree/admin/search/users.rabl
new file mode 100644
index 00000000000..3b8ecc1b10d
--- /dev/null
+++ b/core/app/views/spree/admin/search/users.rabl
@@ -0,0 +1,32 @@
+object false
+child @users => :users do
+ attributes :email
+ address_fields = [:firstname, :lastname,
+ :address1, :address2,
+ :city, :zipcode,
+ :phone, :state_name,
+ :state_id, :country_id,
+ :company]
+
+ child :ship_address => :ship_address do
+ attributes *address_fields
+ child :state do
+ attributes :name
+ end
+
+ child :country do
+ attributes :name
+ end
+ end
+
+ child :bill_address => :bill_address do
+ attributes *address_fields
+ child :state do
+ attributes :name
+ end
+
+ child :country do
+ attributes :name
+ end
+ end
+end
diff --git a/core/app/views/spree/admin/shared/_head.html.erb b/core/app/views/spree/admin/shared/_head.html.erb
index 3f285f287b7..5419e342e56 100644
--- a/core/app/views/spree/admin/shared/_head.html.erb
+++ b/core/app/views/spree/admin/shared/_head.html.erb
@@ -21,7 +21,7 @@
<%= javascript_tag do -%>
jQuery.alerts.dialogClass = 'spree';
- <%== "var AUTH_TOKEN = #{form_authenticity_token.inspect};" if protect_against_forgery? %>
+ <%== "var AUTH_TOKEN = #{form_authenticity_token.inspect};" %>
<% end -%>
<%= yield :head %>
diff --git a/core/lib/spree/core.rb b/core/lib/spree/core.rb
index fece4c74547..c962bc8ebdb 100644
--- a/core/lib/spree/core.rb
+++ b/core/lib/spree/core.rb
@@ -40,6 +40,7 @@
require 'cancan'
require 'select2-rails'
require 'spree/money'
+require 'rabl'
module Spree
diff --git a/core/spec/requests/admin/orders/customer_details_spec.rb b/core/spec/requests/admin/orders/customer_details_spec.rb
index f86c30916e7..13cc49dee22 100644
--- a/core/spec/requests/admin/orders/customer_details_spec.rb
+++ b/core/spec/requests/admin/orders/customer_details_spec.rb
@@ -5,16 +5,27 @@
let(:shipping_method) { create(:shipping_method, :display_on => "front_end") }
let(:order) { create(:order_with_inventory_unit_shipped, :completed_at => 1.year.ago, :shipping_method => shipping_method) }
+ let(:country) do
+ create(:country, :name => "Kangaland")
+ end
+
+ let(:state) do
+ create(:state, :name => "Alabama", :country => country)
+ end
before do
reset_spree_preferences do |config|
- config.default_country_id = create(:country).id
+ config.default_country_id = country.id
+ config.company = true
end
create(:shipping_method, :display_on => "front_end")
create(:order_with_inventory_unit_shipped, :completed_at => "2011-02-01 12:36:15")
- create(:user, :email => 'foobar@example.com', :ship_address => create(:address), :bill_address => create(:address))
- create(:country)
+ ship_address = create(:address, :country => country, :state => state)
+ bill_address = create(:address, :country => country, :state => state)
+ create(:user, :email => 'foobar@example.com',
+ :ship_address => ship_address,
+ :bill_address => bill_address)
visit spree.admin_path
click_link "Orders"
@@ -23,11 +34,9 @@
context "editing an order", :js => true do
it "should be able to populate customer details for an existing order" do
- pending "Waiting on Jones Lee to fix customer searching"
click_link "Customer Details"
fill_in "customer_search", :with => "foobar"
sleep(3)
-
page.execute_script %Q{ $('.ui-menu-item a:contains("foobar@example.com")').trigger("mouseenter").click(); }
["ship_address", "bill_address"].each do |address|
@@ -38,32 +47,30 @@
find_field("order_#{address}_attributes_address2").value.should == "Northwest"
find_field("order_#{address}_attributes_city").value.should == "Herndon"
find_field("order_#{address}_attributes_zipcode").value.should == "20170"
- find_field("order_#{address}_attributes_state_id").find('option[selected]').text.should == "Alabama"
- find_field("order_#{address}_attributes_country_id").find('option[selected]').text.should == "United States"
+ find_field("order_#{address}_attributes_state_id").value.should == state.id.to_s
+ find_field("order_#{address}_attributes_country_id").value.should == country.id.to_s
find_field("order_#{address}_attributes_phone").value.should == "123-456-7890"
end
end
it "should be able to update customer details for an existing order" do
- pending "Hanging at line 60"
order.ship_address = create(:address)
order.save!
click_link "Customer Details"
- fill_in "order_ship_address_attributes_firstname", :with => "John 99"
- fill_in "order_ship_address_attributes_lastname", :with => "Doe"
- fill_in "order_ship_address_attributes_lastname", :with => "Company"
- fill_in "order_ship_address_attributes_address1", :with => "100 first lane"
- fill_in "order_ship_address_attributes_address2", :with => "#101"
- fill_in "order_ship_address_attributes_city", :with => "Bethesda"
- fill_in "order_ship_address_attributes_zipcode", :with => "20170"
- fill_in "order_ship_address_attributes_state_name", :with => "Alabama"
- fill_in "order_ship_address_attributes_phone", :with => "123-456-7890"
- click_button "Continue"
+ ["ship", "bill"].each do |type|
+ fill_in "order_#{type}_address_attributes_firstname", :with => "John 99"
+ fill_in "order_#{type}_address_attributes_lastname", :with => "Doe"
+ fill_in "order_#{type}_address_attributes_lastname", :with => "Company"
+ fill_in "order_#{type}_address_attributes_address1", :with => "100 first lane"
+ fill_in "order_#{type}_address_attributes_address2", :with => "#101"
+ fill_in "order_#{type}_address_attributes_city", :with => "Bethesda"
+ fill_in "order_#{type}_address_attributes_zipcode", :with => "20170"
+ select "Alabama", :from => "order_#{type}_address_attributes_state_id"
+ fill_in "order_#{type}_address_attributes_phone", :with => "123-456-7890"
+ end
- visit spree.admin_path
- click_link "Orders"
- within(:css, 'table#listing_orders') { click_link "Edit" }
+ click_button "Continue"
click_link "Customer Details"
find_field('order_ship_address_attributes_firstname').value.should == "John 99"
diff --git a/core/spree_core.gemspec b/core/spree_core.gemspec
index 8cbdd9f400d..f6be62b4709 100644
--- a/core/spree_core.gemspec
+++ b/core/spree_core.gemspec
@@ -37,4 +37,5 @@ Gem::Specification.new do |s|
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.1'
end
From bea1a03ae563861cbb1904e18c91c8a175295da6 Mon Sep 17 00:00:00 2001
From: Alberto Vena
Date: Fri, 7 Sep 2012 20:37:26 +0200
Subject: [PATCH 125/346] disable via js double click on remove link and update
button, fixes #1879
Fixes #1934
---
core/app/assets/javascripts/store/cart.js.coffee | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/core/app/assets/javascripts/store/cart.js.coffee b/core/app/assets/javascripts/store/cart.js.coffee
index 185d7341fd9..e220f7d362d 100644
--- a/core/app/assets/javascripts/store/cart.js.coffee
+++ b/core/app/assets/javascripts/store/cart.js.coffee
@@ -1,6 +1,9 @@
$ ->
if ($ 'form#update-cart').is('*')
- ($ 'form#update-cart a.delete').show().on 'click', ->
+ ($ 'form#update-cart a.delete').show().one 'click', ->
($ this).parents('.line-item').first().find('input.line_item_quantity').val 0
($ this).parents('form').first().submit()
- false
\ No newline at end of file
+ false
+
+ ($ 'form#update-cart').submit ->
+ ($ 'form#update-cart #update-button').attr('disabled', true)
\ No newline at end of file
From e9be4ff25f80090311533fdac5bf3e0b105739a5 Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Mon, 10 Sep 2012 12:42:15 +0200
Subject: [PATCH 126/346] Fix missing sass-rails dev dependency for extension
gemspec
Fixes #1874
---
cmd/lib/spree_cmd/templates/extension/extension.gemspec | 1 +
1 file changed, 1 insertion(+)
diff --git a/cmd/lib/spree_cmd/templates/extension/extension.gemspec b/cmd/lib/spree_cmd/templates/extension/extension.gemspec
index 39274729838..005821c9736 100644
--- a/cmd/lib/spree_cmd/templates/extension/extension.gemspec
+++ b/cmd/lib/spree_cmd/templates/extension/extension.gemspec
@@ -23,4 +23,5 @@ Gem::Specification.new do |s|
s.add_development_dependency 'ffaker'
s.add_development_dependency 'rspec-rails', '~> 2.9'
s.add_development_dependency 'sqlite3'
+ s.add_development_dependency 'sass-rails'
end
From 65c943f711ba0fa35368fb92a483316f7b184bcf Mon Sep 17 00:00:00 2001
From: Tim Neems
Date: Fri, 7 Sep 2012 13:15:51 -0400
Subject: [PATCH 127/346] Fix limiting the availability of aShippingMethod to
front end or back end
Fixes #1933
---
core/app/models/spree/shipping_method.rb | 4 ++--
core/spec/models/shipping_method_spec.rb | 28 ++++++++++++++++++++++++
2 files changed, 30 insertions(+), 2 deletions(-)
diff --git a/core/app/models/spree/shipping_method.rb b/core/app/models/spree/shipping_method.rb
index 5b1537ee89c..0c7fcdd35ed 100644
--- a/core/app/models/spree/shipping_method.rb
+++ b/core/app/models/spree/shipping_method.rb
@@ -13,10 +13,10 @@ class ShippingMethod < ActiveRecord::Base
calculated_adjustments
def available?(order, display_on = nil)
- displayable? && calculator.available?(order)
+ displayable?(display_on) && calculator.available?(order)
end
- def displayable?
+ def displayable?(display_on)
(self.display_on == display_on.to_s || self.display_on.blank?)
end
diff --git a/core/spec/models/shipping_method_spec.rb b/core/spec/models/shipping_method_spec.rb
index c76405a8790..df73f0666b9 100644
--- a/core/spec/models/shipping_method_spec.rb
+++ b/core/spec/models/shipping_method_spec.rb
@@ -31,6 +31,34 @@
@shipping_method.available?(@order).should be_true
end
end
+
+ context "whe the calculator is front_end" do
+ before { @shipping_method.display_on = 'front_end' }
+
+ context "and the order is processed through the front_end" do
+ it "should be true" do
+ @shipping_method.available?(@order, :front_end).should be_true
+ end
+
+ it "should be false" do
+ @shipping_method.available?(@order, :back_end).should be_false
+ end
+ end
+ end
+
+ context "whe the calculator is back_end" do
+ before { @shipping_method.display_on = 'back_end' }
+
+ context "and the order is processed through the back_end" do
+ it "should be false" do
+ @shipping_method.available?(@order, :front_end).should be_false
+ end
+
+ it "should be true" do
+ @shipping_method.available?(@order, :back_end).should be_true
+ end
+ end
+ end
end
context 'available_to_order?' do
From 30eed3a6be00926c3912ce1fad246894ae2bb5da Mon Sep 17 00:00:00 2001
From: Nick Colgan
Date: Sat, 8 Sep 2012 06:03:21 -0500
Subject: [PATCH 128/346] DRYed up go_to_state method.
Fixes #1935
---
core/app/models/spree/order/checkout.rb | 9 +++------
1 file changed, 3 insertions(+), 6 deletions(-)
diff --git a/core/app/models/spree/order/checkout.rb b/core/app/models/spree/order/checkout.rb
index d9c5845757f..358975cba1c 100644
--- a/core/app/models/spree/order/checkout.rb
+++ b/core/app/models/spree/order/checkout.rb
@@ -83,15 +83,12 @@ def self.define_state_machine!
def self.go_to_state(name, options={})
self.checkout_steps[name] = options
+ previous_states.each do |state|
+ add_transition({:from => state, :to => name}.merge(options))
+ end
if options[:if]
- previous_states.each do |state|
- add_transition({:from => state, :to => name}.merge(options))
- end
self.previous_states << name
else
- previous_states.each do |state|
- add_transition({:from => state, :to => name}.merge(options))
- end
self.previous_states = [name]
end
end
From eae67a411edef251f35a6b06b90eafaa9f19cadb Mon Sep 17 00:00:00 2001
From: Yanick Landry
Date: Wed, 5 Sep 2012 10:38:54 -0400
Subject: [PATCH 129/346] added tax rate label
Fixes #1919
---
core/app/models/spree/tax_rate.rb | 4 ++--
core/app/views/spree/admin/tax_rates/_form.html.erb | 8 ++++++++
core/app/views/spree/admin/tax_rates/index.html.erb | 4 ++++
core/config/locales/en.yml | 1 +
core/db/migrate/20120905145253_add_tax_rate_label.rb | 5 +++++
.../migrate/20120905151823_add_toggle_tax_rate_display.rb | 5 +++++
core/spec/requests/admin/configuration/tax_rates_spec.rb | 2 +-
7 files changed, 26 insertions(+), 3 deletions(-)
create mode 100644 core/db/migrate/20120905145253_add_tax_rate_label.rb
create mode 100644 core/db/migrate/20120905151823_add_toggle_tax_rate_display.rb
diff --git a/core/app/models/spree/tax_rate.rb b/core/app/models/spree/tax_rate.rb
index 5affe2666c3..bd741cbfd6e 100644
--- a/core/app/models/spree/tax_rate.rb
+++ b/core/app/models/spree/tax_rate.rb
@@ -20,7 +20,7 @@ class TaxRate < ActiveRecord::Base
calculated_adjustments
scope :by_zone, lambda { |zone| where(:zone_id => zone) }
- attr_accessible :amount, :tax_category_id, :calculator, :zone_id, :included_in_price
+ attr_accessible :amount, :tax_category_id, :calculator, :zone_id, :included_in_price, :name, :show_rate_in_label
# Gets the array of TaxRates appropriate for the specified order
def self.match(order)
@@ -73,7 +73,7 @@ def adjust(order)
private
def create_label
- "#{tax_category.name} #{amount * 100}%"
+ "#{name ? name : tax_category.name} " + (show_rate_in_label ? "#{amount * 100}%" : "")
end
end
end
diff --git a/core/app/views/spree/admin/tax_rates/_form.html.erb b/core/app/views/spree/admin/tax_rates/_form.html.erb
index 78407e11c1b..f6edd5e598e 100644
--- a/core/app/views/spree/admin/tax_rates/_form.html.erb
+++ b/core/app/views/spree/admin/tax_rates/_form.html.erb
@@ -4,6 +4,10 @@
<%= f.label :zone, t(:zone) %>
<%= f.collection_select(:zone_id, @available_zones, :id, :name) %>
+
+ <%= f.label :name, t(:name) %>
+ <%= f.text_field :name %>
+
<%= f.label :tax_category_id, t(:tax_category) %>
<%= f.collection_select(:tax_category_id, @available_categories,:id, :name) %>
@@ -16,6 +20,10 @@
<%= f.label :amount, t(:rate) %>
<%= f.text_field :amount %>
+
+ <%= f.label :show_rate_in_label, t(:show_rate_in_label) %>
+ <%= f.check_box :show_rate_in_label %>
+
<%= render :partial => 'spree/admin/shared/calculator_fields', :locals => { :f => f } %>
diff --git a/core/app/views/spree/admin/tax_rates/index.html.erb b/core/app/views/spree/admin/tax_rates/index.html.erb
index 54f437c73f5..9890335fb3b 100644
--- a/core/app/views/spree/admin/tax_rates/index.html.erb
+++ b/core/app/views/spree/admin/tax_rates/index.html.erb
@@ -11,9 +11,11 @@
<%= t(:zone) %>
+ <%= t(:name) %>
<%= t(:category) %>
<%= t(:amount) %>
<%= t(:included_in_price) %>
+ <%= t(:show_rate_in_label) %>
<%= t(:calculator) %>
<%= t(:action) %>
@@ -22,9 +24,11 @@
<% @tax_rates.each do |tax_rate|%>
<%=tax_rate.zone.name %>
+ <%=tax_rate.name %>
<%=tax_rate.tax_category.try(:name) || t(:not_available) %>
<%=tax_rate.amount %>
<%=tax_rate.included_in_price %>
+ <%=tax_rate.show_rate_in_label %>
<%=tax_rate.calculator.to_s %>
<%= link_to_edit tax_rate %>
diff --git a/core/config/locales/en.yml b/core/config/locales/en.yml
index 095f8fee3cd..e1d59392348 100644
--- a/core/config/locales/en.yml
+++ b/core/config/locales/en.yml
@@ -108,6 +108,7 @@ en:
spree/tax_rate:
amount: Rate
included_in_price: Included in Price
+ show_rate_in_label: Show rate in label
spree/taxon:
name: Name
permalink: Permalink
diff --git a/core/db/migrate/20120905145253_add_tax_rate_label.rb b/core/db/migrate/20120905145253_add_tax_rate_label.rb
new file mode 100644
index 00000000000..9c70082973a
--- /dev/null
+++ b/core/db/migrate/20120905145253_add_tax_rate_label.rb
@@ -0,0 +1,5 @@
+class AddTaxRateLabel < ActiveRecord::Migration
+ def change
+ add_column :spree_tax_rates, :name, :string
+ end
+end
diff --git a/core/db/migrate/20120905151823_add_toggle_tax_rate_display.rb b/core/db/migrate/20120905151823_add_toggle_tax_rate_display.rb
new file mode 100644
index 00000000000..f4f3406c3ef
--- /dev/null
+++ b/core/db/migrate/20120905151823_add_toggle_tax_rate_display.rb
@@ -0,0 +1,5 @@
+class AddToggleTaxRateDisplay < ActiveRecord::Migration
+ def change
+ add_column :spree_tax_rates, :show_rate_in_label, :boolean, :default => true
+ end
+end
diff --git a/core/spec/requests/admin/configuration/tax_rates_spec.rb b/core/spec/requests/admin/configuration/tax_rates_spec.rb
index d8fe3c0a83b..ee60ce405bd 100644
--- a/core/spec/requests/admin/configuration/tax_rates_spec.rb
+++ b/core/spec/requests/admin/configuration/tax_rates_spec.rb
@@ -14,7 +14,7 @@
it "can see a tax rate in the list if the tax category has been deleted" do
tax_rate.tax_category.mark_deleted!
lambda { click_link "Tax Rates" }.should_not raise_error
- within("table tbody td:nth-child(2)") do
+ within("table tbody td:nth-child(3)") do
page.should have_content("N/A")
end
end
From f2f75c4401ba41b2c057c6f539a93bb3462efe61 Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Mon, 10 Sep 2012 15:23:38 +0200
Subject: [PATCH 130/346] Tidy up TaxRate#create_label method
---
core/app/models/spree/tax_rate.rb | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/core/app/models/spree/tax_rate.rb b/core/app/models/spree/tax_rate.rb
index bd741cbfd6e..bebe82eda32 100644
--- a/core/app/models/spree/tax_rate.rb
+++ b/core/app/models/spree/tax_rate.rb
@@ -73,7 +73,9 @@ def adjust(order)
private
def create_label
- "#{name ? name : tax_category.name} " + (show_rate_in_label ? "#{amount * 100}%" : "")
+ label = ""
+ label << (name.present? ? name : tax_category.name) + " "
+ label << (show_rate_in_label? ? "#{amount * 100}%" : "")
end
end
end
From a61d6c7cd29df552a261ded7ae476f05e325100f Mon Sep 17 00:00:00 2001
From: Yanick Landry
Date: Wed, 5 Sep 2012 10:38:54 -0400
Subject: [PATCH 131/346] added tax rate label
Fixes #1919
Conflicts:
core/app/models/spree/tax_rate.rb
---
core/app/models/spree/tax_rate.rb | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/core/app/models/spree/tax_rate.rb b/core/app/models/spree/tax_rate.rb
index bebe82eda32..bd741cbfd6e 100644
--- a/core/app/models/spree/tax_rate.rb
+++ b/core/app/models/spree/tax_rate.rb
@@ -73,9 +73,7 @@ def adjust(order)
private
def create_label
- label = ""
- label << (name.present? ? name : tax_category.name) + " "
- label << (show_rate_in_label? ? "#{amount * 100}%" : "")
+ "#{name ? name : tax_category.name} " + (show_rate_in_label ? "#{amount * 100}%" : "")
end
end
end
From 5df81d9fdc657033826380a4ad55eab36e09054f Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Mon, 10 Sep 2012 15:23:38 +0200
Subject: [PATCH 132/346] Tidy up TaxRate#create_label method
---
core/app/models/spree/tax_rate.rb | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/core/app/models/spree/tax_rate.rb b/core/app/models/spree/tax_rate.rb
index bd741cbfd6e..bebe82eda32 100644
--- a/core/app/models/spree/tax_rate.rb
+++ b/core/app/models/spree/tax_rate.rb
@@ -73,7 +73,9 @@ def adjust(order)
private
def create_label
- "#{name ? name : tax_category.name} " + (show_rate_in_label ? "#{amount * 100}%" : "")
+ label = ""
+ label << (name.present? ? name : tax_category.name) + " "
+ label << (show_rate_in_label? ? "#{amount * 100}%" : "")
end
end
end
From 17ed2348c3aaeff785d82d725ef80c056677fd46 Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Mon, 10 Sep 2012 12:32:49 +0200
Subject: [PATCH 133/346] Bump select2-rails to ~> 3.0 and rabl to 0.7.2
Conflicts:
core/spree_core.gemspec
---
core/spree_core.gemspec | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/core/spree_core.gemspec b/core/spree_core.gemspec
index f6be62b4709..bcac2289397 100644
--- a/core/spree_core.gemspec
+++ b/core/spree_core.gemspec
@@ -22,7 +22,7 @@ Gem::Specification.new do |s|
s.add_dependency 'awesome_nested_set', '2.1.4'
s.add_dependency 'jquery-rails', '~> 2.0'
- s.add_dependency 'select2-rails', '0.0.9'
+ s.add_dependency 'select2-rails', '~> 3.0'
s.add_dependency 'highline', '= 1.6.11'
s.add_dependency 'state_machine', '= 1.1.2'
@@ -37,5 +37,5 @@ Gem::Specification.new do |s|
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.1'
+ s.add_dependency 'rabl', '0.7.2'
end
From e9f8cdd9828934b975378ef5548a670986e27eb3 Mon Sep 17 00:00:00 2001
From: Fabien Franzen
Date: Tue, 4 Sep 2012 09:49:54 +0200
Subject: [PATCH 134/346] Fix product_properties autocomplete (raw output in
js)
---
core/app/views/spree/admin/product_properties/index.html.erb | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/core/app/views/spree/admin/product_properties/index.html.erb b/core/app/views/spree/admin/product_properties/index.html.erb
index bdf66ecdc81..d143bf64542 100644
--- a/core/app/views/spree/admin/product_properties/index.html.erb
+++ b/core/app/views/spree/admin/product_properties/index.html.erb
@@ -39,7 +39,7 @@
<% end %>
<%= javascript_tag do -%>
- var properties = [<%= @properties.map{|id| "'#{id}'"}.join(', ') %>];
+ var properties = [<%= raw @properties.map{|id| "'#{id}'"}.join(', ') %>];
$("#product_properties input.autocomplete").live("keydown", function(){
already_auto_completed = $(this).is('ac_input');
From 3c0194d1e35c1fbceaa5d9d789d81bc83efc66a5 Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Mon, 10 Sep 2012 16:50:02 +0200
Subject: [PATCH 135/346] Remove poor man's equivalent of to_json from
product_properties/index.html.erb
Fixes #1914
---
core/app/views/spree/admin/product_properties/index.html.erb | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/core/app/views/spree/admin/product_properties/index.html.erb b/core/app/views/spree/admin/product_properties/index.html.erb
index d143bf64542..776c6ae7ead 100644
--- a/core/app/views/spree/admin/product_properties/index.html.erb
+++ b/core/app/views/spree/admin/product_properties/index.html.erb
@@ -39,7 +39,7 @@
<% end %>
<%= javascript_tag do -%>
- var properties = [<%= raw @properties.map{|id| "'#{id}'"}.join(', ') %>];
+ var properties = <%= raw(@properties.to_json) %>;
$("#product_properties input.autocomplete").live("keydown", function(){
already_auto_completed = $(this).is('ac_input');
From 80b94aeebcef76ab0391c924ed7826823a3f1632 Mon Sep 17 00:00:00 2001
From: wans
Date: Sat, 8 Sep 2012 15:40:22 +0300
Subject: [PATCH 136/346] Update core/db/default/spree/countries.yml
added missing country "Serbia"
don`t know if it is ok?
Fixes #1936
Related to #1931
---
core/db/default/spree/countries.yml | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/core/db/default/spree/countries.yml b/core/db/default/spree/countries.yml
index b74cd01f46a..875cca816e0 100644
--- a/core/db/default/spree/countries.yml
+++ b/core/db/default/spree/countries.yml
@@ -1581,3 +1581,9 @@ countries_171:
iso_name: SAINT KITTS AND NEVIS
id: "171"
numcode: "659"
+countries_998:
+ name: Serbia
+ iso3: SRB
+ iso: RS
+ id: "998"
+ numcode: "999"
\ No newline at end of file
From 3bd2d67edab3f123cabbe769999bd1d062348dda Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Mon, 10 Sep 2012 17:27:57 +0200
Subject: [PATCH 137/346] Correct mistaken check for params[:option_type]
introduced with #1859
Fixes #1941
---
core/app/controllers/spree/admin/prototypes_controller.rb | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/core/app/controllers/spree/admin/prototypes_controller.rb b/core/app/controllers/spree/admin/prototypes_controller.rb
index 95aa6343916..2cf9d4e9f4e 100644
--- a/core/app/controllers/spree/admin/prototypes_controller.rb
+++ b/core/app/controllers/spree/admin/prototypes_controller.rb
@@ -29,7 +29,7 @@ def select
private
def set_habtm_associations
- @prototype.property_ids = params[:option_type].blank? ? [] : params[:property][:id]
+ @prototype.property_ids = params[:property].blank? ? [] : params[:property][:id]
@prototype.option_type_ids = params[:option_type].blank? ? [] : params[:option_type][:id]
end
end
From 20b356e1e26183d5039a2bb2687f64afd5b1966b Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Tue, 11 Sep 2012 16:26:05 +0200
Subject: [PATCH 138/346] Add default values for delimiter and separator in
Variant#parse_price
This was crashing earlier when there were missing translations. This now sensibly falls back to the English defaults
---
core/app/models/spree/variant.rb | 3 ++-
.../spree/admin/products_controller_spec.rb | 12 ++++++++++++
core/spec/models/variant_spec.rb | 8 ++++++++
3 files changed, 22 insertions(+), 1 deletion(-)
diff --git a/core/app/models/spree/variant.rb b/core/app/models/spree/variant.rb
index 20da446f7cc..f8a8bf11f89 100644
--- a/core/app/models/spree/variant.rb
+++ b/core/app/models/spree/variant.rb
@@ -138,7 +138,8 @@ def option_value(opt_name)
def parse_price(price)
price = price.to_s
- separator, delimiter = I18n.t([:'number.currency.format.separator', :'number.currency.format.delimiter'])
+ separator = I18n.t(:'number.currency.format.separator', :default => '.')
+ delimiter = I18n.t(:'number.currency.format.delimiter', :default => ',')
non_price_characters = /[^0-9\-#{separator}]/
price.gsub!(non_price_characters, '') # strip everything else first
price.gsub!(separator, '.') unless separator == '.' # then replace the locale-specific decimal separator with the standard separator if necessary
diff --git a/core/spec/controllers/spree/admin/products_controller_spec.rb b/core/spec/controllers/spree/admin/products_controller_spec.rb
index 317cf54b1e9..77e5dc7db87 100644
--- a/core/spec/controllers/spree/admin/products_controller_spec.rb
+++ b/core/spec/controllers/spree/admin/products_controller_spec.rb
@@ -62,6 +62,18 @@
response.should render_template("admin/products/new")
end
+ it "should be able to fallback to NL translations if NL-NL translations are missing" do
+ require 'i18n/backend/fallbacks'
+ I18n.locale = I18n.default_locale
+ I18n.backend.store_translations(:'nl-NL', { :number => { :currency => { :format => { :separator => ',' } } } })
+ I18n.backend.store_translations(:'nl', { :number => { :currency => { :format => { :delimiter => ',' } } } })
+
+ I18n.fallbacks[:'nl-NL'] = :'NL'
+ separator, delimiter = I18n.t([:'number.currency.format.separator', :'number.currency.format.delimiter'])
+
+ spree_post :create, :product => product_attributes
+ end
+
it "should create product from prototype" do
spree_post :create, :product => product_attributes.merge(:prototype_id => prototype.id)
product = Spree::Product.last
diff --git a/core/spec/models/variant_spec.rb b/core/spec/models/variant_spec.rb
index 86791895c76..14562c1b771 100644
--- a/core/spec/models/variant_spec.rb
+++ b/core/spec/models/variant_spec.rb
@@ -218,6 +218,14 @@
variant.price.should == 1599.99
end
end
+
+ context "in a locale it does not know about" do
+ it "defaults to standard" do
+ I18n.locale = :"kl-On" # klingon
+ variant.price = '1,599.99'
+ variant.price.should == 1599.99
+ end
+ end
end
context "cost_price=" do
From 8028718b082cd1212ab62ed32d0621200d6ee796 Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Tue, 11 Sep 2012 16:45:56 +0200
Subject: [PATCH 139/346] Revert "Add default values for delimiter and
separator in Variant#parse_price"
This reverts commit 20b356e1e26183d5039a2bb2687f64afd5b1966b.
---
core/app/models/spree/variant.rb | 3 +--
.../spree/admin/products_controller_spec.rb | 12 ------------
core/spec/models/variant_spec.rb | 8 --------
3 files changed, 1 insertion(+), 22 deletions(-)
diff --git a/core/app/models/spree/variant.rb b/core/app/models/spree/variant.rb
index f8a8bf11f89..20da446f7cc 100644
--- a/core/app/models/spree/variant.rb
+++ b/core/app/models/spree/variant.rb
@@ -138,8 +138,7 @@ def option_value(opt_name)
def parse_price(price)
price = price.to_s
- separator = I18n.t(:'number.currency.format.separator', :default => '.')
- delimiter = I18n.t(:'number.currency.format.delimiter', :default => ',')
+ separator, delimiter = I18n.t([:'number.currency.format.separator', :'number.currency.format.delimiter'])
non_price_characters = /[^0-9\-#{separator}]/
price.gsub!(non_price_characters, '') # strip everything else first
price.gsub!(separator, '.') unless separator == '.' # then replace the locale-specific decimal separator with the standard separator if necessary
diff --git a/core/spec/controllers/spree/admin/products_controller_spec.rb b/core/spec/controllers/spree/admin/products_controller_spec.rb
index 77e5dc7db87..317cf54b1e9 100644
--- a/core/spec/controllers/spree/admin/products_controller_spec.rb
+++ b/core/spec/controllers/spree/admin/products_controller_spec.rb
@@ -62,18 +62,6 @@
response.should render_template("admin/products/new")
end
- it "should be able to fallback to NL translations if NL-NL translations are missing" do
- require 'i18n/backend/fallbacks'
- I18n.locale = I18n.default_locale
- I18n.backend.store_translations(:'nl-NL', { :number => { :currency => { :format => { :separator => ',' } } } })
- I18n.backend.store_translations(:'nl', { :number => { :currency => { :format => { :delimiter => ',' } } } })
-
- I18n.fallbacks[:'nl-NL'] = :'NL'
- separator, delimiter = I18n.t([:'number.currency.format.separator', :'number.currency.format.delimiter'])
-
- spree_post :create, :product => product_attributes
- end
-
it "should create product from prototype" do
spree_post :create, :product => product_attributes.merge(:prototype_id => prototype.id)
product = Spree::Product.last
diff --git a/core/spec/models/variant_spec.rb b/core/spec/models/variant_spec.rb
index 14562c1b771..86791895c76 100644
--- a/core/spec/models/variant_spec.rb
+++ b/core/spec/models/variant_spec.rb
@@ -218,14 +218,6 @@
variant.price.should == 1599.99
end
end
-
- context "in a locale it does not know about" do
- it "defaults to standard" do
- I18n.locale = :"kl-On" # klingon
- variant.price = '1,599.99'
- variant.price.should == 1599.99
- end
- end
end
context "cost_price=" do
From 386810fcdf9a97f0352d85323a86c9acbda67bd6 Mon Sep 17 00:00:00 2001
From: cmar
Date: Tue, 11 Sep 2012 10:46:37 -0400
Subject: [PATCH 140/346] defect fix checkout address state not displaying
Merges #1947
Fixes #1937
---
core/app/assets/javascripts/store/checkout.js.coffee | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/core/app/assets/javascripts/store/checkout.js.coffee b/core/app/assets/javascripts/store/checkout.js.coffee
index 9d9d90a6989..4dd609b1630 100644
--- a/core/app/assets/javascripts/store/checkout.js.coffee
+++ b/core/app/assets/javascripts/store/checkout.js.coffee
@@ -14,7 +14,7 @@ $ ->
state_select = ($ 'p#' + region + 'state select')
state_input = ($ 'p#' + region + 'state input')
if states
- selected = state_select.val()
+ selected = parseInt state_select.val()
state_select.html ''
states_with_blank = [ [ '', '' ] ].concat(states)
$.each states_with_blank, (pos, id_nm) ->
@@ -54,4 +54,4 @@ $ ->
($ 'input[type="radio"][name="order[payments_attributes][][payment_method_id]"]').click(->
($ '#payment-methods li').hide()
($ '#payment_method_' + @value).show() if @checked
- ).triggerHandler 'click'
\ No newline at end of file
+ ).triggerHandler 'click'
From 9e509724122bdd41facb38e9552d2c660de226d9 Mon Sep 17 00:00:00 2001
From: Jeff Dutil
Date: Tue, 11 Sep 2012 20:11:42 -0400
Subject: [PATCH 141/346] Allow per_page param for admin orders pagination.
Fixes #1949
Also tidy up scoping code in Admin::OrdersController
---
core/app/controllers/spree/admin/orders_controller.rb | 5 ++++-
core/app/models/spree/order.rb | 1 -
.../controllers/spree/admin/orders_controller_spec.rb | 8 ++++++++
3 files changed, 12 insertions(+), 2 deletions(-)
diff --git a/core/app/controllers/spree/admin/orders_controller.rb b/core/app/controllers/spree/admin/orders_controller.rb
index 38af8fcca86..6e4a330f928 100644
--- a/core/app/controllers/spree/admin/orders_controller.rb
+++ b/core/app/controllers/spree/admin/orders_controller.rb
@@ -36,7 +36,10 @@ def index
end
@search = Order.ransack(params[:q])
- @orders = @search.result(:distinct => true).includes([:user, :shipments, :payments]).page(params[:page]).per(Spree::Config[:orders_per_page])
+ @orders = @search.result(:distinct => true).
+ includes([:user, :shipments, :payments]).
+ page(params[:page]).
+ per(params[:per_page] || Spree::Config[:orders_per_page])
# Restore dates
params[:q][:created_at_gt] = created_at_gt
diff --git a/core/app/models/spree/order.rb b/core/app/models/spree/order.rb
index d53d8f9145d..7e905024a7e 100644
--- a/core/app/models/spree/order.rb
+++ b/core/app/models/spree/order.rb
@@ -63,7 +63,6 @@ class Order < ActiveRecord::Base
before_create :link_by_email
after_create :create_tax_charge!
- # TODO: validate the format of the email as well (but we can't rely on authlogic anymore to help with validation)
validates :email, :presence => true, :email => true, :if => :require_email
validate :has_available_shipment
validate :has_available_payment
diff --git a/core/spec/controllers/spree/admin/orders_controller_spec.rb b/core/spec/controllers/spree/admin/orders_controller_spec.rb
index 3d98bcfc1cd..098db000c8f 100644
--- a/core/spec/controllers/spree/admin/orders_controller_spec.rb
+++ b/core/spec/controllers/spree/admin/orders_controller_spec.rb
@@ -15,6 +15,7 @@
order.should_receive(:foo).and_return true
spree_put :fire, {:id => "R1234567", :e => "foo"}
end
+
it "should respond with a flash message if the event cannot be fired" do
order.stub :foo => false
spree_put :fire, {:id => "R1234567", :e => "foo"}
@@ -22,4 +23,11 @@
end
end
+ context "pagination" do
+ it "can page through the orders" do
+ spree_get :index, :page => 2, :per_page => 10
+ assigns[:orders].offset_value.should == 10
+ assigns[:orders].limit_value.should == 10
+ end
+ end
end
From a51acf4876add8c7fe410d5446fd8fbfbf49da55 Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Mon, 10 Sep 2012 16:04:13 +0200
Subject: [PATCH 142/346] Use render_views in API controller tests to fix
broken tests caused by rabl upgrade
---
api/spec/controllers/spree/api/v1/base_controller_spec.rb | 1 +
api/spec/controllers/spree/api/v1/payments_controller_spec.rb | 1 +
api/spec/controllers/spree/api/v1/shipments_controller_spec.rb | 1 +
3 files changed, 3 insertions(+)
diff --git a/api/spec/controllers/spree/api/v1/base_controller_spec.rb b/api/spec/controllers/spree/api/v1/base_controller_spec.rb
index a604465cbe9..9723bddd7bb 100644
--- a/api/spec/controllers/spree/api/v1/base_controller_spec.rb
+++ b/api/spec/controllers/spree/api/v1/base_controller_spec.rb
@@ -1,6 +1,7 @@
require 'spec_helper'
describe Spree::Api::V1::BaseController do
+ render_views
controller(Spree::Api::V1::BaseController) do
def index
render :json => { "products" => [] }
diff --git a/api/spec/controllers/spree/api/v1/payments_controller_spec.rb b/api/spec/controllers/spree/api/v1/payments_controller_spec.rb
index dea1ff11daa..f08ca7468a4 100644
--- a/api/spec/controllers/spree/api/v1/payments_controller_spec.rb
+++ b/api/spec/controllers/spree/api/v1/payments_controller_spec.rb
@@ -2,6 +2,7 @@
module Spree
describe Spree::Api::V1::PaymentsController do
+ render_views
let!(:order) { create(:order) }
let!(:payment) { create(:payment, :order => order) }
let!(:attributes) { [:id, :source_type, :source_id, :amount,
diff --git a/api/spec/controllers/spree/api/v1/shipments_controller_spec.rb b/api/spec/controllers/spree/api/v1/shipments_controller_spec.rb
index c5476b4b454..f3b35baad70 100644
--- a/api/spec/controllers/spree/api/v1/shipments_controller_spec.rb
+++ b/api/spec/controllers/spree/api/v1/shipments_controller_spec.rb
@@ -1,6 +1,7 @@
require 'spec_helper'
describe Spree::Api::V1::ShipmentsController do
+ render_views
let!(:shipment) { create(:shipment) }
let!(:attributes) { [:id, :tracking, :number, :cost, :shipped_at] }
From f659930044e985b15789915055e2ed63e78b2091 Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Wed, 12 Sep 2012 12:41:53 +0200
Subject: [PATCH 143/346] Remove scoping from select2-highlighted query
This element now exists outside the scope. Because that makes complete sense.
Conflicts:
core/spec/support/capybara_ext.rb
---
core/spec/support/capybara_ext.rb | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/core/spec/support/capybara_ext.rb b/core/spec/support/capybara_ext.rb
index cdc21ee7cee..21407b4562b 100644
--- a/core/spec/support/capybara_ext.rb
+++ b/core/spec/support/capybara_ext.rb
@@ -8,9 +8,9 @@ def select2(within, value)
script = %Q{
$('#{within} .select2-search-field input').val('#{value}')
$('#{within} .select2-search-field input').keydown();
- $('#{within} .select2-highlighted').click();
}
page.execute_script(script)
+ page.execute_script("$('.select2-highlighted').mouseup();")
end
end
From acea886d2c2a50f7f561c66649b3a70efe782cc5 Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Wed, 12 Sep 2012 13:52:25 +0200
Subject: [PATCH 144/346] Add disclaimer for separate execution in select2
method
[ci skip]
---
core/spec/support/capybara_ext.rb | 3 +++
1 file changed, 3 insertions(+)
diff --git a/core/spec/support/capybara_ext.rb b/core/spec/support/capybara_ext.rb
index 21407b4562b..57faec122e9 100644
--- a/core/spec/support/capybara_ext.rb
+++ b/core/spec/support/capybara_ext.rb
@@ -10,6 +10,9 @@ def select2(within, value)
$('#{within} .select2-search-field input').keydown();
}
page.execute_script(script)
+
+ # In separate executions as it needs that break between
+ # Otherwise spec/requests/admin/products/edit/variants_spec breaks
page.execute_script("$('.select2-highlighted').mouseup();")
end
end
From f5b2b44b13860d7b43cb7e627bd311cc779c3ab6 Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Thu, 13 Sep 2012 10:39:07 +0200
Subject: [PATCH 145/346] Correct comment in Promotion::Rules::ItemTotal
---
promo/app/models/spree/promotion/rules/item_total.rb | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/promo/app/models/spree/promotion/rules/item_total.rb b/promo/app/models/spree/promotion/rules/item_total.rb
index 971b9210058..bd47243c53c 100644
--- a/promo/app/models/spree/promotion/rules/item_total.rb
+++ b/promo/app/models/spree/promotion/rules/item_total.rb
@@ -1,4 +1,5 @@
-# A rule to limit a promotion to a specific user.
+# A rule to apply to an order greater than (or greater than or equal to)
+# a specific amount
module Spree
class Promotion
module Rules
From 739a1b16ad350829cbff9338da57ffd6f62111b0 Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Thu, 13 Sep 2012 10:39:36 +0200
Subject: [PATCH 146/346] Don't need to use mock_model inside
Spree::Promotion::Rules::ItemTotal test
Just straight-up mocks will do the trick fine
---
.../models/promotion/rules/item_total_spec.rb | 17 +++++++----------
1 file changed, 7 insertions(+), 10 deletions(-)
diff --git a/promo/spec/models/promotion/rules/item_total_spec.rb b/promo/spec/models/promotion/rules/item_total_spec.rb
index ba8db09ace9..09c1db60eb5 100644
--- a/promo/spec/models/promotion/rules/item_total_spec.rb
+++ b/promo/spec/models/promotion/rules/item_total_spec.rb
@@ -2,8 +2,7 @@
describe Spree::Promotion::Rules::ItemTotal do
let(:rule) { Spree::Promotion::Rules::ItemTotal.new }
- let(:order) { mock_model(Spree::Order, :user => nil) }
- # let(:order) { mock_model Order, :line_items => [mock_model(LineItem, :amount => 10), mock_model(LineItem, :amount => 20)] }
+ let(:order) { mock(:order) }
before { rule.preferred_amount = 50 }
@@ -11,19 +10,17 @@
before { rule.preferred_operator = 'gt' }
it "should be eligible when item total is greater than preferred amount" do
- # order.stub(:item_total => 51)
- order.stub :line_items => [mock_model(Spree::LineItem, :amount => 30), mock_model(Spree::LineItem, :amount => 21)]
+ order.stub :line_items => [mock(:line_item, :amount => 30), mock(:line_item, :amount => 21)]
rule.should be_eligible(order)
end
it "should not be eligible when item total is equal to preferred amount" do
- # order.stub(:item_total => 50)
- order.stub :line_items => [mock_model(Spree::LineItem, :amount => 30), mock_model(Spree::LineItem, :amount => 20)]
+ order.stub :line_items => [mock(:line_item, :amount => 30), mock(:line_item, :amount => 20)]
rule.should_not be_eligible(order)
end
it "should not be eligible when item total is lower than to preferred amount" do
- order.stub :line_items => [mock_model(Spree::LineItem, :amount => 30), mock_model(Spree::LineItem, :amount => 19)]
+ order.stub :line_items => [mock(:line_item, :amount => 30), mock(:line_item, :amount => 19)]
rule.should_not be_eligible(order)
end
end
@@ -32,17 +29,17 @@
before { rule.preferred_operator = 'gte' }
it "should be eligible when item total is greater than preferred amount" do
- order.stub :line_items => [mock_model(Spree::LineItem, :amount => 30), mock_model(Spree::LineItem, :amount => 21)]
+ order.stub :line_items => [mock(:line_item, :amount => 30), mock(:line_item, :amount => 21)]
rule.should be_eligible(order)
end
it "should be eligible when item total is equal to preferred amount" do
- order.stub :line_items => [mock_model(Spree::LineItem, :amount => 30), mock_model(Spree::LineItem, :amount => 20)]
+ order.stub :line_items => [mock(:line_item, :amount => 30), mock(:line_item, :amount => 20)]
rule.should be_eligible(order)
end
it "should not be eligible when item total is lower than to preferred amount" do
- order.stub :line_items => [mock_model(Spree::LineItem, :amount => 30), mock_model(Spree::LineItem, :amount => 19)]
+ order.stub :line_items => [mock(:line_item, :amount => 30), mock(:line_item, :amount => 19)]
rule.should_not be_eligible(order)
end
end
From 128af838a3ee8e8daa47fdd742bf16764552adc7 Mon Sep 17 00:00:00 2001
From: Greg Reinacker
Date: Wed, 5 Sep 2012 15:34:17 -0600
Subject: [PATCH 147/346] fix problem where multiple promos applied if using
per item promotions
Fixes #1923
Fix incorrect expectations in spec
Only most valuable promotion should be applied; spec was
expecting all promotions to be applied.
---
promo/app/models/spree/order_decorator.rb | 4 +---
promo/spec/requests/promotion_adjustments_spec.rb | 6 +++---
2 files changed, 4 insertions(+), 6 deletions(-)
diff --git a/promo/app/models/spree/order_decorator.rb b/promo/app/models/spree/order_decorator.rb
index 04c48d0d746..070f00f5d70 100644
--- a/promo/app/models/spree/order_decorator.rb
+++ b/promo/app/models/spree/order_decorator.rb
@@ -16,9 +16,7 @@ def update_adjustments_with_promotion_limiting
most_valuable_adjustment = adjustments.promotion.eligible.max{|a,b| a.amount.abs <=> b.amount.abs}
current_adjustments = (adjustments.promotion.eligible - [most_valuable_adjustment])
current_adjustments.each do |adjustment|
- if adjustment.originator.calculator.is_a?(Spree::Calculator::PerItem)
- adjustment.update_attribute_without_callbacks(:eligible, false)
- end
+ adjustment.update_attribute_without_callbacks(:eligible, false)
end
end
alias_method_chain :update_adjustments, :promotion_limiting
diff --git a/promo/spec/requests/promotion_adjustments_spec.rb b/promo/spec/requests/promotion_adjustments_spec.rb
index d8f01f422b6..faa632f402e 100644
--- a/promo/spec/requests/promotion_adjustments_spec.rb
+++ b/promo/spec/requests/promotion_adjustments_spec.rb
@@ -416,15 +416,15 @@
visit spree.root_path
click_link "RoR Bag"
click_button "Add To Cart"
- Spree::Order.last.total.to_f.should == 13.00
+ Spree::Order.last.total.to_f.should == 15.00
fill_in "order[line_items_attributes][0][quantity]", :with => "2"
click_button "Update"
- Spree::Order.last.total.to_f.should == 31.00
+ Spree::Order.last.total.to_f.should == 35.00
fill_in "order[line_items_attributes][0][quantity]", :with => "3"
click_button "Update"
- Spree::Order.last.total.to_f.should == 49.00
+ Spree::Order.last.total.to_f.should == 54.00
end
def create_per_product_promotion product_name, discount_amount
From 41150d90b0d590a8cbe1e01441150963a36bfff1 Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Thu, 13 Sep 2012 14:12:37 +0200
Subject: [PATCH 148/346] Re-add banners/gateway partial to core
This was mistakenly moved out to spree_auth_devise, but is a core feature
---
.../views/spree/admin/banners/_gateway.html.erb | 14 ++++++++++++++
1 file changed, 14 insertions(+)
create mode 100644 core/app/views/spree/admin/banners/_gateway.html.erb
diff --git a/core/app/views/spree/admin/banners/_gateway.html.erb b/core/app/views/spree/admin/banners/_gateway.html.erb
new file mode 100644
index 00000000000..a745cedcc70
--- /dev/null
+++ b/core/app/views/spree/admin/banners/_gateway.html.erb
@@ -0,0 +1,14 @@
+<% if !spree_current_user.dismissed_banner?(:gateway) &&
+ Spree::PaymentMethod.production.where("type != 'Spree::Gateway::Bogus'").empty? %>
+
+
+
+ <%= t(:payment_processor_choose_banner_text)%>
+ <%= link_to t(:payment_processor_choose_link), "http://spreecommerce.com/products/payment_processing", :target => '_blank' %>
+
+
+ <%= link_to t(:dismiss_banner), dismiss_admin_banner_path(spree_current_user, :banner_id => :gateway),
+ :remote => true, :method => :post, :class => 'dismiss' %>
+
+
+<% end %>
From f1d3c4caca37f5f686d71332dc277de07742fe80 Mon Sep 17 00:00:00 2001
From: cmar
Date: Thu, 13 Sep 2012 08:27:14 -0400
Subject: [PATCH 149/346] define disableSaveOnClick as a function on window
(global) [fixes #1956]
---
core/app/assets/javascripts/store/checkout.js.coffee | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/core/app/assets/javascripts/store/checkout.js.coffee b/core/app/assets/javascripts/store/checkout.js.coffee
index 4dd609b1630..d61052e01a1 100644
--- a/core/app/assets/javascripts/store/checkout.js.coffee
+++ b/core/app/assets/javascripts/store/checkout.js.coffee
@@ -1,4 +1,4 @@
-disableSaveOnClick = ->
+@disableSaveOnClick = ->
($ 'form.edit_order').submit ->
($ this).find(':submit, :image').attr('disabled', true).removeClass('primary').addClass 'disabled'
From 881cb694b0512aa12894a1d141287b17abbbecee Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Trung=20L=C3=AA?=
Date: Thu, 13 Sep 2012 23:19:26 +1000
Subject: [PATCH 150/346] Fixes bad association between credit card and
payments
[Fixes #1953]
---
core/app/models/spree/credit_card.rb | 2 +-
core/spec/models/credit_card_spec.rb | 6 ++++++
2 files changed, 7 insertions(+), 1 deletion(-)
diff --git a/core/app/models/spree/credit_card.rb b/core/app/models/spree/credit_card.rb
index 60ab085cb2f..d85ffca341a 100644
--- a/core/app/models/spree/credit_card.rb
+++ b/core/app/models/spree/credit_card.rb
@@ -1,6 +1,6 @@
module Spree
class CreditCard < ActiveRecord::Base
- has_many :payments
+ has_many :payments, :as => :source
before_save :set_last_digits
after_validation :set_card_type
diff --git a/core/spec/models/credit_card_spec.rb b/core/spec/models/credit_card_spec.rb
index 58081503b66..9613e6349b0 100644
--- a/core/spec/models/credit_card_spec.rb
+++ b/core/spec/models/credit_card_spec.rb
@@ -191,5 +191,11 @@ def stub_rails_env(environment)
credit_card.spree_cc_type.should == "master"
end
end
+
+ context "#associations" do
+ it "should be able to access its payments" do
+ lambda { credit_card.payments.all }.should_not raise_error ActiveRecord::StatementInvalid
+ end
+ end
end
From f9d0dd010455ca88006213d9307c0f6be00825d1 Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Thu, 13 Sep 2012 15:20:05 +0200
Subject: [PATCH 151/346] Fix payment methods banner non-dismissal issue #1924
Related to #1952
Conflicts:
core/app/views/spree/admin/banners/_gateway.html.erb
---
core/app/controllers/spree/admin/banners_controller.rb | 4 ++--
core/app/views/spree/admin/banners/_gateway.html.erb | 4 ++--
2 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/core/app/controllers/spree/admin/banners_controller.rb b/core/app/controllers/spree/admin/banners_controller.rb
index b659b2b6f47..2c33b71cf7d 100644
--- a/core/app/controllers/spree/admin/banners_controller.rb
+++ b/core/app/controllers/spree/admin/banners_controller.rb
@@ -2,12 +2,12 @@ module Spree
module Admin
class BannersController < Spree::Admin::BaseController
def dismiss
- if request.xhr? and params[:id]
+ if params[:id]
if user = try_spree_current_user
user.dismiss_banner(params[:id])
end
- render :nothing => true
end
+ render :nothing => true
end
end
end
diff --git a/core/app/views/spree/admin/banners/_gateway.html.erb b/core/app/views/spree/admin/banners/_gateway.html.erb
index a745cedcc70..d6e7be8508c 100644
--- a/core/app/views/spree/admin/banners/_gateway.html.erb
+++ b/core/app/views/spree/admin/banners/_gateway.html.erb
@@ -7,8 +7,8 @@
<%= link_to t(:payment_processor_choose_link), "http://spreecommerce.com/products/payment_processing", :target => '_blank' %>
- <%= link_to t(:dismiss_banner), dismiss_admin_banner_path(spree_current_user, :banner_id => :gateway),
- :remote => true, :method => :post, :class => 'dismiss' %>
+ <%= link_to t(:dismiss_banner), dismiss_admin_banner_path(:gateway),
+ :remote => true, :method => :post, :class => 'dismiss', :id => "dismiss-banner" %>
<% end %>
From b48546af9697f3c872aa3f23a5f154041be6bcc6 Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Thu, 13 Sep 2012 16:10:49 +0200
Subject: [PATCH 152/346] Remove commented out pending line from
preferable_spec.rb
---
core/spec/models/preferences/preferable_spec.rb | 1 -
1 file changed, 1 deletion(-)
diff --git a/core/spec/models/preferences/preferable_spec.rb b/core/spec/models/preferences/preferable_spec.rb
index a3c5f95b08a..e96fa7e7403 100644
--- a/core/spec/models/preferences/preferable_spec.rb
+++ b/core/spec/models/preferences/preferable_spec.rb
@@ -79,7 +79,6 @@ class B < A
describe "preference access" do
it "handles ghost methods for preferences" do
- #pending("TODO: cmar to look at this test to figure out why it's failing on 1.9")
@a.preferred_color = 'blue'
@a.preferred_color.should eq 'blue'
From d1062ebb22b238bdbf2c9c95e7425b810b146aab Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Thu, 13 Sep 2012 16:19:59 +0200
Subject: [PATCH 153/346] if preference is not found, fallback to DB before
falling back to default
Fixes #1500
---
.../preferences/preferable_class_methods.rb | 2 ++
.../spec/models/preferences/preferable_spec.rb | 18 ++++++++++++++++++
2 files changed, 20 insertions(+)
diff --git a/core/app/models/spree/preferences/preferable_class_methods.rb b/core/app/models/spree/preferences/preferable_class_methods.rb
index dcc0f6a5048..775b5563e8d 100644
--- a/core/app/models/spree/preferences/preferable_class_methods.rb
+++ b/core/app/models/spree/preferences/preferable_class_methods.rb
@@ -15,6 +15,8 @@ def preference(name, type, *args)
else
if get_pending_preference(name)
get_pending_preference(name)
+ elsif preference = Spree::Preference.find_by_name(name)
+ preference.value
else
send self.class.preference_default_getter_method(name)
end
diff --git a/core/spec/models/preferences/preferable_spec.rb b/core/spec/models/preferences/preferable_spec.rb
index e96fa7e7403..123a579c82a 100644
--- a/core/spec/models/preferences/preferable_spec.rb
+++ b/core/spec/models/preferences/preferable_spec.rb
@@ -112,6 +112,24 @@ class B < A
@b.preferences[:color].should eq 'green' #default from A
end
+ context "database fallback" do
+ before do
+ @a.instance_variable_set("@pending_preferences", {})
+ end
+
+ it "retrieves a preference from the database before falling back to default" do
+ preference = mock(:value => "chatreuse")
+ Spree::Preference.should_receive(:find_by_name).with(:color).and_return(preference)
+ @a.preferred_color.should == 'chatreuse'
+ end
+
+ it "defaults if no database key exists" do
+ Spree::Preference.should_receive(:find_by_name).and_return(nil)
+ @a.preferred_color.should == 'green'
+ end
+ end
+
+
context "converts integer preferences to integer values" do
before do
A.preference :is_integer, :integer
From df5b26215b1dc88d72676d8188998cf91adbde6b Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Fri, 31 Aug 2012 17:13:48 +0100
Subject: [PATCH 154/346] Remove useless setting of code to blank string in
promotion_adjustments_spec
---
promo/spec/requests/promotion_adjustments_spec.rb | 2 --
1 file changed, 2 deletions(-)
diff --git a/promo/spec/requests/promotion_adjustments_spec.rb b/promo/spec/requests/promotion_adjustments_spec.rb
index faa632f402e..65e37f4ac3a 100644
--- a/promo/spec/requests/promotion_adjustments_spec.rb
+++ b/promo/spec/requests/promotion_adjustments_spec.rb
@@ -147,7 +147,6 @@
it "should allow an admin to create an automatic promo with flat percent discount" do
fill_in "Name", :with => "Order's total > $30"
- fill_in "Code", :with => ""
select "Order contents changed", :from => "Event"
click_button "Create"
page.should have_content("Editing Promotion")
@@ -176,7 +175,6 @@
it "should allow an admin to create an automatic promotion with free shipping (no code)" do
fill_in "Name", :with => "Free Shipping"
- fill_in "Code", :with => ""
click_button "Create"
page.should have_content("Editing Promotion")
From 3858b4c65f45406d596f20b1ab29154da49e9d6f Mon Sep 17 00:00:00 2001
From: cmar
Date: Thu, 13 Sep 2012 10:30:09 -0400
Subject: [PATCH 155/346] request spec to prevent regression of #1956
---
core/spec/requests/checkout_spec.rb | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
diff --git a/core/spec/requests/checkout_spec.rb b/core/spec/requests/checkout_spec.rb
index 2213d3c3fc4..b7c9b4abf95 100644
--- a/core/spec/requests/checkout_spec.rb
+++ b/core/spec/requests/checkout_spec.rb
@@ -33,6 +33,22 @@
within(:css, "span.out-of-stock") { page.should have_content("Out of Stock") }
end
+ it "prevents double clicking the payment button on checkout", :js => true do
+ visit spree.root_path
+ click_link "RoR Mug"
+ click_button "add-to-cart-button"
+ click_link "Checkout"
+
+ visit spree.checkout_state_path(:payment)
+
+ # prevent form submit to verify button is disabled
+ page.execute_script("$('#checkout_form_payment').submit(function(){return false;})")
+
+ page.should_not have_selector('input.button[disabled]')
+ click_button "Save and Continue"
+ page.should have_selector('input.button[disabled]')
+ end
+
# Regression test for #1596
context "full checkout" do
before do
From 25128e8a11c2f929c711f650e825ab22a9869204 Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Thu, 13 Sep 2012 18:10:27 +0200
Subject: [PATCH 156/346] Check if preferences table exists before falling back
to DB.
Fixes this broken build: http://travis-ci.org/#!/spree/spree/jobs/2435037
---
core/app/models/spree/preferences/preferable_class_methods.rb | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/core/app/models/spree/preferences/preferable_class_methods.rb b/core/app/models/spree/preferences/preferable_class_methods.rb
index 775b5563e8d..f24a391db9b 100644
--- a/core/app/models/spree/preferences/preferable_class_methods.rb
+++ b/core/app/models/spree/preferences/preferable_class_methods.rb
@@ -15,7 +15,7 @@ def preference(name, type, *args)
else
if get_pending_preference(name)
get_pending_preference(name)
- elsif preference = Spree::Preference.find_by_name(name)
+ elsif Spree::Preference.table_exists? && preference = Spree::Preference.find_by_name(name)
preference.value
else
send self.class.preference_default_getter_method(name)
From 84f91aa875d41fa1e77646c9cc25b321dab050cc Mon Sep 17 00:00:00 2001
From: Brian Quinn
Date: Fri, 14 Sep 2012 15:17:00 +0100
Subject: [PATCH 157/346] Prevent double submission of checkout confirm step
---
.../views/spree/checkout/_confirm.html.erb | 1 +
core/spec/requests/checkout_spec.rb | 44 ++++++++++++++-----
2 files changed, 35 insertions(+), 10 deletions(-)
diff --git a/core/app/views/spree/checkout/_confirm.html.erb b/core/app/views/spree/checkout/_confirm.html.erb
index 80a9c22918f..51fb3639103 100644
--- a/core/app/views/spree/checkout/_confirm.html.erb
+++ b/core/app/views/spree/checkout/_confirm.html.erb
@@ -8,4 +8,5 @@
<%= submit_tag t(:place_order), :class => 'continue button primary' %>
+
diff --git a/core/spec/requests/checkout_spec.rb b/core/spec/requests/checkout_spec.rb
index b7c9b4abf95..8f5776057aa 100644
--- a/core/spec/requests/checkout_spec.rb
+++ b/core/spec/requests/checkout_spec.rb
@@ -7,16 +7,19 @@
end
context "visitor makes checkout as guest without registration" do
+ before(:each) do
+ Spree::Product.delete_all
+ @product = create(:product, :name => "RoR Mug")
+ @product.on_hand = 1
+ @product.save
+ create(:zone)
+ end
+
context "when backordering is disabled" do
before(:each) do
reset_spree_preferences do |config|
config.allow_backorders = false
end
- Spree::Product.delete_all
- @product = create(:product, :name => "RoR Mug")
- @product.on_hand = 1
- @product.save
- create(:zone)
end
it "should warn the user about out of stock items" do
@@ -32,13 +35,23 @@
within(:css, "span.out-of-stock") { page.should have_content("Out of Stock") }
end
+ end
- it "prevents double clicking the payment button on checkout", :js => true do
- visit spree.root_path
- click_link "RoR Mug"
- click_button "add-to-cart-button"
- click_link "Checkout"
+ context "and likes to double click buttons" do
+ before(:each) do
+ @order = create(:order_with_totals, :state => 'payment',
+ :bill_address => create(:address),
+ :ship_address => create(:address),
+ :shipping_method => create(:shipping_method))
+ @order.reload
+ @order.update!
+ @order.stub(:available_payment_methods => [ create(:bogus_payment_method, :environment => 'test') ])
+ Spree::CheckoutController.any_instance.stub(:current_order => @order)
+ Spree::CheckoutController.any_instance.stub(:skip_state_validation? => true)
+ end
+
+ it "prevents double clicking the payment button on checkout", :js => true do
visit spree.checkout_state_path(:payment)
# prevent form submit to verify button is disabled
@@ -49,6 +62,17 @@
page.should have_selector('input.button[disabled]')
end
+ it "prevents double clicking the confirm button on checkout", :js => true do
+ visit spree.checkout_state_path(:confirm)
+
+ # prevent form submit to verify button is disabled
+ page.execute_script("$('#checkout_form_confirm').submit(function(){return false;})")
+
+ page.should_not have_selector('input.button[disabled]')
+ click_button "Place Order"
+ page.should have_selector('input.button[disabled]')
+ end
+
# Regression test for #1596
context "full checkout" do
before do
From 66ea016a4b79ba25ce5b023c6ba02b8577a3eb75 Mon Sep 17 00:00:00 2001
From: Laurens Nienhaus
Date: Thu, 13 Sep 2012 19:01:13 +0200
Subject: [PATCH 158/346] Fixed Product.in_taxon to not return duplicates
Merges #1962
---
core/app/models/spree/product/scopes.rb | 2 +-
core/spec/models/product/scopes_spec.rb | 25 +++++++++++++++++++++++++
2 files changed, 26 insertions(+), 1 deletion(-)
create mode 100644 core/spec/models/product/scopes_spec.rb
diff --git a/core/app/models/spree/product/scopes.rb b/core/app/models/spree/product/scopes.rb
index 6226b7c56a4..f9d11717ebf 100644
--- a/core/app/models/spree/product/scopes.rb
+++ b/core/app/models/spree/product/scopes.rb
@@ -51,7 +51,7 @@ def self.simple_scopes
#
# Spree::Product.taxons_id_eq(x)
add_search_scope :in_taxon do |taxon|
- joins(:taxons).where(Taxon.table_name => { :id => taxon.self_and_descendants.map(&:id) })
+ joins(:taxons).where(Taxon.table_name => { :id => taxon.self_and_descendants.map(&:id) }).uniq
end
# This scope selects products in all taxons AND all its descendants
diff --git a/core/spec/models/product/scopes_spec.rb b/core/spec/models/product/scopes_spec.rb
new file mode 100644
index 00000000000..c7c0865a384
--- /dev/null
+++ b/core/spec/models/product/scopes_spec.rb
@@ -0,0 +1,25 @@
+require 'spec_helper'
+
+describe "Product scopes" do
+ let!(:product) { create(:product) }
+
+ context "A product assigned to parent and child taxons" do
+ before do
+ @taxonomy = create(:taxonomy)
+ @root_taxon = @taxonomy.root
+
+ @taxon = create(:taxon, :name => 'A1', :taxonomy_id => @taxonomy.id)
+ @taxon2 = create(:taxon, :name => 'A2', :taxonomy_id => @taxonomy.id)
+
+ @taxon.move_to_child_of(@root_taxon)
+ @taxon2.move_to_child_of(@taxon)
+
+ product.taxons << @taxon
+ product.taxons << @taxon2
+ end
+
+ it "calling Product.in_taxon should not return duplicate records" do
+ Spree::Product.in_taxon(@taxon).length.should == 1
+ end
+ end
+end
From aca26613a6c4e215748d4eafa99f0ccb668bd096 Mon Sep 17 00:00:00 2001
From: Javier Cuevas
Date: Tue, 4 Sep 2012 18:33:28 +0200
Subject: [PATCH 159/346] Fixes encoding problem in admin when using a
different locale to :en
Fixes #1906, Merges #1916
---
core/app/assets/javascripts/admin/product_autocomplete.js.erb | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/core/app/assets/javascripts/admin/product_autocomplete.js.erb b/core/app/assets/javascripts/admin/product_autocomplete.js.erb
index 08e399de3a1..0d9ef074c2f 100644
--- a/core/app/assets/javascripts/admin/product_autocomplete.js.erb
+++ b/core/app/assets/javascripts/admin/product_autocomplete.js.erb
@@ -1,4 +1,4 @@
-//<%#encoding: UTF-8%>
+<%#encoding: UTF-8%>
// Product autocompletion
image_html = function(item){
return " ";
From d0b06d646a9e149bd638985c73ee3a60dbfb98c4 Mon Sep 17 00:00:00 2001
From: Andrew Hooker
Date: Mon, 17 Sep 2012 13:25:45 -0500
Subject: [PATCH 160/346] Use display_amount which uses Money
Fixes #1975
---
core/app/models/spree/order.rb | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/core/app/models/spree/order.rb b/core/app/models/spree/order.rb
index 7e905024a7e..54d05b4dc94 100644
--- a/core/app/models/spree/order.rb
+++ b/core/app/models/spree/order.rb
@@ -180,7 +180,7 @@ def price_adjustment_totals
price_adjustments.each do |adjustment|
label = adjustment.label
totals[label] ||= 0
- totals[label] = totals[label] + adjustment.amount
+ totals[label] = totals[label] + adjustment.display_amount
end
totals
From 95daa976b59c7be95073d82d61dc4575c5e17b83 Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Tue, 18 Sep 2012 06:10:20 +1000
Subject: [PATCH 161/346] Revert "Use display_amount which uses Money"
This reverts commit d0b06d646a9e149bd638985c73ee3a60dbfb98c4.
See comment in #1975.
---
core/app/models/spree/order.rb | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/core/app/models/spree/order.rb b/core/app/models/spree/order.rb
index 54d05b4dc94..7e905024a7e 100644
--- a/core/app/models/spree/order.rb
+++ b/core/app/models/spree/order.rb
@@ -180,7 +180,7 @@ def price_adjustment_totals
price_adjustments.each do |adjustment|
label = adjustment.label
totals[label] ||= 0
- totals[label] = totals[label] + adjustment.display_amount
+ totals[label] = totals[label] + adjustment.amount
end
totals
From 0c904f624a1a33a2da0c64d2e8088c2c4cb190b4 Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Tue, 18 Sep 2012 08:20:20 +1000
Subject: [PATCH 162/346] Revert "Fixed Product.in_taxon to not return
duplicates"
This reverts commit 6efecbed1426a181b2b59b8821cbf2a52ac56e1e.
---
core/app/models/spree/product/scopes.rb | 2 +-
core/spec/models/product/scopes_spec.rb | 25 -------------------------
2 files changed, 1 insertion(+), 26 deletions(-)
delete mode 100644 core/spec/models/product/scopes_spec.rb
diff --git a/core/app/models/spree/product/scopes.rb b/core/app/models/spree/product/scopes.rb
index f9d11717ebf..6226b7c56a4 100644
--- a/core/app/models/spree/product/scopes.rb
+++ b/core/app/models/spree/product/scopes.rb
@@ -51,7 +51,7 @@ def self.simple_scopes
#
# Spree::Product.taxons_id_eq(x)
add_search_scope :in_taxon do |taxon|
- joins(:taxons).where(Taxon.table_name => { :id => taxon.self_and_descendants.map(&:id) }).uniq
+ joins(:taxons).where(Taxon.table_name => { :id => taxon.self_and_descendants.map(&:id) })
end
# This scope selects products in all taxons AND all its descendants
diff --git a/core/spec/models/product/scopes_spec.rb b/core/spec/models/product/scopes_spec.rb
deleted file mode 100644
index c7c0865a384..00000000000
--- a/core/spec/models/product/scopes_spec.rb
+++ /dev/null
@@ -1,25 +0,0 @@
-require 'spec_helper'
-
-describe "Product scopes" do
- let!(:product) { create(:product) }
-
- context "A product assigned to parent and child taxons" do
- before do
- @taxonomy = create(:taxonomy)
- @root_taxon = @taxonomy.root
-
- @taxon = create(:taxon, :name => 'A1', :taxonomy_id => @taxonomy.id)
- @taxon2 = create(:taxon, :name => 'A2', :taxonomy_id => @taxonomy.id)
-
- @taxon.move_to_child_of(@root_taxon)
- @taxon2.move_to_child_of(@taxon)
-
- product.taxons << @taxon
- product.taxons << @taxon2
- end
-
- it "calling Product.in_taxon should not return duplicate records" do
- Spree::Product.in_taxon(@taxon).length.should == 1
- end
- end
-end
From 7a978298810117e57850f77c672390321cfdafa3 Mon Sep 17 00:00:00 2001
From: Greg Morrison
Date: Mon, 17 Sep 2012 16:33:15 -0400
Subject: [PATCH 163/346] wrap opts[:ignore_types] in array to properly
concatenate
Fixes #1979
---
core/app/helpers/spree/base_helper.rb | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/core/app/helpers/spree/base_helper.rb b/core/app/helpers/spree/base_helper.rb
index 564fff99909..8996c903f37 100644
--- a/core/app/helpers/spree/base_helper.rb
+++ b/core/app/helpers/spree/base_helper.rb
@@ -87,7 +87,7 @@ def logo(image_path=Spree::Config[:logo])
end
def flash_messages(opts = {})
- opts[:ignore_types] = [:commerce_tracking].concat(opts[:ignore_types] || [])
+ opts[:ignore_types] = [:commerce_tracking].concat([opts[:ignore_types]] || [])
flash.each do |msg_type, text|
unless opts[:ignore_types].include?(msg_type)
From 3a2df5e1d784d186ea90be4a7840d1b1d8463b75 Mon Sep 17 00:00:00 2001
From: Rohan Mitchell
Date: Fri, 14 Sep 2012 10:08:29 +1000
Subject: [PATCH 164/346] Fix product factory name sequence with Kernel.rand so
it is not interpreted as a Spree::Product method
Fixes #1964
---
.../lib/spree/core/testing_support/factories/product_factory.rb | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/core/lib/spree/core/testing_support/factories/product_factory.rb b/core/lib/spree/core/testing_support/factories/product_factory.rb
index 0794d827e09..8f13ecbe3b3 100644
--- a/core/lib/spree/core/testing_support/factories/product_factory.rb
+++ b/core/lib/spree/core/testing_support/factories/product_factory.rb
@@ -1,6 +1,6 @@
FactoryGirl.define do
factory :simple_product, :class => Spree::Product do
- sequence(:name) { |n| "Product ##{n} - #{rand(9999)}" }
+ sequence(:name) { |n| "Product ##{n} - #{Kernel.rand(9999)}" }
description { Faker::Lorem.paragraphs(1 + Kernel.rand(5)).join("\n") }
price 19.99
cost_price 17.00
From 4c703b554313fbe2ca5c69f3a89646f390cde255 Mon Sep 17 00:00:00 2001
From: "Gamaliel A. Toro Herrera"
Date: Tue, 18 Sep 2012 05:09:04 +0200
Subject: [PATCH 165/346] Fix issue where states.js was using wrong URL in
HTTPS
Fixes #1982
---
.../views/spree/admin/orders/customer_details/_form.html.erb | 2 +-
core/app/views/spree/checkout/edit.html.erb | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/core/app/views/spree/admin/orders/customer_details/_form.html.erb b/core/app/views/spree/admin/orders/customer_details/_form.html.erb
index 2e5d17e9e9b..6eed27752a9 100644
--- a/core/app/views/spree/admin/orders/customer_details/_form.html.erb
+++ b/core/app/views/spree/admin/orders/customer_details/_form.html.erb
@@ -43,6 +43,6 @@
<% content_for :head do %>
- <%= javascript_include_tag states_url, 'admin/address_states.js' %>
+ <%= javascript_include_tag states_path, 'admin/address_states.js' %>
<% end %>
diff --git a/core/app/views/spree/checkout/edit.html.erb b/core/app/views/spree/checkout/edit.html.erb
index 3b6c35b20a6..1a8260a1484 100644
--- a/core/app/views/spree/checkout/edit.html.erb
+++ b/core/app/views/spree/checkout/edit.html.erb
@@ -1,5 +1,5 @@
<% content_for :head do %>
- <%= javascript_include_tag states_url(:format => :js) %>
+ <%= javascript_include_tag states_path(:format => :js) %>
<% end %>
<%= render :partial => 'spree/shared/error_messages', :locals => { :target => @order } %>
From a2e35efdb4d9cbcae90bd204be778a78031a0dea Mon Sep 17 00:00:00 2001
From: Jeff Squires
Date: Mon, 17 Sep 2012 15:30:07 -0400
Subject: [PATCH 166/346] adds threading to chain of shipping_method.compute
calls
Fixes #1976
---
core/app/models/spree/order.rb | 19 +++++++++++++++++--
1 file changed, 17 insertions(+), 2 deletions(-)
diff --git a/core/app/models/spree/order.rb b/core/app/models/spree/order.rb
index 7e905024a7e..973484b78f0 100644
--- a/core/app/models/spree/order.rb
+++ b/core/app/models/spree/order.rb
@@ -378,8 +378,23 @@ def available_shipping_methods(display_on = nil)
end
def rate_hash
- @rate_hash ||= available_shipping_methods(:front_end).collect do |ship_method|
- next unless cost = ship_method.calculator.compute(self)
+ return @rate_hash if @rate_hash.present?
+
+ # reserve one slot for each shipping method computation
+ computed_costs = Array.new(available_shipping_methods(:front_end).size)
+
+ # create all the threads and kick off their execution
+ threads = available_shipping_methods(:front_end).each_with_index.map do |ship_method, index|
+ Thread.new { computed_costs[index] = [ship_method, ship_method.calculator.compute(self)] }
+ end
+
+ # wait for all threads to finish
+ threads.map(&:join)
+
+ # now consolidate and memoize the threaded results
+ @rate_hash ||= computed_costs.map do |pair|
+ ship_method,cost = *pair
+ next unless cost
ShippingRate.new( :id => ship_method.id,
:shipping_method => ship_method,
:name => ship_method.name,
From 04d5c69af38e1a0d259171e8a106f940df24d350 Mon Sep 17 00:00:00 2001
From: "Gamaliel A. Toro Herrera"
Date: Tue, 18 Sep 2012 03:18:27 +0200
Subject: [PATCH 167/346] Changing action to relative path in cart_form
[Fixes #1980]
---
core/app/views/spree/products/_cart_form.html.erb | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/core/app/views/spree/products/_cart_form.html.erb b/core/app/views/spree/products/_cart_form.html.erb
index c39b6eecc9d..dd139765b2b 100644
--- a/core/app/views/spree/products/_cart_form.html.erb
+++ b/core/app/views/spree/products/_cart_form.html.erb
@@ -1,4 +1,4 @@
-<%= form_for :order, :url => populate_orders_url do |f| %>
+<%= form_for :order, :url => populate_orders_path do |f| %>
";
}else{
// variant
var variant = item.data['variant'];
@@ -37,8 +37,8 @@ format_product_autocomplete = function(item){
}).join(", ")
html += "
" + name + " ";
- html += "<%= ::I18n.t(:sku) %>: " + variant['sku'] + " ";
- html += "<%= ::I18n.t(:on_hand) %>: " + variant['count_on_hand'] + " ";
+ html += "" + Spree.translations.sku + ": " + variant['sku'] + " ";
+ html += "" + Spree.translations.on_hand + ": " + variant['count_on_hand'] + " ";
}
return html
diff --git a/core/app/views/spree/admin/shared/_head.html.erb b/core/app/views/spree/admin/shared/_head.html.erb
index 5419e342e56..cf96459d856 100644
--- a/core/app/views/spree/admin/shared/_head.html.erb
+++ b/core/app/views/spree/admin/shared/_head.html.erb
@@ -5,18 +5,13 @@
<%= stylesheet_link_tag 'admin/all' %>
<%= javascript_include_tag 'admin/all' %>
-
+<%= render "spree/admin/shared/translations" %>
<%= javascript_tag do %>
Spree.routes = <%== {
:product_search => spree.admin_products_path(:format => 'json'),
:product_search_basic => spree.admin_products_path(:format => 'json', :json_format => 'basic', :limit => 10),
:user_search => spree.admin_search_users_path(:format => 'json', :limit => 10)
}.to_json %>;
-
- strings = <%==
- [:no_results, :type_to_search, :searching].
- inject({}){|memo, item| {item => t(item) }}.to_json
- %>
<% end %>
<%= javascript_tag do -%>
diff --git a/core/app/views/spree/admin/shared/_translations.html.erb b/core/app/views/spree/admin/shared/_translations.html.erb
new file mode 100644
index 00000000000..94b6d8cf316
--- /dev/null
+++ b/core/app/views/spree/admin/shared/_translations.html.erb
@@ -0,0 +1,17 @@
+
From 6ce09cf6492e927b82b7db0f79acc32da372a855 Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Wed, 26 Sep 2012 13:58:18 +1000
Subject: [PATCH 183/346] Fix stack level too deep error on Ruby 1.8 builds
This was caused by gateway_options overriden method (in promo/app/models/payment_decorator.rb) calling itself again and again. The work around is kind of a shim just so that 1.8 works. We should revert it to how it was once we drop support for Ruby 1.8.
Fixes an issue related to #1956
---
core/app/models/spree/payment/processing.rb | 2 ++
promo/app/models/spree/payment_decorator.rb | 6 ++----
promo/spec/models/payment_spec.rb | 15 +++++++++++++++
3 files changed, 19 insertions(+), 4 deletions(-)
create mode 100644 promo/spec/models/payment_spec.rb
diff --git a/core/app/models/spree/payment/processing.rb b/core/app/models/spree/payment/processing.rb
index 5228fdcbe4a..d0c49cadf94 100644
--- a/core/app/models/spree/payment/processing.rb
+++ b/core/app/models/spree/payment/processing.rb
@@ -118,6 +118,8 @@ def gateway_options
options.merge({ :billing_address => order.bill_address.try(:active_merchant_hash),
:shipping_address => order.ship_address.try(:active_merchant_hash) })
+
+ options.merge!(:discount => promo_total) if respond_to?(:promo_total)
end
private
diff --git a/promo/app/models/spree/payment_decorator.rb b/promo/app/models/spree/payment_decorator.rb
index 5925451cbae..4abcae150fa 100644
--- a/promo/app/models/spree/payment_decorator.rb
+++ b/promo/app/models/spree/payment_decorator.rb
@@ -1,7 +1,5 @@
Spree::Payment.class_eval do
- alias_method :old_gateway_options, :gateway_options
- def gateway_options
- options = old_gateway_options
- options.merge!({ :discount => order.promo_total * 100 })
+ def promo_total
+ order.promo_total * 100
end
end
diff --git a/promo/spec/models/payment_spec.rb b/promo/spec/models/payment_spec.rb
new file mode 100644
index 00000000000..69bb7869777
--- /dev/null
+++ b/promo/spec/models/payment_spec.rb
@@ -0,0 +1,15 @@
+require 'spec_helper'
+
+module Spree
+ describe Payment do
+
+ # Regression test for feature introduced in #1956
+ # Previous implementation caused it to stack level too deep
+ it "does not stack level too deep when asked for gateway options" do
+ order = stub_model(Order, :promo_total => 1)
+ payment = stub_model(Payment, :order => order)
+
+ payment.gateway_options[:discount].should == 100
+ end
+ end
+end
From 13f2b306204e8d23991d9084dfe777db68712a09 Mon Sep 17 00:00:00 2001
From: Laurens Nienhaus
Date: Wed, 26 Sep 2012 15:20:46 +0200
Subject: [PATCH 184/346] Translate jstree labels + JS escape taxonomy names
Fixes #2015
---
core/app/assets/javascripts/admin/taxonomy.js | 22 +++++++++----------
.../spree/admin/shared/_translations.html.erb | 11 +++++++++-
.../app/views/spree/admin/taxonomies/edit.erb | 4 ++--
.../admin/taxonomies/get_children.json.erb | 2 +-
4 files changed, 24 insertions(+), 15 deletions(-)
diff --git a/core/app/assets/javascripts/admin/taxonomy.js b/core/app/assets/javascripts/admin/taxonomy.js
index 2ff22301b07..c9d47b62b4b 100644
--- a/core/app/assets/javascripts/admin/taxonomy.js
+++ b/core/app/assets/javascripts/admin/taxonomy.js
@@ -59,7 +59,7 @@ var handle_delete = function(e, data){
last_rollback = data.rlbk;
var node = data.rslt.obj;
- jConfirm('Are you sure you want to delete this taxon?', 'Confirm Taxon Deletion', function(r) {
+ jConfirm(Spree.translations.are_you_sure_delete, Spree.translations.confirm_delete, function(r) {
if(r){
$.ajax({
type: "POST",
@@ -103,7 +103,7 @@ $(document).ready(function(){
},
"strings" : {
"new_node" : new_taxon,
- "loading" : loading + "..."
+ "loading" : Spree.translations.loading + "..."
},
"crrm" : {
"move" : {
@@ -131,48 +131,48 @@ $(document).ready(function(){
if(type_of_node == "root") {
menu = {
"create" : {
- "label" : "Create",
+ "label" : Spree.translations.add,
"action" : function (obj) { this.create(obj); }
},
"paste" : {
"separator_before" : true,
- "label" : "Paste",
+ "label" : Spree.translations.paste,
"action" : function (obj) { is_cut = false; this.paste(obj); },
"_disabled" : is_cut == false
},
"edit" : {
"separator_before" : true,
- "label" : "Edit",
+ "label" : Spree.translations.edit,
"action" : function (obj) { window.location = base_url + obj.attr("id") + "/edit/"; }
}
}
} else {
menu = {
"create" : {
- "label" : "Create",
+ "label" : Spree.translations.add,
"action" : function (obj) { this.create(obj); }
},
"rename" : {
- "label" : "Rename",
+ "label" : Spree.translations.rename,
"action" : function (obj) { this.rename(obj); }
},
"remove" : {
- "label" : "Remove",
+ "label" : Spree.translations.remove,
"action" : function (obj) { this.remove(obj); }
},
"cut" : {
"separator_before" : true,
- "label" : "Cut",
+ "label" : Spree.translations.cut,
"action" : function (obj) { is_cut = true; this.cut(obj); }
},
"paste" : {
- "label" : "Paste",
+ "label" : Spree.translations.paste,
"action" : function (obj) { is_cut = false; this.paste(obj); },
"_disabled" : is_cut == false
},
"edit" : {
"separator_before" : true,
- "label" : "Edit",
+ "label" : Spree.translations.edit,
"action" : function (obj) { window.location = base_url + obj.attr("id") + "/edit/"; }
}
}
diff --git a/core/app/views/spree/admin/shared/_translations.html.erb b/core/app/views/spree/admin/shared/_translations.html.erb
index 94b6d8cf316..5b4c7bfd50f 100644
--- a/core/app/views/spree/admin/shared/_translations.html.erb
+++ b/core/app/views/spree/admin/shared/_translations.html.erb
@@ -11,7 +11,16 @@
:type_to_search => I18n.t(:type_to_search),
:searching => I18n.t(:searching),
:sku => I18n.t(:sku),
- :on_hand => I18n.t(:on_hand)
+ :on_hand => I18n.t(:on_hand),
+ :add => I18n.t(:add),
+ :paste => I18n.t(:paste),
+ :edit => I18n.t(:edit),
+ :rename => I18n.t(:rename),
+ :remove => I18n.t(:remove),
+ :cut => I18n.t(:cut),
+ :loading => I18n.t(:loading),
+ :confirm_delete => I18n.t(:confirm_delete),
+ :are_you_sure_delete => I18n.t(:are_you_sure_delete)
}.to_json
%>
diff --git a/core/app/views/spree/admin/taxonomies/edit.erb b/core/app/views/spree/admin/taxonomies/edit.erb
index c7114bfac9a..064f638eeb8 100755
--- a/core/app/views/spree/admin/taxonomies/edit.erb
+++ b/core/app/views/spree/admin/taxonomies/edit.erb
@@ -28,14 +28,14 @@
var initial = [
{ "attr" :
{ "id" : "<%= @taxonomy.root.id %>", "rel" : "root" },
- "data" : "<%= @taxonomy.root.name %>",
+ "data" : "<%= escape_javascript(raw(@taxonomy.root.name)) %>",
"state" : "open",
"children" : [
<% @taxonomy.root.children.each_with_index do |taxon,i| %>
{
"attr" :
{ "id" : "<%= taxon.id %>"},
- "data" : "<%= taxon.name %>"
+ "data" : "<%= escape_javascript(raw(taxon.name)) %>"
<% unless taxon.children.empty? %>
,"state" : "closed"
<% end %>
diff --git a/core/app/views/spree/admin/taxonomies/get_children.json.erb b/core/app/views/spree/admin/taxonomies/get_children.json.erb
index 66177f4560f..003aec9d85f 100755
--- a/core/app/views/spree/admin/taxonomies/get_children.json.erb
+++ b/core/app/views/spree/admin/taxonomies/get_children.json.erb
@@ -1,7 +1,7 @@
[<% @taxons.each_with_index do |t,i| %>
{ "attr" :
{ "id" : "<%= t.id %>" },
- "data" : "<%= t.name %>"
+ "data" : "<%= escape_javascript(raw(t.name)) %>"
<% unless t.children.empty? %>
,"state" : "closed"
<% end %>
From 6a7601cc0f4aada63013bb3b0f0c3ea056eab32e Mon Sep 17 00:00:00 2001
From: Alberto Vena
Date: Wed, 26 Sep 2012 02:27:25 +0200
Subject: [PATCH 185/346] allow case insensitive coupon codes
Fixes #2009
Fixes #2012
---
.../spree/checkout_controller_decorator.rb | 4 +--
.../spree/orders_controller_decorator.rb | 2 +-
promo/app/models/spree/promotion.rb | 4 +++
promo/spec/requests/checkout_spec.rb | 28 +++++++++++++------
4 files changed, 26 insertions(+), 12 deletions(-)
diff --git a/promo/app/controllers/spree/checkout_controller_decorator.rb b/promo/app/controllers/spree/checkout_controller_decorator.rb
index 3fd876be623..412b35f7269 100644
--- a/promo/app/controllers/spree/checkout_controller_decorator.rb
+++ b/promo/app/controllers/spree/checkout_controller_decorator.rb
@@ -8,9 +8,7 @@ def update
if @order.coupon_code.present?
event_name = "spree.checkout.coupon_code_added"
- if Spree::Promotion.exists?(:code => @order.coupon_code,
- :event_name => event_name)
-
+ if promo = Spree::Promotion.with_coupon_code(@order.coupon_code).where(:event_name => event_name).first
fire_event(event_name, :coupon_code => @order.coupon_code)
# If it doesn't exist, raise an error!
# Giving them another chance to enter a valid coupon code
diff --git a/promo/app/controllers/spree/orders_controller_decorator.rb b/promo/app/controllers/spree/orders_controller_decorator.rb
index 1e6033b66e7..e193d3b2c9b 100644
--- a/promo/app/controllers/spree/orders_controller_decorator.rb
+++ b/promo/app/controllers/spree/orders_controller_decorator.rb
@@ -21,7 +21,7 @@ def update
def apply_coupon_code
return if @order.coupon_code.blank?
- if promo = Spree::Promotion.where(:code => @order.coupon_code).first
+ if promo = Spree::Promotion.with_coupon_code(@order.coupon_code).first
if promo.order_activatable?(@order)
fire_event('spree.checkout.coupon_code_added', :coupon_code => @order.coupon_code)
true
diff --git a/promo/app/models/spree/promotion.rb b/promo/app/models/spree/promotion.rb
index 6c306504b81..10f00a83a5c 100644
--- a/promo/app/models/spree/promotion.rb
+++ b/promo/app/models/spree/promotion.rb
@@ -36,6 +36,10 @@ def self.advertised
where(:advertise => true)
end
+ def self.with_coupon_code(coupon_code)
+ search(:code_cont => coupon_code).result
+ end
+
# TODO: Remove that after fix for https://rails.lighthouseapp.com/projects/8994/tickets/4329-has_many-through-association-does-not-link-models-on-association-save
# is provided
def save(*)
diff --git a/promo/spec/requests/checkout_spec.rb b/promo/spec/requests/checkout_spec.rb
index 197f2d8bb01..30e58729bb3 100644
--- a/promo/spec/requests/checkout_spec.rb
+++ b/promo/spec/requests/checkout_spec.rb
@@ -40,14 +40,26 @@
page.should have_content("The coupon code you entered doesn't exist. Please try again.")
end
- it "cannot enter a promotion code that was created after the order" do
- visit spree.root_path
- click_link "RoR Mug"
- click_button "add-to-cart-button"
- promotion.update_column(:created_at, 1.day.from_now)
- fill_in "Coupon code", :with => "onetwo"
- click_button "Apply"
- page.should have_content("The coupon code you entered doesn't exist. Please try again.")
+ context "on the cart page" do
+ before do
+ visit spree.root_path
+ click_link "RoR Mug"
+ click_button "add-to-cart-button"
+ end
+
+ it "cannot enter a promotion code that was created after the order" do
+ promotion.update_column(:created_at, 1.day.from_now)
+ fill_in "Coupon code", :with => "onetwo"
+ click_button "Apply"
+ page.should have_content("The coupon code you entered doesn't exist. Please try again.")
+ end
+
+ it "can enter a promotion code with both upper and lower case letters" do
+ promotion.update_column(:created_at, 1.minute.ago)
+ fill_in "Coupon code", :with => "ONETWO"
+ click_button "Apply"
+ page.should have_content("The coupon code was successfully applied to your order.")
+ end
end
end
end
From da1e1d8fd2aee7b2f3f7a76b37fe38003f19c4fe Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Thu, 27 Sep 2012 11:10:23 +1000
Subject: [PATCH 186/346] Show error message for GET requests to
/orders/populate
Fixes #2006
Conflicts:
core/spec/requests/cart_spec.rb
---
core/config/locales/en.yml | 1 +
core/config/routes.rb | 7 +++++++
core/spec/requests/cart_spec.rb | 23 +++++++++++++++++++++++
3 files changed, 31 insertions(+)
diff --git a/core/config/locales/en.yml b/core/config/locales/en.yml
index e1d59392348..4dc9458a16a 100644
--- a/core/config/locales/en.yml
+++ b/core/config/locales/en.yml
@@ -699,6 +699,7 @@ en:
please_create_user: "Please create a user account"
please_define_payment_methods: "Please define some payment methods first."
powered_by: "Powered by"
+ populate_get_error: "Something went wrong. Please try adding the item again."
presentation: Presentation
preview: Preview
previous: Previous
diff --git a/core/config/routes.rb b/core/config/routes.rb
index 98ee165f5aa..858db839767 100755
--- a/core/config/routes.rb
+++ b/core/config/routes.rb
@@ -15,6 +15,13 @@
get '/checkout/:state', :to => 'checkout#edit', :as => :checkout_state
get '/checkout', :to => 'checkout#edit' , :as => :checkout
+ populate_redirect = redirect do |params, request|
+ request.flash[:error] = I18n.t(:populate_get_error)
+ request.referer || '/cart'
+ end
+
+ get '/orders/populate', :via => :get, :to => populate_redirect
+
resources :orders do
post :populate, :on => :collection
diff --git a/core/spec/requests/cart_spec.rb b/core/spec/requests/cart_spec.rb
index a978180d356..820cc749923 100644
--- a/core/spec/requests/cart_spec.rb
+++ b/core/spec/requests/cart_spec.rb
@@ -10,4 +10,27 @@
visit spree.cart_path
lambda { find("li#link-to-cart a") }.should raise_error(Capybara::ElementNotFound)
end
+
+ it "prevents double clicking the remove button on cart", :js => true do
+ @product = create(:product, :name => "RoR Mug", :on_hand => 1)
+
+ visit spree.root_path
+ click_link "RoR Mug"
+ click_button "add-to-cart-button"
+
+ # prevent form submit to verify button is disabled
+ page.execute_script("$('#update-cart').submit(function(){return false;})")
+
+ page.should_not have_selector('button#update-button[disabled]')
+ page.find(:css, '.delete img').click
+ page.should have_selector('button#update-button[disabled]')
+ end
+
+ # Regression test for #2006
+ it "does not error out with a 404 when GET'ing to /orders/populate" do
+ visit '/orders/populate'
+ within(".error") do
+ page.should have_content(I18n.t(:populate_get))
+ end
+ end
end
From c1837cf0b4e8d7fe3c4b229a7336e3d76b27100e Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Thu, 27 Sep 2012 12:26:19 +1000
Subject: [PATCH 187/346] Return options at end of gateway_options
Fixes this broken build: http://travis-ci.org/#!/spree/spree/jobs/2577646/L194
---
core/app/models/spree/payment/processing.rb | 1 +
1 file changed, 1 insertion(+)
diff --git a/core/app/models/spree/payment/processing.rb b/core/app/models/spree/payment/processing.rb
index d0c49cadf94..5383515228b 100644
--- a/core/app/models/spree/payment/processing.rb
+++ b/core/app/models/spree/payment/processing.rb
@@ -120,6 +120,7 @@ def gateway_options
:shipping_address => order.ship_address.try(:active_merchant_hash) })
options.merge!(:discount => promo_total) if respond_to?(:promo_total)
+ options
end
private
From 42eb0effebdcca59d4c7171849c6a7bbf4749861 Mon Sep 17 00:00:00 2001
From: Andrew Hooker
Date: Wed, 26 Sep 2012 20:58:29 -0500
Subject: [PATCH 188/346] Referencing Correct I18n string for
populate_get_error translation
Fixes #2018
---
core/spec/requests/cart_spec.rb | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/core/spec/requests/cart_spec.rb b/core/spec/requests/cart_spec.rb
index 820cc749923..b367072e6d1 100644
--- a/core/spec/requests/cart_spec.rb
+++ b/core/spec/requests/cart_spec.rb
@@ -30,7 +30,7 @@
it "does not error out with a 404 when GET'ing to /orders/populate" do
visit '/orders/populate'
within(".error") do
- page.should have_content(I18n.t(:populate_get))
+ page.should have_content(I18n.t(:populate_get_error))
end
end
end
From ce0912135b0a6a71fdc6ab8c29de219900e0dc84 Mon Sep 17 00:00:00 2001
From: Zee Yang
Date: Fri, 28 Sep 2012 13:35:29 -0700
Subject: [PATCH 189/346] Fix missing address in gateway profile
[Fixes #2027]
---
core/app/models/spree/payment/processing.rb | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/core/app/models/spree/payment/processing.rb b/core/app/models/spree/payment/processing.rb
index 5383515228b..f252102f77e 100644
--- a/core/app/models/spree/payment/processing.rb
+++ b/core/app/models/spree/payment/processing.rb
@@ -116,7 +116,7 @@ def gateway_options
options.merge!({ :currency => payment_method.preferences[:currency_code] }) if payment_method && payment_method.preferences[:currency_code]
- options.merge({ :billing_address => order.bill_address.try(:active_merchant_hash),
+ options.merge!({ :billing_address => order.bill_address.try(:active_merchant_hash),
:shipping_address => order.ship_address.try(:active_merchant_hash) })
options.merge!(:discount => promo_total) if respond_to?(:promo_total)
From e163d70fd60dd05c34bd7ff4d7fce4393c9f67e7 Mon Sep 17 00:00:00 2001
From: Zee Yang
Date: Fri, 28 Sep 2012 13:33:05 -0700
Subject: [PATCH 190/346] Mail setting enable_starttls_auto and tls would throw
ssl error if all set together
[Fixes #2026]
---
core/lib/spree/core/mail_settings.rb | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/core/lib/spree/core/mail_settings.rb b/core/lib/spree/core/mail_settings.rb
index e1929ca40e0..6badb9e4770 100644
--- a/core/lib/spree/core/mail_settings.rb
+++ b/core/lib/spree/core/mail_settings.rb
@@ -22,7 +22,7 @@ def self.init
end
tls = mail_method.preferred_secure_connection_type == 'TLS'
- mail_server_settings[:enable_starttls_auto] = mail_server_settings[:tls] = tls
+ mail_server_settings[:enable_starttls_auto] = tls
ActionMailer::Base.smtp_settings = mail_server_settings
ActionMailer::Base.perform_deliveries = true
From a1202f44235af480c891b57e4aa535ea83e7159a Mon Sep 17 00:00:00 2001
From: Jeff Dutil
Date: Sat, 29 Sep 2012 05:14:03 -0400
Subject: [PATCH 191/346] Fix preference lookup to use key not deprecated name
column.
[Fixes #2029]
---
core/app/models/spree/preference.rb | 2 +-
.../models/spree/preferences/preferable_class_methods.rb | 2 +-
core/app/models/spree/product.rb | 1 -
.../20120929093553_remove_unused_preference_columns.rb | 8 ++++++++
core/spec/models/preference_spec.rb | 4 ----
core/spec/models/preferences/preferable_spec.rb | 4 ++--
6 files changed, 12 insertions(+), 9 deletions(-)
create mode 100644 core/db/migrate/20120929093553_remove_unused_preference_columns.rb
diff --git a/core/app/models/spree/preference.rb b/core/app/models/spree/preference.rb
index ce555f088f8..fb657f9f835 100644
--- a/core/app/models/spree/preference.rb
+++ b/core/app/models/spree/preference.rb
@@ -1,5 +1,5 @@
class Spree::Preference < ActiveRecord::Base
- attr_accessible :name, :key, :value_type, :value
+ attr_accessible :key, :value_type, :value
validates :key, :presence => true
validates :value_type, :presence => true
diff --git a/core/app/models/spree/preferences/preferable_class_methods.rb b/core/app/models/spree/preferences/preferable_class_methods.rb
index f24a391db9b..96575ceb6ee 100644
--- a/core/app/models/spree/preferences/preferable_class_methods.rb
+++ b/core/app/models/spree/preferences/preferable_class_methods.rb
@@ -15,7 +15,7 @@ def preference(name, type, *args)
else
if get_pending_preference(name)
get_pending_preference(name)
- elsif Spree::Preference.table_exists? && preference = Spree::Preference.find_by_name(name)
+ elsif Spree::Preference.table_exists? && preference = Spree::Preference.find_by_key(name)
preference.value
else
send self.class.preference_default_getter_method(name)
diff --git a/core/app/models/spree/product.rb b/core/app/models/spree/product.rb
index e5f560f735b..303f2b100e3 100755
--- a/core/app/models/spree/product.rb
+++ b/core/app/models/spree/product.rb
@@ -87,7 +87,6 @@ def variants_with_only_master
master
end
-
def to_param
permalink.present? ? permalink : (permalink_was || name.to_s.to_url)
end
diff --git a/core/db/migrate/20120929093553_remove_unused_preference_columns.rb b/core/db/migrate/20120929093553_remove_unused_preference_columns.rb
new file mode 100644
index 00000000000..434cfb2be5e
--- /dev/null
+++ b/core/db/migrate/20120929093553_remove_unused_preference_columns.rb
@@ -0,0 +1,8 @@
+class RemoveUnusedPreferenceColumns < ActiveRecord::Migration
+ def change
+ # Columns have already been removed if the application was upgraded from an older version, but must be removed from new apps.
+ remove_column :spree_preferences, :name if ActiveRecord::Base.connection.column_exists?(:spree_preferences, :name)
+ remove_column :spree_preferences, :owner_id if ActiveRecord::Base.connection.column_exists?(:spree_preferences, :owner_id)
+ remove_column :spree_preferences, :owner_type if ActiveRecord::Base.connection.column_exists?(:spree_preferences, :owner_type)
+ end
+end
diff --git a/core/spec/models/preference_spec.rb b/core/spec/models/preference_spec.rb
index 94aae06baf5..2b2aab754bd 100644
--- a/core/spec/models/preference_spec.rb
+++ b/core/spec/models/preference_spec.rb
@@ -118,7 +118,3 @@ def round_trip_preference(key, value, value_type)
end
end
-
-
-
-
diff --git a/core/spec/models/preferences/preferable_spec.rb b/core/spec/models/preferences/preferable_spec.rb
index 123a579c82a..3a30c61e4b6 100644
--- a/core/spec/models/preferences/preferable_spec.rb
+++ b/core/spec/models/preferences/preferable_spec.rb
@@ -119,12 +119,12 @@ class B < A
it "retrieves a preference from the database before falling back to default" do
preference = mock(:value => "chatreuse")
- Spree::Preference.should_receive(:find_by_name).with(:color).and_return(preference)
+ Spree::Preference.should_receive(:find_by_key).with(:color).and_return(preference)
@a.preferred_color.should == 'chatreuse'
end
it "defaults if no database key exists" do
- Spree::Preference.should_receive(:find_by_name).and_return(nil)
+ Spree::Preference.should_receive(:find_by_key).and_return(nil)
@a.preferred_color.should == 'green'
end
end
From e892145ce91fc9f52d6f2e556faf917f7a62f9a1 Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Fri, 28 Sep 2012 08:56:44 +1000
Subject: [PATCH 192/346] Remove doubly-defined gateway_options from
Payment::Processing
---
core/app/models/spree/payment/processing.rb | 16 ----------------
1 file changed, 16 deletions(-)
diff --git a/core/app/models/spree/payment/processing.rb b/core/app/models/spree/payment/processing.rb
index f252102f77e..5e24fa8b7b9 100644
--- a/core/app/models/spree/payment/processing.rb
+++ b/core/app/models/spree/payment/processing.rb
@@ -155,22 +155,6 @@ def record_response(response)
log_entries.create({:details => response.to_yaml}, :without_protection => true)
end
- def gateway_options
- options = { :email => order.email,
- :customer => order.email,
- :ip => '192.168.1.100', # TODO: Use an actual IP
- :order_id => order.number }
-
- options.merge!({ :shipping => order.ship_total * 100,
- :tax => order.tax_total * 100,
- :subtotal => order.item_total * 100 })
-
- options.merge!({ :currency => payment_method.preferences[:currency_code] }) if payment_method && payment_method.preferences[:currency_code]
-
- options.merge({ :billing_address => order.bill_address.try(:active_merchant_hash),
- :shipping_address => order.ship_address.try(:active_merchant_hash) })
- end
-
def protect_from_connection_error
begin
yield
From c6dcf2d7593490197ca8c85e50d042dcec7d96ca Mon Sep 17 00:00:00 2001
From: kei
Date: Mon, 1 Oct 2012 20:19:50 +0900
Subject: [PATCH 193/346] Manage currency whose subunit is not 100 (like JPY)
[Fixes #2030]
---
core/lib/spree/money.rb | 2 +-
core/spec/lib/money_spec.rb | 16 ++++++++++++++++
2 files changed, 17 insertions(+), 1 deletion(-)
diff --git a/core/lib/spree/money.rb b/core/lib/spree/money.rb
index 17a5bbfdf4c..0160bfceb9d 100644
--- a/core/lib/spree/money.rb
+++ b/core/lib/spree/money.rb
@@ -3,7 +3,7 @@
module Spree
class Money
def initialize(amount, options={})
- @money = ::Money.new(amount * 100, Spree::Config[:currency])
+ @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
diff --git a/core/spec/lib/money_spec.rb b/core/spec/lib/money_spec.rb
index 7da6c965438..e60f010d13b 100644
--- a/core/spec/lib/money_spec.rb
+++ b/core/spec/lib/money_spec.rb
@@ -1,3 +1,4 @@
+#encoding: UTF-8
require 'spec_helper'
module Spree
@@ -45,5 +46,20 @@ module Spree
money.to_s.should == "10.00 $"
end
end
+
+ context "JPY" do
+ before do
+ reset_spree_preferences do |config|
+ config.currency = "JPY"
+ config.currency_symbol_position = :before
+ config.display_currency = false
+ end
+ end
+
+ it "formats correctly" do
+ money = Spree::Money.new(1000)
+ money.to_s.should == "Â¥1,000"
+ end
+ end
end
end
From eabb396b4a9ad5213a782eb369120b5f634df06c Mon Sep 17 00:00:00 2001
From: Peter Berkenbosch
Date: Mon, 1 Oct 2012 22:27:04 +0200
Subject: [PATCH 194/346] add some width to the select2 boxes
fixes #2032
---
core/app/assets/stylesheets/admin/admin-form.css.erb | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/core/app/assets/stylesheets/admin/admin-form.css.erb b/core/app/assets/stylesheets/admin/admin-form.css.erb
index f2ebac9030d..f207825e1f3 100755
--- a/core/app/assets/stylesheets/admin/admin-form.css.erb
+++ b/core/app/assets/stylesheets/admin/admin-form.css.erb
@@ -161,3 +161,7 @@ fieldset {
-moz-border-radius-topright: 5px;
-webkit-border-top-right-radius: 5px; }
+/* make sure the select2 boxes on product#edit have some width to select. */
+.select2-choices {
+ min-width: 150px;
+}
From 3cacb233c34a47a769d42cdb2669cac9899bf95e Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Wed, 3 Oct 2012 10:50:12 +1000
Subject: [PATCH 195/346] Don't automatically singularize taxonomy names within
shared/_taxonomies
Rather, users should be able to choose if they want singular or plural names just by naming the taxonomies
Fixes #2038
---
core/app/views/spree/shared/_taxonomies.html.erb | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/core/app/views/spree/shared/_taxonomies.html.erb b/core/app/views/spree/shared/_taxonomies.html.erb
index dbccfb6eaa6..512d39fdf68 100644
--- a/core/app/views/spree/shared/_taxonomies.html.erb
+++ b/core/app/views/spree/shared/_taxonomies.html.erb
@@ -1,6 +1,6 @@
From a86e8bc531023c97e7ddd06b9f33aa895df41c52 Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Thu, 4 Oct 2012 08:43:16 +1000
Subject: [PATCH 196/346] Revert "Fix preference lookup to use key not
deprecated name column."
This reverts commit fd0edc38ef03a6a64b3549aa673a482210cdec59.
As per this comment: https://github.com/spree/spree/commit/fd0edc38ef03a6a64b3549aa673a482210cdec59#commitcomment-1943611
---
core/app/models/spree/preference.rb | 2 +-
.../models/spree/preferences/preferable_class_methods.rb | 2 +-
core/app/models/spree/product.rb | 1 +
.../20120929093553_remove_unused_preference_columns.rb | 8 --------
core/spec/models/preference_spec.rb | 4 ++++
core/spec/models/preferences/preferable_spec.rb | 4 ++--
6 files changed, 9 insertions(+), 12 deletions(-)
delete mode 100644 core/db/migrate/20120929093553_remove_unused_preference_columns.rb
diff --git a/core/app/models/spree/preference.rb b/core/app/models/spree/preference.rb
index fb657f9f835..ce555f088f8 100644
--- a/core/app/models/spree/preference.rb
+++ b/core/app/models/spree/preference.rb
@@ -1,5 +1,5 @@
class Spree::Preference < ActiveRecord::Base
- attr_accessible :key, :value_type, :value
+ attr_accessible :name, :key, :value_type, :value
validates :key, :presence => true
validates :value_type, :presence => true
diff --git a/core/app/models/spree/preferences/preferable_class_methods.rb b/core/app/models/spree/preferences/preferable_class_methods.rb
index 96575ceb6ee..f24a391db9b 100644
--- a/core/app/models/spree/preferences/preferable_class_methods.rb
+++ b/core/app/models/spree/preferences/preferable_class_methods.rb
@@ -15,7 +15,7 @@ def preference(name, type, *args)
else
if get_pending_preference(name)
get_pending_preference(name)
- elsif Spree::Preference.table_exists? && preference = Spree::Preference.find_by_key(name)
+ elsif Spree::Preference.table_exists? && preference = Spree::Preference.find_by_name(name)
preference.value
else
send self.class.preference_default_getter_method(name)
diff --git a/core/app/models/spree/product.rb b/core/app/models/spree/product.rb
index 303f2b100e3..e5f560f735b 100755
--- a/core/app/models/spree/product.rb
+++ b/core/app/models/spree/product.rb
@@ -87,6 +87,7 @@ def variants_with_only_master
master
end
+
def to_param
permalink.present? ? permalink : (permalink_was || name.to_s.to_url)
end
diff --git a/core/db/migrate/20120929093553_remove_unused_preference_columns.rb b/core/db/migrate/20120929093553_remove_unused_preference_columns.rb
deleted file mode 100644
index 434cfb2be5e..00000000000
--- a/core/db/migrate/20120929093553_remove_unused_preference_columns.rb
+++ /dev/null
@@ -1,8 +0,0 @@
-class RemoveUnusedPreferenceColumns < ActiveRecord::Migration
- def change
- # Columns have already been removed if the application was upgraded from an older version, but must be removed from new apps.
- remove_column :spree_preferences, :name if ActiveRecord::Base.connection.column_exists?(:spree_preferences, :name)
- remove_column :spree_preferences, :owner_id if ActiveRecord::Base.connection.column_exists?(:spree_preferences, :owner_id)
- remove_column :spree_preferences, :owner_type if ActiveRecord::Base.connection.column_exists?(:spree_preferences, :owner_type)
- end
-end
diff --git a/core/spec/models/preference_spec.rb b/core/spec/models/preference_spec.rb
index 2b2aab754bd..94aae06baf5 100644
--- a/core/spec/models/preference_spec.rb
+++ b/core/spec/models/preference_spec.rb
@@ -118,3 +118,7 @@ def round_trip_preference(key, value, value_type)
end
end
+
+
+
+
diff --git a/core/spec/models/preferences/preferable_spec.rb b/core/spec/models/preferences/preferable_spec.rb
index 3a30c61e4b6..123a579c82a 100644
--- a/core/spec/models/preferences/preferable_spec.rb
+++ b/core/spec/models/preferences/preferable_spec.rb
@@ -119,12 +119,12 @@ class B < A
it "retrieves a preference from the database before falling back to default" do
preference = mock(:value => "chatreuse")
- Spree::Preference.should_receive(:find_by_key).with(:color).and_return(preference)
+ Spree::Preference.should_receive(:find_by_name).with(:color).and_return(preference)
@a.preferred_color.should == 'chatreuse'
end
it "defaults if no database key exists" do
- Spree::Preference.should_receive(:find_by_key).and_return(nil)
+ Spree::Preference.should_receive(:find_by_name).and_return(nil)
@a.preferred_color.should == 'green'
end
end
From d8e9dff688c56ab2c7e15c88fffcc51c6e482f44 Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Thu, 4 Oct 2012 09:43:30 +1000
Subject: [PATCH 197/346] Tidy up return_authorizations/_form JS
Conflicts:
core/app/views/spree/admin/return_authorizations/_form.html.erb
---
.../return_authorizations/_form.html.erb | 50 +++++++------------
1 file changed, 17 insertions(+), 33 deletions(-)
diff --git a/core/app/views/spree/admin/return_authorizations/_form.html.erb b/core/app/views/spree/admin/return_authorizations/_form.html.erb
index 3570b700274..ac0754ed3b5 100644
--- a/core/app/views/spree/admin/return_authorizations/_form.html.erb
+++ b/core/app/views/spree/admin/return_authorizations/_form.html.erb
@@ -20,8 +20,8 @@
<% elsif units.select(&:shipped?).empty? %>
0
<% else %>
- <%= text_field_tag "return_quantity[#{variant.id}]",
- @return_authorization.inventory_units.group_by(&:variant)[variant].try(:size) || 0, {:style => 'width:30px;'} %>
+ <%= number_field_tag "return_quantity[#{variant.id}]",
+ @return_authorization.inventory_units.group_by(&:variant)[variant].try(:size) || 0, {:style => 'width:50px;', :min => 0} %>
<% end %>
@@ -33,7 +33,7 @@
<% if @return_authorization.received? %>
<%= money @return_authorization.amount %>
<% else %>
- <%= f.text_field :amount, {:style => 'width:80px;'} %> <%= t(:rma_value) %>:
+ <%= f.text_field :amount, {:style => 'width:80px;'} %> <%= t(:rma_value) %>: 0.00
<%= f.error_message_on :amount %>
<% end %>
<% end %>
@@ -45,35 +45,19 @@
<% end %>
- <% content_for :head do %>
- <%= javascript_tag do -%>
- var variant_prices = new Array();
- <% @return_authorization.order.inventory_units.group_by(&:variant).each do | variant, units| %>
- variant_prices[<%= variant.id.to_s %>] = <%= variant.price %>;
- <% end %>
-
- function calculate_rma_price(object, value){
- var rma_amount = 0;
-
- $.each($("td.return_quantity input"), function(i, inpt){
- var variant_id = $(inpt).attr('id').replace("return_quantity_", "");
- rma_amount += variant_prices[variant_id] * $(inpt).val()
- });
+
From b0ef8abe34ca04d730484d509a5f9329d417b0f9 Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Thu, 4 Oct 2012 10:32:14 +1000
Subject: [PATCH 198/346] Add workaround for rails/rails#5868
---
core/app/controllers/spree/admin/products_controller.rb | 7 -------
core/config/initializers/rails_5868.rb | 8 ++++++++
2 files changed, 8 insertions(+), 7 deletions(-)
create mode 100644 core/config/initializers/rails_5868.rb
diff --git a/core/app/controllers/spree/admin/products_controller.rb b/core/app/controllers/spree/admin/products_controller.rb
index d2be9bafc2a..a8967b402e6 100644
--- a/core/app/controllers/spree/admin/products_controller.rb
+++ b/core/app/controllers/spree/admin/products_controller.rb
@@ -88,13 +88,6 @@ def collection
includes([:master, {:variants => [:images, :option_values]}]).
page(params[:page]).
per(Spree::Config[:admin_products_per_page])
-
- if params[:q][:s].include?("master_price")
- # By applying the group in the main query we get an undefined method gsub for Arel::Nodes::Descending
- # It seems to only work when the price is actually being sorted in the query
- # To be investigated later.
- @collection = @collection.group("spree_variants.price")
- end
else
includes = [{:variants => [:images, {:option_values => :option_type}]}, {:master => :images}]
diff --git a/core/config/initializers/rails_5868.rb b/core/config/initializers/rails_5868.rb
new file mode 100644
index 00000000000..77eeaee3d4f
--- /dev/null
+++ b/core/config/initializers/rails_5868.rb
@@ -0,0 +1,8 @@
+# Temporary fix for
+# NoMethodError: undefined method `gsub' for #
+# See https://github.com/rails/rails/issues/5868
+class Arel::Nodes::Ordering
+ def gsub(*a, &b)
+ to_sql.gsub(*a, &b)
+ end
+end
From 36714cf72a42e39d98d499016c3416b4b9c733c0 Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Thu, 4 Oct 2012 10:59:44 +1000
Subject: [PATCH 199/346] Remove distinct option from ransack call in
Admin::OrdersController
Fixes #2010
---
core/app/controllers/spree/admin/orders_controller.rb | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/core/app/controllers/spree/admin/orders_controller.rb b/core/app/controllers/spree/admin/orders_controller.rb
index 6e4a330f928..aa4a712b4be 100644
--- a/core/app/controllers/spree/admin/orders_controller.rb
+++ b/core/app/controllers/spree/admin/orders_controller.rb
@@ -36,8 +36,7 @@ def index
end
@search = Order.ransack(params[:q])
- @orders = @search.result(:distinct => true).
- includes([:user, :shipments, :payments]).
+ @orders = @search.result.includes([:user, :shipments, :payments]).
page(params[:page]).
per(params[:per_page] || Spree::Config[:orders_per_page])
From ce3600039ed7aa4261dddc9a7cb2a3333fb07890 Mon Sep 17 00:00:00 2001
From: Zee Yang
Date: Fri, 28 Sep 2012 13:37:59 -0700
Subject: [PATCH 200/346] Don't process payments if no payment is required
Fixes #2028
---
core/app/models/spree/order/checkout.rb | 2 +-
core/spec/models/order/checkout_spec.rb | 13 +++++++++++++
2 files changed, 14 insertions(+), 1 deletion(-)
diff --git a/core/app/models/spree/order/checkout.rb b/core/app/models/spree/order/checkout.rb
index 358975cba1c..a6c2901ad63 100644
--- a/core/app/models/spree/order/checkout.rb
+++ b/core/app/models/spree/order/checkout.rb
@@ -64,7 +64,7 @@ def self.define_state_machine!
before_transition :to => :complete do |order|
begin
- order.process_payments!
+ order.process_payments! if order.payment_required?
rescue Spree::Core::GatewayError
!!Spree::Config[:allow_checkout_on_gateway_error]
end
diff --git a/core/spec/models/order/checkout_spec.rb b/core/spec/models/order/checkout_spec.rb
index d0ee98dca2d..c0125d47f54 100644
--- a/core/spec/models/order/checkout_spec.rb
+++ b/core/spec/models/order/checkout_spec.rb
@@ -138,6 +138,19 @@
order.state.should == "complete"
end
end
+
+ # Regression test for #2028
+ context "when payment is not required" do
+ before do
+ order.stub :payment_required => false
+ end
+
+ it "does not call process payments" do
+ order.should_not_receive(:process_payments!)
+ order.next!
+ order.state.should == "complete"
+ end
+ end
end
end
From 701847419391356a63184fa3635add299e9b997a Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Thu, 4 Oct 2012 14:54:22 +1000
Subject: [PATCH 201/346] stub payment_required? to be true for tests that
check order complete status
Fixes broken tests caused by fix for #2028
---
core/spec/models/order/checkout_spec.rb | 4 +++-
core/spec/models/order/state_machine_spec.rb | 1 +
2 files changed, 4 insertions(+), 1 deletion(-)
diff --git a/core/spec/models/order/checkout_spec.rb b/core/spec/models/order/checkout_spec.rb
index c0125d47f54..43a1685fc04 100644
--- a/core/spec/models/order/checkout_spec.rb
+++ b/core/spec/models/order/checkout_spec.rb
@@ -130,6 +130,7 @@
context "without confirmation required" do
before do
order.stub :confirmation_required? => false
+ order.stub :payment_required? => true
end
it "transitions to complete" do
@@ -142,7 +143,7 @@
# Regression test for #2028
context "when payment is not required" do
before do
- order.stub :payment_required => false
+ order.stub :payment_required? => false
end
it "does not call process payments" do
@@ -166,6 +167,7 @@ class SubclassedOrder < Spree::Order
it "should only call default transitions once when checkout_flow is redefined" do
order = SubclassedOrder.new
+ order.stub :payment_required? => true
order.should_receive(:process_payments!).once
order.state = "payment"
order.next!
diff --git a/core/spec/models/order/state_machine_spec.rb b/core/spec/models/order/state_machine_spec.rb
index ff69dcbbfcd..782538f2f18 100644
--- a/core/spec/models/order/state_machine_spec.rb
+++ b/core/spec/models/order/state_machine_spec.rb
@@ -21,6 +21,7 @@
context "when credit card payment fails" do
before do
order.stub(:process_payments!).and_raise(Spree::Core::GatewayError)
+ order.stub :payment_required? => true
end
context "when not configured to allow failed payments" do
From f505c9c0c4070a727e5a9f80f2143d226b657f8a Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Fri, 5 Oct 2012 14:51:42 +1000
Subject: [PATCH 202/346] Add greater_than validation to LineItem and ensure
products can't be set below 1
Fixes #2046
---
core/app/models/spree/line_item.rb | 2 +-
core/app/views/spree/products/_cart_form.html.erb | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/core/app/models/spree/line_item.rb b/core/app/models/spree/line_item.rb
index 0585ddc75cb..fd19371684a 100644
--- a/core/app/models/spree/line_item.rb
+++ b/core/app/models/spree/line_item.rb
@@ -10,7 +10,7 @@ class LineItem < ActiveRecord::Base
before_validation :copy_price
validates :variant, :presence => true
- validates :quantity, :numericality => { :only_integer => true, :message => I18n.t('validation.must_be_int') }
+ validates :quantity, :numericality => { :only_integer => true, :message => I18n.t('validation.must_be_int'), :greater_than => 0 }
validates :price, :numericality => true
validate :stock_availability
validate :quantity_no_less_than_shipped
diff --git a/core/app/views/spree/products/_cart_form.html.erb b/core/app/views/spree/products/_cart_form.html.erb
index dd139765b2b..58be77a1523 100644
--- a/core/app/views/spree/products/_cart_form.html.erb
+++ b/core/app/views/spree/products/_cart_form.html.erb
@@ -37,7 +37,7 @@
<% if @product.has_stock? || Spree::Config[:allow_backorders] %>
<%= number_field_tag (@product.has_variants? ? :quantity : "variants[#{@product.master.id}]"),
- 1, :class => 'title', :in => 1..@product.on_hand %>
+ 1, :class => 'title', :in => 1..@product.on_hand, :min => 1 %>
<%= button_tag :class => 'large primary', :id => 'add-to-cart-button', :type => :submit do %>
<%= t(:add_to_cart) %>
<% end %>
From 5e2b8001a73d705bb61d8968b0ded53322c9bb0d Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Fri, 5 Oct 2012 14:59:51 +1000
Subject: [PATCH 203/346] Account for situations where tax_rates may not have a
zone
Fixes #2019
---
core/app/views/spree/admin/tax_rates/index.html.erb | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/core/app/views/spree/admin/tax_rates/index.html.erb b/core/app/views/spree/admin/tax_rates/index.html.erb
index 9890335fb3b..4664b9bf73b 100644
--- a/core/app/views/spree/admin/tax_rates/index.html.erb
+++ b/core/app/views/spree/admin/tax_rates/index.html.erb
@@ -23,7 +23,7 @@
<% @tax_rates.each do |tax_rate|%>
- <%=tax_rate.zone.name %>
+ <%=tax_rate.zone.try(:name) || t(:not_available) %>
<%=tax_rate.name %>
<%=tax_rate.tax_category.try(:name) || t(:not_available) %>
<%=tax_rate.amount %>
From cbaab7183c0788bcf399bed690381ba995d8d401 Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Tue, 25 Sep 2012 14:59:30 +1000
Subject: [PATCH 204/346] Apply payments partially
Rather than iterating through each payment for an order and attempt to apply it, only iterate through pending payments and apply them until the payment_total has been brought in line (or has crossed over) the order total.
Fixes #1954
Fixes #2008
---
core/app/models/spree/order.rb | 14 ++++++-
core/spec/models/order/payment_spec.rb | 54 ++++++++++++++++++++++++++
2 files changed, 67 insertions(+), 1 deletion(-)
create mode 100644 core/spec/models/order/payment_spec.rb
diff --git a/core/app/models/spree/order.rb b/core/app/models/spree/order.rb
index 3ff0bc551b6..d0b3b998667 100644
--- a/core/app/models/spree/order.rb
+++ b/core/app/models/spree/order.rb
@@ -422,9 +422,21 @@ def payment_method
end
end
+ def pending_payments
+ payments.with_state('checkout')
+ end
+
def process_payments!
begin
- payments.each(&:process!)
+ pending_payments.each do |payment|
+ break if payment_total >= total
+
+ payment.process!
+
+ if payment.completed?
+ self.payment_total += payment.amount
+ end
+ end
rescue Core::GatewayError
!!Spree::Config[:allow_checkout_on_gateway_error]
end
diff --git a/core/spec/models/order/payment_spec.rb b/core/spec/models/order/payment_spec.rb
new file mode 100644
index 00000000000..2558be91755
--- /dev/null
+++ b/core/spec/models/order/payment_spec.rb
@@ -0,0 +1,54 @@
+require 'spec_helper'
+
+module Spree
+ describe Order do
+ let(:order) { stub_model(Order) }
+ let(:updater) { Spree::OrderUpdater.new(order) }
+
+ before do
+ # So that Payment#purchase! is called during processing
+ Spree::Config[:auto_capture] = true
+
+ order.stub_chain(:line_items, :empty?).and_return(false)
+ order.stub :total => 100
+ end
+
+ it 'processes all payments' do
+ payment_1 = Factory(:payment, :amount => 50)
+ payment_2 = Factory(:payment, :amount => 50)
+ order.stub(:pending_payments).and_return([payment_1, payment_2])
+
+ order.process_payments!
+ updater.update_payment_state
+ order.payment_state.should == 'paid'
+
+ payment_1.should be_completed
+ payment_2.should be_completed
+ end
+
+ it 'does not go over total for order' do
+ payment_1 = Factory(:payment, :amount => 50)
+ payment_2 = Factory(:payment, :amount => 50)
+ payment_3 = Factory(:payment, :amount => 50)
+ order.stub(:pending_payments).and_return([payment_1, payment_2, payment_3])
+
+ order.process_payments!
+ updater.update_payment_state
+ order.payment_state.should == 'paid'
+
+ payment_1.should be_completed
+ payment_2.should be_completed
+ payment_3.should be_pending
+ end
+
+ it "does not use failed payments" do
+ payment_1 = Factory(:payment, :amount => 50)
+ payment_2 = Factory(:payment, :amount => 50, :state => 'failed')
+ order.stub(:pending_payments).and_return([payment_1])
+
+ payment_2.should_not_receive(:process!)
+
+ order.process_payments!
+ end
+ end
+end
From 49028831622a561f37caba35dcd7447ffd6646b5 Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Mon, 8 Oct 2012 09:20:46 +1100
Subject: [PATCH 205/346] Downgrade to cocaine 0.3.2 as 0.4.0 breaks
imagemagick.
Breakage demonstrated here: https://travis-ci.org/#!/spree/spree/jobs/2689309
This is related to thoughtbot/cocaine#28.
---
core/spree_core.gemspec | 1 +
1 file changed, 1 insertion(+)
diff --git a/core/spree_core.gemspec b/core/spree_core.gemspec
index bcac2289397..b0cb3029092 100644
--- a/core/spree_core.gemspec
+++ b/core/spree_core.gemspec
@@ -38,4 +38,5 @@ Gem::Specification.new do |s|
s.add_dependency 'cancan', '1.6.7'
s.add_dependency 'money', '5.0.0'
s.add_dependency 'rabl', '0.7.2'
+ s.add_dependency 'cocaine', "<= 0.3.2"
end
From e7e0c697501eea2944daa575ff8ca59dfa964e99 Mon Sep 17 00:00:00 2001
From: Derek Ethier
Date: Fri, 5 Oct 2012 11:38:22 -0700
Subject: [PATCH 206/346] Move routes definition into a view to parallel
translation settings.
Removing the javascript_tag setting in _head fixes the overwritten Spree javascript variable in _head (for admin) that caused plugins that relied on translations to break
Fixes #2054
Conflicts:
core/app/views/spree/admin/shared/_head.html.erb
---
core/app/views/spree/admin/shared/_head.html.erb | 9 ++-------
core/app/views/spree/admin/shared/_routes.html.erb | 8 ++++++++
2 files changed, 10 insertions(+), 7 deletions(-)
create mode 100644 core/app/views/spree/admin/shared/_routes.html.erb
diff --git a/core/app/views/spree/admin/shared/_head.html.erb b/core/app/views/spree/admin/shared/_head.html.erb
index cf96459d856..4c73d3078df 100644
--- a/core/app/views/spree/admin/shared/_head.html.erb
+++ b/core/app/views/spree/admin/shared/_head.html.erb
@@ -5,14 +5,9 @@
<%= stylesheet_link_tag 'admin/all' %>
<%= javascript_include_tag 'admin/all' %>
+
<%= render "spree/admin/shared/translations" %>
-<%= javascript_tag do %>
- Spree.routes = <%== {
- :product_search => spree.admin_products_path(:format => 'json'),
- :product_search_basic => spree.admin_products_path(:format => 'json', :json_format => 'basic', :limit => 10),
- :user_search => spree.admin_search_users_path(:format => 'json', :limit => 10)
- }.to_json %>;
-<% end %>
+<%= render "spree/admin/shared/routes" %>
<%= javascript_tag do -%>
jQuery.alerts.dialogClass = 'spree';
diff --git a/core/app/views/spree/admin/shared/_routes.html.erb b/core/app/views/spree/admin/shared/_routes.html.erb
new file mode 100644
index 00000000000..809e297a9ac
--- /dev/null
+++ b/core/app/views/spree/admin/shared/_routes.html.erb
@@ -0,0 +1,8 @@
+
From 09d1c774b0fae3951c0d7d1dcbd0fc1d0f79bd34 Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Mon, 8 Oct 2012 09:31:30 +1100
Subject: [PATCH 207/346] Freeze to paperclip 2.7.1 as 2.8.0 breaks without
cocaine 0.4.0
---
core/spree_core.gemspec | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/core/spree_core.gemspec b/core/spree_core.gemspec
index b0cb3029092..ab26e8a4514 100644
--- a/core/spree_core.gemspec
+++ b/core/spree_core.gemspec
@@ -27,7 +27,7 @@ Gem::Specification.new do |s|
s.add_dependency 'highline', '= 1.6.11'
s.add_dependency 'state_machine', '= 1.1.2'
s.add_dependency 'ffaker', '~> 1.12.0'
- s.add_dependency 'paperclip', '~> 2.7'
+ s.add_dependency 'paperclip', '2.7.1'
s.add_dependency 'aws-sdk', '~> 1.3.4'
s.add_dependency 'ransack', '~> 0.7.0'
s.add_dependency 'activemerchant', '= 1.28.0'
From c6043ed4371559c17b2eba206574625df0db3815 Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Mon, 8 Oct 2012 10:45:19 +1100
Subject: [PATCH 208/346] Don't reference OrderUpdater in order/payment_spec
This is because it's from master, and this is 1-2-stable. Use Order#update_payment_state instead
---
core/spec/models/order/payment_spec.rb | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/core/spec/models/order/payment_spec.rb b/core/spec/models/order/payment_spec.rb
index 2558be91755..554c55f5b71 100644
--- a/core/spec/models/order/payment_spec.rb
+++ b/core/spec/models/order/payment_spec.rb
@@ -3,7 +3,6 @@
module Spree
describe Order do
let(:order) { stub_model(Order) }
- let(:updater) { Spree::OrderUpdater.new(order) }
before do
# So that Payment#purchase! is called during processing
@@ -19,7 +18,7 @@ module Spree
order.stub(:pending_payments).and_return([payment_1, payment_2])
order.process_payments!
- updater.update_payment_state
+ order.send(:update_payment_state)
order.payment_state.should == 'paid'
payment_1.should be_completed
@@ -33,7 +32,7 @@ module Spree
order.stub(:pending_payments).and_return([payment_1, payment_2, payment_3])
order.process_payments!
- updater.update_payment_state
+ order.send(:update_payment_state)
order.payment_state.should == 'paid'
payment_1.should be_completed
From ea5f53629a1ade3ff4652455c61b7716ed13b15c Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Mon, 8 Oct 2012 10:45:38 +1100
Subject: [PATCH 209/346] Correct stubbing for Order#process_payments
---
core/spec/models/order_spec.rb | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/core/spec/models/order_spec.rb b/core/spec/models/order_spec.rb
index 44543ade9f3..9a933b2fd27 100644
--- a/core/spec/models/order_spec.rb
+++ b/core/spec/models/order_spec.rb
@@ -124,8 +124,12 @@ def compute(computable)
context "#process_payments!" do
it "should process the payments" do
- order.stub!(:payments).and_return([mock(Spree::Payment)])
- order.payment.should_receive(:process!)
+ order.stub(:total).and_return(10)
+ payment = stub_model(Spree::Payment)
+ payments = [payment]
+ order.stub(:payments).and_return(payments)
+ payments.should_receive(:with_state).with('checkout').and_return(payments)
+ payments.first.should_receive(:process!)
order.process_payments!
end
end
From 5fb367b805ee9bc109a4a1a4e56a41edaf979ae2 Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Mon, 8 Oct 2012 11:14:58 +1100
Subject: [PATCH 210/346] Re-add grouping for spree_variants.price to
admin/products_controller
This fixes this failing build: https://travis-ci.org/#!/spree/spree/jobs/2701229
---
core/app/controllers/spree/admin/products_controller.rb | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/core/app/controllers/spree/admin/products_controller.rb b/core/app/controllers/spree/admin/products_controller.rb
index a8967b402e6..1b71542b079 100644
--- a/core/app/controllers/spree/admin/products_controller.rb
+++ b/core/app/controllers/spree/admin/products_controller.rb
@@ -88,6 +88,11 @@ def collection
includes([:master, {:variants => [:images, :option_values]}]).
page(params[:page]).
per(Spree::Config[:admin_products_per_page])
+
+ # PostgreSQL compatibility
+ if params[:q][:s].include?("master_price")
+ @collection = @collection.group("spree_variants.price")
+ end
else
includes = [{:variants => [:images, {:option_values => :option_type}]}, {:master => :images}]
From 89f6e7b89353496094deceda5de47a55c10fa18b Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Mon, 8 Oct 2012 11:37:32 +1100
Subject: [PATCH 211/346] Upgrade paperclip to 2.8
Conflicts:
core/spree_core.gemspec
---
core/spree_core.gemspec | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/core/spree_core.gemspec b/core/spree_core.gemspec
index ab26e8a4514..194de0415fa 100644
--- a/core/spree_core.gemspec
+++ b/core/spree_core.gemspec
@@ -27,7 +27,7 @@ Gem::Specification.new do |s|
s.add_dependency 'highline', '= 1.6.11'
s.add_dependency 'state_machine', '= 1.1.2'
s.add_dependency 'ffaker', '~> 1.12.0'
- s.add_dependency 'paperclip', '2.7.1'
+ s.add_dependency 'paperclip', '~> 2.8'
s.add_dependency 'aws-sdk', '~> 1.3.4'
s.add_dependency 'ransack', '~> 0.7.0'
s.add_dependency 'activemerchant', '= 1.28.0'
@@ -38,5 +38,4 @@ Gem::Specification.new do |s|
s.add_dependency 'cancan', '1.6.7'
s.add_dependency 'money', '5.0.0'
s.add_dependency 'rabl', '0.7.2'
- s.add_dependency 'cocaine', "<= 0.3.2"
end
From db3041586fb18b4905ac18e8a6918aeabf35fac4 Mon Sep 17 00:00:00 2001
From: Michael Bianco
Date: Sat, 6 Oct 2012 11:48:58 -0400
Subject: [PATCH 212/346] Exclude expired promotions from
Spree::Product#possible_promotions
Fixes #2058
---
promo/app/models/spree/product_decorator.rb | 5 +-
.../requests/promotion_adjustments_spec.rb | 58 +++++++++----------
2 files changed, 28 insertions(+), 35 deletions(-)
diff --git a/promo/app/models/spree/product_decorator.rb b/promo/app/models/spree/product_decorator.rb
index 8a81786e580..ccf3345eff6 100644
--- a/promo/app/models/spree/product_decorator.rb
+++ b/promo/app/models/spree/product_decorator.rb
@@ -2,8 +2,7 @@
has_and_belongs_to_many :promotion_rules, :join_table => :spree_products_promotion_rules
def possible_promotions
- all_rules = promotion_rules
- promotion_ids = all_rules.map(&:activator_id).uniq
- Spree::Promotion.advertised.where(:id => promotion_ids)
+ promotion_ids = promotion_rules.map(&:activator_id).uniq
+ Spree::Promotion.advertised.where(:id => promotion_ids).reject(&:expired?)
end
end
diff --git a/promo/spec/requests/promotion_adjustments_spec.rb b/promo/spec/requests/promotion_adjustments_spec.rb
index 68f006a8da3..08ef79e9251 100644
--- a/promo/spec/requests/promotion_adjustments_spec.rb
+++ b/promo/spec/requests/promotion_adjustments_spec.rb
@@ -24,6 +24,24 @@
let!(:address) { create(:address, :state => Spree::State.first) }
+ it "should properly populate Spree::Product#possible_promotions" do
+ promotion = create_per_product_promotion 'RoR Mug', 5.0
+ promotion.update_column :advertise, true
+
+ mug = Spree::Product.find_by_name 'RoR Mug'
+ bag = Spree::Product.find_by_name 'RoR Bag'
+
+ mug.possible_promotions.size.should == 1
+ bag.possible_promotions.size.should == 0
+
+ # expire the promotion
+ promotion.expires_at = Date.today.beginning_of_week
+ promotion.starts_at = Date.today.beginning_of_week.advance(:day => 3)
+ promotion.save!
+
+ mug.possible_promotions.size.should == 0
+ end
+
it "should allow an admin to create a flat rate discount coupon promo" do
fill_in "Name", :with => "Order's total > $30"
fill_in "Usage Limit", :with => "100"
@@ -422,12 +440,15 @@
Spree::Order.last.total.to_f.should == 54.00
end
- def create_per_product_promotion product_name, discount_amount
+ def create_per_product_promotion product_name, discount_amount, event = "Add to cart"
+ promotion_name = "Bundle d#{discount_amount}"
+
visit spree.admin_path
click_link "Promotions"
click_link "New Promotion"
- fill_in "Name", :with => "Bundle"
- select "Add to cart", :from => "Event"
+
+ fill_in "Name", :with => promotion_name
+ select event, :from => "Event"
click_button "Create"
page.should have_content("Editing Promotion")
@@ -449,6 +470,8 @@ def create_per_product_promotion product_name, discount_amount
within('#actions_container') { click_button "Update" }
within('.calculator-fields') { fill_in "Amount", :with => discount_amount.to_s }
within('#actions_container') { click_button "Update" }
+
+ Spree::Promotion.find_by_name promotion_name
end
def add_to_cart product_name
@@ -474,34 +497,5 @@ def do_checkout
fill_in "card_code", :with => "123"
click_button "Save and Continue"
end
-
- def create_per_product_promotion product_name, discount_amount
- visit spree.admin_path
- click_link "Promotions"
- click_link "New Promotion"
- fill_in "Name", :with => "Bundle"
- select "Add to cart", :from => "Event"
- click_button "Create"
- page.should have_content("Editing Promotion")
-
- # add product_name to last promotion
- promotion = Spree::Promotion.last
- promotion.rules << Spree::Promotion::Rules::Product.new()
- product = Spree::Product.find_by_name(product_name)
- rule = promotion.rules.last
- rule.products << product
- if rule.save
- puts "Created promotion: new price for #{product_name} is #{product.price - discount_amount} (was #{product.price})"
- else
- puts "Failed to create promotion: price for #{product_name} is still #{product.price}"
- end
-
- select "Create adjustment", :from => "Add action of type"
- within('#action_fields') { click_button "Add" }
- select "Flat Rate (per item)", :from => "Calculator"
- within('#actions_container') { click_button "Update" }
- within('.calculator-fields') { fill_in "Amount", :with => discount_amount.to_s }
- within('#actions_container') { click_button "Update" }
- end
end
end
From 77e983b24d5de9d5f0fd393a12cae008bc488a5d Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Mon, 8 Oct 2012 12:35:04 +1100
Subject: [PATCH 213/346] Fix PriceSack incorrect calculation
Fixes #2055
---
core/app/models/spree/calculator/price_sack.rb | 2 +-
core/spec/models/calculator/price_sack_spec.rb | 15 ++++++++++++++-
2 files changed, 15 insertions(+), 2 deletions(-)
diff --git a/core/app/models/spree/calculator/price_sack.rb b/core/app/models/spree/calculator/price_sack.rb
index e45703abc7c..90ac2b0dcb9 100644
--- a/core/app/models/spree/calculator/price_sack.rb
+++ b/core/app/models/spree/calculator/price_sack.rb
@@ -22,7 +22,7 @@ def compute(object)
base = object.respond_to?(:amount) ? object.amount : object.to_d
end
- if base >= self.preferred_minimal_amount
+ if base < self.preferred_minimal_amount
self.preferred_normal_amount
else
self.preferred_discount_amount
diff --git a/core/spec/models/calculator/price_sack_spec.rb b/core/spec/models/calculator/price_sack_spec.rb
index 6911fc3c63d..f26ed8d4d58 100644
--- a/core/spec/models/calculator/price_sack_spec.rb
+++ b/core/spec/models/calculator/price_sack_spec.rb
@@ -1,7 +1,14 @@
require 'spec_helper'
describe Spree::Calculator::PriceSack do
- let(:calculator) { Spree::Calculator::PriceSack.new }
+ let(:calculator) do
+ calculator = Spree::Calculator::PriceSack.new
+ calculator.preferred_minimal_amount = 5
+ calculator.preferred_normal_amount = 10
+ calculator.preferred_discount_amount = 1
+ calculator
+ end
+
let(:order) { stub_model(Spree::Order) }
let(:shipment) { stub_model(Spree::Shipment) }
@@ -14,4 +21,10 @@
it "computes with a snipment object" do
calculator.compute(shipment)
end
+
+ # Regression test for #2055
+ it "computes the correct amount" do
+ calculator.compute(2).should == calculator.preferred_normal_amount
+ calculator.compute(6).should == calculator.preferred_discount_amount
+ end
end
From c762d258b9240c7ffdaffdf62bd99029c7362433 Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Mon, 8 Oct 2012 13:05:16 +1100
Subject: [PATCH 214/346] Remove save overriding from Spree::Promotion as
rails/rails@91fd6510563f84ee473bb217bc63ed598abe3f24 fixes the issue
---
promo/app/models/spree/promotion.rb | 8 --------
1 file changed, 8 deletions(-)
diff --git a/promo/app/models/spree/promotion.rb b/promo/app/models/spree/promotion.rb
index 10f00a83a5c..c9b76619dbb 100644
--- a/promo/app/models/spree/promotion.rb
+++ b/promo/app/models/spree/promotion.rb
@@ -40,14 +40,6 @@ def self.with_coupon_code(coupon_code)
search(:code_cont => coupon_code).result
end
- # TODO: Remove that after fix for https://rails.lighthouseapp.com/projects/8994/tickets/4329-has_many-through-association-does-not-link-models-on-association-save
- # is provided
- def save(*)
- if super
- promotion_rules.each(&:save)
- end
- end
-
def activate(payload)
return unless order_activatable? payload[:order]
From 6be61fdd39a57e5d22a3e9b1426f366271bd5874 Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Mon, 8 Oct 2012 15:54:34 +1100
Subject: [PATCH 215/346] Use 1.8 compatible BigDecimal parsing in PriceSack
Fixes this build: https://travis-ci.org/#!/spree/spree/jobs/2701882
---
core/app/models/spree/calculator/price_sack.rb | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/core/app/models/spree/calculator/price_sack.rb b/core/app/models/spree/calculator/price_sack.rb
index 90ac2b0dcb9..a3ea0c18bc9 100644
--- a/core/app/models/spree/calculator/price_sack.rb
+++ b/core/app/models/spree/calculator/price_sack.rb
@@ -1,4 +1,6 @@
require_dependency 'spree/calculator'
+# For #to_d method on Ruby 1.8
+require 'bigdecimal/util'
module Spree
class Calculator::PriceSack < Calculator
@@ -17,9 +19,9 @@ def self.description
# as object we always get line items, as calculable we have Coupon, ShippingMethod
def compute(object)
if object.is_a?(Array)
- base = object.map { |o| o.respond_to?(:amount) ? o.amount : o.to_d }.sum
+ base = object.map { |o| o.respond_to?(:amount) ? o.amount : BigDecimal(o.to_s) }.sum
else
- base = object.respond_to?(:amount) ? object.amount : object.to_d
+ base = object.respond_to?(:amount) ? object.amount : BigDecimal(object.to_s)
end
if base < self.preferred_minimal_amount
From db31a335b727f909b783b251dd1dea5050c70b72 Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Tue, 9 Oct 2012 10:15:19 +1100
Subject: [PATCH 216/346] Make base_helper test for flash_messages more
resilient to random hash order in Ruby 1.8
Conflicts:
core/spec/helpers/base_helper_spec.rb
---
core/app/helpers/spree/base_helper.rb | 2 +-
core/spec/helpers/base_helper_spec.rb | 30 +++++++++++++++++++++++++++
2 files changed, 31 insertions(+), 1 deletion(-)
diff --git a/core/app/helpers/spree/base_helper.rb b/core/app/helpers/spree/base_helper.rb
index 8996c903f37..b6cd6bbaaab 100644
--- a/core/app/helpers/spree/base_helper.rb
+++ b/core/app/helpers/spree/base_helper.rb
@@ -87,7 +87,7 @@ def logo(image_path=Spree::Config[:logo])
end
def flash_messages(opts = {})
- opts[:ignore_types] = [:commerce_tracking].concat([opts[:ignore_types]] || [])
+ opts[:ignore_types] = [:commerce_tracking].concat(Array(opts[:ignore_types]) || [])
flash.each do |msg_type, text|
unless opts[:ignore_types].include?(msg_type)
diff --git a/core/spec/helpers/base_helper_spec.rb b/core/spec/helpers/base_helper_spec.rb
index 3f1342bb475..bae571bde02 100644
--- a/core/spec/helpers/base_helper_spec.rb
+++ b/core/spec/helpers/base_helper_spec.rb
@@ -74,4 +74,34 @@
end
end
+
+ # Regression test for #2034
+ context "flash_message" do
+ let(:flash) { {:notice => "ok", :foo => "foo", :bar => "bar"} }
+
+ it "should output all flash content" do
+ flash_messages
+ html = Nokogiri::HTML(helper.output_buffer)
+ html.css(".notice").text.should == "ok"
+ html.css(".foo").text.should == "foo"
+ html.css(".bar").text.should == "bar"
+ end
+
+ it "should output flash content except one key" do
+ flash_messages(:ignore_types => :bar)
+ html = Nokogiri::HTML(helper.output_buffer)
+ html.css(".notice").text.should == "ok"
+ html.css(".foo").text.should == "foo"
+ html.css(".bar").text.should be_empty
+ end
+
+ it "should output flash content except some keys" do
+ flash_messages(:ignore_types => [:foo, :bar])
+ html = Nokogiri::HTML(helper.output_buffer)
+ html.css(".notice").text.should == "ok"
+ html.css(".foo").text.should be_empty
+ html.css(".bar").text.should be_empty
+ helper.output_buffer.should == "ok
"
+ end
+ end
end
From 27dacbdc2d33546cf07baca59a5a4321536328a6 Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Wed, 10 Oct 2012 16:24:26 +1100
Subject: [PATCH 217/346] use preference_cache_key inside check for preference
Fixes #2067
Conflicts:
core/app/models/spree/preferences/preferable_class_methods.rb
---
core/app/models/spree/preferences/preferable_class_methods.rb | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/core/app/models/spree/preferences/preferable_class_methods.rb b/core/app/models/spree/preferences/preferable_class_methods.rb
index f24a391db9b..d544dbc4fef 100644
--- a/core/app/models/spree/preferences/preferable_class_methods.rb
+++ b/core/app/models/spree/preferences/preferable_class_methods.rb
@@ -15,7 +15,7 @@ def preference(name, type, *args)
else
if get_pending_preference(name)
get_pending_preference(name)
- elsif Spree::Preference.table_exists? && preference = Spree::Preference.find_by_name(name)
+ elsif Spree::Preference.table_exists? && preference = Spree::Preference.find_by_key(preference_cache_key(name))
preference.value
else
send self.class.preference_default_getter_method(name)
From b85a8968eadce601e62432986511da6337381206 Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Wed, 10 Oct 2012 18:00:41 +1100
Subject: [PATCH 218/346] Revert "use preference_cache_key inside check for
preference"
This reverts commit 27dacbdc2d33546cf07baca59a5a4321536328a6.
---
core/app/models/spree/preferences/preferable_class_methods.rb | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/core/app/models/spree/preferences/preferable_class_methods.rb b/core/app/models/spree/preferences/preferable_class_methods.rb
index d544dbc4fef..f24a391db9b 100644
--- a/core/app/models/spree/preferences/preferable_class_methods.rb
+++ b/core/app/models/spree/preferences/preferable_class_methods.rb
@@ -15,7 +15,7 @@ def preference(name, type, *args)
else
if get_pending_preference(name)
get_pending_preference(name)
- elsif Spree::Preference.table_exists? && preference = Spree::Preference.find_by_key(preference_cache_key(name))
+ elsif Spree::Preference.table_exists? && preference = Spree::Preference.find_by_name(name)
preference.value
else
send self.class.preference_default_getter_method(name)
From 1a7a1006cd99de777ab6665eeb45391940c47a83 Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Thu, 11 Oct 2012 11:51:38 +1100
Subject: [PATCH 219/346] Ensure that address information cannot be updated by
people who do not own it
---
.../spree/api/v1/addresses_controller.rb | 2 ++
.../spree/api/v1/addresses_controller_spec.rb | 36 +++++++++++++++----
core/app/models/spree/ability.rb | 5 +++
3 files changed, 36 insertions(+), 7 deletions(-)
diff --git a/api/app/controllers/spree/api/v1/addresses_controller.rb b/api/app/controllers/spree/api/v1/addresses_controller.rb
index c22596b2652..aa708d0ffb9 100644
--- a/api/app/controllers/spree/api/v1/addresses_controller.rb
+++ b/api/app/controllers/spree/api/v1/addresses_controller.rb
@@ -4,10 +4,12 @@ module V1
class AddressesController < Spree::Api::V1::BaseController
def show
@address = Address.find(params[:id])
+ authorize! :read, @address
end
def update
@address = Address.find(params[:id])
+ authorize! :read, @address
@address.update_attributes(params[:address])
render :show, :status => 200
end
diff --git a/api/spec/controllers/spree/api/v1/addresses_controller_spec.rb b/api/spec/controllers/spree/api/v1/addresses_controller_spec.rb
index 293fee15d50..1ff3175556a 100644
--- a/api/spec/controllers/spree/api/v1/addresses_controller_spec.rb
+++ b/api/spec/controllers/spree/api/v1/addresses_controller_spec.rb
@@ -9,15 +9,37 @@ module Spree
@address = create(:address)
end
- it "gets an address" do
- api_get :show, :id => @address.id
- json_response['address']['address1'].should eq @address.address1
+ context "with their own address" do
+ before do
+ Address.any_instance.stub :user => current_api_user
+ end
+
+ it "gets an address" do
+ api_get :show, :id => @address.id
+ json_response['address']['address1'].should eq @address.address1
+ end
+
+ it "updates an address" do
+ api_put :update, :id => @address.id,
+ :address => { :address1 => "123 Test Lane" }
+ json_response['address']['address1'].should eq '123 Test Lane'
+ end
end
- it "updates an address" do
- api_put :update, :id => @address.id,
- :address => { :address1 => "123 Test Lane" }
- json_response['address']['address1'].should eq '123 Test Lane'
+ context "on somebody else's address" do
+ before do
+ Address.any_instance.stub :user => stub_model(Spree::LegacyUser)
+ end
+
+ it "cannot retreive address information" do
+ api_get :show, :id => @address.id
+ assert_unauthorized!
+ end
+
+ it "cannot update address information" do
+ api_get :update, :id => @address.id
+ assert_unauthorized!
+ end
end
end
end
diff --git a/core/app/models/spree/ability.rb b/core/app/models/spree/ability.rb
index 7a9fc2c9af0..a6864a7fb55 100644
--- a/core/app/models/spree/ability.rb
+++ b/core/app/models/spree/ability.rb
@@ -51,6 +51,11 @@ def initialize(user)
order.user == user || order.token && token == order.token
end
can :create, Order
+
+ can :read, Address do |address|
+ address.user == user
+ end
+
#############################
can :read, Product
can :index, Product
From 0be84a409f31a1b507d5b50e1d33fe8850344783 Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Thu, 11 Oct 2012 11:57:50 +1100
Subject: [PATCH 220/346] [api] only admins should be allowed to create, edit
or delete images
---
.../spree/api/v1/images_controller.rb | 3 +
.../spree/api/v1/images_controller_spec.rb | 63 ++++++++++++-------
2 files changed, 45 insertions(+), 21 deletions(-)
diff --git a/api/app/controllers/spree/api/v1/images_controller.rb b/api/app/controllers/spree/api/v1/images_controller.rb
index b8df78a4d79..096b8972a26 100644
--- a/api/app/controllers/spree/api/v1/images_controller.rb
+++ b/api/app/controllers/spree/api/v1/images_controller.rb
@@ -7,17 +7,20 @@ def show
end
def create
+ authorize! :create, Image
@image = Image.create(params[:image])
render :show, :status => 201
end
def update
+ authorize! :update, Image
@image = Image.find(params[:id])
@image.update_attributes(params[:image])
render :show, :status => 200
end
def destroy
+ authorize! :delete, Image
@image = Image.find(params[:id])
@image.destroy
render :text => nil
diff --git a/api/spec/controllers/spree/api/v1/images_controller_spec.rb b/api/spec/controllers/spree/api/v1/images_controller_spec.rb
index 28076b3569c..430adc73c07 100644
--- a/api/spec/controllers/spree/api/v1/images_controller_spec.rb
+++ b/api/spec/controllers/spree/api/v1/images_controller_spec.rb
@@ -13,32 +13,53 @@ module Spree
stub_authentication!
end
- it "can upload a new image for a variant" do
- lambda do
- api_post :create,
- :image => { :attachment => upload_image('thinking-cat.jpg'),
- :viewable_type => 'Spree::Variant',
- :viewable_id => product.master.to_param }
- response.status.should == 201
- json_response.should have_attributes(attributes)
- end.should change(Image, :count).by(1)
+ context "as an admin" do
+ sign_in_as_admin!
+
+ it "can upload a new image for a variant" do
+ lambda do
+ api_post :create,
+ :image => { :attachment => upload_image('thinking-cat.jpg'),
+ :viewable_type => 'Spree::Variant',
+ :viewable_id => product.master.to_param }
+ response.status.should == 201
+ json_response.should have_attributes(attributes)
+ end.should change(Image, :count).by(1)
+ end
+
+ context "working with an existing image" do
+ let!(:product_image) { product.master.images.create!(:attachment => image('thinking-cat.jpg')) }
+
+ it "can update image data" do
+ product_image.position.should == 1
+ api_post :update, :image => { :position => 2 }, :id => product_image.id
+ response.status.should == 200
+ json_response.should have_attributes(attributes)
+ product_image.reload.position.should == 2
+ end
+
+ it "can delete an image" do
+ api_delete :destroy, :id => product_image.id
+ response.status.should == 200
+ lambda { product_image.reload }.should raise_error(ActiveRecord::RecordNotFound)
+ end
+ end
end
- context "working with an existing image" do
- let!(:product_image) { product.master.images.create!(:attachment => image('thinking-cat.jpg')) }
+ context "as a non-admin" do
+ it "cannot create an image" do
+ api_post :create
+ assert_unauthorized!
+ end
- it "can update image data" do
- product_image.position.should == 1
- api_post :update, :image => { :position => 2 }, :id => product_image.id
- response.status.should == 200
- json_response.should have_attributes(attributes)
- product_image.reload.position.should == 2
+ it "cannot update an image" do
+ api_put :update, :id => 1
+ assert_unauthorized!
end
- it "can delete an image" do
- api_delete :destroy, :id => product_image.id
- response.status.should == 200
- lambda { product_image.reload }.should raise_error(ActiveRecord::RecordNotFound)
+ it "cannot delete an image" do
+ api_delete :destroy, :id => 1
+ assert_unauthorized!
end
end
end
From 2268ac127032fa4da0591eef01376f71cc4f74e4 Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Thu, 11 Oct 2012 12:03:31 +1100
Subject: [PATCH 221/346] [api] Only allow admins to transition shipments to
ready and ship
---
.../spree/api/v1/shipments_controller.rb | 3 +++
.../spree/api/v1/shipments_controller_spec.rb | 18 ++++++++++++++++--
2 files changed, 19 insertions(+), 2 deletions(-)
diff --git a/api/app/controllers/spree/api/v1/shipments_controller.rb b/api/app/controllers/spree/api/v1/shipments_controller.rb
index 2f44e970754..ecd7f3629d5 100644
--- a/api/app/controllers/spree/api/v1/shipments_controller.rb
+++ b/api/app/controllers/spree/api/v1/shipments_controller.rb
@@ -6,6 +6,7 @@ class ShipmentsController < BaseController
before_filter :find_and_update_shipment, :only => [:ship, :ready]
def ready
+ authorize! :read, Shipment
unless @shipment.ready?
@shipment.ready!
end
@@ -13,6 +14,7 @@ def ready
end
def ship
+ authorize! :read, Shipment
unless @shipment.shipped?
@shipment.ship!
end
@@ -23,6 +25,7 @@ def ship
def find_order
@order = Spree::Order.find_by_number!(params[:order_id])
+ authorize! :read, @order
end
def find_and_update_shipment
diff --git a/api/spec/controllers/spree/api/v1/shipments_controller_spec.rb b/api/spec/controllers/spree/api/v1/shipments_controller_spec.rb
index f3b35baad70..14c8529cc1f 100644
--- a/api/spec/controllers/spree/api/v1/shipments_controller_spec.rb
+++ b/api/spec/controllers/spree/api/v1/shipments_controller_spec.rb
@@ -10,8 +10,22 @@
stub_authentication!
end
- context "working with a shipment" do
- let!(:resource_scoping) { { :order_id => shipment.order.to_param, :id => shipment.to_param } }
+ let!(:resource_scoping) { { :order_id => shipment.order.to_param, :id => shipment.to_param } }
+
+ context "as a non-admin" do
+ it "cannot make a shipment ready" do
+ api_put :ready
+ assert_unauthorized!
+ end
+
+ it "cannot make a shipment shipped" do
+ api_put :ship
+ assert_unauthorized!
+ end
+ end
+
+ context "as an admin" do
+ sign_in_as_admin!
it "can make a shipment ready" do
api_put :ready
From 65f5c0664ec9edf16099237e91a870e28c69e830 Mon Sep 17 00:00:00 2001
From: Brian Quinn
Date: Thu, 11 Oct 2012 15:25:27 +0100
Subject: [PATCH 222/346] Pass all changes to variant.count_on_hand to on_hand=
to ensure backorders are processed correctly. Also, added lock_version column
to prevent stale update to variants on hand values.
---
core/app/models/spree/variant.rb | 7 +++++
...21009142519_add_lock_version_to_variant.rb | 5 ++++
core/spec/models/variant_spec.rb | 26 +++++++++++++++++++
3 files changed, 38 insertions(+)
create mode 100644 core/db/migrate/20121009142519_add_lock_version_to_variant.rb
diff --git a/core/app/models/spree/variant.rb b/core/app/models/spree/variant.rb
index 20da446f7cc..497fb5ae5d7 100644
--- a/core/app/models/spree/variant.rb
+++ b/core/app/models/spree/variant.rb
@@ -21,6 +21,7 @@ class Variant < ActiveRecord::Base
validates :cost_price, :numericality => { :greater_than_or_equal_to => 0, :allow_nil => true } if self.table_exists? && self.column_names.include?('cost_price')
validates :count_on_hand, :numericality => true
+ before_save :process_backorders
after_save :recalculate_product_on_hand, :if => :is_master?
# default variant scope only lists non-deleted variants
@@ -134,6 +135,12 @@ def option_value(opt_name)
private
+ def process_backorders
+ if count_changes = changes['count_on_hand']
+ self.on_hand = count_changes.last
+ end
+ end
+
# strips all non-price-like characters from the price, taking into account locale settings
def parse_price(price)
price = price.to_s
diff --git a/core/db/migrate/20121009142519_add_lock_version_to_variant.rb b/core/db/migrate/20121009142519_add_lock_version_to_variant.rb
new file mode 100644
index 00000000000..91c8ec33a7f
--- /dev/null
+++ b/core/db/migrate/20121009142519_add_lock_version_to_variant.rb
@@ -0,0 +1,5 @@
+class AddLockVersionToVariant < ActiveRecord::Migration
+ def change
+ add_column :spree_variants, :lock_version, :integer, :default => 0
+ end
+end
diff --git a/core/spec/models/variant_spec.rb b/core/spec/models/variant_spec.rb
index 86791895c76..8e20635d54b 100644
--- a/core/spec/models/variant_spec.rb
+++ b/core/spec/models/variant_spec.rb
@@ -28,6 +28,22 @@
variant.run_callbacks(:save)
end
+ it "lock_version should prevent stale updates" do
+ copy = Spree::Variant.find(variant.id)
+
+ copy.count_on_hand = 200
+ copy.save!
+
+ variant.count_on_hand = 100
+ expect { variant.save }.to raise_error ActiveRecord::StaleObjectError
+
+ variant.reload.count_on_hand.should == 200
+ variant.count_on_hand = 100
+ variant.save
+
+ variant.reload.count_on_hand.should == 100
+ end
+
context "on_hand=" do
before { variant.stub(:inventory_units => mock('inventory-units')) }
@@ -130,6 +146,16 @@
end
+ context "count_on_hand" do
+ context "when setting count_on_hand directly" do
+ it "should pass new value to on_hand=" do
+ variant.count_on_hand = 20
+ variant.should_receive(:on_hand=).with(20)
+ variant.run_callbacks(:save)
+ end
+ end
+ end
+
context "in_stock?" do
context "when :track_inventory_levels is true" do
before { Spree::Config.set :track_inventory_levels => true }
From c0a05db2bf29446b3c017b9a10296cb86dd72ac5 Mon Sep 17 00:00:00 2001
From: Brian Quinn
Date: Thu, 11 Oct 2012 15:52:02 +0100
Subject: [PATCH 223/346] Make variant lock_version accessible
---
core/app/models/spree/variant.rb | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/core/app/models/spree/variant.rb b/core/app/models/spree/variant.rb
index 497fb5ae5d7..f8f9ce8f481 100644
--- a/core/app/models/spree/variant.rb
+++ b/core/app/models/spree/variant.rb
@@ -6,7 +6,7 @@ class Variant < ActiveRecord::Base
:tax_category_id, :shipping_category_id, :meta_description,
:meta_keywords, :tax_category
- attr_accessible :name, :presentation, :cost_price,
+ attr_accessible :name, :presentation, :cost_price, :lock_version,
:position, :on_hand, :option_value_ids,
:product_id, :option_values_attributes, :price,
:weight, :height, :width, :depth, :sku
From 63d42a1fa3e47d05d5a0d59438113c17f809488d Mon Sep 17 00:00:00 2001
From: Brian Quinn
Date: Thu, 11 Oct 2012 20:58:43 +0100
Subject: [PATCH 224/346] Move backorder fulfillment within the variant model
into after_save callback, it was being called too early (on on_hand being
set). Now it waits for the variant to be saved before processing.
---
core/app/models/spree/variant.rb | 30 +++++++++++++++++-------------
core/spec/models/variant_spec.rb | 12 +-----------
2 files changed, 18 insertions(+), 24 deletions(-)
diff --git a/core/app/models/spree/variant.rb b/core/app/models/spree/variant.rb
index f8f9ce8f481..5e7c094387f 100644
--- a/core/app/models/spree/variant.rb
+++ b/core/app/models/spree/variant.rb
@@ -21,7 +21,7 @@ class Variant < ActiveRecord::Base
validates :cost_price, :numericality => { :greater_than_or_equal_to => 0, :allow_nil => true } if self.table_exists? && self.column_names.include?('cost_price')
validates :count_on_hand, :numericality => true
- before_save :process_backorders
+ after_save :process_backorders
after_save :recalculate_product_on_hand, :if => :is_master?
# default variant scope only lists non-deleted variants
@@ -33,19 +33,9 @@ def on_hand
Spree::Config[:track_inventory_levels] ? count_on_hand : (1.0 / 0) # Infinity
end
- # Adjusts the inventory units to match the given new level.
+ # set actual attribute
def on_hand=(new_level)
if Spree::Config[:track_inventory_levels]
- new_level = new_level.to_i
-
- # increase Inventory when
- if new_level > on_hand
- # fill backordered orders before creating new units
- backordered_units = inventory_units.with_state('backordered')
- backordered_units.slice(0, new_level).each(&:fill_backorder)
- new_level -= backordered_units.length
- end
-
self.count_on_hand = new_level
else
raise 'Cannot set on_hand value when Spree::Config[:track_inventory_levels] is false'
@@ -137,7 +127,21 @@ def option_value(opt_name)
def process_backorders
if count_changes = changes['count_on_hand']
- self.on_hand = count_changes.last
+ new_level = count_changes.last
+
+ if Spree::Config[:track_inventory_levels]
+ new_level = new_level.to_i
+
+ # update backorders if level is positive
+ if new_level > 0
+ # fill backordered orders before creating new units
+ backordered_units = inventory_units.with_state('backordered')
+ backordered_units.slice(0, new_level).each(&:fill_backorder)
+ new_level -= backordered_units.length
+ end
+
+ self.update_attribute_without_callbacks(:count_on_hand, new_level)
+ end
end
end
diff --git a/core/spec/models/variant_spec.rb b/core/spec/models/variant_spec.rb
index 8e20635d54b..7b4ee236b58 100644
--- a/core/spec/models/variant_spec.rb
+++ b/core/spec/models/variant_spec.rb
@@ -98,7 +98,7 @@
end
- context "and count is decreased" do
+ context "and count is negative" do
before { variant.inventory_units.stub(:with_state).and_return([]) }
it "should change count_on_hand to given value" do
@@ -146,16 +146,6 @@
end
- context "count_on_hand" do
- context "when setting count_on_hand directly" do
- it "should pass new value to on_hand=" do
- variant.count_on_hand = 20
- variant.should_receive(:on_hand=).with(20)
- variant.run_callbacks(:save)
- end
- end
- end
-
context "in_stock?" do
context "when :track_inventory_levels is true" do
before { Spree::Config.set :track_inventory_levels => true }
From 4eb5ecfdbc0ad5a4ea6f31598b074bad60c6124b Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Fri, 12 Oct 2012 08:21:44 +1100
Subject: [PATCH 225/346] Spree::AuthenticationHelpers should be loaded each
request, not just once
Fixes #2076
---
.../generators/spree/custom_user/custom_user_generator.rb | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/core/lib/generators/spree/custom_user/custom_user_generator.rb b/core/lib/generators/spree/custom_user/custom_user_generator.rb
index cb261d0edc4..8c9be8278c1 100644
--- a/core/lib/generators/spree/custom_user/custom_user_generator.rb
+++ b/core/lib/generators/spree/custom_user/custom_user_generator.rb
@@ -27,7 +27,10 @@ def generate
file_action = File.exist?('config/initializers/spree.rb') ? :append_file : :create_file
send(file_action, 'config/initializers/spree.rb') do
- %Q{require 'spree/authentication_helpers'\n}
+ %Q{
+ Rails.application.config.to_prepare do
+ require_dependency 'spree/authentication_helpers'
+ end\n}
end
end
From 7d26aa20af3cbc9be70ba9074f5c05ee676637d8 Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Fri, 12 Oct 2012 12:03:07 +1100
Subject: [PATCH 226/346] Don't alter variant on_hand amount with
InventoryUnit#restock_variant if track_inventory_units is disabled
---
core/app/models/spree/inventory_unit.rb | 6 ++++--
core/spec/models/inventory_unit_spec.rb | 11 +++++++++++
2 files changed, 15 insertions(+), 2 deletions(-)
diff --git a/core/app/models/spree/inventory_unit.rb b/core/app/models/spree/inventory_unit.rb
index c12905fe155..cd020232471 100644
--- a/core/app/models/spree/inventory_unit.rb
+++ b/core/app/models/spree/inventory_unit.rb
@@ -113,8 +113,10 @@ def update_order
end
def restock_variant
- variant.on_hand += 1
- variant.save
+ if Spree::Config[:track_inventory_levels]
+ variant.on_hand += 1
+ variant.save
+ end
end
end
end
diff --git a/core/spec/models/inventory_unit_spec.rb b/core/spec/models/inventory_unit_spec.rb
index 30f2d532f34..8ae2a763d67 100644
--- a/core/spec/models/inventory_unit_spec.rb
+++ b/core/spec/models/inventory_unit_spec.rb
@@ -258,6 +258,17 @@
inventory_unit.variant.should_receive(:save)
inventory_unit.return!
end
+
+ # Regression test for #2074
+ context "with inventory tracking disabled" do
+ before { Spree::Config[:track_inventory_levels] = false }
+
+ it "does not update on_hand for variant" do
+ inventory_unit.variant.should_not_receive(:on_hand=).with(96)
+ inventory_unit.variant.should_not_receive(:save)
+ inventory_unit.return!
+ end
+ end
end
end
From 9b2276b49ff0ac0d39e6e772aee401d053563c28 Mon Sep 17 00:00:00 2001
From: Brian Quinn
Date: Fri, 12 Oct 2012 15:17:43 +0100
Subject: [PATCH 227/346] Shipments should remain pending until the order is
complete, and its state should be updated to the correct state when the order
completes. Currently shipments where incorrectly becoming "ready" when the
order was still in checkout.
---
core/app/models/spree/order.rb | 8 +++++++-
core/app/models/spree/shipment.rb | 3 ++-
core/spec/models/order_spec.rb | 8 +++++++-
core/spec/models/shipment_spec.rb | 10 +++++++++-
4 files changed, 25 insertions(+), 4 deletions(-)
diff --git a/core/app/models/spree/order.rb b/core/app/models/spree/order.rb
index d0b3b998667..5dafb109304 100644
--- a/core/app/models/spree/order.rb
+++ b/core/app/models/spree/order.rb
@@ -349,8 +349,14 @@ def credit_cards
def finalize!
touch :completed_at
InventoryUnit.assign_opening_inventory(self)
+
# lock all adjustments (coupon promotions, etc.)
adjustments.each { |adjustment| adjustment.update_column('locked', true) }
+
+ # update shipments (get their states set correctly)
+ update_payment_state
+ shipments.each { |shipment| shipment.update!(self) }
+
deliver_order_confirmation_email
self.state_changes.create({
@@ -531,7 +537,7 @@ def update_shipment_state
#
# The +payment_state+ value helps with reporting, etc. since it provides a quick and easy way to locate Orders needing attention.
def update_payment_state
-
+
#line_item are empty when user empties cart
if self.line_items.empty? || round_money(payment_total) < round_money(total)
self.payment_state = 'balance_due'
diff --git a/core/app/models/spree/shipment.rb b/core/app/models/spree/shipment.rb
index c91bafbe234..9808c2cbad4 100644
--- a/core/app/models/spree/shipment.rb
+++ b/core/app/models/spree/shipment.rb
@@ -115,10 +115,11 @@ def validate_shipping_method
# Determines the appropriate +state+ according to the following logic:
#
- # pending unless +order.payment_state+ is +paid+
+ # pending unless order is complete and +order.payment_state+ is +paid+
# shipped if already shipped (ie. does not change the state)
# ready all other cases
def determine_state(order)
+ return 'pending' unless order.complete?
return 'pending' if inventory_units.any? &:backordered?
return 'shipped' if state == 'shipped'
order.paid? ? 'ready' : 'pending'
diff --git a/core/spec/models/order_spec.rb b/core/spec/models/order_spec.rb
index 9a933b2fd27..37258a69366 100644
--- a/core/spec/models/order_spec.rb
+++ b/core/spec/models/order_spec.rb
@@ -85,7 +85,13 @@ def compute(computable)
Spree::InventoryUnit.should_receive(:assign_opening_inventory).with(order)
order.finalize!
end
- it "should change the shipment state to ready if order is paid"
+ it "should change the shipment state to ready if order is paid" do
+ order.stub :shipping_method => mock_model(Spree::ShippingMethod, :create_adjustment => true)
+ order.create_shipment!
+ order.stub(:paid? => true, :complete? => true)
+ order.finalize!
+ order.shipment.state.should == 'ready'
+ end
after { Spree::Config.set :track_inventory_levels => true }
it "should not sell inventory units if track_inventory_levels is false" do
diff --git a/core/spec/models/shipment_spec.rb b/core/spec/models/shipment_spec.rb
index 2644660f7d4..0d58189e430 100644
--- a/core/spec/models/shipment_spec.rb
+++ b/core/spec/models/shipment_spec.rb
@@ -5,7 +5,7 @@
reset_spree_preferences
end
- let(:order) { mock_model Spree::Order, :backordered? => false }
+ let(:order) { mock_model Spree::Order, :backordered? => false, :complete? => true }
let(:shipping_method) { mock_model Spree::ShippingMethod, :calculator => mock('calculator') }
let(:shipment) do
shipment = Spree::Shipment.new :order => order, :shipping_method => shipping_method
@@ -44,6 +44,14 @@
end
end
+ context "when order is incomplete" do
+ before { order.stub :complete? => false }
+ it "should result in a 'pending' state" do
+ shipment.should_receive(:update_column).with("state", "pending")
+ shipment.update!(order)
+ end
+ end
+
context "when order is paid" do
before { order.stub :paid? => true }
it "should result in a 'ready' state" do
From 7df8f8d05580daf6c3979ab50f0d67ff182218a6 Mon Sep 17 00:00:00 2001
From: Brian Quinn
Date: Fri, 12 Oct 2012 15:47:31 +0100
Subject: [PATCH 228/346] Fix Api shipments_controller_spec
---
api/spec/controllers/spree/api/v1/shipments_controller_spec.rb | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/api/spec/controllers/spree/api/v1/shipments_controller_spec.rb b/api/spec/controllers/spree/api/v1/shipments_controller_spec.rb
index 14c8529cc1f..cc5886ba0ed 100644
--- a/api/spec/controllers/spree/api/v1/shipments_controller_spec.rb
+++ b/api/spec/controllers/spree/api/v1/shipments_controller_spec.rb
@@ -6,7 +6,7 @@
let!(:attributes) { [:id, :tracking, :number, :cost, :shipped_at] }
before do
- Spree::Order.any_instance.stub(:paid? => true)
+ Spree::Order.any_instance.stub(:paid? => true, :complete? => true)
stub_authentication!
end
From 1b5af2ae3b7ad0084201d0dc70b69451e7fed928 Mon Sep 17 00:00:00 2001
From: Brian Quinn
Date: Fri, 12 Oct 2012 18:27:29 +0100
Subject: [PATCH 229/346] Update order shipment_state on finalize also
---
core/app/models/spree/order.rb | 4 +++-
core/spec/models/order_spec.rb | 2 ++
2 files changed, 5 insertions(+), 1 deletion(-)
diff --git a/core/app/models/spree/order.rb b/core/app/models/spree/order.rb
index 5dafb109304..ae093d44553 100644
--- a/core/app/models/spree/order.rb
+++ b/core/app/models/spree/order.rb
@@ -353,9 +353,11 @@ def finalize!
# lock all adjustments (coupon promotions, etc.)
adjustments.each { |adjustment| adjustment.update_column('locked', true) }
- # update shipments (get their states set correctly)
+ # update payment and shipment(s) states, and save
update_payment_state
shipments.each { |shipment| shipment.update!(self) }
+ update_shipment_state
+ save
deliver_order_confirmation_email
diff --git a/core/spec/models/order_spec.rb b/core/spec/models/order_spec.rb
index 37258a69366..cb978cbe5d0 100644
--- a/core/spec/models/order_spec.rb
+++ b/core/spec/models/order_spec.rb
@@ -90,7 +90,9 @@ def compute(computable)
order.create_shipment!
order.stub(:paid? => true, :complete? => true)
order.finalize!
+ order.reload # reload so we're sure the changes are persisted
order.shipment.state.should == 'ready'
+ order.shipment_state.should == 'ready'
end
after { Spree::Config.set :track_inventory_levels => true }
From fa309c75124521978eaed5717bf82e466186de75 Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Mon, 15 Oct 2012 08:28:29 +1030
Subject: [PATCH 230/346] Line item quantity validator must be greater than -1
This is because the delete button on the cart zeroes the quantity field on line items before submitting the form again.
We will perhaps need to take a look at improving the cart interface so that line items are removed in the background.
---
core/app/models/spree/line_item.rb | 2 +-
core/spec/requests/cart_spec.rb | 11 +++++++++++
2 files changed, 12 insertions(+), 1 deletion(-)
diff --git a/core/app/models/spree/line_item.rb b/core/app/models/spree/line_item.rb
index fd19371684a..d08fd072e91 100644
--- a/core/app/models/spree/line_item.rb
+++ b/core/app/models/spree/line_item.rb
@@ -10,7 +10,7 @@ class LineItem < ActiveRecord::Base
before_validation :copy_price
validates :variant, :presence => true
- validates :quantity, :numericality => { :only_integer => true, :message => I18n.t('validation.must_be_int'), :greater_than => 0 }
+ validates :quantity, :numericality => { :only_integer => true, :message => I18n.t('validation.must_be_int'), :greater_than => -1 }
validates :price, :numericality => true
validate :stock_availability
validate :quantity_no_less_than_shipped
diff --git a/core/spec/requests/cart_spec.rb b/core/spec/requests/cart_spec.rb
index b367072e6d1..81be9c406f2 100644
--- a/core/spec/requests/cart_spec.rb
+++ b/core/spec/requests/cart_spec.rb
@@ -33,4 +33,15 @@
page.should have_content(I18n.t(:populate_get_error))
end
end
+
+ it 'allows you to remove an item from the cart', :js => true do
+ create(:product, :name => "RoR Mug", :on_hand => 1)
+ visit spree.root_path
+ click_link "RoR Mug"
+ click_button "add-to-cart-button"
+ within("#line_items") do
+ click_link "delete_line_item_1"
+ end
+ page.should_not have_content("Line items quantity must be an integer")
+ end
end
From 486fe41c36aabf2689a3e81f642ca802d54b9d74 Mon Sep 17 00:00:00 2001
From: Jeff Dutil
Date: Mon, 15 Oct 2012 16:06:07 -0400
Subject: [PATCH 231/346] Correct card_code typo, and add coupon code hook.
Fixes #2088
---
core/app/views/spree/checkout/payment/_gateway.html.erb | 2 +-
.../app/views/spree/checkout/_coupon_code_field.html.erb | 8 ++++----
2 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/core/app/views/spree/checkout/payment/_gateway.html.erb b/core/app/views/spree/checkout/payment/_gateway.html.erb
index d282c231360..fc4fd319739 100644
--- a/core/app/views/spree/checkout/payment/_gateway.html.erb
+++ b/core/app/views/spree/checkout/payment/_gateway.html.erb
@@ -19,7 +19,7 @@
<%= select_year(Date.today, :prefix => param_prefix, :field_name => 'year', :start_year => Date.today.year, :end_year => Date.today.year + 15, :class => 'required') %>
*
-
+
<%= label_tag nil, t(:card_code) %>
<%= text_field_tag "#{param_prefix}[verification_value]", '', options_hash.merge(:id => 'card_code', :class => 'required', :size => 5) %>
*
diff --git a/promo/app/views/spree/checkout/_coupon_code_field.html.erb b/promo/app/views/spree/checkout/_coupon_code_field.html.erb
index 2e55f0daa99..5b0f3aec58f 100644
--- a/promo/app/views/spree/checkout/_coupon_code_field.html.erb
+++ b/promo/app/views/spree/checkout/_coupon_code_field.html.erb
@@ -1,6 +1,6 @@
<% if Spree::Promotion.count > 0 %>
-
- <%= form.label :coupon_code %>
- <%= form.text_field :coupon_code %>
-
+
+ <%= form.label :coupon_code %>
+ <%= form.text_field :coupon_code %>
+
<% end %>
From 1b393a0ce925a7b67b64e658f0982c833b338953 Mon Sep 17 00:00:00 2001
From: John Dyer
Date: Fri, 12 Oct 2012 14:43:38 -0400
Subject: [PATCH 232/346] Update order before redirecting to checkout when
'Checkout' button is pressed on cart page
Fixes #2086
---
core/app/views/spree/orders/edit.html.erb | 4 +++-
.../admin/configuration/shipping_methods_spec.rb | 12 ++++++------
core/spec/requests/checkout_spec.rb | 2 +-
.../controllers/spree/orders_controller_decorator.rb | 10 +++++++++-
4 files changed, 19 insertions(+), 9 deletions(-)
diff --git a/core/app/views/spree/orders/edit.html.erb b/core/app/views/spree/orders/edit.html.erb
index 3dcd125acbb..3e8393fb0eb 100644
--- a/core/app/views/spree/orders/edit.html.erb
+++ b/core/app/views/spree/orders/edit.html.erb
@@ -26,7 +26,9 @@
<%= button_tag :class => 'primary', :id => 'update-button' do %>
<%= t(:update) %>
<% end %>
- <%= link_to t(:checkout), checkout_state_path(@order.checkout_steps.first), :class => 'button checkout primary', :id => 'checkout-link' %>
+ <%= button_tag :class => 'button checkout primary', :id => 'checkout-link', :name => 'checkout' do %>
+ <%= t(:checkout) %>
+ <% end %>
diff --git a/core/spec/requests/admin/configuration/shipping_methods_spec.rb b/core/spec/requests/admin/configuration/shipping_methods_spec.rb
index be1a32085e8..62f0b8f9027 100644
--- a/core/spec/requests/admin/configuration/shipping_methods_spec.rb
+++ b/core/spec/requests/admin/configuration/shipping_methods_spec.rb
@@ -81,7 +81,7 @@
visit spree.root_path
click_link "Mug"
click_button "Add To Cart"
- click_link "Checkout"
+ click_button "Checkout"
str_addr = "bill_address"
select "United States", :from => "order_#{str_addr}_attributes_country_id"
@@ -108,7 +108,7 @@
visit spree.root_path
click_link "Mug"
click_button "Add To Cart"
- click_link "Checkout"
+ click_button "Checkout"
str_addr = "bill_address"
select "United States", :from => "order_#{str_addr}_attributes_country_id"
@@ -137,7 +137,7 @@
visit spree.root_path
click_link "Mug"
click_button "Add To Cart"
- click_link "Checkout"
+ click_button "Checkout"
str_addr = "bill_address"
select "United States", :from => "order_#{str_addr}_attributes_country_id"
@@ -162,7 +162,7 @@
visit spree.root_path
click_link "Mug"
click_button "Add To Cart"
- click_link "Checkout"
+ click_button "Checkout"
str_addr = "bill_address"
select "United States", :from => "order_#{str_addr}_attributes_country_id"
@@ -198,7 +198,7 @@
click_link "Home"
click_link "Shirt"
click_button "Add To Cart"
- click_link "Checkout"
+ click_button "Checkout"
str_addr = "bill_address"
select "United States", :from => "order_#{str_addr}_attributes_country_id"
@@ -226,7 +226,7 @@
click_link "Home"
click_link "Shirt"
click_button "Add To Cart"
- click_link "Checkout"
+ click_button "Checkout"
str_addr = "bill_address"
select "United States", :from => "order_#{str_addr}_attributes_country_id"
diff --git a/core/spec/requests/checkout_spec.rb b/core/spec/requests/checkout_spec.rb
index 8f5776057aa..7e5056a714b 100644
--- a/core/spec/requests/checkout_spec.rb
+++ b/core/spec/requests/checkout_spec.rb
@@ -91,7 +91,7 @@
visit spree.root_path
click_link "RoR Mug"
click_button "add-to-cart-button"
- click_link "Checkout"
+ click_button "Checkout"
Spree::Order.last.update_column(:email, "ryan@spreecommerce.com")
address = "order_bill_address_attributes"
diff --git a/promo/app/controllers/spree/orders_controller_decorator.rb b/promo/app/controllers/spree/orders_controller_decorator.rb
index e193d3b2c9b..7b3dda46fb0 100644
--- a/promo/app/controllers/spree/orders_controller_decorator.rb
+++ b/promo/app/controllers/spree/orders_controller_decorator.rb
@@ -13,7 +13,15 @@ def update
end
@order.line_items = @order.line_items.select {|li| li.quantity > 0 }
fire_event('spree.order.contents_changed')
- respond_with(@order) { |format| format.html { redirect_to cart_path } }
+ respond_with(@order) do |format|
+ format.html do
+ if params.has_key?(:checkout)
+ redirect_to checkout_state_path(@order.checkout_steps.first)
+ else
+ redirect_to cart_path
+ end
+ end
+ end
else
respond_with(@order)
end
From 09cc6b91edb226fbd3cca785df40fc9d493d5c3d Mon Sep 17 00:00:00 2001
From: Jeff Dutil
Date: Fri, 12 Oct 2012 10:43:16 -0400
Subject: [PATCH 233/346] Return product records rather than just their ids.
Fixes #2082
---
core/app/models/spree/product/scopes.rb | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/core/app/models/spree/product/scopes.rb b/core/app/models/spree/product/scopes.rb
index 6226b7c56a4..f5a7eff8bc2 100644
--- a/core/app/models/spree/product/scopes.rb
+++ b/core/app/models/spree/product/scopes.rb
@@ -113,7 +113,7 @@ def self.simple_scopes
end
conditions = "#{option_values}.name = ? AND #{option_values}.option_type_id = ?", value, option_type_id
- select("DISTINCT spree_products.id").joins(:variants_including_master => :option_values).where(conditions)
+ group("spree_products.id").joins(:variants_including_master => :option_values).where(conditions)
end
# Finds all products which have either:
@@ -192,7 +192,7 @@ def self.available(available_on = nil)
end
add_search_scope :taxons_name_eq do |name|
- select("DISTINCT spree_products.id").joins(:taxons).where(Taxon.arel_table[:name].eq(name))
+ group("spree_products.id").joins(:taxons).where(Taxon.arel_table[:name].eq(name))
end
if (ActiveRecord::Base.connection.adapter_name == 'PostgreSQL')
From 7d35001bf23763b7314580ffc2ef4a293bb568b7 Mon Sep 17 00:00:00 2001
From: Jeff Dutil
Date: Fri, 12 Oct 2012 09:43:10 -0400
Subject: [PATCH 234/346] Define import variables scss explicitly to allow
extensions to run JS request specs.
Fixes #2081
---
core/app/assets/stylesheets/store/screen.css.scss | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/core/app/assets/stylesheets/store/screen.css.scss b/core/app/assets/stylesheets/store/screen.css.scss
index cf250d70cb8..aa69a6d0e19 100644
--- a/core/app/assets/stylesheets/store/screen.css.scss
+++ b/core/app/assets/stylesheets/store/screen.css.scss
@@ -1,4 +1,4 @@
-@import "store/variables";
+@import "./variables.css.scss";
/*--------------------------------------*/
/* Basic styles
From d3f796bf5c72c121125102c15389c431f8eea783 Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Tue, 16 Oct 2012 11:12:32 +1100
Subject: [PATCH 235/346] Go to checkout state page when checkout button is
clicked
Fixes #2086
Conflicts:
core/spec/requests/checkout_spec.rb
---
core/app/controllers/spree/orders_controller.rb | 10 +++++++++-
core/spec/requests/checkout_spec.rb | 2 +-
2 files changed, 10 insertions(+), 2 deletions(-)
diff --git a/core/app/controllers/spree/orders_controller.rb b/core/app/controllers/spree/orders_controller.rb
index 801b897861c..c5c331d8898 100644
--- a/core/app/controllers/spree/orders_controller.rb
+++ b/core/app/controllers/spree/orders_controller.rb
@@ -15,7 +15,15 @@ def update
if @order.update_attributes(params[:order])
@order.line_items = @order.line_items.select {|li| li.quantity > 0 }
fire_event('spree.order.contents_changed')
- respond_with(@order) { |format| format.html { redirect_to cart_path } }
+ respond_with(@order) do |format|
+ format.html do
+ if params.has_key?(:checkout)
+ redirect_to checkout_state_path(@order.checkout_steps.first)
+ else
+ redirect_to cart_path
+ end
+ end
+ end
else
respond_with(@order)
end
diff --git a/core/spec/requests/checkout_spec.rb b/core/spec/requests/checkout_spec.rb
index 7e5056a714b..7158d4fba58 100644
--- a/core/spec/requests/checkout_spec.rb
+++ b/core/spec/requests/checkout_spec.rb
@@ -31,7 +31,7 @@
@product.on_hand = 0
@product.save
- click_link "Checkout"
+ click_button "Checkout"
within(:css, "span.out-of-stock") { page.should have_content("Out of Stock") }
end
From 5f58982a78d64c8567648f9828c806e319813942 Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Tue, 16 Oct 2012 14:01:03 +1100
Subject: [PATCH 236/346] [promo] Fix references to checkout *button*
Relates to #2086
---
promo/spec/requests/checkout_spec.rb | 2 +-
promo/spec/requests/promotion_adjustments_spec.rb | 14 +++++++-------
2 files changed, 8 insertions(+), 8 deletions(-)
diff --git a/promo/spec/requests/checkout_spec.rb b/promo/spec/requests/checkout_spec.rb
index 30e58729bb3..085cb1921dd 100644
--- a/promo/spec/requests/checkout_spec.rb
+++ b/promo/spec/requests/checkout_spec.rb
@@ -16,7 +16,7 @@
click_link "RoR Mug"
click_button "add-to-cart-button"
- click_link "Checkout"
+ click_button "Checkout"
fill_in "order_email", :with => "spree@example.com"
click_button "Continue"
diff --git a/promo/spec/requests/promotion_adjustments_spec.rb b/promo/spec/requests/promotion_adjustments_spec.rb
index 08ef79e9251..0956972ef10 100644
--- a/promo/spec/requests/promotion_adjustments_spec.rb
+++ b/promo/spec/requests/promotion_adjustments_spec.rb
@@ -66,7 +66,7 @@
visit spree.root_path
click_link "RoR Mug"
click_button "Add To Cart"
- click_link "Checkout"
+ click_button "Checkout"
fill_in "Customer E-Mail", :with => "spree@example.com"
str_addr = "bill_address"
@@ -112,7 +112,7 @@
visit spree.root_path
click_link "RoR Mug"
click_button "Add To Cart"
- click_link "Checkout"
+ click_button "Checkout"
fill_in "Customer E-Mail", :with => "spree@example.com"
str_addr = "bill_address"
@@ -138,7 +138,7 @@
visit spree.root_path
click_link "RoR Mug"
click_button "Add To Cart"
- click_link "Checkout"
+ click_button "Checkout"
fill_in "Customer E-Mail", :with => "spree@example.com"
str_addr = "bill_address"
@@ -206,7 +206,7 @@
visit spree.root_path
click_link "RoR Bag"
click_button "Add To Cart"
- click_link "Checkout"
+ click_button "Checkout"
fill_in "Customer E-Mail", :with => "spree@example.com"
str_addr = "bill_address"
@@ -229,7 +229,7 @@
visit spree.root_path
click_link "RoR Mug"
click_button "Add To Cart"
- click_link "Checkout"
+ click_button "Checkout"
str_addr = "bill_address"
select "United States", :from => "order_#{str_addr}_attributes_country_id"
@@ -330,7 +330,7 @@
visit spree.root_path
click_link "RoR Bag"
click_button "Add To Cart"
- click_link "Checkout"
+ click_button "Checkout"
str_addr = "bill_address"
fill_in "order_email", :with => "buyer@spreecommerce.com"
@@ -481,7 +481,7 @@ def add_to_cart product_name
end
def do_checkout
- click_link "Checkout"
+ click_button "Checkout"
str_addr = "bill_address"
fill_in "order_email", :with => "buyer@spreecommerce.com"
select "United States", :from => "order_#{str_addr}_attributes_country_id"
From e73a1cb2b7478350cf681c8f14a1f1c86d95687c Mon Sep 17 00:00:00 2001
From: Steve Hoeksema
Date: Tue, 16 Oct 2012 15:01:43 +1300
Subject: [PATCH 237/346] Provide the Spree current user to the searcher class
Fixes #2089
---
core/app/controllers/spree/home_controller.rb | 1 +
core/app/controllers/spree/products_controller.rb | 1 +
core/app/controllers/spree/taxons_controller.rb | 1 +
core/lib/spree/core/search/base.rb | 1 +
core/spec/controllers/spree/home_controller_spec.rb | 11 +++++++++++
.../controllers/spree/products_controller_spec.rb | 8 ++++++++
.../spec/controllers/spree/taxons_controller_spec.rb | 12 ++++++++++++
core/spec/lib/search/base_spec.rb | 7 +++++++
8 files changed, 42 insertions(+)
create mode 100644 core/spec/controllers/spree/home_controller_spec.rb
create mode 100644 core/spec/controllers/spree/taxons_controller_spec.rb
diff --git a/core/app/controllers/spree/home_controller.rb b/core/app/controllers/spree/home_controller.rb
index 26500eee353..5c1dd586f73 100644
--- a/core/app/controllers/spree/home_controller.rb
+++ b/core/app/controllers/spree/home_controller.rb
@@ -5,6 +5,7 @@ class HomeController < BaseController
def index
@searcher = Spree::Config.searcher_class.new(params)
+ @searcher.current_user = try_spree_current_user
@products = @searcher.retrieve_products
respond_with(@products)
end
diff --git a/core/app/controllers/spree/products_controller.rb b/core/app/controllers/spree/products_controller.rb
index dc39576fa2a..fa8cd136600 100644
--- a/core/app/controllers/spree/products_controller.rb
+++ b/core/app/controllers/spree/products_controller.rb
@@ -8,6 +8,7 @@ class ProductsController < BaseController
def index
@searcher = Config.searcher_class.new(params)
+ @searcher.current_user = try_spree_current_user
@products = @searcher.retrieve_products
respond_with(@products)
end
diff --git a/core/app/controllers/spree/taxons_controller.rb b/core/app/controllers/spree/taxons_controller.rb
index a1ad043231b..39d7055ab0a 100644
--- a/core/app/controllers/spree/taxons_controller.rb
+++ b/core/app/controllers/spree/taxons_controller.rb
@@ -10,6 +10,7 @@ def show
return unless @taxon
@searcher = Spree::Config.searcher_class.new(params.merge(:taxon => @taxon.id))
+ @searcher.current_user = try_spree_current_user
@products = @searcher.retrieve_products
respond_with(@taxon)
diff --git a/core/lib/spree/core/search/base.rb b/core/lib/spree/core/search/base.rb
index 19f09b1d694..87b6423f6c4 100644
--- a/core/lib/spree/core/search/base.rb
+++ b/core/lib/spree/core/search/base.rb
@@ -3,6 +3,7 @@ module Core
module Search
class Base
attr_accessor :properties
+ attr_accessor :current_user
def initialize(params)
@properties = {}
diff --git a/core/spec/controllers/spree/home_controller_spec.rb b/core/spec/controllers/spree/home_controller_spec.rb
new file mode 100644
index 00000000000..b5342dde718
--- /dev/null
+++ b/core/spec/controllers/spree/home_controller_spec.rb
@@ -0,0 +1,11 @@
+require 'spec_helper'
+
+describe Spree::HomeController do
+ it "should provide the current user to the searcher class" do
+ user = stub(:last_incomplete_spree_order => nil)
+ controller.stub :spree_current_user => user
+ Spree::Config.searcher_class.any_instance.should_receive(:current_user=).with(user)
+ spree_get :index
+ response.status.should == 200
+ end
+end
diff --git a/core/spec/controllers/spree/products_controller_spec.rb b/core/spec/controllers/spree/products_controller_spec.rb
index 9f72d99e125..e83052fd8b6 100644
--- a/core/spec/controllers/spree/products_controller_spec.rb
+++ b/core/spec/controllers/spree/products_controller_spec.rb
@@ -14,4 +14,12 @@
spree_get :show, :id => product.to_param
response.status.should == 404
end
+
+ it "should provide the current user to the searcher class" do
+ user = stub(:last_incomplete_spree_order => nil)
+ controller.stub :spree_current_user => user
+ Spree::Config.searcher_class.any_instance.should_receive(:current_user=).with(user)
+ spree_get :index
+ response.status.should == 200
+ end
end
diff --git a/core/spec/controllers/spree/taxons_controller_spec.rb b/core/spec/controllers/spree/taxons_controller_spec.rb
new file mode 100644
index 00000000000..9ca6cb7da74
--- /dev/null
+++ b/core/spec/controllers/spree/taxons_controller_spec.rb
@@ -0,0 +1,12 @@
+require 'spec_helper'
+
+describe Spree::TaxonsController do
+ it "should provide the current user to the searcher class" do
+ taxon = create(:taxon, :permalink => "test")
+ user = stub(:last_incomplete_spree_order => nil)
+ controller.stub :spree_current_user => user
+ Spree::Config.searcher_class.any_instance.should_receive(:current_user=).with(user)
+ spree_get :show, :id => taxon.permalink
+ response.status.should == 200
+ end
+end
diff --git a/core/spec/lib/search/base_spec.rb b/core/spec/lib/search/base_spec.rb
index d8a1a8c96a6..3b2ff8df725 100644
--- a/core/spec/lib/search/base_spec.rb
+++ b/core/spec/lib/search/base_spec.rb
@@ -50,4 +50,11 @@
searcher.retrieve_products.count.should == 1
end
+ it "accepts a current user" do
+ user = stub
+ searcher = Spree::Core::Search::Base.new({})
+ searcher.current_user = user
+ searcher.current_user.should eql(user)
+ end
+
end
From 136cbda8fa73f8903ce5dc462e6a587f35ed0082 Mon Sep 17 00:00:00 2001
From: Clemens Kofler
Date: Wed, 17 Oct 2012 00:09:49 +0200
Subject: [PATCH 238/346] Fix price parsing for numeric values
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Price parsing should only happen when the given price value is a string – otherwise it doesn't make
sense. This prevents issues where a numeric value is assigned, e.g. when using a value directly
from the database. See the issues discussed in https://github.com/spree/spree/pull/1885.
Fixes #1885
---
core/app/models/spree/variant.rb | 2 +-
core/spec/models/variant_spec.rb | 16 ++++++++++++++++
2 files changed, 17 insertions(+), 1 deletion(-)
diff --git a/core/app/models/spree/variant.rb b/core/app/models/spree/variant.rb
index 5e7c094387f..9a87cae7c7a 100644
--- a/core/app/models/spree/variant.rb
+++ b/core/app/models/spree/variant.rb
@@ -147,7 +147,7 @@ def process_backorders
# strips all non-price-like characters from the price, taking into account locale settings
def parse_price(price)
- price = price.to_s
+ return price unless price.is_a?(String)
separator, delimiter = I18n.t([:'number.currency.format.separator', :'number.currency.format.delimiter'])
non_price_characters = /[^0-9\-#{separator}]/
diff --git a/core/spec/models/variant_spec.rb b/core/spec/models/variant_spec.rb
index 7b4ee236b58..2c3a6fec013 100644
--- a/core/spec/models/variant_spec.rb
+++ b/core/spec/models/variant_spec.rb
@@ -234,6 +234,14 @@
variant.price.should == 1599.99
end
end
+
+ context "with a numeric price" do
+ it "uses the price as is" do
+ I18n.locale = :de
+ variant.price = 1599.99
+ variant.price.should == 1599.99
+ end
+ end
end
context "cost_price=" do
@@ -251,6 +259,14 @@
variant.cost_price.should == 1599.99
end
end
+
+ context "with a numeric price" do
+ it "uses the price as is" do
+ I18n.locale = :de
+ variant.cost_price = 1599.99
+ variant.cost_price.should == 1599.99
+ end
+ end
end
end
end
From d9d40cd36a9f7b940584e11b0648905852c8bb0f Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Thu, 11 Oct 2012 11:36:45 +1100
Subject: [PATCH 239/346] Allow unauthenticated API requests for the
ProductsController
---
.../spree/api/v1/base_controller.rb | 13 ++++++++--
api/app/models/spree/api_configuration.rb | 5 ++++
api/lib/spree/api/engine.rb | 4 +++
.../spree/api/v1/products_controller_spec.rb | 16 ++----------
...nauthenticated_products_controller_spec.rb | 26 +++++++++++++++++++
.../protect_product_actions.rb | 17 ++++++++++++
api/spec/spec_helper.rb | 5 ++++
7 files changed, 70 insertions(+), 16 deletions(-)
create mode 100644 api/app/models/spree/api_configuration.rb
create mode 100644 api/spec/controllers/spree/api/v1/unauthenticated_products_controller_spec.rb
create mode 100644 api/spec/shared_examples/protect_product_actions.rb
diff --git a/api/app/controllers/spree/api/v1/base_controller.rb b/api/app/controllers/spree/api/v1/base_controller.rb
index 9a237b5b133..a534b8a887f 100644
--- a/api/app/controllers/spree/api/v1/base_controller.rb
+++ b/api/app/controllers/spree/api/v1/base_controller.rb
@@ -41,8 +41,13 @@ def check_for_api_key
end
def authenticate_user
- unless @current_api_user = Spree.user_class.find_by_spree_api_key(api_key)
- render "spree/api/v1/errors/invalid_api_key", :status => 401 and return
+ if requires_authentication?
+ unless @current_api_user = Spree.user_class.find_by_spree_api_key(api_key)
+ render "spree/api/v1/errors/invalid_api_key", :status => 401 and return
+ end
+ else
+ # Effectively, an anonymous user
+ @current_api_user = Spree.user_class.new
end
end
@@ -50,6 +55,10 @@ def unauthorized
render "spree/api/v1/errors/unauthorized", :status => 401 and return
end
+ def requires_authentication?
+ Spree::Api::Config[:requires_authentication]
+ end
+
def not_found
render "spree/api/v1/errors/not_found", :status => 404 and return
end
diff --git a/api/app/models/spree/api_configuration.rb b/api/app/models/spree/api_configuration.rb
new file mode 100644
index 00000000000..a9d5d733ef4
--- /dev/null
+++ b/api/app/models/spree/api_configuration.rb
@@ -0,0 +1,5 @@
+module Spree
+ class ApiConfiguration < Preferences::Configuration
+ preference :requires_authentication, :boolean, :default => true
+ end
+end
diff --git a/api/lib/spree/api/engine.rb b/api/lib/spree/api/engine.rb
index 8b7ee9e2212..502da59daaa 100644
--- a/api/lib/spree/api/engine.rb
+++ b/api/lib/spree/api/engine.rb
@@ -6,6 +6,10 @@ class Engine < Rails::Engine
isolate_namespace Spree
engine_name 'spree_api'
+ initializer "spree.api.environment", :before => :load_config_initializers do |app|
+ Spree::Api::Config = Spree::ApiConfiguration.new
+ end
+
def self.activate
Dir.glob(File.join(File.dirname(__FILE__), "../../../app/**/*_decorator*.rb")) do |c|
Rails.configuration.cache_classes ? require(c) : load(c)
diff --git a/api/spec/controllers/spree/api/v1/products_controller_spec.rb b/api/spec/controllers/spree/api/v1/products_controller_spec.rb
index 59c0c9904c0..47df8166fb4 100644
--- a/api/spec/controllers/spree/api/v1/products_controller_spec.rb
+++ b/api/spec/controllers/spree/api/v1/products_controller_spec.rb
@@ -1,4 +1,5 @@
require 'spec_helper'
+require 'shared_examples/protect_product_actions'
module Spree
describe Spree::Api::V1::ProductsController do
@@ -105,20 +106,7 @@ module Spree
required_attributes.should include("price")
end
- it "cannot create a new product if not an admin" do
- api_post :create, :product => { :name => "Brand new product!" }
- assert_unauthorized!
- end
-
- it "cannot update a product" do
- api_put :update, :id => product.to_param, :product => { :name => "I hacked your store!" }
- assert_unauthorized!
- end
-
- it "cannot delete a product" do
- api_delete :destroy, :id => product.to_param
- assert_unauthorized!
- end
+ it_behaves_like "modifying product actions are restricted"
end
context "as an admin" do
diff --git a/api/spec/controllers/spree/api/v1/unauthenticated_products_controller_spec.rb b/api/spec/controllers/spree/api/v1/unauthenticated_products_controller_spec.rb
new file mode 100644
index 00000000000..0d3a10a9a6f
--- /dev/null
+++ b/api/spec/controllers/spree/api/v1/unauthenticated_products_controller_spec.rb
@@ -0,0 +1,26 @@
+require 'shared_examples/protect_product_actions'
+require 'spec_helper'
+
+module Spree
+ describe Spree::Api::V1::ProductsController do
+ render_views
+
+ let!(:product) { create(:product) }
+ let(:attributes) { [:id, :name, :description, :price, :available_on, :permalink, :count_on_hand, :meta_description, :meta_keywords, :taxon_ids] }
+
+ context "without authentication" do
+ before { Spree::Api::Config[:requires_authentication] = false }
+
+ it "retreives a list of products" do
+ api_get :index
+ json_response["products"].first.should have_attributes(attributes)
+ json_response["count"].should == 1
+ json_response["current_page"].should == 1
+ json_response["pages"].should == 1
+ end
+
+ it_behaves_like "modifying product actions are restricted"
+ end
+ end
+end
+
diff --git a/api/spec/shared_examples/protect_product_actions.rb b/api/spec/shared_examples/protect_product_actions.rb
new file mode 100644
index 00000000000..0dc3c2607d8
--- /dev/null
+++ b/api/spec/shared_examples/protect_product_actions.rb
@@ -0,0 +1,17 @@
+shared_examples "modifying product actions are restricted" do
+ it "cannot create a new product if not an admin" do
+ api_post :create, :product => { :name => "Brand new product!" }
+ assert_unauthorized!
+ end
+
+ it "cannot update a product" do
+ api_put :update, :id => product.to_param, :product => { :name => "I hacked your store!" }
+ assert_unauthorized!
+ end
+
+ it "cannot delete a product" do
+ api_delete :destroy, :id => product.to_param
+ assert_unauthorized!
+ end
+end
+
diff --git a/api/spec/spec_helper.rb b/api/spec/spec_helper.rb
index 01c364898c3..b2f1b6903ae 100644
--- a/api/spec/spec_helper.rb
+++ b/api/spec/spec_helper.rb
@@ -19,4 +19,9 @@
config.include FactoryGirl::Syntax::Methods
config.include Spree::Api::TestingSupport::Helpers, :type => :controller
config.extend Spree::Api::TestingSupport::Setup, :type => :controller
+ config.include Spree::Core::TestingSupport::Preferences, :type => :controller
+
+ config.before do
+ Spree::Api::Config[:requires_authentication] = true
+ end
end
From 3fad013a7c56fbd7692485a5f5d1cd27a9e0bd60 Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Wed, 17 Oct 2012 12:01:32 +1100
Subject: [PATCH 240/346] Remove not null constraint from products on hand
Fixes #2096
---
...emove_not_null_constraint_from_products_on_hand.rb | 11 +++++++++++
1 file changed, 11 insertions(+)
create mode 100644 core/db/migrate/20121017010007_remove_not_null_constraint_from_products_on_hand.rb
diff --git a/core/db/migrate/20121017010007_remove_not_null_constraint_from_products_on_hand.rb b/core/db/migrate/20121017010007_remove_not_null_constraint_from_products_on_hand.rb
new file mode 100644
index 00000000000..8f413e325f8
--- /dev/null
+++ b/core/db/migrate/20121017010007_remove_not_null_constraint_from_products_on_hand.rb
@@ -0,0 +1,11 @@
+class RemoveNotNullConstraintFromProductsOnHand < ActiveRecord::Migration
+ def up
+ change_column :spree_products, :count_on_hand, :integer, :null => true
+ change_column :spree_variants, :count_on_hand, :integer, :null => true
+ end
+
+ def down
+ change_column :spree_products, :count_on_hand, :integer, :null => false
+ change_column :spree_variants, :count_on_hand, :integer, :null => false
+ end
+end
From c2055e52f9759e0d3fc0b6efbc58b1ec7f946df2 Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Wed, 17 Oct 2012 12:07:34 +1100
Subject: [PATCH 241/346] Add regression test for #2097
---
core/spec/requests/admin/products/products_spec.rb | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/core/spec/requests/admin/products/products_spec.rb b/core/spec/requests/admin/products/products_spec.rb
index 17913f6abc9..1d9280f5f4d 100644
--- a/core/spec/requests/admin/products/products_spec.rb
+++ b/core/spec/requests/admin/products/products_spec.rb
@@ -143,6 +143,15 @@
page.should have_content("Name can't be blank")
page.should have_content("Price can't be blank")
end
+
+ # Regression test for #2097
+ it "can set the count on hand to a null value", :js => true do
+ fill_in "product_name", :with => "Baseball Cap"
+ fill_in "product_price", :with => "100"
+ fill_in "product_count_on_hand", :with => ""
+ click_button "Create"
+ page.should have_content("successfully created!")
+ end
end
context "cloning a product", :js => true do
From 2f35cea3f72b42d6923214afff44a3ed6f1589e7 Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Mon, 1 Oct 2012 11:19:27 +1000
Subject: [PATCH 242/346] Add TestingSupport helpers for flash and preferences
---
core/lib/spree/core/testing_support/flash.rb | 17 ++++++++++++
.../spree/core/testing_support/preferences.rb | 26 +++++++++++++++++++
core/spec/spec_helper.rb | 5 ++++
core/spec/support/preferences.rb | 14 ----------
4 files changed, 48 insertions(+), 14 deletions(-)
create mode 100644 core/lib/spree/core/testing_support/flash.rb
create mode 100644 core/lib/spree/core/testing_support/preferences.rb
delete mode 100644 core/spec/support/preferences.rb
diff --git a/core/lib/spree/core/testing_support/flash.rb b/core/lib/spree/core/testing_support/flash.rb
new file mode 100644
index 00000000000..6be2d4f0189
--- /dev/null
+++ b/core/lib/spree/core/testing_support/flash.rb
@@ -0,0 +1,17 @@
+module Spree
+ module Core
+ module TestingSupport
+ module Flash
+ def assert_flash_notice(flash)
+ if flash.is_a?(Symbol)
+ flash = I18n.t(flash)
+ end
+
+ within("[class='flash notice']") do
+ page.should have_content(flash)
+ end
+ end
+ end
+ end
+ end
+end
diff --git a/core/lib/spree/core/testing_support/preferences.rb b/core/lib/spree/core/testing_support/preferences.rb
new file mode 100644
index 00000000000..f2c2c94bc06
--- /dev/null
+++ b/core/lib/spree/core/testing_support/preferences.rb
@@ -0,0 +1,26 @@
+module Spree
+ module Core
+ module TestingSupport
+ module Preferences
+ # Resets all preferences to default values, you can
+ # pass a block to override the defaults with a block
+ #
+ # reset_spree_preferences do |config|
+ # config.site_name = "my fancy pants store"
+ # end
+ #
+ def reset_spree_preferences
+ Spree::Preferences::Store.instance.persistence = false
+ config = Rails.application.config.spree.preferences
+ config.reset
+ yield(config) if block_given?
+ end
+
+ def assert_preference_unset(preference)
+ find("#preferences_#{preference}")['checked'].should be_false
+ Spree::Config[preference].should be_false
+ end
+ end
+ end
+ end
+end
diff --git a/core/spec/spec_helper.rb b/core/spec/spec_helper.rb
index 83505cd3360..f1dda4a61e6 100644
--- a/core/spec/spec_helper.rb
+++ b/core/spec/spec_helper.rb
@@ -9,10 +9,13 @@
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
require 'database_cleaner'
+
require 'spree/core/testing_support/factories'
require 'spree/core/testing_support/env'
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/core/url_helpers'
require 'paperclip/matchers'
@@ -55,6 +58,8 @@
config.include FactoryGirl::Syntax::Methods
config.include Spree::Core::UrlHelpers
config.include Spree::Core::TestingSupport::ControllerRequests
+ config.include Spree::Core::TestingSupport::Preferences
+ config.include Spree::Core::TestingSupport::Flash
config.include Paperclip::Shoulda::Matchers
end
diff --git a/core/spec/support/preferences.rb b/core/spec/support/preferences.rb
deleted file mode 100644
index ba1731ba34f..00000000000
--- a/core/spec/support/preferences.rb
+++ /dev/null
@@ -1,14 +0,0 @@
-# Resets all preferences to default values, you can
-# pass a block to override the defaults with a block
-#
-# reset_spree_preferences do |config|
-# config.site_name = "my fancy pants store"
-# end
-#
-def reset_spree_preferences
- Spree::Preferences::Store.instance.persistence = false
- config = Rails.application.config.spree.preferences
- config.reset
- yield(config) if block_given?
-end
-
From 8631f26d1e15a44f007fce950f833071aee80db8 Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Wed, 17 Oct 2012 12:11:20 +1100
Subject: [PATCH 243/346] Add requires_authentication? check for
check_for_api_key before_filter in Api::V1::BaseController
---
api/app/controllers/spree/api/v1/base_controller.rb | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/api/app/controllers/spree/api/v1/base_controller.rb b/api/app/controllers/spree/api/v1/base_controller.rb
index a534b8a887f..fbd8aa98bb0 100644
--- a/api/app/controllers/spree/api/v1/base_controller.rb
+++ b/api/app/controllers/spree/api/v1/base_controller.rb
@@ -7,7 +7,7 @@ class BaseController < ActionController::Metal
attr_accessor :current_api_user
before_filter :set_content_type
- before_filter :check_for_api_key
+ before_filter :check_for_api_key, :if => :requires_authentication?
before_filter :authenticate_user
rescue_from CanCan::AccessDenied, :with => :unauthorized
From 1880bc05a44a03d3d082e704f54b7eb99c382b4c Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Wed, 17 Oct 2012 13:24:12 +1100
Subject: [PATCH 244/346] product_on_hand, not product_count_on_hand for
regression test for #2097
---
core/spec/requests/admin/products/products_spec.rb | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/core/spec/requests/admin/products/products_spec.rb b/core/spec/requests/admin/products/products_spec.rb
index 1d9280f5f4d..d1fa169dabc 100644
--- a/core/spec/requests/admin/products/products_spec.rb
+++ b/core/spec/requests/admin/products/products_spec.rb
@@ -148,7 +148,7 @@
it "can set the count on hand to a null value", :js => true do
fill_in "product_name", :with => "Baseball Cap"
fill_in "product_price", :with => "100"
- fill_in "product_count_on_hand", :with => ""
+ fill_in "product_on_hand", :with => ""
click_button "Create"
page.should have_content("successfully created!")
end
From e66daf7c39a415bc25cc342c1fb8320b79e8e9e3 Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Wed, 17 Oct 2012 13:48:20 +1100
Subject: [PATCH 245/346] Don't clear mail_method or payment_method password if
it's not sent through with params
Fixes #2094
---
.../spree/admin/mail_methods_controller.rb | 7 +++++
.../spree/admin/payment_methods_controller.rb | 8 +++++-
.../admin/payment_methods_controller_spec.rb | 28 +++++++++++++++++++
.../admin/configuration/mail_methods_spec.rb | 16 +++++++++--
4 files changed, 56 insertions(+), 3 deletions(-)
create mode 100644 core/spec/controllers/spree/admin/payment_methods_controller_spec.rb
diff --git a/core/app/controllers/spree/admin/mail_methods_controller.rb b/core/app/controllers/spree/admin/mail_methods_controller.rb
index 7cfa7fcbec2..f76b433c3f6 100644
--- a/core/app/controllers/spree/admin/mail_methods_controller.rb
+++ b/core/app/controllers/spree/admin/mail_methods_controller.rb
@@ -3,6 +3,13 @@ module Admin
class MailMethodsController < ResourceController
after_filter :initialize_mail_settings
+ def update
+ if params[:mail_method][:preferred_smtp_password].blank?
+ params[:mail_method].delete(:preferred_smtp_password)
+ end
+ super
+ end
+
def testmail
@mail_method = Spree::MailMethod.find(params[:id])
if TestMailer.test_email(@mail_method, try_spree_current_user).deliver
diff --git a/core/app/controllers/spree/admin/payment_methods_controller.rb b/core/app/controllers/spree/admin/payment_methods_controller.rb
index 9109868ecb3..c8afcdb5097 100644
--- a/core/app/controllers/spree/admin/payment_methods_controller.rb
+++ b/core/app/controllers/spree/admin/payment_methods_controller.rb
@@ -27,7 +27,13 @@ def update
end
payment_method_params = params[ActiveModel::Naming.param_key(@payment_method)] || {}
- if @payment_method.update_attributes(params[:payment_method].merge(payment_method_params))
+ attributes = params[:payment_method].merge(payment_method_params)
+ attributes.each do |k,v|
+ if k.include?("password") && attributes[k].blank?
+ attributes.delete(k)
+ end
+ end
+ if @payment_method.update_attributes(attributes)
invoke_callbacks(:update, :after)
flash.notice = I18n.t(:successfully_updated, :resource => I18n.t(:payment_method))
respond_with(@payment_method, :location => edit_admin_payment_method_path(@payment_method))
diff --git a/core/spec/controllers/spree/admin/payment_methods_controller_spec.rb b/core/spec/controllers/spree/admin/payment_methods_controller_spec.rb
new file mode 100644
index 00000000000..a1acff2e198
--- /dev/null
+++ b/core/spec/controllers/spree/admin/payment_methods_controller_spec.rb
@@ -0,0 +1,28 @@
+require 'spec_helper'
+
+module Spree
+ class GatewayWithPassword < PaymentMethod
+ attr_accessible :preferred_password
+
+ preference :password, :string, :default => "password"
+ end
+end
+
+module Spree
+ describe Admin::PaymentMethodsController do
+ stub_authorization!
+
+ let(:payment_method) { Spree::GatewayWithPassword.create!(:name => "Bogus", :preferred_password => "haxme") }
+
+ # regression test for #2094
+ it "does not clear password on update" do
+ payment_method.preferred_password.should == "haxme"
+ spree_put :update, :id => payment_method.id, :payment_method => { :type => payment_method.class.to_s, :preferred_password => "" }
+ response.should redirect_to(spree.edit_admin_payment_method_path(payment_method))
+
+ payment_method.reload
+ payment_method.preferred_password.should == "haxme"
+ end
+
+ end
+end
diff --git a/core/spec/requests/admin/configuration/mail_methods_spec.rb b/core/spec/requests/admin/configuration/mail_methods_spec.rb
index 9529d210b46..315746c4389 100644
--- a/core/spec/requests/admin/configuration/mail_methods_spec.rb
+++ b/core/spec/requests/admin/configuration/mail_methods_spec.rb
@@ -31,8 +31,9 @@
end
context "edit" do
- before(:each) do
- create(:mail_method)
+ let!(:mail_method) { create(:mail_method, :preferred_smtp_password => "haxme") }
+
+ before do
click_link "Mail Methods"
end
@@ -44,5 +45,16 @@
within(:css, "table.index tbody tr") { click_link "Edit" }
find_field("mail_method_preferred_mail_bcc").value.should == "spree@example.com99"
end
+
+ # Regression test for #2094
+ it "does not clear password if not provided" do
+ mail_method.preferred_smtp_password.should == "haxme"
+ within_row(1) { click_icon :edit }
+ click_button "Update"
+ page.should have_content("successfully updated!")
+
+ mail_method.reload
+ mail_method.preferred_smtp_password.should_not be_blank
+ end
end
end
From d8c68d4c31bcb5904f7db163e7079e6e289aa0f0 Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Wed, 17 Oct 2012 14:54:25 +1100
Subject: [PATCH 246/346] Use within in mail_methods_spec
As was the style at the time...
---
core/spec/requests/admin/configuration/mail_methods_spec.rb | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/core/spec/requests/admin/configuration/mail_methods_spec.rb b/core/spec/requests/admin/configuration/mail_methods_spec.rb
index 315746c4389..b6183d1d94e 100644
--- a/core/spec/requests/admin/configuration/mail_methods_spec.rb
+++ b/core/spec/requests/admin/configuration/mail_methods_spec.rb
@@ -49,7 +49,7 @@
# Regression test for #2094
it "does not clear password if not provided" do
mail_method.preferred_smtp_password.should == "haxme"
- within_row(1) { click_icon :edit }
+ within(:css, "table.index tbody tr") { click_link "Edit" }
click_button "Update"
page.should have_content("successfully updated!")
From 596f4609fa3d07969a4153e558d95284b482a9c8 Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Wed, 17 Oct 2012 14:56:41 +1100
Subject: [PATCH 247/346] Correctly set product_on_hand check in products_spec
test
---
core/spec/requests/admin/products/products_spec.rb | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/core/spec/requests/admin/products/products_spec.rb b/core/spec/requests/admin/products/products_spec.rb
index d1fa169dabc..ef367ffce49 100644
--- a/core/spec/requests/admin/products/products_spec.rb
+++ b/core/spec/requests/admin/products/products_spec.rb
@@ -148,9 +148,12 @@
it "can set the count on hand to a null value", :js => true do
fill_in "product_name", :with => "Baseball Cap"
fill_in "product_price", :with => "100"
- fill_in "product_on_hand", :with => ""
click_button "Create"
page.should have_content("successfully created!")
+ fill_in "product_on_hand", :with => ""
+ click_button "Update"
+ page.should_not have_content("spree_products.count_on_hand may not be NULL")
+ page.should have_content("successfully updated!")
end
end
From 5b53c72608ec75a038b0f4569bd93c2f7423eeae Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Wed, 17 Oct 2012 15:22:09 +1100
Subject: [PATCH 248/346] WIP: taxon selector
---
.../views/spree/admin/products/_form.html.erb | 18 ++++++++++++++++--
1 file changed, 16 insertions(+), 2 deletions(-)
diff --git a/core/app/views/spree/admin/products/_form.html.erb b/core/app/views/spree/admin/products/_form.html.erb
index bcdd619cd01..ba78a7fa975 100644
--- a/core/app/views/spree/admin/products/_form.html.erb
+++ b/core/app/views/spree/admin/products/_form.html.erb
@@ -115,8 +115,22 @@
From b12f99a54eeac055ed6b8b2f67422a72179647a9 Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Wed, 17 Oct 2012 16:28:21 +1100
Subject: [PATCH 249/346] Fix parameter names within
mail_methods_controller_spec
---
.../controllers/spree/admin/mail_methods_controller_spec.rb | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/core/spec/controllers/spree/admin/mail_methods_controller_spec.rb b/core/spec/controllers/spree/admin/mail_methods_controller_spec.rb
index 923f2ada8b8..aaa494d0496 100644
--- a/core/spec/controllers/spree/admin/mail_methods_controller_spec.rb
+++ b/core/spec/controllers/spree/admin/mail_methods_controller_spec.rb
@@ -7,7 +7,6 @@
let(:mail_method) { mock_model(Spree::MailMethod).as_null_object }
before do
- Spree::Order.stub :find => order
Spree::MailMethod.stub :find => mail_method
request.env["HTTP_REFERER"] = "/"
end
@@ -15,14 +14,14 @@
context "#create" do
it "should reinitialize the mail settings" do
Spree::Core::MailSettings.should_receive :init
- spree_put :create, {:order_id => "123", :id => "456", :mail_method_parmas => {:environment => "foo"}}
+ spree_put :create, { :id => "456", :mail_method => {:environment => "foo"}}
end
end
context "#update" do
it "should reinitialize the mail settings" do
Spree::Core::MailSettings.should_receive :init
- spree_put :update, {:order_id => "123", :id => "456", :mail_method_params => {:environment => "foo"}}
+ spree_put :update, { :id => "456", :mail_method => {:environment => "foo"}}
end
end
From b1fd705f9836bd651962b6a2c63852b6bcf80443 Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Wed, 17 Oct 2012 16:30:13 +1100
Subject: [PATCH 250/346] Revert "WIP: taxon selector"
This reverts commit 5b53c72608ec75a038b0f4569bd93c2f7423eeae.
This commit isn't supposed to be here yet...
---
.../views/spree/admin/products/_form.html.erb | 18 ++----------------
1 file changed, 2 insertions(+), 16 deletions(-)
diff --git a/core/app/views/spree/admin/products/_form.html.erb b/core/app/views/spree/admin/products/_form.html.erb
index ba78a7fa975..bcdd619cd01 100644
--- a/core/app/views/spree/admin/products/_form.html.erb
+++ b/core/app/views/spree/admin/products/_form.html.erb
@@ -115,22 +115,8 @@
From 83e23390d70cb1fbfba8cad74ae9ae9d364e23bc Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Thu, 18 Oct 2012 09:38:30 +1100
Subject: [PATCH 251/346] 1-2-stable branch of spree_auth_devise MUST now be
used with 1-2-stable Spree
Fixes #2013
---
cmd/lib/spree_cmd/installer.rb | 2 +-
lib/sandbox.sh | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/cmd/lib/spree_cmd/installer.rb b/cmd/lib/spree_cmd/installer.rb
index 8ab1c909606..038c5c0ea5a 100644
--- a/cmd/lib/spree_cmd/installer.rb
+++ b/cmd/lib/spree_cmd/installer.rb
@@ -98,7 +98,7 @@ def add_gems
end
if @install_default_auth
- gem :spree_auth_devise, :git => "git://github.com/spree/spree_auth_devise"
+ gem :spree_auth_devise, :github => "spree/spree_auth_devise", :branch => "1-2-stable"
end
run 'bundle install', :capture => true
diff --git a/lib/sandbox.sh b/lib/sandbox.sh
index 7169a4eb573..3944652ef35 100755
--- a/lib/sandbox.sh
+++ b/lib/sandbox.sh
@@ -4,6 +4,6 @@ rm -rf sandbox
rails new sandbox --skip-bundle
cd sandbox
echo "gem 'spree', :path => '..'" >> Gemfile
-echo "gem 'spree_auth_devise', :git => 'git://github.com/spree/spree_auth_devise'" >> Gemfile
+echo "gem 'spree_auth_devise', :github => 'spree/spree_auth_devise', :branch => '1-2-stable'" >> Gemfile
bundle install --gemfile Gemfile
rails g spree:install --auto-accept --user_class=Spree::User
From d166514cfb92e38ca3f81400862e3369dfe61f48 Mon Sep 17 00:00:00 2001
From: Jeff Dutil
Date: Wed, 17 Oct 2012 16:45:07 -0400
Subject: [PATCH 252/346] Fix FactoryGirl deprecations.
Fixes #2104
---
.../spree/api/v1/taxons_controller_spec.rb | 6 +++---
core/spec/models/order/payment_spec.rb | 14 +++++++-------
core/spec/models/tracker_spec.rb | 2 +-
core/spec/requests/checkout_spec.rb | 6 +++---
4 files changed, 14 insertions(+), 14 deletions(-)
diff --git a/api/spec/controllers/spree/api/v1/taxons_controller_spec.rb b/api/spec/controllers/spree/api/v1/taxons_controller_spec.rb
index bd7de8192db..17f8a76d4c4 100644
--- a/api/spec/controllers/spree/api/v1/taxons_controller_spec.rb
+++ b/api/spec/controllers/spree/api/v1/taxons_controller_spec.rb
@@ -4,9 +4,9 @@ module Spree
describe Api::V1::TaxonsController do
render_views
- let(:taxonomy) { Factory(:taxonomy) }
- let(:taxon) { Factory(:taxon, :name => "Ruby", :taxonomy => taxonomy) }
- let(:taxon2) { Factory(:taxon, :name => "Rails", :taxonomy => taxonomy) }
+ let(:taxonomy) { create(:taxonomy) }
+ let(:taxon) { create(:taxon, :name => "Ruby", :taxonomy => taxonomy) }
+ let(:taxon2) { create(:taxon, :name => "Rails", :taxonomy => taxonomy) }
let(:attributes) { ["id", "name", "permalink", "position", "parent_id", "taxonomy_id"] }
before do
diff --git a/core/spec/models/order/payment_spec.rb b/core/spec/models/order/payment_spec.rb
index 554c55f5b71..5985d6d16bc 100644
--- a/core/spec/models/order/payment_spec.rb
+++ b/core/spec/models/order/payment_spec.rb
@@ -13,8 +13,8 @@ module Spree
end
it 'processes all payments' do
- payment_1 = Factory(:payment, :amount => 50)
- payment_2 = Factory(:payment, :amount => 50)
+ payment_1 = create(:payment, :amount => 50)
+ payment_2 = create(:payment, :amount => 50)
order.stub(:pending_payments).and_return([payment_1, payment_2])
order.process_payments!
@@ -26,9 +26,9 @@ module Spree
end
it 'does not go over total for order' do
- payment_1 = Factory(:payment, :amount => 50)
- payment_2 = Factory(:payment, :amount => 50)
- payment_3 = Factory(:payment, :amount => 50)
+ payment_1 = create(:payment, :amount => 50)
+ payment_2 = create(:payment, :amount => 50)
+ payment_3 = create(:payment, :amount => 50)
order.stub(:pending_payments).and_return([payment_1, payment_2, payment_3])
order.process_payments!
@@ -41,8 +41,8 @@ module Spree
end
it "does not use failed payments" do
- payment_1 = Factory(:payment, :amount => 50)
- payment_2 = Factory(:payment, :amount => 50, :state => 'failed')
+ payment_1 = create(:payment, :amount => 50)
+ payment_2 = create(:payment, :amount => 50, :state => 'failed')
order.stub(:pending_payments).and_return([payment_1])
payment_2.should_not_receive(:process!)
diff --git a/core/spec/models/tracker_spec.rb b/core/spec/models/tracker_spec.rb
index 176b792e644..b4b97ad1980 100644
--- a/core/spec/models/tracker_spec.rb
+++ b/core/spec/models/tracker_spec.rb
@@ -2,7 +2,7 @@
describe Spree::Tracker do
describe "current" do
- before(:each) { @tracker = Factory(:tracker) }
+ before(:each) { @tracker = create(:tracker) }
it "returns the first active tracker for the environment" do
Spree::Tracker.current.should == @tracker
diff --git a/core/spec/requests/checkout_spec.rb b/core/spec/requests/checkout_spec.rb
index 7158d4fba58..4062c856c24 100644
--- a/core/spec/requests/checkout_spec.rb
+++ b/core/spec/requests/checkout_spec.rb
@@ -3,7 +3,7 @@
describe "Checkout" do
let(:country) { create(:country, :name => "Kangaland") }
before do
- Factory(:state, :name => "Victoria", :country => country)
+ create(:state, :name => "Victoria", :country => country)
end
context "visitor makes checkout as guest without registration" do
@@ -76,9 +76,9 @@
# Regression test for #1596
context "full checkout" do
before do
- Factory(:payment_method)
+ create(:payment_method)
Spree::ShippingMethod.delete_all
- shipping_method = Factory(:shipping_method)
+ shipping_method = create(:shipping_method)
calculator = Spree::Calculator::PerItem.create!({:calculable => shipping_method}, :without_protection => true)
shipping_method.calculator = calculator
shipping_method.save
From b8739bed5e85bfcc811dc0ee8dc291ab4d88fa66 Mon Sep 17 00:00:00 2001
From: Ben-M
Date: Wed, 17 Oct 2012 15:42:37 +0200
Subject: [PATCH 253/346] Marks orders as returned if all return authorizations
are received.
Fixes #1714
Fixes #2099
---
core/app/models/spree/order.rb | 4 ++++
core/app/models/spree/order/checkout.rb | 2 +-
core/app/models/spree/return_authorization.rb | 1 +
3 files changed, 6 insertions(+), 1 deletion(-)
diff --git a/core/app/models/spree/order.rb b/core/app/models/spree/order.rb
index ae093d44553..5fc84a3dba1 100644
--- a/core/app/models/spree/order.rb
+++ b/core/app/models/spree/order.rb
@@ -238,6 +238,10 @@ def allow_resume?
true
end
+ def awaiting_returns?
+ return_authorizations.any? { |return_authorization| return_authorization.authorized? }
+ end
+
def add_variant(variant, quantity = 1)
current_item = find_line_item_by_variant(variant)
if current_item
diff --git a/core/app/models/spree/order/checkout.rb b/core/app/models/spree/order/checkout.rb
index a6c2901ad63..908abd3f03b 100644
--- a/core/app/models/spree/order/checkout.rb
+++ b/core/app/models/spree/order/checkout.rb
@@ -51,7 +51,7 @@ def self.define_state_machine!
end
event :return do
- transition :to => :returned, :from => :awaiting_return
+ transition :to => :returned, :from => :awaiting_return, :unless => :awaiting_returns?
end
event :resume do
diff --git a/core/app/models/spree/return_authorization.rb b/core/app/models/spree/return_authorization.rb
index be7eca34beb..5554c4955ad 100644
--- a/core/app/models/spree/return_authorization.rb
+++ b/core/app/models/spree/return_authorization.rb
@@ -72,6 +72,7 @@ def process_return
credit.source = self
credit.adjustable = order
credit.save
+ order.return if inventory_units.all?(&:returned)
end
def allow_receive?
From 424916fa9287cc546862d386d73678927d579d57 Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Wed, 17 Oct 2012 17:50:11 +1100
Subject: [PATCH 254/346] AJAXify autocomplete for taxons on product
autocomplete page
Fixes #2087
Fixes #2073
---
.travis.yml | 6 ----
.../app/assets/javascripts/admin/admin.js.erb | 1 +
.../admin/taxon_autocomplete.js.erb | 34 +++++++++++++++++++
.../spree/admin/products_controller.rb | 7 ++++
.../spree/admin/taxons_controller.rb | 8 +++++
core/app/models/spree/taxon.rb | 7 ++++
.../views/spree/admin/products/_form.html.erb | 8 ++---
.../views/spree/admin/shared/_routes.html.erb | 1 +
core/app/views/spree/admin/taxons/search.rabl | 5 +++
core/config/routes.rb | 6 ++++
.../admin/products/edit/taxons_spec.rb | 3 +-
core/spec/support/capybara_ext.rb | 6 ++--
12 files changed, 78 insertions(+), 14 deletions(-)
create mode 100644 core/app/assets/javascripts/admin/taxon_autocomplete.js.erb
create mode 100644 core/app/views/spree/admin/taxons/search.rabl
diff --git a/.travis.yml b/.travis.yml
index b77e5121e51..de58f065982 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -21,12 +21,6 @@ notifications:
skip_join: true
channels:
- "irc.freenode.org#spree"
-branches:
- only:
- - 1-0-stable
- - 1-1-stable
- - 1-2-stable
- - master
rvm:
- 1.8.7
- 1.9.3
diff --git a/core/app/assets/javascripts/admin/admin.js.erb b/core/app/assets/javascripts/admin/admin.js.erb
index 8d514abc727..c0a3223c9af 100644
--- a/core/app/assets/javascripts/admin/admin.js.erb
+++ b/core/app/assets/javascripts/admin/admin.js.erb
@@ -1,6 +1,7 @@
//<%#encoding: UTF-8%>
//= require_self
//= require admin/product_autocomplete
+//= require admin/taxon_autocomplete
//= require select2
/**
diff --git a/core/app/assets/javascripts/admin/taxon_autocomplete.js.erb b/core/app/assets/javascripts/admin/taxon_autocomplete.js.erb
new file mode 100644
index 00000000000..4b81a2c6223
--- /dev/null
+++ b/core/app/assets/javascripts/admin/taxon_autocomplete.js.erb
@@ -0,0 +1,34 @@
+function cleanTaxons(data) {
+ var taxons = $.map(data['taxons'], function(result) {
+ return result['taxon']
+ })
+ return taxons;
+}
+
+$(document).ready(function() {
+ $("#product_taxon_ids").select2({
+ placeholder: "Add a taxon",
+ multiple: true,
+ initSelection: function(element, callback) {
+ return $.getJSON(Spree.routes.taxon_search + "?ids=" + (element.val()), null, function(data) {
+ return callback(self.cleanTaxons(data));
+ })
+ },
+ ajax: {
+ url: Spree.routes.taxon_search,
+ datatype: 'json',
+ data: function(term, page) {
+ return { q: term }
+ },
+ results: function (data, page) {
+ return { results: self.cleanTaxons(data) }
+ }
+ },
+ formatResult: function(taxon) {
+ return taxon.name
+ },
+ formatSelection: function(taxon) {
+ return taxon.name
+ }
+ })
+})
diff --git a/core/app/controllers/spree/admin/products_controller.rb b/core/app/controllers/spree/admin/products_controller.rb
index 1b71542b079..52046384c73 100644
--- a/core/app/controllers/spree/admin/products_controller.rb
+++ b/core/app/controllers/spree/admin/products_controller.rb
@@ -19,6 +19,13 @@ def index
end
end
+ def update
+ if params[:product][:taxon_ids].present?
+ params[:product][:taxon_ids] = params[:product][:taxon_ids].split(',')
+ end
+ super
+ end
+
def destroy
@product = Product.where(:permalink => params[:id]).first!
@product.delete
diff --git a/core/app/controllers/spree/admin/taxons_controller.rb b/core/app/controllers/spree/admin/taxons_controller.rb
index ef3826ca31a..ff0e3ed056b 100644
--- a/core/app/controllers/spree/admin/taxons_controller.rb
+++ b/core/app/controllers/spree/admin/taxons_controller.rb
@@ -4,6 +4,14 @@ class TaxonsController < Spree::Admin::BaseController
respond_to :html, :json, :js
+ def search
+ if params[:ids]
+ @taxons = Spree::Taxon.where(:id => params[:ids])
+ else
+ @taxons = Spree::Taxon.limit(20).search(:name_cont => params[:q]).result
+ end
+ end
+
def create
@taxonomy = Taxonomy.find(params[:taxonomy_id])
@taxon = @taxonomy.taxons.build(params[:taxon])
diff --git a/core/app/models/spree/taxon.rb b/core/app/models/spree/taxon.rb
index 6c939671dde..ecd861da1aa 100644
--- a/core/app/models/spree/taxon.rb
+++ b/core/app/models/spree/taxon.rb
@@ -51,5 +51,12 @@ def active_products
scope
end
+ def pretty_name
+ ancestor_chain = self.ancestors.inject("") do |name, ancestor|
+ name += "#{ancestor.name} -> "
+ end
+ ancestor_chain + "#{name}"
+ end
+
end
end
diff --git a/core/app/views/spree/admin/products/_form.html.erb b/core/app/views/spree/admin/products/_form.html.erb
index bcdd619cd01..d75d23917a8 100644
--- a/core/app/views/spree/admin/products/_form.html.erb
+++ b/core/app/views/spree/admin/products/_form.html.erb
@@ -88,7 +88,7 @@
<%= f.field_container :taxons do %>
<%= f.label :taxon_ids, t(:taxons) %>
- <%= f.select :taxon_ids, taxon_options_for(@product), {}, :class => "select2", :multiple => true %>
+ <%= f.hidden_field :taxon_ids, :value => @product.taxon_ids.join(',') %>
<% end %>
<%= f.field_container :option_types do %>
@@ -114,9 +114,7 @@
diff --git a/core/app/views/spree/admin/shared/_routes.html.erb b/core/app/views/spree/admin/shared/_routes.html.erb
index 809e297a9ac..fe29622b4ce 100644
--- a/core/app/views/spree/admin/shared/_routes.html.erb
+++ b/core/app/views/spree/admin/shared/_routes.html.erb
@@ -1,6 +1,7 @@
+ $('.select2-container').css({width: '20em'})
+
+<% end %>
From ce1e1fdc4fedcae954e4768d574c52f09afc49ea Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Thu, 18 Oct 2012 17:04:29 +1100
Subject: [PATCH 262/346] Regression test for #2004 has been moved out to
orders_controller_transitions spec
---
.../controllers/spree/orders_controller_spec.rb | 15 ---------------
1 file changed, 15 deletions(-)
diff --git a/core/spec/controllers/spree/orders_controller_spec.rb b/core/spec/controllers/spree/orders_controller_spec.rb
index fda4555854c..2d5d8c84541 100644
--- a/core/spec/controllers/spree/orders_controller_spec.rb
+++ b/core/spec/controllers/spree/orders_controller_spec.rb
@@ -65,21 +65,6 @@
spree_put :update, {}, {:order_id => 1}
response.should redirect_to(spree.cart_path)
end
-
- # Regression test for #2004
- context "with a transition callback on first state" do
- before do
- first_state, _ = Spree::Order.checkout_steps.first
- Spree::Order.state_machine.after_transition :to => first_state do |order|
- puts "OMG!"
- end
- end
-
- it "correctly calls the transition callback" do
- order.stub(:update_attributes).and_return true
- spree_put :update, { :checkout => "checkout" }, { :order_id => 1}
- end
- end
end
context "#empty" do
From 741ebe9a1f78cbfef43990da0733d00f0a0693b4 Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Thu, 18 Oct 2012 18:13:24 +1100
Subject: [PATCH 263/346] Use count inside scopes_spec.rb
---
core/spec/models/product/scopes_spec.rb | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/core/spec/models/product/scopes_spec.rb b/core/spec/models/product/scopes_spec.rb
index 746c63d2a15..cb897929d36 100644
--- a/core/spec/models/product/scopes_spec.rb
+++ b/core/spec/models/product/scopes_spec.rb
@@ -17,7 +17,7 @@
end
it "calling Product.in_taxon should not return duplicate records" do
- Spree::Product.in_taxon(@parent_taxon).to_a.should == 1
+ Spree::Product.in_taxon(@parent_taxon).to_a.count.should == 1
end
end
end
From bd035fc8b1ac80cb38a5355db4eb2c7d25bef224 Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Thu, 18 Oct 2012 18:13:17 +1100
Subject: [PATCH 264/346] Use 1.8 syntax in product/scopes_spec
---
core/spec/models/product/scopes_spec.rb | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/core/spec/models/product/scopes_spec.rb b/core/spec/models/product/scopes_spec.rb
index cb897929d36..0d477e1d56e 100644
--- a/core/spec/models/product/scopes_spec.rb
+++ b/core/spec/models/product/scopes_spec.rb
@@ -8,8 +8,8 @@
@taxonomy = create(:taxonomy)
@root_taxon = @taxonomy.root
- @parent_taxon = create(:taxon, name: 'Parent', :taxonomy_id => @taxonomy.id, :parent => @root_taxon)
- @child_taxon = create(:taxon, name: 'Child 1', :taxonomy_id => @taxonomy.id, :parent => @parent_taxon)
+ @parent_taxon = create(:taxon, :name => 'Parent', :taxonomy_id => @taxonomy.id, :parent => @root_taxon)
+ @child_taxon = create(:taxon, :name =>'Child 1', :taxonomy_id => @taxonomy.id, :parent => @parent_taxon)
@parent_taxon.reload # Need to reload for descendents to show up
product.taxons << @parent_taxon
From ac67745fe37d02a5c2a22ef754c8bf55cb6c4a6b Mon Sep 17 00:00:00 2001
From: Jonathan Roes
Date: Thu, 18 Oct 2012 18:24:01 -0400
Subject: [PATCH 265/346] Use _url to disregard asset host for states.js.
Fixes #2113
---
core/app/views/spree/checkout/edit.html.erb | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/core/app/views/spree/checkout/edit.html.erb b/core/app/views/spree/checkout/edit.html.erb
index 1a8260a1484..3b6c35b20a6 100644
--- a/core/app/views/spree/checkout/edit.html.erb
+++ b/core/app/views/spree/checkout/edit.html.erb
@@ -1,5 +1,5 @@
<% content_for :head do %>
- <%= javascript_include_tag states_path(:format => :js) %>
+ <%= javascript_include_tag states_url(:format => :js) %>
<% end %>
<%= render :partial => 'spree/shared/error_messages', :locals => { :target => @order } %>
From 46df78942e1c8ad774da609046488a3385f7bafe Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Fri, 19 Oct 2012 10:09:21 +1100
Subject: [PATCH 266/346] Spree::Product.on_hand no longer sums deleted
variants
Fixes #2112
---
core/app/models/spree/product/scopes.rb | 2 +-
core/spec/models/product/scopes_spec.rb | 14 ++++++++++++++
2 files changed, 15 insertions(+), 1 deletion(-)
diff --git a/core/app/models/spree/product/scopes.rb b/core/app/models/spree/product/scopes.rb
index 27669653997..4601e4e4db1 100644
--- a/core/app/models/spree/product/scopes.rb
+++ b/core/app/models/spree/product/scopes.rb
@@ -199,7 +199,7 @@ def self.available(available_on = nil)
add_search_scope :on_hand do
variants_table = Variant.table_name
- where("#{table_name}.id in (select product_id from #{variants_table} where product_id = #{table_name}.id group by product_id having sum(count_on_hand) > 0)")
+ where("#{table_name}.id in (select product_id from #{variants_table} where product_id = #{table_name}.id and #{variants_table}.deleted_at IS NULL group by product_id having sum(count_on_hand) > 0)")
end
add_search_scope :taxons_name_eq do |name|
diff --git a/core/spec/models/product/scopes_spec.rb b/core/spec/models/product/scopes_spec.rb
index 0d477e1d56e..8c3a3003309 100644
--- a/core/spec/models/product/scopes_spec.rb
+++ b/core/spec/models/product/scopes_spec.rb
@@ -20,4 +20,18 @@
Spree::Product.in_taxon(@parent_taxon).to_a.count.should == 1
end
end
+
+ context "on_hand" do
+ # Regression test for #2111
+ context "A product with a deleted variant" do
+ before do
+ variant = product.variants.create({:count_on_hand => 300}, :without_protection => true)
+ variant.update_column(:deleted_at, Time.now)
+ end
+
+ it "does not include the deleted variant in on_hand summary" do
+ Spree::Product.on_hand.should be_empty
+ end
+ end
+ end
end
From d8fe4e83f13939584b645b8bc0432afeac266a11 Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Fri, 19 Oct 2012 10:45:30 +1100
Subject: [PATCH 267/346] select2 is not enabled for option types in test mode
---
core/spec/requests/admin/products/edit/variants_spec.rb | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/core/spec/requests/admin/products/edit/variants_spec.rb b/core/spec/requests/admin/products/edit/variants_spec.rb
index 8793f8a35bc..ef31db32db8 100644
--- a/core/spec/requests/admin/products/edit/variants_spec.rb
+++ b/core/spec/requests/admin/products/edit/variants_spec.rb
@@ -37,7 +37,7 @@
visit spree.admin_path
click_link "Products"
within('table.index tr:nth-child(2)') { click_link "Edit" }
- select2('#product_option_types_field', 'color')
+ select "colors", :from => "Option Types"
click_button "Update"
page.should have_content("successfully updated!")
From b60fc087fab417b69c37f6e6115a8ecc7545b4a0 Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Sat, 20 Oct 2012 08:08:37 +1100
Subject: [PATCH 268/346] Remove excessive spacing in JS for
products/new.html.erb
---
core/app/views/spree/admin/products/new.html.erb | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/core/app/views/spree/admin/products/new.html.erb b/core/app/views/spree/admin/products/new.html.erb
index c4c9dd50fac..ba6541a5a0b 100644
--- a/core/app/views/spree/admin/products/new.html.erb
+++ b/core/app/views/spree/admin/products/new.html.erb
@@ -59,7 +59,7 @@
//";
- var prototype_select = $('#product_prototype_id');
+ var prototype_select = $('#product_prototype_id');
prototype_select.change(function() {
var id = prototype_select.val();
if (id.length) {
From 88b1c62d85bed5bb9fda99d81d21ce5beaa18d46 Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Sat, 20 Oct 2012 08:14:59 +1100
Subject: [PATCH 269/346] capture! now does not operate on 'completed' payments
Fixes #2119
---
core/app/models/spree/payment/processing.rb | 1 +
core/spec/models/payment_spec.rb | 19 ++++++++++++++-----
2 files changed, 15 insertions(+), 5 deletions(-)
diff --git a/core/app/models/spree/payment/processing.rb b/core/app/models/spree/payment/processing.rb
index 5e24fa8b7b9..921132b7fc5 100644
--- a/core/app/models/spree/payment/processing.rb
+++ b/core/app/models/spree/payment/processing.rb
@@ -28,6 +28,7 @@ def purchase!
end
def capture!
+ return true if completed?
protect_from_connection_error do
check_environment
diff --git a/core/spec/models/payment_spec.rb b/core/spec/models/payment_spec.rb
index 738d54ed307..870dd23df26 100644
--- a/core/spec/models/payment_spec.rb
+++ b/core/spec/models/payment_spec.rb
@@ -182,11 +182,6 @@
payment.state = 'pending'
end
- it "should not do anything" do
- payment.payment_method.should_not_receive(:capture)
- payment.log_entries.should_not_receive(:create)
- end
-
context "if sucessful" do
before do
payment.payment_method.should_receive(:capture).with(payment, card, anything).and_return(success_response)
@@ -213,6 +208,20 @@
end
end
end
+
+ # Regression test for #2119
+ context "when payment is completed" do
+ before do
+ payment.state = 'completed'
+ end
+
+ it "should do nothing" do
+ payment.should_not_receive(:complete)
+ payment.payment_method.should_not_receive(:capture)
+ payment.log_entries.should_not_receive(:create)
+ payment.capture!
+ end
+ end
end
context "#void" do
From b9fdd6a67b48e67f645bb1cb218aea57573ee242 Mon Sep 17 00:00:00 2001
From: Brice Sanchez
Date: Fri, 19 Oct 2012 14:39:06 -0400
Subject: [PATCH 270/346] Localize order adjustements term in
orders/_adjustments view
Fixes #2123
---
core/app/views/spree/orders/_adjustments.html.erb | 2 +-
core/config/locales/en.yml | 1 +
2 files changed, 2 insertions(+), 1 deletion(-)
diff --git a/core/app/views/spree/orders/_adjustments.html.erb b/core/app/views/spree/orders/_adjustments.html.erb
index bb2d556722d..c913661f2be 100644
--- a/core/app/views/spree/orders/_adjustments.html.erb
+++ b/core/app/views/spree/orders/_adjustments.html.erb
@@ -1,6 +1,6 @@
-
+
diff --git a/core/config/locales/en.yml b/core/config/locales/en.yml
index 4dc9458a16a..7e4392da26c 100644
--- a/core/config/locales/en.yml
+++ b/core/config/locales/en.yml
@@ -605,6 +605,7 @@ en:
or: or
or_over_price: "%{price} or over"
order: Order
+ order_adjustments: "Order adjustments"
order_confirmation_note: ""
order_date: "Order Date"
order_details: "Order Details"
From 0c91bad3f267158a71bea219237255c71ee50437 Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Mon, 22 Oct 2012 11:37:52 +1100
Subject: [PATCH 271/346] Show credit card form on checkout payment screen
after invalid data has been entered
Fixes #2122
---
core/app/assets/javascripts/store/checkout.js.coffee | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/core/app/assets/javascripts/store/checkout.js.coffee b/core/app/assets/javascripts/store/checkout.js.coffee
index d61052e01a1..f0336cd8fcb 100644
--- a/core/app/assets/javascripts/store/checkout.js.coffee
+++ b/core/app/assets/javascripts/store/checkout.js.coffee
@@ -51,7 +51,11 @@ $ ->
).triggerHandler 'click'
if ($ '#checkout_form_payment').is('*')
+ # Activate already checked payment method if form is re-rendered
+ # i.e. if user enters invalid data
+ ($ 'input[type="radio"]:checked').click()
+
($ 'input[type="radio"][name="order[payments_attributes][][payment_method_id]"]').click(->
($ '#payment-methods li').hide()
($ '#payment_method_' + @value).show() if @checked
- ).triggerHandler 'click'
+ )
From fd3746205ca96afcbf49145d26c97ab8ff0fda4a Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Mon, 22 Oct 2012 12:47:30 +1100
Subject: [PATCH 272/346] Create a tax charge whenever a line item is created
or destroyed
Fixes #1481
---
core/app/models/spree/line_item.rb | 1 +
core/spec/models/line_item_spec.rb | 28 ++++++++++++++++++++++++++--
2 files changed, 27 insertions(+), 2 deletions(-)
diff --git a/core/app/models/spree/line_item.rb b/core/app/models/spree/line_item.rb
index d08fd072e91..9bcd364fc36 100644
--- a/core/app/models/spree/line_item.rb
+++ b/core/app/models/spree/line_item.rb
@@ -80,6 +80,7 @@ def remove_inventory
def update_order
# update the order totals, etc.
+ order.create_tax_charge!
order.update!
end
diff --git a/core/spec/models/line_item_spec.rb b/core/spec/models/line_item_spec.rb
index 3d3d23e8bf1..68a4dc03941 100644
--- a/core/spec/models/line_item_spec.rb
+++ b/core/spec/models/line_item_spec.rb
@@ -22,14 +22,18 @@
end
context '#save' do
- it 'should update inventory and totals' do
+ it 'should update inventory, totals, and tax' do
Spree::InventoryUnit.stub(:increase)
line_item.should_receive(:update_inventory)
+ # Regression check for #1481
+ order.should_receive(:create_tax_charge!)
order.should_receive(:update!)
line_item.save
end
context 'when order#completed? is true' do
+ # We don't care about this method for these tests
+ before { line_item.stub(:update_order) }
context 'and line_item is a new record' do
before { line_item.stub(:new_record? => true) }
@@ -37,6 +41,8 @@
it 'should increase inventory' do
Spree::InventoryUnit.stub(:increase)
Spree::InventoryUnit.should_receive(:increase).with(order, variant, 5)
+ # We don't care about this method for this test
+ line_item.stub(:update_order)
line_item.save
end
end
@@ -72,7 +78,11 @@
end
context 'when order#completed? is false' do
- before { order.stub(:completed? => false) }
+ before do
+ order.stub(:completed? => false)
+ # We don't care about this method for this test
+ line_item.stub(:update_order)
+ end
it 'should not manage inventory' do
Spree::InventoryUnit.should_not_receive(:increase)
@@ -83,8 +93,18 @@
end
context '#destroy' do
+ # Regression test for #1481
+ it "applies tax adjustments" do
+ # We don't care about this method for this test
+ line_item.stub(:remove_inventory)
+ order.should_receive(:create_tax_charge!)
+ line_item.destroy
+ end
+
context 'when order.completed? is true' do
it 'should remove inventory' do
+ # We don't care about this method for this test
+ line_item.stub(:update_order)
Spree::InventoryUnit.should_receive(:decrease).with(order, variant, 5)
line_item.destroy
end
@@ -106,6 +126,8 @@
end
it 'should allow destroy when no units have shipped' do
+ # We don't care about this method for this test
+ line_item.stub(:update_order)
line_item.should_receive(:remove_inventory)
line_item.destroy.should be_true
end
@@ -193,6 +215,8 @@
shipment.stub(:inventory_units => inventory_units)
inventory_units.stub(:shipped => shipped_inventory_units)
shipped_inventory_units.stub(:where).with(:variant_id => line_item.variant_id).and_return(shipped_inventory_units)
+ # We don't care about this method for these test
+ line_item.stub(:update_order)
end
it 'should not allow quantity to be adjusted lower than already shipped units' do
From 87f5988401111e7e28d4f41fcb29c8c65ccb6918 Mon Sep 17 00:00:00 2001
From: Karsten Senz
Date: Mon, 22 Oct 2012 17:54:07 +0200
Subject: [PATCH 273/346] Added REST support for create, update, delete and
show of product properties
Fixes #2132
---
.../api/v1/product_properties_controller.rb | 59 ++++++++++++++
.../api/v1/product_properties/index.rabl | 4 +
.../spree/api/v1/product_properties/new.rabl | 2 +
.../spree/api/v1/product_properties/show.rabl | 2 +
api/config/routes.rb | 4 +-
.../v1/product_properties_controller_spec.rb | 77 +++++++++++++++++++
6 files changed, 146 insertions(+), 2 deletions(-)
create mode 100644 api/app/controllers/spree/api/v1/product_properties_controller.rb
create mode 100644 api/app/views/spree/api/v1/product_properties/index.rabl
create mode 100644 api/app/views/spree/api/v1/product_properties/new.rabl
create mode 100644 api/app/views/spree/api/v1/product_properties/show.rabl
create mode 100644 api/spec/controllers/spree/api/v1/product_properties_controller_spec.rb
diff --git a/api/app/controllers/spree/api/v1/product_properties_controller.rb b/api/app/controllers/spree/api/v1/product_properties_controller.rb
new file mode 100644
index 00000000000..460f1c92d77
--- /dev/null
+++ b/api/app/controllers/spree/api/v1/product_properties_controller.rb
@@ -0,0 +1,59 @@
+module Spree
+ module Api
+ module V1
+ class ProductPropertiesController < Spree::Api::V1::BaseController
+ before_filter :product
+ before_filter :product_property, :only => [:show, :update, :destroy]
+
+ def index
+ @product_properties = @product.product_properties
+ end
+
+ def show
+ end
+
+ def new
+ end
+
+ def create
+ authorize! :create, ProductProperty
+ @product_property = @product.product_properties.new(params[:product_property])
+ if @product_property.save
+ render :show, :status => 201
+ else
+ invalid_resource!(@product_property)
+ end
+ end
+
+ def update
+ authorize! :update, ProductProperty
+ if @product_property && @product_property.update_attributes(params[:product_property])
+ render :show, :status => 200
+ else
+ invalid_resource!(@product_property)
+ end
+ end
+
+ def destroy
+ authorize! :delete, ProductProperty
+ if(@product_property)
+ @product_property.destroy
+ render :text => nil, :status => 200
+ else
+ invalid_resource!(@product_property)
+ end
+
+ end
+
+ private
+ def product
+ @product ||= Spree::Product.find_by_permalink(params[:product_id]) if params[:product_id]
+ end
+
+ def product_property
+ @product_property = @product.product_properties.find(:first, :joins => :property, :conditions => {'spree_properties.name' => params['property_name']},:readonly => false)
+ end
+ end
+ end
+ end
+end
\ No newline at end of file
diff --git a/api/app/views/spree/api/v1/product_properties/index.rabl b/api/app/views/spree/api/v1/product_properties/index.rabl
new file mode 100644
index 00000000000..b99ff8a9f0d
--- /dev/null
+++ b/api/app/views/spree/api/v1/product_properties/index.rabl
@@ -0,0 +1,4 @@
+collection @product_properties
+attributes *product_property_attributes
+
+
diff --git a/api/app/views/spree/api/v1/product_properties/new.rabl b/api/app/views/spree/api/v1/product_properties/new.rabl
new file mode 100644
index 00000000000..9556ea41320
--- /dev/null
+++ b/api/app/views/spree/api/v1/product_properties/new.rabl
@@ -0,0 +1,2 @@
+node(:attributes) { [*product_property_attributes] }
+node(:required_attributes) { [] }
\ No newline at end of file
diff --git a/api/app/views/spree/api/v1/product_properties/show.rabl b/api/app/views/spree/api/v1/product_properties/show.rabl
new file mode 100644
index 00000000000..12e24137b53
--- /dev/null
+++ b/api/app/views/spree/api/v1/product_properties/show.rabl
@@ -0,0 +1,2 @@
+object @product_property
+attributes *product_property_attributes
diff --git a/api/config/routes.rb b/api/config/routes.rb
index ea2cfa6348c..5e36fc901eb 100644
--- a/api/config/routes.rb
+++ b/api/config/routes.rb
@@ -16,13 +16,13 @@
end
resources :variants
+ resources :product_properties
end
resources :images
-
resources :variants, :only => [:index] do
end
-
+
resources :orders do
collection do
get :search
diff --git a/api/spec/controllers/spree/api/v1/product_properties_controller_spec.rb b/api/spec/controllers/spree/api/v1/product_properties_controller_spec.rb
new file mode 100644
index 00000000000..6dc10d19a1f
--- /dev/null
+++ b/api/spec/controllers/spree/api/v1/product_properties_controller_spec.rb
@@ -0,0 +1,77 @@
+require 'spec_helper'
+require 'shared_examples/protect_product_actions'
+
+module Spree
+ describe Spree::Api::V1::ProductPropertiesController do
+ render_views
+
+ let!(:product) { create(:product) }
+ let!(:property_1) {product.product_properties.create(:property_name => "My Property 1", :value => "my value 1")}
+ let!(:property_2) {product.product_properties.create(:property_name => "My Property 2", :value => "my value 2")}
+
+ let(:attributes) { [:id, :product_id, :property_id, :value, :property_name] }
+ let(:resource_scoping) { { :product_id => product.to_param } }
+
+ before do
+ stub_authentication!
+ end
+
+ it "can see a list of all product properties" do
+ api_get :index
+ json_response.count.should eq 2
+ json_response.first.should have_attributes(attributes)
+ end
+
+ it "can see a single product_property" do
+ api_get :show, :property_name => property_1.property_name
+ json_response.count.should eq 1
+ json_response.should have_attributes(attributes)
+ end
+
+ it "can learn how to create a new product property" do
+ api_get :new
+ json_response["attributes"].should == attributes.map(&:to_s)
+ json_response["required_attributes"].should be_empty
+ end
+
+ it "cannot create a new product property if not an admin" do
+ api_post :create, :product_property => { :property_name => "My Property 3" }
+ assert_unauthorized!
+ end
+
+ it "cannot update a product property" do
+ api_put :update, :property_name => property_1.property_name, :product_property => { :value => "my value 456" }
+ assert_unauthorized!
+ end
+
+ it "cannot delete a product property" do
+ api_delete :destroy, :property_name => property_1.property_name
+ assert_unauthorized!
+ lambda { property_1.reload }.should_not raise_error
+ end
+
+ context "as an admin" do
+ sign_in_as_admin!
+
+ it "can create a new product property" do
+ expect do
+ api_post :create, :product_property => { :property_name => "My Property 3", :value => "my value 3" }
+ end.to change(product.product_properties, :count).by(1)
+ json_response.should have_attributes(attributes)
+ response.status.should == 201
+ end
+
+ it "can update a product property" do
+ api_put :update, :property_name => property_1.property_name, :product_property => { :value => "my value 456" }
+ response.status.should == 200
+ end
+
+ it "can delete a variant" do
+ api_delete :destroy, :property_name => property_1.property_name
+ response.status.should == 200
+ lambda { property_1.reload }.should raise_error(ActiveRecord::RecordNotFound)
+ end
+ end
+
+ end
+end
\ No newline at end of file
From 90e3f5562ce5b17812e1e51a17cd8d06138786da Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Tue, 23 Oct 2012 14:47:54 +1100
Subject: [PATCH 274/346] Destroying a product returns no data, therefore 204
status is better
---
api/app/controllers/spree/api/v1/products_controller.rb | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/api/app/controllers/spree/api/v1/products_controller.rb b/api/app/controllers/spree/api/v1/products_controller.rb
index 9967742309c..ea6bca68ffc 100644
--- a/api/app/controllers/spree/api/v1/products_controller.rb
+++ b/api/app/controllers/spree/api/v1/products_controller.rb
@@ -44,7 +44,7 @@ def destroy
@product = find_product(params[:id])
@product.update_attribute(:deleted_at, Time.now)
@product.variants_including_master.update_all(:deleted_at => Time.now)
- render :text => nil, :status => 200
+ render :text => nil, :status => 204
end
end
end
From 9979c1543a8683ea0130cd55037833c91923eed2 Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Wed, 24 Oct 2012 09:22:54 +1100
Subject: [PATCH 275/346] [api] Admin requests MUST now use a token, even if
requires_authentication is disabled
Fixes #2140
---
.../spree/api/v1/base_controller.rb | 2 +-
.../spree/api/v1/products_controller_spec.rb | 19 +++++++++++++++++++
2 files changed, 20 insertions(+), 1 deletion(-)
diff --git a/api/app/controllers/spree/api/v1/base_controller.rb b/api/app/controllers/spree/api/v1/base_controller.rb
index fbd8aa98bb0..6b44d12806a 100644
--- a/api/app/controllers/spree/api/v1/base_controller.rb
+++ b/api/app/controllers/spree/api/v1/base_controller.rb
@@ -41,7 +41,7 @@ def check_for_api_key
end
def authenticate_user
- if requires_authentication?
+ if requires_authentication? || api_key.present?
unless @current_api_user = Spree.user_class.find_by_spree_api_key(api_key)
render "spree/api/v1/errors/invalid_api_key", :status => 401 and return
end
diff --git a/api/spec/controllers/spree/api/v1/products_controller_spec.rb b/api/spec/controllers/spree/api/v1/products_controller_spec.rb
index 47df8166fb4..7a679baa1a1 100644
--- a/api/spec/controllers/spree/api/v1/products_controller_spec.rb
+++ b/api/spec/controllers/spree/api/v1/products_controller_spec.rb
@@ -144,6 +144,25 @@ module Spree
response.status.should == 201
end
+ # Regression test for #2140
+ context "with authentication_required set to false" do
+ before do
+ Spree::Api::Config.requires_authentication = false
+ end
+
+ after do
+ Spree::Api::Config.requires_authentication = true
+ end
+
+ it "can still create a product" do
+ api_post :create, :product => { :name => "The Other Product",
+ :price => 19.99 },
+ :token => "fake"
+ json_response.should have_attributes(attributes)
+ response.status.should == 201
+ end
+ end
+
it "cannot create a new product with invalid attributes" do
api_post :create, :product => {}
response.status.should == 422
From 57087498679babf2cc41d16189c3dab102fcdc26 Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Wed, 24 Oct 2012 09:40:13 +1100
Subject: [PATCH 276/346] [api] Fix response.status for
ProductsController#destroy
---
api/spec/controllers/spree/api/v1/products_controller_spec.rb | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/api/spec/controllers/spree/api/v1/products_controller_spec.rb b/api/spec/controllers/spree/api/v1/products_controller_spec.rb
index 7a679baa1a1..649f91120ad 100644
--- a/api/spec/controllers/spree/api/v1/products_controller_spec.rb
+++ b/api/spec/controllers/spree/api/v1/products_controller_spec.rb
@@ -187,7 +187,7 @@ module Spree
it "can delete a product" do
product.deleted_at.should be_nil
api_delete :destroy, :id => product.to_param
- response.status.should == 200
+ response.status.should == 204
product.reload.deleted_at.should_not be_nil
end
end
From e271b4f305c6505c49bc008dc34a17d1ed3d6365 Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Wed, 24 Oct 2012 10:09:39 +1100
Subject: [PATCH 277/346] [api] Variants API is now paginated and scoped
correctly
Responses were previously returned as:
[ { variant: } ]
But are now returned as
{ variants: [{ variant: }] }
Just like products are.
---
.../spree/api/v1/variants_controller.rb | 2 +-
.../views/spree/api/v1/variants/index.rabl | 12 ++++++---
.../spree/api/v1/variants_controller_spec.rb | 26 ++++++++++++++++---
3 files changed, 33 insertions(+), 7 deletions(-)
diff --git a/api/app/controllers/spree/api/v1/variants_controller.rb b/api/app/controllers/spree/api/v1/variants_controller.rb
index 655c986fe38..80c6da798f2 100644
--- a/api/app/controllers/spree/api/v1/variants_controller.rb
+++ b/api/app/controllers/spree/api/v1/variants_controller.rb
@@ -5,7 +5,7 @@ class VariantsController < Spree::Api::V1::BaseController
before_filter :product
def index
- @variants = scope.includes(:option_values).scoped
+ @variants = scope.includes(:option_values).page(params[:page])
end
def show
diff --git a/api/app/views/spree/api/v1/variants/index.rabl b/api/app/views/spree/api/v1/variants/index.rabl
index 7790118a0e4..0dde8b0bedf 100644
--- a/api/app/views/spree/api/v1/variants/index.rabl
+++ b/api/app/views/spree/api/v1/variants/index.rabl
@@ -1,3 +1,9 @@
-collection @variants
-attributes *variant_attributes
-child(:option_values => :option_values) { attributes *option_value_attributes }
+object false
+node(:count) { @variants.total_count }
+node(:current_page) { params[:page] ? params[:page].to_i : 1 }
+node(:pages) { @variants.num_pages }
+
+child(@variants => :variants) do
+ attributes *variant_attributes
+ child(:option_values => :option_values) { attributes *option_value_attributes }
+end
diff --git a/api/spec/controllers/spree/api/v1/variants_controller_spec.rb b/api/spec/controllers/spree/api/v1/variants_controller_spec.rb
index 9b57a8fdff2..f67156dd96f 100644
--- a/api/spec/controllers/spree/api/v1/variants_controller_spec.rb
+++ b/api/spec/controllers/spree/api/v1/variants_controller_spec.rb
@@ -20,16 +20,36 @@ module Spree
stub_authentication!
end
- it "can see a list of all variants" do
+ it "can see a paginated list of variants" do
api_get :index
- json_response.first.should have_attributes(attributes)
- option_values = json_response.last["variant"]["option_values"]
+ json_response["variants"].first.should have_attributes(attributes)
+ json_response["count"].should == 1
+ json_response["current_page"].should == 1
+ json_response["pages"].should == 1
+ end
+
+ it "variants returned contain option values data" do
+ api_get :index
+ option_values = json_response["variants"].last["variant"]["option_values"]
option_values.first.should have_attributes([:name,
:presentation,
:option_type_name,
:option_type_id])
end
+ context "pagination" do
+ default_per_page(1)
+
+ it "can select the next page of variants" do
+ second_variant = create(:variant)
+ api_get :index, :page => 2
+ json_response["variants"].first.should have_attributes(attributes)
+ json_response["count"].should == 3
+ json_response["current_page"].should == 2
+ json_response["pages"].should == 3
+ end
+ end
+
it "can see a single variant" do
api_get :show, :id => variant.to_param
json_response.should have_attributes(attributes)
From 2b27c65fc9040258cd0e9ee36423cb1fdb91f9c8 Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Wed, 24 Oct 2012 10:45:50 +1100
Subject: [PATCH 278/346] [api] Only show deleted variants when 1) the user is
an admin and 2) when they pass through the show_deleted parameter
Fixes #2141
---
.../spree/api/v1/variants_controller.rb | 18 +++++++++++-
.../spree/api/v1/variants_controller_spec.rb | 29 +++++++++++++++++++
core/app/models/spree/product.rb | 2 ++
3 files changed, 48 insertions(+), 1 deletion(-)
diff --git a/api/app/controllers/spree/api/v1/variants_controller.rb b/api/app/controllers/spree/api/v1/variants_controller.rb
index 80c6da798f2..3337dd478c6 100644
--- a/api/app/controllers/spree/api/v1/variants_controller.rb
+++ b/api/app/controllers/spree/api/v1/variants_controller.rb
@@ -48,7 +48,23 @@ def product
end
def scope
- @product ? @product.variants_including_master : Variant
+ if @product
+ unless current_api_user.has_spree_role?("admin") || params[:show_deleted]
+ variants = @product.variants_including_master
+ else
+ variants = @product.variants_including_master_and_deleted
+ end
+ else
+ variants = Variant.scoped
+ if current_api_user.has_spree_role?("admin")
+ unless params[:show_deleted]
+ variants = Variant.active
+ end
+ else
+ variants = variants.active
+ end
+ end
+ variants
end
end
end
diff --git a/api/spec/controllers/spree/api/v1/variants_controller_spec.rb b/api/spec/controllers/spree/api/v1/variants_controller_spec.rb
index f67156dd96f..18ac9937d1d 100644
--- a/api/spec/controllers/spree/api/v1/variants_controller_spec.rb
+++ b/api/spec/controllers/spree/api/v1/variants_controller_spec.rb
@@ -37,6 +37,23 @@ module Spree
:option_type_id])
end
+ # Regression test for #2141
+ context "a deleted variant" do
+ before do
+ variant.update_column(:deleted_at, Time.now)
+ end
+
+ it "is not returned in the results" do
+ api_get :index
+ json_response["variants"].count.should == 0
+ end
+
+ it "is not returned even when show_deleted is passed" do
+ api_get :index, :show_deleted => true
+ json_response["variants"].count.should == 0
+ end
+ end
+
context "pagination" do
default_per_page(1)
@@ -86,6 +103,18 @@ module Spree
sign_in_as_admin!
let(:resource_scoping) { { :product_id => variant.product.to_param } }
+ # Test for #2141
+ context "deleted variants" do
+ before do
+ variant.update_column(:deleted_at, Time.now)
+ end
+
+ it "are visible by admin" do
+ api_get :index, :show_deleted => 1
+ json_response["variants"].count.should == 1
+ end
+ end
+
it "can create a new variant" do
api_post :create, :variant => { :sku => "12345" }
json_response.should have_attributes(attributes)
diff --git a/core/app/models/spree/product.rb b/core/app/models/spree/product.rb
index e5f560f735b..5247e80d09b 100755
--- a/core/app/models/spree/product.rb
+++ b/core/app/models/spree/product.rb
@@ -44,6 +44,8 @@ class Product < ActiveRecord::Base
:conditions => { :deleted_at => nil },
:dependent => :destroy
+ has_many :variants_including_master_and_deleted, :class_name => 'Spree::Variant'
+
delegate_belongs_to :master, :sku, :price, :weight, :height, :width, :depth, :is_master
delegate_belongs_to :master, :cost_price if Variant.table_exists? && Variant.column_names.include?('cost_price')
From ea05560ffb8a8799325a27a9ea7f20f2d5527630 Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Wed, 24 Oct 2012 11:51:59 +1100
Subject: [PATCH 279/346] [api] /orders should always return an :orders key,
even if there are no orders
---
api/app/views/spree/api/v1/orders/index.rabl | 2 +-
.../controllers/spree/api/v1/orders_controller_spec.rb | 8 ++++++++
2 files changed, 9 insertions(+), 1 deletion(-)
diff --git a/api/app/views/spree/api/v1/orders/index.rabl b/api/app/views/spree/api/v1/orders/index.rabl
index 033dead6a1f..c937d2bffcf 100644
--- a/api/app/views/spree/api/v1/orders/index.rabl
+++ b/api/app/views/spree/api/v1/orders/index.rabl
@@ -1,5 +1,5 @@
object false
-child(@orders) do
+child(@orders => :orders) do
attributes *order_attributes
end
node(:count) { @orders.count }
diff --git a/api/spec/controllers/spree/api/v1/orders_controller_spec.rb b/api/spec/controllers/spree/api/v1/orders_controller_spec.rb
index a0686e3ea8b..af0f485c767 100644
--- a/api/spec/controllers/spree/api/v1/orders_controller_spec.rb
+++ b/api/spec/controllers/spree/api/v1/orders_controller_spec.rb
@@ -172,6 +172,14 @@ def clean_address(address)
context "as an admin" do
sign_in_as_admin!
+ context "with no orders" do
+ before { Spree::Order.delete_all }
+ it "still returns a root :orders key" do
+ api_get :index
+ json_response["orders"].should == []
+ end
+ end
+
context "with two orders" do
before { create(:order) }
From f77a83e77db697247d251983f79fa88dee3904e8 Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Wed, 24 Oct 2012 12:35:26 +1100
Subject: [PATCH 280/346] [api] Allow an order to be created without parameters
---
api/app/controllers/spree/api/v1/orders_controller.rb | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/api/app/controllers/spree/api/v1/orders_controller.rb b/api/app/controllers/spree/api/v1/orders_controller.rb
index dddac3aabba..a093ed89191 100644
--- a/api/app/controllers/spree/api/v1/orders_controller.rb
+++ b/api/app/controllers/spree/api/v1/orders_controller.rb
@@ -64,8 +64,8 @@ def empty
private
- def map_nested_attributes
- @nested_params = map_nested_attributes_keys Order, params[:order]
+ def nested_params
+ map_nested_attributes_keys Order, params[:order] || {}
end
def order
From b88a841ec3848a2a87a43b15d29d2e4947be8f8f Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Wed, 24 Oct 2012 12:39:21 +1100
Subject: [PATCH 281/346] [api] nested_params does not need to define an
instance variable
---
api/app/controllers/spree/api/v1/orders_controller.rb | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/api/app/controllers/spree/api/v1/orders_controller.rb b/api/app/controllers/spree/api/v1/orders_controller.rb
index a093ed89191..dbde9d8d250 100644
--- a/api/app/controllers/spree/api/v1/orders_controller.rb
+++ b/api/app/controllers/spree/api/v1/orders_controller.rb
@@ -2,7 +2,6 @@ module Spree
module Api
module V1
class OrdersController < Spree::Api::V1::BaseController
- before_filter :map_nested_attributes, :only => [:create, :update]
before_filter :authorize_read!, :except => [:index, :search, :create]
def index
@@ -20,13 +19,13 @@ def search
end
def create
- @order = Order.build_from_api(current_api_user, @nested_params)
+ @order = Order.build_from_api(current_api_user, nested_params)
next!
end
def update
authorize! :update, Order
- if order.update_attributes(@nested_params)
+ if order.update_attributes(nested_params)
order.update!
render :show
else
From 0f008be9003b1f71772734de88e3446ad87ef390 Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Wed, 24 Oct 2012 12:39:39 +1100
Subject: [PATCH 282/346] [api] OrdersController#create should respond with 201
---
api/app/controllers/spree/api/v1/orders_controller.rb | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/api/app/controllers/spree/api/v1/orders_controller.rb b/api/app/controllers/spree/api/v1/orders_controller.rb
index dbde9d8d250..76d46753cde 100644
--- a/api/app/controllers/spree/api/v1/orders_controller.rb
+++ b/api/app/controllers/spree/api/v1/orders_controller.rb
@@ -20,7 +20,7 @@ def search
def create
@order = Order.build_from_api(current_api_user, nested_params)
- next!
+ next!(:status => 201)
end
def update
@@ -71,9 +71,9 @@ def order
@order ||= Order.find_by_number!(params[:id])
end
- def next!
+ def next!(options={})
if @order.valid? && @order.next
- render :show, :status => 200
+ render :show, :status => options[:status] || 200
else
render :could_not_transition, :status => 422
end
From 9142745bb4b457c20d86b9dbdf6a274343ea509f Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Wed, 24 Oct 2012 12:40:39 +1100
Subject: [PATCH 283/346] [api] Fix orders_controller tests
---
.../controllers/spree/api/v1/orders_controller_spec.rb | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/api/spec/controllers/spree/api/v1/orders_controller_spec.rb b/api/spec/controllers/spree/api/v1/orders_controller_spec.rb
index af0f485c767..062c7fb41be 100644
--- a/api/spec/controllers/spree/api/v1/orders_controller_spec.rb
+++ b/api/spec/controllers/spree/api/v1/orders_controller_spec.rb
@@ -61,7 +61,7 @@ module Spree
it "can create an order" do
variant = create(:variant)
api_post :create, :order => { :line_items => [{ :variant_id => variant.to_param, :quantity => 5 }] }
- response.status.should == 200
+ response.status.should == 201
order = Order.last
order.line_items.count.should == 1
order.line_items.first.variant.should == variant
@@ -69,6 +69,13 @@ module Spree
json_response["order"]["state"].should == "address"
end
+ it "can create an order without any parameters" do
+ lambda { api_post :create }.should_not raise_error(NoMethodError)
+ response.status.should == 201
+ order = Order.last
+ json_response["order"]["state"].should == "address"
+ end
+
context "working with an order" do
before do
Order.any_instance.stub :user => current_api_user
From 69d6946fae18eb6fcc05b2232208d1f5c91d7bda Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Wed, 24 Oct 2012 12:55:34 +1100
Subject: [PATCH 284/346] [api] allow an order to have either its shipping
address or billing address updated
---
api/app/controllers/spree/api/v1/orders_controller.rb | 4 ++--
.../controllers/spree/api/v1/orders_controller_spec.rb | 9 +++++++++
2 files changed, 11 insertions(+), 2 deletions(-)
diff --git a/api/app/controllers/spree/api/v1/orders_controller.rb b/api/app/controllers/spree/api/v1/orders_controller.rb
index 76d46753cde..d20e5421863 100644
--- a/api/app/controllers/spree/api/v1/orders_controller.rb
+++ b/api/app/controllers/spree/api/v1/orders_controller.rb
@@ -34,8 +34,8 @@ def update
end
def address
- order.build_ship_address(params[:shipping_address])
- order.build_bill_address(params[:billing_address])
+ order.build_ship_address(params[:shipping_address]) if params[:shipping_address]
+ order.build_bill_address(params[:billing_address]) if params[:billing_address]
next!
end
diff --git a/api/spec/controllers/spree/api/v1/orders_controller_spec.rb b/api/spec/controllers/spree/api/v1/orders_controller_spec.rb
index 062c7fb41be..928ebfe6019 100644
--- a/api/spec/controllers/spree/api/v1/orders_controller_spec.rb
+++ b/api/spec/controllers/spree/api/v1/orders_controller_spec.rb
@@ -111,6 +111,15 @@ def clean_address(address)
json_response["order"]["shipping_methods"].should_not be_empty
end
+ it "can add just shipping address information to an order" do
+ api_put :address, :id => order.to_param, :shipping_address => shipping_address
+ response.status.should == 200
+ order.reload
+ order.shipping_address.reload
+ order.shipping_address.firstname.should == shipping_address[:firstname]
+ order.bill_address.should be_nil
+ end
+
it "cannot use an address that has no valid shipping methods" do
shipping_method.destroy
api_put :address, :id => order.to_param, :shipping_address => shipping_address, :billing_address => billing_address
From d3cb336a7d82da7f383e50b39fe984a4b3e7484d Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Thu, 25 Oct 2012 09:38:14 +1100
Subject: [PATCH 285/346] Do not allow void_transaction! to take place if
payment is already voided
Fixes sub-issue from #2119
---
core/app/models/spree/payment/processing.rb | 1 +
core/spec/models/payment_spec.rb | 12 ++++++++++++
2 files changed, 13 insertions(+)
diff --git a/core/app/models/spree/payment/processing.rb b/core/app/models/spree/payment/processing.rb
index 921132b7fc5..64208d9f975 100644
--- a/core/app/models/spree/payment/processing.rb
+++ b/core/app/models/spree/payment/processing.rb
@@ -48,6 +48,7 @@ def capture!
end
def void_transaction!
+ return true if void?
protect_from_connection_error do
check_environment
diff --git a/core/spec/models/payment_spec.rb b/core/spec/models/payment_spec.rb
index 870dd23df26..29050940897 100644
--- a/core/spec/models/payment_spec.rb
+++ b/core/spec/models/payment_spec.rb
@@ -274,6 +274,18 @@
lambda { payment.void_transaction! }.should raise_error(Spree::Core::GatewayError)
end
end
+
+ # Regression test for #2119
+ context "if payment is already voided" do
+ before do
+ payment.state = 'void'
+ end
+
+ it "should not void the payment" do
+ payment.payment_method.should_not_receive(:void)
+ payment.void_transaction!
+ end
+ end
end
context "#credit" do
From dadb84da555cba21257b0e9eb299ffc7db7bcbb5 Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Thu, 25 Oct 2012 10:56:38 +1100
Subject: [PATCH 286/346] [api] Always include a :payments key in payments
response
---
api/app/views/spree/api/v1/payments/index.rabl | 2 +-
api/spec/controllers/spree/api/v1/payments_controller_spec.rb | 4 ++--
2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/api/app/views/spree/api/v1/payments/index.rabl b/api/app/views/spree/api/v1/payments/index.rabl
index 3d9b2a44f85..63c9bb00cdd 100644
--- a/api/app/views/spree/api/v1/payments/index.rabl
+++ b/api/app/views/spree/api/v1/payments/index.rabl
@@ -1,2 +1,2 @@
-collection @payments
+collection @payments => :payments
attributes *payment_attributes
diff --git a/api/spec/controllers/spree/api/v1/payments_controller_spec.rb b/api/spec/controllers/spree/api/v1/payments_controller_spec.rb
index f08ca7468a4..2e83759c04d 100644
--- a/api/spec/controllers/spree/api/v1/payments_controller_spec.rb
+++ b/api/spec/controllers/spree/api/v1/payments_controller_spec.rb
@@ -22,7 +22,7 @@ module Spree
it "can view the payments for their order" do
api_get :index
- json_response.first.should have_attributes(attributes)
+ json_response["payments"].first.should have_attributes(attributes)
end
it "can learn how to create a new payment" do
@@ -67,7 +67,7 @@ module Spree
it "can view the payments on any order" do
api_get :index
response.status.should == 200
- json_response.first.should have_attributes(attributes)
+ json_response["payments"].first.should have_attributes(attributes)
end
context "for a given payment" do
From 461ef568c6e10499c116c1d305dba77ed54a2902 Mon Sep 17 00:00:00 2001
From: Karsten Senz
Date: Tue, 23 Oct 2012 16:47:12 +0200
Subject: [PATCH 287/346] [api] Fix ProductPropertiesController to use ID,
rather than name
Fixes #2143
---
.../api/v1/product_properties_controller.rb | 8 +++-
.../v1/product_properties_controller_spec.rb | 45 ++++++++++++-------
2 files changed, 36 insertions(+), 17 deletions(-)
diff --git a/api/app/controllers/spree/api/v1/product_properties_controller.rb b/api/app/controllers/spree/api/v1/product_properties_controller.rb
index 460f1c92d77..c7d0b1a9402 100644
--- a/api/app/controllers/spree/api/v1/product_properties_controller.rb
+++ b/api/app/controllers/spree/api/v1/product_properties_controller.rb
@@ -48,12 +48,16 @@ def destroy
private
def product
@product ||= Spree::Product.find_by_permalink(params[:product_id]) if params[:product_id]
+ @product ||= Spree::Product.find_by_id(params[:product_id]) if params[:product_id]
end
def product_property
- @product_property = @product.product_properties.find(:first, :joins => :property, :conditions => {'spree_properties.name' => params['property_name']},:readonly => false)
+ if @product
+ @product_property ||= @product.product_properties.find(:first, :joins => :property, :conditions => {'spree_properties.name' => params[:id]},:readonly => false)
+ @product_property ||= @product.product_properties.find_by_id(params[:id])
+ end
end
end
end
end
-end
\ No newline at end of file
+end
diff --git a/api/spec/controllers/spree/api/v1/product_properties_controller_spec.rb b/api/spec/controllers/spree/api/v1/product_properties_controller_spec.rb
index 6dc10d19a1f..cafd12685df 100644
--- a/api/spec/controllers/spree/api/v1/product_properties_controller_spec.rb
+++ b/api/spec/controllers/spree/api/v1/product_properties_controller_spec.rb
@@ -8,70 +8,85 @@ module Spree
let!(:product) { create(:product) }
let!(:property_1) {product.product_properties.create(:property_name => "My Property 1", :value => "my value 1")}
let!(:property_2) {product.product_properties.create(:property_name => "My Property 2", :value => "my value 2")}
-
+
let(:attributes) { [:id, :product_id, :property_id, :value, :property_name] }
let(:resource_scoping) { { :product_id => product.to_param } }
before do
stub_authentication!
end
-
+
it "can see a list of all product properties" do
api_get :index
json_response.count.should eq 2
json_response.first.should have_attributes(attributes)
end
-
+
it "can see a single product_property" do
- api_get :show, :property_name => property_1.property_name
+ api_get :show, :id => property_1.property_name
json_response.count.should eq 1
json_response.should have_attributes(attributes)
end
-
+
it "can learn how to create a new product property" do
api_get :new
json_response["attributes"].should == attributes.map(&:to_s)
json_response["required_attributes"].should be_empty
end
-
+
it "cannot create a new product property if not an admin" do
api_post :create, :product_property => { :property_name => "My Property 3" }
assert_unauthorized!
end
-
+
it "cannot update a product property" do
- api_put :update, :property_name => property_1.property_name, :product_property => { :value => "my value 456" }
+ api_put :update, :id => property_1.property_name, :product_property => { :value => "my value 456" }
assert_unauthorized!
end
-
+
it "cannot delete a product property" do
api_delete :destroy, :property_name => property_1.property_name
assert_unauthorized!
lambda { property_1.reload }.should_not raise_error
end
-
+
context "as an admin" do
sign_in_as_admin!
it "can create a new product property" do
expect do
- api_post :create, :product_property => { :property_name => "My Property 3", :value => "my value 3" }
+ api_post :create, :product_property => { :property_name => "My Property 3", :value => "my value 3" }
end.to change(product.product_properties, :count).by(1)
json_response.should have_attributes(attributes)
response.status.should == 201
end
it "can update a product property" do
- api_put :update, :property_name => property_1.property_name, :product_property => { :value => "my value 456" }
+ api_put :update, :id => property_1.property_name, :product_property => { :value => "my value 456" }
response.status.should == 200
end
it "can delete a variant" do
- api_delete :destroy, :property_name => property_1.property_name
+ api_delete :destroy, :id => property_1.property_name
response.status.should == 200
lambda { property_1.reload }.should raise_error(ActiveRecord::RecordNotFound)
end
end
-
+
+ context "with product identified by id" do
+ let(:resource_scoping) { { :product_id => product.id } }
+ it "can see a list of all product properties" do
+ api_get :index
+ json_response.count.should eq 2
+ json_response.first.should have_attributes(attributes)
+ end
+ it "can see a single product_property by id" do
+ api_get :show, :id => property_1.id
+ json_response.count.should eq 1
+ puts "Response: #{json_response}"
+ json_response.should have_attributes(attributes)
+ end
+ end
+
end
-end
\ No newline at end of file
+end
From 66da2af840f45128d870141da0c788cccc36a4d1 Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Thu, 25 Oct 2012 12:31:27 +1100
Subject: [PATCH 288/346] [api] Add capture endpoint for payments
---
.../spree/api/v1/payments_controller.rb | 4 ++++
.../spree/api/v1/payments_controller_spec.rb | 18 ++++++++++++++++++
2 files changed, 22 insertions(+)
diff --git a/api/app/controllers/spree/api/v1/payments_controller.rb b/api/app/controllers/spree/api/v1/payments_controller.rb
index e33386c5010..73a219e88db 100644
--- a/api/app/controllers/spree/api/v1/payments_controller.rb
+++ b/api/app/controllers/spree/api/v1/payments_controller.rb
@@ -29,6 +29,10 @@ def authorize
perform_payment_action(:authorize)
end
+ def capture
+ perform_payment_action(:capture)
+ end
+
def purchase
perform_payment_action(:purchase)
end
diff --git a/api/spec/controllers/spree/api/v1/payments_controller_spec.rb b/api/spec/controllers/spree/api/v1/payments_controller_spec.rb
index 2e83759c04d..e1eae06a158 100644
--- a/api/spec/controllers/spree/api/v1/payments_controller_spec.rb
+++ b/api/spec/controllers/spree/api/v1/payments_controller_spec.rb
@@ -89,6 +89,24 @@ module Spree
payment.state.should == "failed"
end
+ it "can capture" do
+ api_put :capture, :id => payment.to_param
+ response.status.should == 200
+ payment.reload
+ payment.state.should == "completed"
+ end
+
+ it "returns a 422 status when purchasing fails" do
+ fake_response = stub(:success? => false, :to_s => "Insufficient funds")
+ Spree::Gateway::Bogus.any_instance.should_receive(:capture).and_return(fake_response)
+ api_put :capture, :id => payment.to_param
+ response.status.should == 422
+ json_response["error"].should == "There was a problem with the payment gateway: Insufficient funds"
+
+ payment.reload
+ payment.state.should == "pending"
+ end
+
it "can purchase" do
api_put :purchase, :id => payment.to_param
response.status.should == 200
From 7fbc3f366871e8d0bec9070a97352fbde587a385 Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Thu, 25 Oct 2012 12:40:26 +1100
Subject: [PATCH 289/346] [api] Don't use deprecated syntax in
ProductPropertiesController
---
.../controllers/spree/api/v1/product_properties_controller.rb | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/api/app/controllers/spree/api/v1/product_properties_controller.rb b/api/app/controllers/spree/api/v1/product_properties_controller.rb
index c7d0b1a9402..af59ad5a65e 100644
--- a/api/app/controllers/spree/api/v1/product_properties_controller.rb
+++ b/api/app/controllers/spree/api/v1/product_properties_controller.rb
@@ -53,7 +53,7 @@ def product
def product_property
if @product
- @product_property ||= @product.product_properties.find(:first, :joins => :property, :conditions => {'spree_properties.name' => params[:id]},:readonly => false)
+ @product_property ||= @product.product_properties.joins(:property).where('spree_properties.name' => params[:id]).readonly(false)
@product_property ||= @product.product_properties.find_by_id(params[:id])
end
end
From 80f2ec04326c4682f07ca346f4eff2bf8753f1fe Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Thu, 25 Oct 2012 12:42:06 +1100
Subject: [PATCH 290/346] [api] whitespaces in ProductPropertiesController
---
.../api/v1/product_properties_controller.rb | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)
diff --git a/api/app/controllers/spree/api/v1/product_properties_controller.rb b/api/app/controllers/spree/api/v1/product_properties_controller.rb
index af59ad5a65e..d54b1ed1f57 100644
--- a/api/app/controllers/spree/api/v1/product_properties_controller.rb
+++ b/api/app/controllers/spree/api/v1/product_properties_controller.rb
@@ -8,13 +8,13 @@ class ProductPropertiesController < Spree::Api::V1::BaseController
def index
@product_properties = @product.product_properties
end
-
+
def show
end
-
+
def new
end
-
+
def create
authorize! :create, ProductProperty
@product_property = @product.product_properties.new(params[:product_property])
@@ -24,7 +24,7 @@ def create
invalid_resource!(@product_property)
end
end
-
+
def update
authorize! :update, ProductProperty
if @product_property && @product_property.update_attributes(params[:product_property])
@@ -33,7 +33,7 @@ def update
invalid_resource!(@product_property)
end
end
-
+
def destroy
authorize! :delete, ProductProperty
if(@product_property)
@@ -42,15 +42,15 @@ def destroy
else
invalid_resource!(@product_property)
end
-
+
end
-
+
private
def product
@product ||= Spree::Product.find_by_permalink(params[:product_id]) if params[:product_id]
@product ||= Spree::Product.find_by_id(params[:product_id]) if params[:product_id]
end
-
+
def product_property
if @product
@product_property ||= @product.product_properties.joins(:property).where('spree_properties.name' => params[:id]).readonly(false)
From c116e378ceadfc6df0b2ea18fe6c9c400542ebc4 Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Thu, 25 Oct 2012 14:11:24 +1100
Subject: [PATCH 291/346] Fix product properties API to not show properties for
unavailable products
---
.../spree/api/v1/product_properties_controller.rb | 9 ++++-----
.../api/v1/product_properties_controller_spec.rb | 12 +++++++++++-
2 files changed, 15 insertions(+), 6 deletions(-)
diff --git a/api/app/controllers/spree/api/v1/product_properties_controller.rb b/api/app/controllers/spree/api/v1/product_properties_controller.rb
index d54b1ed1f57..d3845764980 100644
--- a/api/app/controllers/spree/api/v1/product_properties_controller.rb
+++ b/api/app/controllers/spree/api/v1/product_properties_controller.rb
@@ -2,7 +2,7 @@ module Spree
module Api
module V1
class ProductPropertiesController < Spree::Api::V1::BaseController
- before_filter :product
+ before_filter :find_product
before_filter :product_property, :only => [:show, :update, :destroy]
def index
@@ -46,14 +46,13 @@ def destroy
end
private
- def product
- @product ||= Spree::Product.find_by_permalink(params[:product_id]) if params[:product_id]
- @product ||= Spree::Product.find_by_id(params[:product_id]) if params[:product_id]
+ def find_product
+ @product = super(params[:product_id])
end
def product_property
if @product
- @product_property ||= @product.product_properties.joins(:property).where('spree_properties.name' => params[:id]).readonly(false)
+ @product_property ||= @product.product_properties.joins(:property).where('spree_properties.name' => params[:id]).readonly(false).first
@product_property ||= @product.product_properties.find_by_id(params[:id])
end
end
diff --git a/api/spec/controllers/spree/api/v1/product_properties_controller_spec.rb b/api/spec/controllers/spree/api/v1/product_properties_controller_spec.rb
index cafd12685df..f0d70c333bb 100644
--- a/api/spec/controllers/spree/api/v1/product_properties_controller_spec.rb
+++ b/api/spec/controllers/spree/api/v1/product_properties_controller_spec.rb
@@ -16,6 +16,17 @@ module Spree
stub_authentication!
end
+ context "if product is deleted" do
+ before do
+ product.update_column(:deleted_at, Time.now)
+ end
+
+ it "can not see a list of product properties" do
+ api_get :index
+ response.status.should == 404
+ end
+ end
+
it "can see a list of all product properties" do
api_get :index
json_response.count.should eq 2
@@ -24,7 +35,6 @@ module Spree
it "can see a single product_property" do
api_get :show, :id => property_1.property_name
- json_response.count.should eq 1
json_response.should have_attributes(attributes)
end
From fbe3251af32f1017107c72f5dace0a180288333f Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Thu, 25 Oct 2012 14:20:22 +1100
Subject: [PATCH 292/346] [api] Ensure there is always a :product_properties
key returned by /products/:id/products_properties
---
.../views/spree/api/v1/product_properties/index.rabl | 2 +-
.../spree/api/v1/product_properties_controller_spec.rb | 10 +++++-----
2 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/api/app/views/spree/api/v1/product_properties/index.rabl b/api/app/views/spree/api/v1/product_properties/index.rabl
index b99ff8a9f0d..7c2c87d8582 100644
--- a/api/app/views/spree/api/v1/product_properties/index.rabl
+++ b/api/app/views/spree/api/v1/product_properties/index.rabl
@@ -1,4 +1,4 @@
-collection @product_properties
+collection @product_properties => :product_properties
attributes *product_property_attributes
diff --git a/api/spec/controllers/spree/api/v1/product_properties_controller_spec.rb b/api/spec/controllers/spree/api/v1/product_properties_controller_spec.rb
index f0d70c333bb..643e9d9c9e9 100644
--- a/api/spec/controllers/spree/api/v1/product_properties_controller_spec.rb
+++ b/api/spec/controllers/spree/api/v1/product_properties_controller_spec.rb
@@ -29,8 +29,8 @@ module Spree
it "can see a list of all product properties" do
api_get :index
- json_response.count.should eq 2
- json_response.first.should have_attributes(attributes)
+ json_response["product_properties"].count.should eq 2
+ json_response["product_properties"].first.should have_attributes(attributes)
end
it "can see a single product_property" do
@@ -87,13 +87,13 @@ module Spree
let(:resource_scoping) { { :product_id => product.id } }
it "can see a list of all product properties" do
api_get :index
- json_response.count.should eq 2
- json_response.first.should have_attributes(attributes)
+ json_response["product_properties"].count.should eq 2
+ json_response["product_properties"].first.should have_attributes(attributes)
end
+
it "can see a single product_property by id" do
api_get :show, :id => property_1.id
json_response.count.should eq 1
- puts "Response: #{json_response}"
json_response.should have_attributes(attributes)
end
end
From 02719d10e9df5563ec7cc2e3eef80a586935be5e Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Thu, 25 Oct 2012 14:21:56 +1100
Subject: [PATCH 293/346] [api] find by property id first, then name
This is to stop SQL errors like this from happening:
https://travis-ci.org/#!/spree/spree/jobs/2923604
---
.../controllers/spree/api/v1/product_properties_controller.rb | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/api/app/controllers/spree/api/v1/product_properties_controller.rb b/api/app/controllers/spree/api/v1/product_properties_controller.rb
index d3845764980..3d0ebdc9da8 100644
--- a/api/app/controllers/spree/api/v1/product_properties_controller.rb
+++ b/api/app/controllers/spree/api/v1/product_properties_controller.rb
@@ -52,8 +52,8 @@ def find_product
def product_property
if @product
- @product_property ||= @product.product_properties.joins(:property).where('spree_properties.name' => params[:id]).readonly(false).first
@product_property ||= @product.product_properties.find_by_id(params[:id])
+ @product_property ||= @product.product_properties.joins(:property).where('spree_properties.name' => params[:id]).readonly(false).first
end
end
end
From 02ae4a0d7984d03c8b888120fa877e0258fbc2bc Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Thu, 25 Oct 2012 15:00:02 +1100
Subject: [PATCH 294/346] [api] allow build_from_api to accept empty
line_item_attributes
---
api/app/models/spree/order_decorator.rb | 1 +
1 file changed, 1 insertion(+)
diff --git a/api/app/models/spree/order_decorator.rb b/api/app/models/spree/order_decorator.rb
index c52cdb3b8cc..34e8a2599d1 100644
--- a/api/app/models/spree/order_decorator.rb
+++ b/api/app/models/spree/order_decorator.rb
@@ -1,6 +1,7 @@
Spree::Order.class_eval do
def self.build_from_api(user, params)
order = create
+ params[:line_items_attributes] ||= []
params[:line_items_attributes].each do |line_item|
order.add_variant(Spree::Variant.find(line_item[:variant_id]), line_item[:quantity])
end
From 7d9cc656a240be302d481a5d14016d5fb7c404b9 Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Thu, 25 Oct 2012 14:43:59 +1100
Subject: [PATCH 295/346] [api] destroy statuses should return status 204
---
api/app/controllers/spree/api/v1/images_controller.rb | 2 +-
api/app/controllers/spree/api/v1/line_items_controller.rb | 2 +-
.../spree/api/v1/product_properties_controller.rb | 2 +-
api/app/controllers/spree/api/v1/taxonomies_controller.rb | 2 +-
api/app/controllers/spree/api/v1/taxons_controller.rb | 2 +-
api/app/controllers/spree/api/v1/variants_controller.rb | 2 +-
api/app/controllers/spree/api/v1/zones_controller.rb | 2 +-
api/spec/controllers/spree/api/v1/images_controller_spec.rb | 2 +-
.../controllers/spree/api/v1/line_items_controller_spec.rb | 2 +-
.../spree/api/v1/product_properties_controller_spec.rb | 2 +-
.../controllers/spree/api/v1/taxonomies_controller_spec.rb | 6 +++++-
api/spec/controllers/spree/api/v1/taxons_controller_spec.rb | 5 +++++
.../controllers/spree/api/v1/variants_controller_spec.rb | 2 +-
api/spec/controllers/spree/api/v1/zones_controller_spec.rb | 2 +-
14 files changed, 22 insertions(+), 13 deletions(-)
diff --git a/api/app/controllers/spree/api/v1/images_controller.rb b/api/app/controllers/spree/api/v1/images_controller.rb
index 096b8972a26..12d0fc94f70 100644
--- a/api/app/controllers/spree/api/v1/images_controller.rb
+++ b/api/app/controllers/spree/api/v1/images_controller.rb
@@ -23,7 +23,7 @@ def destroy
authorize! :delete, Image
@image = Image.find(params[:id])
@image.destroy
- render :text => nil
+ render :text => nil, :status => 204
end
end
diff --git a/api/app/controllers/spree/api/v1/line_items_controller.rb b/api/app/controllers/spree/api/v1/line_items_controller.rb
index 28dfd2b866d..90c2c9a5fad 100644
--- a/api/app/controllers/spree/api/v1/line_items_controller.rb
+++ b/api/app/controllers/spree/api/v1/line_items_controller.rb
@@ -26,7 +26,7 @@ def destroy
authorize! :read, order
@line_item = order.line_items.find(params[:id])
@line_item.destroy
- render :text => nil, :status => 200
+ render :text => nil, :status => 204
end
private
diff --git a/api/app/controllers/spree/api/v1/product_properties_controller.rb b/api/app/controllers/spree/api/v1/product_properties_controller.rb
index 3d0ebdc9da8..8159292e7b7 100644
--- a/api/app/controllers/spree/api/v1/product_properties_controller.rb
+++ b/api/app/controllers/spree/api/v1/product_properties_controller.rb
@@ -38,7 +38,7 @@ def destroy
authorize! :delete, ProductProperty
if(@product_property)
@product_property.destroy
- render :text => nil, :status => 200
+ render :text => nil, :status => 204
else
invalid_resource!(@product_property)
end
diff --git a/api/app/controllers/spree/api/v1/taxonomies_controller.rb b/api/app/controllers/spree/api/v1/taxonomies_controller.rb
index e3180018056..76d0824f059 100644
--- a/api/app/controllers/spree/api/v1/taxonomies_controller.rb
+++ b/api/app/controllers/spree/api/v1/taxonomies_controller.rb
@@ -32,7 +32,7 @@ def update
def destroy
authorize! :delete, Taxonomy
taxonomy.destroy
- render :text => nil, :status => 200
+ render :text => nil, :status => 204
end
private
diff --git a/api/app/controllers/spree/api/v1/taxons_controller.rb b/api/app/controllers/spree/api/v1/taxons_controller.rb
index bed8b1118ca..96f3235e6bc 100644
--- a/api/app/controllers/spree/api/v1/taxons_controller.rb
+++ b/api/app/controllers/spree/api/v1/taxons_controller.rb
@@ -32,7 +32,7 @@ def update
def destroy
authorize! :delete, Taxon
taxon.destroy
- render :text => nil, :status => 200
+ render :text => nil, :status => 204
end
private
diff --git a/api/app/controllers/spree/api/v1/variants_controller.rb b/api/app/controllers/spree/api/v1/variants_controller.rb
index 3337dd478c6..ecd3a519964 100644
--- a/api/app/controllers/spree/api/v1/variants_controller.rb
+++ b/api/app/controllers/spree/api/v1/variants_controller.rb
@@ -39,7 +39,7 @@ def destroy
authorize! :delete, Variant
@variant = scope.find(params[:id])
@variant.destroy
- render :text => nil, :status => 200
+ render :text => nil, :status => 204
end
private
diff --git a/api/app/controllers/spree/api/v1/zones_controller.rb b/api/app/controllers/spree/api/v1/zones_controller.rb
index 2b5def5df18..142ff7ea318 100644
--- a/api/app/controllers/spree/api/v1/zones_controller.rb
+++ b/api/app/controllers/spree/api/v1/zones_controller.rb
@@ -32,7 +32,7 @@ def update
def destroy
authorize! :delete, Zone
zone.destroy
- render :text => nil, :status => 200
+ render :text => nil, :status => 204
end
private
diff --git a/api/spec/controllers/spree/api/v1/images_controller_spec.rb b/api/spec/controllers/spree/api/v1/images_controller_spec.rb
index 430adc73c07..876fa79c4d7 100644
--- a/api/spec/controllers/spree/api/v1/images_controller_spec.rb
+++ b/api/spec/controllers/spree/api/v1/images_controller_spec.rb
@@ -40,7 +40,7 @@ module Spree
it "can delete an image" do
api_delete :destroy, :id => product_image.id
- response.status.should == 200
+ response.status.should == 204
lambda { product_image.reload }.should raise_error(ActiveRecord::RecordNotFound)
end
end
diff --git a/api/spec/controllers/spree/api/v1/line_items_controller_spec.rb b/api/spec/controllers/spree/api/v1/line_items_controller_spec.rb
index b1dd46e5075..d6da43d21ff 100644
--- a/api/spec/controllers/spree/api/v1/line_items_controller_spec.rb
+++ b/api/spec/controllers/spree/api/v1/line_items_controller_spec.rb
@@ -47,7 +47,7 @@ module Spree
it "can delete a line item on the order" do
line_item = order.line_items.first
api_delete :destroy, :id => line_item.id
- response.status.should == 200
+ response.status.should == 204
lambda { line_item.reload }.should raise_error(ActiveRecord::RecordNotFound)
end
end
diff --git a/api/spec/controllers/spree/api/v1/product_properties_controller_spec.rb b/api/spec/controllers/spree/api/v1/product_properties_controller_spec.rb
index 643e9d9c9e9..21378ffdabb 100644
--- a/api/spec/controllers/spree/api/v1/product_properties_controller_spec.rb
+++ b/api/spec/controllers/spree/api/v1/product_properties_controller_spec.rb
@@ -78,7 +78,7 @@ module Spree
it "can delete a variant" do
api_delete :destroy, :id => property_1.property_name
- response.status.should == 200
+ response.status.should == 204
lambda { property_1.reload }.should raise_error(ActiveRecord::RecordNotFound)
end
end
diff --git a/api/spec/controllers/spree/api/v1/taxonomies_controller_spec.rb b/api/spec/controllers/spree/api/v1/taxonomies_controller_spec.rb
index 32fb2bed04e..7595837d8c6 100644
--- a/api/spec/controllers/spree/api/v1/taxonomies_controller_spec.rb
+++ b/api/spec/controllers/spree/api/v1/taxonomies_controller_spec.rb
@@ -82,7 +82,11 @@ module Spree
json_response["error"].should == "Invalid resource. Please fix errors and try again."
errors = json_response["errors"]
end
- end
+ it "can destroy" do
+ api_delete :destroy, :id => taxonomy.id
+ response.status.should == 204
+ end
+ end
end
end
diff --git a/api/spec/controllers/spree/api/v1/taxons_controller_spec.rb b/api/spec/controllers/spree/api/v1/taxons_controller_spec.rb
index 17f8a76d4c4..82d7d7f6d71 100644
--- a/api/spec/controllers/spree/api/v1/taxons_controller_spec.rb
+++ b/api/spec/controllers/spree/api/v1/taxons_controller_spec.rb
@@ -76,6 +76,11 @@ module Spree
taxon.reload.children.count.should eq 1
end
+
+ it "can destroy" do
+ api_delete :destroy, :taxonomy_id => taxonomy.id, :id => taxon.id
+ response.status.should == 204
+ end
end
end
diff --git a/api/spec/controllers/spree/api/v1/variants_controller_spec.rb b/api/spec/controllers/spree/api/v1/variants_controller_spec.rb
index 18ac9937d1d..265e521b89c 100644
--- a/api/spec/controllers/spree/api/v1/variants_controller_spec.rb
+++ b/api/spec/controllers/spree/api/v1/variants_controller_spec.rb
@@ -130,7 +130,7 @@ module Spree
it "can delete a variant" do
api_delete :destroy, :id => variant.to_param
- response.status.should == 200
+ response.status.should == 204
lambda { variant.reload }.should raise_error(ActiveRecord::RecordNotFound)
end
end
diff --git a/api/spec/controllers/spree/api/v1/zones_controller_spec.rb b/api/spec/controllers/spree/api/v1/zones_controller_spec.rb
index 6b8b5572543..761ce5e6ed9 100644
--- a/api/spec/controllers/spree/api/v1/zones_controller_spec.rb
+++ b/api/spec/controllers/spree/api/v1/zones_controller_spec.rb
@@ -46,7 +46,7 @@ module Spree
it "can delete a zone" do
api_delete :destroy, :id => @zone.id
- response.status.should == 200
+ response.status.should == 204
lambda { @zone.reload }.should raise_error(ActiveRecord::RecordNotFound)
end
end
From 3518b65fa61613d6426f1bef6fe0503b2a16fec2 Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Fri, 26 Oct 2012 11:37:04 +1100
Subject: [PATCH 296/346] [api] Tidy up parameters in zones_controller_spec
---
.../spree/api/v1/zones_controller_spec.rb | 33 ++++++++++++++-----
1 file changed, 25 insertions(+), 8 deletions(-)
diff --git a/api/spec/controllers/spree/api/v1/zones_controller_spec.rb b/api/spec/controllers/spree/api/v1/zones_controller_spec.rb
index 761ce5e6ed9..8903acf2889 100644
--- a/api/spec/controllers/spree/api/v1/zones_controller_spec.rb
+++ b/api/spec/controllers/spree/api/v1/zones_controller_spec.rb
@@ -27,21 +27,38 @@ module Spree
sign_in_as_admin!
it "can create a new zone" do
- api_post :create, :zone => { :name => "North Pole",
- :zone_members => [ :zone_member => {
- :zoneable_id => 1 }] }
+ params = {
+ :name => "North Pole",
+ :zone_members => [
+ {
+ :zoneable_type => "Spree::Country",
+ :zoneable_id => 1
+ }
+ ]
+ }
+
response.status.should == 201
json_response.should have_attributes(attributes)
+ json_response["zone"]["zone_members"].should_not be_empty
end
it "updates a zone" do
- api_put :update, :id => @zone.id,
- :zone => { :name => "Americas",
- :zone_members => [ :zone_member => {
- :zoneable_type => 'Spree::Country',
- :zoneable_id => 1 }]}
+ params = { :id => 1,
+ :zone => {
+ :name => "North Pole",
+ :zone_members => [
+ {
+ :zoneable_type => "Spree::Country",
+ :zoneable_id => 1
+ }
+ ]
+ }
+ }
+
+ api_put :update, params
response.status.should == 200
json_response['zone']['name'].should eq 'Americas'
+ json_response['zone']['zone_members'].should_not be_blank
end
it "can delete a zone" do
From 405c764954688f719c7652539751430cca0224e2 Mon Sep 17 00:00:00 2001
From: Ted Lilley
Date: Fri, 26 Oct 2012 11:40:06 +1100
Subject: [PATCH 297/346] Remove X-UA-Compatible from layout
Fixes #2152
Fixes #2151
---
core/app/views/spree/shared/_head.html.erb | 2 --
1 file changed, 2 deletions(-)
diff --git a/core/app/views/spree/shared/_head.html.erb b/core/app/views/spree/shared/_head.html.erb
index ae107c4a5ab..86d91408538 100644
--- a/core/app/views/spree/shared/_head.html.erb
+++ b/core/app/views/spree/shared/_head.html.erb
@@ -1,6 +1,4 @@
-
-
<%= title %>
From 38f7cf2077d387b588e7ad837e038466cfee4632 Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Fri, 26 Oct 2012 11:41:51 +1100
Subject: [PATCH 298/346] Fixing Jirafe Links, Fixes #2144
Fixes #2150
---
dash/app/views/spree/admin/analytics/sign_up.html.erb | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/dash/app/views/spree/admin/analytics/sign_up.html.erb b/dash/app/views/spree/admin/analytics/sign_up.html.erb
index 794095e6006..dd4efe66ab1 100644
--- a/dash/app/views/spree/admin/analytics/sign_up.html.erb
+++ b/dash/app/views/spree/admin/analytics/sign_up.html.erb
@@ -3,11 +3,11 @@
<%= t(:analytics_sign_up) %>
<%= check_box_tag 'store[terms_of_service]', @store[:terms_of_service], @store.has_key?(:terms_of_service), :size => 50 %>
- <%= label_tag 'store[terms_of_service]', t(:agree_to_terms_of_service) %> (<%= t(:review) %> )
+ <%= label_tag 'store[terms_of_service]', t(:agree_to_terms_of_service) %> (<%= t(:review) %> )
<%= check_box_tag 'store[privacy_policy]', @store[:privacy_policy], @store.has_key?(:privacy_policy), :size => 50 %>
- <%= label_tag 'store[privacy_policy]', t(:agree_to_privacy_policy) %> (<%= t(:review) %> )
+ <%= label_tag 'store[privacy_policy]', t(:agree_to_privacy_policy) %> (<%= t(:review) %> )
<%= label_tag :first_name %>
From 4d36d3f72d049ceedbcf2b61e1ee597beefbc098 Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Thu, 25 Oct 2012 12:03:19 -0400
Subject: [PATCH 299/346] Remove ShippingMethod#calculator_available?
Related to #2149
---
core/app/models/spree/shipping_method.rb | 4 ----
1 file changed, 4 deletions(-)
diff --git a/core/app/models/spree/shipping_method.rb b/core/app/models/spree/shipping_method.rb
index ff083e72b08..b22e9eb3d9f 100644
--- a/core/app/models/spree/shipping_method.rb
+++ b/core/app/models/spree/shipping_method.rb
@@ -23,10 +23,6 @@ def displayable?(display_on)
(self.display_on == display_on.to_s || self.display_on.blank?)
end
- def calculator_available?(order)
- caluclator.available?(order)
- end
-
def within_zone?(order)
zone && zone.include?(order.ship_address)
end
From 5687ae06e9d77b8cf115adcf38fcf1bb3b56ffb3 Mon Sep 17 00:00:00 2001
From: Denis Ivanov
Date: Wed, 24 Oct 2012 15:45:33 -0700
Subject: [PATCH 300/346] Stripping EXIF from JPGs
Fixes #2142
Fixes #2145
---
core/app/models/spree/image.rb | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/core/app/models/spree/image.rb b/core/app/models/spree/image.rb
index 089360948bf..d52138fbffc 100644
--- a/core/app/models/spree/image.rb
+++ b/core/app/models/spree/image.rb
@@ -9,7 +9,8 @@ class Image < Asset
:styles => { :mini => '48x48>', :small => '100x100>', :product => '240x240>', :large => '600x600>' },
:default_style => :product,
:url => '/spree/products/:id/:style/:basename.:extension',
- :path => ':rails_root/public/spree/products/:id/:style/:basename.:extension'
+ :path => ':rails_root/public/spree/products/:id/:style/:basename.:extension',
+ :convert_options => { :all => '-strip' }
# 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
From 831436febac1e75844330574da13d925411f43f7 Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Fri, 26 Oct 2012 13:52:19 +1100
Subject: [PATCH 301/346] Ensure ALL select2 choices show up in taxons for
admin/products/edit
Fixes #2139
---
core/app/controllers/spree/admin/taxons_controller.rb | 2 +-
core/spec/requests/admin/products/edit/taxons_spec.rb | 3 +++
2 files changed, 4 insertions(+), 1 deletion(-)
diff --git a/core/app/controllers/spree/admin/taxons_controller.rb b/core/app/controllers/spree/admin/taxons_controller.rb
index ff0e3ed056b..18a4fb3a59a 100644
--- a/core/app/controllers/spree/admin/taxons_controller.rb
+++ b/core/app/controllers/spree/admin/taxons_controller.rb
@@ -6,7 +6,7 @@ class TaxonsController < Spree::Admin::BaseController
def search
if params[:ids]
- @taxons = Spree::Taxon.where(:id => params[:ids])
+ @taxons = Spree::Taxon.where(:id => params[:ids].split(','))
else
@taxons = Spree::Taxon.limit(20).search(:name_cont => params[:q]).result
end
diff --git a/core/spec/requests/admin/products/edit/taxons_spec.rb b/core/spec/requests/admin/products/edit/taxons_spec.rb
index fe6a9d348f4..34f912ffe37 100644
--- a/core/spec/requests/admin/products/edit/taxons_spec.rb
+++ b/core/spec/requests/admin/products/edit/taxons_spec.rb
@@ -25,6 +25,9 @@ def selected_taxons
select2("#product_taxons_field", "Clothing")
click_button "Update"
selected_taxons.should =~ [taxon_1.id, taxon_2.id]
+
+ # Regression test for #2139
+ all("#s2id_product_taxon_ids .select2-search-choice").count.should == 2
end
end
end
From 4fb4617e9fdcfb503578aafaf77966a374ff79e1 Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Mon, 29 Oct 2012 09:17:16 +1100
Subject: [PATCH 302/346] [api] Fix zones_controller_spec
---
.../spree/api/v1/zones_controller_spec.rb | 21 +++++++++++--------
1 file changed, 12 insertions(+), 9 deletions(-)
diff --git a/api/spec/controllers/spree/api/v1/zones_controller_spec.rb b/api/spec/controllers/spree/api/v1/zones_controller_spec.rb
index 8903acf2889..6819eea436e 100644
--- a/api/spec/controllers/spree/api/v1/zones_controller_spec.rb
+++ b/api/spec/controllers/spree/api/v1/zones_controller_spec.rb
@@ -28,22 +28,25 @@ module Spree
it "can create a new zone" do
params = {
- :name => "North Pole",
- :zone_members => [
- {
- :zoneable_type => "Spree::Country",
- :zoneable_id => 1
- }
- ]
+ :zone => {
+ :name => "North Pole",
+ :zone_members => [
+ {
+ :zoneable_type => "Spree::Country",
+ :zoneable_id => 1
+ }
+ ]
+ }
}
+ api_post :create, params
response.status.should == 201
json_response.should have_attributes(attributes)
json_response["zone"]["zone_members"].should_not be_empty
end
it "updates a zone" do
- params = { :id => 1,
+ params = { :id => @zone.id,
:zone => {
:name => "North Pole",
:zone_members => [
@@ -57,7 +60,7 @@ module Spree
api_put :update, params
response.status.should == 200
- json_response['zone']['name'].should eq 'Americas'
+ json_response['zone']['name'].should eq 'North Pole'
json_response['zone']['zone_members'].should_not be_blank
end
From 74a7914903b9d7dac77e0cbd38b1919fb3396254 Mon Sep 17 00:00:00 2001
From: Brian Quinn
Date: Fri, 2 Nov 2012 14:56:08 +0000
Subject: [PATCH 303/346] Only include eligible promotions in promo_total
---
promo/app/models/spree/order_decorator.rb | 2 +-
promo/spec/models/order_spec.rb | 11 +++++++++++
2 files changed, 12 insertions(+), 1 deletion(-)
diff --git a/promo/app/models/spree/order_decorator.rb b/promo/app/models/spree/order_decorator.rb
index 71a37c990b1..cfa30399309 100644
--- a/promo/app/models/spree/order_decorator.rb
+++ b/promo/app/models/spree/order_decorator.rb
@@ -23,6 +23,6 @@ def update_adjustments_with_promotion_limiting
end
def promo_total
- adjustments.promotion.map(&:amount).sum
+ adjustments.eligible.promotion.map(&:amount).sum
end
end
diff --git a/promo/spec/models/order_spec.rb b/promo/spec/models/order_spec.rb
index e40d2c4e80d..4ebcd50b395 100644
--- a/promo/spec/models/order_spec.rb
+++ b/promo/spec/models/order_spec.rb
@@ -48,6 +48,17 @@ def create_adjustment(label, amount)
order.adjustments.eligible.promotion.first.amount.to_i.should == -200
end
+ it "should only include eligible adjustments in promo_total" do
+ create_adjustment("Promotion A", -100)
+ create(:adjustment, :adjustable => order,
+ :originator => nil,
+ :amount => -1000,
+ :locked => true,
+ :eligible => false,
+ :label => 'Bad promo')
+
+ order.promo_total.to_f.should == -100.to_f
+ end
end
end
From 1a0db0d012fca1d748f4be19bcd6d132aef8d5de Mon Sep 17 00:00:00 2001
From: Masahiro Saito
Date: Sat, 3 Nov 2012 04:02:52 +0900
Subject: [PATCH 304/346] Removes deprecation warning during preferable_spec
run
Fixes #2174
---
core/spec/models/preferences/preferable_spec.rb | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/core/spec/models/preferences/preferable_spec.rb b/core/spec/models/preferences/preferable_spec.rb
index 123a579c82a..13b57e6af89 100644
--- a/core/spec/models/preferences/preferable_spec.rb
+++ b/core/spec/models/preferences/preferable_spec.rb
@@ -261,10 +261,10 @@ class PrefTest < ActiveRecord::Base
it "saves preferences for serialized object" do
pr = PrefTest.new
- pr[:pref_test_any] = [1, 2]
- pr[:pref_test_any].should == [1, 2]
+ pr.set_preference(:pref_test_any, [1, 2])
+ pr.get_preference(:pref_test_any).should == [1, 2]
pr.save!
- pr[:pref_test_any].should == [1, 2]
+ pr.get_preference(:pref_test_any).should == [1, 2]
end
end
From 5ff1f4d4ca109c520b54ae03146c12d6cf18e5c3 Mon Sep 17 00:00:00 2001
From: Stephane Bounmy
Date: Sat, 3 Nov 2012 19:17:57 +0100
Subject: [PATCH 305/346] taxon autocomplete display pretty_name instead of
name
Fixes #2178
---
core/app/assets/javascripts/admin/taxon_autocomplete.js.erb | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/core/app/assets/javascripts/admin/taxon_autocomplete.js.erb b/core/app/assets/javascripts/admin/taxon_autocomplete.js.erb
index 4b81a2c6223..aba94328cdf 100644
--- a/core/app/assets/javascripts/admin/taxon_autocomplete.js.erb
+++ b/core/app/assets/javascripts/admin/taxon_autocomplete.js.erb
@@ -25,10 +25,10 @@ $(document).ready(function() {
}
},
formatResult: function(taxon) {
- return taxon.name
+ return taxon.pretty_name
},
formatSelection: function(taxon) {
- return taxon.name
+ return taxon.pretty_name
}
})
})
From 68b70195e6627f07b50d0e368134def3685c01f4 Mon Sep 17 00:00:00 2001
From: Stephane Bounmy
Date: Thu, 1 Nov 2012 21:54:05 +0100
Subject: [PATCH 306/346] orders should only display variant text on
order_details page
Fixes #2170
---
core/app/views/spree/shared/_order_details.html.erb | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/core/app/views/spree/shared/_order_details.html.erb b/core/app/views/spree/shared/_order_details.html.erb
index 80a387f347d..97a7aab6e17 100644
--- a/core/app/views/spree/shared/_order_details.html.erb
+++ b/core/app/views/spree/shared/_order_details.html.erb
@@ -1,5 +1,5 @@
-
+
<% if order.has_step?("address") %>
<%= t(:shipping_address) %> <%= link_to "(#{t(:edit)})", checkout_state_path(:address) unless @order.completed? %>
@@ -75,7 +75,7 @@
<%= item.variant.product.name %>
<%= truncate(item.variant.product.description, :length => 100, :omission => "...") %>
- <%= "(" + variant_options(item.variant) + ")" unless item.variant .option_values.empty? %>
+ <%= "(" + item.variant.options_text + ")" unless item.variant.option_values.empty? %>
<%= money item.price %>
<%= item.quantity %>
From b37892c7305fe970599f900c9de207a9dc3a0f1e Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Mon, 5 Nov 2012 11:53:39 +1100
Subject: [PATCH 307/346] Add patience to admin/configuration/states_spec
---
core/spec/requests/admin/configuration/states_spec.rb | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/core/spec/requests/admin/configuration/states_spec.rb b/core/spec/requests/admin/configuration/states_spec.rb
index 56d4d0cd483..63938f3e8b9 100644
--- a/core/spec/requests/admin/configuration/states_spec.rb
+++ b/core/spec/requests/admin/configuration/states_spec.rb
@@ -37,7 +37,12 @@
it "should show validation errors", :js => true do
click_link "States"
select country.name, :from => "country"
+
+ wait_until do
+ page.should have_selector("#new_state_link", :visible => true)
+ end
click_link "new_state_link"
+
fill_in "state_name", :with => ""
fill_in "Abbreviation", :with => ""
click_button "Create"
From 5b90824a9e7498a2f133bc03206c630d9c2521b6 Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Mon, 5 Nov 2012 11:53:53 +1100
Subject: [PATCH 308/346] no need for 1.9.2 statement inside gc_hacks anymore
---
core/spec/support/gc_hacks.rb | 14 ++++++--------
1 file changed, 6 insertions(+), 8 deletions(-)
diff --git a/core/spec/support/gc_hacks.rb b/core/spec/support/gc_hacks.rb
index 5fe23567cb5..20604e3021e 100644
--- a/core/spec/support/gc_hacks.rb
+++ b/core/spec/support/gc_hacks.rb
@@ -2,14 +2,12 @@
counter = -1
RSpec.configure do |config|
config.after(:each) do
- unless RUBY_VERSION =~ /1\.9\.2/
- counter += 1
- if counter > 9
- GC.enable
- GC.start
- GC.disable
- counter = 0
- end
+ counter += 1
+ if counter > 9
+ GC.enable
+ GC.start
+ GC.disable
+ counter = 0
end
end
From 96d1e17a463938c755ad94b198a06745ac2e2a21 Mon Sep 17 00:00:00 2001
From: Brian Quinn
Date: Mon, 5 Nov 2012 14:37:22 +0000
Subject: [PATCH 309/346] Only show eligible adjustment in admin order edit
view
---
core/app/views/spree/admin/orders/_form.html.erb | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/core/app/views/spree/admin/orders/_form.html.erb b/core/app/views/spree/admin/orders/_form.html.erb
index 88529f29650..9236133c465 100644
--- a/core/app/views/spree/admin/orders/_form.html.erb
+++ b/core/app/views/spree/admin/orders/_form.html.erb
@@ -26,7 +26,7 @@
- <% @order.adjustments.each do |adjustment| %>
+ <% @order.adjustments.eligible.each do |adjustment| %>
<%= adjustment.label %>
<%= adjustment.display_amount %>
From 913e7cac59440608a8c7e051596207a1383fbb8e Mon Sep 17 00:00:00 2001
From: Sean Schofield
Date: Mon, 5 Nov 2012 19:33:52 -0500
Subject: [PATCH 310/346] Remove 1.8.7 support in travis
Since we're having intermittent failures with Travis and 1.8.7 we should just strike this for now.
---
.travis.yml | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/.travis.yml b/.travis.yml
index de58f065982..241ead6f1c8 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -22,5 +22,4 @@ notifications:
channels:
- "irc.freenode.org#spree"
rvm:
- - 1.8.7
- - 1.9.3
+ - 1.9.3
\ No newline at end of file
From 194ccdb7cc62baa2f24020cfb5f4caf42147bb20 Mon Sep 17 00:00:00 2001
From: John Dyer
Date: Tue, 6 Nov 2012 17:32:12 -0500
Subject: [PATCH 311/346] [Fixes #2184] CreditCard number is no longer blank
when processing payments. Thanks to @liufengyun for the solution
---
core/app/models/spree/order.rb | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/core/app/models/spree/order.rb b/core/app/models/spree/order.rb
index 5fc84a3dba1..4e42c3d1941 100644
--- a/core/app/models/spree/order.rb
+++ b/core/app/models/spree/order.rb
@@ -435,7 +435,7 @@ def payment_method
end
def pending_payments
- payments.with_state('checkout')
+ payments.select {|p| p.state == "checkout"}
end
def process_payments!
From 11586897c86821c7e9b6cf5d688013af63f47120 Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Wed, 7 Nov 2012 09:52:30 +1100
Subject: [PATCH 312/346] Explicitly set Spree::CreditCard table name within
spree/payments.rb
Fixes #2130
---
sample/db/sample/spree/payments.rb | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/sample/db/sample/spree/payments.rb b/sample/db/sample/spree/payments.rb
index b07cb687e0d..f0f27c2a0d9 100644
--- a/sample/db/sample/spree/payments.rb
+++ b/sample/db/sample/spree/payments.rb
@@ -8,6 +8,10 @@ def self.current
end
end
+# This table was previously called spree_creditcards, and older migrations
+# reference it as such. Make it explicit here that this table has been renamed.
+Spree::CreditCard.table_name = 'spree_credit_cards'
+
creditcard = Spree::CreditCard.create({ :cc_type => 'visa', :month => 12, :year => 2014, :last_digits => '1111',
:first_name => 'Sean', :last_name => 'Schofield',
:gateway_customer_profile_id => 'BGS-1234' }, :without_protection => true)
From 3375f53ca14eb1706aba85962225561058465e68 Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Wed, 7 Nov 2012 09:57:59 +1100
Subject: [PATCH 313/346] Remove check for with_state call in order_spec
Related to #2184
---
core/spec/models/order_spec.rb | 1 -
1 file changed, 1 deletion(-)
diff --git a/core/spec/models/order_spec.rb b/core/spec/models/order_spec.rb
index cb978cbe5d0..a1ba8104710 100644
--- a/core/spec/models/order_spec.rb
+++ b/core/spec/models/order_spec.rb
@@ -136,7 +136,6 @@ def compute(computable)
payment = stub_model(Spree::Payment)
payments = [payment]
order.stub(:payments).and_return(payments)
- payments.should_receive(:with_state).with('checkout').and_return(payments)
payments.first.should_receive(:process!)
order.process_payments!
end
From 3d1733ed788821c70b880aa2eb53af655c889ab8 Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Wed, 7 Nov 2012 11:34:45 +1100
Subject: [PATCH 314/346] Remove gc_hacks file
The 'hacks' in this file were causing the GC for Ruby to be disabled, which was causing memory to balloon out of control when running the tests. Without this file, memory consumption is normal.
Proof: https://gist.github.com/4028714
---
core/spec/support/gc_hacks.rb | 17 -----------------
1 file changed, 17 deletions(-)
delete mode 100644 core/spec/support/gc_hacks.rb
diff --git a/core/spec/support/gc_hacks.rb b/core/spec/support/gc_hacks.rb
deleted file mode 100644
index 20604e3021e..00000000000
--- a/core/spec/support/gc_hacks.rb
+++ /dev/null
@@ -1,17 +0,0 @@
-# From: http://www.rubyinside.com/careful-cutting-to-get-faster-rspec-runs-with-rails-5207.html
-counter = -1
-RSpec.configure do |config|
- config.after(:each) do
- counter += 1
- if counter > 9
- GC.enable
- GC.start
- GC.disable
- counter = 0
- end
- end
-
- config.after(:suite) do
- counter = 0
- end
-end
From df570d0462ea20267f9385acbfe6a4ca9f03ed4a Mon Sep 17 00:00:00 2001
From: Andrew Hooker
Date: Tue, 30 Oct 2012 13:41:55 -0500
Subject: [PATCH 315/346] Adding return authorization API
Closes #2163
---
.../v1/return_authorizations_controller.rb | 51 +++++++++
api/app/helpers/spree/api/api_helpers.rb | 4 +
.../api/v1/return_authorizations/index.rabl | 2 +
.../api/v1/return_authorizations/new.rabl | 3 +
.../api/v1/return_authorizations/show.rabl | 2 +
api/config/routes.rb | 1 +
.../return_authorizations_controller_spec.rb | 105 ++++++++++++++++++
7 files changed, 168 insertions(+)
create mode 100644 api/app/controllers/spree/api/v1/return_authorizations_controller.rb
create mode 100644 api/app/views/spree/api/v1/return_authorizations/index.rabl
create mode 100644 api/app/views/spree/api/v1/return_authorizations/new.rabl
create mode 100644 api/app/views/spree/api/v1/return_authorizations/show.rabl
create mode 100644 api/spec/controllers/spree/api/v1/return_authorizations_controller_spec.rb
diff --git a/api/app/controllers/spree/api/v1/return_authorizations_controller.rb b/api/app/controllers/spree/api/v1/return_authorizations_controller.rb
new file mode 100644
index 00000000000..e5e1eb23d93
--- /dev/null
+++ b/api/app/controllers/spree/api/v1/return_authorizations_controller.rb
@@ -0,0 +1,51 @@
+module Spree
+ module Api
+ module V1
+ class ReturnAuthorizationsController < Spree::Api::V1::BaseController
+
+ def index
+ authorize! :read, order
+ @return_authorizations = order.return_authorizations
+ end
+
+ def show
+ authorize! :read, order
+ @return_authorization = order.return_authorizations.find(params[:id])
+ end
+
+ def create
+ authorize! :read, order
+ @return_authorization = order.return_authorizations.build(params[:return_authorization], :as => :api)
+ if @return_authorization.save
+ render :show, :status => 201
+ else
+ invalid_resource!(@return_authorization)
+ end
+ end
+
+ def update
+ authorize! :read, order
+ @return_authorization = order.return_authorizations.find(params[:id])
+ if @return_authorization.update_attributes(params[:return_authorization])
+ render :show
+ else
+ invalid_resource!(@return_authorization)
+ end
+ end
+
+ def destroy
+ authorize! :read, order
+ @return_authorization = order.return_authorizations.find(params[:id])
+ @return_authorization.destroy
+ render :text => nil, :status => 204
+ end
+
+ private
+
+ def order
+ @order ||= Order.find_by_number!(params[:order_id])
+ end
+ end
+ end
+ end
+end
diff --git a/api/app/helpers/spree/api/api_helpers.rb b/api/app/helpers/spree/api/api_helpers.rb
index 51d97b8a1fa..2e83d403562 100644
--- a/api/app/helpers/spree/api/api_helpers.rb
+++ b/api/app/helpers/spree/api/api_helpers.rb
@@ -63,6 +63,10 @@ def taxonomy_attributes
def taxon_attributes
[:id, :name, :permalink, :position, :parent_id, :taxonomy_id]
end
+
+ def return_authorization_attributes
+ [:id, :number, :state, :amount, :order_id, :reason, :created_at, :updated_at]
+ end
end
end
end
diff --git a/api/app/views/spree/api/v1/return_authorizations/index.rabl b/api/app/views/spree/api/v1/return_authorizations/index.rabl
new file mode 100644
index 00000000000..5754986c2cc
--- /dev/null
+++ b/api/app/views/spree/api/v1/return_authorizations/index.rabl
@@ -0,0 +1,2 @@
+collection @return_authorizations => :return_authorizations
+attributes *return_authorization_attributes
diff --git a/api/app/views/spree/api/v1/return_authorizations/new.rabl b/api/app/views/spree/api/v1/return_authorizations/new.rabl
new file mode 100644
index 00000000000..362fa8ac9de
--- /dev/null
+++ b/api/app/views/spree/api/v1/return_authorizations/new.rabl
@@ -0,0 +1,3 @@
+object false
+node(:attributes) { [*return_authorization_attributes] }
+node(:required_attributes) { required_fields_for(Spree::ReturnAuthorization) }
diff --git a/api/app/views/spree/api/v1/return_authorizations/show.rabl b/api/app/views/spree/api/v1/return_authorizations/show.rabl
new file mode 100644
index 00000000000..00b07a3b1c2
--- /dev/null
+++ b/api/app/views/spree/api/v1/return_authorizations/show.rabl
@@ -0,0 +1,2 @@
+object @return_authorization
+attributes *return_authorization_attributes
\ No newline at end of file
diff --git a/api/config/routes.rb b/api/config/routes.rb
index 5e36fc901eb..2de6f221d6b 100644
--- a/api/config/routes.rb
+++ b/api/config/routes.rb
@@ -24,6 +24,7 @@
end
resources :orders do
+ resources :return_authorizations
collection do
get :search
end
diff --git a/api/spec/controllers/spree/api/v1/return_authorizations_controller_spec.rb b/api/spec/controllers/spree/api/v1/return_authorizations_controller_spec.rb
new file mode 100644
index 00000000000..d7e3c7cee1e
--- /dev/null
+++ b/api/spec/controllers/spree/api/v1/return_authorizations_controller_spec.rb
@@ -0,0 +1,105 @@
+require 'spec_helper'
+
+module Spree
+ describe Api::V1::ReturnAuthorizationsController do
+ render_views
+
+ let!(:order) do
+ order = create(:order)
+ order.line_items << create(:line_item)
+ order.shipments << create(:shipment, :state => 'shipped')
+ order.finalize!
+ order.shipments.each(&:ready!)
+ order.shipments.each(&:ship!)
+ order
+ end
+
+ let(:product) { create(:product) }
+ let(:attributes) { [:id, :reason, :amount, :state] }
+ let(:resource_scoping) { { :order_id => order.to_param } }
+
+ before do
+ stub_authentication!
+ end
+
+ it "can learn how to create a new return authorization" do
+ api_get :new
+ json_response["attributes"].should == ["id", "number", "state", "amount", "order_id", "reason", "created_at", "updated_at"]
+ required_attributes = json_response["required_attributes"]
+ required_attributes.should include("order")
+ end
+
+ context "as the order owner" do
+ before do
+ Order.any_instance.stub :user => current_api_user
+ end
+
+ it "can add a new return authorization to an existing order" do
+ api_post :create, :return_autorization => { :order_id => order.id, :amount => 14.22, :reason => "Defective" }
+ response.status.should == 201
+ json_response.should have_attributes(attributes)
+ json_response["return_authorization"]["state"].should_not be_blank
+ end
+
+ it "can show return authorization" do
+ order.return_authorizations << create(:return_authorization)
+ return_authorization = order.return_authorizations.first
+ api_get :show, :order_id => order.id, :id => return_authorization.id
+ response.status.should == 200
+ json_response.should have_attributes(attributes)
+ json_response["return_authorization"]["state"].should_not be_blank
+ end
+
+ it "can get a list of return authorization" do
+ order.return_authorizations << create(:return_authorization)
+ order.return_authorizations << create(:return_authorization)
+ return_authorizations = order.return_authorizations
+ api_get :index, { :order_id => order.id }
+ response.status.should == 200
+ return_authorizations = json_response["return_authorizations"]
+ return_authorizations.first.should have_attributes(attributes)
+ return_authorizations.first.should_not == return_authorizations.last
+ end
+
+ it "can update a return authorization on the order" do
+ order.return_authorizations << create(:return_authorization)
+ return_authorization = order.return_authorizations.first
+ api_put :update, :id => return_authorization.id, :return_authorization => { :amount => 19.99 }
+ response.status.should == 200
+ json_response.should have_attributes(attributes)
+ end
+
+ it "can delete a return authorization on the order" do
+ order.return_authorizations << create(:return_authorization)
+ return_authorization = order.return_authorizations.first
+ api_delete :destroy, :id => return_authorization.id
+ response.status.should == 204
+ lambda { return_authorization.reload }.should raise_error(ActiveRecord::RecordNotFound)
+ end
+ end
+
+ context "as just another user" do
+ it "cannot add a return authorization to the order" do
+ api_post :create, :return_autorization => { :order_id => order.id, :amount => 14.22, :reason => "Defective" }
+ assert_unauthorized!
+ end
+
+ it "cannot update a return authorization on the order" do
+ order.return_authorizations << create(:return_authorization)
+ return_authorization = order.return_authorizations.first
+ api_put :update, :id => return_authorization.id, :return_authorization => { :amount => 19.99 }
+ assert_unauthorized!
+ return_authorization.reload.amount.should_not == 19.99
+ end
+
+ it "cannot delete a return authorization on the order" do
+ order.return_authorizations << create(:return_authorization)
+ return_authorization = order.return_authorizations.first
+ api_delete :destroy, :id => return_authorization.id
+ assert_unauthorized!
+ lambda { return_authorization.reload }.should_not raise_error(ActiveRecord::RecordNotFound)
+ end
+ end
+
+ end
+end
From 58aac9daea230e011e9652109a44c464c7a32050 Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Wed, 7 Nov 2012 12:21:49 +1100
Subject: [PATCH 316/346] Restrict admin-y actions on return authorizations to
just admins
Related to #2163
---
.../v1/return_authorizations_controller.rb | 11 +++-
.../return_authorizations_controller_spec.rb | 55 ++++++++++++++-----
2 files changed, 48 insertions(+), 18 deletions(-)
diff --git a/api/app/controllers/spree/api/v1/return_authorizations_controller.rb b/api/app/controllers/spree/api/v1/return_authorizations_controller.rb
index e5e1eb23d93..1b37e4fe19a 100644
--- a/api/app/controllers/spree/api/v1/return_authorizations_controller.rb
+++ b/api/app/controllers/spree/api/v1/return_authorizations_controller.rb
@@ -13,8 +13,12 @@ def show
@return_authorization = order.return_authorizations.find(params[:id])
end
+ def new
+ authorize! :admin, order
+ end
+
def create
- authorize! :read, order
+ authorize! :manage, Spree::Order
@return_authorization = order.return_authorizations.build(params[:return_authorization], :as => :api)
if @return_authorization.save
render :show, :status => 201
@@ -24,7 +28,7 @@ def create
end
def update
- authorize! :read, order
+ authorize! :manage, Spree::Order
@return_authorization = order.return_authorizations.find(params[:id])
if @return_authorization.update_attributes(params[:return_authorization])
render :show
@@ -34,7 +38,8 @@ def update
end
def destroy
- authorize! :read, order
+ authorize! :manage, Spree::Order
+ @return_authorization = order.return_authorizations.find(params[:id])
@return_authorization = order.return_authorizations.find(params[:id])
@return_authorization.destroy
render :text => nil, :status => 204
diff --git a/api/spec/controllers/spree/api/v1/return_authorizations_controller_spec.rb b/api/spec/controllers/spree/api/v1/return_authorizations_controller_spec.rb
index d7e3c7cee1e..39598f6bd76 100644
--- a/api/spec/controllers/spree/api/v1/return_authorizations_controller_spec.rb
+++ b/api/spec/controllers/spree/api/v1/return_authorizations_controller_spec.rb
@@ -22,25 +22,11 @@ module Spree
stub_authentication!
end
- it "can learn how to create a new return authorization" do
- api_get :new
- json_response["attributes"].should == ["id", "number", "state", "amount", "order_id", "reason", "created_at", "updated_at"]
- required_attributes = json_response["required_attributes"]
- required_attributes.should include("order")
- end
-
context "as the order owner" do
before do
Order.any_instance.stub :user => current_api_user
end
- it "can add a new return authorization to an existing order" do
- api_post :create, :return_autorization => { :order_id => order.id, :amount => 14.22, :reason => "Defective" }
- response.status.should == 201
- json_response.should have_attributes(attributes)
- json_response["return_authorization"]["state"].should_not be_blank
- end
-
it "can show return authorization" do
order.return_authorizations << create(:return_authorization)
return_authorization = order.return_authorizations.first
@@ -50,7 +36,7 @@ module Spree
json_response["return_authorization"]["state"].should_not be_blank
end
- it "can get a list of return authorization" do
+ it "can get a list of return authorizations" do
order.return_authorizations << create(:return_authorization)
order.return_authorizations << create(:return_authorization)
return_authorizations = order.return_authorizations
@@ -61,6 +47,37 @@ module Spree
return_authorizations.first.should_not == return_authorizations.last
end
+ it "cannot learn how to create a new return authorization" do
+ api_get :new
+ assert_unauthorized!
+ end
+
+ it "cannot create a new return authorization" do
+ api_post :create
+ assert_unauthorized!
+ end
+
+ it "cannot update a return authorization" do
+ api_put :update
+ assert_unauthorized!
+ end
+
+ it "cannot delete a return authorization" do
+ api_delete :destroy
+ assert_unauthorized!
+ end
+ end
+
+ context "as an admin" do
+ sign_in_as_admin!
+
+ it "can learn how to create a new return authorization" do
+ api_get :new
+ json_response["attributes"].should == ["id", "number", "state", "amount", "order_id", "reason", "created_at", "updated_at"]
+ required_attributes = json_response["required_attributes"]
+ required_attributes.should include("order")
+ end
+
it "can update a return authorization on the order" do
order.return_authorizations << create(:return_authorization)
return_authorization = order.return_authorizations.first
@@ -76,6 +93,14 @@ module Spree
response.status.should == 204
lambda { return_authorization.reload }.should raise_error(ActiveRecord::RecordNotFound)
end
+
+ it "can add a new return authorization to an existing order" do
+ api_post :create, :return_autorization => { :order_id => order.id, :amount => 14.22, :reason => "Defective" }
+ response.status.should == 201
+ json_response.should have_attributes(attributes)
+ json_response["return_authorization"]["state"].should_not be_blank
+ end
+
end
context "as just another user" do
From 23fa86aa6b27304193dc2118bfbfc924ce5bc348 Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Wed, 7 Nov 2012 13:45:37 +1100
Subject: [PATCH 317/346] [api] Restrict all return authorization actions
Relates to #2163
---
.../v1/return_authorizations_controller.rb | 15 +++----
.../return_authorizations_controller_spec.rb | 44 +++++++++++--------
2 files changed, 31 insertions(+), 28 deletions(-)
diff --git a/api/app/controllers/spree/api/v1/return_authorizations_controller.rb b/api/app/controllers/spree/api/v1/return_authorizations_controller.rb
index 1b37e4fe19a..0b1bc5c4608 100644
--- a/api/app/controllers/spree/api/v1/return_authorizations_controller.rb
+++ b/api/app/controllers/spree/api/v1/return_authorizations_controller.rb
@@ -2,23 +2,17 @@ module Spree
module Api
module V1
class ReturnAuthorizationsController < Spree::Api::V1::BaseController
+ before_filter :authorize_admin!
def index
- authorize! :read, order
@return_authorizations = order.return_authorizations
end
def show
- authorize! :read, order
@return_authorization = order.return_authorizations.find(params[:id])
end
- def new
- authorize! :admin, order
- end
-
def create
- authorize! :manage, Spree::Order
@return_authorization = order.return_authorizations.build(params[:return_authorization], :as => :api)
if @return_authorization.save
render :show, :status => 201
@@ -28,7 +22,6 @@ def create
end
def update
- authorize! :manage, Spree::Order
@return_authorization = order.return_authorizations.find(params[:id])
if @return_authorization.update_attributes(params[:return_authorization])
render :show
@@ -38,8 +31,6 @@ def update
end
def destroy
- authorize! :manage, Spree::Order
- @return_authorization = order.return_authorizations.find(params[:id])
@return_authorization = order.return_authorizations.find(params[:id])
@return_authorization.destroy
render :text => nil, :status => 204
@@ -50,6 +41,10 @@ def destroy
def order
@order ||= Order.find_by_number!(params[:order_id])
end
+
+ def authorize_admin!
+ authorize! :manage, Spree::ReturnAuthorization
+ end
end
end
end
diff --git a/api/spec/controllers/spree/api/v1/return_authorizations_controller_spec.rb b/api/spec/controllers/spree/api/v1/return_authorizations_controller_spec.rb
index 39598f6bd76..3797aa75897 100644
--- a/api/spec/controllers/spree/api/v1/return_authorizations_controller_spec.rb
+++ b/api/spec/controllers/spree/api/v1/return_authorizations_controller_spec.rb
@@ -27,24 +27,14 @@ module Spree
Order.any_instance.stub :user => current_api_user
end
- it "can show return authorization" do
- order.return_authorizations << create(:return_authorization)
- return_authorization = order.return_authorizations.first
- api_get :show, :order_id => order.id, :id => return_authorization.id
- response.status.should == 200
- json_response.should have_attributes(attributes)
- json_response["return_authorization"]["state"].should_not be_blank
+ it "cannot see any return authorizations" do
+ api_get :index
+ assert_unauthorized!
end
- it "can get a list of return authorizations" do
- order.return_authorizations << create(:return_authorization)
- order.return_authorizations << create(:return_authorization)
- return_authorizations = order.return_authorizations
- api_get :index, { :order_id => order.id }
- response.status.should == 200
- return_authorizations = json_response["return_authorizations"]
- return_authorizations.first.should have_attributes(attributes)
- return_authorizations.first.should_not == return_authorizations.last
+ it "cannot see a single return authorization" do
+ api_get :show, :id => 1
+ assert_unauthorized!
end
it "cannot learn how to create a new return authorization" do
@@ -71,6 +61,26 @@ module Spree
context "as an admin" do
sign_in_as_admin!
+ it "can show return authorization" do
+ order.return_authorizations << create(:return_authorization)
+ return_authorization = order.return_authorizations.first
+ api_get :show, :order_id => order.id, :id => return_authorization.id
+ response.status.should == 200
+ json_response.should have_attributes(attributes)
+ json_response["return_authorization"]["state"].should_not be_blank
+ end
+
+ it "can get a list of return authorizations" do
+ order.return_authorizations << create(:return_authorization)
+ order.return_authorizations << create(:return_authorization)
+ return_authorizations = order.return_authorizations
+ api_get :index, { :order_id => order.id }
+ response.status.should == 200
+ return_authorizations = json_response["return_authorizations"]
+ return_authorizations.first.should have_attributes(attributes)
+ return_authorizations.first.should_not == return_authorizations.last
+ end
+
it "can learn how to create a new return authorization" do
api_get :new
json_response["attributes"].should == ["id", "number", "state", "amount", "order_id", "reason", "created_at", "updated_at"]
@@ -100,7 +110,6 @@ module Spree
json_response.should have_attributes(attributes)
json_response["return_authorization"]["state"].should_not be_blank
end
-
end
context "as just another user" do
@@ -125,6 +134,5 @@ module Spree
lambda { return_authorization.reload }.should_not raise_error(ActiveRecord::RecordNotFound)
end
end
-
end
end
From 1e4fb60c6fcb7a5e8da7681b4388fe240c37e539 Mon Sep 17 00:00:00 2001
From: Andrew Hooker
Date: Mon, 5 Nov 2012 16:43:00 -0600
Subject: [PATCH 318/346] Adding Notes about Promo Checkout Controller Override
Fixes #2182
Conflicts:
core/app/controllers/spree/checkout_controller.rb
---
core/app/controllers/spree/checkout_controller.rb | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/core/app/controllers/spree/checkout_controller.rb b/core/app/controllers/spree/checkout_controller.rb
index 53bdf1ea7c7..8b84a821be5 100644
--- a/core/app/controllers/spree/checkout_controller.rb
+++ b/core/app/controllers/spree/checkout_controller.rb
@@ -2,7 +2,12 @@ module Spree
# Handles checkout logic. This is somewhat contrary to standard REST convention since there is not actually a
# Checkout object. There's enough distinct logic specific to checkout which has nothing to do with updating an
# order that this approach is waranted.
- class CheckoutController < BaseController
+ #
+ # Much of this file, especially the update action is overriden in the promo gem.
+ # This is to allow for the promo behavior but also allow the promo gem to be
+ # removed if the functionality is not needed.
+
+ class CheckoutController < Spree::BaseController
ssl_required
before_filter :load_order
@@ -13,6 +18,7 @@ class CheckoutController < BaseController
respond_to :html
# Updates the order and advances to the next state (when possible.)
+ # Overriden by the promo gem if it exists.
def update
if @order.update_attributes(object_params)
fire_event('spree.checkout.update')
From 359c98f93fb409c6e5ba99fc122b0354efbe0000 Mon Sep 17 00:00:00 2001
From: Nicholas Frandsen
Date: Wed, 31 Oct 2012 13:26:26 +0100
Subject: [PATCH 319/346] Refactor out methods to product class that control if
a product is on sale or on display.
Fixes #2167
---
core/app/models/spree/product.rb | 10 +++++++
.../views/spree/products/_cart_form.html.erb | 2 +-
.../app/views/spree/shared/_products.html.erb | 2 +-
core/spec/models/product_spec.rb | 26 +++++++++++++++++++
4 files changed, 38 insertions(+), 2 deletions(-)
diff --git a/core/app/models/spree/product.rb b/core/app/models/spree/product.rb
index 5247e80d09b..4b399c6a1d9 100755
--- a/core/app/models/spree/product.rb
+++ b/core/app/models/spree/product.rb
@@ -99,6 +99,16 @@ def has_variants?
variants.any?
end
+ # should product be displayed on products pages and search
+ def on_display?
+ has_stock? || Spree::Config[:show_zero_stock_products]
+ end
+
+ # is this product actually available for purchase
+ def on_sale?
+ has_stock? || Spree::Config[:allow_backorders]
+ end
+
# returns the number of inventory units "on_hand" for this product
def on_hand
has_variants? ? variants.sum(&:on_hand) : master.on_hand
diff --git a/core/app/views/spree/products/_cart_form.html.erb b/core/app/views/spree/products/_cart_form.html.erb
index 58be77a1523..4dd465faab6 100644
--- a/core/app/views/spree/products/_cart_form.html.erb
+++ b/core/app/views/spree/products/_cart_form.html.erb
@@ -35,7 +35,7 @@
- <% if @product.has_stock? || Spree::Config[:allow_backorders] %>
+ <% if @product.on_sale? %>
<%= number_field_tag (@product.has_variants? ? :quantity : "variants[#{@product.master.id}]"),
1, :class => 'title', :in => 1..@product.on_hand, :min => 1 %>
<%= button_tag :class => 'large primary', :id => 'add-to-cart-button', :type => :submit do %>
diff --git a/core/app/views/spree/shared/_products.html.erb b/core/app/views/spree/shared/_products.html.erb
index aa817d1c37c..b126dcbc01f 100644
--- a/core/app/views/spree/shared/_products.html.erb
+++ b/core/app/views/spree/shared/_products.html.erb
@@ -12,7 +12,7 @@
<% reset_cycle('default') %>
<% products.each do |product| %>
- <% if Spree::Config[:show_zero_stock_products] || product.has_stock? %>
+ <% if product.on_display? %>
"classes") %>" data-hook="products_list_item" itemscope itemtype="http://schema.org/Product">
<%= link_to small_image(product, :itemprop => "image"), product, :itemprop => 'url' %>
diff --git a/core/spec/models/product_spec.rb b/core/spec/models/product_spec.rb
index 9e68a441e30..f990759f5c6 100644
--- a/core/spec/models/product_spec.rb
+++ b/core/spec/models/product_spec.rb
@@ -72,6 +72,32 @@
end
end
+ # Test for #2167
+ context "#on_display?" do
+ it "is on display if product has stock" do
+ product.stub :has_stock? => true
+ assert product.on_display?
+ end
+
+ it "is on display if show_zero_stock_products preference is set to true" do
+ Spree::Config[:show_zero_stock_products] = true
+ assert product.on_display?
+ end
+ end
+
+ # Test for #2167
+ context "#on_sale?" do
+ it "is on sale if the product has stock" do
+ product.stub :has_stock? => true
+ assert product.on_sale?
+ end
+
+ it "is on sale if allow_backorders preference is set to true" do
+ Spree::Config[:allow_backorders] = true
+ assert product.on_sale?
+ end
+ end
+
context "#price" do
# Regression test for #1173
it 'strips non-price characters' do
From 5099d25eb5677d1b629562e68ff1f3d5f50dadc6 Mon Sep 17 00:00:00 2001
From: Michael Bianco
Date: Wed, 7 Nov 2012 13:32:48 -0500
Subject: [PATCH 320/346] Adding promotion usage information to the admin
Fixes #2193
---
promo/app/views/spree/admin/promotions/_form.html.erb | 3 ++-
promo/config/locales/en.yml | 1 +
2 files changed, 3 insertions(+), 1 deletion(-)
diff --git a/promo/app/views/spree/admin/promotions/_form.html.erb b/promo/app/views/spree/admin/promotions/_form.html.erb
index 1d02632691f..e64ffb89e2e 100644
--- a/promo/app/views/spree/admin/promotions/_form.html.erb
+++ b/promo/app/views/spree/admin/promotions/_form.html.erb
@@ -37,7 +37,8 @@
<%= t(:expiry) %>
<%= f.label :usage_limit %>
- <%= f.text_field :usage_limit %>
+ <%= f.text_field :usage_limit %>
+ <%= t(:current_promotion_usage, :count => @promotion.credits_count) %>
diff --git a/promo/config/locales/en.yml b/promo/config/locales/en.yml
index 195aead439e..24e0d3d2576 100644
--- a/promo/config/locales/en.yml
+++ b/promo/config/locales/en.yml
@@ -18,6 +18,7 @@ en:
coupon_code: Coupon code
coupon_code_applied: The coupon code was successfully applied to your order.
editing_promotion: Editing Promotion
+ current_promotion_usage: 'Current Usage: %{count}'
events:
spree:
checkout:
From 07f22d90c1c34e64ffde2f05f796a388e9a38b9e Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Thu, 8 Nov 2012 15:57:59 +1100
Subject: [PATCH 321/346] stub has_available_shipment calls in tests
This method is caused unwanted side-effects
Related to #2191
---
core/spec/models/order/state_machine_spec.rb | 9 +++++++++
core/spec/models/order_spec.rb | 4 ++++
2 files changed, 13 insertions(+)
diff --git a/core/spec/models/order/state_machine_spec.rb b/core/spec/models/order/state_machine_spec.rb
index 782538f2f18..e5c3781cb93 100644
--- a/core/spec/models/order/state_machine_spec.rb
+++ b/core/spec/models/order/state_machine_spec.rb
@@ -122,6 +122,8 @@
end
it "should send a cancel email" do
+ # Stub methods that cause side-effects in this test
+ order.stub :has_available_shipment
order.stub :restock_items!
mail_message = mock "Mail::Message"
Spree::OrderMailer.should_receive(:cancel_email).with(order).and_return mail_message
@@ -135,6 +137,8 @@
shipment.stub(:update_order)
Spree::OrderMailer.stub(:cancel_email).and_return(mail_message = stub)
mail_message.stub :deliver
+
+ order.stub :has_available_shipment
end
# Regression fix for #729
@@ -147,8 +151,10 @@
context "resets payment state" do
before do
# TODO: This is ugly :(
+ # Stubs methods that cause unwanted side effects in this test
Spree::OrderMailer.stub(:cancel_email).and_return(mail_message = stub)
mail_message.stub :deliver
+ order.stub :has_available_shipment
end
context "without shipped items" do
@@ -180,6 +186,9 @@
order.stub :email => "user@spreecommerce.com"
order.stub :state => "canceled"
order.stub :allow_resume? => true
+
+ # Stubs method that cause unwanted side effects in this test
+ order.stub :has_available_shipment
end
it "should send a resume email" do
diff --git a/core/spec/models/order_spec.rb b/core/spec/models/order_spec.rb
index a1ba8104710..ec15dfa3aea 100644
--- a/core/spec/models/order_spec.rb
+++ b/core/spec/models/order_spec.rb
@@ -115,6 +115,10 @@ def compute(computable)
end
it "should freeze all adjustments" do
+ # Stub this method as it's called due to a callback
+ # and it's irrelevant to this test
+ order.stub :has_available_shipment
+
Spree::OrderMailer.stub_chain :confirm_email, :deliver
adjustment1 = mock_model(Spree::Adjustment, :mandatory => true)
adjustment2 = mock_model(Spree::Adjustment, :mandatory => false)
From b9915d0616cc9bd80661f2ba0fa84d954e870aab Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Thu, 8 Nov 2012 15:57:59 +1100
Subject: [PATCH 322/346] stub has_available_shipment calls in tests
This method is caused unwanted side-effects
Related to #2191
Conflicts:
core/spec/models/order/state_machine_spec.rb
---
core/spec/models/order/state_machine_spec.rb | 6 ------
1 file changed, 6 deletions(-)
diff --git a/core/spec/models/order/state_machine_spec.rb b/core/spec/models/order/state_machine_spec.rb
index e5c3781cb93..f1efdbe0971 100644
--- a/core/spec/models/order/state_machine_spec.rb
+++ b/core/spec/models/order/state_machine_spec.rb
@@ -191,12 +191,6 @@
order.stub :has_available_shipment
end
- it "should send a resume email" do
- pending "Pending test for #818"
- order.stub :unstock_items!
- order.resume!
- end
-
context "unstocks inventory" do
let(:variant) { stub_model(Spree::Variant) }
From 6a8737873621a7f19ce9a1995aa72158118d93a7 Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Thu, 8 Nov 2012 15:16:46 +1100
Subject: [PATCH 323/346] update totals before checking if payment is required
Fixes #2191
---
core/app/models/spree/order.rb | 1 +
core/spec/models/order_spec.rb | 18 ++++++++++++++++++
2 files changed, 19 insertions(+)
diff --git a/core/app/models/spree/order.rb b/core/app/models/spree/order.rb
index 4e42c3d1941..c1385ac8317 100644
--- a/core/app/models/spree/order.rb
+++ b/core/app/models/spree/order.rb
@@ -127,6 +127,7 @@ def checkout_allowed?
# Is this a free order in which case the payment step should be skipped
def payment_required?
+ Spree::OrderUpdater.new(self).update_totals
total.to_f > 0.0
end
diff --git a/core/spec/models/order_spec.rb b/core/spec/models/order_spec.rb
index ec15dfa3aea..76916c6dd8c 100644
--- a/core/spec/models/order_spec.rb
+++ b/core/spec/models/order_spec.rb
@@ -598,4 +598,22 @@ def compute(computable)
end
end
end
+
+ # Regression test for #2191
+ context "when an order has an adjustment that zeroes the total, but another adjustment for shipping that raises it above zero" do
+ let!(:persisted_order) { create(:order) }
+ let!(:line_item) { create(:line_item) }
+ let!(:shipping_method) { create(:shipping_method) }
+
+ before do
+ persisted_order.line_items << line_item
+ persisted_order.adjustments.create(:amount => 19.99, :label => "Promotion")
+ persisted_order.state = 'delivery'
+ end
+
+ it "transitions from delivery to payment" do
+ persisted_order.shipping_method = shipping_method
+ persisted_order.next_transition.to.should == "payment"
+ end
+ end
end
From 93e6edeef635ee8ae793a6202fd150937f955de0 Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Thu, 8 Nov 2012 16:48:33 +1100
Subject: [PATCH 324/346] Directly call update_totals in payment_required?
method
---
core/app/models/spree/order.rb | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/core/app/models/spree/order.rb b/core/app/models/spree/order.rb
index c1385ac8317..86d300d615e 100644
--- a/core/app/models/spree/order.rb
+++ b/core/app/models/spree/order.rb
@@ -127,7 +127,7 @@ def checkout_allowed?
# Is this a free order in which case the payment step should be skipped
def payment_required?
- Spree::OrderUpdater.new(self).update_totals
+ update_totals
total.to_f > 0.0
end
From 74c0423bb0a1680bf8d09d47d249ad926b06c367 Mon Sep 17 00:00:00 2001
From: John Dyer
Date: Thu, 8 Nov 2012 10:24:48 -0500
Subject: [PATCH 325/346] Various API improvements.
* Merge search/index actions of API's OrderController
* Add searching ability to API's CountriesController
* Allow pages and per_page parameters to be passed to Countries
* Add count node to payments index action
* Allow pages and per_page parameters to be passed to Payments
* Add searching ability to API's PaymentsController
* Allow pages and per_page parameters to be passed to ProductProperties
* Add searching ability to API's ProductPropertiesController
* Merge search/index actions of API's ProductsController
* Allow per_page parameter to be passed to Products
* Add search and allow per_page parameter to be passed to ReturnAuthorizations
* Allow pages and per_page parameters to be passed to Taxonomies
* Add searching ability to API's TaxonomiesController
* Add search and allow per_page parameter to be passed to Variants
* Allow pages and per_page parameter to be passed to API's Zones
* Add searching ability to API's ZonesController
Closes #2198
---
.../spree/api/v1/countries_controller.rb | 3 ++-
.../spree/api/v1/orders_controller.rb | 7 +----
.../spree/api/v1/payments_controller.rb | 2 +-
.../api/v1/product_properties_controller.rb | 3 ++-
.../spree/api/v1/products_controller.rb | 7 +----
.../v1/return_authorizations_controller.rb | 3 ++-
.../spree/api/v1/taxonomies_controller.rb | 3 ++-
.../spree/api/v1/variants_controller.rb | 3 ++-
.../spree/api/v1/zones_controller.rb | 2 +-
api/app/helpers/spree/api/api_helpers.rb | 4 +++
.../views/spree/api/v1/countries/index.rabl | 9 +++++--
.../views/spree/api/v1/countries/show.rabl | 4 +--
.../views/spree/api/v1/payments/index.rabl | 9 +++++--
.../api/v1/product_properties/index.rabl | 11 +++++---
.../views/spree/api/v1/products/index.rabl | 3 ++-
.../api/v1/return_authorizations/index.rabl | 9 +++++--
.../views/spree/api/v1/taxonomies/index.rabl | 9 +++++--
.../views/spree/api/v1/variants/index.rabl | 3 ++-
api/app/views/spree/api/v1/zones/index.rabl | 9 +++++--
api/config/routes.rb | 9 +------
.../spree/api/v1/countries_controller_spec.rb | 26 ++++++++++++++++++-
.../spree/api/v1/orders_controller_spec.rb | 19 ++++++++++++++
.../spree/api/v1/payments_controller_spec.rb | 24 ++++++++++++++++-
.../v1/product_properties_controller_spec.rb | 15 +++++++++++
.../spree/api/v1/products_controller_spec.rb | 13 ++++++++--
.../return_authorizations_controller_spec.rb | 21 +++++++++++++--
.../api/v1/taxonomies_controller_spec.rb | 19 ++++++++++++--
.../spree/api/v1/variants_controller_spec.rb | 17 +++++++++++-
.../spree/api/v1/zones_controller_spec.rb | 19 ++++++++++++--
29 files changed, 229 insertions(+), 56 deletions(-)
diff --git a/api/app/controllers/spree/api/v1/countries_controller.rb b/api/app/controllers/spree/api/v1/countries_controller.rb
index 8435596d5a1..8252b3bbabe 100644
--- a/api/app/controllers/spree/api/v1/countries_controller.rb
+++ b/api/app/controllers/spree/api/v1/countries_controller.rb
@@ -3,7 +3,8 @@ module Api
module V1
class CountriesController < Spree::Api::V1::BaseController
def index
- @countries = Country.includes(:states).order('name ASC')
+ @countries = Country.ransack(params[:q]).result.includes(:states).order('name ASC')
+ .page(params[:page]).per(params[:per_page])
end
def show
diff --git a/api/app/controllers/spree/api/v1/orders_controller.rb b/api/app/controllers/spree/api/v1/orders_controller.rb
index d20e5421863..55ea57d2f95 100644
--- a/api/app/controllers/spree/api/v1/orders_controller.rb
+++ b/api/app/controllers/spree/api/v1/orders_controller.rb
@@ -7,17 +7,12 @@ class OrdersController < Spree::Api::V1::BaseController
def index
# should probably look at turning this into a CanCan step
raise CanCan::AccessDenied unless current_api_user.has_spree_role?("admin")
- @orders = Order.page(params[:page]).per(params[:per_page])
+ @orders = Order.ransack(params[:q]).result.page(params[:page]).per(params[:per_page])
end
def show
end
- def search
- @orders = Order.ransack(params[:q]).result.page(params[:page])
- render :index
- end
-
def create
@order = Order.build_from_api(current_api_user, nested_params)
next!(:status => 201)
diff --git a/api/app/controllers/spree/api/v1/payments_controller.rb b/api/app/controllers/spree/api/v1/payments_controller.rb
index 73a219e88db..8b14446088e 100644
--- a/api/app/controllers/spree/api/v1/payments_controller.rb
+++ b/api/app/controllers/spree/api/v1/payments_controller.rb
@@ -6,7 +6,7 @@ class PaymentsController < Spree::Api::V1::BaseController
before_filter :find_payment, :only => [:show, :authorize, :purchase, :capture, :void, :credit]
def index
- @payments = @order.payments
+ @payments = @order.payments.ransack(params[:q]).result.page(params[:page]).per(params[:per_page])
end
def new
diff --git a/api/app/controllers/spree/api/v1/product_properties_controller.rb b/api/app/controllers/spree/api/v1/product_properties_controller.rb
index 8159292e7b7..f30b5ff793a 100644
--- a/api/app/controllers/spree/api/v1/product_properties_controller.rb
+++ b/api/app/controllers/spree/api/v1/product_properties_controller.rb
@@ -6,7 +6,8 @@ class ProductPropertiesController < Spree::Api::V1::BaseController
before_filter :product_property, :only => [:show, :update, :destroy]
def index
- @product_properties = @product.product_properties
+ @product_properties = @product.product_properties.ransack(params[:q]).result
+ .page(params[:page]).per(params[:per_page])
end
def show
diff --git a/api/app/controllers/spree/api/v1/products_controller.rb b/api/app/controllers/spree/api/v1/products_controller.rb
index ea6bca68ffc..99722e91715 100644
--- a/api/app/controllers/spree/api/v1/products_controller.rb
+++ b/api/app/controllers/spree/api/v1/products_controller.rb
@@ -3,12 +3,7 @@ module Api
module V1
class ProductsController < Spree::Api::V1::BaseController
def index
- @products = product_scope.page(params[:page])
- end
-
- def search
- @products = product_scope.ransack(params[:q]).result.page(params[:page])
- render :index
+ @products = product_scope.ransack(params[:q]).result.page(params[:page]).per(params[:per_page])
end
def show
diff --git a/api/app/controllers/spree/api/v1/return_authorizations_controller.rb b/api/app/controllers/spree/api/v1/return_authorizations_controller.rb
index 0b1bc5c4608..b772ff4a44b 100644
--- a/api/app/controllers/spree/api/v1/return_authorizations_controller.rb
+++ b/api/app/controllers/spree/api/v1/return_authorizations_controller.rb
@@ -5,7 +5,8 @@ class ReturnAuthorizationsController < Spree::Api::V1::BaseController
before_filter :authorize_admin!
def index
- @return_authorizations = order.return_authorizations
+ @return_authorizations = order.return_authorizations.ransack(params[:q]).result
+ .page(params[:page]).per(params[:per_page])
end
def show
diff --git a/api/app/controllers/spree/api/v1/taxonomies_controller.rb b/api/app/controllers/spree/api/v1/taxonomies_controller.rb
index 76d0824f059..b3b7f951986 100644
--- a/api/app/controllers/spree/api/v1/taxonomies_controller.rb
+++ b/api/app/controllers/spree/api/v1/taxonomies_controller.rb
@@ -3,7 +3,8 @@ module Api
module V1
class TaxonomiesController < Spree::Api::V1::BaseController
def index
- @taxonomies = Taxonomy.order('name').includes(:root => :children)
+ @taxonomies = Taxonomy.order('name').includes(:root => :children).ransack(params[:q]).result
+ .page(params[:page]).per(params[:per_page])
end
def show
diff --git a/api/app/controllers/spree/api/v1/variants_controller.rb b/api/app/controllers/spree/api/v1/variants_controller.rb
index ecd3a519964..6890cb729f5 100644
--- a/api/app/controllers/spree/api/v1/variants_controller.rb
+++ b/api/app/controllers/spree/api/v1/variants_controller.rb
@@ -5,7 +5,8 @@ class VariantsController < Spree::Api::V1::BaseController
before_filter :product
def index
- @variants = scope.includes(:option_values).page(params[:page])
+ @variants = scope.includes(:option_values).ransack(params[:q]).result.
+ page(params[:page]).per(params[:per_page])
end
def show
diff --git a/api/app/controllers/spree/api/v1/zones_controller.rb b/api/app/controllers/spree/api/v1/zones_controller.rb
index 142ff7ea318..ec33f4f65db 100644
--- a/api/app/controllers/spree/api/v1/zones_controller.rb
+++ b/api/app/controllers/spree/api/v1/zones_controller.rb
@@ -3,7 +3,7 @@ module Api
module V1
class ZonesController < Spree::Api::V1::BaseController
def index
- @zones = Zone.order('name ASC')
+ @zones = Zone.order('name ASC').ransack(params[:q]).result.page(params[:page]).per(params[:per_page])
end
def show
diff --git a/api/app/helpers/spree/api/api_helpers.rb b/api/app/helpers/spree/api/api_helpers.rb
index 2e83d403562..8cbf5b5784d 100644
--- a/api/app/helpers/spree/api/api_helpers.rb
+++ b/api/app/helpers/spree/api/api_helpers.rb
@@ -67,6 +67,10 @@ def taxon_attributes
def return_authorization_attributes
[:id, :number, :state, :amount, :order_id, :reason, :created_at, :updated_at]
end
+
+ def country_attributes
+ [:id, :iso_name, :iso, :iso3, :name, :numcode]
+ end
end
end
end
diff --git a/api/app/views/spree/api/v1/countries/index.rabl b/api/app/views/spree/api/v1/countries/index.rabl
index cfb3010e608..028c4ad0f3f 100644
--- a/api/app/views/spree/api/v1/countries/index.rabl
+++ b/api/app/views/spree/api/v1/countries/index.rabl
@@ -1,2 +1,7 @@
-collection @countries
-extends "spree/api/v1/countries/show"
\ No newline at end of file
+object false
+child(@countries => :countries) do
+ attributes *country_attributes
+end
+node(:count) { @countries.count }
+node(:current_page) { params[:page] || 1 }
+node(:pages) { @countries.num_pages }
diff --git a/api/app/views/spree/api/v1/countries/show.rabl b/api/app/views/spree/api/v1/countries/show.rabl
index 4e3bf830420..19d4322a9c3 100644
--- a/api/app/views/spree/api/v1/countries/show.rabl
+++ b/api/app/views/spree/api/v1/countries/show.rabl
@@ -1,5 +1,5 @@
object @country
-attributes :id, :iso_name, :iso, :iso3, :name, :numcode
+attributes *country_attributes
child :states => :states do
attributes :id, :name, :abbr, :country_id
-end
\ No newline at end of file
+end
diff --git a/api/app/views/spree/api/v1/payments/index.rabl b/api/app/views/spree/api/v1/payments/index.rabl
index 63c9bb00cdd..f72651a0d53 100644
--- a/api/app/views/spree/api/v1/payments/index.rabl
+++ b/api/app/views/spree/api/v1/payments/index.rabl
@@ -1,2 +1,7 @@
-collection @payments => :payments
-attributes *payment_attributes
+object false
+child(@payments => :payments) do
+ attributes *payment_attributes
+end
+node(:count) { @payments.count }
+node(:current_page) { params[:page] || 1 }
+node(:pages) { @payments.num_pages }
diff --git a/api/app/views/spree/api/v1/product_properties/index.rabl b/api/app/views/spree/api/v1/product_properties/index.rabl
index 7c2c87d8582..3f81a99d7b6 100644
--- a/api/app/views/spree/api/v1/product_properties/index.rabl
+++ b/api/app/views/spree/api/v1/product_properties/index.rabl
@@ -1,4 +1,7 @@
-collection @product_properties => :product_properties
-attributes *product_property_attributes
-
-
+object false
+child(@product_properties => :product_properties) do
+ attributes *product_property_attributes
+end
+node(:count) { @product_properties.count }
+node(:current_page) { params[:page] || 1 }
+node(:pages) { @product_properties.num_pages }
diff --git a/api/app/views/spree/api/v1/products/index.rabl b/api/app/views/spree/api/v1/products/index.rabl
index 8797e5e4f54..54107ca7530 100644
--- a/api/app/views/spree/api/v1/products/index.rabl
+++ b/api/app/views/spree/api/v1/products/index.rabl
@@ -1,5 +1,6 @@
object false
-node(:count) { @products.total_count }
+node(:count) { @products.count }
+node(:total_count) { @products.total_count }
node(:current_page) { params[:page] ? params[:page].to_i : 1 }
node(:pages) { @products.num_pages }
child(@products) do
diff --git a/api/app/views/spree/api/v1/return_authorizations/index.rabl b/api/app/views/spree/api/v1/return_authorizations/index.rabl
index 5754986c2cc..6574912a6d0 100644
--- a/api/app/views/spree/api/v1/return_authorizations/index.rabl
+++ b/api/app/views/spree/api/v1/return_authorizations/index.rabl
@@ -1,2 +1,7 @@
-collection @return_authorizations => :return_authorizations
-attributes *return_authorization_attributes
+object false
+child(@return_authorizations => :return_authorizations) do
+ attributes *return_authorization_attributes
+end
+node(:count) { @return_authorizations.count }
+node(:current_page) { params[:page] || 1 }
+node(:pages) { @return_authorizations.num_pages }
diff --git a/api/app/views/spree/api/v1/taxonomies/index.rabl b/api/app/views/spree/api/v1/taxonomies/index.rabl
index f12f6acd9c3..0a279e048d7 100644
--- a/api/app/views/spree/api/v1/taxonomies/index.rabl
+++ b/api/app/views/spree/api/v1/taxonomies/index.rabl
@@ -1,2 +1,7 @@
-collection @taxonomies
-extends "spree/api/v1/taxonomies/show"
+object false
+child(@taxonomies => :taxonomies) do
+ extends "spree/api/v1/taxonomies/show"
+end
+node(:count) { @taxonomies.count }
+node(:current_page) { params[:page] || 1 }
+node(:pages) { @taxonomies.num_pages }
diff --git a/api/app/views/spree/api/v1/variants/index.rabl b/api/app/views/spree/api/v1/variants/index.rabl
index 0dde8b0bedf..d37c886a2a0 100644
--- a/api/app/views/spree/api/v1/variants/index.rabl
+++ b/api/app/views/spree/api/v1/variants/index.rabl
@@ -1,5 +1,6 @@
object false
-node(:count) { @variants.total_count }
+node(:count) { @variants.count }
+node(:total_count) { @variants.total_count }
node(:current_page) { params[:page] ? params[:page].to_i : 1 }
node(:pages) { @variants.num_pages }
diff --git a/api/app/views/spree/api/v1/zones/index.rabl b/api/app/views/spree/api/v1/zones/index.rabl
index b16039b448b..232ed4e2395 100644
--- a/api/app/views/spree/api/v1/zones/index.rabl
+++ b/api/app/views/spree/api/v1/zones/index.rabl
@@ -1,2 +1,7 @@
-collection @zones
-extends 'spree/api/v1/zones/show'
+object false
+child(@zones => :zones) do
+ extends 'spree/api/v1/zones/show'
+end
+node(:count) { @zones.count }
+node(:current_page) { params[:page] || 1 }
+node(:pages) { @zones.num_pages }
diff --git a/api/config/routes.rb b/api/config/routes.rb
index 2de6f221d6b..4e8685870b1 100644
--- a/api/config/routes.rb
+++ b/api/config/routes.rb
@@ -11,10 +11,6 @@
namespace :api do
scope :module => :v1 do
resources :products do
- collection do
- get :search
- end
-
resources :variants
resources :product_properties
end
@@ -22,12 +18,9 @@
resources :images
resources :variants, :only => [:index] do
end
-
+
resources :orders do
resources :return_authorizations
- collection do
- get :search
- end
member do
put :address
put :delivery
diff --git a/api/spec/controllers/spree/api/v1/countries_controller_spec.rb b/api/spec/controllers/spree/api/v1/countries_controller_spec.rb
index fb198f20393..3493d7e5c1b 100644
--- a/api/spec/controllers/spree/api/v1/countries_controller_spec.rb
+++ b/api/spec/controllers/spree/api/v1/countries_controller_spec.rb
@@ -12,7 +12,31 @@ module Spree
it "gets all countries" do
api_get :index
- json_response.first['country']['iso3'].should eq @country.iso3
+ json_response["countries"].first['country']['iso3'].should eq @country.iso3
+ end
+
+ context "with two countries" do
+ before { @zambia = create(:country, :name => "Zambia") }
+
+ it "can view all countries" do
+ api_get :index
+ json_response['count'].should == 2
+ json_response['current_page'].should == 1
+ json_response['pages'].should == 1
+ end
+
+ it 'can query the results through a paramter' do
+ api_get :index, :q => { :name_cont => 'zam' }
+ json_response['count'].should == 1
+ json_response['countries'].first['country']['name'].should eq @zambia.name
+ end
+
+ it 'can control the page size through a parameter' do
+ api_get :index, :per_page => 1
+ json_response['count'].should == 1
+ json_response['current_page'].should == 1
+ json_response['pages'].should == 2
+ end
end
it "includes states" do
diff --git a/api/spec/controllers/spree/api/v1/orders_controller_spec.rb b/api/spec/controllers/spree/api/v1/orders_controller_spec.rb
index 928ebfe6019..8ae65bf2c54 100644
--- a/api/spec/controllers/spree/api/v1/orders_controller_spec.rb
+++ b/api/spec/controllers/spree/api/v1/orders_controller_spec.rb
@@ -218,6 +218,25 @@ def clean_address(address)
end
end
+ context "search" do
+ before do
+ create(:order)
+ Spree::Order.last.update_attribute(:email, 'spree@spreecommerce.com')
+ end
+
+ let(:expected_result) { Spree::Order.last }
+
+ it "can query the results through a parameter" do
+ api_get :index, :q => { :email_cont => 'spree' }
+ json_response["orders"].count.should == 1
+ json_response["orders"].first.should have_attributes(attributes)
+ json_response["orders"].first["order"]["email"].should == expected_result.email
+ json_response["count"].should == 1
+ json_response["current_page"].should == 1
+ json_response["pages"].should == 1
+ end
+ end
+
context "can cancel an order" do
before do
order.completed_at = Time.now
diff --git a/api/spec/controllers/spree/api/v1/payments_controller_spec.rb b/api/spec/controllers/spree/api/v1/payments_controller_spec.rb
index e1eae06a158..e2ef5589f13 100644
--- a/api/spec/controllers/spree/api/v1/payments_controller_spec.rb
+++ b/api/spec/controllers/spree/api/v1/payments_controller_spec.rb
@@ -6,7 +6,7 @@ module Spree
let!(:order) { create(:order) }
let!(:payment) { create(:payment, :order => order) }
let!(:attributes) { [:id, :source_type, :source_id, :amount,
- :payment_method_id, :response_code, :state, :avs_response,
+ :payment_method_id, :response_code, :state, :avs_response,
:created_at, :updated_at] }
let(:resource_scoping) { { :order_id => order.to_param } }
@@ -70,6 +70,28 @@ module Spree
json_response["payments"].first.should have_attributes(attributes)
end
+ context "multiple payments" do
+ before { @payment = create(:payment, :order => order, :response_code => '99999') }
+
+ it "can view all payments on an order" do
+ api_get :index
+ json_response["count"].should == 2
+ end
+
+ it 'can control the page size through a parameter' do
+ api_get :index, :per_page => 1
+ json_response['count'].should == 1
+ json_response['current_page'].should == 1
+ json_response['pages'].should == 2
+ end
+
+ it 'can query the results through a paramter' do
+ api_get :index, :q => { :response_code_cont => '999' }
+ json_response['count'].should == 1
+ json_response['payments'].first['payment']['response_code'].should eq @payment.response_code
+ end
+ end
+
context "for a given payment" do
it "can authorize" do
diff --git a/api/spec/controllers/spree/api/v1/product_properties_controller_spec.rb b/api/spec/controllers/spree/api/v1/product_properties_controller_spec.rb
index 21378ffdabb..4da171ce53e 100644
--- a/api/spec/controllers/spree/api/v1/product_properties_controller_spec.rb
+++ b/api/spec/controllers/spree/api/v1/product_properties_controller_spec.rb
@@ -33,6 +33,21 @@ module Spree
json_response["product_properties"].first.should have_attributes(attributes)
end
+ it "can control the page size through a parameter" do
+ api_get :index, :per_page => 1
+ json_response['product_properties'].count.should == 1
+ json_response['current_page'].should == 1
+ json_response['pages'].should == 2
+ end
+
+ it 'can query the results through a paramter' do
+ Spree::ProductProperty.last.update_attribute(:value, 'loose')
+ property = Spree::ProductProperty.last
+ api_get :index, :q => { :value_cont => 'loose' }
+ json_response['count'].should == 1
+ json_response['product_properties'].first['product_property']['value'].should eq property.value
+ end
+
it "can see a single product_property" do
api_get :show, :id => property_1.property_name
json_response.should have_attributes(attributes)
diff --git a/api/spec/controllers/spree/api/v1/products_controller_spec.rb b/api/spec/controllers/spree/api/v1/products_controller_spec.rb
index 649f91120ad..5a2d4a735c6 100644
--- a/api/spec/controllers/spree/api/v1/products_controller_spec.rb
+++ b/api/spec/controllers/spree/api/v1/products_controller_spec.rb
@@ -34,15 +34,24 @@ module Spree
second_product = create(:product)
api_get :index, :page => 2
json_response["products"].first.should have_attributes(attributes)
- json_response["count"].should == 2
+ json_response["total_count"].should == 2
json_response["current_page"].should == 2
json_response["pages"].should == 2
end
+
+ it 'can control the page size through a parameter' do
+ create(:product)
+ api_get :index, :per_page => 1
+ json_response['count'].should == 1
+ json_response['total_count'].should == 2
+ json_response['current_page'].should == 1
+ json_response['pages'].should == 2
+ end
end
it "can search for products" do
create(:product, :name => "The best product in the world")
- api_get :search, :q => { :name_cont => "best" }
+ api_get :index, :q => { :name_cont => "best" }
json_response["products"].first.should have_attributes(attributes)
json_response["count"].should == 1
end
diff --git a/api/spec/controllers/spree/api/v1/return_authorizations_controller_spec.rb b/api/spec/controllers/spree/api/v1/return_authorizations_controller_spec.rb
index 3797aa75897..c054c7018ea 100644
--- a/api/spec/controllers/spree/api/v1/return_authorizations_controller_spec.rb
+++ b/api/spec/controllers/spree/api/v1/return_authorizations_controller_spec.rb
@@ -73,14 +73,31 @@ module Spree
it "can get a list of return authorizations" do
order.return_authorizations << create(:return_authorization)
order.return_authorizations << create(:return_authorization)
- return_authorizations = order.return_authorizations
- api_get :index, { :order_id => order.id }
+ api_get :index, { :order_id => order.id }
response.status.should == 200
return_authorizations = json_response["return_authorizations"]
return_authorizations.first.should have_attributes(attributes)
return_authorizations.first.should_not == return_authorizations.last
end
+ it 'can control the page size through a parameter' do
+ order.return_authorizations << create(:return_authorization)
+ order.return_authorizations << create(:return_authorization)
+ api_get :index, :order_id => order.id, :per_page => 1
+ json_response['count'].should == 1
+ json_response['current_page'].should == 1
+ json_response['pages'].should == 2
+ end
+
+ it 'can query the results through a paramter' do
+ order.return_authorizations << create(:return_authorization)
+ expected_result = create(:return_authorization, :reason => 'damaged')
+ order.return_authorizations << expected_result
+ api_get :index, :q => { :reason_cont => 'damage' }
+ json_response['count'].should == 1
+ json_response['return_authorizations'].first['return_authorization']['reason'].should eq expected_result.reason
+ end
+
it "can learn how to create a new return authorization" do
api_get :new
json_response["attributes"].should == ["id", "number", "state", "amount", "order_id", "reason", "created_at", "updated_at"]
diff --git a/api/spec/controllers/spree/api/v1/taxonomies_controller_spec.rb b/api/spec/controllers/spree/api/v1/taxonomies_controller_spec.rb
index 7595837d8c6..73ab462b6d7 100644
--- a/api/spec/controllers/spree/api/v1/taxonomies_controller_spec.rb
+++ b/api/spec/controllers/spree/api/v1/taxonomies_controller_spec.rb
@@ -20,8 +20,23 @@ module Spree
it "gets all taxonomies" do
api_get :index
- json_response.first['taxonomy']['name'].should eq taxonomy.name
- json_response.first['taxonomy']['root']['taxons'].count.should eq 1
+ json_response["taxonomies"].first['taxonomy']['name'].should eq taxonomy.name
+ json_response["taxonomies"].first['taxonomy']['root']['taxons'].count.should eq 1
+ end
+
+ it 'can control the page size through a parameter' do
+ create(:taxonomy)
+ api_get :index, :per_page => 1
+ json_response['count'].should == 1
+ json_response['current_page'].should == 1
+ json_response['pages'].should == 2
+ end
+
+ it 'can query the results through a paramter' do
+ expected_result = create(:taxonomy, :name => 'Style')
+ api_get :index, :q => { :name_cont => 'style' }
+ json_response['count'].should == 1
+ json_response['taxonomies'].first['taxonomy']['name'].should eq expected_result.name
end
it "gets a single taxonomy" do
diff --git a/api/spec/controllers/spree/api/v1/variants_controller_spec.rb b/api/spec/controllers/spree/api/v1/variants_controller_spec.rb
index 265e521b89c..5d353c0e550 100644
--- a/api/spec/controllers/spree/api/v1/variants_controller_spec.rb
+++ b/api/spec/controllers/spree/api/v1/variants_controller_spec.rb
@@ -28,6 +28,21 @@ module Spree
json_response["pages"].should == 1
end
+ it 'can control the page size through a parameter' do
+ create(:variant)
+ api_get :index, :per_page => 1
+ json_response['count'].should == 1
+ json_response['current_page'].should == 1
+ json_response['pages'].should == 3
+ end
+
+ it 'can query the results through a paramter' do
+ expected_result = create(:variant, :sku => 'FOOBAR')
+ api_get :index, :q => { :sku_cont => 'FOO' }
+ json_response['count'].should == 1
+ json_response['variants'].first['variant']['sku'].should eq expected_result.sku
+ end
+
it "variants returned contain option values data" do
api_get :index
option_values = json_response["variants"].last["variant"]["option_values"]
@@ -61,7 +76,7 @@ module Spree
second_variant = create(:variant)
api_get :index, :page => 2
json_response["variants"].first.should have_attributes(attributes)
- json_response["count"].should == 3
+ json_response["total_count"].should == 3
json_response["current_page"].should == 2
json_response["pages"].should == 3
end
diff --git a/api/spec/controllers/spree/api/v1/zones_controller_spec.rb b/api/spec/controllers/spree/api/v1/zones_controller_spec.rb
index 6819eea436e..787054b8ed9 100644
--- a/api/spec/controllers/spree/api/v1/zones_controller_spec.rb
+++ b/api/spec/controllers/spree/api/v1/zones_controller_spec.rb
@@ -13,7 +13,22 @@ module Spree
it "gets list of zones" do
api_get :index
- json_response.first.should have_attributes(attributes)
+ json_response['zones'].first.should have_attributes(attributes)
+ end
+
+ it 'can control the page size through a parameter' do
+ create(:zone)
+ api_get :index, :per_page => 1
+ json_response['count'].should == 1
+ json_response['current_page'].should == 1
+ json_response['pages'].should == 2
+ end
+
+ it 'can query the results through a paramter' do
+ expected_result = create(:zone, :name => 'South America')
+ api_get :index, :q => { :name_cont => 'south' }
+ json_response['count'].should == 1
+ json_response['zones'].first['zone']['name'].should eq expected_result.name
end
it "gets a zone" do
@@ -58,7 +73,7 @@ module Spree
}
}
- api_put :update, params
+ api_put :update, params
response.status.should == 200
json_response['zone']['name'].should eq 'North Pole'
json_response['zone']['zone_members'].should_not be_blank
From f57f12d66aa784f1a66787769ee256681a7a7c1e Mon Sep 17 00:00:00 2001
From: Michael Bianco
Date: Tue, 30 Oct 2012 21:35:36 -0400
Subject: [PATCH 326/346] Require secure connection on OrderController#show
Fixes #2164
Conflicts:
core/app/controllers/spree/orders_controller.rb
---
core/app/controllers/spree/orders_controller.rb | 2 ++
1 file changed, 2 insertions(+)
diff --git a/core/app/controllers/spree/orders_controller.rb b/core/app/controllers/spree/orders_controller.rb
index 2cd40f287ea..082922d4321 100644
--- a/core/app/controllers/spree/orders_controller.rb
+++ b/core/app/controllers/spree/orders_controller.rb
@@ -1,5 +1,7 @@
module Spree
class OrdersController < BaseController
+ ssl_required :show
+
rescue_from ActiveRecord::RecordNotFound, :with => :render_404
helper 'spree/products'
From fa9999581c10874d411545cfb3916b3f5c4a2080 Mon Sep 17 00:00:00 2001
From: Michael Bianco
Date: Thu, 8 Nov 2012 14:05:20 -0500
Subject: [PATCH 327/346] Adding Order#variants
Convenience method for grabbing a list of variants
Fixes #2195
---
core/app/models/spree/order.rb | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/core/app/models/spree/order.rb b/core/app/models/spree/order.rb
index 86d300d615e..ab7847a4367 100644
--- a/core/app/models/spree/order.rb
+++ b/core/app/models/spree/order.rb
@@ -467,6 +467,10 @@ def products
line_items.map { |li| li.variant.product }
end
+ def variants
+ line_items.map(&:variant)
+ end
+
def insufficient_stock_lines
line_items.select &:insufficient_stock?
end
From ade5b3adb97170e9205d1d2ced3b57668fdef89e Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Mon, 12 Nov 2012 16:31:19 +1100
Subject: [PATCH 328/346] Don't include 'out of stock' error message in
shipment mailers
If a product is being shipped, let's assume that it's *in*-stock
Fixes #2196
---
core/app/views/spree/shipment_mailer/shipped_email.text.erb | 2 +-
core/spec/mailers/shipment_mailer_spec.rb | 6 +++---
2 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/core/app/views/spree/shipment_mailer/shipped_email.text.erb b/core/app/views/spree/shipment_mailer/shipped_email.text.erb
index 59d90446d1b..76a95577742 100644
--- a/core/app/views/spree/shipment_mailer/shipped_email.text.erb
+++ b/core/app/views/spree/shipment_mailer/shipped_email.text.erb
@@ -6,7 +6,7 @@
<%= t('shipment_mailer.shipped_email.shipment_summary') %>
============================================================
<% @shipment.manifest.each do |item| %>
- <%= item.variant.sku %> <%= item.variant.product.name %> <%= variant_options(item.variant, :include_style => false) %> (<%= item.quantity %>)
+ <%= item.variant.sku %> <%= item.variant.product.name %> <%= item.variant.options_text %>
<% end %>
============================================================
diff --git a/core/spec/mailers/shipment_mailer_spec.rb b/core/spec/mailers/shipment_mailer_spec.rb
index 8e2bf84a50d..a4882e4cfbc 100644
--- a/core/spec/mailers/shipment_mailer_spec.rb
+++ b/core/spec/mailers/shipment_mailer_spec.rb
@@ -16,10 +16,10 @@
shipment
end
- it "doesn't include out of stock html span in the email body" do
- Spree::Config.allow_backorders = false
+ # Regression test for #2196
+ it "doesn't include out of stock in the email body" do
shipment_email = Spree::ShipmentMailer.shipped_email(shipment)
- shipment_email.body.should_not include(%Q{span class="out-of-stock"})
+ shipment_email.body.should_not include(%Q{Out of Stock})
end
context "emails must be translatable" do
From 9ecee524f9d2027ccfa2ac4887357213238d2eaf Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Tue, 13 Nov 2012 07:45:49 +1100
Subject: [PATCH 329/346] Bump README Rails version to 3.2.9
---
README.md | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/README.md b/README.md
index e3cbefaae9b..df308004827 100644
--- a/README.md
+++ b/README.md
@@ -29,9 +29,9 @@ Installation
The fastest way to get started is by using the spree command line tool
available in the spree gem which will add Spree to an existing Rails application.
- $ gem install rails -v 3.2.8
+ $ gem install rails -v 3.2.9
$ gem install spree
- $ rails _3.2.8_ new my_store
+ $ rails _3.2.9_ new my_store
$ spree install my_store
This will add the Spree gem to your Gemfile, create initializers, copy migrations and
From a61f4f433e6d0a83685a309af8932f1357cb72a9 Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Tue, 13 Nov 2012 09:35:05 +1100
Subject: [PATCH 330/346] Bump state_machine_spec
This is failing on Travis, but not locally. But I've *seen* it fail locally. Need a second opinion.
---
core/spec/models/order/state_machine_spec.rb | 1 -
1 file changed, 1 deletion(-)
diff --git a/core/spec/models/order/state_machine_spec.rb b/core/spec/models/order/state_machine_spec.rb
index f1efdbe0971..00a0cd835d7 100644
--- a/core/spec/models/order/state_machine_spec.rb
+++ b/core/spec/models/order/state_machine_spec.rb
@@ -179,7 +179,6 @@
it "should change shipment status (unless shipped)"
end
-
# Another regression test for #729
context "#resume" do
before do
From 5c6549084ca5358aba936b85399d8b442e9fce1a Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Tue, 13 Nov 2012 11:38:32 +1100
Subject: [PATCH 331/346] Stub call to restock_items! which we don't care about
in order cancellation tests
---
core/spec/models/order/state_machine_spec.rb | 1 +
1 file changed, 1 insertion(+)
diff --git a/core/spec/models/order/state_machine_spec.rb b/core/spec/models/order/state_machine_spec.rb
index 00a0cd835d7..45ed7b79398 100644
--- a/core/spec/models/order/state_machine_spec.rb
+++ b/core/spec/models/order/state_machine_spec.rb
@@ -155,6 +155,7 @@
Spree::OrderMailer.stub(:cancel_email).and_return(mail_message = stub)
mail_message.stub :deliver
order.stub :has_available_shipment
+ order.stub :restock_items!
end
context "without shipped items" do
From c1eefb4a65261aa8107f240bb169f5561eb8ea91 Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Tue, 13 Nov 2012 12:51:56 +1100
Subject: [PATCH 332/346] Force rails dependency to be 3.2.9 (or higher, within
3.2.x branch)
---
core/spree_core.gemspec | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/core/spree_core.gemspec b/core/spree_core.gemspec
index 194de0415fa..396f791df9f 100644
--- a/core/spree_core.gemspec
+++ b/core/spree_core.gemspec
@@ -31,7 +31,7 @@ Gem::Specification.new do |s|
s.add_dependency 'aws-sdk', '~> 1.3.4'
s.add_dependency 'ransack', '~> 0.7.0'
s.add_dependency 'activemerchant', '= 1.28.0'
- s.add_dependency 'rails', '~> 3.2.8'
+ s.add_dependency 'rails', '~> 3.2.9'
s.add_dependency 'kaminari', '0.13.0'
s.add_dependency 'deface', '>= 0.9.0'
s.add_dependency 'stringex', '~> 1.3.2'
From bf9f3719e6ee83232018d9c9f795df43564208d4 Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Tue, 13 Nov 2012 16:46:47 +1100
Subject: [PATCH 333/346] [api] fix syntactical errors in CountriesController
---
api/app/controllers/spree/api/v1/countries_controller.rb | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/api/app/controllers/spree/api/v1/countries_controller.rb b/api/app/controllers/spree/api/v1/countries_controller.rb
index 8252b3bbabe..55f72e9cd25 100644
--- a/api/app/controllers/spree/api/v1/countries_controller.rb
+++ b/api/app/controllers/spree/api/v1/countries_controller.rb
@@ -3,8 +3,10 @@ module Api
module V1
class CountriesController < Spree::Api::V1::BaseController
def index
- @countries = Country.ransack(params[:q]).result.includes(:states).order('name ASC')
- .page(params[:page]).per(params[:per_page])
+ @countries = Country.
+ ransack(params[:q]).result.
+ includes(:states).order('name ASC').
+ page(params[:page]).per(params[:per_page])
end
def show
From 2da5749cbad7d84cea43c9e0feb6949d10842e84 Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Tue, 13 Nov 2012 16:55:37 +1100
Subject: [PATCH 334/346] [api] Fix syntax in ProductPropertiesController
---
.../spree/api/v1/product_properties_controller.rb | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/api/app/controllers/spree/api/v1/product_properties_controller.rb b/api/app/controllers/spree/api/v1/product_properties_controller.rb
index f30b5ff793a..b2b7508251a 100644
--- a/api/app/controllers/spree/api/v1/product_properties_controller.rb
+++ b/api/app/controllers/spree/api/v1/product_properties_controller.rb
@@ -6,8 +6,9 @@ class ProductPropertiesController < Spree::Api::V1::BaseController
before_filter :product_property, :only => [:show, :update, :destroy]
def index
- @product_properties = @product.product_properties.ransack(params[:q]).result
- .page(params[:page]).per(params[:per_page])
+ @product_properties = @product.product_properties.
+ ransack(params[:q]).result
+ .page(params[:page]).per(params[:per_page])
end
def show
From 4d5cab97a5232f93ce3dfd94bdce5397d27eb065 Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Tue, 13 Nov 2012 16:58:24 +1100
Subject: [PATCH 335/346] [api] Fix syntax within
ReturnAuthorizationsController
---
.../spree/api/v1/return_authorizations_controller.rb | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/api/app/controllers/spree/api/v1/return_authorizations_controller.rb b/api/app/controllers/spree/api/v1/return_authorizations_controller.rb
index b772ff4a44b..b8accbb3346 100644
--- a/api/app/controllers/spree/api/v1/return_authorizations_controller.rb
+++ b/api/app/controllers/spree/api/v1/return_authorizations_controller.rb
@@ -5,8 +5,9 @@ class ReturnAuthorizationsController < Spree::Api::V1::BaseController
before_filter :authorize_admin!
def index
- @return_authorizations = order.return_authorizations.ransack(params[:q]).result
- .page(params[:page]).per(params[:per_page])
+ @return_authorizations = order.return_authorizations.
+ ransack(params[:q]).result.
+ page(params[:page]).per(params[:per_page])
end
def show
From 160f4fdf0cd196166c0f913961c5cf668c205314 Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Tue, 13 Nov 2012 17:01:09 +1100
Subject: [PATCH 336/346] [api] Fix syntax in taxonomies and variants
controllers
---
api/app/controllers/spree/api/v1/taxonomies_controller.rb | 6 ++++--
api/app/controllers/spree/api/v1/variants_controller.rb | 5 +++--
2 files changed, 7 insertions(+), 4 deletions(-)
diff --git a/api/app/controllers/spree/api/v1/taxonomies_controller.rb b/api/app/controllers/spree/api/v1/taxonomies_controller.rb
index b3b7f951986..d1d802ecfc5 100644
--- a/api/app/controllers/spree/api/v1/taxonomies_controller.rb
+++ b/api/app/controllers/spree/api/v1/taxonomies_controller.rb
@@ -3,8 +3,10 @@ module Api
module V1
class TaxonomiesController < Spree::Api::V1::BaseController
def index
- @taxonomies = Taxonomy.order('name').includes(:root => :children).ransack(params[:q]).result
- .page(params[:page]).per(params[:per_page])
+ @taxonomies = Taxonomy.
+ order('name').includes(:root => :children).
+ ransack(params[:q]).result.
+ page(params[:page]).per(params[:per_page])
end
def show
diff --git a/api/app/controllers/spree/api/v1/variants_controller.rb b/api/app/controllers/spree/api/v1/variants_controller.rb
index 6890cb729f5..694e7adbca4 100644
--- a/api/app/controllers/spree/api/v1/variants_controller.rb
+++ b/api/app/controllers/spree/api/v1/variants_controller.rb
@@ -5,8 +5,9 @@ class VariantsController < Spree::Api::V1::BaseController
before_filter :product
def index
- @variants = scope.includes(:option_values).ransack(params[:q]).result.
- page(params[:page]).per(params[:per_page])
+ @variants = scope.
+ includes(:option_values).ransack(params[:q]).result.
+ page(params[:page]).per(params[:per_page])
end
def show
From 80a8e5b477650c4a5605c5e0e1e420c2b8ed47d6 Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Wed, 14 Nov 2012 14:03:42 +1100
Subject: [PATCH 337/346] [promo] Fix user picker
Fixes #1890
Conflicts:
core/app/views/spree/admin/shared/_routes.html.erb
promo/app/views/spree/admin/promotions/rules/_user.html.erb
---
.../spree/admin/search_controller.rb | 20 ++++++-----
core/app/views/spree/admin/search/users.rabl | 2 +-
.../views/spree/admin/shared/_routes.html.erb | 5 ++-
.../assets/javascripts/admin/spree_promo.js | 35 +++++++++++++++++++
.../admin/promotions/rules/_user.html.erb | 12 +++----
5 files changed, 54 insertions(+), 20 deletions(-)
diff --git a/core/app/controllers/spree/admin/search_controller.rb b/core/app/controllers/spree/admin/search_controller.rb
index ed21d1538e5..49abde0ef13 100644
--- a/core/app/controllers/spree/admin/search_controller.rb
+++ b/core/app/controllers/spree/admin/search_controller.rb
@@ -8,14 +8,18 @@ class SearchController < Spree::Admin::BaseController
# TODO: Clean this up by moving searching out to user_class_extensions
# And then JSON building with something like Active Model Serializers
def users
- @users = Spree.user_class.ransack({
- :m => 'or',
- :email_start => params[:q],
- :ship_address_firstname_start => params[:q],
- :ship_address_lastname_start => params[:q],
- :bill_address_firstname_start => params[:q],
- :bill_address_lastname_start => params[:q]
- }).result.limit(params[:limit] || 100)
+ if params[:ids]
+ @users = Spree.user_class.where(:id => params[:ids].split(','))
+ else
+ @users = Spree.user_class.ransack({
+ :m => 'or',
+ :email_start => params[:q],
+ :ship_address_firstname_start => params[:q],
+ :ship_address_lastname_start => params[:q],
+ :bill_address_firstname_start => params[:q],
+ :bill_address_lastname_start => params[:q]
+ }).result.limit(10)
+ end
end
end
end
diff --git a/core/app/views/spree/admin/search/users.rabl b/core/app/views/spree/admin/search/users.rabl
index 3b8ecc1b10d..6e6d3932f05 100644
--- a/core/app/views/spree/admin/search/users.rabl
+++ b/core/app/views/spree/admin/search/users.rabl
@@ -1,6 +1,6 @@
object false
child @users => :users do
- attributes :email
+ attributes :email, :id
address_fields = [:firstname, :lastname,
:address1, :address2,
:city, :zipcode,
diff --git a/core/app/views/spree/admin/shared/_routes.html.erb b/core/app/views/spree/admin/shared/_routes.html.erb
index fe29622b4ce..a15905645f8 100644
--- a/core/app/views/spree/admin/shared/_routes.html.erb
+++ b/core/app/views/spree/admin/shared/_routes.html.erb
@@ -3,7 +3,6 @@
:product_search => spree.admin_products_path(:format => 'json'),
:taxon_search => spree.search_admin_taxons_path(:format => 'json'),
:product_search_basic => spree.admin_products_path(:format => 'json', :json_format => 'basic', :limit => 10),
- :user_search => spree.admin_search_users_path(:format => 'json', :limit => 10)
- }.to_json
-%>
+ :user_search => spree.admin_search_users_path(:format => 'json')
+ }.to_json %>;
diff --git a/promo/app/assets/javascripts/admin/spree_promo.js b/promo/app/assets/javascripts/admin/spree_promo.js
index 451b28e682b..73a06727fbf 100644
--- a/promo/app/assets/javascripts/admin/spree_promo.js
+++ b/promo/app/assets/javascripts/admin/spree_promo.js
@@ -1,2 +1,37 @@
//= require admin/spree_core
//= require_tree .
+
+function cleanUsers(data) {
+ var users = $.map(data['users'], function(result) {
+ return result['user']
+ })
+ return users;
+}
+
+$(document).ready(function() {
+ $('.user_picker').select2({
+ minimumInputLength: 1,
+ multiple: true,
+ initSelection: function(element, callback) {
+ $.get(Spree.routes.user_search, { ids: element.val() }, function(data) {
+ callback(cleanUsers(data))
+ })
+ },
+ ajax: {
+ url: Spree.routes.user_search,
+ datatype: 'json',
+ data: function(term, page) {
+ return { q: term }
+ },
+ results: function(data, page) {
+ return { results: cleanUsers(data) }
+ }
+ },
+ formatResult: function(user) {
+ return user.email;
+ },
+ formatSelection: function(user) {
+ return user.email;
+ }
+ });
+})
diff --git a/promo/app/views/spree/admin/promotions/rules/_user.html.erb b/promo/app/views/spree/admin/promotions/rules/_user.html.erb
index d777810cffa..d09610ecf1b 100644
--- a/promo/app/views/spree/admin/promotions/rules/_user.html.erb
+++ b/promo/app/views/spree/admin/promotions/rules/_user.html.erb
@@ -1,8 +1,4 @@
-
-
- <%= t('user_rule.choose_users') %>
- <% user_names_hash = promotion_rule.users.inject({}){|memo,item| memo[item.id] = item.email; memo} %>
- <% user_rules = promotion_rule.users.collect { |u| { :id => u.id, :name => u.email } } %>
-
-
-
+
+ <%= t('user_rule.choose_users') %>
+
+
From 6f0d8f3b1b0f2bd9b1e391fbbafdd2282c27ed1d Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Thu, 15 Nov 2012 10:05:41 +1100
Subject: [PATCH 338/346] Add spree_auth_devise to extension Gemfile
---
cmd/lib/spree_cmd/templates/extension/Gemfile | 3 +++
1 file changed, 3 insertions(+)
diff --git a/cmd/lib/spree_cmd/templates/extension/Gemfile b/cmd/lib/spree_cmd/templates/extension/Gemfile
index d65e2a66952..17dbc22025e 100644
--- a/cmd/lib/spree_cmd/templates/extension/Gemfile
+++ b/cmd/lib/spree_cmd/templates/extension/Gemfile
@@ -1,3 +1,6 @@
source 'http://rubygems.org'
+# Provides basic authentication functionality for testing parts of your engine
+gem 'spree_auth_devise', :git => "git://github.com/spree/spree_auth_devise"
+
gemspec
From a5fab651fc8e29c0d7d67d76b8a5cea69042a9ac Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Thu, 15 Nov 2012 16:22:03 +1100
Subject: [PATCH 339/346] Remove testing_support/env
---
core/lib/spree/core/testing_support/env.rb | 2 --
core/spec/spec_helper.rb | 1 -
dash/spec/spec_helper.rb | 1 -
promo/spec/spec_helper.rb | 1 -
4 files changed, 5 deletions(-)
delete mode 100644 core/lib/spree/core/testing_support/env.rb
diff --git a/core/lib/spree/core/testing_support/env.rb b/core/lib/spree/core/testing_support/env.rb
deleted file mode 100644
index 16bae913543..00000000000
--- a/core/lib/spree/core/testing_support/env.rb
+++ /dev/null
@@ -1,2 +0,0 @@
-Capybara.default_selector = :css
-Capybara.server_boot_timeout = 50
\ No newline at end of file
diff --git a/core/spec/spec_helper.rb b/core/spec/spec_helper.rb
index f1dda4a61e6..1bcf9189de8 100644
--- a/core/spec/spec_helper.rb
+++ b/core/spec/spec_helper.rb
@@ -11,7 +11,6 @@
require 'database_cleaner'
require 'spree/core/testing_support/factories'
-require 'spree/core/testing_support/env'
require 'spree/core/testing_support/controller_requests'
require 'spree/core/testing_support/authorization_helpers'
require 'spree/core/testing_support/preferences'
diff --git a/dash/spec/spec_helper.rb b/dash/spec/spec_helper.rb
index cf2796681c3..5667cb90ace 100644
--- a/dash/spec/spec_helper.rb
+++ b/dash/spec/spec_helper.rb
@@ -12,7 +12,6 @@
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
require 'spree/core/testing_support/factories'
-require 'spree/core/testing_support/env'
require 'spree/core/testing_support/controller_requests'
require 'active_record/fixtures'
diff --git a/promo/spec/spec_helper.rb b/promo/spec/spec_helper.rb
index 23f2c24e1b4..7c5e7d2d821 100644
--- a/promo/spec/spec_helper.rb
+++ b/promo/spec/spec_helper.rb
@@ -12,7 +12,6 @@
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
require 'spree/core/testing_support/factories'
-require 'spree/core/testing_support/env'
require 'spree/core/testing_support/authorization_helpers'
require 'factories'
From 74868b051ee57e5d160b806570fc2c4547f854ac Mon Sep 17 00:00:00 2001
From: Jeff Dutil
Date: Wed, 14 Nov 2012 03:27:10 -0500
Subject: [PATCH 340/346] Ignore .sass-cache for extensions.
Fixes #2212
---
cmd/lib/spree_cmd/templates/extension/gitignore | 1 +
1 file changed, 1 insertion(+)
diff --git a/cmd/lib/spree_cmd/templates/extension/gitignore b/cmd/lib/spree_cmd/templates/extension/gitignore
index 2b6b0de6feb..e8a3f9c27e6 100644
--- a/cmd/lib/spree_cmd/templates/extension/gitignore
+++ b/cmd/lib/spree_cmd/templates/extension/gitignore
@@ -4,6 +4,7 @@
.DS_Store
.idea
.project
+.sass-cache
coverage
Gemfile.lock
tmp
From 09c9455266a686214d882ba87805e6e6386b8dd2 Mon Sep 17 00:00:00 2001
From: Ryan Bigg
Date: Thu, 15 Nov 2012 19:10:20 +1100
Subject: [PATCH 341/346] Freeze capybara dependency to 1.1.3
---
common_spree_dependencies.rb | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/common_spree_dependencies.rb b/common_spree_dependencies.rb
index 6dd7f708c66..eb97ab1dc4b 100644
--- a/common_spree_dependencies.rb
+++ b/common_spree_dependencies.rb
@@ -24,7 +24,7 @@
gem 'ffaker'
gem 'shoulda-matchers', '~> 1.0.0'
- gem 'capybara'
+ gem 'capybara', '1.1.3'
gem 'selenium-webdriver', '2.25.0'
gem 'database_cleaner', '0.7.1'
gem 'launchy'
From 0d81ee0a2265797641ce90e120ea4fd8b085fc12 Mon Sep 17 00:00:00 2001
From: Brian Quinn
Date: Thu, 15 Nov 2012 10:15:19 +0000
Subject: [PATCH 342/346] Add missing route to api payments capture
---
api/config/routes.rb | 1 +
1 file changed, 1 insertion(+)
diff --git a/api/config/routes.rb b/api/config/routes.rb
index 4e8685870b1..4e201f28011 100644
--- a/api/config/routes.rb
+++ b/api/config/routes.rb
@@ -32,6 +32,7 @@
resources :payments do
member do
put :authorize
+ put :capture
put :purchase
put :void
put :credit
From 6767ce6a9634cb4dc59fa58f7f40680216d79608 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Trung=20L=C3=AA?=
Date: Sun, 18 Nov 2012 18:22:58 +1100
Subject: [PATCH 343/346] Move OrdersController#accurate_title to private
---
core/app/controllers/spree/orders_controller.rb | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/core/app/controllers/spree/orders_controller.rb b/core/app/controllers/spree/orders_controller.rb
index 082922d4321..79e4a95f28a 100644
--- a/core/app/controllers/spree/orders_controller.rb
+++ b/core/app/controllers/spree/orders_controller.rb
@@ -15,7 +15,7 @@ def show
def update
@order = current_order
if @order.update_attributes(params[:order])
- @order.line_items = @order.line_items.select {|li| li.quantity > 0 }
+ @order.line_items = @order.line_items.select { |li| li.quantity > 0 }
fire_event('spree.order.contents_changed')
respond_with(@order) do |format|
format.html do
@@ -75,8 +75,10 @@ def empty
redirect_to spree.cart_path
end
- def accurate_title
- @order && @order.completed? ? "#{Order.model_name.human} #{@order.number}" : t(:shopping_cart)
- end
+ private
+
+ def accurate_title
+ @order && @order.completed? ? "#{Order.model_name.human} #{@order.number}" : t(:shopping_cart)
+ end
end
end
From b85fc2c85f017e4a4f706b87e864775dcb459056 Mon Sep 17 00:00:00 2001
From: Sean Schofield
Date: Mon, 19 Nov 2012 14:26:51 -0500
Subject: [PATCH 344/346] Version bump
---
SPREE_VERSION | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/SPREE_VERSION b/SPREE_VERSION
index 26aaba0e866..6085e946503 100644
--- a/SPREE_VERSION
+++ b/SPREE_VERSION
@@ -1 +1 @@
-1.2.0
+1.2.1
From c2b30442a809fbd2361295763708ea53f8804cd0 Mon Sep 17 00:00:00 2001
From: Sean Schofield
Date: Mon, 19 Nov 2012 14:51:11 -0500
Subject: [PATCH 345/346] 1.2.2.beta version
---
SPREE_VERSION | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/SPREE_VERSION b/SPREE_VERSION
index 6085e946503..14334cb7828 100644
--- a/SPREE_VERSION
+++ b/SPREE_VERSION
@@ -1 +1 @@
-1.2.1
+1.2.2.beta
From b8da85915e024afbae1f71d0691602d8a23498ec Mon Sep 17 00:00:00 2001
From: Sean Schofield
Date: Mon, 19 Nov 2012 15:24:51 -0500
Subject: [PATCH 346/346] Version bump
---
SPREE_VERSION | 2 +-
cmd/lib/spree_cmd/extension.rb | 2 +-
core/lib/spree/core/version.rb | 2 +-
3 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/SPREE_VERSION b/SPREE_VERSION
index 14334cb7828..23aa8390630 100644
--- a/SPREE_VERSION
+++ b/SPREE_VERSION
@@ -1 +1 @@
-1.2.2.beta
+1.2.2
diff --git a/cmd/lib/spree_cmd/extension.rb b/cmd/lib/spree_cmd/extension.rb
index 6ca9f901b44..788b7009d65 100644
--- a/cmd/lib/spree_cmd/extension.rb
+++ b/cmd/lib/spree_cmd/extension.rb
@@ -51,7 +51,7 @@ def class_name
end
def spree_version
- '1.2.0'
+ '1.2.2'
end
def use_prefix(prefix)
diff --git a/core/lib/spree/core/version.rb b/core/lib/spree/core/version.rb
index be4a35390b7..3cab75d2453 100644
--- a/core/lib/spree/core/version.rb
+++ b/core/lib/spree/core/version.rb
@@ -1,5 +1,5 @@
module Spree
def self.version
- "1.2.0"
+ "1.2.2"
end
end