shopping_mall 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +27 -0
  3. data/.rspec +1 -0
  4. data/.travis.yml +7 -0
  5. data/Gemfile +6 -0
  6. data/LICENSE.txt +22 -0
  7. data/README.md +94 -0
  8. data/Rakefile +16 -0
  9. data/app/models/spree/option_type_decorator.rb +7 -0
  10. data/app/models/spree/option_types_prototype.rb +6 -0
  11. data/app/models/spree/option_value_decorator.rb +6 -0
  12. data/app/models/spree/option_values_variant.rb +6 -0
  13. data/app/models/spree/order_decorator.rb +6 -0
  14. data/app/models/spree/orders_promotion.rb +6 -0
  15. data/app/models/spree/product_decorator.rb +6 -0
  16. data/app/models/spree/products_promotion_rule.rb +6 -0
  17. data/app/models/spree/promotion_decorator.rb +4 -0
  18. data/app/models/spree/promotion_rule_decorator.rb +6 -0
  19. data/app/models/spree/properties_prototype.rb +6 -0
  20. data/app/models/spree/property_decorator.rb +16 -0
  21. data/app/models/spree/prototype_decorator.rb +10 -0
  22. data/app/models/spree/role_decorator.rb +4 -0
  23. data/app/models/spree/roles_user.rb +6 -0
  24. data/app/models/spree/shipping_method_decorator.rb +4 -0
  25. data/app/models/spree/shipping_methods_zone.rb +6 -0
  26. data/app/models/spree/user_decorator.rb +4 -0
  27. data/app/models/spree/variant_decorator.rb +6 -0
  28. data/app/models/spree/zone_decorator.rb +32 -0
  29. data/app/models/spree/zone_member_decorator.rb +16 -0
  30. data/config/initializers/shopping_mall_initializer.rb +3 -0
  31. data/db/migrate/20140611225105_hatbm_to_hmt.rb +17 -0
  32. data/lib/generators/shopping_mall/install_generator.rb +41 -0
  33. data/lib/generators/templates/shopping_mall.rb +20 -0
  34. data/lib/shopping_mall/engine.rb +18 -0
  35. data/lib/shopping_mall/escalator.rb +20 -0
  36. data/lib/shopping_mall/version.rb +3 -0
  37. data/lib/shopping_mall.rb +50 -0
  38. data/lib/tasks/db.rake +41 -0
  39. data/shopping_mall.gemspec +40 -0
  40. data/spec/features/tenancy_spec.rb +13 -0
  41. data/spec/models/spree/option_type_decorator_spec.rb +12 -0
  42. data/spec/models/spree/option_value_decorator_spec.rb +12 -0
  43. data/spec/models/spree/order_decorator_spec.rb +13 -0
  44. data/spec/models/spree/product_decorator_spec.rb +12 -0
  45. data/spec/models/spree/promotion_decorator_spec.rb +12 -0
  46. data/spec/models/spree/property_decorator_spec.rb +21 -0
  47. data/spec/models/spree/prototype_decorator_spec.rb +19 -0
  48. data/spec/models/spree/role_decorator_spec.rb +14 -0
  49. data/spec/models/spree/shipping_method_decorator_spec.rb +12 -0
  50. data/spec/models/spree/user_decorator_spec.rb +16 -0
  51. data/spec/models/spree/variant_decorator_spec.rb +13 -0
  52. data/spec/models/spree/zone_decorator_spec.rb +78 -0
  53. data/spec/shopping_mall/config_spec.rb +37 -0
  54. data/spec/shopping_mall/escalator_spec.rb +31 -0
  55. data/spec/spec_helper.rb +49 -0
  56. metadata +353 -0
