Skip to content
This repository
Browse code

Merge pull request #8 from railsdog/topic/seeds-edge

Forward ports jbrien/spree_landlord#19 to master
  • Loading branch information...
commit 52178ce21d11907baea25a431de65303261558f3 2 parents b79eb25 + ea570e4
Jeff Squires jsqu99 authored
36 app/models/spree/tenant.rb
@@ -5,6 +5,8 @@ class Tenant < ActiveRecord::Base
5 5 before_validation :downcase_shortname
6 6 before_validation :ensure_name_is_present
7 7
  8 + after_create :seed_tenant
  9 +
8 10 ['domain', 'shortname'].each do |attrib|
9 11 validates attrib.to_sym, uniqueness: true, presence: true
10 12 end
@@ -29,17 +31,25 @@ def current_tenant_id
29 31 end
30 32
31 33 def set_current_tenant( tenant )
32   - # able to handle tenant obj or tenant_id
33   - case tenant
34   - when Tenant then tenant_id = tenant.id
35   - when Integer then
36   - tenant_id = tenant
37   - unless Spree::Tenant.exists?(tenant_id)
38   - raise Spree::SpreeLandlord::TenantNotFound, "No tenant found with id = #{tenant_id}"
39   - end
40   - else
41   - raise ArgumentError, "invalid tenant object or id"
42   - end # case
  34 + tenant_id = nil
  35 +
  36 + if tenant.present?
  37 + # able to handle tenant obj or tenant_id
  38 + case tenant
  39 + when Tenant then tenant_id = tenant.id
  40 + when Integer then
  41 + tenant_id = tenant
  42 + unless Spree::Tenant.exists?(tenant_id)
  43 + raise Spree::SpreeLandlord::TenantNotFound, "No tenant found with id = #{tenant_id}"
  44 + end
  45 + else
  46 + raise ArgumentError, "invalid tenant object or id"
  47 + end # case
  48 + else
  49 + tenant_id = Spree::Tenant.master.id
  50 + end
  51 +
  52 + raise "Invalid tenant id" if tenant_id.nil?
43 53
44 54 Thread.current[:tenant_id] = tenant_id
45 55 end
@@ -56,5 +66,9 @@ def ensure_name_is_present
56 66 self.name ||= self.shortname.humanize.titleize if self.shortname.present?
57 67 end
58 68 end
  69 +
  70 + def seed_tenant
  71 + Spree::SpreeLandlord::TenantSeeder.new(self).seed
  72 + end
59 73 end
60 74 end
9 app/models/spree/zone_decorator.rb
... ... @@ -0,0 +1,9 @@
  1 +Spree::Zone.class_eval do
  2 + # ugly hack to remove the uniqueness validator on name
  3 + _validate_callbacks.reject! do |callback|
  4 + callback.raw_filter.kind_of?(ActiveRecord::Validations::UniquenessValidator) &&
  5 + callback.raw_filter.attributes == [:name]
  6 + end
  7 +
  8 + validates :name, :uniqueness => { :scope => :tenant_id }
  9 +end
2  db/migrate/20121117163506_add_tennent_id_to_models.rb
@@ -10,4 +10,4 @@ def change
10 10
11 11 Spree::SpreeLandlord::TenantBootstrapper.new.run
12 12 end
13   -end
  13 +end
8 lib/spree/spree_landlord/tenant_bootstrapper.rb
@@ -4,11 +4,19 @@ class TenantBootstrapper
4 4 attr_reader :first_tenant
5 5
6 6 def run
  7 + clear_column_cache
7 8 create_first_tenant
8 9 create_tenants_admin_role
9 10 notify
10 11 end
11 12
  13 + def clear_column_cache
  14 + Spree::Tenant.connection.schema_cache.clear!
  15 + Spree::Landlord.model_names.each do |model|
  16 + model.reset_column_information
  17 + end
  18 + end
  19 +
