Merge branch 'master' into optimise-shopfront

This commit is contained in:
Rohan Mitchell
2015-06-12 12:15:20 +10:00
19 changed files with 140 additions and 77 deletions

View File

@@ -251,8 +251,7 @@ GEM
erubis (2.7.0)
eventmachine (1.0.3)
excon (0.25.3)
execjs (1.4.0)
multi_json (~> 1.0)
execjs (2.5.2)
factory_girl (3.3.0)
activesupport (>= 3.0.0)
factory_girl_rails (3.3.0)
@@ -354,7 +353,7 @@ GEM
net-scp (1.1.2)
net-ssh (>= 2.6.5)
net-ssh (2.6.8)
newrelic_rpm (3.6.7.152)
newrelic_rpm (3.12.0.288)
nokogiri (1.6.6.2)
mini_portile (~> 0.6.0)
oj (2.1.2)
@@ -502,9 +501,9 @@ GEM
turn (0.8.3)
ansi
tzinfo (0.3.44)
uglifier (1.2.4)
uglifier (2.7.1)
execjs (>= 0.3.0)
multi_json (>= 1.0.2)
json (>= 1.8.0)
unicorn (4.9.0)
kgio (~> 2.6)
rack

View File

@@ -7,5 +7,5 @@ Darkswarm.factory "MapConfiguration", ->
zoom: 12
additional_options: {}
#mapTypeId: 'satellite'
styles: [{"featureType":"landscape","stylers":[{"saturation":-100},{"lightness":65},{"visibility":"on"}]},{"featureType":"poi","stylers":[{"saturation":-100},{"lightness":51},{"visibility":"simplified"}]},{"featureType":"road.highway","stylers":[{"saturation":-100},{"visibility":"simplified"}]},{"featureType":"road.arterial","stylers":[{"saturation":-100},{"lightness":30},{"visibility":"on"}]},{"featureType":"road.local","stylers":[{"saturation":-100},{"lightness":40},{"visibility":"on"}]},{"featureType":"transit","stylers":[{"saturation":-100},{"visibility":"simplified"}]},{"featureType":"administrative.province","stylers":[{"visibility":"off"}]},{"featureType":"water","elementType":"labels","stylers":[{"visibility":"on"},{"lightness":-25},{"saturation":-100}]},{"featureType":"water","elementType":"geometry","stylers":[{"hue":"#ffff00"},{"lightness":-25},{"saturation":-97}]}]
styles: [{"featureType":"landscape","stylers":[{"saturation":-100},{"lightness":65},{"visibility":"on"}]},{"featureType":"poi","stylers":[{"saturation":-100},{"lightness":51},{"visibility":"simplified"}]},{"featureType":"road.highway","stylers":[{"saturation":-100},{"visibility":"simplified"}]},{"featureType":"road.arterial","stylers":[{"saturation":-100},{"lightness":30},{"visibility":"on"}]},{"featureType":"road.local","stylers":[{"saturation":-100},{"lightness":40},{"visibility":"on"}]},{"featureType":"transit","stylers":[{"saturation":-100},{"visibility":"simplified"}]},{"featureType":"administrative.province","stylers":[{"visibility":"off"}]},{"featureType":"water","elementType":"labels","stylers":[{"visibility":"on"},{"lightness":-25},{"saturation":-100}]},{"featureType":"water","elementType":"geometry","stylers":[{"hue":"#ffff00"},{"lightness":-25},{"saturation":-97}]},{"featureType":"road","elementType": "labels.icon","stylers":[{"visibility":"off"}]}]

View File

@@ -30,9 +30,18 @@
float: right
margin-left: 0.5rem
//Hub Link
@media all and (max-width: 640px)
a.hub
display: block
//Hub Name
span.hub-name-listing
font-weight: 700
&:after
content: ">>"
display: inline-block
margin-left: 5px
//CLOSED row
&.closed

View File

@@ -1,5 +1,8 @@
Spree::Api::LineItemsController.class_eval do
after_filter :apply_enterprise_fees, :only => :update
after_filter :apply_enterprise_fees, only: :update
private
def apply_enterprise_fees
authorize! :read, order

View File

@@ -1,6 +1,9 @@
module Spree
Adjustment.class_eval do
has_one :metadata, class_name: 'AdjustmentMetadata', dependent: :destroy
# Deletion of metadata is handled in the database.
# So we don't need the option `dependent: :destroy` as long as
# AdjustmentMetadata has no destroy logic itself.
has_one :metadata, class_name: 'AdjustmentMetadata'
scope :enterprise_fee, where(originator_type: 'EnterpriseFee')
scope :included_tax, where(originator_type: 'Spree::TaxRate', adjustable_type: 'Spree::LineItem')

