2017-12-10 23:05:11 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2020-12-15 14:49:47 -05:00
|
|
|
ENV["DB"] ||= "sqlite"
|
|
|
|
|
2018-06-03 22:49:23 -04:00
|
|
|
require "fileutils"
|
2016-03-05 17:07:32 -05:00
|
|
|
require "bundler"
|
2010-10-15 07:53:33 -04:00
|
|
|
Bundler::GemHelper.install_tasks
|
2010-10-12 08:15:56 -04:00
|
|
|
|
2020-12-15 14:49:47 -05:00
|
|
|
desc "Copy the database.DB.yml per ENV['DB']"
|
|
|
|
task :install_database_yml do
|
|
|
|
puts format("installing database.yml for %s", ENV["DB"])
|
|
|
|
|
2018-06-03 22:49:23 -04:00
|
|
|
# It's tempting to use `git clean` here, but this rake task will be run by
|
|
|
|
# people working on changes that haven't been committed yet, so we have to
|
|
|
|
# be more selective with what we delete.
|
|
|
|
::FileUtils.rm("spec/dummy_app/db/database.yml", force: true)
|
2020-12-15 14:49:47 -05:00
|
|
|
|
|
|
|
FileUtils.cp(
|
|
|
|
"spec/dummy_app/config/database.#{ENV['DB']}.yml",
|
|
|
|
"spec/dummy_app/config/database.yml"
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
desc "Delete generated files and databases"
|
|
|
|
task :clean do
|
|
|
|
puts format("dropping %s database", ENV["DB"])
|
2018-06-03 22:49:23 -04:00
|
|
|
case ENV["DB"]
|
|
|
|
when "mysql"
|
2020-12-15 14:49:47 -05:00
|
|
|
# TODO: only works locally. doesn't respect database.yml
|
|
|
|
system "mysqladmin drop -f paper_trail_test > /dev/null 2>&1"
|
2018-06-03 22:49:23 -04:00
|
|
|
when "postgres"
|
2020-12-15 14:49:47 -05:00
|
|
|
# TODO: only works locally. doesn't respect database.yml
|
|
|
|
system "dropdb --if-exists paper_trail_test > /dev/null 2>&1"
|
2018-06-03 22:49:23 -04:00
|
|
|
when nil, "sqlite"
|
|
|
|
::FileUtils.rm(::Dir.glob("spec/dummy_app/db/*.sqlite3"))
|
|
|
|
else
|
|
|
|
raise "Don't know how to clean specified RDBMS: #{ENV['DB']}"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-12-15 14:49:47 -05:00
|
|
|
desc <<~EOS
|
|
|
|
Write a database.yml for the specified RDBMS, and create database. Does not
|
|
|
|
migrate. Migration happens later in spec_helper.
|
|
|
|
EOS
|
|
|
|
task prepare: %i[clean install_database_yml] do
|
|
|
|
puts format("creating %s database", ENV["DB"])
|
2018-06-03 22:49:23 -04:00
|
|
|
case ENV["DB"]
|
|
|
|
when "mysql"
|
2020-12-15 14:49:47 -05:00
|
|
|
# TODO: only works locally. doesn't respect database.yml
|
|
|
|
system "mysqladmin create paper_trail_test"
|
2018-06-03 22:49:23 -04:00
|
|
|
when "postgres"
|
2020-12-15 14:49:47 -05:00
|
|
|
# TODO: only works locally. doesn't respect database.yml
|
|
|
|
system "createdb paper_trail_test"
|
2018-06-03 22:49:23 -04:00
|
|
|
when nil, "sqlite"
|
2020-12-15 14:49:47 -05:00
|
|
|
# noop. test.sqlite3 will be created when migration happens
|
2018-06-03 22:49:23 -04:00
|
|
|
nil
|
|
|
|
else
|
|
|
|
raise "Don't know how to create specified DB: #{ENV['DB']}"
|
|
|
|
end
|
2014-03-14 16:11:10 -04:00
|
|
|
end
|
|
|
|
|
2016-03-05 17:07:32 -05:00
|
|
|
require "rspec/core/rake_task"
|
|
|
|
desc "Run tests on PaperTrail with RSpec"
|
2016-02-06 23:53:05 -05:00
|
|
|
task(:spec).clear
|
|
|
|
RSpec::Core::RakeTask.new(:spec) do |t|
|
|
|
|
t.verbose = false # hide list of specs bit.ly/1nVq3Jn
|
|
|
|
end
|
2013-08-27 15:12:33 -04:00
|
|
|
|
2016-03-05 17:07:32 -05:00
|
|
|
require "rubocop/rake_task"
|
2015-11-27 21:16:37 -05:00
|
|
|
RuboCop::RakeTask.new
|
|
|
|
|
2016-03-05 17:07:32 -05:00
|
|
|
desc "Default: run all available test suites"
|
2018-05-29 18:25:44 -04:00
|
|
|
task default: %i[rubocop prepare spec]
|