12 20 def create_first_tenant
13 21 @first_tenant = Spree::Tenant.new
14 22 @first_tenant.domain = "#{dns_friendly_app_name}.dev"
393 lib/spree/spree_landlord/tenant_seeder.rb
... ... @@ -0,0 +1,393 @@
  1 +module Spree
  2 + module SpreeLandlord
  3 + class TenantSeeder
  4 + def initialize(tenant)
  5 + @tenant = tenant
  6 + end
  7 +
  8 + def seed
  9 + seed_roles
  10 + seed_countries
  11 + set_default_country_id
  12 + seed_states
  13 + seed_zones
  14 + seed_zone_members
  15 + end
  16 +
  17 + def seed_roles
  18 + ['admin', 'user'].each do |role_name|
  19 + role = Spree::Role.new
  20 + role.tenant_id = @tenant.id
  21 + role.name = role_name
  22 + role.save!
  23 + end
  24 + end
  25 +
  26 + def seed_countries
  27 + countries_data = [
  28 + {"name"=>"Afghanistan", "iso3"=>"AFG", "iso"=>"AF", "iso_name"=>"AFGHANISTAN", "numcode"=>"4"},
  29 + {"name"=>"Albania", "iso3"=>"ALB", "iso"=>"AL", "iso_name"=>"ALBANIA", "numcode"=>"8"},
  30 + {"name"=>"Algeria", "iso3"=>"DZA", "iso"=>"DZ", "iso_name"=>"ALGERIA", "numcode"=>"12"},
  31 + {"name"=>"American Samoa", "iso3"=>"ASM", "iso"=>"AS", "iso_name"=>"AMERICAN SAMOA", "numcode"=>"16"},
  32 + {"name"=>"Andorra", "iso3"=>"AND", "iso"=>"AD", "iso_name"=>"ANDORRA", "numcode"=>"20"},
  33 + {"name"=>"Angola", "iso3"=>"AGO", "iso"=>"AO", "iso_name"=>"ANGOLA", "numcode"=>"24"},
  34 + {"name"=>"Anguilla", "iso3"=>"AIA", "iso"=>"AI", "iso_name"=>"ANGUILLA", "numcode"=>"660"},
  35 + {"name"=>"Antigua and Barbuda", "iso3"=>"ATG", "iso"=>"AG", "iso_name"=>"ANTIGUA AND BARBUDA", "numcode"=>"28"},
  36 + {"name"=>"Argentina", "iso3"=>"ARG", "iso"=>"AR", "iso_name"=>"ARGENTINA", "numcode"=>"32"},
  37 + {"name"=>"Armenia", "iso3"=>"ARM", "iso"=>"AM", "iso_name"=>"ARMENIA", "numcode"=>"51"},
  38 + {"name"=>"Aruba", "iso3"=>"ABW", "iso"=>"AW", "iso_name"=>"ARUBA", "numcode"=>"533"},
  39 + {"name"=>"Australia", "iso3"=>"AUS", "iso"=>"AU", "iso_name"=>"AUSTRALIA", "numcode"=>"36"},
  40 + {"name"=>"Austria", "iso3"=>"AUT", "iso"=>"AT", "iso_name"=>"AUSTRIA", "numcode"=>"40"},
  41 + {"name"=>"Azerbaijan", "iso3"=>"AZE", "iso"=>"AZ", "iso_name"=>"AZERBAIJAN", "numcode"=>"31"},
  42 + {"name"=>"Bahamas", "iso3"=>"BHS", "iso"=>"BS", "iso_name"=>"BAHAMAS", "numcode"=>"44"},
  43 + {"name"=>"Bahrain", "iso3"=>"BHR", "iso"=>"BH", "iso_name"=>"BAHRAIN", "numcode"=>"48"},
  44 + {"name"=>"Bangladesh", "iso3"=>"BGD", "iso"=>"BD", "iso_name"=>"BANGLADESH", "numcode"=>"50"},
  45 + {"name"=>"Barbados", "iso3"=>"BRB", "iso"=>"BB", "iso_name"=>"BARBADOS", "numcode"=>"52"},
  46 + {"name"=>"Belarus", "iso3"=>"BLR", "iso"=>"BY", "iso_name"=>"BELARUS", "numcode"=>"112"},
  47 + {"name"=>"Belgium", "iso3"=>"BEL", "iso"=>"BE", "iso_name"=>"BELGIUM", "numcode"=>"56"},
  48 + {"name"=>"Belize", "iso3"=>"BLZ", "iso"=>"BZ", "iso_name"=>"BELIZE", "numcode"=>"84"},
  49 + {"name"=>"Benin", "iso3"=>"BEN", "iso"=>"BJ", "iso_name"=>"BENIN", "numcode"=>"204"},
  50 + {"name"=>"Bermuda", "iso3"=>"BMU", "iso"=>"BM", "iso_name"=>"BERMUDA", "numcode"=>"60"},
  51 + {"name"=>"Bhutan", "iso3"=>"BTN", "iso"=>"BT", "iso_name"=>"BHUTAN", "numcode"=>"64"},
  52 + {"name"=>"Bolivia", "iso3"=>"BOL", "iso"=>"BO", "iso_name"=>"BOLIVIA", "numcode"=>"68"},
  53 + {"name"=>"Bosnia and Herzegovina", "iso3"=>"BIH", "iso"=>"BA", "iso_name"=>"BOSNIA AND HERZEGOVINA", "numcode"=>"70"},
  54 + {"name"=>"Botswana", "iso3"=>"BWA", "iso"=>"BW", "iso_name"=>"BOTSWANA", "numcode"=>"72"},
  55 + {"name"=>"Brazil", "iso3"=>"BRA", "iso"=>"BR", "iso_name"=>"BRAZIL", "numcode"=>"76"},
  56 + {"name"=>"Brunei Darussalam", "iso3"=>"BRN", "iso"=>"BN", "iso_name"=>"BRUNEI DARUSSALAM", "numcode"=>"96"},
  57 + {"name"=>"Bulgaria", "iso3"=>"BGR", "iso"=>"BG", "iso_name"=>"BULGARIA", "numcode"=>"100"},
  58 + {"name"=>"Burkina Faso", "iso3"=>"BFA", "iso"=>"BF", "iso_name"=>"BURKINA FASO", "numcode"=>"854"},
  59 + {"name"=>"Burundi", "iso3"=>"BDI", "iso"=>"BI", "iso_name"=>"BURUNDI", "numcode"=>"108"},
  60 + {"name"=>"Cambodia", "iso3"=>"KHM", "iso"=>"KH", "iso_name"=>"CAMBODIA", "numcode"=>"116"},
  61 + {"name"=>"Cameroon", "iso3"=>"CMR", "iso"=>"CM", "iso_name"=>"CAMEROON", "numcode"=>"120"},
  62 + {"name"=>"Canada", "iso3"=>"CAN", "iso"=>"CA", "iso_name"=>"CANADA", "numcode"=>"124"},
  63 + {"name"=>"Cape Verde", "iso3"=>"CPV", "iso"=>"CV", "iso_name"=>"CAPE VERDE", "numcode"=>"132"},
  64 + {"name"=>"Cayman Islands", "iso3"=>"CYM", "iso"=>"KY", "iso_name"=>"CAYMAN ISLANDS", "numcode"=>"136"},
  65 + {"name"=>"Central African Republic", "iso3"=>"CAF", "iso"=>"CF", "iso_name"=>"CENTRAL AFRICAN REPUBLIC", "numcode"=>"140"},
  66 + {"name"=>"Chad", "iso3"=>"TCD", "iso"=>"TD", "iso_name"=>"CHAD", "numcode"=>"148"},
  67 + {"name"=>"Chile", "iso3"=>"CHL", "iso"=>"CL", "iso_name"=>"CHILE", "numcode"=>"152"},
  68 + {"name"=>"China", "iso3"=>"CHN", "iso"=>"CN", "iso_name"=>"CHINA", "numcode"=>"156"},
  69 + {"name"=>"Colombia", "iso3"=>"COL", "iso"=>"CO", "iso_name"=>"COLOMBIA", "numcode"=>"170"},
  70 + {"name"=>"Comoros", "iso3"=>"COM", "iso"=>"KM", "iso_name"=>"COMOROS", "numcode"=>"174"},
  71 + {"name"=>"Congo", "iso3"=>"COG", "iso"=>"CG", "iso_name"=>"CONGO", "numcode"=>"178"},
  72 + {"name"=>"Congo, the Democratic Republic of the", "iso3"=>"COD", "iso"=>"CD", "iso_name"=>"CONGO, THE DEMOCRATIC REPUBLIC OF THE", "numcode"=>"180"},
  73 + {"name"=>"Cook Islands", "iso3"=>"COK", "iso"=>"CK", "iso_name"=>"COOK ISLANDS", "numcode"=>"184"},
  74 + {"name"=>"Costa Rica", "iso3"=>"CRI", "iso"=>"CR", "iso_name"=>"COSTA RICA", "numcode"=>"188"},
  75 + {"name"=>"Cote D'Ivoire", "iso3"=>"CIV", "iso"=>"CI", "iso_name"=>"COTE D'IVOIRE", "numcode"=>"384"},
  76 + {"name"=>"Croatia", "iso3"=>"HRV", "iso"=>"HR", "iso_name"=>"CROATIA", "numcode"=>"191"},
  77 + {"name"=>"Cuba", "iso3"=>"CUB", "iso"=>"CU", "iso_name"=>"CUBA", "numcode"=>"192"},
  78 + {"name"=>"Cyprus", "iso3"=>"CYP", "iso"=>"CY", "iso_name"=>"CYPRUS", "numcode"=>"196"},
  79 + {"name"=>"Czech Republic", "iso3"=>"CZE", "iso"=>"CZ", "iso_name"=>"CZECH REPUBLIC", "numcode"=>"203"},
  80 + {"name"=>"Denmark", "iso3"=>"DNK", "iso"=>"DK", "iso_name"=>"DENMARK", "numcode"=>"208"},
  81 + {"name"=>"Djibouti", "iso3"=>"DJI", "iso"=>"DJ", "iso_name"=>"DJIBOUTI", "numcode"=>"262"},
  82 + {"name"=>"Dominica", "iso3"=>"DMA", "iso"=>"DM", "iso_name"=>"DOMINICA", "numcode"=>"212"},
  83 + {"name"=>"Dominican Republic", "iso3"=>"DOM", "iso"=>"DO", "iso_name"=>"DOMINICAN REPUBLIC", "numcode"=>"214"},
  84 + {"name"=>"Ecuador", "iso3"=>"ECU", "iso"=>"EC", "iso_name"=>"ECUADOR", "numcode"=>"218"},
  85 + {"name"=>"Egypt", "iso3"=>"EGY", "iso"=>"EG", "iso_name"=>"EGYPT", "numcode"=>"818"},
  86 + {"name"=>"El Salvador", "iso3"=>"SLV", "iso"=>"SV", "iso_name"=>"EL SALVADOR", "numcode"=>"222"},
  87 + {"name"=>"Equatorial Guinea", "iso3"=>"GNQ", "iso"=>"GQ", "iso_name"=>"EQUATORIAL GUINEA", "numcode"=>"226"},
  88 + {"name"=>"Eritrea", "iso3"=>"ERI", "iso"=>"ER", "iso_name"=>"ERITREA", "numcode"=>"232"},
  89 + {"name"=>"Estonia", "iso3"=>"EST", "iso"=>"EE", "iso_name"=>"ESTONIA", "numcode"=>"233"},
  90 + {"name"=>"Ethiopia", "iso3"=>"ETH", "iso"=>"ET", "iso_name"=>"ETHIOPIA", "numcode"=>"231"},
  91 + {"name"=>"Falkland Islands (Malvinas)", "iso3"=>"FLK", "iso"=>"FK", "iso_name"=>"FALKLAND ISLANDS (MALVINAS)", "numcode"=>"238"},
  92 + {"name"=>"Faroe Islands", "iso3"=>"FRO", "iso"=>"FO", "iso_name"=>"FAROE ISLANDS", "numcode"=>"234"},
  93 + {"name"=>"Fiji", "iso3"=>"FJI", "iso"=>"FJ", "iso_name"=>"FIJI", "numcode"=>"242"},
  94 + {"name"=>"Finland", "iso3"=>"FIN", "iso"=>"FI", "iso_name"=>"FINLAND", "numcode"=>"246"},
  95 + {"name"=>"France", "iso3"=>"FRA", "iso"=>"FR", "iso_name"=>"FRANCE", "numcode"=>"250"},
  96 + {"name"=>"French Guiana", "iso3"=>"GUF", "iso"=>"GF", "iso_name"=>"FRENCH GUIANA", "numcode"=>"254"},
  97 + {"name"=>"French Polynesia", "iso3"=>"PYF", "iso"=>"PF", "iso_name"=>"FRENCH POLYNESIA", "numcode"=>"258"},
  98 + {"name"=>"Gabon", "iso3"=>"GAB", "iso"=>"GA", "iso_name"=>"GABON", "numcode"=>"266"},
  99 + {"name"=>"Gambia", "iso3"=>"GMB", "iso"=>"GM", "iso_name"=>"GAMBIA", "numcode"=>"270"},
  100 + {"name"=>"Georgia", "iso3"=>"GEO", "iso"=>"GE", "iso_name"=>"GEORGIA", "numcode"=>"268"},
  101 + {"name"=>"Germany", "iso3"=>"DEU", "iso"=>"DE", "iso_name"=>"GERMANY", "numcode"=>"276"},
  102 + {"name"=>"Ghana", "iso3"=>"GHA", "iso"=>"GH", "iso_name"=>"GHANA", "numcode"=>"288"},
  103 + {"name"=>"Gibraltar", "iso3"=>"GIB", "iso"=>"GI", "iso_name"=>"GIBRALTAR", "numcode"=>"292"},
  104 + {"name"=>"Greece", "iso3"=>"GRC", "iso"=>"GR", "iso_name"=>"GREECE", "numcode"=>"300"},
  105 + {"name"=>"Greenland", "iso3"=>"GRL", "iso"=>"GL", "iso_name"=>"GREENLAND", "numcode"=>"304"},
  106 + {"name"=>"Grenada", "iso3"=>"GRD", "iso"=>"GD", "iso_name"=>"GRENADA", "numcode"=>"308"},
  107 + {"name"=>"Guadeloupe", "iso3"=>"GLP", "iso"=>"GP", "iso_name"=>"GUADELOUPE", "numcode"=>"312"},
  108 + {"name"=>"Guam", "iso3"=>"GUM", "iso"=>"GU", "iso_name"=>"GUAM", "numcode"=>"316"},
  109 + {"name"=>"Guatemala", "iso3"=>"GTM", "iso"=>"GT", "iso_name"=>"GUATEMALA", "numcode"=>"320"},
  110 + {"name"=>"Guinea", "iso3"=>"GIN", "iso"=>"GN", "iso_name"=>"GUINEA", "numcode"=>"324"},
  111 + {"name"=>"Guinea-Bissau", "iso3"=>"GNB", "iso"=>"GW", "iso_name"=>"GUINEA-BISSAU", "numcode"=>"624"},
  112 + {"name"=>"Guyana", "iso3"=>"GUY", "iso"=>"GY", "iso_name"=>"GUYANA", "numcode"=>"328"},
  113 + {"name"=>"Haiti", "iso3"=>"HTI", "iso"=>"HT", "iso_name"=>"HAITI", "numcode"=>"332"},
  114 + {"name"=>"Holy See (Vatican City State)", "iso3"=>"VAT", "iso"=>"VA", "iso_name"=>"HOLY SEE (VATICAN CITY STATE)", "numcode"=>"336"},
  115 + {"name"=>"Honduras", "iso3"=>"HND", "iso"=>"HN", "iso_name"=>"HONDURAS", "numcode"=>"340"},
  116 + {"name"=>"Hong Kong", "iso3"=>"HKG", "iso"=>"HK", "iso_name"=>"HONG KONG", "numcode"=>"344"},
  117 + {"name"=>"Hungary", "iso3"=>"HUN", "iso"=>"HU", "iso_name"=>"HUNGARY", "numcode"=>"348"},
  118 + {"name"=>"Iceland", "iso3"=>"ISL", "iso"=>"IS", "iso_name"=>"ICELAND", "numcode"=>"352"},
  119 + {"name"=>"India", "iso3"=>"IND", "iso"=>"IN", "iso_name"=>"INDIA", "numcode"=>"356"},
  120 + {"name"=>"Indonesia", "iso3"=>"IDN", "iso"=>"ID", "iso_name"=>"INDONESIA", "numcode"=>"360"},
  121 + {"name"=>"Iran, Islamic Republic of", "iso3"=>"IRN", "iso"=>"IR", "iso_name"=>"IRAN, ISLAMIC REPUBLIC OF", "numcode"=>"364"},
  122 + {"name"=>"Iraq", "iso3"=>"IRQ", "iso"=>"IQ", "iso_name"=>"IRAQ", "numcode"=>"368"},
  123 + {"name"=>"Ireland", "iso3"=>"IRL", "iso"=>"IE", "iso_name"=>"IRELAND", "numcode"=>"372"},
  124 + {"name"=>"Israel", "iso3"=>"ISR", "iso"=>"IL", "iso_name"=>"ISRAEL", "numcode"=>"376"},
  125 + {"name"=>"Italy", "iso3"=>"ITA", "iso"=>"IT", "iso_name"=>"ITALY", "numcode"=>"380"},
  126 + {"name"=>"Jamaica", "iso3"=>"JAM", "iso"=>"JM", "iso_name"=>"JAMAICA", "numcode"=>"388"},
  127 + {"name"=>"Japan", "iso3"=>"JPN", "iso"=>"JP", "iso_name"=>"JAPAN", "numcode"=>"392"},
  128 + {"name"=>"Jordan", "iso3"=>"JOR", "iso"=>"JO", "iso_name"=>"JORDAN", "numcode"=>"400"},
  129 + {"name"=>"Kazakhstan", "iso3"=>"KAZ", "iso"=>"KZ", "iso_name"=>"KAZAKHSTAN", "numcode"=>"398"},
  130 + {"name"=>"Kenya", "iso3"=>"KEN", "iso"=>"KE", "iso_name"=>"KENYA", "numcode"=>"404"},
  131 + {"name"=>"Kiribati", "iso3"=>"KIR", "iso"=>"KI", "iso_name"=>"KIRIBATI", "numcode"=>"296"},
  132 + {"name"=>"Kuwait", "iso3"=>"KWT", "iso"=>"KW", "iso_name"=>"KUWAIT", "numcode"=>"414"},
  133 + {"name"=>"Kyrgyzstan", "iso3"=>"KGZ", "iso"=>"KG", "iso_name"=>"KYRGYZSTAN", "numcode"=>"417"},
  134 + {"name"=>"Lao People's Democratic Republic", "iso3"=>"LAO", "iso"=>"LA", "iso_name"=>"LAO PEOPLE'S DEMOCRATIC REPUBLIC", "numcode"=>"418"},
  135 + {"name"=>"Latvia", "iso3"=>"LVA", "iso"=>"LV", "iso_name"=>"LATVIA", "numcode"=>"428"},
  136 + {"name"=>"Lebanon", "iso3"=>"LBN", "iso"=>"LB", "iso_name"=>"LEBANON", "numcode"=>"422"},
  137 + {"name"=>"Lesotho", "iso3"=>"LSO", "iso"=>"LS", "iso_name"=>"LESOTHO", "numcode"=>"426"},
  138 + {"name"=>"Liberia", "iso3"=>"LBR", "iso"=>"LR", "iso_name"=>"LIBERIA", "numcode"=>"430"},
  139 + {"name"=>"Libyan Arab Jamahiriya", "iso3"=>"LBY", "iso"=>"LY", "iso_name"=>"LIBYAN ARAB JAMAHIRIYA", "numcode"=>"434"},
  140 + {"name"=>"Liechtenstein", "iso3"=>"LIE", "iso"=>"LI", "iso_name"=>"LIECHTENSTEIN", "numcode"=>"438"},
  141 + {"name"=>"Lithuania", "iso3"=>"LTU", "iso"=>"LT", "iso_name"=>"LITHUANIA", "numcode"=>"440"},
  142 + {"name"=>"Luxembourg", "iso3"=>"LUX", "iso"=>"LU", "iso_name"=>"LUXEMBOURG", "numcode"=>"442"},
  143 + {"name"=>"Macao", "iso3"=>"MAC", "iso"=>"MO", "iso_name"=>"MACAO", "numcode"=>"446"},
  144 + {"name"=>"Macedonia", "iso3"=>"MKD", "iso"=>"MK", "iso_name"=>"MACEDONIA, THE FORMER YUGOSLAV REPUBLIC OF", "numcode"=>"807"},
  145 + {"name"=>"Madagascar", "iso3"=>"MDG", "iso"=>"MG", "iso_name"=>"MADAGASCAR", "numcode"=>"450"},
  146 + {"name"=>"Malawi", "iso3"=>"MWI", "iso"=>"MW", "iso_name"=>"MALAWI", "numcode"=>"454"},
  147 + {"name"=>"Malaysia", "iso3"=>"MYS", "iso"=>"MY", "iso_name"=>"MALAYSIA", "numcode"=>"458"},
  148 + {"name"=>"Maldives", "iso3"=>"MDV", "iso"=>"MV", "iso_name"=>"MALDIVES", "numcode"=>"462"},
  149 + {"name"=>"Mali", "iso3"=>"MLI", "iso"=>"ML", "iso_name"=>"MALI", "numcode"=>"466"},
  150 + {"name"=>"Malta", "iso3"=>"MLT", "iso"=>"MT", "iso_name"=>"MALTA", "numcode"=>"470"},
  151 + {"name"=>"Marshall Islands", "iso3"=>"MHL", "iso"=>"MH", "iso_name"=>"MARSHALL ISLANDS", "numcode"=>"584"},
  152 + {"name"=>"Martinique", "iso3"=>"MTQ", "iso"=>"MQ", "iso_name"=>"MARTINIQUE", "numcode"=>"474"},
  153 + {"name"=>"Mauritania", "iso3"=>"MRT", "iso"=>"MR", "iso_name"=>"MAURITANIA", "numcode"=>"478"},
  154 + {"name"=>"Mauritius", "iso3"=>"MUS", "iso"=>"MU", "iso_name"=>"MAURITIUS", "numcode"=>"480"},
  155 + {"name"=>"Mexico", "iso3"=>"MEX", "iso"=>"MX", "iso_name"=>"MEXICO", "numcode"=>"484"},
  156 + {"name"=>"Micronesia, Federated States of", "iso3"=>"FSM", "iso"=>"FM", "iso_name"=>"MICRONESIA, FEDERATED STATES OF", "numcode"=>"583"},
  157 + {"name"=>"Moldova, Republic of", "iso3"=>"MDA", "iso"=>"MD", "iso_name"=>"MOLDOVA, REPUBLIC OF", "numcode"=>"498"},
  158 + {"name"=>"Monaco", "iso3"=>"MCO", "iso"=>"MC", "iso_name"=>"MONACO", "numcode"=>"492"},
  159 + {"name"=>"Mongolia", "iso3"=>"MNG", "iso"=>"MN", "iso_name"=>"MONGOLIA", "numcode"=>"496"},
  160 + {"name"=>"Montserrat", "iso3"=>"MSR", "iso"=>"MS", "iso_name"=>"MONTSERRAT", "numcode"=>"500"},
  161 + {"name"=>"Morocco", "iso3"=>"MAR", "iso"=>"MA", "iso_name"=>"MOROCCO", "numcode"=>"504"},
  162 + {"name"=>"Mozambique", "iso3"=>"MOZ", "iso"=>"MZ", "iso_name"=>"MOZAMBIQUE", "numcode"=>"508"},
  163 + {"name"=>"Myanmar", "iso3"=>"MMR", "iso"=>"MM", "iso_name"=>"MYANMAR", "numcode"=>"104"},
  164 + {"name"=>"Namibia", "iso3"=>"NAM", "iso"=>"NA", "iso_name"=>"NAMIBIA", "numcode"=>"516"},
  165 + {"name"=>"Nauru", "iso3"=>"NRU", "iso"=>"NR", "iso_name"=>"NAURU", "numcode"=>"520"},
  166 + {"name"=>"Nepal", "iso3"=>"NPL", "iso"=>"NP", "iso_name"=>"NEPAL", "numcode"=>"524"},
  167 + {"name"=>"Netherlands Antilles", "iso3"=>"ANT", "iso"=>"AN", "iso_name"=>"NETHERLANDS ANTILLES", "numcode"=>"530"},
  168 + {"name"=>"Netherlands", "iso3"=>"NLD", "iso"=>"NL", "iso_name"=>"NETHERLANDS", "numcode"=>"528"},
  169 + {"name"=>"New Caledonia", "iso3"=>"NCL", "iso"=>"NC", "iso_name"=>"NEW CALEDONIA", "numcode"=>"540"},
  170 + {"name"=>"New Zealand", "iso3"=>"NZL", "iso"=>"NZ", "iso_name"=>"NEW ZEALAND", "numcode"=>"554"},
  171 + {"name"=>"Nicaragua", "iso3"=>"NIC", "iso"=>"NI", "iso_name"=>"NICARAGUA", "numcode"=>"558"},
  172 + {"name"=>"Niger", "iso3"=>"NER", "iso"=>"NE", "iso_name"=>"NIGER", "numcode"=>"562"},
  173 + {"name"=>"Nigeria", "iso3"=>"NGA", "iso"=>"NG", "iso_name"=>"NIGERIA", "numcode"=>"566"},
  174 + {"name"=>"Niue", "iso3"=>"NIU", "iso"=>"NU", "iso_name"=>"NIUE", "numcode"=>"570"},
  175 + {"name"=>"Norfolk Island", "iso3"=>"NFK", "iso"=>"NF", "iso_name"=>"NORFOLK ISLAND", "numcode"=>"574"},
  176 + {"name"=>"North Korea", "iso3"=>"PRK", "iso"=>"KP", "iso_name"=>"KOREA, DEMOCRATIC PEOPLE'S REPUBLIC OF", "numcode"=>"408"},
  177 + {"name"=>"Northern Mariana Islands", "iso3"=>"MNP", "iso"=>"MP", "iso_name"=>"NORTHERN MARIANA ISLANDS", "numcode"=>"580"},
  178 + {"name"=>"Norway", "iso3"=>"NOR", "iso"=>"NO", "iso_name"=>"NORWAY", "numcode"=>"578"},
  179 + {"name"=>"Oman", "iso3"=>"OMN", "iso"=>"OM", "iso_name"=>"OMAN", "numcode"=>"512"},
  180 + {"name"=>"Pakistan", "iso3"=>"PAK", "iso"=>"PK", "iso_name"=>"PAKISTAN", "numcode"=>"586"},
  181 + {"name"=>"Palau", "iso3"=>"PLW", "iso"=>"PW", "iso_name"=>"PALAU", "numcode"=>"585"},
  182 + {"name"=>"Panama", "iso3"=>"PAN", "iso"=>"PA", "iso_name"=>"PANAMA", "numcode"=>"591"},
  183 + {"name"=>"Papua New Guinea", "iso3"=>"PNG", "iso"=>"PG", "iso_name"=>"PAPUA NEW GUINEA", "numcode"=>"598"},
  184 + {"name"=>"Paraguay", "iso3"=>"PRY", "iso"=>"PY", "iso_name"=>"PARAGUAY", "numcode"=>"600"},
  185 + {"name"=>"Peru", "iso3"=>"PER", "iso"=>"PE", "iso_name"=>"PERU", "numcode"=>"604"},
  186 + {"name"=>"Philippines", "iso3"=>"PHL", "iso"=>"PH", "iso_name"=>"PHILIPPINES", "numcode"=>"608"},
  187 + {"name"=>"Pitcairn", "iso3"=>"PCN", "iso"=>"PN", "iso_name"=>"PITCAIRN", "numcode"=>"612"},
  188 + {"name"=>"Poland", "iso3"=>"POL", "iso"=>"PL", "iso_name"=>"POLAND", "numcode"=>"616"},
  189 + {"name"=>"Portugal", "iso3"=>"PRT", "iso"=>"PT", "iso_name"=>"PORTUGAL", "numcode"=>"620"},
  190 + {"name"=>"Puerto Rico", "iso3"=>"PRI", "iso"=>"PR", "iso_name"=>"PUERTO RICO", "numcode"=>"630"},
  191 + {"name"=>"Qatar", "iso3"=>"QAT", "iso"=>"QA", "iso_name"=>"QATAR", "numcode"=>"634"},
  192 + {"name"=>"Reunion", "iso3"=>"REU", "iso"=>"RE", "iso_name"=>"REUNION", "numcode"=>"638"},
  193 + {"name"=>"Romania", "iso3"=>"ROM", "iso"=>"RO", "iso_name"=>"ROMANIA", "numcode"=>"642"},
  194 + {"name"=>"Russian Federation", "iso3"=>"RUS", "iso"=>"RU", "iso_name"=>"RUSSIAN FEDERATION", "numcode"=>"643"},
  195 + {"name"=>"Rwanda", "iso3"=>"RWA", "iso"=>"RW", "iso_name"=>"RWANDA", "numcode"=>"646"},
  196 + {"name"=>"Saint Helena", "iso3"=>"SHN", "iso"=>"SH", "iso_name"=>"SAINT HELENA", "numcode"=>"654"},
  197 + {"name"=>"Saint Kitts and Nevis", "iso3"=>"KNA", "iso"=>"KN", "iso_name"=>"SAINT KITTS AND NEVIS", "numcode"=>"659"},
  198 + {"name"=>"Saint Lucia", "iso3"=>"LCA", "iso"=>"LC", "iso_name"=>"SAINT LUCIA", "numcode"=>"662"},
  199 + {"name"=>"Saint Pierre and Miquelon", "iso3"=>"SPM", "iso"=>"PM", "iso_name"=>"SAINT PIERRE AND MIQUELON", "numcode"=>"666"},
  200 + {"name"=>"Saint Vincent and the Grenadines", "iso3"=>"VCT", "iso"=>"VC", "iso_name"=>"SAINT VINCENT AND THE GRENADINES", "numcode"=>"670"},
  201 + {"name"=>"Samoa", "iso3"=>"WSM", "iso"=>"WS", "iso_name"=>"SAMOA", "numcode"=>"882"},
  202 + {"name"=>"San Marino", "iso3"=>"SMR", "iso"=>"SM", "iso_name"=>"SAN MARINO", "numcode"=>"674"},
  203 + {"name"=>"Sao Tome and Principe", "iso3"=>"STP", "iso"=>"ST", "iso_name"=>"SAO TOME AND PRINCIPE", "numcode"=>"678"},
  204 + {"name"=>"Saudi Arabia", "iso3"=>"SAU", "iso"=>"SA", "iso_name"=>"SAUDI ARABIA", "numcode"=>"682"},
  205 + {"name"=>"Senegal", "iso3"=>"SEN", "iso"=>"SN", "iso_name"=>"SENEGAL", "numcode"=>"686"},
  206 + {"name"=>"Serbia", "iso3"=>"SRB", "iso"=>"RS", "iso_name"=>"REPUBLIC OF SERBIA", "numcode"=>"688"},
  207 + {"name"=>"Seychelles", "iso3"=>"SYC", "iso"=>"SC", "iso_name"=>"SEYCHELLES", "numcode"=>"690"},
  208 + {"name"=>"Sierra Leone", "iso3"=>"SLE", "iso"=>"SL", "iso_name"=>"SIERRA LEONE", "numcode"=>"694"},
  209 + {"name"=>"Singapore", "iso3"=>"SGP", "iso"=>"SG", "iso_name"=>"SINGAPORE", "numcode"=>"702"},
  210 + {"name"=>"Slovakia", "iso3"=>"SVK", "iso"=>"SK", "iso_name"=>"SLOVAKIA", "numcode"=>"703"},
  211 + {"name"=>"Slovenia", "iso3"=>"SVN", "iso"=>"SI", "iso_name"=>"SLOVENIA", "numcode"=>"705"},
  212 + {"name"=>"Solomon Islands", "iso3"=>"SLB", "iso"=>"SB", "iso_name"=>"SOLOMON ISLANDS", "numcode"=>"90"},
  213 + {"name"=>"Somalia", "iso3"=>"SOM", "iso"=>"SO", "iso_name"=>"SOMALIA", "numcode"=>"706"},
  214 + {"name"=>"South Africa", "iso3"=>"ZAF", "iso"=>"ZA", "iso_name"=>"SOUTH AFRICA", "numcode"=>"710"},
  215 + {"name"=>"South Korea", "iso3"=>"KOR", "iso"=>"KR", "iso_name"=>"KOREA, REPUBLIC OF", "numcode"=>"410"},
  216 + {"name"=>"Spain", "iso3"=>"ESP", "iso"=>"ES", "iso_name"=>"SPAIN", "numcode"=>"724"},
  217 + {"name"=>"Sri Lanka", "iso3"=>"LKA", "iso"=>"LK", "iso_name"=>"SRI LANKA", "numcode"=>"144"},
  218 + {"name"=>"Sudan", "iso3"=>"SDN", "iso"=>"SD", "iso_name"=>"SUDAN", "numcode"=>"736"},
  219 + {"name"=>"Suriname", "iso3"=>"SUR", "iso"=>"SR", "iso_name"=>"SURINAME", "numcode"=>"740"},
  220 + {"name"=>"Svalbard and Jan Mayen", "iso3"=>"SJM", "iso"=>"SJ", "iso_name"=>"SVALBARD AND JAN MAYEN", "numcode"=>"744"},
  221 + {"name"=>"Swaziland", "iso3"=>"SWZ", "iso"=>"SZ", "iso_name"=>"SWAZILAND", "numcode"=>"748"},
  222 + {"name"=>"Sweden", "iso3"=>"SWE", "iso"=>"SE", "iso_name"=>"SWEDEN", "numcode"=>"752"},
  223 + {"name"=>"Switzerland", "iso3"=>"CHE", "iso"=>"CH", "iso_name"=>"SWITZERLAND", "numcode"=>"756"},
  224 + {"name"=>"Syrian Arab Republic", "iso3"=>"SYR", "iso"=>"SY", "iso_name"=>"SYRIAN ARAB REPUBLIC", "numcode"=>"760"},
  225 + {"name"=>"Taiwan", "iso3"=>"TWN", "iso"=>"TW", "iso_name"=>"TAIWAN, PROVINCE OF CHINA", "numcode"=>"158"},
  226 + {"name"=>"Tajikistan", "iso3"=>"TJK", "iso"=>"TJ", "iso_name"=>"TAJIKISTAN", "numcode"=>"762"},
  227 + {"name"=>"Tanzania, United Republic of", "iso3"=>"TZA", "iso"=>"TZ", "iso_name"=>"TANZANIA, UNITED REPUBLIC OF", "numcode"=>"834"},
  228 + {"name"=>"Thailand", "iso3"=>"THA", "iso"=>"TH", "iso_name"=>"THAILAND", "numcode"=>"764"},
  229 + {"name"=>"Togo", "iso3"=>"TGO", "iso"=>"TG", "iso_name"=>"TOGO", "numcode"=>"768"},
  230 + {"name"=>"Tokelau", "iso3"=>"TKL", "iso"=>"TK", "iso_name"=>"TOKELAU", "numcode"=>"772"},
  231 + {"name"=>"Tonga", "iso3"=>"TON", "iso"=>"TO", "iso_name"=>"TONGA", "numcode"=>"776"},
  232 + {"name"=>"Trinidad and Tobago", "iso3"=>"TTO", "iso"=>"TT", "iso_name"=>"TRINIDAD AND TOBAGO", "numcode"=>"780"},
  233 + {"name"=>"Tunisia", "iso3"=>"TUN", "iso"=>"TN", "iso_name"=>"TUNISIA", "numcode"=>"788"},
  234 + {"name"=>"Turkey", "iso3"=>"TUR", "iso"=>"TR", "iso_name"=>"TURKEY", "numcode"=>"792"},
  235 + {"name"=>"Turkmenistan", "iso3"=>"TKM", "iso"=>"TM", "iso_name"=>"TURKMENISTAN", "numcode"=>"795"},
  236 + {"name"=>"Turks and Caicos Islands", "iso3"=>"TCA", "iso"=>"TC", "iso_name"=>"TURKS AND CAICOS ISLANDS", "numcode"=>"796"},
  237 + {"name"=>"Tuvalu", "iso3"=>"TUV", "iso"=>"TV", "iso_name"=>"TUVALU", "numcode"=>"798"},
  238 + {"name"=>"Uganda", "iso3"=>"UGA", "iso"=>"UG", "iso_name"=>"UGANDA", "numcode"=>"800"},
  239 + {"name"=>"Ukraine", "iso3"=>"UKR", "iso"=>"UA", "iso_name"=>"UKRAINE", "numcode"=>"804"},
  240 + {"name"=>"United Arab Emirates", "iso3"=>"ARE", "iso"=>"AE", "iso_name"=>"UNITED ARAB EMIRATES", "numcode"=>"784"},
  241 + {"name"=>"United Kingdom", "iso3"=>"GBR", "iso"=>"GB", "iso_name"=>"UNITED KINGDOM", "numcode"=>"826"},
  242 + {"name"=>"United States", "iso3"=>"USA", "iso"=>"US", "iso_name"=>"UNITED STATES", "numcode"=>"840"},
  243 + {"name"=>"Uruguay", "iso3"=>"URY", "iso"=>"UY", "iso_name"=>"URUGUAY", "numcode"=>"858"},
  244 + {"name"=>"Uzbekistan", "iso3"=>"UZB", "iso"=>"UZ", "iso_name"=>"UZBEKISTAN", "numcode"=>"860"},
  245 + {"name"=>"Vanuatu", "iso3"=>"VUT", "iso"=>"VU", "iso_name"=>"VANUATU", "numcode"=>"548"},
  246 + {"name"=>"Venezuela", "iso3"=>"VEN", "iso"=>"VE", "iso_name"=>"VENEZUELA", "numcode"=>"862"},
  247 + {"name"=>"Viet Nam", "iso3"=>"VNM", "iso"=>"VN", "iso_name"=>"VIET NAM", "numcode"=>"704"},
  248 + {"name"=>"Virgin Islands, British", "iso3"=>"VGB", "iso"=>"VG", "iso_name"=>"VIRGIN ISLANDS, BRITISH", "numcode"=>"92"},
  249 + {"name"=>"Virgin Islands, U.S.", "iso3"=>"VIR", "iso"=>"VI", "iso_name"=>"VIRGIN ISLANDS, U.S.", "numcode"=>"850"},
  250 + {"name"=>"Wallis and Futuna", "iso3"=>"WLF", "iso"=>"WF", "iso_name"=>"WALLIS AND FUTUNA", "numcode"=>"876"},
  251 + {"name"=>"Western Sahara", "iso3"=>"ESH", "iso"=>"EH", "iso_name"=>"WESTERN SAHARA", "numcode"=>"732"},
  252 + {"name"=>"Yemen", "iso3"=>"YEM", "iso"=>"YE", "iso_name"=>"YEMEN", "numcode"=>"887"},
  253 + {"name"=>"Zambia", "iso3"=>"ZMB", "iso"=>"ZM", "iso_name"=>"ZAMBIA", "numcode"=>"894"},
  254 + {"name"=>"Zimbabwe", "iso3"=>"ZWE", "iso"=>"ZW", "iso_name"=>"ZIMBABWE", "numcode"=>"716"},
  255 + ]
  256 +
  257 + countries_data.each do |country_data|
  258 + Spree::Country.new(country_data.reject { |key| key == :id }, without_protection: true).tap do |c|
  259 + c.tenant_id = @tenant.id
  260 + c.save!
  261 + end
  262 + end
  263 + end
  264 +
  265 + def set_default_country_id
  266 + old_current_tenant_id = Spree::Tenant.current_tenant_id
  267 + Spree::Tenant.set_current_tenant(@tenant)
  268 + united_states = Spree::Country.where(iso: 'US').first
  269 + Spree::Config[:default_country_id] = united_states.id
  270 + Spree::Tenant.set_current_tenant(old_current_tenant_id)
  271 + end
  272 +
  273 + def seed_states
  274 + states_data = [
  275 + {"name"=>"Alabama", "country_iso"=>"US", "abbr"=>"AL"},
  276 + {"name"=>"Alaska", "country_iso"=>"US", "abbr"=>"AK"},
  277 + {"name"=>"Arizona", "country_iso"=>"US", "abbr"=>"AZ"},
  278 + {"name"=>"Arkansas", "country_iso"=>"US", "abbr"=>"AR"},
  279 + {"name"=>"California", "country_iso"=>"US", "abbr"=>"CA"},
  280 + {"name"=>"Colorado", "country_iso"=>"US", "abbr"=>"CO"},
  281 + {"name"=>"Connecticut", "country_iso"=>"US", "abbr"=>"CT"},
  282 + {"name"=>"Delaware", "country_iso"=>"US", "abbr"=>"DE"},
  283 + {"name"=>"District of Columbia", "country_iso"=>"US", "abbr"=>"DC"},
  284 + {"name"=>"Florida", "country_iso"=>"US", "abbr"=>"FL"},
  285 + {"name"=>"Georgia", "country_iso"=>"US", "abbr"=>"GA"},
  286 + {"name"=>"Hawaii", "country_iso"=>"US", "abbr"=>"HI"},
  287 + {"name"=>"Idaho", "country_iso"=>"US", "abbr"=>"ID"},
  288 + {"name"=>"Illinois", "country_iso"=>"US", "abbr"=>"IL"},
  289 + {"name"=>"Indiana", "country_iso"=>"US", "abbr"=>"IN"},
  290 + {"name"=>"Iowa", "country_iso"=>"US", "abbr"=>"IA"},
  291 + {"name"=>"Kansas", "country_iso"=>"US", "abbr"=>"KS"},
  292 + {"name"=>"Kentucky", "country_iso"=>"US", "abbr"=>"KY"},
  293 + {"name"=>"Louisiana", "country_iso"=>"US", "abbr"=>"LA"},
  294 + {"name"=>"Maine", "country_iso"=>"US", "abbr"=>"ME"},
  295 + {"name"=>"Maryland", "country_iso"=>"US", "abbr"=>"MD"},
  296 + {"name"=>"Massachusetts", "country_iso"=>"US", "abbr"=>"MA"},
  297 + {"name"=>"Michigan", "country_iso"=>"US", "abbr"=>"MI"},
  298 + {"name"=>"Minnesota", "country_iso"=>"US", "abbr"=>"MN"},
  299 + {"name"=>"Mississippi", "country_iso"=>"US", "abbr"=>"MS"},
  300 + {"name"=>"Missouri", "country_iso"=>"US", "abbr"=>"MO"},
  301 + {"name"=>"Montana", "country_iso"=>"US", "abbr"=>"MT"},
  302 + {"name"=>"Nebraska", "country_iso"=>"US", "abbr"=>"NE"},
  303 + {"name"=>"Nevada", "country_iso"=>"US", "abbr"=>"NV"},
  304 + {"name"=>"New Hampshire", "country_iso"=>"US", "abbr"=>"NH"},
  305 + {"name"=>"New Jersey", "country_iso"=>"US", "abbr"=>"NJ"},
  306 + {"name"=>"New Mexico", "country_iso"=>"US", "abbr"=>"NM"},
  307 + {"name"=>"New York", "country_iso"=>"US", "abbr"=>"NY"},
  308 + {"name"=>"North Carolina", "country_iso"=>"US", "abbr"=>"NC"},
  309 + {"name"=>"North Dakota", "country_iso"=>"US", "abbr"=>"ND"},
  310 + {"name"=>"Ohio", "country_iso"=>"US", "abbr"=>"OH"},
  311 + {"name"=>"Oklahoma", "country_iso"=>"US", "abbr"=>"OK"},
  312 + {"name"=>"Oregon", "country_iso"=>"US", "abbr"=>"OR"},
  313 + {"name"=>"Pennsylvania", "country_iso"=>"US", "abbr"=>"PA"},
  314 + {"name"=>"Rhode Island", "country_iso"=>"US", "abbr"=>"RI"},
  315 + {"name"=>"South Carolina", "country_iso"=>"US", "abbr"=>"SC"},
  316 + {"name"=>"South Dakota", "country_iso"=>"US", "abbr"=>"SD"},
  317 + {"name"=>"Tennessee", "country_iso"=>"US", "abbr"=>"TN"},
  318 + {"name"=>"Texas", "country_iso"=>"US", "abbr"=>"TX"},
  319 + {"name"=>"Utah", "country_iso"=>"US", "abbr"=>"UT"},
  320 + {"name"=>"Vermont", "country_iso"=>"US", "abbr"=>"VT"},
  321 + {"name"=>"Virginia", "country_iso"=>"US", "abbr"=>"VA"},
  322 + {"name"=>"Washington", "country_iso"=>"US", "abbr"=>"WA"},
  323 + {"name"=>"West Virginia", "country_iso"=>"US", "abbr"=>"WV"},
  324 + {"name"=>"Wisconsin", "country_iso"=>"US", "abbr"=>"WI"},
  325 + {"name"=>"Wyoming", "country_iso"=>"US", "abbr"=>"WY"},
  326 + ]
  327 +
  328 + states_data.each do |state_data|
  329 + country_iso = state_data.delete('country_iso')
  330 + Spree::State.new(state_data, without_protection: true).tap do |s|
  331 + s.country = Spree::Country.unscoped.where(iso: country_iso, tenant_id: @tenant.id).first
  332 + s.tenant_id = @tenant.id
  333 + s.save!
  334 + end
  335 + end
  336 + end
  337 +
  338 + def seed_zones
  339 + zones_data = [
  340 + {"name"=>"EU_VAT", "created_at"=>"2009-06-04 13:22:26 -0400", "updated_at"=>"2009-06-04 13:22:26 -0400", "description"=>"Countries that make up the EU VAT zone."},
  341 + {"name"=>"North America", "created_at"=>"2009-06-04 13:22:41 -0400", "updated_at"=>"2009-06-04 13:22:41 -0400", "description"=>"USA + Canada"},
  342 + ]
  343 +
  344 + zones_data.each do |zone_data|
  345 + Spree::Zone.new(zone_data, without_protection: true).tap do |z|
  346 + z.tenant_id = @tenant.id
  347 + z.save!
  348 + end
  349 + end
  350 + end
  351 +
  352 + def seed_zone_members
  353 + zone_members_data = [
  354 + {"zoneable_id"=>Spree::Country.unscoped.where(iso3: 'POL', tenant_id: @tenant.id).first.id, "created_at"=>"2009-06-04 09:22:26 -0400", "updated_at"=>"2009-06-04 09:22:26 -0400", "zone_id"=>Spree::Zone.unscoped.where(name: 'EU_VAT', tenant_id: @tenant.id).first.id, "zoneable_type"=>"Spree::Country"},
  355 + {"zoneable_id"=>Spree::Country.unscoped.where(iso3: 'FIN', tenant_id: @tenant.id).first.id, "created_at"=>"2009-06-04 09:22:26 -0400", "updated_at"=>"2009-06-04 09:22:26 -0400", "zone_id"=>Spree::Zone.unscoped.where(name: 'EU_VAT', tenant_id: @tenant.id).first.id, "zoneable_type"=>"Spree::Country"},
  356 + {"zoneable_id"=>Spree::Country.unscoped.where(iso3: 'PRT', tenant_id: @tenant.id).first.id, "created_at"=>"2009-06-04 09:22:26 -0400", "updated_at"=>"2009-06-04 09:22:26 -0400", "zone_id"=>Spree::Zone.unscoped.where(name: 'EU_VAT', tenant_id: @tenant.id).first.id, "zoneable_type"=>"Spree::Country"},
  357 + {"zoneable_id"=>Spree::Country.unscoped.where(iso3: 'ROM', tenant_id: @tenant.id).first.id, "created_at"=>"2009-06-04 09:22:26 -0400", "updated_at"=>"2009-06-04 09:22:26 -0400", "zone_id"=>Spree::Zone.unscoped.where(name: 'EU_VAT', tenant_id: @tenant.id).first.id, "zoneable_type"=>"Spree::Country"},
  358 + {"zoneable_id"=>Spree::Country.unscoped.where(iso3: 'DEU', tenant_id: @tenant.id).first.id, "created_at"=>"2009-06-04 09:22:26 -0400", "updated_at"=>"2009-06-04 09:22:26 -0400", "zone_id"=>Spree::Zone.unscoped.where(name: 'EU_VAT', tenant_id: @tenant.id).first.id, "zoneable_type"=>"Spree::Country"},
  359 + {"zoneable_id"=>Spree::Country.unscoped.where(iso3: 'FRA', tenant_id: @tenant.id).first.id, "created_at"=>"2009-06-04 09:22:26 -0400", "updated_at"=>"2009-06-04 09:22:26 -0400", "zone_id"=>Spree::Zone.unscoped.where(name: 'EU_VAT', tenant_id: @tenant.id).first.id, "zoneable_type"=>"Spree::Country"},
  360 + {"zoneable_id"=>Spree::Country.unscoped.where(iso3: 'SVK', tenant_id: @tenant.id).first.id, "created_at"=>"2009-06-04 09:22:26 -0400", "updated_at"=>"2009-06-04 09:22:26 -0400", "zone_id"=>Spree::Zone.unscoped.where(name: 'EU_VAT', tenant_id: @tenant.id).first.id, "zoneable_type"=>"Spree::Country"},
  361 + {"zoneable_id"=>Spree::Country.unscoped.where(iso3: 'HUN', tenant_id: @tenant.id).first.id, "created_at"=>"2009-06-04 09:22:26 -0400", "updated_at"=>"2009-06-04 09:22:26 -0400", "zone_id"=>Spree::Zone.unscoped.where(name: 'EU_VAT', tenant_id: @tenant.id).first.id, "zoneable_type"=>"Spree::Country"},
  362 + {"zoneable_id"=>Spree::Country.unscoped.where(iso3: 'SVN', tenant_id: @tenant.id).first.id, "created_at"=>"2009-06-04 09:22:26 -0400", "updated_at"=>"2009-06-04 09:22:26 -0400", "zone_id"=>Spree::Zone.unscoped.where(name: 'EU_VAT', tenant_id: @tenant.id).first.id, "zoneable_type"=>"Spree::Country"},
  363 + {"zoneable_id"=>Spree::Country.unscoped.where(iso3: 'IRL', tenant_id: @tenant.id).first.id, "created_at"=>"2009-06-04 09:22:26 -0400", "updated_at"=>"2009-06-04 09:22:26 -0400", "zone_id"=>Spree::Zone.unscoped.where(name: 'EU_VAT', tenant_id: @tenant.id).first.id, "zoneable_type"=>"Spree::Country"},
  364 + {"zoneable_id"=>Spree::Country.unscoped.where(iso3: 'AUT', tenant_id: @tenant.id).first.id, "created_at"=>"2009-06-04 09:22:26 -0400", "updated_at"=>"2009-06-04 09:22:26 -0400", "zone_id"=>Spree::Zone.unscoped.where(name: 'EU_VAT', tenant_id: @tenant.id).first.id, "zoneable_type"=>"Spree::Country"},
  365 + {"zoneable_id"=>Spree::Country.unscoped.where(iso3: 'ESP', tenant_id: @tenant.id).first.id, "created_at"=>"2009-06-04 09:22:26 -0400", "updated_at"=>"2009-06-04 09:22:26 -0400", "zone_id"=>Spree::Zone.unscoped.where(name: 'EU_VAT', tenant_id: @tenant.id).first.id, "zoneable_type"=>"Spree::Country"},
  366 + {"zoneable_id"=>Spree::Country.unscoped.where(iso3: 'ITA', tenant_id: @tenant.id).first.id, "created_at"=>"2009-06-04 09:22:26 -0400", "updated_at"=>"2009-06-04 09:22:26 -0400", "zone_id"=>Spree::Zone.unscoped.where(name: 'EU_VAT', tenant_id: @tenant.id).first.id, "zoneable_type"=>"Spree::Country"},
  367 + {"zoneable_id"=>Spree::Country.unscoped.where(iso3: 'BEL', tenant_id: @tenant.id).first.id, "created_at"=>"2009-06-04 09:22:26 -0400", "updated_at"=>"2009-06-04 09:22:26 -0400", "zone_id"=>Spree::Zone.unscoped.where(name: 'EU_VAT', tenant_id: @tenant.id).first.id, "zoneable_type"=>"Spree::Country"},
  368 + {"zoneable_id"=>Spree::Country.unscoped.where(iso3: 'SWE', tenant_id: @tenant.id).first.id, "created_at"=>"2009-06-04 09:22:26 -0400", "updated_at"=>"2009-06-04 09:22:26 -0400", "zone_id"=>Spree::Zone.unscoped.where(name: 'EU_VAT', tenant_id: @tenant.id).first.id, "zoneable_type"=>"Spree::Country"},
  369 + {"zoneable_id"=>Spree::Country.unscoped.where(iso3: 'LVA', tenant_id: @tenant.id).first.id, "created_at"=>"2009-06-04 09:22:26 -0400", "updated_at"=>"2009-06-04 09:22:26 -0400", "zone_id"=>Spree::Zone.unscoped.where(name: 'EU_VAT', tenant_id: @tenant.id).first.id, "zoneable_type"=>"Spree::Country"},
  370 + {"zoneable_id"=>Spree::Country.unscoped.where(iso3: 'BGR', tenant_id: @tenant.id).first.id, "created_at"=>"2009-06-04 09:22:26 -0400", "updated_at"=>"2009-06-04 09:22:26 -0400", "zone_id"=>Spree::Zone.unscoped.where(name: 'EU_VAT', tenant_id: @tenant.id).first.id, "zoneable_type"=>"Spree::Country"},
  371 + {"zoneable_id"=>Spree::Country.unscoped.where(iso3: 'GBR', tenant_id: @tenant.id).first.id, "created_at"=>"2009-06-04 09:22:26 -0400", "updated_at"=>"2009-06-04 09:22:26 -0400", "zone_id"=>Spree::Zone.unscoped.where(name: 'EU_VAT', tenant_id: @tenant.id).first.id, "zoneable_type"=>"Spree::Country"},
  372 + {"zoneable_id"=>Spree::Country.unscoped.where(iso3: 'LTU', tenant_id: @tenant.id).first.id, "created_at"=>"2009-06-04 09:22:26 -0400", "updated_at"=>"2009-06-04 09:22:26 -0400", "zone_id"=>Spree::Zone.unscoped.where(name: 'EU_VAT', tenant_id: @tenant.id).first.id, "zoneable_type"=>"Spree::Country"},
  373 + {"zoneable_id"=>Spree::Country.unscoped.where(iso3: 'CYP', tenant_id: @tenant.id).first.id, "created_at"=>"2009-06-04 09:22:26 -0400", "updated_at"=>"2009-06-04 09:22:26 -0400", "zone_id"=>Spree::Zone.unscoped.where(name: 'EU_VAT', tenant_id: @tenant.id).first.id, "zoneable_type"=>"Spree::Country"},
  374 + {"zoneable_id"=>Spree::Country.unscoped.where(iso3: 'LUX', tenant_id: @tenant.id).first.id, "created_at"=>"2009-06-04 09:22:26 -0400", "updated_at"=>"2009-06-04 09:22:26 -0400", "zone_id"=>Spree::Zone.unscoped.where(name: 'EU_VAT', tenant_id: @tenant.id).first.id, "zoneable_type"=>"Spree::Country"},
  375 + {"zoneable_id"=>Spree::Country.unscoped.where(iso3: 'CZE', tenant_id: @tenant.id).first.id, "created_at"=>"2009-06-04 09:22:26 -0400", "updated_at"=>"2009-06-04 09:22:26 -0400", "zone_id"=>Spree::Zone.unscoped.where(name: 'EU_VAT', tenant_id: @tenant.id).first.id, "zoneable_type"=>"Spree::Country"},
  376 + {"zoneable_id"=>Spree::Country.unscoped.where(iso3: 'USA', tenant_id: @tenant.id).first.id, "created_at"=>"2009-06-04 13:22:41 -0400", "updated_at"=>"2009-06-04 13:22:41 -0400", "zone_id"=>Spree::Zone.unscoped.where(name: 'North America', tenant_id: @tenant.id).first.id, "zoneable_type"=>"Spree::Country"},
  377 + {"zoneable_id"=>Spree::Country.unscoped.where(iso3: 'MLT', tenant_id: @tenant.id).first.id, "created_at"=>"2009-06-04 09:22:26 -0400", "updated_at"=>"2009-06-04 09:22:26 -0400", "zone_id"=>Spree::Zone.unscoped.where(name: 'EU_VAT', tenant_id: @tenant.id).first.id, "zoneable_type"=>"Spree::Country"},
  378 + {"zoneable_id"=>Spree::Country.unscoped.where(iso3: 'DNK', tenant_id: @tenant.id).first.id, "created_at"=>"2009-06-04 09:22:26 -0400", "updated_at"=>"2009-06-04 09:22:26 -0400", "zone_id"=>Spree::Zone.unscoped.where(name: 'EU_VAT', tenant_id: @tenant.id).first.id, "zoneable_type"=>"Spree::Country"},
  379 + {"zoneable_id"=>Spree::Country.unscoped.where(iso3: 'CAN', tenant_id: @tenant.id).first.id, "created_at"=>"2009-06-04 13:22:41 -0400", "updated_at"=>"2009-06-04 13:22:41 -0400", "zone_id"=>Spree::Zone.unscoped.where(name: 'North America', tenant_id: @tenant.id).first.id, "zoneable_type"=>"Spree::Country"},
  380 + {"zoneable_id"=>Spree::Country.unscoped.where(iso3: 'NLD', tenant_id: @tenant.id).first.id, "created_at"=>"2009-06-04 09:22:26 -0400", "updated_at"=>"2009-06-04 09:22:26 -0400", "zone_id"=>Spree::Zone.unscoped.where(name: 'EU_VAT', tenant_id: @tenant.id).first.id, "zoneable_type"=>"Spree::Country"},
  381 + {"zoneable_id"=>Spree::Country.unscoped.where(iso3: 'EST', tenant_id: @tenant.id).first.id, "created_at"=>"2009-06-04 09:22:26 -0400", "updated_at"=>"2009-06-04 09:22:26 -0400", "zone_id"=>Spree::Zone.unscoped.where(name: 'EU_VAT', tenant_id: @tenant.id).first.id, "zoneable_type"=>"Spree::Country"},
  382 + ]
  383 +
  384 + zone_members_data.each do |zone_member_data|
  385 + Spree::ZoneMember.new(zone_member_data, without_protection: true).tap do |zm|
  386 + zm.tenant_id = @tenant.id
  387 + zm.save!
  388 + end
  389 + end
  390 + end
  391 + end
  392 + end
  393 +end
