Merge branch 'master' into product-amount-units

This commit is contained in:
Rohan Mitchell
2014-01-07 16:00:06 +11:00
48 changed files with 202 additions and 209 deletions

View File

@@ -78,7 +78,6 @@ group :test do
end
group :chili do
gem 'enterprises_distributor_info_rich_text_feature', path: 'lib/chili/enterprises_distributor_info_rich_text_feature'
gem 'eaterprises_feature', path: 'lib/chili/eaterprises_feature'
gem 'local_organics_feature', path: 'lib/chili/local_organics_feature'
end

View File

@@ -107,13 +107,6 @@ PATH
chili (~> 3.1)
rails (~> 3.2.11)
PATH
remote: lib/chili/enterprises_distributor_info_rich_text_feature
specs:
enterprises_distributor_info_rich_text_feature (0.0.1)
chili (~> 3.1)
rails (~> 3.2.11)
PATH
remote: lib/chili/local_organics_feature
specs:
@@ -479,7 +472,6 @@ DEPENDENCIES
debugger-linecache
deface!
eaterprises_feature!
enterprises_distributor_info_rich_text_feature!
factory_girl_rails
faker
geocoder

View File

@@ -372,3 +372,10 @@ div#eft-payment-alert {
display: none;
}
/* Distributor details */
.distributor-details .next-collection-at {
font-size: 20px;
font-weight: bold;
color: #de790c;
}

View File

@@ -72,7 +72,8 @@ module Admin
def collection
ocs = OrderCycle.managed_by(spree_current_user)
ocs.soonest_closing +
ocs.undated +
ocs.soonest_closing +
ocs.soonest_opening +
ocs.most_recently_closed
end

View File

@@ -50,6 +50,8 @@ Spree::Admin::ReportsController.class_eval do
@report_types = REPORT_TYPES[:customers]
@report_type = params[:report_type]
@report = OpenFoodNetwork::CustomersReport.new spree_current_user, params
render_report(@report.header, @report.table, params[:csv], "customers.csv")
end
def orders_and_distributors
@@ -557,6 +559,7 @@ Spree::Admin::ReportsController.class_eval do
@report = OpenFoodNetwork::ProductsAndInventoryReport.new spree_current_user, params
#@table = @report.table
#@header = @report.header
render_report(@report.header, @report.table, params[:csv], "products_and_inventory.csv")
end
def render_report (header, table, create_csv, csv_file_name)

View File

@@ -18,7 +18,9 @@ module OrderCyclesHelper
end
def order_cycle_status_class(order_cycle)
if order_cycle.upcoming?
if order_cycle.undated?
'undated'
elsif order_cycle.upcoming?
'upcoming'
elsif order_cycle.open?
'open'

View File

@@ -1,3 +1,13 @@
Spree::OrderMailer.class_eval do
helper HtmlHelper
helper CheckoutHelper
def confirm_email(order, resend = false)
find_order(order)
subject = (resend ? "[#{t(:resend).upcase}] " : '')
subject += "#{Spree::Config[:site_name]} #{t('order_mailer.confirm_email.subject')} ##{@order.number}"
mail(:to => @order.email,
:from => @order.distributor.email || from_address,
:subject => subject,
:cc => "orders@openfoodnetwork.org")
end
end

View File

