Skip to content

Commit cecf524

Browse files
committed
Ensure db:seed runs before spree_sample:load
1 parent 1050ca0 commit cecf524

File tree

6 files changed

+27
-6
lines changed

6 files changed

+27
-6
lines changed

core/app/models/spree/order_merger.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def merge!(other_order, user = nil)
6767

6868
private
6969

70-
# Retreive a matching line item from the existing order
70+
# Retrieve a matching line item from the existing order
7171
#
7272
# It will compare line items based on variants, and all line item
7373
# comparison hooks on the order.

sample/db/samples/tax_rates.rb

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
11
# frozen_string_literal: true
22

3-
north_america = Spree::Zone.find_by!(name: "North America")
3+
begin
4+
north_america = Spree::Zone.find_by!(name: "North America")
5+
rescue ActiveRecord::RecordNotFound
6+
puts <<~TEXT
7+
Couldn't find 'North America' zone. Did you run `rake db:seed` first?
8+
9+
That task will set up the countries, states and zones required for Spree.
10+
TEXT
11+
exit
12+
end
13+
414
clothing = Spree::TaxCategory.find_by!(name: "Default")
515
tax_rate = Spree::TaxRate.create(
616
name: "North America",

sample/lib/spree/sample.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ module Spree
77
module Sample
88
class << self
99
def load_sample(file, shell: Thor::Base.shell.new)
10-
# If file is exists within application it takes precendence.
10+
# If file is exists within application it takes precedence.
1111
if File.exist?(File.join(Rails.root, 'db', 'samples', "#{file}.rb"))
1212
path = File.expand_path(File.join(Rails.root, 'db', 'samples', "#{file}.rb"))
1313
else

sample/lib/tasks/sample.rake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ require 'spree/sample'
55

66
namespace :spree_sample do
77
desc 'Loads sample data'
8-
task load: :environment do
8+
task load: ['db:seed', :environment] do
99
if ARGV.include?("db:migrate")
1010
puts <<~TEXT
1111
Please run db:migrate separately from spree_sample:load.

sample/solidus_sample.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Gem::Specification.new do |s|
1111

1212
s.author = 'Solidus Team'
1313
s.email = 'contact@solidus.io'
14-
s.homepage = 'http://solidus.io'
14+
s.homepage = 'https://solidus.io'
1515
s.license = 'BSD-3-Clause'
1616

1717
s.metadata['rubygems_mfa_required'] = 'true'
Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# frozen_string_literal: true
22

3-
require 'spec_helper'
3+
require "spec_helper"
4+
require "rake"
45

56
describe "Load samples" do
67
it "doesn't raise any error" do
@@ -9,4 +10,14 @@
910
SpreeSample::Engine.load_samples
1011
}.to output.to_stdout
1112
end
13+
14+
it "has db:seed as a prerequisite" do
15+
task = Rake::Task["spree_sample:load"]
16+
seed_task = Rake::Task["db:seed"]
17+
expect(task.prerequisite_tasks).to include(seed_task)
18+
end
19+
20+
before do
21+
Rails.application.load_tasks
22+
end
1223
end

0 commit comments

Comments
 (0)