Skip to content

Commit 858e37f

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

File tree

3 files changed

+24
-3
lines changed

3 files changed

+24
-3
lines changed

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/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.
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)