View File

@@ -157,20 +157,22 @@ Spree::Order.class_eval do
end
def update_distribution_charge!
EnterpriseFee.clear_all_adjustments_on_order self
with_lock do
EnterpriseFee.clear_all_adjustments_on_order self
line_items.each do |line_item|
if provided_by_order_cycle? line_item
OpenFoodNetwork::EnterpriseFeeCalculator.new.create_line_item_adjustments_for line_item
line_items.each do |line_item|
if provided_by_order_cycle? line_item
OpenFoodNetwork::EnterpriseFeeCalculator.new.create_line_item_adjustments_for line_item
else
pd = product_distribution_for line_item
pd.create_adjustment_for line_item if pd
else
pd = product_distribution_for line_item
pd.create_adjustment_for line_item if pd
end
end
end
if order_cycle
OpenFoodNetwork::EnterpriseFeeCalculator.new.create_order_adjustments_for self
if order_cycle
OpenFoodNetwork::EnterpriseFeeCalculator.new.create_order_adjustments_for self
end
end
end

View File

@@ -1,7 +1,7 @@
.row.active_table_row{"ng-if" => "hub.is_distributor", "ng-click" => "toggle($event)", "ng-class" => "{'closed' : !open(), 'is_distributor' : producer.is_distributor}", bindonce: true}
.columns.small-12.medium-6.large-5.skinny-head
%a.hub{"bo-href" => "hub.path", "ng-class" => "{primary: hub.active, secondary: !hub.active}", "ofn-empties-cart" => "hub"}
.columns.small-12.medium-5.large-5.skinny-head
%a.hub{"bo-href" => "hub.path", "ng-class" => "{primary: hub.active, secondary: !hub.active}", "ofn-empties-cart" => "hub", "data-is-link" => "true"}
%i{bo: {class: "hub.icon_font"}}
%span.margin-top.hub-name-listing{"bo-bind" => "hub.name | truncate:40"}
@@ -10,7 +10,7 @@
.columns.small-2.medium-1.large-1
%span.margin-top{"bo-bind" => "hub.address.state_name | uppercase"}
.columns.small-6.medium-3.large-4.text-right{"bo-if" => "hub.active"}
.columns.small-4.medium-3.large-3.text-right{"bo-if" => "hub.active"}
%a.hub.open_closed{"bo-href" => "hub.path", "ng-class" => "{primary: hub.active, secondary: !hub.active}", "ofn-empties-cart" => "hub"}
%i.ofn-i_033-open-sign
%span.margin-top{ bo: { if: "current()" } }
@@ -18,13 +18,17 @@
%span.margin-top{ bo: { if: "!current()" } }
%span{"bo-bind" => "hub.orders_close_at | sensible_timeframe"}
.columns.small-6.medium-3.large-4.text-right{"bo-if" => "!hub.active"}
.columns.small-4.medium-3.large-3.text-right{"bo-if" => "!hub.active"}
%a.hub.open_closed{"bo-href" => "hub.path", "ng-class" => "{primary: hub.active, secondary: !hub.active}", "ofn-empties-cart" => "hub"}
%i.ofn-i_032-closed-sign
%span.margin-top{ bo: { if: "current()" } }
%em Shopping here
%span.margin-top{ bo: { if: "!current()" } } Orders closed
.columns.small-2.medium-1.large-1.text-right
%span.margin-top
%i{"ng-class" => "{'ofn-i_005-caret-down' : !open(), 'ofn-i_006-caret-up' : open()}"}
.row.active_table_row{"ng-if" => "!hub.is_distributor", "ng-class" => "closed"}
.columns.small-12.medium-6.large-5.skinny-head
%a.hub{"ng-click" => "openModal(hub)", "ng-class" => "{primary: hub.active, secondary: !hub.active}"}
@@ -39,3 +43,4 @@
.columns.small-6.medium-3.large-4.text-right
%span.margin-top{ bo: { if: "!current()" } }
%em Profile only

View File

