spree_drop_ship 3.1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +18 -0
- data/Gemfile +9 -0
- data/LICENSE +21 -0
- data/README.md +116 -0
- data/Rakefile +15 -0
- data/Versionfile +6 -0
- data/app/assets/javascripts/spree/backend/spree_drop_ship.js +2 -0
- data/app/assets/javascripts/spree/frontend/spree_drop_ship.js +1 -0
- data/app/assets/stylesheets/spree/backend/spree_drop_ship.scss +22 -0
- data/app/assets/stylesheets/spree/frontend/spree_drop_ship.css +3 -0
- data/app/controllers/ckeditor/attachment_files_controller_decorator.rb +20 -0
- data/app/controllers/ckeditor/pictures_controller_decorator.rb +17 -0
- data/app/controllers/spree/admin/drop_ship_settings_controller.rb +19 -0
- data/app/controllers/spree/admin/products_controller_decorator.rb +19 -0
- data/app/controllers/spree/admin/shipments_controller.rb +47 -0
- data/app/controllers/spree/admin/stock_locations_controller_decorator.rb +14 -0
- data/app/controllers/spree/admin/suppliers_controller.rb +32 -0
- data/app/controllers/spree/api/v1/stock_locations_controller_decorator.rb +18 -0
- data/app/controllers/spree/base_controller_decorator.rb +23 -0
- data/app/mailers/spree/drop_ship_order_mailer.rb +13 -0
- data/app/mailers/spree/supplier_mailer.rb +12 -0
- data/app/models/ckeditor/asset_decorator.rb +5 -0
- data/app/models/spree/drop_ship_configuration.rb +17 -0
- data/app/models/spree/order_decorator.rb +27 -0
- data/app/models/spree/payment_decorator.rb +7 -0
- data/app/models/spree/product_decorator.rb +32 -0
- data/app/models/spree/shipment_decorator.rb +39 -0
- data/app/models/spree/stock/splitter/drop_ship.rb +42 -0
- data/app/models/spree/stock_location_decorator.rb +18 -0
- data/app/models/spree/supplier.rb +117 -0
- data/app/models/spree/supplier_ability.rb +28 -0
- data/app/models/spree/supplier_variant.rb +6 -0
- data/app/models/spree/user_decorator.rb +11 -0
- data/app/models/spree/variant_decorator.rb +24 -0
- data/app/models/spree.rb +5 -0
- data/app/overrides/spree/admin/products/_form/converted_admin_product_form_right.html.erb.deface +5 -0
- data/app/overrides/spree/admin/products/index/override_rows.html.erb.deface +22 -0
- data/app/overrides/spree/admin/shared/sub_menu/_configuration/add_drop_ship_settings.html.erb.deface +3 -0
- data/app/overrides/spree/admin/stock_locations/_form/add_supplier.html.erb.deface +12 -0
- data/app/overrides/spree/admin/stock_movements/_form/fix_bootstrap_form.html.erb.deface +11 -0
- data/app/overrides/spree/layouts/admin/add_profile_admin_tabs.html.erb.deface +8 -0
- data/app/overrides/spree/layouts/admin/converted_admin_tabs.html.erb.deface +18 -0
- data/app/views/spree/admin/drop_ship_settings/edit.html.erb +21 -0
- data/app/views/spree/admin/shared/_header.html.erb +24 -0
- data/app/views/spree/admin/shipments/edit.html.erb +24 -0
- data/app/views/spree/admin/shipments/index.html.erb +95 -0
- data/app/views/spree/admin/suppliers/_form.html.erb +69 -0
- data/app/views/spree/admin/suppliers/edit.html.erb +22 -0
- data/app/views/spree/admin/suppliers/index.html.erb +71 -0
- data/app/views/spree/admin/suppliers/new.html.erb +17 -0
- data/app/views/spree/drop_ship_order_mailer/supplier_order.html.erb +119 -0
- data/app/views/spree/shared/unauthorized.erb +1 -0
- data/app/views/spree/supplier_mailer/welcome.html.erb +53 -0
- data/config/locales/en.yml +89 -0
- data/config/locales/es.yml +133 -0
- data/config/routes.rb +9 -0
- data/db/migrate/20121006073854_create_suppliers.rb +20 -0
- data/db/migrate/20130216070944_product_belongs_to_supplier.rb +6 -0
- data/db/migrate/20130405005502_stock_locations_belongs_to_supplier.rb +6 -0
- data/db/migrate/20130405011127_user_belongs_to_supplier.rb +6 -0
- data/db/migrate/20130428063053_add_balanced_token_to_suppliers.rb +7 -0
- data/db/migrate/20130510181443_add_supplier_id_to_ckeditor_assets.rb +8 -0
- data/db/migrate/20130606220913_add_permalink_to_suppliers.rb +6 -0
- data/db/migrate/20140323170638_add_supplier_commission_to_shipments.rb +5 -0
- data/db/migrate/20140416184616_migrate_payment_and_commission.rb +7 -0
- data/db/migrate/20140529041325_create_spree_supplier_variants.rb +15 -0
- data/lib/generators/spree_drop_ship/install/install_generator.rb +30 -0
- data/lib/spree_drop_ship/engine.rb +31 -0
- data/lib/spree_drop_ship/factories.rb +93 -0
- data/lib/spree_drop_ship.rb +6 -0
- data/lib/tasks/spree_sample.rake +72 -0
- data/script/rails +7 -0
- data/spec/features/admin/orders_spec.rb +12 -0
- data/spec/features/admin/products_spec.rb +25 -0
- data/spec/features/admin/return_authorizations_spec.rb +7 -0
- data/spec/features/admin/settings_spec.rb +33 -0
- data/spec/features/admin/shipments_spec.rb +80 -0
- data/spec/features/admin/stock_management_spec.rb +153 -0
- data/spec/features/admin/stock_spec.rb +98 -0
- data/spec/features/admin/suppliers_spec.rb +126 -0
- data/spec/models/spree/order_decorator_spec.rb +54 -0
- data/spec/models/spree/payment_decorator_spec.rb +7 -0
- data/spec/models/spree/product_decorator_spec.rb +13 -0
- data/spec/models/spree/shipment_decorator_spec.rb +47 -0
- data/spec/models/spree/stock/splitter/drop_ship_spec.rb +62 -0
- data/spec/models/spree/stock_location_decorator_spec.rb +33 -0
- data/spec/models/spree/supplier_ability_spec.rb +172 -0
- data/spec/models/spree/supplier_spec.rb +123 -0
- data/spec/models/spree/supplier_variant_spec.rb +5 -0
- data/spec/models/spree/user_decorator_spec.rb +17 -0
- data/spec/models/spree/variant_decorator_spec.rb +7 -0
- data/spec/spec_helper.rb +79 -0
- data/spec/support/integration_helpers.rb +15 -0
- data/spree_drop_ship.gemspec +42 -0
- metadata +411 -0
@@ -0,0 +1,126 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
feature 'Admin - Suppliers', js: true do
|
4
|
+
|
5
|
+
before do
|
6
|
+
country = create(:country, name: "United States")
|
7
|
+
create(:state, name: "Vermont", country: country)
|
8
|
+
@supplier = create :supplier
|
9
|
+
end
|
10
|
+
|
11
|
+
context 'as an Admin' do
|
12
|
+
|
13
|
+
before do
|
14
|
+
login_user create(:admin_user)
|
15
|
+
visit spree.admin_path
|
16
|
+
within '[data-hook=admin_tabs]' do
|
17
|
+
click_link 'Suppliers'
|
18
|
+
end
|
19
|
+
page.should have_content('Listing Suppliers')
|
20
|
+
end
|
21
|
+
|
22
|
+
scenario 'should be able to create new supplier' do
|
23
|
+
click_link 'New Supplier'
|
24
|
+
check 'supplier_active'
|
25
|
+
fill_in 'supplier[name]', with: 'Test Supplier'
|
26
|
+
fill_in 'supplier[email]', with: 'spree@example.com'
|
27
|
+
fill_in 'supplier[url]', with: 'http://www.test.com'
|
28
|
+
fill_in 'supplier[commission_flat_rate]', with: '0'
|
29
|
+
fill_in 'supplier[commission_percentage]', with: '0'
|
30
|
+
fill_in 'supplier[address_attributes][firstname]', with: 'First'
|
31
|
+
fill_in 'supplier[address_attributes][lastname]', with: 'Last'
|
32
|
+
fill_in 'supplier[address_attributes][address1]', with: '1 Test Drive'
|
33
|
+
fill_in 'supplier[address_attributes][city]', with: 'Test City'
|
34
|
+
fill_in 'supplier[address_attributes][zipcode]', with: '55555'
|
35
|
+
select2 'United States', from: 'Country'
|
36
|
+
select2 'Vermont', from: 'State'
|
37
|
+
fill_in 'supplier[address_attributes][phone]', with: '555-555-5555'
|
38
|
+
click_button 'Create'
|
39
|
+
page.should have_content('Supplier "Test Supplier" has been successfully created!')
|
40
|
+
end
|
41
|
+
|
42
|
+
scenario 'should be able to delete supplier' do
|
43
|
+
click_icon 'delete'
|
44
|
+
page.driver.browser.switch_to.alert.accept
|
45
|
+
within 'table' do
|
46
|
+
page.should_not have_content(@supplier.name)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
scenario 'should be able to edit supplier' do
|
51
|
+
click_icon 'edit'
|
52
|
+
check 'supplier_active'
|
53
|
+
fill_in 'supplier[name]', with: 'Test Supplier'
|
54
|
+
fill_in 'supplier[email]', with: 'spree@example.com'
|
55
|
+
fill_in 'supplier[url]', with: 'http://www.test.com'
|
56
|
+
fill_in 'supplier[commission_flat_rate]', with: '0'
|
57
|
+
fill_in 'supplier[commission_percentage]', with: '0'
|
58
|
+
fill_in 'supplier[address_attributes][firstname]', with: 'First'
|
59
|
+
fill_in 'supplier[address_attributes][lastname]', with: 'Last'
|
60
|
+
fill_in 'supplier[address_attributes][address1]', with: '1 Test Drive'
|
61
|
+
fill_in 'supplier[address_attributes][city]', with: 'Test City'
|
62
|
+
fill_in 'supplier[address_attributes][zipcode]', with: '55555'
|
63
|
+
select2 'United States', from: 'Country'
|
64
|
+
select2 'Vermont', from: 'State'
|
65
|
+
fill_in 'supplier[address_attributes][phone]', with: '555-555-5555'
|
66
|
+
click_button 'Update'
|
67
|
+
page.should have_content('Supplier "Test Supplier" has been successfully updated!')
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
71
|
+
|
72
|
+
context 'as a Supplier' do
|
73
|
+
before do
|
74
|
+
@user = create(:supplier_user)
|
75
|
+
login_user @user
|
76
|
+
visit spree.edit_admin_supplier_path(@user.supplier)
|
77
|
+
end
|
78
|
+
|
79
|
+
scenario 'should only see tabs they have access to' do
|
80
|
+
within '[data-hook=admin_tabs]' do
|
81
|
+
page.should_not have_link('Overview')
|
82
|
+
page.should have_link('Products')
|
83
|
+
page.should_not have_link('Reports')
|
84
|
+
page.should_not have_link('Configuration')
|
85
|
+
page.should_not have_link('Promotions')
|
86
|
+
page.should_not have_link('Suppliers')
|
87
|
+
page.should have_link('Shipments')
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
scenario 'should be able to update supplier' do
|
92
|
+
fill_in 'supplier[name]', with: 'Test Supplier'
|
93
|
+
fill_in 'supplier[email]', with: @user.email
|
94
|
+
fill_in 'supplier[url]', with: 'http://www.test.com'
|
95
|
+
fill_in 'supplier[address_attributes][firstname]', with: 'First'
|
96
|
+
fill_in 'supplier[address_attributes][lastname]', with: 'Last'
|
97
|
+
fill_in 'supplier[address_attributes][address1]', with: '1 Test Drive'
|
98
|
+
fill_in 'supplier[address_attributes][city]', with: 'Test City'
|
99
|
+
fill_in 'supplier[address_attributes][zipcode]', with: '55555'
|
100
|
+
select2 'United States', from: 'Country'
|
101
|
+
select2 'Vermont', from: 'State'
|
102
|
+
fill_in 'supplier[address_attributes][phone]', with: '555-555-5555'
|
103
|
+
page.should_not have_css('#supplier_active') # cannot edit active
|
104
|
+
page.should_not have_css('#supplier_featured') # cannot edit featured
|
105
|
+
page.should_not have_css('#s2id_supplier_user_ids') # cannot edit assigned users
|
106
|
+
page.should_not have_css('#supplier_commission_flat_rate') # cannot edit flat rate commission
|
107
|
+
page.should_not have_css('#supplier_commission_percentage') # cannot edit comission percentage
|
108
|
+
click_button 'Update'
|
109
|
+
page.should have_content('Supplier "Test Supplier" has been successfully updated!')
|
110
|
+
page.current_path.should eql(spree.edit_admin_supplier_path(@user.reload.supplier))
|
111
|
+
end
|
112
|
+
|
113
|
+
end
|
114
|
+
|
115
|
+
context 'as a User other than the suppliers' do
|
116
|
+
|
117
|
+
scenario 'should be unauthorized' do
|
118
|
+
supplier = create(:supplier)
|
119
|
+
login_user create(:user)
|
120
|
+
visit spree.edit_admin_supplier_path(supplier)
|
121
|
+
page.should have_content('Authorization Failure')
|
122
|
+
end
|
123
|
+
|
124
|
+
end
|
125
|
+
|
126
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Spree::Order do
|
4
|
+
|
5
|
+
context '#finalize_with_drop_ship!' do
|
6
|
+
|
7
|
+
after do
|
8
|
+
SpreeDropShip::Config[:send_supplier_email] = true
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'should deliver drop ship orders when Spree::DropShipConfig[:send_supplier_email] == true' do
|
12
|
+
order = create(:order_with_totals, ship_address: create(:address))
|
13
|
+
order.line_items = [create(:line_item, variant: create(:variant_with_supplier)), create(:line_item, variant: create(:variant_with_supplier))]
|
14
|
+
order.create_proposed_shipments
|
15
|
+
|
16
|
+
order.shipments.each do |shipment|
|
17
|
+
Spree::DropShipOrderMailer.should_receive(:supplier_order).with(shipment.id).and_return(double(Mail, :deliver! => true))
|
18
|
+
end
|
19
|
+
|
20
|
+
order.finalize!
|
21
|
+
order.reload
|
22
|
+
|
23
|
+
# Check orders are properly split.
|
24
|
+
order.shipments.size.should eql(2)
|
25
|
+
order.shipments.each do |shipment|
|
26
|
+
shipment.line_items.size.should eql(1)
|
27
|
+
shipment.line_items.first.variant.suppliers.first.should eql(shipment.supplier)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'should NOT deliver drop ship orders when Spree::DropShipConfig[:send_supplier_email] == false' do
|
32
|
+
SpreeDropShip::Config[:send_supplier_email] = false
|
33
|
+
order = create(:order_with_totals, ship_address: create(:address))
|
34
|
+
order.line_items = [create(:line_item, variant: create(:variant_with_supplier)), create(:line_item, variant: create(:variant_with_supplier))]
|
35
|
+
order.create_proposed_shipments
|
36
|
+
|
37
|
+
order.shipments.each do |shipment|
|
38
|
+
Spree::DropShipOrderMailer.should_not_receive(:supplier_order).with(shipment.id)
|
39
|
+
end
|
40
|
+
|
41
|
+
order.finalize!
|
42
|
+
order.reload
|
43
|
+
|
44
|
+
# Check orders are properly split.
|
45
|
+
order.shipments.size.should eql(2)
|
46
|
+
order.shipments.each do |shipment|
|
47
|
+
shipment.line_items.size.should eql(1)
|
48
|
+
shipment.line_items.first.variant.suppliers.first.should eql(shipment.supplier)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Spree::Shipment do
|
4
|
+
|
5
|
+
describe 'Scopes' do
|
6
|
+
|
7
|
+
it '#by_supplier' do
|
8
|
+
supplier = create(:supplier)
|
9
|
+
stock_location_1 = supplier.stock_locations.first
|
10
|
+
stock_location_2 = create(:stock_location, supplier: supplier)
|
11
|
+
shipment_1 = create(:shipment)
|
12
|
+
shipment_2 = create(:shipment, stock_location: stock_location_1)
|
13
|
+
shipment_3 = create(:shipment)
|
14
|
+
shipment_4 = create(:shipment, stock_location: stock_location_2)
|
15
|
+
shipment_5 = create(:shipment)
|
16
|
+
shipment_6 = create(:shipment, stock_location: stock_location_1)
|
17
|
+
|
18
|
+
expect(subject.class.by_supplier(supplier.id)).to match_array([shipment_2, shipment_4, shipment_6])
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
describe '#after_ship' do
|
24
|
+
|
25
|
+
it 'should capture payment if balance due' do
|
26
|
+
skip 'TODO make it so!'
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'should track commission for shipment' do
|
30
|
+
supplier = create(:supplier_with_commission)
|
31
|
+
shipment = create(:shipment, stock_location: supplier.stock_locations.first)
|
32
|
+
|
33
|
+
expect(shipment.supplier_commission.to_f).to eql(0.0)
|
34
|
+
shipment.stub final_price_with_items: 10.0
|
35
|
+
shipment.send(:after_ship)
|
36
|
+
expect(shipment.reload.supplier_commission.to_f).to eql(1.5)
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
it '#final_price_with_items' do
|
42
|
+
shipment = build :shipment
|
43
|
+
shipment.stub item_cost: 50.0, final_price: 5.5
|
44
|
+
expect(shipment.final_price_with_items.to_f).to eql(55.5)
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Spree
|
4
|
+
module Stock
|
5
|
+
module Splitter
|
6
|
+
describe DropShip do
|
7
|
+
|
8
|
+
let(:supplier_1) { create(:supplier) }
|
9
|
+
let(:supplier_2) { create(:supplier) }
|
10
|
+
|
11
|
+
let(:variant_1) {
|
12
|
+
v = create(:variant)
|
13
|
+
v.product.add_supplier! supplier_1
|
14
|
+
v.reload.supplier_variants.find_by_supplier_id(supplier_1.id).update_column(:cost, 5)
|
15
|
+
v.product.add_supplier! supplier_2
|
16
|
+
v.reload.supplier_variants.find_by_supplier_id(supplier_2.id).update_column(:cost, 6)
|
17
|
+
v
|
18
|
+
}
|
19
|
+
let(:variant_2) {
|
20
|
+
v = create(:variant)
|
21
|
+
v.product.add_supplier! supplier_1
|
22
|
+
v.reload.supplier_variants.find_by_supplier_id(supplier_1.id).update_column(:cost, 5)
|
23
|
+
v.product.add_supplier! supplier_2
|
24
|
+
v.reload.supplier_variants.find_by_supplier_id(supplier_2.id).update_column(:cost, 4)
|
25
|
+
v
|
26
|
+
}
|
27
|
+
let(:variant_3) {
|
28
|
+
v = create(:variant)
|
29
|
+
v.product.add_supplier! supplier_1
|
30
|
+
v.product.add_supplier! supplier_2
|
31
|
+
v.reload
|
32
|
+
}
|
33
|
+
let(:variant_4) { create(:variant) }
|
34
|
+
|
35
|
+
let(:variants){
|
36
|
+
[variant_1, variant_2, variant_3, variant_4]
|
37
|
+
}
|
38
|
+
|
39
|
+
let(:packer) { build(:stock_packer) }
|
40
|
+
|
41
|
+
subject { DropShip.new(packer) }
|
42
|
+
|
43
|
+
it 'splits packages for drop ship' do
|
44
|
+
package = Package.new(packer.stock_location)
|
45
|
+
package = Package.new(packer.stock_location)
|
46
|
+
4.times { |i| package.add build(:inventory_unit, variant: variants[i]) }
|
47
|
+
|
48
|
+
packages = subject.split([package])
|
49
|
+
packages.count.should eq 3
|
50
|
+
|
51
|
+
expect(packages[0].stock_location).to eq(packer.stock_location)
|
52
|
+
expect(packages[0].contents.count).to eq(1)
|
53
|
+
expect(packages[1].stock_location).to eq(supplier_1.stock_locations.first)
|
54
|
+
expect(packages[1].contents.count).to eq(2)
|
55
|
+
expect(packages[2].stock_location).to eq(supplier_2.stock_locations.first)
|
56
|
+
expect(packages[2].contents.count).to eq(1)
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Spree::StockLocation do
|
4
|
+
|
5
|
+
it { should belong_to(:supplier) }
|
6
|
+
|
7
|
+
subject { create(:stock_location, backorderable_default: true) }
|
8
|
+
|
9
|
+
context "propagate variants" do
|
10
|
+
|
11
|
+
let(:variant) { build(:variant) }
|
12
|
+
let(:stock_item) { subject.propagate_variant(variant) }
|
13
|
+
|
14
|
+
context "passes backorderable default config" do
|
15
|
+
context "true" do
|
16
|
+
before { subject.backorderable_default = true }
|
17
|
+
it { stock_item.backorderable.should be true }
|
18
|
+
end
|
19
|
+
|
20
|
+
context "false" do
|
21
|
+
before { subject.backorderable_default = false }
|
22
|
+
it { stock_item.backorderable.should be false }
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
context 'does not propagate for non supplier variants' do
|
27
|
+
before { subject.supplier_id = create(:supplier).id }
|
28
|
+
it { stock_item.should be_nil }
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
@@ -0,0 +1,172 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'cancan/matchers'
|
3
|
+
require 'spree/testing_support/ability_helpers'
|
4
|
+
|
5
|
+
describe Spree::SupplierAbility do
|
6
|
+
|
7
|
+
let(:user) { create(:user, supplier: create(:supplier)) }
|
8
|
+
let(:ability) { Spree::SupplierAbility.new(user) }
|
9
|
+
let(:token) { nil }
|
10
|
+
|
11
|
+
context 'for Dash' do
|
12
|
+
let(:resource) { Spree::Admin::RootController }
|
13
|
+
|
14
|
+
context 'requested by supplier' do
|
15
|
+
it_should_behave_like 'access denied'
|
16
|
+
it_should_behave_like 'no index allowed'
|
17
|
+
it_should_behave_like 'admin denied'
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
context 'for Product' do
|
22
|
+
let(:resource) { create(:product) }
|
23
|
+
|
24
|
+
it_should_behave_like 'index allowed'
|
25
|
+
it_should_behave_like 'admin granted'
|
26
|
+
|
27
|
+
context 'requested by another suppliers user' do
|
28
|
+
let(:resource) {
|
29
|
+
product = create(:product)
|
30
|
+
product.add_supplier!(create(:supplier))
|
31
|
+
product
|
32
|
+
}
|
33
|
+
it_should_behave_like 'access denied'
|
34
|
+
end
|
35
|
+
|
36
|
+
context 'requested by suppliers user' do
|
37
|
+
let(:resource) {
|
38
|
+
product = create(:product)
|
39
|
+
product.add_supplier!(user.supplier)
|
40
|
+
product.reload
|
41
|
+
}
|
42
|
+
# it_should_behave_like 'access granted'
|
43
|
+
it { ability.should be_able_to :read, resource }
|
44
|
+
it { ability.should be_able_to :stock, resource }
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
context 'for Shipment' do
|
49
|
+
context 'requested by another suppliers user' do
|
50
|
+
let(:resource) { Spree::Shipment.new({stock_location: create(:stock_location, supplier: create(:supplier))}, without_protection: true) }
|
51
|
+
it_should_behave_like 'access denied'
|
52
|
+
it_should_behave_like 'no index allowed'
|
53
|
+
it_should_behave_like 'admin denied'
|
54
|
+
it { ability.should_not be_able_to :ready, resource }
|
55
|
+
it { ability.should_not be_able_to :ship, resource }
|
56
|
+
end
|
57
|
+
|
58
|
+
context 'requested by suppliers user' do
|
59
|
+
context 'when order is complete' do
|
60
|
+
let(:resource) {
|
61
|
+
order = create(:completed_order_for_drop_ship_with_totals)
|
62
|
+
order.stock_locations.first.update_attribute :supplier, user.supplier
|
63
|
+
Spree::Shipment.new({order: order, stock_location: order.stock_locations.first }, without_protection: true)
|
64
|
+
}
|
65
|
+
it_should_behave_like 'access granted'
|
66
|
+
it_should_behave_like 'index allowed'
|
67
|
+
it_should_behave_like 'admin granted'
|
68
|
+
it { ability.should be_able_to :ready, resource }
|
69
|
+
it { ability.should be_able_to :ship, resource }
|
70
|
+
end
|
71
|
+
|
72
|
+
context 'when order is incomplete' do
|
73
|
+
let(:resource) { Spree::Shipment.new({stock_location: create(:stock_location, supplier: user.supplier)}, without_protection: true) }
|
74
|
+
it_should_behave_like 'access denied'
|
75
|
+
it { ability.should_not be_able_to :ready, resource }
|
76
|
+
it { ability.should_not be_able_to :ship, resource }
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
context 'for StockItem' do
|
82
|
+
let(:resource) { Spree::StockItem }
|
83
|
+
|
84
|
+
it_should_behave_like 'index allowed'
|
85
|
+
it_should_behave_like 'admin granted'
|
86
|
+
|
87
|
+
context 'requested by another suppliers user' do
|
88
|
+
let(:resource) {
|
89
|
+
supplier = create(:supplier)
|
90
|
+
variant = create(:product).master
|
91
|
+
variant.product.add_supplier! supplier
|
92
|
+
supplier.stock_locations.first.stock_items.first
|
93
|
+
}
|
94
|
+
it_should_behave_like 'access denied'
|
95
|
+
end
|
96
|
+
|
97
|
+
context 'requested by suppliers user' do
|
98
|
+
let(:resource) {
|
99
|
+
variant = create(:product).master
|
100
|
+
variant.product.add_supplier! user.supplier
|
101
|
+
user.supplier.stock_locations.first.stock_items.first
|
102
|
+
}
|
103
|
+
it_should_behave_like 'access granted'
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
context 'for StockLocation' do
|
108
|
+
context 'requsted by another suppliers user' do
|
109
|
+
let(:resource) {
|
110
|
+
supplier = create(:supplier)
|
111
|
+
variant = create(:product).master
|
112
|
+
variant.product.add_supplier! supplier
|
113
|
+
supplier.stock_locations.first
|
114
|
+
}
|
115
|
+
it_should_behave_like 'create only'
|
116
|
+
end
|
117
|
+
|
118
|
+
context 'requested by suppliers user' do
|
119
|
+
let(:resource) {
|
120
|
+
variant = create(:product).master
|
121
|
+
variant.product.add_supplier! user.supplier
|
122
|
+
user.supplier.stock_locations.first
|
123
|
+
}
|
124
|
+
it_should_behave_like 'access granted'
|
125
|
+
it_should_behave_like 'admin granted'
|
126
|
+
it_should_behave_like 'index allowed'
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
context 'for StockMovement' do
|
131
|
+
let(:resource) { Spree::StockMovement }
|
132
|
+
|
133
|
+
it_should_behave_like 'index allowed'
|
134
|
+
it_should_behave_like 'admin granted'
|
135
|
+
|
136
|
+
context 'requested by another suppliers user' do
|
137
|
+
let(:resource) {
|
138
|
+
supplier = create(:supplier)
|
139
|
+
variant = create(:product).master
|
140
|
+
variant.product.add_supplier! supplier
|
141
|
+
Spree::StockMovement.new({ stock_item: supplier.stock_locations.first.stock_items.first }, without_protection: true)
|
142
|
+
}
|
143
|
+
it_should_behave_like 'create only'
|
144
|
+
end
|
145
|
+
|
146
|
+
context 'requested by suppliers user' do
|
147
|
+
let(:resource) {
|
148
|
+
variant = create(:product).master
|
149
|
+
variant.product.add_supplier! user.supplier
|
150
|
+
Spree::StockMovement.new({ stock_item: user.supplier.stock_locations.first.stock_items.first }, without_protection: true)
|
151
|
+
}
|
152
|
+
it_should_behave_like 'access granted'
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
context 'for Supplier' do
|
157
|
+
context 'requested by any user' do
|
158
|
+
let(:ability) { Spree::SupplierAbility.new(create(:user)) }
|
159
|
+
let(:resource) { Spree::Supplier }
|
160
|
+
|
161
|
+
it_should_behave_like 'admin denied'
|
162
|
+
it_should_behave_like 'access denied'
|
163
|
+
end
|
164
|
+
|
165
|
+
context 'requested by suppliers user' do
|
166
|
+
let(:resource) { user.supplier }
|
167
|
+
it_should_behave_like 'admin granted'
|
168
|
+
it_should_behave_like 'update only'
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
end
|
@@ -0,0 +1,123 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Spree::Supplier do
|
4
|
+
|
5
|
+
it { should belong_to(:address) }
|
6
|
+
|
7
|
+
it { should have_many(:products).through(:variants) }
|
8
|
+
it { should have_many(:stock_locations) }
|
9
|
+
it { should have_many(:users) }
|
10
|
+
it { should have_many(:variants).through(:supplier_variants) }
|
11
|
+
|
12
|
+
it { should validate_presence_of(:email) }
|
13
|
+
it { should validate_presence_of(:name) }
|
14
|
+
|
15
|
+
it '#deleted?' do
|
16
|
+
subject.deleted_at = nil
|
17
|
+
subject.deleted_at?.should eql(false)
|
18
|
+
subject.deleted_at = Time.now
|
19
|
+
subject.deleted_at?.should eql(true)
|
20
|
+
end
|
21
|
+
|
22
|
+
context '#assign_user' do
|
23
|
+
|
24
|
+
before do
|
25
|
+
@instance = build(:supplier)
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'with user' do
|
29
|
+
Spree.user_class.should_not_receive :find_by_email
|
30
|
+
@instance.email = 'test@test.com'
|
31
|
+
@instance.users << create(:user)
|
32
|
+
@instance.save
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'with existing user email' do
|
36
|
+
user = create(:user, email: 'test@test.com')
|
37
|
+
Spree.user_class.should_receive(:find_by_email).with(user.email).and_return(user)
|
38
|
+
@instance.email = user.email
|
39
|
+
@instance.save
|
40
|
+
@instance.reload.users.first.should eql(user)
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
it '#create_stock_location' do
|
46
|
+
Spree::StockLocation.count.should eql(0)
|
47
|
+
supplier = create :supplier
|
48
|
+
Spree::StockLocation.first.active.should be true
|
49
|
+
Spree::StockLocation.first.country.should eql(supplier.address.country)
|
50
|
+
Spree::StockLocation.first.supplier.should eql(supplier)
|
51
|
+
end
|
52
|
+
|
53
|
+
context '#send_welcome' do
|
54
|
+
|
55
|
+
after do
|
56
|
+
SpreeDropShip::Config[:send_supplier_email] = true
|
57
|
+
end
|
58
|
+
|
59
|
+
before do
|
60
|
+
@instance = build(:supplier)
|
61
|
+
@mail_message = double('Mail::Message')
|
62
|
+
end
|
63
|
+
|
64
|
+
context 'with Spree::DropShipConfig[:send_supplier_email] == false' do
|
65
|
+
|
66
|
+
it 'should not send' do
|
67
|
+
SpreeDropShip::Config[:send_supplier_email] = false
|
68
|
+
expect {
|
69
|
+
Spree::SupplierMailer.should_not_receive(:welcome).with(an_instance_of(Integer))
|
70
|
+
}
|
71
|
+
@instance.save
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|
75
|
+
|
76
|
+
context 'with Spree::DropShipConfig[:send_supplier_email] == true' do
|
77
|
+
|
78
|
+
it 'should send welcome email' do
|
79
|
+
expect {
|
80
|
+
Spree::SupplierMailer.should_receive(:welcome).with(an_instance_of(Integer))
|
81
|
+
}
|
82
|
+
@instance.save
|
83
|
+
end
|
84
|
+
|
85
|
+
end
|
86
|
+
|
87
|
+
end
|
88
|
+
|
89
|
+
it '#set_commission' do
|
90
|
+
SpreeDropShip::Config.set default_commission_flat_rate: 1
|
91
|
+
SpreeDropShip::Config.set default_commission_percentage: 1
|
92
|
+
supplier = create :supplier
|
93
|
+
SpreeDropShip::Config.set default_commission_flat_rate: 0
|
94
|
+
SpreeDropShip::Config.set default_commission_percentage: 0
|
95
|
+
# Default configuration is 0.0 for each.
|
96
|
+
supplier.commission_flat_rate.to_f.should eql(1.0)
|
97
|
+
supplier.commission_percentage.to_f.should eql(1.0)
|
98
|
+
# With custom commission applied.
|
99
|
+
supplier = create :supplier, commission_flat_rate: 123, commission_percentage: 25
|
100
|
+
supplier.commission_flat_rate.should eql(123.0)
|
101
|
+
supplier.commission_percentage.should eql(25.0)
|
102
|
+
end
|
103
|
+
|
104
|
+
describe '#shipments' do
|
105
|
+
|
106
|
+
let!(:supplier) { create(:supplier) }
|
107
|
+
|
108
|
+
it 'should return shipments for suppliers stock locations' do
|
109
|
+
stock_location_1 = supplier.stock_locations.first
|
110
|
+
stock_location_2 = create(:stock_location, supplier: supplier)
|
111
|
+
shipment_1 = create(:shipment)
|
112
|
+
shipment_2 = create(:shipment, stock_location: stock_location_1)
|
113
|
+
shipment_3 = create(:shipment)
|
114
|
+
shipment_4 = create(:shipment, stock_location: stock_location_2)
|
115
|
+
shipment_5 = create(:shipment)
|
116
|
+
shipment_6 = create(:shipment, stock_location: stock_location_1)
|
117
|
+
|
118
|
+
expect(supplier.shipments).to match_array([shipment_2, shipment_4, shipment_6])
|
119
|
+
end
|
120
|
+
|
121
|
+
end
|
122
|
+
|
123
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Spree.user_class do
|
4
|
+
|
5
|
+
it { should belong_to(:supplier) }
|
6
|
+
|
7
|
+
it { should have_many(:variants).through(:supplier) }
|
8
|
+
|
9
|
+
let(:user) { build :user }
|
10
|
+
|
11
|
+
it '#supplier?' do
|
12
|
+
user.supplier?.should be false
|
13
|
+
user.supplier = build :supplier
|
14
|
+
user.supplier?.should be true
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|