@@ -16,6 +16,7 @@ class OrderCycle < ActiveRecord::Base
scope :inactive, lambda { where('order_cycles.orders_open_at > ? OR order_cycles.orders_close_at < ?', Time.now, Time.now) }
scope :upcoming, lambda { where('order_cycles.orders_open_at > ?', Time.now) }
scope :closed, lambda { where('order_cycles.orders_close_at < ?', Time.now) }
scope :undated, where(orders_open_at: nil, orders_close_at: nil)
scope :distributing_product, lambda { |product|
joins(:exchanges => :variants).
@@ -111,16 +112,21 @@ class OrderCycle < ActiveRecord::Base
self.variants.include? variant
end
def undated?
self.orders_open_at.nil? && self.orders_close_at.nil?
end
def upcoming?
Time.now < self.orders_open_at
self.orders_open_at && Time.now < self.orders_open_at
end
def open?
Time.now > self.orders_open_at && Time.now < self.orders_close_at
self.orders_open_at && self.orders_close_at &&
Time.now > self.orders_open_at && Time.now < self.orders_close_at
end
def closed?
Time.now > self.orders_close_at
self.orders_close_at && Time.now > self.orders_close_at
end
def exchange_for_distributor(distributor)
@@ -131,6 +137,10 @@ class OrderCycle < ActiveRecord::Base
exchange_for_distributor(distributor).andand.pickup_time || distributor.next_collection_at
end
def pickup_instructions_for(distributor)
exchange_for_distributor(distributor).andand.pickup_instructions
end
# -- Fees
def create_adjustments_for(line_item)

View File

@@ -14,7 +14,7 @@ class AbilityDecorator
user.enterprises.include? product.supplier
end
can [:admin, :index, :read, :create, :edit, :update, :search], Spree::Variant
can [:admin, :index, :read, :create, :edit, :update, :search, :destroy], Spree::Variant
can [:admin, :index, :read, :create, :edit], Spree::ProductProperty
can [:admin, :index, :read, :create, :edit], Spree::Image

View File

@@ -1,4 +1,4 @@
Deface::Override.new(:virtual_path => "spree/admin/shared/_product_sub_menu",
:name => "add_bulk_edit_tab_to_products_admin_sub_menu",
:insert_bottom => "[data-hook='admin_product_sub_tabs']",
:text => "<%= tab :bulk_product_edit, :url => bulk_edit_admin_products_path %>")
:text => "<%= tab :bulk_product_edit, :url => bulk_edit_admin_products_path %>")

View File

@@ -1,4 +1,4 @@
- if Rails.env.staging? or Rails.env.production?
- if Rails.env.staging?
:javascript
(function (d, t) {
var bh = d.createElement(t), s = d.getElementsByTagName(t)[0];
@@ -6,3 +6,12 @@
bh.src = '//www.bugherd.com/sidebarv2.js?apikey=4ftxjbgwx7y6ssykayr04w';
s.parentNode.insertBefore(bh, s);
})(document, 'script');
- elsif Rails.env.production?
:javascript
(function (d, t) {
var bh = d.createElement(t), s = d.getElementsByTagName(t)[0];
bh.type = 'text/javascript';
bh.src = '//www.bugherd.com/sidebarv2.js?apikey=xro3uv55objies58o2wrua';
s.parentNode.insertBefore(bh, s);
})(document, 'script');

View File

@@ -20,7 +20,7 @@
%br
= label_tag nil, "Report Type: "
= select_tag(:report_type, options_for_select(@report_types, @report_type))
= select_tag(:report_type, options_for_select(@report_types, params[:report_type]))
%br
%br

View File

@@ -1,5 +1,5 @@
<%= tab :overview, :route => :admin, :icon => 'icon-dashboard' %>
<%= tab :orders, :payments, :creditcard_payments, :shipments, :credit_cards, :return_authorizations, :url => admin_orders_path('q[s]' => 'completed_at desc'), :icon => 'icon-shopping-cart' %>
<%= tab :products , :option_types, :properties, :prototypes, :variants, :product_properties, :taxons, :icon => 'icon-th-large' %>
<%= tab :products , :option_types, :properties, :prototypes, :variants, :product_properties, :taxons, :url => bulk_edit_admin_products_path, :icon => 'icon-th-large' %>
<%= tab :reports, :icon => 'icon-file' %>
<%= tab :configurations, :general_settings, :mail_methods, :tax_categories, :zones, :states, :payment_methods, :inventory_settings, :taxonomies, :shipping_methods, :trackers, :label => 'configuration', :icon => 'icon-wrench', :url => edit_admin_general_settings_path %>

View File

@@ -5,37 +5,40 @@ Please review and retain the following order information for your records.
============================================================
Order Summary
============================================================
Order for: <%= @order.bill_address.full_name %>
Order for: <%= @order.bill_address.full_name %>
<% @order.line_items.each do |item| %>
<%= item.variant.sku %> <%= raw(item.variant.product.name) %> <%= raw(item.variant.options_text) -%> (<%=item.quantity%>) @ <%= item.single_money %> = <%= item.display_amount %>
<%= item.variant.sku %> <%= raw(item.variant.product.supplier.name) %> <%= raw(item.variant.product.name) %> <%= raw(item.variant.options_text) -%> (<%=item.quantity%>) @ <%= item.single_money %> = <%= item.display_amount %>
<% end %>
============================================================
Subtotal: <%= @order.display_item_total %>
<% @order.adjustments.each do |adjustment| %>
<% checkout_adjustments_for_summary(@order).each do |adjustment| %>
<%= raw(adjustment.label) %> <%= adjustment.display_amount %>
<% end %>
Order Total: <%= @order.display_total %>
<% if @order.payments.first.payment_method.name.include? "EFT" %>
<% if @order.payments.first.andand.payment_method.andand.name.andand.include? "EFT" %>
============================================================
Payment Details
============================================================
<%= @order.payments.first.payment_method.description.html_safe %>
<%= @order.payments.first.andand.payment_method.andand.description.andand.html_safe %>
<% end %>
============================================================
Collection / Delivery Details
============================================================
Address:
<%= @order.distributor.name %>
<% address = @order.distributor.address %>
<%= address.address1 %> <%= ",\n #{address.address2}" unless address.address2.blank? %>
<%= [address.city, address.state_text, address.zipcode, address.country.name].compact.join ', ' %>
Collection time:
<%= @order.distributor.next_collection_at %>
Contact:
<%= @order.distributor.contact %>
<%= "Phone: #{@order.distributor.phone}" %>
<%= "Email: #{@order.distributor.email}" %>
<%= raw strip_html @order.distributor.distributor_info %>
Thank you for your business.
<% if @order.order_cycle %>
<%= @order.order_cycle.pickup_time_for(@order.distributor) %>
<%= @order.order_cycle.pickup_instructions_for(@order.distributor) %>
<% else %>
<%= @order.distributor.next_collection_at %>
<% end %>
Thanks for your support.
<%= @order.distributor.contact %>,
<%= @order.distributor.name %>
<%= @order.distributor.phone %>
<%= @order.distributor.email %>
<%= @order.distributor.website %>

View File

@@ -22,6 +22,7 @@ Spree.config do |config|
# -- spree_paypal_express
# Auto-capture payments. Without this option, payments must be manually captured in the paypal interface.
config.auto_capture = true
#config.override_actionmailer_config = false
end

View File

@@ -1,3 +0,0 @@
.bundle/
log/*.log
pkg/

View File

@@ -1,3 +0,0 @@
= EnterprisesDistributorInfoRichTextFeature
This project rocks and uses MIT-LICENSE.

View File

@@ -1,13 +0,0 @@
// This is a manifest file that'll be compiled into application.js, which will include all the files
// listed below.
//
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
//
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// the compiled file.
//
// WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
// GO AFTER THE REQUIRES BELOW.
//
//= require_tree .

View File

@@ -1,13 +0,0 @@
/*
* This is a manifest file that'll be compiled into application.css, which will include all the files
* listed below.
*
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
* or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
*
* You're free to add application-wide styles to this file and they'll appear at the top of the
* compiled file, but it's generally better to create a new file per style scope.
*
*= require_self
*= require_tree .
*/

View File

@@ -1,5 +0,0 @@
.distributor-details .next-collection-at {
font-size: 20px;
font-weight: bold;
color: #de790c;
}

View File

@@ -1,2 +0,0 @@
<!-- insert_bottom 'head' -->
<%= stylesheet_link_tag 'enterprises_distributor_info_rich_text_feature/application' %>

View File

@@ -1,40 +0,0 @@
Dear <%= @order.bill_address.firstname %>,
Please review and retain the following order information for your records.
============================================================
Order Summary
============================================================
Order for: <%= @order.bill_address.full_name %>
<% @order.line_items.each do |item| %>
<%= item.variant.sku %> <%= raw(item.variant.product.name) %> <%= raw(item.variant.options_text) -%> (<%=item.quantity%>) @ <%= item.single_money %> = <%= item.display_amount %>
<% end %>
============================================================
Subtotal: <%= @order.display_item_total %>
<% checkout_adjustments_for_summary(@order).each do |adjustment| %>
<%= raw(adjustment.label) %> <%= adjustment.display_amount %>
<% end %>
Order Total: <%= @order.display_total %>
<% if @order.payments.first.payment_method.name.include? "EFT" %>
============================================================
Payment Details
============================================================
<%= @order.payments.first.payment_method.description.html_safe %>
<% end %>
============================================================
Collection / Delivery Details
============================================================
<%= raw strip_html @order.distributor.distributor_info %>
<% if @order.order_cycle %>
<%= @order.order_cycle.pickup_time_for(@order.distributor) %>
<% else %>
<%= @order.distributor.next_collection_at %>
<% end %>
Thanks for your support.
<%= @order.distributor.contact %>,
<%= @order.distributor.name %>