@@ -79,7 +79,7 @@ module Openfoodnetwork
config.assets.enabled = true
# Version of your assets, change this if you want to expire all your assets
config.assets.version = '1.0'
config.assets.version = '1.1'
config.sass.load_paths += [
"#{Gem.loaded_specs['foundation-rails'].full_gem_path}/vendor/assets/stylesheets/foundation/components",

View File

@@ -1,8 +1,10 @@
# Be sure to restart your server when you modify this file.
Openfoodnetwork::Application.config.session_store :cookie_store, key: '_openfoodnetwork_session'
# The cookie_store can be too small for very long URLs stored by Devise.
# The maximum size of cookies is 4096 bytes.
#Openfoodnetwork::Application.config.session_store :cookie_store, key: '_openfoodnetwork_session'
# Use the database for sessions instead of the cookie-based default,
# which shouldn't be used to store highly confidential information
# (create the session table with "rails generate session_migration")
# Openfoodnetwork::Application.config.session_store :active_record_store
Openfoodnetwork::Application.config.session_store :active_record_store

View File

@@ -1,27 +1,2 @@
preload_app true # https://newrelic.com/docs/ruby/no-data-with-unicorn
worker_processes 4 # amount of unicorn workers to spin up
timeout 60 # restarts workers that hang for 30 seconds
# https://devcenter.heroku.com/articles/forked-pg-connections
before_fork do |server, worker|
Signal.trap 'TERM' do
puts 'Unicorn master intercepting TERM and sending myself QUIT instead'
Process.kill 'QUIT', Process.pid
end
defined?(ActiveRecord::Base) and
ActiveRecord::Base.connection.disconnect!
end
after_fork do |server, worker|
Signal.trap 'TERM' do
puts 'Unicorn worker intercepting TERM and doing nothing. Wait for master to sent QUIT'
end
defined?(ActiveRecord::Base) and
ActiveRecord::Base.establish_connection
end
worker_processes 2 # amount of unicorn workers to spin up
timeout 120 # restarts workers that hang for 30 seconds

View File

@@ -0,0 +1,12 @@
class AddSessionsTable < ActiveRecord::Migration
def change
create_table :sessions do |t|
t.string :session_id, :null => false
t.text :data
t.timestamps
end
add_index :sessions, :session_id
add_index :sessions, :updated_at
end
end

View File

@@ -0,0 +1,11 @@
class DependentDeleteAdjustmentMetadata < ActiveRecord::Migration
def up
remove_foreign_key "adjustment_metadata", name: "adjustment_metadata_adjustment_id_fk"
add_foreign_key "adjustment_metadata", "spree_adjustments", name: "adjustment_metadata_adjustment_id_fk", column: "adjustment_id", dependent: :delete
end
def down
remove_foreign_key "adjustment_metadata", name: "adjustment_metadata_adjustment_id_fk"
add_foreign_key "adjustment_metadata", "spree_adjustments", name: "adjustment_metadata_adjustment_id_fk", column: "adjustment_id"
end
end

View File

@@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20150603001843) do
ActiveRecord::Schema.define(:version => 20150605052516) do
create_table "adjustment_metadata", :force => true do |t|
t.integer "adjustment_id"
@@ -397,6 +397,16 @@ ActiveRecord::Schema.define(:version => 20150603001843) do
add_index "product_distributions", ["enterprise_fee_id"], :name => "index_product_distributions_on_enterprise_fee_id"
add_index "product_distributions", ["product_id"], :name => "index_product_distributions_on_product_id"
create_table "sessions", :force => true do |t|
t.string "session_id", :null => false
t.text "data"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
add_index "sessions", ["session_id"], :name => "index_sessions_on_session_id"
add_index "sessions", ["updated_at"], :name => "index_sessions_on_updated_at"
create_table "spree_activators", :force => true do |t|
t.string "description"
t.datetime "expires_at"
@@ -1116,7 +1126,7 @@ ActiveRecord::Schema.define(:version => 20150603001843) do
add_index "variant_overrides", ["variant_id", "hub_id"], :name => "index_variant_overrides_on_variant_id_and_hub_id"
add_foreign_key "adjustment_metadata", "enterprises", name: "adjustment_metadata_enterprise_id_fk"
add_foreign_key "adjustment_metadata", "spree_adjustments", name: "adjustment_metadata_adjustment_id_fk", column: "adjustment_id"
add_foreign_key "adjustment_metadata", "spree_adjustments", name: "adjustment_metadata_adjustment_id_fk", column: "adjustment_id", dependent: :delete
add_foreign_key "carts", "spree_users", name: "carts_user_id_fk", column: "user_id"

View File

@@ -212,7 +212,7 @@ FactoryGirl.define do
factory :customer, :class => Customer do
email { Faker::Internet.email }
enterprise
code { Faker::Lorem.word }
code { SecureRandom.base64(150) }
user
end
end

View File