9 lib/tasks/spree_landlord.rake
@@ -100,7 +100,14 @@ namespace :db do
100 100 Spree::SpreeLandlord::TenantMigrator.new.move_unassigned_to_master
101 101 end
102 102
103   - task :migrate => :reset_column_information
  103 + task :migrate => :reset_column_information do
  104 + # clear tables that are seeded by spree_core
  105 + Spree::Country.delete_all
  106 + Spree::State.delete_all
  107 + Spree::Zone.delete_all
  108 + Spree::Role.delete_all
  109 + Spree::ZoneMember.delete_all
  110 + end
104 111
105 112 task :reset_column_information do
106 113 ActiveRecord::Base.send(:subclasses).each do |model|
4 spec/api/full_domain_routing_spec.rb
... ... @@ -1,8 +1,8 @@
1 1 require 'spec_helper'
2 2
3 3 describe 'full domain routing' do
4   - let!(:apples_tenant) { FactoryGirl.create(:tenant, :shortname => 'apples', :domain => 'apples.com', name: "Apple") }
5   - let!(:oranges_tenant) { FactoryGirl.create(:tenant, :shortname => 'oranges', :domain => 'oranges.com', name: "Orange") }
  4 + let!(:apples_tenant) { Spree::Tenant.create!(:shortname => 'apples', :domain => 'apples.com', :name => 'Apple') }
  5 + let!(:oranges_tenant) { Spree::Tenant.create!(:shortname => 'oranges', :domain => 'oranges.com', :name => 'Orange') }