View File

@@ -1,3 +0,0 @@
EnterprisesDistributorInfoRichTextFeature::Engine.automount!
EnterprisesDistributorInfoRichTextFeature::Engine.routes.draw do
end

View File

@@ -1,5 +0,0 @@
class AddDistributorInfoToEnterprises < ActiveRecord::Migration
def change
add_column :enterprises, :distributor_info, :text
end
end

View File

@@ -1,22 +0,0 @@
$:.push File.expand_path("../lib", __FILE__)
# Maintain your gem's version:
require "enterprises_distributor_info_rich_text_feature/version"
# Describe your gem and declare its dependencies:
Gem::Specification.new do |s|
s.name = "enterprises_distributor_info_rich_text_feature"
s.version = EnterprisesDistributorInfoRichTextFeature::VERSION
s.authors = ["Rohan Mitchell"]
s.email = ["rohan@rohanmitchell.com"]
s.homepage = ""
s.summary = "Summary of EnterprisesDistributorInfoRichTextFeature."
s.description = "Description of EnterprisesDistributorInfoRichTextFeature."
s.files = Dir["{app,config,db,lib}/**/*"] + ["README.rdoc"]
s.add_dependency "rails", "~> 3.2.11"
s.add_dependency 'chili', '~> 3.1'
s.add_development_dependency "sqlite3"
end

View File

@@ -1,7 +0,0 @@
require "chili"
require "enterprises_distributor_info_rich_text_feature/engine"
module EnterprisesDistributorInfoRichTextFeature
extend Chili::Base
active_if { OpenFoodNetwork::FeatureToggle.enabled? :enterprises_distributor_info_rich_text }
end

View File

@@ -1,23 +0,0 @@
require_relative '../../../../open_food_network/feature_toggle'
module EnterprisesDistributorInfoRichTextFeature
class Engine < ::Rails::Engine
isolate_namespace EnterprisesDistributorInfoRichTextFeature
initializer 'enterprises_distributor_info_rich_text_feature.mailer', :after => :load_config_initializers do |app|
if OpenFoodNetwork::FeatureToggle.enabled? :enterprises_distributor_info_rich_text
::Spree::OrderMailer.class_eval do
helper CheckoutHelper
def confirm_email(order, resend = false)
find_order(order)
subject = (resend ? "[#{t(:resend).upcase}] " : '')
subject += "#{Spree::Config[:site_name]} #{t('order_mailer.confirm_email.subject')} ##{@order.number}"
mail(:to => @order.email, :from => from_address, :subject => subject,
:template_name => 'confirm_email_with_distributor_info')
end
end
end
end
end
end

View File

@@ -1,3 +0,0 @@
module EnterprisesDistributorInfoRichTextFeature
VERSION = "0.0.1"
end

View File

@@ -1,3 +0,0 @@
class EnterprisesDistributorInfoRichTextFeatureGenerator < Rails::Generators::Base
include Chili::GeneratorProxy
end

View File

@@ -8,17 +8,29 @@ module OpenFoodNetwork
end
def header
["Supplier", "Product", "SKU", "Variant", "On Hand", "Price"]
[
"Supplier",
"Producer Suburb",
"Product",
"Product Properties",
"Variant Value",
"Price",
"Group Buy Unit Quantity",
"Amount"
]
end
def table
variants.map do |variant|
[variant.product.supplier.name,
variant.product.name,
variant.sku,
variant.options_text,
variant.count_on_hand,
variant.price]
variant.product.supplier.address.city,
variant.product.name,
variant.product.properties.map(&:name).join(", "),
variant.options_text,
variant.price,
variant.product.group_buy_unit_size,
""
]
end
end

