diff --git a/app/assets/javascripts/darkswarm/controllers/checkout/accordion_controller.js.coffee b/app/assets/javascripts/darkswarm/controllers/checkout/accordion_controller.js.coffee index b6f533e751..38f41c6f6b 100644 --- a/app/assets/javascripts/darkswarm/controllers/checkout/accordion_controller.js.coffee +++ b/app/assets/javascripts/darkswarm/controllers/checkout/accordion_controller.js.coffee @@ -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 + diff --git a/app/assets/javascripts/darkswarm/controllers/checkout/details_controller.js.coffee b/app/assets/javascripts/darkswarm/controllers/checkout/details_controller.js.coffee index c9d559a0d0..8153c24f92 100644 --- a/app/assets/javascripts/darkswarm/controllers/checkout/details_controller.js.coffee +++ b/app/assets/javascripts/darkswarm/controllers/checkout/details_controller.js.coffee @@ -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") - diff --git a/app/assets/javascripts/darkswarm/services/checkout_form_state.js.coffee b/app/assets/javascripts/darkswarm/services/checkout_form_state.js.coffee index 9d68efba64..6fedb6b3c6 100644 --- a/app/assets/javascripts/darkswarm/services/checkout_form_state.js.coffee +++ b/app/assets/javascripts/darkswarm/services/checkout_form_state.js.coffee @@ -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 diff --git a/app/assets/stylesheets/darkswarm/shop.css.sass b/app/assets/stylesheets/darkswarm/shop.css.sass index 0c2972367a..a23458b941 100644 --- a/app/assets/stylesheets/darkswarm/shop.css.sass +++ b/app/assets/stylesheets/darkswarm/shop.css.sass @@ -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 diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index b9e46d3237..a19f92c918 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -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 diff --git a/app/controllers/spree/admin/base_controller_decorator.rb b/app/controllers/spree/admin/base_controller_decorator.rb index df7076345f..7199ca4dec 100644 --- a/app/controllers/spree/admin/base_controller_decorator.rb +++ b/app/controllers/spree/admin/base_controller_decorator.rb @@ -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 diff --git a/app/controllers/spree/admin/orders_controller_decorator.rb b/app/controllers/spree/admin/orders_controller_decorator.rb index 51c7acba09..27d9a36943 100644 --- a/app/controllers/spree/admin/orders_controller_decorator.rb +++ b/app/controllers/spree/admin/orders_controller_decorator.rb @@ -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 \ No newline at end of file +end diff --git a/app/controllers/spree/admin/overview_controller_decorator.rb b/app/controllers/spree/admin/overview_controller_decorator.rb index a6142d26c0..a2288dab88 100644 --- a/app/controllers/spree/admin/overview_controller_decorator.rb +++ b/app/controllers/spree/admin/overview_controller_decorator.rb @@ -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 + diff --git a/app/models/enterprise.rb b/app/models/enterprise.rb index dd40744492..7c54bb1f10 100644 --- a/app/models/enterprise.rb +++ b/app/models/enterprise.rb @@ -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 diff --git a/app/models/enterprise_group.rb b/app/models/enterprise_group.rb index 1cea76db72..a06612a064 100644 --- a/app/models/enterprise_group.rb +++ b/app/models/enterprise_group.rb @@ -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 diff --git a/app/models/spree/classification_decorator.rb b/app/models/spree/classification_decorator.rb new file mode 100644 index 0000000000..7e34e6890e --- /dev/null +++ b/app/models/spree/classification_decorator.rb @@ -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 diff --git a/app/models/spree/product_decorator.rb b/app/models/spree/product_decorator.rb index 972befe54a..36473d4e24 100644 --- a/app/models/spree/product_decorator.rb +++ b/app/models/spree/product_decorator.rb @@ -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 diff --git a/app/overrides/add_primary_taxon_to_admin_product.rb b/app/overrides/add_primary_taxon_to_admin_product.rb new file mode 100644 index 0000000000..9f7c5edde5 --- /dev/null +++ b/app/overrides/add_primary_taxon_to_admin_product.rb @@ -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") diff --git a/app/overrides/add_primary_taxon_to_admin_product_new.rb b/app/overrides/add_primary_taxon_to_admin_product_new.rb new file mode 100644 index 0000000000..e5c9d24e7f --- /dev/null +++ b/app/overrides/add_primary_taxon_to_admin_product_new.rb @@ -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") diff --git a/app/overrides/spree/admin/products/_form/add_notes_field.html.haml.deface b/app/overrides/spree/admin/products/_form/add_notes_field.html.haml.deface index dadebd01d4..dcc7937d6b 100644 --- a/app/overrides/spree/admin/products/_form/add_notes_field.html.haml.deface +++ b/app/overrides/spree/admin/products/_form/add_notes_field.html.haml.deface @@ -4,4 +4,3 @@ = f.label :notes, t(:notes) = f.text_area :notes, { :class => 'fullwidth', rows: 5 } = f.error_message_on :notes - diff --git a/app/views/admin/enterprises/_form.html.haml b/app/views/admin/enterprises/_form.html.haml index 161f43d34d..06fe94ebf4 100644 --- a/app/views/admin/enterprises/_form.html.haml +++ b/app/views/admin/enterprises/_form.html.haml @@ -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 diff --git a/app/views/checkout/_billing.html.haml b/app/views/checkout/_billing.html.haml index dc48eadbe2..f8129d32c9 100644 --- a/app/views/checkout/_billing.html.haml +++ b/app/views/checkout/_billing.html.haml @@ -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 diff --git a/app/views/checkout/_payment.html.haml b/app/views/checkout/_payment.html.haml index 195ae9e42a..e972ebfcf1 100644 --- a/app/views/checkout/_payment.html.haml +++ b/app/views/checkout/_payment.html.haml @@ -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 diff --git a/app/views/checkout/_shipping.html.haml b/app/views/checkout/_shipping.html.haml index dfa69d43c5..215ea8ed61 100644 --- a/app/views/checkout/_shipping.html.haml +++ b/app/views/checkout/_shipping.html.haml @@ -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 diff --git a/app/views/shop/products/_form.html.haml b/app/views/shop/products/_form.html.haml index 5a3af9684e..6212ef746d 100644 --- a/app/views/shop/products/_form.html.haml +++ b/app/views/shop/products/_form.html.haml @@ -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 diff --git a/app/views/shop/products/_master.html.haml b/app/views/shop/products/_master.html.haml index 7398912bda..bd8a8cd3de 100644 --- a/app/views/shop/products/_master.html.haml +++ b/app/views/shop/products/_master.html.haml @@ -1,4 +1,4 @@ -.small-1.column +.small-1.columns %span.bulk{"bo-if" => "product.group_buy"} bulk   diff --git a/app/views/shop/products/_summary.html.haml b/app/views/shop/products/_summary.html.haml index e41c6ef440..22ce416336 100644 --- a/app/views/shop/products/_summary.html.haml +++ b/app/views/shop/products/_summary.html.haml @@ -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 diff --git a/app/views/shop/products/_variants.html.haml b/app/views/shop/products/_variants.html.haml index 14ff8eff24..6751f8c62c 100644 --- a/app/views/shop/products/_variants.html.haml +++ b/app/views/shop/products/_variants.html.haml @@ -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   diff --git a/app/views/shop/show.html.haml b/app/views/shop/show.html.haml index d4b36a5e29..ad0080edae 100644 --- a/app/views/shop/show.html.haml +++ b/app/views/shop/show.html.haml @@ -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" diff --git a/app/views/shopping_shared/_details.html.haml b/app/views/shopping_shared/_details.html.haml index e152be43c0..2a8e1b10b1 100644 --- a/app/views/shopping_shared/_details.html.haml +++ b/app/views/shopping_shared/_details.html.haml @@ -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" diff --git a/app/views/shopping_shared/_tabs.html.haml b/app/views/shopping_shared/_tabs.html.haml index 3a29a12e6c..a5320a7ec5 100644 --- a/app/views/shopping_shared/_tabs.html.haml +++ b/app/views/shopping_shared/_tabs.html.haml @@ -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"} diff --git a/config/initializers/paperclip.rb b/config/initializers/paperclip.rb index c40b9a4130..5dd5c644b4 100644 --- a/config/initializers/paperclip.rb +++ b/config/initializers/paperclip.rb @@ -1,3 +1,3 @@ -Paperclip::Attachment.default_options[:convert_options] = { +Paperclip::Attachment.default_options[:source_file_options] = { all: "-auto-orient" } diff --git a/db/migrate/20140522044009_add_primary_taxon_to_products.rb b/db/migrate/20140522044009_add_primary_taxon_to_products.rb index f6ff3cfe96..fb7b9b3160 100644 --- a/db/migrate/20140522044009_add_primary_taxon_to_products.rb +++ b/db/migrate/20140522044009_add_primary_taxon_to_products.rb @@ -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 diff --git a/spec/controllers/spree/admin/base_controller_spec.rb b/spec/controllers/spree/admin/base_controller_spec.rb new file mode 100644 index 0000000000..0985d733a7 --- /dev/null +++ b/spec/controllers/spree/admin/base_controller_spec.rb @@ -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 diff --git a/spec/factories.rb b/spec/factories.rb index 6da7824d47..394112125a 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -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' diff --git a/spec/features/admin/authentication_spec.rb b/spec/features/admin/authentication_spec.rb new file mode 100644 index 0000000000..c4768e5eed --- /dev/null +++ b/spec/features/admin/authentication_spec.rb @@ -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 diff --git a/spec/features/admin/bulk_product_update_spec.rb b/spec/features/admin/bulk_product_update_spec.rb index d89280df80..0e15fbd2f4 100644 --- a/spec/features/admin/bulk_product_update_spec.rb +++ b/spec/features/admin/bulk_product_update_spec.rb @@ -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' diff --git a/spec/features/admin/products_spec.rb b/spec/features/admin/products_spec.rb index 63a73ccbff..fd7235200b 100644 --- a/spec/features/admin/products_spec.rb +++ b/spec/features/admin/products_spec.rb @@ -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 diff --git a/spec/features/consumer/authentication_spec.rb b/spec/features/consumer/authentication_spec.rb index 76e4a20877..8853a07c3d 100644 --- a/spec/features/consumer/authentication_spec.rb +++ b/spec/features/consumer/authentication_spec.rb @@ -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 diff --git a/spec/features/consumer/shopping/shopping_spec.rb b/spec/features/consumer/shopping/shopping_spec.rb index 9946be2f5b..b1b905fe82 100644 --- a/spec/features/consumer/shopping/shopping_spec.rb +++ b/spec/features/consumer/shopping/shopping_spec.rb @@ -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 diff --git a/spec/javascripts/unit/darkswarm/controllers/checkout/accordion_controller_spec.js.coffee b/spec/javascripts/unit/darkswarm/controllers/checkout/accordion_controller_spec.js.coffee index 1c0c199351..d35fb93e86 100644 --- a/spec/javascripts/unit/darkswarm/controllers/checkout/accordion_controller_spec.js.coffee +++ b/spec/javascripts/unit/darkswarm/controllers/checkout/accordion_controller_spec.js.coffee @@ -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 diff --git a/spec/models/spree/classification_spec.rb b/spec/models/spree/classification_spec.rb new file mode 100644 index 0000000000..f26f6da0c0 --- /dev/null +++ b/spec/models/spree/classification_spec.rb @@ -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 diff --git a/spec/models/spree/product_spec.rb b/spec/models/spree/product_spec.rb index a5333b6d11..8d04d690b0 100644 --- a/spec/models/spree/product_spec.rb +++ b/spec/models/spree/product_spec.rb @@ -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