Last active
May 17, 2018 15:23
-
-
Save thisismydesign/b1489437327e3bbcec6da4573ef68203 to your computer and use it in GitHub Desktop.
Rails#32915 db:create cannot be executed twice via `Rake::Task.invoke`
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# frozen_string_literal: true | |
begin | |
require "bundler/inline" | |
rescue LoadError => e | |
$stderr.puts "Bundler version 1.10 or later is required. Please update your Bundler" | |
raise e | |
end | |
a = gemfile(true) do | |
source "https://rubygems.org" | |
gem "activerecord", "5.2.0" | |
gem "sqlite3", "1.3.13" | |
gem "rake", "~> 10.0" | |
gem "rspec", "~> 3.0" | |
end | |
require "active_record" | |
require "rspec" | |
require "rake" | |
require "fileutils" | |
def load_active_record_tasks(database_configuration:, root:, db_dir: root, migrations_paths: [root], env: "development", seed_loader: nil) | |
include ActiveRecord::Tasks | |
DatabaseTasks.database_configuration = database_configuration | |
DatabaseTasks.root = root | |
DatabaseTasks.db_dir = db_dir | |
DatabaseTasks.migrations_paths = migrations_paths | |
DatabaseTasks.env = env | |
DatabaseTasks.seed_loader = seed_loader | |
task :environment do | |
ActiveRecord::Base.configurations = DatabaseTasks.database_configuration | |
ActiveRecord::Base.establish_connection DatabaseTasks.env.to_sym | |
end | |
load 'active_record/railties/databases.rake' | |
end | |
root = Pathname.new(".") | |
sqlite3_config = { | |
"development" => { | |
"adapter" => "sqlite3", | |
"database" => "development" | |
} | |
} | |
load_active_record_tasks(database_configuration: sqlite3_config, root: root, db_dir: root) | |
RSpec.configure do |config| | |
config.formatter = "documentation" | |
end | |
RSpec.describe "db:create issue", :aggregate_failures do | |
let(:db_name) { sqlite3_config["development"]["database"] } | |
let(:db) { root.join(db_name) } | |
before do | |
FileUtils.rm(db) rescue Errno::ENOENT | |
end | |
after do | |
FileUtils.rm(db) rescue Errno::ENOENT | |
end | |
describe "db:create issue" do | |
it "db:create can be executed twice but says DB already exists" do | |
Rake::Task["db:create"].invoke | |
# Issue closed, fix is to add `Rake::Task["db:create"].reenable` here | |
expect { Rake::Task["db:create"].invoke }.to output("Database '#{db_name}' already exists\n").to_stderr | |
end | |
it "db:create can be executed again successfully after drop" do | |
Rake::Task["db:create"].invoke | |
Rake::Task["db:drop"].invoke | |
# Issue closed, fix is to add `Rake::Task["db:create"].reenable` here | |
expect { Rake::Task["db:create"].invoke }.to output("Created database '#{db_name}''n").to_stdout | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ rspec _rails#32915.rb | |
Fetching gem metadata from https://rubygems.org/........ | |
Resolving dependencies... | |
Using rake 10.5.0 | |
Using concurrent-ruby 1.0.5 | |
Using i18n 1.0.1 | |
Using minitest 5.11.3 | |
Using thread_safe 0.3.6 | |
Using tzinfo 1.2.5 | |
Using activesupport 5.2.0 | |
Using activemodel 5.2.0 | |
Using arel 9.0.0 | |
Using activerecord 5.2.0 | |
Using bundler 1.16.0 | |
Using diff-lcs 1.3 | |
Using rspec-support 3.7.1 | |
Using rspec-core 3.7.1 | |
Using rspec-expectations 3.7.0 | |
Using rspec-mocks 3.7.0 | |
Using rspec 3.7.0 | |
Using sqlite3 1.3.13 | |
db:create issue | |
db:create issue | |
Created database 'development' | |
db:create can be executed twice but says DB already exists (FAILED - 1) | |
Dropped database 'development' | |
db:create can be executed again successfully after drop (FAILED - 2) | |
Failures: | |
1) db:create issue db:create issue db:create can be executed twice but says DB already exists | |
Failure/Error: expect { Rake::Task["db:create"].invoke }.to output("Database '#{db_name}' already exists").to_stderr | |
expected block to output "Database 'development' already exists" to stderr, but output nothing | |
# ./test.rb:71:in `block (3 levels) in <top (required)>' | |
2) db:create issue db:create issue db:create can be executed again successfully after drop | |
Failure/Error: expect { Rake::Task["db:create"].invoke }.to output("Created database '#{db_name}'").to_stdout | |
expected block to output "Created database 'development'" to stdout, but output nothing | |
# ./test.rb:78:in `block (3 levels) in <top (required)>' | |
Finished in 0.30052 seconds (files took 2.67 seconds to load) | |
2 examples, 2 failures | |
Failed examples: | |
rspec ./test.rb:68 # db:create issue db:create issue db:create can be executed twice but says DB already exists | |
rspec ./test.rb:74 # db:create issue db:create issue db:create can be executed again successfully after drop |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment