Skip to content

Commit

Permalink
Use github actions, remove all unsupported versions and refactor tests (
Browse files Browse the repository at this point in the history
  • Loading branch information
piotaixr authored Nov 2, 2023
1 parent 848dbef commit 4bec718
Show file tree
Hide file tree
Showing 7 changed files with 110 additions and 136 deletions.
28 changes: 28 additions & 0 deletions .github/workflows/master.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Development

on:
push:

jobs:
tests:
name: Tests
runs-on: ubuntu-latest
strategy:
matrix:
ruby_version:
- 2.7.7
- 3.0.5
- 3.1.3
ar:
- "~> 6.0.0"
- "~> 6.1.0"
env:
NOKOGIRI_USE_SYSTEM_LIBRARIES: 1
AR: ${{ matrix.ar }}
steps:
- uses: actions/checkout@v3
- uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby_version }}
bundler-cache: true
- run: bundle exec rake spec
29 changes: 0 additions & 29 deletions .travis.yml

This file was deleted.

7 changes: 4 additions & 3 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
source 'https://rubygems.org'

gem 'rake', '>= 10.0'
gem 'activerecord', ENV['AR'] ? ENV['AR'].split(",") : [">= 4.2.7", "< 7.1.0", "!= 5.2.3", "!=5.2.3.rc1"]
gem 'railties', ENV['AR'] ? ENV['AR'].split(",") : [">= 4.2.7", "< 7.1.0", "!= 5.2.3", "!=5.2.3.rc1"]
gem 'activerecord', ENV['AR'] ? ENV['AR'].split(",") : [">= 6.0.0", "< 7.1.0"]
gem 'railties', ENV['AR'] ? ENV['AR'].split(",") : [">= 6.0.0", "< 7.1.0"]
gem 'nokogiri', "~> 1.14.pre"

group :dev do
gem 'sqlite3', ENV['SQL'] ? ENV['SQL'].split(",") : ['~> 1.4']
gem 'sqlite3', '~> 1.5'
gem 'rspec', '>= 2.99.0'
gem 'jeweler'
end
26 changes: 6 additions & 20 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,32 +1,16 @@
require 'rubygems'
require 'bundler/setup'

task :default do
sh "rspec spec"
end

task :all do
sh "AR='~>3.0.0' bundle update activerecord && bundle exec rake"
sh "AR='~>3.1.0.rc4' bundle update activerecord && bundle exec rake"
end

task :specs => ["specs:nodb"]
namespace :specs do
begin
require 'rspec/core/rake_task'

desc "only specs that don't use database connection"
RSpec::Core::RakeTask.new "nodb" do |t|
t.pattern = "spec/standalone_migrations/**/*_spec.rb"
end

desc "run all specs for travis"
RSpec::Core::RakeTask.new "travis" do |t|
t.pattern = "spec/**/*_spec.rb"
t.rspec_opts = "--tag ~@travis_error"
end

desc "run all specs including those which uses database"
task :all => [:default, :nodb]
RSpec::Core::RakeTask.new(:spec)
rescue LoadError
# no rspec available
end

# rake install -> install gem locally (for tests)
Expand All @@ -50,3 +34,5 @@ else

Jeweler::GemcutterTasks.new
end

task default: "spec"
76 changes: 35 additions & 41 deletions spec/standalone_migrations/configurator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,36 @@
module StandaloneMigrations
describe Configurator, "which allows define custom dirs and files to work with your migrations" do

describe "environment yaml configuration loading" do
around(:each) do |example|
Dir.mktmpdir do |dir|
Dir.chdir(dir) do
example.run
end
end
end

describe "environment yaml configuration loading" do

let(:env_hash_other_db) do
{
"development" => { "adapter" => "mysql2", "database" => "database_name" },
"test" => { "adapter" => "mysql2", "database" => "database_name" },
"production" => {"adapter" => "mysql2", "database" => "database_name" }
"development" => {"adapter" => "mysql2", "database" => "database_name"},
"test" => {"adapter" => "mysql2", "database" => "database_name"},
"production" => {"adapter" => "mysql2", "database" => "database_name"}
}
end

