diff --git a/lib/tasks/dev.rake b/lib/tasks/dev.rake index 2eff925395..e14ef6a535 100644 --- a/lib/tasks/dev.rake +++ b/lib/tasks/dev.rake @@ -316,6 +316,22 @@ namespace :ofn do if EnterpriseRole.count < 1 EnterpriseRole.create!(user: Spree::User.first, enterprise: enterprise2) end + display_deprecation_warning + end + + def display_deprecation_warning + behaviour = ActiveSupport::Deprecation.behavior = :stderr + ActiveSupport::Deprecation.behavior = :stderr + ActiveSupport::Deprecation.warn(< 0 && + Spree::Country.count > 0 && + Spree::State.count > 0 + end +end diff --git a/lib/tasks/sample_data/addressing.rb b/lib/tasks/sample_data/addressing.rb new file mode 100644 index 0000000000..bc1471e276 --- /dev/null +++ b/lib/tasks/sample_data/addressing.rb @@ -0,0 +1,25 @@ +module Addressing + private + + def address(string) + state = country.states.first + parts = string.split(", ") + Spree::Address.new( + address1: parts[0], + city: parts[1], + zipcode: parts[2], + state: state, + country: country + ) + end + + def zone + zone = Spree::Zone.find_or_create_by_name!(ENV.fetch('CHECKOUT_ZONE')) + zone.members.create!(zoneable: country) unless zone.zoneables.include?(country) + zone + end + + def country + Spree::Country.find_by_iso(ENV.fetch('DEFAULT_COUNTRY_CODE')) + end +end diff --git a/lib/tasks/sample_data/customer_factory.rb b/lib/tasks/sample_data/customer_factory.rb new file mode 100644 index 0000000000..4c1904f2cd --- /dev/null +++ b/lib/tasks/sample_data/customer_factory.rb @@ -0,0 +1,18 @@ +require "tasks/sample_data/logging" + +class CustomerFactory + include Logging + + def create_samples(users) + log "Creating customers" + jane = users["Jane Customer"] + maryse_shop = Enterprise.find_by_name("Maryse's Private Shop") + return if Customer.where(user_id: jane, enterprise_id: maryse_shop).exists? + log "- #{jane.email}" + Customer.create!( + email: jane.email, + user: jane, + enterprise: maryse_shop + ) + end +end diff --git a/lib/tasks/sample_data/enterprise_factory.rb b/lib/tasks/sample_data/enterprise_factory.rb new file mode 100644 index 0000000000..cf5d62db22 --- /dev/null +++ b/lib/tasks/sample_data/enterprise_factory.rb @@ -0,0 +1,94 @@ +require "tasks/sample_data/addressing" +require "tasks/sample_data/logging" + +class EnterpriseFactory + include Logging + include Addressing + + def create_samples(users) + log "Creating enterprises:" + enterprise_data(users).map do |data| + name = data[:name] + log "- #{name}" + data[:long_description] = data[:long_description].strip_heredoc.tr("\n", " ") + Enterprise.create_with(data).find_or_create_by_name!(name) + end + end + + private + + # rubocop:disable Metrics/MethodLength + def enterprise_data(users) + [ + { + name: "Penny's Profile", + owner: users["Penny Profile"], + is_primary_producer: false, + sells: "none", + address: address("25 Myrtle Street, Bayswater, 3153"), + long_description: <