Skip to content

Commit

Permalink
silencing migrations & asset compilation output for builds on CI - mo…
Browse files Browse the repository at this point in the history
…re readable
  • Loading branch information
damianlegawiec committed Mar 2, 2016
1 parent 05f54a8 commit 70323c2
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 43 deletions.
2 changes: 1 addition & 1 deletion build-ci.rb
Expand Up @@ -47,7 +47,7 @@ def pass?
end
end

private
private

# Check if current bundle is already usable
#
Expand Down
53 changes: 31 additions & 22 deletions core/lib/spree/migrations.rb
Expand Up @@ -21,12 +21,12 @@ def initialize(config, engine_name)
# Shouldn't run on test mode because migrations inside engine don't have
# engine name on the file name
def check
if File.directory?("db/migrate")
if File.directory?(app_dir)
engine_in_app = app_migrations.map do |file_name|
name, engine = file_name.split(".", 2)
next unless match_engine?(engine)
name
end.compact! || []
end.compact

missing_migrations = engine_migrations.sort - engine_in_app.sort
unless missing_migrations.empty?
Expand All @@ -41,28 +41,37 @@ def check
end

private
def engine_migrations
Dir.entries("#{config.root}/db/migrate").map do |file_name|
name = file_name.split("_", 2).last.split(".", 2).first
name.empty? ? next : name
end.compact! || []
end

def app_migrations
Dir.entries("db/migrate").map do |file_name|
next if [".", ".."].include? file_name
name = file_name.split("_", 2).last
name.empty? ? next : name
end.compact! || []
end
def engine_migrations
Dir.entries(engine_dir).map do |file_name|
name = file_name.split("_", 2).last.split(".", 2).first
name.empty? ? next : name
end.compact! || []
end

def match_engine?(engine)
if engine_name == "spree"
# Avoid stores upgrading from 1.3 getting wrong warnings
["spree.rb", "spree_promo.rb"].include? engine
else
engine == "#{engine_name}.rb"
end
def app_migrations
Dir.entries(app_dir).map do |file_name|
next if [".", ".."].include? file_name
name = file_name.split("_", 2).last
name.empty? ? next : name
end.compact! || []
end

def app_dir
"#{Rails.root}/db/migrate"
end

def engine_dir
"#{config.root}/db/migrate"
end

def match_engine?(engine)
if engine_name == "spree"
# Avoid stores upgrading from 1.3 getting wrong warnings
["spree.rb", "spree_promo.rb"].include? engine
else
engine == "#{engine_name}.rb"
end
end
end
end
20 changes: 6 additions & 14 deletions core/lib/spree/testing_support/common_rake.rb
Expand Up @@ -6,11 +6,11 @@

desc "Generates a dummy app for testing"
namespace :common do
task :test_app, :user_class do |t, args|
args.with_defaults(:user_class => "Spree::LegacyUser")
require "#{ENV['LIB_NAME']}"
task :test_app, :user_class do |_t, args|
args.with_defaults(user_class: "Spree::LegacyUser")
require ENV['LIB_NAME'].to_s

ENV["RAILS_ENV"] = 'test'
ENV['RAILS_ENV'] = 'test'

Spree::DummyGenerator.start ["--lib_name=#{ENV['LIB_NAME']}", "--quiet"]
Spree::InstallGenerator.start ["--lib_name=#{ENV['LIB_NAME']}", "--auto-accept", "--migrate=false", "--seed=false", "--sample=false", "--quiet", "--user_class=#{args[:user_class]}"]
Expand All @@ -30,16 +30,8 @@
end
end

task :seed do |t, args|
task :seed do |_t|
puts "Seeding ..."
cmd = "bundle exec rake db:seed RAILS_ENV=test"

if RUBY_PLATFORM =~ /mswin|mingw/ # windows
cmd += " >nul"
else
cmd += " >/dev/null"
end

system(cmd)
system("bundle exec rake db:seed RAILS_ENV=test > #{File::NULL}")
end
end
15 changes: 9 additions & 6 deletions core/spec/lib/spree/migrations_spec.rb
Expand Up @@ -7,15 +7,18 @@ module Spree

let(:config) { double("Config", root: "dir") }

subject { described_class.new(config, "spree") }
let(:engine_dir) { "dir/db/migrate" }
let(:app_dir) { "#{Rails.root}/db/migrate" }

subject { described_class.new(config, "spree") }

before do
expect(File).to receive(:directory?).with("db/migrate").and_return true
expect(File).to receive(:directory?).with(app_dir).and_return true
end

it "warns about missing migrations" do
expect(Dir).to receive(:entries).with("db/migrate").and_return app_migrations
expect(Dir).to receive(:entries).with("dir/db/migrate").and_return engine_migrations
expect(Dir).to receive(:entries).with(app_dir).and_return app_migrations
expect(Dir).to receive(:entries).with(engine_dir).and_return engine_migrations

silence_stream(STDOUT) {
expect(subject.check).to eq true
Expand All @@ -24,8 +27,8 @@ module Spree

context "no missing migrations" do
it "says nothing" do
expect(Dir).to receive(:entries).with("dir/db/migrate").and_return engine_migrations
expect(Dir).to receive(:entries).with("db/migrate").and_return (app_migrations + engine_migrations)
expect(Dir).to receive(:entries).with(engine_dir).and_return engine_migrations
expect(Dir).to receive(:entries).with(app_dir).and_return(app_migrations + engine_migrations)
expect(subject.check).to eq nil
end
end
Expand Down

0 comments on commit 70323c2

Please sign in to comment.