spree_marketplace 3.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +15 -0
  3. data/.rspec +1 -0
  4. data/.travis.yml +13 -0
  5. data/Gemfile +14 -0
  6. data/LICENSE +21 -0
  7. data/README.md +87 -0
  8. data/Rakefile +15 -0
  9. data/Versionfile +12 -0
  10. data/app/assets/javascripts/spree/backend/spree_marketplace.js.coffee +24 -0
  11. data/app/assets/javascripts/spree/frontend/spree_marketplace.js +2 -0
  12. data/app/assets/javascripts/spree/frontend/supplier_address.js.coffee +56 -0
  13. data/app/assets/stylesheets/spree/backend/spree_marketplace.css +3 -0
  14. data/app/assets/stylesheets/spree/frontend/spree_marketplace.css +10 -0
  15. data/app/controllers/spree/admin/marketplace_settings_controller.rb +19 -0
  16. data/app/controllers/spree/admin/supplier_bank_accounts_controller.rb +24 -0
  17. data/app/controllers/spree/suppliers_controller.rb +67 -0
  18. data/app/models/spree/marketplace_ability.rb +14 -0
  19. data/app/models/spree/marketplace_configuration.rb +27 -0
  20. data/app/models/spree/supplier_ability.rb +76 -0
  21. data/app/models/spree/supplier_bank_account.rb +15 -0
  22. data/app/models/spree/supplier_decorator.rb +55 -0
  23. data/app/overrides/spree/admin/shared/_configuration_menu/add_marketplace_settings.html.erb.deface +3 -0
  24. data/app/overrides/spree/admin/suppliers/edit/add_bank_accounts.html.erb.deface +14 -0
  25. data/app/overrides/spree/layouts/admin/add_stripe_js_to_head.html.erb.deface +6 -0
  26. data/app/overrides/spree/users/show/add_supplier_info.html.erb.deface +17 -0
  27. data/app/views/spree/admin/marketplace_settings/edit.html.erb +23 -0
  28. data/app/views/spree/admin/supplier_bank_accounts/new.html.erb +28 -0
  29. data/app/views/spree/suppliers/new.html.erb +29 -0
  30. data/config/locales/en.yml +14 -0
  31. data/config/locales/es.yml +30 -0
  32. data/config/routes.rb +9 -0
  33. data/db/migrate/20130424201333_create_supplier_bank_accounts.rb +12 -0
  34. data/db/migrate/20131209022116_convert_to_stripe.rb +6 -0
  35. data/lib/generators/spree_marketplace/install/install_generator.rb +31 -0
  36. data/lib/spree_marketplace.rb +4 -0
  37. data/lib/spree_marketplace/engine.rb +47 -0
  38. data/lib/spree_marketplace/factories.rb +29 -0
  39. data/script/rails +7 -0
  40. data/spec/features/admin/bank_accounts_spec.rb +50 -0
  41. data/spec/features/admin/products_spec.rb +225 -0
  42. data/spec/features/admin/properties_spec.rb +91 -0
  43. data/spec/features/admin/relations_spec.rb +31 -0
  44. data/spec/features/admin/return_authorizations_spec.rb +7 -0
  45. data/spec/features/admin/settings_spec.rb +29 -0
  46. data/spec/features/admin/suppliers_controller_spec.rb +43 -0
  47. data/spec/features/supplier_signup_spec.rb +134 -0
  48. data/spec/models/spree/marketplace_ability_spec.rb +32 -0
  49. data/spec/models/spree/supplier_ability_spec.rb +337 -0
  50. data/spec/models/spree/supplier_bank_account_spec.rb +13 -0
  51. data/spec/models/spree/supplier_spec.rb +7 -0
  52. data/spec/spec_helper.rb +85 -0
  53. data/spec/support/integration_helpers.rb +15 -0
  54. data/spree_marketplace.gemspec +90 -0
  55. metadata +391 -0
