Merge master (with primary taxons restored)

This commit is contained in:
Rob H
2014-05-30 15:45:48 +10:00
38 changed files with 195 additions and 83 deletions

View 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

View File

@@ -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'

View 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

View File

@@ -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'

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View 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

View File

@@ -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