View File

@@ -190,6 +190,8 @@ describe Spree::Admin::ReportsController do
OpenFoodNetwork::ProductsAndInventoryReport.should_receive(:new)
.with(user, {"test"=>"foo", "controller"=>"spree/admin/reports", "action"=>"products_and_inventory"})
.and_return(report = double(:report))
report.stub(:header).and_return []
report.stub(:table).and_return []
spree_get :products_and_inventory, :test => "foo"
assigns(:report).should == report
end
@@ -236,6 +238,8 @@ describe Spree::Admin::ReportsController do
OpenFoodNetwork::CustomersReport.should_receive(:new)
.with(user, {"test"=>"foo", "controller"=>"spree/admin/reports", "action"=>"customers"})
.and_return(report = double(:report))
report.stub(:header).and_return []
report.stub(:table).and_return []
spree_get :customers, :test => "foo"
assigns(:report).should == report
end

View File

@@ -29,6 +29,8 @@ feature %q{
oc5 = create(:simple_order_cycle, name: '5',
orders_open_at: 1.month.ago, orders_close_at: 2.weeks.ago)
oc1 = create(:order_cycle, name: '1')
oc0 = create(:simple_order_cycle, name: '0',
orders_open_at: nil, orders_close_at: nil)
# When I go to the admin order cycles page
login_to_admin_section
@@ -36,9 +38,10 @@ feature %q{
# Then the order cycles should be ordered correctly
page.all('#listing_order_cycles tr td:first-child').map(&:text).should ==
['1', '2', '3', '4', '5', '6']
['0', '1', '2', '3', '4', '5', '6']
# And the rows should have the correct classes
page.should have_selector "#listing_order_cycles tr.order-cycle-#{oc0.id}.undated"
page.should have_selector "#listing_order_cycles tr.order-cycle-#{oc1.id}.open"
page.should have_selector "#listing_order_cycles tr.order-cycle-#{oc2.id}.open"
page.should have_selector "#listing_order_cycles tr.order-cycle-#{oc3.id}.upcoming"
@@ -47,7 +50,8 @@ feature %q{
page.should have_selector "#listing_order_cycles tr.order-cycle-#{oc6.id}.closed"
# And I should see all the details for an order cycle
within('table#listing_order_cycles tbody tr:first-child') do
# (the table includes a hidden field between each row, making this nth-child(3) instead of 2)
within('table#listing_order_cycles tbody tr:nth-child(3)') do
# Then I should see the basic fields
page.should have_selector 'a', text: oc1.name

View File

@@ -104,6 +104,7 @@ feature %q{
product = create(:simple_product, supplier: @supplier2)
click_link 'Products'
within('#sub_nav') { click_link 'Products' }
click_link product.name
within('#sidebar') { click_link 'Product Distributions' }

View File

@@ -143,13 +143,12 @@ feature %q{
table = rows.map { |r| r.all("th,td").map { |c| c.text.strip } }
table.sort.should == [
["Supplier", "Product", "SKU", "Variant", "On Hand", "Price"],
[product_1.supplier.name, "Product Name", variant_1.sku, "Size: Test", "10", "100.0"],
[product_1.supplier.name, "Product Name", variant_2.sku, "Size: S", "20", "80.0"],
[product_2.supplier.name, "Product 2", product_2.master.sku, "", "9", "99.0"]
["Supplier", "Producer Suburb", "Product", "Product Properties", "Variant Value", "Price", "Group Buy Unit Quantity", "Amount"],
[product_1.supplier.name, product_1.supplier.address.city, "Product Name", product_1.properties.join(", "), "Size: Test", "100.0", product_1.group_buy_unit_size.to_s, ""],
[product_1.supplier.name, product_1.supplier.address.city, "Product Name", product_1.properties.join(", "), "Size: S", "80.0", product_1.group_buy_unit_size.to_s, ""],
[product_2.supplier.name, product_1.supplier.address.city, "Product 2", product_1.properties.join(", "), "", "99.0", product_1.group_buy_unit_size.to_s, ""]
].sort
end
end
end

View File

@@ -10,9 +10,16 @@ feature "enterprises distributor info as rich text" do
enterprises_distributor_info_rich_text: true})
ActionMailer::Base.delivery_method = :test
ActionMailer::Base.perform_deliveries = true
ActionMailer::Base.deliveries = []
# The deployment is not set to local_organics on Rails init, so these
#
# initializers won't run. Re-call them now that the deployment is set.
EnterprisesDistributorInfoRichTextFeature::Engine.initializers.each &:run
end
after do
ActionMailer::Base.deliveries.clear
end

View File

@@ -348,7 +348,7 @@ feature %q{
# -- Checkout: Email
email = ActionMailer::Base.deliveries.last
email.body.should =~ /Distribution \$12.00/
email.body.should =~ /Distribution[\s+]\$12.00/
end
scenario "buying a product from an order cycle", :js => true do
@@ -414,7 +414,8 @@ feature %q{
# -- Checkout: Email
email = ActionMailer::Base.deliveries.last
email.body.should =~ /Distribution \$54.00/
email.from.include?(@distributor_oc.email).should == true
email.body.should =~ /Distribution[\s+]\$54.00/
end
scenario "when I have past orders, it fills in my address", :js => true do
@@ -497,7 +498,7 @@ feature %q{
# -- Checkout: Email
email = ActionMailer::Base.deliveries.last
email.body.should =~ /Distribution \$54.00/
email.body.should =~ /Distribution[\s+]\$54.00/
end

View File

@@ -32,4 +32,5 @@ describe OrderCyclesHelper do
helper.stub!(:current_distributor).and_return d
helper.pickup_time.should == "turtles"
end
end

View File

@@ -13,24 +13,40 @@ module OpenFoodNetwork
end
it "Should return headers" do
subject.header.should == ["Supplier", "Product", "SKU", "Variant", "On Hand", "Price"]
subject.header.should == [
"Supplier",
"Producer Suburb",
"Product",
"Product Properties",
"Variant Value",
"Price",
"Group Buy Unit Quantity",
"Amount"
]
end
it "should build a table from a list of variants" do
variant = double(:variant, sku: "sku",
options_text: "Variant Name",
count_on_hand: 10,
price: 100)
options_text: "Variant Name",
count_on_hand: 10,
price: 100)
variant.stub_chain(:product, :supplier, :name).and_return("Supplier")
variant.stub_chain(:product, :supplier, :address, :city).and_return("A city")
variant.stub_chain(:product, :name).and_return("Product Name")
variant.stub_chain(:product, :properties).and_return [double(name: "test"), double(name: "foo")]
variant.stub_chain(:product, :group_buy_unit_size).and_return(21)
subject.stub(:variants).and_return [variant]
subject.table.should == [[
"Supplier",
"A city",
"Product Name",
"sku",
"test, foo",
"Variant Name",
10,
100]]
100,
21,
""
]]
end
it "fetches variants for some params" do

View File

@@ -0,0 +1,36 @@
require 'spec_helper'
describe Spree::OrderMailer do
after do
ActionMailer::Base.deliveries.clear
end
before do
ActionMailer::Base.delivery_method = :test
ActionMailer::Base.perform_deliveries = true
ActionMailer::Base.deliveries = []
@bill_address = create(:address)
@distributor_address = create(:address, :address1 => "distributor address", :city => 'The Shire', :zipcode => "1234")
@distributor = create(:distributor_enterprise, :address => @distributor_address)
product = create(:product)
product_distribution = create(:product_distribution, :product => product, :distributor => @distributor)
@shipping_instructions = "pick up on thursday please!"
@order1 = create(:order, :distributor => @distributor, :bill_address => @bill_address, :special_instructions => @shipping_instructions)
end
it "should send an email when given an order" do
Spree::OrderMailer.confirm_email(@order1.id).deliver
ActionMailer::Base.deliveries.count.should == 1
end
it "should send the email from the enterprise email" do
Spree::OrderMailer.confirm_email(@order1.id).deliver
ActionMailer::Base.deliveries.first.from.should == [@distributor.email]
end
it "should cc orders" do
Spree::OrderMailer.confirm_email(@order1.id).deliver
ActionMailer::Base.deliveries.first.cc.should == ["orders@openfoodnetwork.org"]
end
end

View File

@@ -81,12 +81,12 @@ describe Exchange do
it "finds exchanges going to any of a number of enterprises" do
Exchange.to_enterprises([coordinator]).should == [incoming_exchange]
Exchange.to_enterprises([coordinator, distributor]).should == [incoming_exchange, outgoing_exchange]
Exchange.to_enterprises([coordinator, distributor]).sort.should == [incoming_exchange, outgoing_exchange].sort
end
it "finds exchanges coming from any of a number of enterprises" do
Exchange.from_enterprises([coordinator]).should == [outgoing_exchange]
Exchange.from_enterprises([supplier, coordinator]).should == [incoming_exchange, outgoing_exchange]
Exchange.from_enterprises([supplier, coordinator]).sort.should == [incoming_exchange, outgoing_exchange].sort
end
it "finds exchanges with a particular variant" do

View File

@@ -34,11 +34,13 @@ describe OrderCycle do
oc_active = create(:simple_order_cycle, orders_open_at: 1.week.ago, orders_close_at: 1.week.from_now)
oc_not_yet_open = create(:simple_order_cycle, orders_open_at: 1.week.from_now, orders_close_at: 2.weeks.from_now)
oc_already_closed = create(:simple_order_cycle, orders_open_at: 2.weeks.ago, orders_close_at: 1.week.ago)
oc_undated = create(:simple_order_cycle, orders_open_at: nil, orders_close_at: nil)
OrderCycle.active.should == [oc_active]
OrderCycle.inactive.sort.should == [oc_not_yet_open, oc_already_closed].sort
OrderCycle.upcoming.should == [oc_not_yet_open]
OrderCycle.closed.should == [oc_already_closed]
OrderCycle.undated.should == [oc_undated]
end
it "finds order cycles accessible by a user" do
@@ -223,7 +225,7 @@ describe OrderCycle do
@d2 = create(:enterprise, next_collection_at: '2-8pm Friday')
@e0 = create(:exchange, order_cycle: @oc, sender: create(:enterprise), receiver: @oc.coordinator)
@e1 = create(:exchange, order_cycle: @oc, sender: @oc.coordinator, receiver: @d1, pickup_time: '5pm Tuesday')
@e1 = create(:exchange, order_cycle: @oc, sender: @oc.coordinator, receiver: @d1, pickup_time: '5pm Tuesday', pickup_instructions: "Come get it!")
@e2 = create(:exchange, order_cycle: @oc, sender: @oc.coordinator, receiver: @d2, pickup_time: nil)
end
@@ -241,6 +243,12 @@ describe OrderCycle do
@oc.pickup_time_for(@d2).should == '2-8pm Friday'
end
end
describe "finding pickup instructions for a distributor" do
it "returns the pickup instructions" do
@oc.pickup_instructions_for(@d1).should == "Come get it!"
end
end
end
describe "checking status" do
@@ -248,6 +256,7 @@ describe OrderCycle do
it "reports status when an order cycle is upcoming" do
Timecop.freeze(oc.orders_open_at - 1.second) do
oc.should_not be_undated
oc.should be_upcoming
oc.should_not be_open
oc.should_not be_closed
@@ -255,6 +264,7 @@ describe OrderCycle do
end
it "reports status when an order cycle is open" do
oc.should_not be_undated
oc.should_not be_upcoming
oc.should be_open
oc.should_not be_closed
@@ -262,11 +272,21 @@ describe OrderCycle do
it "reports status when an order cycle has closed" do
Timecop.freeze(oc.orders_close_at + 1.second) do
oc.should_not be_undated
oc.should_not be_upcoming
oc.should_not be_open
oc.should be_closed
end
end
it "reports status when an order cycle is undated" do
oc.update_attributes!(orders_open_at: nil, orders_close_at: nil)
oc.should be_undated
oc.should_not be_upcoming
oc.should_not be_open
oc.should_not be_closed
end
end
it "clones itself" do

View File

@@ -44,7 +44,7 @@ module Spree
end
it "should be able to read/write their enterprises' product variants" do
should have_ability([:admin, :index, :read, :create, :edit, :search, :update], for: Spree::Variant)
should have_ability([:admin, :index, :read, :create, :edit, :search, :update, :destroy], for: Spree::Variant)
end
it "should be able to read/write their enterprises' product properties" do