@@ -0,0 +1,13 @@
1
+ require 'spec_helper'
2
+
3
+ feature 'Tenancy', js: true do
4
+ context 'index' do
5
+ background do
6
+ visit 'http://tenant-name.example.dev:3000'
7
+ end
8
+
9
+ xscenario 'homepage' do
10
+ expect(page).to have_text 'welcome'
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,12 @@
1
+ require 'spec_helper'
2
+
3
+ describe Spree::OptionType do
4
+ it { should have_many(:prototypes).through(:option_types_prototypes) }
5
+
6
+ context 'has_many through sanity check' do
7
+ it 'associates correctly' do
8
+ option_type = create :option_type, prototypes: [create(:prototype)]
9
+ expect(option_type.prototypes.size).to eq 1
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,12 @@
1
+ require 'spec_helper'
2
+
3
+ describe Spree::OptionValue do
4
+ it { should have_many(:variants).through(:option_values_variants) }
5
+
6
+ context 'has_many through sanity check' do
7
+ it 'associates correctly' do
8
+ option_value = create :option_value, variants: [create(:variant)]
9
+ expect(option_value.variants.size).to eq 1
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,13 @@
1
+ require 'spec_helper'
2
+
3
+ describe Spree::Order do
4
+ it { should have_many(:promotions).through(:orders_promotions) }
5
+
6
+ context 'has_many through sanity check' do
7
+ it 'associates correctly' do
8
+ order = create :order, promotions: [create(:promotion)]
9
+ expect(order.promotions.size).to eq 1
10
+ end
11
+ end
12
+
13
+ end
@@ -0,0 +1,12 @@
1
+ require 'spec_helper'
2
+
3
+ describe Spree::Product do
4
+ it { should have_many(:promotion_rules).through(:products_promotion_rules) }
5
+
6
+ context 'has_many through sanity check' do
7
+ it 'associates correctly' do
8
+ product = create :product, promotion_rules: [Spree::PromotionRule.new]
9
+ expect(product.promotion_rules.size).to eq 1
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,12 @@
1
+ require 'spec_helper'
2
+
3
+ describe Spree::Promotion do
4
+ it { should have_many(:orders).through(:orders_promotions) }
5
+
6
+ context 'has_many through sanity check' do
7
+ it 'associates correctly' do
8
+ promotion = create :promotion, orders: [create(:order)]
9
+ expect(promotion.orders.size).to eq 1
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,21 @@
1
+ require 'spec_helper'
2
+
3
+ describe Spree::Property do
4
+ it { should have_many(:prototypes).through(:properties_prototypes) }
5
+
6
+ context 'has_many through sanity check' do
7
+ it 'associates correctly' do
8
+ property = create :property, prototypes: [create(:prototype)]
9
+ expect(property.prototypes.size).to eq 1
10
+ end
11
+ end
12
+
13
+ context '#find_all_by_prototype' do
14
+ it 'returns all found properties' do
15
+ properties = (1..5).map { create(:property) }
16
+ prototype = create :prototype, properties: properties
17
+
18
+ expect(Spree::Property.find_all_by_prototype(prototype)).to eq properties
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+
3
+ describe Spree::Prototype do
4
+ it { should have_many(:properties).through(:properties_prototypes) }
5
+ it { should have_many(:option_types).through(:option_types_prototypes) }
6
+
7
+ context 'has_many through sanity check' do
8
+ subject { create :prototype }
9
+
10
+ it 'associates properties correctly' do
11
+ expect(subject.properties.size).to eq 1
12
+ end
13
+
14
+ it 'associates option_types correctly' do
15
+ subject.option_types << create(:option_type)
16
+ expect(subject.option_types.size).to eq 1
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,14 @@
1
+ require 'spec_helper'
2
+
3
+ describe Spree::Role do
4
+ it { should have_many(:users).through(:roles_users) }
5
+
6
+ context 'has_many through sanity check' do
7
+ it 'associates correctly' do
8
+ role = create :role
9
+ role.users << create(:user)
10
+
11
+ expect(role.users.size).to eq 1
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,12 @@
1
+ require 'spec_helper'
2
+
3
+ describe Spree::ShippingMethod do
4
+ it { should have_many(:zones).through(:shipping_methods_zones) }
5
+
6
+ context 'has_many through sanity check' do
7
+ it 'associates correctly' do
8
+ shipping_method = create :shipping_method
9
+ expect(shipping_method.zones.size).to eq 1
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,16 @@
1
+ require 'spec_helper'
2
+
3
+ describe Spree::User do
4
+ it { should have_many(:roles).through(:roles_users) }
5
+
6
+ it 'is on default_schema' do
7
+ expect(Spree::User.table_name).to eq 'public.spree_users'
8
+ end
9
+
10
+ context 'has_many through sanity check' do
11
+ it 'associates correctly' do
12
+ user = create :user, roles: [create(:role)]
13
+ expect(user.roles.size).to eq(1)
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,13 @@
1
+ require 'spec_helper'
2
+
3
+ describe Spree::Variant do
4
+ it { should have_many(:option_values).through(:option_values_variants) }
5
+
6
+ context 'has_many through sanity check' do
7
+ it 'associates correctly' do
8
+ option = create(:option_value)
9
+ variant = create :variant, option_values: [option]
10
+ expect(variant.option_values).to include option
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,78 @@
1
+ require 'spec_helper'
2
+
3
+ describe Spree::Zone do
4
+ it { should have_many(:shipping_methods).through(:shipping_methods_zones) }
5
+
6
+ context 'has_many through sanity check' do
7
+ it 'associates correctly' do
8
+ zone = create(:zone, shipping_methods: [create(:shipping_method)])
9
+ expect(zone.shipping_methods.size).to eq 1
10
+ end
11
+ end
12
+
13
+ context '#match' do
14
+ let(:country_zone) { create(:zone, name: 'CountryZone') }
15
+ let(:country) do
16
+ country = create(:country)
17
+ # Create at least one state for this country
18
+ state = create(:state, country: country)
19
+ country
20
+ end
21
+
22
+ before { country_zone.members.create(zoneable: country) }
23
+
24
+ context 'when there is only one qualifying zone' do
25
+ let(:address) do
26
+ create(:address, country: country, state: country.states.first)
27
+ end
28
+
29
+ it 'should return the qualifying zone' do
30
+ Spree::Zone.match(address).should == country_zone
31
+ end
32
+ end
33
+
34
+ context 'when there are two qualified zones with same member type' do
35
+ let(:address) do
36
+ create(:address, country: country, state: country.states.first)
37
+ end
38
+ let(:second_zone) { create(:zone, name: 'SecondZone') }
39
+
40
+ before { second_zone.members.create(zoneable: country) }
41
+
42
+ context 'when both zones have the same number of members' do
43
+ it 'hould return the zone that was created first' do
44
+ Spree::Zone.match(address).should == country_zone
45
+ end
46
+ end
47
+
48
+ context 'when one of the zones has fewer members' do
49
+ let(:country2) { create(:country) }
50
+
51
+ before { country_zone.members.create(zoneable: country2) }
52
+
53
+ it 'should return the zone with fewer members' do
54
+ Spree::Zone.match(address).should == second_zone
55
+ end
56
+ end
57
+ end
58
+
59
+ context 'when there are two qualified zones with different member types' do
60
+ let(:state_zone) { create(:zone, name: 'StateZone') }
61
+ let(:address) do
62
+ create(:address, country: country, state: country.states.first)
63
+ end
64
+
65
+ before { state_zone.members.create(zoneable: country.states.first) }
66
+
67
+ it 'should return the zone with the more specific member type' do
68
+ Spree::Zone.match(address).should == state_zone
69
+ end
70
+ end
71
+
72
+ context 'when there are no qualifying zones' do
73
+ it 'should return nil' do
74
+ Spree::Zone.match(Spree::Address.new).should be_nil
75
+ end
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,37 @@
1
+ require 'spec_helper'
2
+
3
+ describe ShoppingMall do
4
+ context '#configure' do
5
+ it 'Apartment has DEFAULT_SPREE_EXCLUSIONS on initialize' do
6
+ expect(Apartment.excluded_models).to(
7
+ eq(ShoppingMall::DEFAULT_SPREE_EXCLUSIONS)
8
+ )
9
+ end
10
+
11
+ it 'excluded_models is a pass-through to Apartment' do
12
+ exclusions = ['Spree::User']
13
+ ShoppingMall.configure { |config| config.excluded_models = exclusions }
14
+ expect(Apartment.excluded_models).to eq exclusions
15
+ end
16
+
17
+ it 'has a default escalator' do
18
+ expect(ShoppingMall.escalator).to eq 'Subdomain'
19
+ end
20
+
21
+ it 'calling #escalator_class returns Subdomain escalator as default' do
22
+ expect(ShoppingMall.escalator_class).to eq Apartment::Elevators::Subdomain
23
+ end
24
+
25
+ it 'accepts escalator on config' do
26
+ ShoppingMall.configure { |config| config.escalator = 'Domain' }
27
+ expect(ShoppingMall.escalator).to eq 'Domain'
28
+ end
29
+ end
30
+
31
+ after do
32
+ ShoppingMall.configure do |config|
33
+ config.escalator = 'Subdomain'
34
+ config.excluded_models = ShoppingMall::DEFAULT_SPREE_EXCLUSIONS
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,31 @@
1
+ require 'spec_helper'
2
+
3
+ describe ShoppingMall::Escalator do
4
+ context 'delegation' do
5
+ %w[Subdomain Domain FirstSubdomain].each do |domain_type|
6
+ context "with config as #{domain_type}" do
7
+ it "sets delegator as Apartment::Elevator::#{domain_type}" do
8
+ ShoppingMall.configure { |config| config.escalator = domain_type }
9
+ test = ShoppingMall::Escalator.new double(foo: 'bar')
10
+ expect(test.escalator.class.to_s).to(
11
+ eq "Apartment::Elevators::#{domain_type}"
12
+ )
13
+ end
14
+ end
15
+ end
16
+
17
+ it '.call is passed to escalator' do
18
+ test = ShoppingMall::Escalator.new double(foo: 'bar')
19
+ env = Rack::MockRequest.env_for('foo')
20
+ expect(test.escalator).to receive(:call).with(env)
21
+ test.call env
22
+ end
23
+ end
24
+
25
+ after do
26
+ ShoppingMall.configure do |config|
27
+ config.escalator = 'Subdomain'
28
+ config.excluded_models = ShoppingMall::DEFAULT_SPREE_EXCLUSIONS
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,49 @@
1
+ require 'simplecov'
2
+ SimpleCov.start 'rails'
3
+
4
+ ENV["RAILS_ENV"] = 'test'
5
+
6
+ require File.expand_path('../dummy/config/environment.rb', __FILE__)
7
+ require 'rspec/rails'
8
+ require 'shoulda-matchers'
9
+ require 'ffaker'
10
+ require 'database_cleaner'
11
+ require 'capybara'
12
+ require 'capybara/rspec'
13
+ require 'capybara/rails'
14
+ require 'capybara/poltergeist'
15
+
16
+ Dir[File.join(File.dirname(__FILE__), 'support/**/*.rb')].each {|f| require f }
17
+
18
+ require 'spree/testing_support/factories'
19
+ require 'spree/testing_support/controller_requests'
20
+ require 'spree/testing_support/authorization_helpers'
21
+ require 'spree/testing_support/url_helpers'
22
+
23
+ FactoryGirl.find_definitions
24
+
25
+ RSpec.configure do |config|
26
+ config.deprecation_stream = 'rspec.log'
27
+ config.include Spree::TestingSupport::ControllerRequests
28
+ config.include FactoryGirl::Syntax::Methods
29
+ config.include Spree::TestingSupport::UrlHelpers
30
+ config.use_transactional_fixtures = false
31
+ config.expose_current_running_example_as :example
32
+ config.infer_spec_type_from_file_location!
33
+
34
+ config.before(:suite) do
35
+ DatabaseCleaner.strategy = :transaction
36
+ DatabaseCleaner.clean_with(:truncation)
37
+ end
38
+
39
+ config.before do
40
+ DatabaseCleaner.strategy = example.metadata[:js] ? :truncation : :transaction
41
+ DatabaseCleaner.start
42
+ end
43
+
44
+ config.after do
45
+ DatabaseCleaner.clean
46
+ end
47
+
48
+ Capybara.javascript_driver = :poltergeist
49
+ end