6 6
7 7 let!(:apple) {
8 8 Spree::Tenant.set_current_tenant(apples_tenant)
4 spec/api/preferences_spec.rb
... ... @@ -1,8 +1,8 @@
1 1 require 'spec_helper'
2 2
3 3 describe 'preferences' do
4   - let!(:apples_tenant) { FactoryGirl.create(:tenant, :shortname => 'apples', :domain => 'apples.com') }
5   - let!(:oranges_tenant) { FactoryGirl.create(:tenant, :shortname => 'oranges', :domain => 'oranges.com') }
  4 + let!(:apples_tenant) { Spree::Tenant.create!(:shortname => 'apples', :domain => 'apples.com') }
  5 + let!(:oranges_tenant) { Spree::Tenant.create!(:shortname => 'oranges', :domain => 'oranges.com') }
6 6
7 7 let!(:apples_tenant_site_name) {
8 8 Spree::Tenant.set_current_tenant(apples_tenant)
6 spec/api/subdomain_routing_spec.rb
@@ -2,9 +2,9 @@
2 2
3 3 describe 'subdomain routing' do
4 4 let!(:master_tenant) { Spree::Tenant.master }
5   - let!(:apples_tenant) { FactoryGirl.create(:tenant, :shortname => 'apples') }
6   - let!(:oranges_tenant) { FactoryGirl.create(:tenant, :shortname => 'oranges') }
7   - let!(:mixed_tenant) { FactoryGirl.create(:tenant, :shortname => 'Mixed') }
  5 + let!(:apples_tenant) { Spree::Tenant.create!(:shortname => 'apples', :domain => 'apples.dev') }
  6 + let!(:oranges_tenant) { Spree::Tenant.create!(:shortname => 'oranges', :domain => 'oranges.dev') }
  7 + let!(:mixed_tenant) { Spree::Tenant.create!(:shortname => 'Mixed', :domain => 'mixed.dev') }
8 8
9 9 let!(:apple) {
10 10 Spree::Tenant.set_current_tenant(apples_tenant)
4 spec/features/preferences_spec.rb
... ... @@ -1,8 +1,8 @@
1 1 require 'spec_helper'
2 2
3 3 describe 'preferences' do
4   - let!(:alpha_tenant) { FactoryGirl.create(:tenant, shortname: 'alpha') }
5   - let!(:beta_tenant) { FactoryGirl.create(:tenant, shortname: 'beta') }
  4 + let!(:alpha_tenant) { Spree::Tenant.create!(:shortname => 'alpha', :domain => 'alpha.dev') }
  5 + let!(:beta_tenant) { Spree::Tenant.create!(:shortname => 'beta', :domain => 'beta.dev') }
6 6
7 7 let!(:super_admin) {
8 8 Spree::User.create!(email: 'super@example.com', password: 'spree123')
15 spec/features/states_spec.rb
... ... @@ -0,0 +1,15 @@
  1 +require 'spec_helper'
  2 +
  3 +describe 'States' do
  4 + extend AuthorizationHelpers::Request
  5 + stub_authorization!
  6 +
  7 + let!(:alpha_tenant) { Spree::Tenant.create!(:shortname => 'alpha', :domain => 'alpha.dev') }
  8 +
  9 + it 'can view states without crashing' do
  10 + visit 'http://alpha.dev/admin'
  11 + click_link 'Configuration'
  12 + click_link 'States'
  13 + expect(page).to have_content('Alabama')
  14 + end
  15 +end
100 spec/features/tenant_checkout_spec.rb
... ... @@ -0,0 +1,100 @@
  1 +require 'spec_helper'
  2 +
  3 +describe 'Tenant checkout process' do
  4 + let!(:alpha_tenant) { Spree::Tenant.create!(shortname: 'alpha', domain: 'alpha.dev') }
  5 + let!(:beta_tenant) { Spree::Tenant.create!(shortname: 'beta', domain: 'beta.dev') }
  6 +
  7 + let!(:alpha_product) {
  8 + Spree::Tenant.set_current_tenant(alpha_tenant)
  9 + Spree::Product.create!(name: 'Alpha Product', price: 9.99, available_on: 1.day.ago)
  10 + }
  11 +
  12 + let!(:beta_product) {
  13 + Spree::Tenant.set_current_tenant(beta_tenant)
  14 + Spree::Product.create!(name: 'Beta Product', price: 12.25, available_on: 1.day.ago)
  15 + }
  16 +
  17 + let!(:alpha_shipping) {
  18 + Spree::Tenant.set_current_tenant(alpha_tenant)
  19 + Spree::ShippingMethod.create!(
  20 + name: 'Free Shipping',
  21 + zone: Spree::Zone.where(name: 'North America').first,
  22 + calculator_type: 'Spree::Calculator::FlatRate'
  23 + ).tap do |s|
  24 + s.calculator = Spree::Calculator::FlatRate.create!({calculable: s}, without_protection: true)
  25 + s.save!
  26 + end
  27 + }
  28 +
  29 + let!(:beta_shipping) {
  30 + Spree::Tenant.set_current_tenant(beta_tenant)
  31 + Spree::ShippingMethod.create!(
  32 + name: 'Free Shipping',
  33 + zone: Spree::Zone.where(name: 'North America').first,
  34 + calculator_type: 'Spree::Calculator::FlatRate'
  35 + ).tap do |s|
  36 + s.calculator = Spree::Calculator::FlatRate.create!({calculable: s}, without_protection: true)
  37 + s.save!
  38 + end
  39 + }
  40 +
  41 + let!(:alpha_payment_method) {
  42 + Spree::Tenant.set_current_tenant(alpha_tenant)
  43 + Spree::PaymentMethod::Check.create!(
  44 + name: 'Default',
  45 + environment: 'test',
  46 + active: true)
  47 + }
  48 +
  49 + let!(:beta_payment_method) {
  50 + Spree::Tenant.set_current_tenant(beta_tenant)
  51 + Spree::PaymentMethod::Check.create!(
  52 + name: 'Default',
  53 + environment: 'test',
  54 + active: true)
  55 + }
  56 +
  57 + it 'purchases a product from the alpha tenant' do
  58 + visit 'http://alpha.dev'
  59 + click_on 'Alpha Product'
  60 + click_on 'Add To Cart'
  61 + click_on 'Checkout'
  62 + fill_in 'order_email', with: 'naruto@uzamaki.jp'
  63 + click_on 'Continue'
  64 + fill_in 'First Name', with: 'Naruto'
  65 + fill_in 'Last Name', with: 'Uzamaki'
  66 + fill_in 'Street Address', with: '126 Ramen Way'
  67 + fill_in 'City', with: 'Konohama'
  68 + fill_in 'order_bill_address_attributes_state_name', with: 'Virginia'
  69 + select 'United States', from: 'Country'
  70 + fill_in 'Zip', with: '23229'
  71 + fill_in 'Phone', with: '8885551212'
  72 + check 'Use Billing Address'
  73 + click_on 'Save and Continue'
  74 + click_on 'Save and Continue'
  75 + click_on 'Save and Continue'
  76 + expect(page).to have_content('Your order has been processed successfully')
  77 + end
  78 +
  79 + it 'purchases a product from the beta tenant' do
  80 + visit 'http://beta.dev'
  81 + click_on 'Beta Product'
  82 + click_on 'Add To Cart'
  83 + click_on 'Checkout'
  84 + fill_in 'order_email', with: 'naruto@uzamaki.jp'
  85 + click_on 'Continue'
  86 + fill_in 'First Name', with: 'Naruto'
  87 + fill_in 'Last Name', with: 'Uzamaki'
  88 + fill_in 'Street Address', with: '126 Ramen Way'
  89 + fill_in 'City', with: 'Konohama'
  90 + fill_in 'order_bill_address_attributes_state_name', with: 'Virginia'
  91 + select 'United States', from: 'Country'
  92 + fill_in 'Zip', with: '23229'
  93 + fill_in 'Phone', with: '8885551212'
  94 + check 'Use Billing Address'
  95 + click_on 'Save and Continue'
  96 + click_on 'Save and Continue'
  97 + click_on 'Save and Continue'
  98 + expect(page).to have_content('Your order has been processed successfully')
  99 + end
  100 +end
27 spec/features/zones_spec.rb
... ... @@ -0,0 +1,27 @@
  1 +require 'spec_helper'
  2 +
  3 +describe 'Zones' do
  4 + extend AuthorizationHelpers::Request
  5 + stub_authorization!
  6 +
  7 + let!(:alpha_tenant) { Spree::Tenant.create!(:shortname => 'alpha', :domain => 'alpha.dev') }
  8 + let!(:beta_tenant) { Spree::Tenant.create!(:shortname => 'beta', :domain => 'beta.dev') }
  9 +
  10 + it 'permits creating two zones with the same name on different tenants' do
  11 + visit 'http://alpha.dev/admin'
  12 + click_link 'Configuration'
  13 + click_link 'Zones'
  14 + click_link 'New Zone'
  15 + fill_in 'Name', with: 'Test'
  16 + click_button 'Create'
  17 + expect(page).to have_content('Zone "Test" has been successfully created')
  18 +
  19 + visit 'http://beta.dev/admin'
  20 + click_link 'Configuration'
  21 + click_link 'Zones'
  22 + click_link 'New Zone'
  23 + fill_in 'Name', with: 'Test'
  24 + click_button 'Create'
  25 + expect(page).to have_content('Zone "Test" has been successfully created')
  26 + end
  27 +end
6 spec/lib/spree/spree_landlord/tenant_finder_spec.rb
@@ -5,9 +5,9 @@
5 5 describe '#find_target_tenant' do
6 6 subject(:finder) { Spree::SpreeLandlord::TenantFinder.new }
7 7 before { Spree::Tenant.destroy_all }
8   - let!(:master) { FactoryGirl.create(:tenant, :shortname => 'master', :domain => 'master.com') }
9   - let!(:apples) { FactoryGirl.create(:tenant, :shortname => 'apples', :domain => 'apples.com') }
10   - let!(:oranges) { FactoryGirl.create(:tenant, :shortname => 'oranges', :domain => 'oranges.com') }
  8 + let!(:master) { Spree::Tenant.create!(:shortname => 'master', :domain => 'master.com') }
  9 + let!(:apples) { Spree::Tenant.create!(:shortname => 'apples', :domain => 'apples.com') }
  10 + let!(:oranges) { Spree::Tenant.create!(:shortname => 'oranges', :domain => 'oranges.com') }
11 11
12 12 def request(uri)
13 13 env = Rack::MockRequest.env_for(uri)
165 spec/lib/spree/spree_landlord/tenant_seeder_spec.rb
... ... @@ -0,0 +1,165 @@
  1 +require 'spec_helper'
  2 +
  3 +describe Spree::SpreeLandlord::TenantSeeder do
  4 + let(:spree_default_seeds_dir) {
  5 + File.join(Gem.loaded_specs['spree_core'].full_gem_path, 'db', 'default')
  6 + }
  7 +
  8 + def load_seed_data(seed_file)
  9 + YAML.load_file(File.join(spree_default_seeds_dir, seed_file))
  10 + end
  11 +
  12 + let(:roles_seed_data) {
  13 + load_seed_data('spree/roles.yml')
  14 + }
  15 +
  16 + let(:countries_seed_data) {
  17 + load_seed_data('spree/countries.yml')
  18 + }
  19 +
  20 + let(:states_seed_data) {
  21 + load_seed_data('spree/states.yml')
  22 + }
  23 +
  24 + let(:zones_seed_data) {
  25 + load_seed_data('spree/zones.yml')
  26 + }
  27 +
  28 + let(:zone_members_seed_data) {
  29 + load_seed_data('spree/zone_members.yml')
  30 + }
  31 +
  32 + let!(:tenant) {
  33 + Spree::Tenant.new.tap do |t|
  34 + t.stub(:seed_tenant)
  35 + t.shortname = 'test'
  36 + t.domain = 'test.dev'
  37 + t.save!
  38 + end
  39 + }
  40 +
  41 + let(:seeder) {
  42 + Spree::SpreeLandlord::TenantSeeder.new(tenant)
  43 + }
  44 +
  45 + before do
  46 + Spree::Tenant.set_current_tenant(tenant)
  47 + end
  48 +
  49 + describe '#seed' do
  50 + before do
  51 + seeder.seed
  52 + end
  53 +
  54 + it 'generates all roles in spree core' do
  55 + roles_seed_data.each do |key, values|
  56 + expect(Spree::Role.where(:name => values['name']).count).to be == 1
  57 + end
  58 + end
  59 +
  60 + it 'generates all countries in spree_core' do
  61 + countries_seed_data.each do |key, values|
  62 + country_query = Spree::Country.where(:name => values['name'])
  63 +
  64 + expect(country_query.count).to be == 1
  65 +
  66 + country = country_query.first
  67 + expect(country.iso3).to eq(values['iso3'])
  68 + expect(country.iso).to eq(values['iso'])
  69 +
  70 + # the seed data in spree_core is incomplete for Serbia
  71 + # the values here are sourced from http://www.unc.edu/~rowlett/units/codes/country.htm
  72 + unless country.name == 'Serbia'
  73 + expect(country.iso_name).to eq(values['iso_name'])
  74 + expect(country.numcode).to eq(values['numcode'].to_i)
  75 + else
  76 + expect(country.iso_name).to eq('REPUBLIC OF SERBIA')
  77 + expect(country.numcode).to eq(688)
  78 + end
  79 + end
  80 + end
  81 +
  82 + it 'sets default_country_id preference to a tenanted country' do
  83 + Spree::Tenant.set_current_tenant(tenant)
  84 + united_states = Spree::Country.where(iso: 'US').first
  85 + expect(Spree::Config[:default_country_id]).to eq(united_states.id)
  86 + end
  87 +
  88 + it 'generates all states in spree_core' do
  89 + united_states = Spree::Country.where(:iso => 'US').first
  90 +
  91 + states_seed_data.each do |key, values|
  92 + state_query = Spree::State.where(:name => values['name'])
  93 + expect(state_query.count).to be == 1
  94 +
  95 + state = state_query.first
  96 + expect(state.country).to eq(united_states)
  97 + expect(state.abbr).to eq(values['abbr'])
  98 + end
  99 + end
  100 +
  101 + it 'generates all zones in spree_core' do
  102 + zones_seed_data.each do |key, values|
  103 + zone_query = Spree::Zone.where(:name => values['name'])
  104 +
  105 + expect(zone_query.count).to be == 1
  106 +
  107 + zone = zone_query.first
  108 + expect(zone.created_at).to eq(values['created_at'])
  109 + expect(zone.updated_at).to eq(values['updated_at'])
  110 + expect(zone.description).to eq(values['description'])
  111 + end
  112 + end
  113 +
  114 + it 'generates all zone members in spree_core' do
  115 + zones_ids_map = {
  116 + 1 => Spree::Zone.where(name: 'EU_VAT').first.id,
  117 + 2 => Spree::Zone.where(name: 'North America').first.id
  118 + }
  119 +
  120 + zoneables_ids_map = {
  121 + 13 => Spree::Country.where(iso3: 'AUT').first.id,
  122 + 20 => Spree::Country.where(iso3: 'BEL').first.id,
  123 + 30 => Spree::Country.where(iso3: 'BGR').first.id,
  124 + 35 => Spree::Country.where(iso3: 'CAN').first.id,
  125 + 51 => Spree::Country.where(iso3: 'CYP').first.id,
  126 + 52 => Spree::Country.where(iso3: 'CZE').first.id,
  127 + 53 => Spree::Country.where(iso3: 'DNK').first.id,
  128 + 62 => Spree::Country.where(iso3: 'EST').first.id,
  129 + 67 => Spree::Country.where(iso3: 'FIN').first.id,
  130 + 68 => Spree::Country.where(iso3: 'FRA').first.id,
  131 + 74 => Spree::Country.where(iso3: 'DEU').first.id,
  132 + 90 => Spree::Country.where(iso3: 'HUN').first.id,
  133 + 96 => Spree::Country.where(iso3: 'IRL').first.id,
  134 + 98 => Spree::Country.where(iso3: 'ITA').first.id,
  135 + 110 => Spree::Country.where(iso3: 'LVA').first.id,
  136 + 116 => Spree::Country.where(iso3: 'LTU').first.id,
  137 + 117 => Spree::Country.where(iso3: 'LUX').first.id,
  138 + 125 => Spree::Country.where(iso3: 'MLT').first.id,
  139 + 142 => Spree::Country.where(iso3: 'NLD').first.id,
  140 + 162 => Spree::Country.where(iso3: 'POL').first.id,
  141 + 163 => Spree::Country.where(iso3: 'PRT').first.id,
  142 + 167 => Spree::Country.where(iso3: 'ROM').first.id,
  143 + 183 => Spree::Country.where(iso3: 'SVK').first.id,
  144 + 184 => Spree::Country.where(iso3: 'SVN').first.id,
  145 + 188 => Spree::Country.where(iso3: 'ESP').first.id,
  146 + 194 => Spree::Country.where(iso3: 'SWE').first.id,
  147 + 213 => Spree::Country.where(iso3: 'GBR').first.id,
  148 + 214 => Spree::Country.where(iso3: 'USA').first.id,
  149 + }
  150 +
  151 + zone_members_seed_data.each do |key, values|
  152 + zone_member_query = Spree::ZoneMember.where(
  153 + zone_id: zones_ids_map[values['zone_id'].to_i],
  154 + zoneable_id: zoneables_ids_map[values['zoneable_id'].to_i])
  155 +
  156 + expect(zone_member_query.count).to be == 1
  157 +
  158 + zone = zone_member_query.first
  159 + expect(zone.created_at).to eq(values['created_at'])
  160 + expect(zone.updated_at).to eq(values['updated_at'])
  161 + expect(zone.zoneable_type).to eq(values['zoneable_type'])
  162 + end
  163 + end
  164 + end
  165 +end
2  spec/models/spree/multi_tenant_spec.rb
@@ -18,7 +18,7 @@
18 18
19 19 context 'with new instances' do
20 20 context 'when the current tenant is explicitly set' do
21   - let(:tenant) { FactoryGirl.create(:tenant) }
  21 + let(:tenant) { Spree::Tenant.create!(shortname: 'test', domain: 'test.dev') }
22 22
23 23 before do
24 24 Spree::Tenant.set_current_tenant(tenant)
4 spec/models/spree/preference_spec.rb
... ... @@ -1,8 +1,8 @@
1 1 require 'spec_helper'
2 2
3 3 describe Spree::Preference do
4   - let(:alpha_tenant) { FactoryGirl.create(:tenant, :shortname => 'alpha') }
5   - let(:beta_tenant) { FactoryGirl.create(:tenant, :shortname => 'beta') }
  4 + let(:alpha_tenant) { Spree::Tenant.create!(:shortname => 'alpha', :domain => 'alpha.dev') }
  5 + let(:beta_tenant) { Spree::Tenant.create!(:shortname => 'beta', :domain => 'beta.dev') }
6 6
7 7 it 'permits saving the same key for two different tenants' do
8 8 Spree::Preference.create!(:key => 'test', :tenant => alpha_tenant, :value_type => :string, :value => 'alpha test')
48 spec/models/spree/tenant_spec.rb
@@ -63,8 +63,8 @@ def assert_requires_attribute(attribute_name)
63 63
64 64 context 'when there are tenants' do
65 65 it 'treats the first tenant as the master' do
66   - first_tenant = FactoryGirl.create(:tenant)
67   - second_tenant = FactoryGirl.create(:tenant)
  66 + first_tenant = Spree::Tenant.create!(shortname: 'first', domain: 'first.dev')
  67 + second_tenant = Spree::Tenant.create!(shortname: 'second', domain: 'second.dev')
68 68
69 69 Spree::Tenant.master.should == first_tenant
70 70 end
@@ -93,7 +93,8 @@ def assert_requires_attribute(attribute_name)
93 93
94 94 context 'when current thread has no tenant id' do
95 95 it 'returns the master tenant id' do
96   - tenant = FactoryGirl.create(:tenant)
  96 + tenant = Spree::Tenant.create(shortname: 'test', domain: 'test.dev')
  97 + Thread.current[:tenant_id] = nil
97 98 Spree::Tenant.should_receive(:master).and_return(tenant)
98 99
99 100 Spree::Tenant.current_tenant_id.should == tenant.id
@@ -106,7 +107,7 @@ def assert_requires_attribute(attribute_name)
106 107 Thread.current[:tenant_id] = nil
107 108 end
108 109
109   - let(:tenant) { FactoryGirl.create(:tenant) }
  110 + let(:tenant) { Spree::Tenant.create!(shortname: 'test', domain: 'test.dev') }
110 111
111 112 context 'with an integer' do
112 113 it 'sets the tenant id stored in the current thread' do
@@ -129,6 +130,16 @@ def assert_requires_attribute(attribute_name)
129 130 end
130 131 end
131 132
  133 + context 'with nil' do
  134 + it 'set the tenant id to the id of the master tenant' do
  135 + Thread.current[:tenant_id].should == nil
  136 +
  137 + Spree::Tenant.set_current_tenant(nil)
  138 +
  139 + Thread.current[:tenant_id].should == Spree::Tenant.master.id
  140 + end
  141 + end
  142 +
132 143 context 'with something else' do
133 144 it 'raises an exception' do
134 145 expect {
@@ -138,4 +149,33 @@ def assert_requires_attribute(attribute_name)
138 149 end
139 150 end
140 151
  152 + context '#create' do
  153 + let(:created_tenant) do
  154 + Spree::Tenant.create!(shortname: 'temp', domain: 'temp.info')
  155 + end
  156 +
  157 + before do
  158 + Spree::Tenant.set_current_tenant(created_tenant)
  159 + end
  160 +
  161 + it 'seeds tenant with roles' do
  162 + expect(Spree::Role.count).to be > 0
  163 + end
  164 +
  165 + it 'seeds tenant with states' do
  166 + expect(Spree::State.count).to be > 0
  167 + end
  168 +
  169 + it 'seeds tenant with countries' do
  170 + expect(Spree::Country.count).to be > 0
  171 + end
  172 +
  173 + it 'seeds tenant with zones' do
  174 + expect(Spree::Zone.count).to be > 0
  175 + end
  176 +
  177 + it 'seeds tenant with zone_members' do
  178 + expect(Spree::ZoneMember.count).to be > 0
  179 + end
  180 + end
141 181 end

0 comments on commit 52178ce

Please sign in to comment.
Something went wrong with that request. Please try again.