mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Merge master (with primary taxons restored)
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
Darkswarm.controller "AccordionCtrl", ($scope, storage) ->
|
||||
Darkswarm.controller "AccordionCtrl", ($scope, storage, $timeout) ->
|
||||
$scope.accordion =
|
||||
details: true
|
||||
shipping: false
|
||||
@@ -9,3 +9,8 @@ Darkswarm.controller "AccordionCtrl", ($scope, storage) ->
|
||||
$scope.show = (name)->
|
||||
$scope.accordion[name] = true
|
||||
|
||||
$timeout =>
|
||||
if $scope.checkout.$valid
|
||||
for k, v of $scope.accordion
|
||||
$scope.accordion[k] = false
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
Darkswarm.controller "DetailsCtrl", ($scope) ->
|
||||
angular.extend(this, new FieldsetMixin($scope))
|
||||
|
||||
$scope.name = "details"
|
||||
$scope.nextPanel = "billing"
|
||||
|
||||
@@ -11,11 +12,3 @@ Darkswarm.controller "DetailsCtrl", ($scope) ->
|
||||
$scope.fullName = ->
|
||||
[$scope.order.bill_address.firstname ? null,
|
||||
$scope.order.bill_address.lastname ? null].join(" ").trim()
|
||||
|
||||
|
||||
#$scope.$watch ->
|
||||
#$scope.detailsValid()
|
||||
#, (valid)->
|
||||
#if valid
|
||||
#$scope.show("billing")
|
||||
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
Darkswarm.factory 'CheckoutFormState', ()->
|
||||
# Just a singleton place to store data about the form statr
|
||||
# Just a singleton place to store data about the form state
|
||||
new class CheckoutFormState
|
||||
|
||||
@@ -27,7 +27,6 @@
|
||||
margin-right: 12px
|
||||
location
|
||||
font-family: "AvenirBla_IE", "AvenirBla"
|
||||
padding-right: 16px
|
||||
@media all and (max-width: 768px)
|
||||
location, location + small
|
||||
display: block
|
||||
@@ -58,21 +57,23 @@
|
||||
@media all and (max-width: 768px)
|
||||
font-size: 1.2em
|
||||
select
|
||||
width: 280px
|
||||
width: inherit
|
||||
display: inline-block
|
||||
vackground: transparent
|
||||
border-width: 2px
|
||||
border-color: #666666
|
||||
border-width: 1px
|
||||
border-color: #999
|
||||
color: #666
|
||||
font-size: 1em
|
||||
margin-bottom: 0
|
||||
padding: 8px 0px 8px 12px
|
||||
padding: 8px 20px 8px 12px
|
||||
@media all and (max-width: 768px)
|
||||
font-size: 1.2em
|
||||
width: 180px
|
||||
// width: 180px
|
||||
closing
|
||||
font-size: 0.875em
|
||||
color: black
|
||||
font-size: 1.5em
|
||||
display: block
|
||||
padding-top: 14px
|
||||
padding-bottom: 20px
|
||||
|
||||
products
|
||||
display: block
|
||||
|
||||
@@ -4,6 +4,11 @@ class ApplicationController < ActionController::Base
|
||||
|
||||
include EnterprisesHelper
|
||||
|
||||
def redirect_to(options = {}, response_status = {})
|
||||
::Rails.logger.error("Redirected by #{caller(1).first rescue "unknown"}")
|
||||
super(options, response_status)
|
||||
end
|
||||
|
||||
def after_sign_in_path_for(resource)
|
||||
if request.referer and referer_path = URI(request.referer).path
|
||||
[main_app.checkout_path].include?(referer_path) ? referer_path : root_path
|
||||
|
||||
@@ -11,4 +11,16 @@ Spree::Admin::BaseController.class_eval do
|
||||
authorize! :admin, record
|
||||
authorize! action, record
|
||||
end
|
||||
|
||||
# This is in Spree::Core::ControllerHelpers::Auth
|
||||
# But you can't easily reopen modules in Ruby
|
||||
def unauthorized
|
||||
if try_spree_current_user
|
||||
flash[:error] = t(:authorization_failure)
|
||||
redirect_to '/unauthorized'
|
||||
else
|
||||
store_location
|
||||
redirect_to root_path(anchor: "login?after_login=#{request.env['PATH_INFO']}")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -15,11 +15,10 @@ Spree::Admin::OrdersController.class_eval do
|
||||
per(params[:per_page] || Spree::Config[:orders_per_page])
|
||||
} } }
|
||||
|
||||
|
||||
private
|
||||
|
||||
def load_spree_api_key
|
||||
current_user.generate_spree_api_key! unless spree_current_user.spree_api_key
|
||||
@spree_api_key = spree_current_user.spree_api_key
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -4,16 +4,5 @@ Spree::Admin::OverviewController.class_eval do
|
||||
@product_count = Spree::Product.active.managed_by(spree_current_user).count
|
||||
@order_cycle_count = OrderCycle.active.managed_by(spree_current_user).count
|
||||
end
|
||||
|
||||
# This is in Spree::Core::ControllerHelpers::Auth
|
||||
# But you can't easily reopen modules in Ruby
|
||||
def unauthorized
|
||||
if try_spree_current_user
|
||||
flash[:error] = t(:authorization_failure)
|
||||
redirect_to '/unauthorized'
|
||||
else
|
||||
store_location
|
||||
redirect_to root_path(anchor: "login?after_login=#{spree.admin_path}")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -15,11 +15,12 @@ class Enterprise < ActiveRecord::Base
|
||||
has_and_belongs_to_many :payment_methods, join_table: 'distributors_payment_methods', class_name: 'Spree::PaymentMethod', foreign_key: 'distributor_id'
|
||||
has_and_belongs_to_many :shipping_methods, join_table: 'distributors_shipping_methods', class_name: 'Spree::ShippingMethod', foreign_key: 'distributor_id'
|
||||
|
||||
|
||||
delegate :latitude, :longitude, :city, :state_name, :to => :address
|
||||
|
||||
accepts_nested_attributes_for :address
|
||||
has_attached_file :logo, :styles => { :medium => "300x300>", :thumb => "100x100>" }
|
||||
has_attached_file :promo_image, :styles => { :large => "260x1200#", :thumb => "100x100>" }
|
||||
has_attached_file :promo_image, :styles => { :large => "1200x260#", :thumb => "100x100>" }
|
||||
|
||||
validates_presence_of :name
|
||||
validates_presence_of :address
|
||||
|
||||
@@ -9,7 +9,7 @@ class EnterpriseGroup < ActiveRecord::Base
|
||||
attr_accessible :name, :description, :long_description, :on_front_page, :enterprise_ids
|
||||
|
||||
attr_accessible :promo_image
|
||||
has_attached_file :promo_image, styles: {large: "260x1200#"}
|
||||
has_attached_file :promo_image, styles: {large: "1200x260#"}
|
||||
validates_attachment_content_type :promo_image, :content_type => /\Aimage\/.*\Z/
|
||||
|
||||
attr_accessible :logo
|
||||
|
||||
10
app/models/spree/classification_decorator.rb
Normal file
10
app/models/spree/classification_decorator.rb
Normal file
@@ -0,0 +1,10 @@
|
||||
Spree::Classification.class_eval do
|
||||
before_destroy :dont_destroy_if_primary_taxon
|
||||
|
||||
def dont_destroy_if_primary_taxon
|
||||
if product.primary_taxon == taxon
|
||||
errors.add :base, "Taxon #{taxon.name} is the primary taxon of #{product.name} and cannot be deleted"
|
||||
return false
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -5,6 +5,7 @@ Spree::Product.class_eval do
|
||||
has_many :option_types, :through => :product_option_types, :dependent => :destroy
|
||||
|
||||
belongs_to :supplier, :class_name => 'Enterprise'
|
||||
belongs_to :primary_taxon, class_name: 'Spree::Taxon'
|
||||
|
||||
has_many :product_distributions, :dependent => :destroy
|
||||
has_many :distributors, :through => :product_distributions
|
||||
@@ -13,9 +14,10 @@ Spree::Product.class_eval do
|
||||
delegate_belongs_to :master, :unit_value, :unit_description
|
||||
delegate :images_attributes=, to: :master
|
||||
|
||||
attr_accessible :supplier_id, :distributor_ids, :product_distributions_attributes, :group_buy, :group_buy_unit_size, :variant_unit, :variant_unit_scale, :variant_unit_name, :unit_value, :unit_description, :notes, :images_attributes
|
||||
attr_accessible :supplier_id, :primary_taxon_id, :distributor_ids, :product_distributions_attributes, :group_buy, :group_buy_unit_size, :variant_unit, :variant_unit_scale, :variant_unit_name, :unit_value, :unit_description, :notes, :images_attributes
|
||||
|
||||
validates_presence_of :supplier
|
||||
validates_presence_of :primary_taxon
|
||||
|
||||
validates_presence_of :variant_unit, if: :has_variants?
|
||||
validates_presence_of :variant_unit_scale,
|
||||
@@ -25,6 +27,7 @@ Spree::Product.class_eval do
|
||||
|
||||
after_initialize :set_available_on_to_now, :if => :new_record?
|
||||
after_save :update_units
|
||||
before_save :add_primary_taxon_to_taxons
|
||||
|
||||
|
||||
# -- Joins
|
||||
@@ -124,10 +127,6 @@ Spree::Product.class_eval do
|
||||
order_cycle.variants_distributed_by(distributor).where(product_id: self)
|
||||
end
|
||||
|
||||
def primary_taxon
|
||||
self.taxons.order.first
|
||||
end
|
||||
|
||||
# Build a product distribution for each distributor
|
||||
def build_product_distributions_for_user user
|
||||
Enterprise.is_distributor.managed_by(user).each do |distributor|
|
||||
@@ -163,6 +162,10 @@ Spree::Product.class_eval do
|
||||
end
|
||||
end
|
||||
|
||||
def add_primary_taxon_to_taxons
|
||||
taxons << primary_taxon unless taxons.find_by_id(primary_taxon)
|
||||
end
|
||||
|
||||
def self.all_variant_unit_option_types
|
||||
Spree::OptionType.where('name LIKE ?', 'unit_%%')
|
||||
end
|
||||
|
||||
4
app/overrides/add_primary_taxon_to_admin_product.rb
Normal file
4
app/overrides/add_primary_taxon_to_admin_product.rb
Normal file
@@ -0,0 +1,4 @@
|
||||
Deface::Override.new(:virtual_path => "spree/admin/products/_form",
|
||||
:insert_top => "[data-hook='admin_product_form_right']",
|
||||
:partial => "spree/admin/products/primary_taxon_form",
|
||||
:name => "add_primary_taxon_to_admin_product")
|
||||
4
app/overrides/add_primary_taxon_to_admin_product_new.rb
Normal file
4
app/overrides/add_primary_taxon_to_admin_product_new.rb
Normal file
@@ -0,0 +1,4 @@
|
||||
Deface::Override.new(:virtual_path => "spree/admin/products/new",
|
||||
:insert_before => "[data-hook='new_product_attrs']",
|
||||
:partial => "spree/admin/products/primary_taxon_form",
|
||||
:name => "add_primary_taxon_to_admin_product_new")
|
||||
@@ -4,4 +4,3 @@
|
||||
= f.label :notes, t(:notes)
|
||||
= f.text_area :notes, { :class => 'fullwidth', rows: 5 }
|
||||
= f.error_message_on :notes
|
||||
|
||||
|
||||
@@ -177,5 +177,5 @@
|
||||
%a What's this?
|
||||
|
||||
.omega.eight.columns
|
||||
= image_tag @object.promo_image.url if @object.promo_image.present?
|
||||
= image_tag @object.promo_image(:large) if @object.promo_image.present?
|
||||
= f.file_field :promo_image
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
%fieldset#billing
|
||||
%ng-form{"ng-controller" => "BillingCtrl", name: "billing"}
|
||||
|
||||
%h5{"ng-class" => "{valid: billing.$valid, dirty: details.$dirty}"}
|
||||
%h5{"ng-class" => "{valid: billing.$valid, dirty: billing.$dirty}"}
|
||||
%span.right
|
||||
%label.label.round.alert
|
||||
%i.fi-x
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
%fieldset#payment
|
||||
%ng-form{"ng-controller" => "PaymentCtrl", name: "payment"}
|
||||
|
||||
%h5{"ng-class" => "{valid: payment.$valid, dirty: details.$dirty}"}
|
||||
%h5{"ng-class" => "{valid: payment.$valid, dirty: payment.$dirty}"}
|
||||
%span.right
|
||||
%label.label.round.alert
|
||||
%i.fi-x
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
%fieldset#shipping
|
||||
%ng-form{"ng-controller" => "ShippingCtrl", name: "shipping"}
|
||||
|
||||
%h5{"ng-class" => "{valid: shipping.$valid, dirty: details.$dirty}"}
|
||||
%h5{"ng-class" => "{valid: shipping.$valid, dirty: shipping.$dirty}"}
|
||||
%span.right
|
||||
%label.label.round.alert
|
||||
%i.fi-x
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
%div{"bo-if" => "hasVariants"}
|
||||
= render partial: "shop/products/variants"
|
||||
|
||||
.variant.row{"bo-if" => "!hasVariants"}
|
||||
.variants.row{"bo-if" => "!hasVariants"}
|
||||
= render partial: "shop/products/master"
|
||||
|
||||
.row
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
.small-1.column
|
||||
.small-1.columns
|
||||
%span.bulk{"bo-if" => "product.group_buy"} bulk
|
||||
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
.row.summary
|
||||
.small-1.column
|
||||
.small-1.columns
|
||||
%img{"bo-src" => "product.master.images[0].small_url"}
|
||||
|
||||
.small-4.columns.summary-header
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
.row.variants{bindonce: true,
|
||||
"ng-repeat" => "variant in product.variants"}
|
||||
|
||||
.small-1.column
|
||||
.small-1.columns
|
||||
%span.bulk{"bo-if" => "product.group_buy"} bulk
|
||||
|
||||
|
||||
|
||||
@@ -2,15 +2,20 @@
|
||||
- content_for :order_cycle_form do
|
||||
|
||||
%div{"ng-controller" => "OrderCycleChangeCtrl"}
|
||||
%strong.avenir Ready for
|
||||
%closing{"ng-if" => "OrderCycle.selected()"}
|
||||
Next order closing
|
||||
%strong {{ OrderCycle.orders_close_at() | date_in_words }}
|
||||
|
||||
%span Ready for pickup
|
||||
|
||||
/ Will this label should be a variable to reflect pickup or delivery as appropriate
|
||||
|
||||
%select.avenir#order_cycle_id{"ng-model" => "order_cycle.order_cycle_id",
|
||||
"ng-change" => "changeOrderCycle()",
|
||||
"ng-options" => "oc.id as oc.time for oc in #{@order_cycles.map {|oc| {time: pickup_time(oc), id: oc.id}}.to_json}",
|
||||
"popover-placement" => "bottom", "popover" => "When do you want to get your order?", "popover-trigger" => "openTrigger"}
|
||||
|
||||
%closing{"ng-if" => "OrderCycle.selected()"}
|
||||
Orders close
|
||||
%strong {{ OrderCycle.orders_close_at() | date_in_words }}
|
||||
|
||||
|
||||
= render partial: "shopping_shared/details"
|
||||
|
||||
|
||||
@@ -2,11 +2,10 @@
|
||||
%distributor.details.row
|
||||
#distributor_title
|
||||
%img.left{src: current_distributor.logo.url(:thumb)}
|
||||
%h4
|
||||
%h3
|
||||
= current_distributor.name
|
||||
%location= current_distributor.address.city
|
||||
%small
|
||||
%a{href: "/"} Change location
|
||||
/ Will this needs to be a drop-down to choose either pick-up point or delivery once shipping methods are implemented
|
||||
|
||||
= render partial: "shopping_shared/order_cycles"
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#tabs{"ng-controller" => "TabsCtrl"}
|
||||
.row
|
||||
%tabset
|
||||
- for name, heading in { about: "About Us",
|
||||
- for name, heading in { about: "About #{current_distributor.name}",
|
||||
producers: "Producers",
|
||||
groups: "Groups",
|
||||
contact: "Contact"}
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
Paperclip::Attachment.default_options[:convert_options] = {
|
||||
Paperclip::Attachment.default_options[:source_file_options] = {
|
||||
all: "-auto-orient"
|
||||
}
|
||||
|
||||
@@ -1,7 +1,15 @@
|
||||
class AddPrimaryTaxonToProducts < ActiveRecord::Migration
|
||||
def change
|
||||
add_column :spree_products, :primary_taxon_id, :integer
|
||||
<<<<<<< HEAD
|
||||
<<<<<<< HEAD
|
||||
add_index :spree_products, :primary_taxon_id
|
||||
add_foreign_key :spree_products, :spree_taxons, column: :primary_taxon_id
|
||||
=======
|
||||
>>>>>>> fd1e7eb... Adding primary taxon field to product
|
||||
=======
|
||||
add_index :spree_products, :primary_taxon_id
|
||||
add_foreign_key :spree_products, :spree_taxons, column: :primary_taxon_id
|
||||
>>>>>>> 110a6f2... Adding primary taxon to admin forms
|
||||
end
|
||||
end
|
||||
|
||||
15
spec/controllers/spree/admin/base_controller_spec.rb
Normal file
15
spec/controllers/spree/admin/base_controller_spec.rb
Normal file
@@ -0,0 +1,15 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe Spree::Admin::BaseController do
|
||||
controller(Spree::Admin::BaseController) do
|
||||
def index
|
||||
before_filter :unauthorized
|
||||
render text: ""
|
||||
end
|
||||
end
|
||||
|
||||
it "redirects to Angular login" do
|
||||
get :index
|
||||
response.should redirect_to root_path(anchor: "login?after_login=/anonymous")
|
||||
end
|
||||
end
|
||||
@@ -2,6 +2,9 @@ require 'ffaker'
|
||||
require 'spree/core/testing_support/factories'
|
||||
|
||||
FactoryGirl.define do
|
||||
factory :classification, class: Spree::Classification do
|
||||
end
|
||||
|
||||
factory :order_cycle, :parent => :simple_order_cycle do
|
||||
coordinator_fees { [create(:enterprise_fee, enterprise: coordinator)] }
|
||||
|
||||
@@ -150,6 +153,9 @@ end
|
||||
|
||||
|
||||
FactoryGirl.modify do
|
||||
factory :product do
|
||||
primary_taxon { Spree::Taxon.first || FactoryGirl.create(:taxon) }
|
||||
end
|
||||
factory :simple_product do
|
||||
# Fix product factory name sequence with Kernel.rand so it is not interpreted as a Spree::Product method
|
||||
# Pull request: https://github.com/spree/spree/pull/1964
|
||||
@@ -157,6 +163,7 @@ FactoryGirl.modify do
|
||||
sequence(:name) { |n| "Product ##{n} - #{Kernel.rand(9999)}" }
|
||||
|
||||
supplier { Enterprise.is_primary_producer.first || FactoryGirl.create(:supplier_enterprise) }
|
||||
primary_taxon { Spree::Taxon.first || FactoryGirl.create(:taxon) }
|
||||
on_hand 3
|
||||
|
||||
variant_unit 'weight'
|
||||
|
||||
15
spec/features/admin/authentication_spec.rb
Normal file
15
spec/features/admin/authentication_spec.rb
Normal file
@@ -0,0 +1,15 @@
|
||||
require 'spec_helper'
|
||||
|
||||
feature "Authentication", js: true do
|
||||
include UIComponentHelper
|
||||
let(:user) { create(:user, password: "password", password_confirmation: "password") }
|
||||
|
||||
scenario "logging into admin redirects home, then back to admin" do
|
||||
visit spree.admin_path
|
||||
fill_in "Email", with: user.email
|
||||
fill_in "Password", with: user.password
|
||||
click_login_button
|
||||
page.should have_content "Dashboard"
|
||||
current_path.should == spree.admin_path
|
||||
end
|
||||
end
|
||||
@@ -223,20 +223,19 @@ feature %q{
|
||||
scenario "creating a new product" do
|
||||
s = FactoryGirl.create(:supplier_enterprise)
|
||||
d = FactoryGirl.create(:distributor_enterprise)
|
||||
taxon = create(:taxon)
|
||||
|
||||
login_to_admin_section
|
||||
|
||||
visit '/admin/products/bulk_edit'
|
||||
|
||||
#save_screenshot "/Users/willmarshall/Desktop/foo.png"
|
||||
#save_and_open_page
|
||||
find("a", text: "NEW PRODUCT").click
|
||||
|
||||
page.should have_content 'NEW PRODUCT'
|
||||
|
||||
fill_in 'product_name', :with => 'Big Bag Of Apples'
|
||||
select(s.name, :from => 'product_supplier_id')
|
||||
fill_in 'product_price', :with => '10.00'
|
||||
select taxon.name, from: 'product_primary_taxon_id'
|
||||
click_button 'Create'
|
||||
|
||||
URI.parse(current_url).path.should == '/admin/products/bulk_edit'
|
||||
|
||||
@@ -6,6 +6,7 @@ feature %q{
|
||||
} do
|
||||
include AuthenticationWorkflow
|
||||
include WebHelper
|
||||
let!(:taxon) { create(:taxon) }
|
||||
|
||||
background do
|
||||
@supplier = create(:supplier_enterprise, :name => 'New supplier')
|
||||
@@ -22,6 +23,7 @@ feature %q{
|
||||
|
||||
fill_in 'product_name', with: 'A new product !!!'
|
||||
fill_in 'product_price', with: '19.99'
|
||||
select taxon.name, from: "product_primary_taxon_id"
|
||||
select 'New supplier', from: 'product_supplier_id'
|
||||
|
||||
click_button 'Create'
|
||||
@@ -43,6 +45,8 @@ feature %q{
|
||||
|
||||
product.reload
|
||||
product.distributors.sort.should == [@distributors[0], @distributors[2]].sort
|
||||
|
||||
|
||||
product.product_distributions.map { |pd| pd.enterprise_fee }.sort.should == [@enterprise_fees[0], @enterprise_fees[2]].sort
|
||||
end
|
||||
|
||||
@@ -96,6 +100,7 @@ feature %q{
|
||||
|
||||
page.should have_selector('#product_supplier_id')
|
||||
select 'Another Supplier', :from => 'product_supplier_id'
|
||||
select taxon.name, from: "product_primary_taxon_id"
|
||||
|
||||
# Should only have suppliers listed which the user can manage
|
||||
within "#product_supplier_id" do
|
||||
|
||||
@@ -14,15 +14,6 @@ feature "Authentication", js: true do
|
||||
page.should have_content "Select a producer from the list below"
|
||||
current_path.should == producers_path
|
||||
end
|
||||
|
||||
scenario "logging into admin redirects home, then back to admin" do
|
||||
visit spree.admin_path
|
||||
fill_in "Email", with: user.email
|
||||
fill_in "Password", with: user.password
|
||||
click_login_button
|
||||
page.should have_content "Dashboard"
|
||||
current_path.should == spree.admin_path
|
||||
end
|
||||
end
|
||||
|
||||
describe "Loggin in from the home page" do
|
||||
|
||||
@@ -67,7 +67,7 @@ feature "As a consumer I want to shop with a distributor", js: true do
|
||||
|
||||
select "frogs", :from => "order_cycle_id"
|
||||
page.should have_selector "products"
|
||||
page.should have_content "Orders close in 2 days"
|
||||
page.should have_content "Next order closing in 2 days"
|
||||
Spree::Order.last.order_cycle.should == oc1
|
||||
page.should have_content product.name
|
||||
end
|
||||
|
||||
@@ -1,19 +1,40 @@
|
||||
describe "AccordionCtrl", ->
|
||||
ctrl = null
|
||||
scope = scope
|
||||
scope = null
|
||||
|
||||
beforeEach ->
|
||||
module "Darkswarm"
|
||||
localStorage.clear()
|
||||
inject ($controller, $rootScope) ->
|
||||
scope = $rootScope.$new()
|
||||
scope.order =
|
||||
id: 129
|
||||
ctrl = $controller 'AccordionCtrl', {$scope: scope}
|
||||
|
||||
it "defaults the details accordion to visible", ->
|
||||
expect(scope.accordion.details).toEqual true
|
||||
describe "loading incomplete form", ->
|
||||
beforeEach ->
|
||||
inject ($controller, $rootScope) ->
|
||||
scope = $rootScope.$new()
|
||||
scope.order =
|
||||
id: 129
|
||||
ctrl = $controller 'AccordionCtrl', {$scope: scope}
|
||||
|
||||
it "changes accordion", ->
|
||||
scope.show "shipping"
|
||||
expect(scope.accordion["shipping"]).toEqual true
|
||||
it "defaults the details accordion to visible", ->
|
||||
expect(scope.accordion.details).toEqual true
|
||||
|
||||
it "changes accordion", ->
|
||||
scope.show "shipping"
|
||||
expect(scope.accordion["shipping"]).toEqual true
|
||||
|
||||
describe "loading complete form", ->
|
||||
beforeEach ->
|
||||
inject ($controller, $rootScope) ->
|
||||
scope = $rootScope.$new()
|
||||
scope.checkout =
|
||||
$valid: true
|
||||
scope.order =
|
||||
id: 129
|
||||
ctrl = $controller 'AccordionCtrl', {$scope: scope}
|
||||
|
||||
it "automatically closes all sections if the entire form is valid", ->
|
||||
waitsFor ->
|
||||
(scope.accordion.details and
|
||||
scope.accordion.shipping and
|
||||
scope.accordion.payment and
|
||||
scope.accordion.billing) == false
|
||||
, "the accordion to close", 100
|
||||
|
||||
15
spec/models/spree/classification_spec.rb
Normal file
15
spec/models/spree/classification_spec.rb
Normal file
@@ -0,0 +1,15 @@
|
||||
require 'spec_helper'
|
||||
|
||||
module Spree
|
||||
describe Classification do
|
||||
let(:product) { create(:simple_product) }
|
||||
let(:taxon) { create(:taxon) }
|
||||
let(:classification) { create(:classification, taxon: taxon, product: product) }
|
||||
|
||||
it "won't destroy if classification is the primary taxon" do
|
||||
product.primary_taxon = taxon
|
||||
classification.destroy.should be_false
|
||||
classification.errors.messages[:base].should == ["Taxon #{taxon.name} is the primary taxon of #{product.name} and cannot be deleted"]
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -5,6 +5,7 @@ module Spree
|
||||
|
||||
describe "associations" do
|
||||
it { should belong_to(:supplier) }
|
||||
it { should belong_to(:primary_taxon) }
|
||||
it { should have_many(:product_distributions) }
|
||||
end
|
||||
|
||||
@@ -13,6 +14,12 @@ module Spree
|
||||
create(:product).should be_valid
|
||||
end
|
||||
|
||||
it "requires a primary taxon" do
|
||||
product = create(:simple_product)
|
||||
product.primary_taxon = nil
|
||||
product.should_not be_valid
|
||||
end
|
||||
|
||||
it "requires a supplier" do
|
||||
product = create(:simple_product)
|
||||
product.supplier = nil
|
||||
@@ -565,10 +572,10 @@ module Spree
|
||||
describe "Taxons" do
|
||||
let(:taxon1) { create(:taxon) }
|
||||
let(:taxon2) { create(:taxon) }
|
||||
let(:product) { create(:simple_product, taxons: [taxon1, taxon2]) }
|
||||
let(:product) { create(:simple_product) }
|
||||
|
||||
it "returns the first taxon as the primary taxon" do
|
||||
product.primary_taxon.should == taxon1
|
||||
product.taxons.should == [product.primary_taxon]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user