before(:all) do
around(:each) do |example|
@env_hash = {
"development" => { "adapter" => "sqlite3", "database" => "db/development.sql" },
"test" => { "adapter" => "sqlite3", "database" => "db/test.sql" },
"production" => {"adapter" => "sqlite3", "database" => ":memory:" }
"development" => {"adapter" => "sqlite3", "database" => "db/development.sql"},
"test" => {"adapter" => "sqlite3", "database" => "db/test.sql"},
"production" => {"adapter" => "sqlite3", "database" => ":memory:"}
}
@original_dir = Dir.pwd
Dir.chdir( File.expand_path("../../", __FILE__) )
FileUtils.mkdir_p "tmp/db"
Dir.chdir "tmp"
FileUtils.mkdir_p "db"
File.open("db/config.yml", "w") do |f|
f.write @env_hash.to_yaml
end

example.run
end

it "load the specific environment config" do
Expand All @@ -49,7 +55,7 @@ module StandaloneMigrations
let(:configurator) { Configurator.new }

before(:all) do
@new_config = { 'sbrobous' => 'test' }
@new_config = {'sbrobous' => 'test'}
Configurator.environments_config do |env|
env.on "production" do
@new_config
Expand Down Expand Up @@ -80,10 +86,6 @@ module StandaloneMigrations

end

after(:all) do
Dir.chdir @original_dir
end

end

context "default values when .standalone_configurations is missing" do
Expand All @@ -107,10 +109,10 @@ module StandaloneMigrations
context "passing configurations as a parameter" do
let(:args) do
{
:config => "custom/config/database.yml",
:migrate_dir => "custom/db/migrate",
:seeds => "custom/db/seeds.rb",
:schema => "custom/db/schema.rb"
:config => "custom/config/database.yml",
:migrate_dir => "custom/db/migrate",
:seeds => "custom/db/seeds.rb",
:schema => "custom/db/schema.rb"
}
end

Expand Down Expand Up @@ -138,17 +140,17 @@ module StandaloneMigrations

context "using a .standalone_migrations file with configurations" do

before(:all) do
@original_dir = Dir.pwd
Dir.chdir File.expand_path("../", __FILE__)
before(:each) do
file = ".standalone_migrations"
File.open(file, "w") { |file| file.write(yaml_hash.to_yaml) }
end

let(:yaml_hash) do
{
"db" => {
"seeds" => "file/db/seeds.rb",
"migrate" => "file/db/migrate",
"schema" => "file/db/schema.rb"
"seeds" => "file/db/seeds.rb",
"migrate" => "file/db/migrate",
"schema" => "file/db/schema.rb"
},
"config" => {
"database" => "file/config/database.yml"
Expand All @@ -159,9 +161,9 @@ module StandaloneMigrations
let(:yaml_hash_other_db) do
{
"db" => {
"seeds" => "db2/seeds.rb",
"migrate" => "db2/migrate",
"schema" => "db2/schema.rb"
"seeds" => "db2/seeds.rb",
"migrate" => "db2/migrate",
"schema" => "db2/schema.rb"
},
"config" => {
"database" => "config/config_other.yml"
Expand All @@ -170,20 +172,18 @@ module StandaloneMigrations
end

let(:configurator) do
file = ".standalone_migrations"
File.open(file, "w") { |file| file.write(yaml_hash.to_yaml) }
Configurator.new
end

context "with database environment variable passed" do

before(:all) do
before(:each) do
ENV['DATABASE'] = "other_db"
file_other_db = ".other_db.standalone_migrations"
File.open(file_other_db, "w") { |file| file.write(yaml_hash_other_db.to_yaml) }
end

let(:other_configurator) do
file_other_db = ".other_db.standalone_migrations"
File.open(file_other_db, "w") { |file| file.write(yaml_hash_other_db.to_yaml) }
Configurator.new
end

Expand All @@ -196,7 +196,6 @@ module StandaloneMigrations
end

after(:all) do
File.delete ".other_db.standalone_migrations"
ENV['DATABASE'] = nil
end

Expand Down Expand Up @@ -245,11 +244,6 @@ module StandaloneMigrations
expect(configurator.schema).to eq(yaml_hash["db"]["schema"])
end

after(:all) do
File.delete ".standalone_migrations"
Dir.chdir @original_dir
end

end
end
end
Loading

0 comments on commit 4bec718

Please sign in to comment.