@@ -0,0 +1,29 @@
1
+ require 'spree_drop_ship/factories'
2
+
3
+ FactoryGirl.modify do
4
+ factory :supplier, :class => Spree::Supplier do
5
+ sequence(:name) { |i| "Big Store #{i}" }
6
+ email { Faker::Internet.email }
7
+ first_name 'First'
8
+ last_name 'Last'
9
+ url "http://example.com"
10
+ address
11
+ end
12
+ end
13
+
14
+ FactoryGirl.define do
15
+ # Define your Spree extensions Factories within this file to enable applications, and other extensions to use and override them.
16
+ #
17
+ # Example adding this to your spec_helper will load these Factories for use:
18
+ # require 'spree_marketplace/factories'
19
+
20
+ factory :supplier_bank_account, class: Spree::SupplierBankAccount do
21
+ supplier
22
+ # Details sent to Balanced.
23
+ name 'John Doe'
24
+ account_number '9900000001'
25
+ routing_number '121000358'
26
+ type 'checking'
27
+ end
28
+
29
+ end
@@ -0,0 +1,7 @@
1
+ # This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
2
+
3
+ ENGINE_ROOT = File.expand_path('../..', __FILE__)
4
+ ENGINE_PATH = File.expand_path('../../lib/spree_marketplace/engine', __FILE__)
5
+
6
+ require 'rails/all'
7
+ require 'rails/engine/commands'
@@ -0,0 +1,50 @@
1
+ require 'spec_helper'
2
+
3
+ feature 'Admin - Supplier Bank Accounts', js: true do
4
+
5
+ before do
6
+ country = create(:country, name: "United States")
7
+ create(:state, name: "Vermont", country: country)
8
+ end
9
+
10
+ context 'w/Stripe' do
11
+
12
+ before do
13
+ SpreeMarketplace::Config[:stripe_publishable_key] = 'pk_test_DIeu8D1IIjLId2xA02TEJthB'
14
+ SpreeMarketplace::Config[:stripe_secret_key] = 'sk_test_2K6AkjxetfMFks2xBoGKB6wy'
15
+ end
16
+
17
+ context 'as a Supplier' do
18
+
19
+ before do
20
+ login_user create(:supplier_user)
21
+ visit spree.account_path
22
+ within 'dd.supplier-info' do
23
+ click_link 'Edit'
24
+ end
25
+ end
26
+
27
+ scenario 'adding bank accounts should work' do
28
+ click_link 'Add Bank Account'
29
+ fill_in 'supplier_bank_account[account_number]', with: '000123456789'
30
+ fill_in 'supplier_bank_account[routing_number]', with: '110000000'
31
+ select2 'United States', from: 'Country'
32
+ click_button 'Save'
33
+ page.should have_content('xxxxxx6789')
34
+ page.should have_content('Supplier bank account "STRIPE TEST BANK" has been successfully created!')
35
+ end
36
+
37
+ scenario 'adding invalid bank accounts should display error' do
38
+ click_link 'Add Bank Account'
39
+ fill_in 'supplier_bank_account[account_number]', with: '111111111111'
40
+ fill_in 'supplier_bank_account[routing_number]', with: '110000000'
41
+ select2 'United States', from: 'Country'
42
+ click_button 'Save'
43
+ page.should have_content('Must only use a test bank account number when making transfers in test mode')
44
+ end
45
+
46
+ end
47
+
48
+ end
49
+
50
+ end
@@ -0,0 +1,225 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Admin - Products', js: true do
4
+
5
+ context 'as Admin' do
6
+
7
+ xit 'should be able to change supplier' do
8
+ s1 = create(:supplier)
9
+ s2 = create(:supplier)
10
+ product = create :product
11
+ product.add_supplier! s1
12
+
13
+ login_user create(:admin_user)
14
+ visit spree.admin_product_path(product)
15
+
16
+ select2 s2.name, from: 'Supplier'
17
+ click_button 'Update'
18
+
19
+ expect(page).to have_content("Product \"#{product.name}\" has been successfully updated!")
20
+ expect(product.reload.suppliers.first.id).to eql(s2.id)
21
+ end
22
+
23
+ it 'should display all products' do
24
+ product1 = create :product
25
+ product2 = create :product
26
+ product2.add_supplier! create(:supplier)
27
+ product2.reload
28
+ product3 = create :product
29
+ product3.add_supplier! create(:supplier)
30
+ product3.reload
31
+
32
+ login_user create(:admin_user)
33
+ visit spree.admin_products_path
34
+
35
+ page.should have_content(product1.name)
36
+ page.should have_content(product2.name)
37
+ page.should have_content(product3.name)
38
+ end
39
+
40
+ end
41
+
42
+ context 'as Supplier' do
43
+
44
+ before do
45
+ @supplier_user = create(:supplier_user)
46
+ @supplier = @supplier_user.supplier
47
+ login_user @supplier_user
48
+ end
49
+
50
+ context "searching products works with only suppliers in results" do
51
+ it "should be able to search deleted products", :js => true do
52
+ p1 = create(:product, :name => 'apache baseball cap', :deleted_at => "2011-01-06 18:21:13")
53
+ p1.add_supplier! @supplier
54
+ p2 = create(:product, :name => 'zomg shirt')
55
+ p2.add_supplier! @supplier
56
+ create(:product, :name => 'apache baseball bat', :deleted_at => "2011-01-06 18:21:13")
57
+ create(:product, :name => 'zomg bat')
58
+
59
+ visit spree.admin_products_path
60
+ page.should have_content("zomg shirt")
61
+ page.should_not have_content("apache baseball cap")
62
+ page.should_not have_content("apache baseball bat")
63
+ page.should_not have_content("zomg bat")
64
+ check "Show Deleted"
65
+ click_icon :search
66
+ page.should have_content("zomg shirt")
67
+ page.should have_content("apache baseball cap")
68
+ page.should_not have_content("apache baseball bat")
69
+ page.should_not have_content("zomg bat")
70
+ uncheck "Show Deleted"
71
+ click_icon :search
72
+ page.should have_content("zomg shirt")
73
+ page.should_not have_content("apache baseball cap")
74
+ page.should_not have_content("apache baseball bat")
75
+ page.should_not have_content("zomg bat")
76
+ end
77
+
78
+ it "should be able to search products by their properties with only suppliers in results" do
79
+ p1 = create(:product, :name => 'apache baseball cap', :sku => "A100")
80
+ p1.add_supplier! @supplier
81
+ create(:product, :name => 'apache baseball cap2', :sku => "B100")
82
+ create(:product, :name => 'zomg shirt')
83
+ p2 = create(:product, :name => 'zomg skirt')
84
+ p2.add_supplier! @supplier
85
+
86
+
87
+ visit spree.admin_products_path
88
+ fill_in "q_name_cont", :with => "ap"
89
+ click_icon :search
90
+ page.should have_content("apache baseball cap")
91
+ page.should_not have_content("apache baseball cap2")
92
+ page.should_not have_content("zomg shirt")
93
+ page.should_not have_content("zomg skirt")
94
+
95
+ fill_in "q_variants_including_master_sku_cont", :with => "A1"
96
+ click_icon :search
97
+ page.should have_content("apache baseball cap")
98
+ page.should_not have_content("apache baseball cap2")
99
+ page.should_not have_content("zomg shirt")
100
+ page.should_not have_content("zomg skirt")
101
+ end
102
+ end
103
+
104
+ context "creating a new product from a prototype" do
105
+ def build_option_type_with_values(name, values)
106
+ ot = FactoryGirl.create(:option_type, :name => name)
107
+ values.each do |val|
108
+ ot.option_values.create(:name => val.downcase, :presentation => val)
109
+ end
110
+ ot
111
+ end
112
+
113
+ let(:prototype) do
114
+ size = build_option_type_with_values("size", %w(Small Medium Large))
115
+ create(:prototype, :name => "Size", :option_types => [ size ])
116
+ end
117
+
118
+ before do
119
+ @option_type_prototype = prototype
120
+ @property_prototype = create(:prototype, :name => "Random")
121
+ @shipping_category = create(:shipping_category)
122
+ visit spree.admin_products_path
123
+ click_link "admin_new_product"
124
+ within('#new_product') do
125
+ page.should have_content("SKU")
126
+ end
127
+ end
128
+
129
+ it "should allow an supplier to create a new product and variants from a prototype" do
130
+ fill_in "product_name", :with => "Baseball Cap"
131
+ fill_in "product_sku", :with => "B100"
132
+ fill_in "product_price", :with => "100"
133
+ fill_in "product_available_on", :with => "2012/01/24"
134
+ select "Size", :from => "Prototype"
135
+ check "Large"
136
+ select @shipping_category.name, from: "product_shipping_category_id"
137
+ click_button "Create"
138
+ page.should have_content("successfully created!")
139
+ Spree::Product.last.variants.length.should == 1
140
+ # Check suppliers assigned properly
141
+ expect(Spree::Product.last.supplier_ids).to include(@supplier.id)
142
+ end
143
+
144
+ end
145
+
146
+ context "creating a new product" do
147
+
148
+ before do
149
+ @shipping_category = create(:shipping_category)
150
+ end
151
+
152
+ it "should allow an supplier to create a new product" do
153
+ visit spree.admin_products_path
154
+ click_link "admin_new_product"
155
+ within('#new_product') do
156
+ page.should have_content("SKU")
157
+ end
158
+ fill_in "product_name", :with => "Baseball Cap"
159
+ fill_in "product_sku", :with => "B100"
160
+ fill_in "product_price", :with => "100"
161
+ fill_in "product_available_on", :with => "2012/01/24"
162
+ select @shipping_category.name, from: "product_shipping_category_id"
163
+ click_button "Create"
164
+ page.should have_content("successfully created!")
165
+ click_button "Update"
166
+ page.should have_content("successfully updated!")
167
+ # Check suppliers assigned properly
168
+ expect(Spree::Product.last.supplier_ids).to include(@supplier.id)
169
+ end
170
+
171
+ end
172
+
173
+ context "cloning a product" do
174
+ it "should allow an supplier to clone a product" do
175
+ p = create(:product)
176
+ p.add_supplier! @supplier
177
+
178
+ visit spree.admin_products_path
179
+ within_row(1) do
180
+ click_icon :copy
181
+ end
182
+
183
+ page.should have_content("Product has been cloned")
184
+ # Check suppliers assigned properly
185
+ expect(Spree::Product.last.supplier_ids).to include(@supplier.id)
186
+ end
187
+
188
+ context "cloning a deleted product" do
189
+ it "should allow an supplier to clone a deleted product" do
190
+ p = create(:product, name: "apache baseball cap")
191
+ p.add_supplier! @supplier
192
+
193
+ visit spree.admin_products_path
194
+ check "Show Deleted"
195
+ click_button "Search"
196
+
197
+ page.should have_content("apache baseball cap")
198
+
199
+ within_row(1) do
200
+ click_icon :copy
201
+ end
202
+
203
+ page.should have_content("Product has been cloned")
204
+ # Check suppliers assigned properly
205
+ expect(Spree::Product.last.supplier_ids).to include(@supplier.id)
206
+ end
207
+ end
208
+ end
209
+
210
+ context 'updating a product' do
211
+ let(:product) {
212
+ p = create(:product)
213
+ p.add_supplier! @supplier
214
+ p.reload
215
+ }
216
+
217
+ it 'should not display supplier selection' do
218
+ visit spree.admin_product_path(product)
219
+ page.should_not have_css('#product_supplier_id')
220
+ end
221
+ end
222
+
223
+ end
224
+
225
+ end
@@ -0,0 +1,91 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Admin - Properties" do
4
+
5
+ context 'as Supplier' do
6
+
7
+ before do
8
+ @supplier_user = create(:supplier_user)
9
+ @supplier = @supplier_user.supplier
10
+ login_user @supplier_user
11
+ visit spree.admin_products_path
12
+ end
13
+
14
+ context "listing product properties" do
15
+ it "should list the existing product properties" do
16
+ create(:property, name: 'shirt size', presentation: 'size')
17
+ create(:property, name: 'shirt fit', presentation: 'fit')
18
+
19
+ click_link "Properties"
20
+ within_row(1) do
21
+ column_text(1).should == "shirt size"
22
+ column_text(2).should == "size"
23
+ end
24
+ skip 'used to work not sure why not anymore'
25
+ within_row(2) do
26
+ column_text(1).should == "shirt fit"
27
+ column_text(2).should == "fit"
28
+ end
29
+ end
30
+ end
31
+
32
+ context "creating a property" do
33
+ it "should allow an admin to create a new product property", :js => true do
34
+ skip 'Not sure if we want to allow this yet.'
35
+ # click_link "Properties"
36
+ # click_link "new_property_link"
37
+ # within('#new_property') { page.should have_content("New Property") }
38
+ #
39
+ # fill_in "property_name", :with => "color of band"
40
+ # fill_in "property_presentation", :with => "color"
41
+ # click_button "Create"
42
+ # page.should have_content("successfully created!")
43
+ end
44
+ end
45
+
46
+ # TODO 'Not sure if we want to allow this yet.'
47
+ # context "editing a property" do
48
+ # before(:each) do
49
+ # create(:property)
50
+ # click_link "Properties"
51
+ # within_row(1) { click_icon :edit }
52
+ # end
53
+ #
54
+ # it "should allow an admin to edit an existing product property" do
55
+ # fill_in "property_name", :with => "model 99"
56
+ # click_button "Update"
57
+ # page.should have_content("successfully updated!")
58
+ # page.should have_content("model 99")
59
+ # end
60
+ #
61
+ # it "should show validation errors" do
62
+ # fill_in "property_name", :with => ""
63
+ # click_button "Update"
64
+ # page.should have_content("Name can't be blank")
65
+ # end
66
+ # end
67
+
68
+ context "linking a property to a product", js: true do
69
+ before do
70
+ skip 'Still need to add proper support for managing products'
71
+ p = create(:product)
72
+ p.add_supplier! @supplier
73
+
74
+ visit spree.admin_products_path
75
+ click_icon :edit
76
+ click_link "Product Properties"
77
+ end
78
+
79
+ # Regression test for #2279
80
+ it 'should be successful' do
81
+ expect(page).to have_content('Editing Product')
82
+ fill_in "product_product_properties_attributes_0_property_name", with: "A Property"
83
+ fill_in "product_product_properties_attributes_0_value", with: "A Value"
84
+ click_button "Update"
85
+ click_link "Product Properties"
86
+ expect(page).to have_css("tbody#product_properties")
87
+ expect(all("tbody#product_properties tr").count).to eq 2
88
+ end
89
+ end
90
+ end
91
+ end
@@ -0,0 +1,31 @@
1
+ require 'spec_helper'
2
+
3
+ feature 'Admin - Product Relation Management', js: true do
4
+
5
+ before do
6
+ Spree::RelationType.create(:name => "Related Products", :applies_to => "Spree::Product")
7
+ @user = create(:supplier_user)
8
+ @supplier1 = @user.supplier
9
+ @supplier2 = create(:supplier)
10
+ @product1 = create :product
11
+ @product1.add_supplier! @supplier1
12
+ # TODO shoudl we allow them to relate to anyones product or only their own?
13
+ @product2 = create :product
14
+ end
15
+
16
+ context 'as Supplier' do
17
+ scenario 'should be able to add relations' do
18
+ skip 'for some reason targetted_select2_search is not working properly'
19
+ login_user @user
20
+ visit spree.related_admin_product_path(@product1)
21
+ targetted_select2_search @product2.name, from: 'Name or SKU'
22
+ select2 @product2.name, from: 'Name or SKU'
23
+ click_link 'Add'
24
+ wait_for_ajax
25
+ within '#products-table-wrapper' do
26
+ page.should have_content(@product2.name)
27
+ end
28
+ end
29
+ end
30
+
31
+ end
@@ -0,0 +1,7 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Admin - Return Authorizations" do
4
+
5
+ skip 'TODO: need to write, but should likely wait until after https://github.com/spree/spree/issues/4026'
6
+
7
+ end