-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Ensure db:seed runs before spree_sample:load #4907
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,8 +3,11 @@ | |
| begin | ||
| north_america = Spree::Zone.find_by!(name: "North America") | ||
| rescue ActiveRecord::RecordNotFound | ||
| puts "Couldn't find 'North America' zone. Did you run `rake db:seed` first?" | ||
| puts "That task will set up the countries, states and zones required for Spree." | ||
| puts <<~TEXT | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Love this DX, thanks! |
||
| Couldn't find 'North America' zone. Did you run `rails db:seed` first? | ||
|
|
||
| That task will set up the countries, states and zones required for your store. | ||
| TEXT | ||
| exit | ||
| end | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,38 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| require 'spec_helper' | ||
| require "spec_helper" | ||
| require "rake" | ||
|
|
||
| describe "Load samples" do | ||
| it "doesn't raise any error" do | ||
| expect { | ||
| Spree::Core::Engine.load_seed | ||
| expect do | ||
| pid = fork { Spree::Core::Engine.load_seed } | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we need a separate process here instead of just running |
||
| Process.wait(pid) | ||
| SpreeSample::Engine.load_samples | ||
| }.to output.to_stdout | ||
| ensure | ||
| Process.kill(:KILL, pid) unless $?.exitstatus.zero? | ||
| end.not_to raise_error | ||
| end | ||
|
|
||
| it "has db:seed as a prerequisite" do | ||
| Rails.application.load_tasks | ||
|
|
||
| task = Rake::Task["spree_sample:load"] | ||
| seed_task = Rake::Task["db:seed"] | ||
| expect(task.prerequisite_tasks).to include(seed_task) | ||
| end | ||
| end | ||
|
|
||
| describe "Load seeds multiple times" do | ||
| it "doesn't duplicate records" do | ||
| 4.times do | ||
| pid = fork { Spree::Core::Engine.load_seed } | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will this local variable be overridden at each cycle? Might this interfere with the process killing in the ensure block (it only always kills the last process but previous ones might still be executing)? |
||
| Process.wait(pid) | ||
| ensure | ||
| Process.kill(:KILL, pid) unless $?.exitstatus.zero? | ||
| end | ||
|
|
||
| expect(Spree::Store.count).to eq(1) | ||
| expect(Spree::Zone.count).to eq(2) | ||
| end | ||
| end | ||
Uh oh!
There was an error while loading. Please reload this page.