@@ -117,31 +117,34 @@ feature %q{
end
end
scenario "creating a new product", js: true do
Spree::Config.products_require_tax_category = false
click_link 'Products'
click_link 'New Product'
context "products do not require a tax category" do
around { |example| with_products_require_tax_category(false) { example.run } }
fill_in 'product_name', :with => 'A new product !!!'
fill_in 'product_price', :with => '19.99'
scenario "creating a new product", js: true do
click_link 'Products'
click_link 'New Product'
page.should have_selector('#product_supplier_id')
select 'Another Supplier', :from => 'product_supplier_id'
select 'Weight (g)', from: 'product_variant_unit_with_scale'
fill_in 'product_unit_value_with_description', with: '500'
select taxon.name, from: "product_primary_taxon_id"
select 'None', from: "product_tax_category_id"
fill_in 'product_name', :with => 'A new product !!!'
fill_in 'product_price', :with => '19.99'
# Should only have suppliers listed which the user can manage
page.should have_select 'product_supplier_id', with_options: [@supplier2.name, @supplier_permitted.name]
page.should_not have_select 'product_supplier_id', with_options: [@supplier.name]
page.should have_selector('#product_supplier_id')
select 'Another Supplier', :from => 'product_supplier_id'
select 'Weight (g)', from: 'product_variant_unit_with_scale'
fill_in 'product_unit_value_with_description', with: '500'
select taxon.name, from: "product_primary_taxon_id"
select 'None', from: "product_tax_category_id"
click_button 'Create'
# Should only have suppliers listed which the user can manage
page.should have_select 'product_supplier_id', with_options: [@supplier2.name, @supplier_permitted.name]
page.should_not have_select 'product_supplier_id', with_options: [@supplier.name]
flash_message.should == 'Product "A new product !!!" has been successfully created!'
product = Spree::Product.find_by_name('A new product !!!')
product.supplier.should == @supplier2
product.tax_category.should be_nil
click_button 'Create'
flash_message.should == 'Product "A new product !!!" has been successfully created!'
product = Spree::Product.find_by_name('A new product !!!')
product.supplier.should == @supplier2
product.tax_category.should be_nil
end
end
scenario "editing a product" do

View File

@@ -40,7 +40,7 @@ module Spree
describe "tax category" do
context "when a tax category is required" do
before { Spree::Config.products_require_tax_category = true }
around { |example| with_products_require_tax_category(true) { example.run } }
it "is invalid when a tax category is not provided" do
build(:product, tax_category_id: nil).should_not be_valid
@@ -48,7 +48,7 @@ module Spree
end
context "when a tax category is not required" do
before { Spree::Config.products_require_tax_category = false }
around { |example| with_products_require_tax_category(false) { example.run } }
it "is valid when a tax category is not provided" do
build(:product, tax_category_id: nil).should be_valid

View File

@@ -0,0 +1,13 @@
# Large requests can fail if Devise tries to store the URL in the session cookie.
#
# http://daniel.fone.net.nz/blog/2014/11/28/actiondispatch-cookies-cookieoverflow-via-devise-s-user_return_to/
require 'spec_helper'
RSpec.describe 'A very large request', type: :request do
it 'should not overflow cookies' do
get '/admin', foo: 'x' * ActionDispatch::Cookies::SignedCookieJar::MAX_COOKIE_SIZE
expect(response.status).to eq(302) # HTTP status 302 - Found
## Use the newer syntax if rspec gets upgraded
# expect(response).to have_http_status(:redirect)
end
end

View File

@@ -80,6 +80,9 @@ RSpec.configure do |config|
# Geocoding
config.before(:each) { Spree::Address.any_instance.stub(:geocode).and_return([1,1]) }
# Ensure we start with consistent config settings
config.before(:all) { Spree::Config.products_require_tax_category = false }
# Helpers
config.include Rails.application.routes.url_helpers
config.include Spree::UrlHelpers
@@ -91,6 +94,7 @@ RSpec.configure do |config|
config.include OpenFoodNetwork::ControllerHelper, :type => :controller
config.include OpenFoodNetwork::FeatureToggleHelper
config.include OpenFoodNetwork::EnterpriseGroupsHelper
config.include OpenFoodNetwork::ProductsHelper
config.include OpenFoodNetwork::DistributionHelper
config.include OpenFoodNetwork::HtmlHelper
config.include ActionView::Helpers::DateHelper

View File

@@ -0,0 +1,12 @@
module OpenFoodNetwork
module ProductsHelper
def with_products_require_tax_category(value)
original_value = Spree::Config.products_require_tax_category
Spree::Config.products_require_tax_category = value
yield
ensure
Spree::Config.products_require_tax_category = original_value
end
end
end