slodd 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.ruby-version +1 -1
- data/.travis.yml +3 -0
- data/Gemfile +1 -1
- data/README.md +4 -2
- data/Rakefile +5 -5
- data/bin/gurl +6 -6
- data/bin/slodd +11 -11
- data/lib/slodd.rb +6 -6
- data/lib/slodd/config.rb +34 -9
- data/lib/slodd/github.rb +3 -3
- data/lib/slodd/http.rb +1 -1
- data/lib/slodd/runner.rb +4 -4
- data/lib/slodd/version.rb +1 -1
- data/slodd.gemspec +17 -16
- data/spec/lib/config_spec.rb +111 -87
- data/spec/lib/gitub_spec.rb +18 -18
- data/spec/lib/http_spec.rb +5 -5
- data/spec/lib/local_spec.rb +3 -3
- data/spec/lib/runner_spec.rb +12 -12
- data/spec/spec_helper.rb +12 -5
- data/spec/support/schema.rb +2 -2
- metadata +5 -6
- data/.rubocop.yml +0 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a48e3c454332b7fb8a9c550ede53dcd5be02fb03
|
4
|
+
data.tar.gz: eb50f18fd0ae40bfdff86a8b89a824009b4f3fa4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5f9bc7ec5c4fd353956191b645cd0658f0f460a0375f9962cec009fb3840c0d98eece5afc6293ed890adcf6f02ce6afc93baf57e5f862d3a815740862362cc01
|
7
|
+
data.tar.gz: bdec1445b47d839f045bdab722bf144e59d06dac0c96478812e4c3da5790182cb68ebdae3f84a2f7b3e9a6f3e2dd74df87a259ac3750f91263b797caff37e986
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.1.
|
1
|
+
2.1.7
|
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,8 +1,10 @@
|
|
1
1
|
Schema Loading On Dependent Databases
|
2
2
|
=====================================
|
3
3
|
|
4
|
-
[![Build Status](https://travis-ci.org/errm/slodd.
|
5
|
-
[![Gem Version](https://badge.fury.io/rb/slodd.
|
4
|
+
[![Build Status](https://travis-ci.org/errm/slodd.svg?branch=master)](https://travis-ci.org/errm/slodd)
|
5
|
+
[![Gem Version](https://badge.fury.io/rb/slodd.svg)](http://badge.fury.io/rb/slodd)
|
6
|
+
[![Code Climate](https://codeclimate.com/github/errm/slodd/badges/gpa.svg)](https://codeclimate.com/github/errm/slodd)
|
7
|
+
[![Test Coverage](https://codeclimate.com/github/errm/slodd/badges/coverage.svg)](https://codeclimate.com/github/errm/slodd)
|
6
8
|
|
7
9
|
Slodd is a lightweight tool for loading an activerecord schema.rb into a database, like rake db:schema:load but more awesome.
|
8
10
|
|
data/Rakefile
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
1
|
+
require 'bundler/gem_tasks'
|
2
|
+
require 'rspec/core/rake_task'
|
3
|
+
require 'reevoocop/rake_task'
|
4
4
|
|
5
|
-
|
5
|
+
ReevooCop::RakeTask.new(:reevoocop)
|
6
6
|
RSpec::Core::RakeTask.new(:spec)
|
7
7
|
|
8
|
-
task default: [:spec, :
|
8
|
+
task default: [:spec, :reevoocop]
|
data/bin/gurl
CHANGED
@@ -1,23 +1,23 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
# encoding: utf-8
|
3
3
|
|
4
|
-
require
|
5
|
-
require
|
4
|
+
require 'slodd'
|
5
|
+
require 'optparse'
|
6
6
|
|
7
7
|
OptionParser.new do |opt|
|
8
|
-
opt.on(
|
8
|
+
opt.on('-g', '--github USER/REPO', 'github repo') do |g|
|
9
9
|
Slodd::Config.github = g
|
10
10
|
end
|
11
11
|
|
12
|
-
opt.on(
|
12
|
+
opt.on('-t', '--token TOKEN', 'github token') do |t|
|
13
13
|
Slodd::Config.token = t
|
14
14
|
end
|
15
15
|
|
16
|
-
opt.on(
|
16
|
+
opt.on('-r', '--ref REF', 'github ref') do |r|
|
17
17
|
Slodd::Config.ref = r
|
18
18
|
end
|
19
19
|
|
20
|
-
opt.on(
|
20
|
+
opt.on('-f', '--file-schema-path PATH', 'Path to schema.rb') do |f|
|
21
21
|
Slodd::Config.path = f
|
22
22
|
end
|
23
23
|
end.parse!
|
data/bin/slodd
CHANGED
@@ -1,43 +1,43 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
# encoding: utf-8
|
3
3
|
|
4
|
-
require
|
5
|
-
require
|
4
|
+
require 'slodd'
|
5
|
+
require 'optparse'
|
6
6
|
|
7
7
|
OptionParser.new do |opt|
|
8
|
-
opt.on(
|
8
|
+
opt.on('-d', '--database DATABASES', 'Database names') do |d|
|
9
9
|
Slodd::Config.databases = d
|
10
10
|
end
|
11
11
|
|
12
|
-
opt.on(
|
12
|
+
opt.on('-s', '--schema URI', 'URI for schema.rb') do |s|
|
13
13
|
Slodd::Config.url = s
|
14
14
|
end
|
15
15
|
|
16
|
-
opt.on(
|
16
|
+
opt.on('-g', '--github USER/REPO', 'github repo') do |g|
|
17
17
|
Slodd::Config.github = g
|
18
18
|
end
|
19
19
|
|
20
|
-
opt.on(
|
20
|
+
opt.on('-t', '--token TOKEN', 'github token') do |t|
|
21
21
|
Slodd::Config.token = t
|
22
22
|
end
|
23
23
|
|
24
|
-
opt.on(
|
24
|
+
opt.on('-r', '--ref REF', 'github ref') do |r|
|
25
25
|
Slodd::Config.ref = r
|
26
26
|
end
|
27
27
|
|
28
|
-
opt.on(
|
28
|
+
opt.on('-f', '--file-schema-path PATH', 'Path to schema.rb') do |f|
|
29
29
|
Slodd::Config.path = f
|
30
30
|
end
|
31
31
|
|
32
|
-
opt.on(
|
32
|
+
opt.on('-u', '--username USERNAME', 'MySQL Username') do |u|
|
33
33
|
Slodd::Config.username = u
|
34
34
|
end
|
35
35
|
|
36
|
-
opt.on(
|
36
|
+
opt.on('-p', '--password PASSWORD', 'MySQL Password') do |p|
|
37
37
|
Slodd::Config.password = p
|
38
38
|
end
|
39
39
|
|
40
|
-
opt.on(
|
40
|
+
opt.on('-h', '--host HOST', 'MySQL Hostname') do |h|
|
41
41
|
Slodd::Config.host = h
|
42
42
|
end
|
43
43
|
end.parse!
|
data/lib/slodd.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
-
require
|
2
|
+
require 'slodd/version'
|
3
3
|
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require
|
7
|
-
require
|
8
|
-
require
|
4
|
+
require 'slodd/github'
|
5
|
+
require 'slodd/local'
|
6
|
+
require 'slodd/http'
|
7
|
+
require 'slodd/config'
|
8
|
+
require 'slodd/runner'
|
9
9
|
|
10
10
|
module Slodd
|
11
11
|
end
|
data/lib/slodd/config.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
-
require
|
2
|
+
require 'active_support/core_ext/module/attribute_accessors'
|
3
|
+
require 'uri'
|
3
4
|
|
4
5
|
module Slodd
|
5
6
|
module Config
|
@@ -8,29 +9,29 @@ module Slodd
|
|
8
9
|
mattr_writer :databases
|
9
10
|
|
10
11
|
def self.defaults
|
11
|
-
self.path =
|
12
|
-
self.username =
|
13
|
-
self.host =
|
12
|
+
self.path = 'db/schema.rb'
|
13
|
+
self.username = 'root'
|
14
|
+
self.host = 'localhost'
|
14
15
|
self.databases = nil
|
15
16
|
end
|
16
17
|
|
17
18
|
defaults
|
18
19
|
|
19
20
|
def self.databases
|
21
|
+
self.databases = database_uri.path[1..-1] if database_uri
|
20
22
|
@@databases ? @@databases.split : []
|
21
23
|
end
|
22
24
|
|
23
25
|
def self.database_settings
|
24
|
-
|
25
|
-
password ? settings.merge(password: password) : settings
|
26
|
+
settings_from_url || settings_from_args
|
26
27
|
end
|
27
28
|
|
28
29
|
def self.owner
|
29
|
-
github.split(
|
30
|
+
github.split('/')[0] if github
|
30
31
|
end
|
31
32
|
|
32
33
|
def self.repo
|
33
|
-
github.split(
|
34
|
+
github.split('/')[1] if github
|
34
35
|
end
|
35
36
|
|
36
37
|
def self.fetcher
|
@@ -55,8 +56,32 @@ module Slodd
|
|
55
56
|
token: token,
|
56
57
|
path: path,
|
57
58
|
ref: ref,
|
58
|
-
url: url
|
59
|
+
url: url,
|
59
60
|
}.delete_if { |_, v| v.nil? }
|
60
61
|
end
|
62
|
+
|
63
|
+
private
|
64
|
+
|
65
|
+
def self.settings_from_url
|
66
|
+
return unless database_uri
|
67
|
+
self.databases = database_uri.path[1..-1]
|
68
|
+
{
|
69
|
+
adapter: database_uri.scheme,
|
70
|
+
host: database_uri.host,
|
71
|
+
username: database_uri.user,
|
72
|
+
password: database_uri.password,
|
73
|
+
}
|
74
|
+
end
|
75
|
+
|
76
|
+
def self.database_uri
|
77
|
+
return unless ENV['DATABASE_URL']
|
78
|
+
@_database_uri ||= URI.parse(ENV['DATABASE_URL'])
|
79
|
+
end
|
80
|
+
|
81
|
+
def self.settings_from_args
|
82
|
+
settings = { adapter: 'mysql2', host: host, username: username }
|
83
|
+
settings.merge!(password: password) if password
|
84
|
+
settings
|
85
|
+
end
|
61
86
|
end
|
62
87
|
end
|
data/lib/slodd/github.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
-
require
|
2
|
+
require 'open-uri'
|
3
3
|
|
4
4
|
module Slodd
|
5
5
|
class Github
|
@@ -29,8 +29,8 @@ module Slodd
|
|
29
29
|
|
30
30
|
def headers
|
31
31
|
{
|
32
|
-
|
33
|
-
|
32
|
+
'Accept' => 'application/vnd.github.3.raw',
|
33
|
+
'Authorization' => "token #{token}",
|
34
34
|
}
|
35
35
|
end
|
36
36
|
end
|
data/lib/slodd/http.rb
CHANGED
data/lib/slodd/runner.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
-
require
|
3
|
-
require
|
2
|
+
require 'active_record'
|
3
|
+
require 'mysql2'
|
4
4
|
|
5
5
|
module Slodd
|
6
6
|
class Runner
|
@@ -15,7 +15,7 @@ module Slodd
|
|
15
15
|
def run!
|
16
16
|
Config.databases.each do |database|
|
17
17
|
create_database(database)
|
18
|
-
eval(schema)
|
18
|
+
eval(schema) # rubocop:disable Lint/Eval
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
@@ -39,7 +39,7 @@ module Slodd
|
|
39
39
|
end
|
40
40
|
|
41
41
|
def options
|
42
|
-
{ charset:
|
42
|
+
{ charset: 'utf8', collation: 'utf8_unicode_ci' }
|
43
43
|
end
|
44
44
|
|
45
45
|
def error_message(sqlerr, database)
|
data/lib/slodd/version.rb
CHANGED
data/slodd.gemspec
CHANGED
@@ -1,25 +1,26 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
|
-
lib = File.expand_path(
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
3
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require
|
4
|
+
require 'slodd/version'
|
5
|
+
require 'English'
|
5
6
|
|
6
7
|
Gem::Specification.new do |gem|
|
7
|
-
gem.name =
|
8
|
+
gem.name = 'slodd'
|
8
9
|
gem.version = Slodd::VERSION
|
9
|
-
gem.authors = [
|
10
|
-
gem.email = [
|
11
|
-
gem.description =
|
12
|
-
gem.summary =
|
13
|
-
gem.homepage =
|
10
|
+
gem.authors = ['Ed Robinson']
|
11
|
+
gem.email = ['ed.robinson@reevoo.com']
|
12
|
+
gem.description = 'Schema Loading On Dependent Databases'
|
13
|
+
gem.summary = 'Schema Loading On Dependent Databases'
|
14
|
+
gem.homepage = 'https://github.com/errm/slodd'
|
14
15
|
|
15
|
-
gem.files = `git ls-files`.split(
|
16
|
+
gem.files = `git ls-files`.split($RS)
|
16
17
|
gem.executables = gem.files.grep(/^bin\//).map { |f| File.basename(f) }
|
17
18
|
gem.test_files = gem.files.grep(/^(test|spec|features)\//)
|
18
|
-
gem.require_paths = [
|
19
|
-
gem.add_dependency(
|
20
|
-
gem.add_dependency(
|
21
|
-
gem.add_development_dependency(
|
22
|
-
gem.add_development_dependency(
|
23
|
-
gem.add_development_dependency(
|
24
|
-
gem.add_development_dependency(
|
19
|
+
gem.require_paths = ['lib']
|
20
|
+
gem.add_dependency('activerecord')
|
21
|
+
gem.add_dependency('mysql2')
|
22
|
+
gem.add_development_dependency('rspec')
|
23
|
+
gem.add_development_dependency('rake')
|
24
|
+
gem.add_development_dependency('codeclimate-test-reporter')
|
25
|
+
gem.add_development_dependency('reevoocop')
|
25
26
|
end
|
data/spec/lib/config_spec.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
-
require
|
2
|
+
require 'spec_helper'
|
3
3
|
|
4
4
|
describe Slodd::Config do
|
5
5
|
subject { described_class }
|
@@ -8,181 +8,205 @@ describe Slodd::Config do
|
|
8
8
|
subject.reset
|
9
9
|
end
|
10
10
|
|
11
|
-
describe
|
12
|
-
describe
|
13
|
-
it
|
14
|
-
expect(subject.path).to eq
|
11
|
+
describe 'attributes' do
|
12
|
+
describe '.path' do
|
13
|
+
it 'has a default' do
|
14
|
+
expect(subject.path).to eq 'db/schema.rb'
|
15
15
|
end
|
16
16
|
|
17
|
-
it
|
18
|
-
subject.path =
|
19
|
-
expect(subject.path).to eq
|
17
|
+
it 'can be overridden' do
|
18
|
+
subject.path = 'dingdong/schema.rb'
|
19
|
+
expect(subject.path).to eq 'dingdong/schema.rb'
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
|
-
describe
|
23
|
+
describe 'github attrs' do
|
24
24
|
before do
|
25
|
-
subject.github =
|
25
|
+
subject.github = 'errm/awesome_rails_app'
|
26
26
|
end
|
27
27
|
|
28
|
-
describe
|
29
|
-
specify { expect(subject.owner).to eq
|
28
|
+
describe '.owner' do
|
29
|
+
specify { expect(subject.owner).to eq 'errm' }
|
30
30
|
end
|
31
31
|
|
32
|
-
describe
|
33
|
-
specify { expect(subject.repo).to eq
|
32
|
+
describe '.repo' do
|
33
|
+
specify { expect(subject.repo).to eq 'awesome_rails_app' }
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
37
|
-
describe
|
38
|
-
it
|
39
|
-
expect(subject.username).to eq
|
37
|
+
describe '.username' do
|
38
|
+
it 'has a default' do
|
39
|
+
expect(subject.username).to eq 'root'
|
40
40
|
end
|
41
41
|
|
42
|
-
it
|
43
|
-
subject.username =
|
44
|
-
expect(subject.username).to eq
|
42
|
+
it 'can be overridden' do
|
43
|
+
subject.username = 'mysqlusr'
|
44
|
+
expect(subject.username).to eq 'mysqlusr'
|
45
45
|
end
|
46
46
|
end
|
47
47
|
|
48
|
-
describe
|
49
|
-
it
|
48
|
+
describe '.password' do
|
49
|
+
it 'defaults to nil' do
|
50
50
|
expect(subject.password).to be_nil
|
51
51
|
end
|
52
52
|
|
53
|
-
it
|
54
|
-
subject.password =
|
55
|
-
expect(subject.password).to eq
|
53
|
+
it 'can be overridden' do
|
54
|
+
subject.password = 'mysqlpass'
|
55
|
+
expect(subject.password).to eq 'mysqlpass'
|
56
56
|
end
|
57
57
|
end
|
58
58
|
|
59
|
-
describe
|
60
|
-
it
|
59
|
+
describe '.url' do
|
60
|
+
it 'defaults to nil' do
|
61
61
|
expect(subject.url).to be_nil
|
62
62
|
end
|
63
63
|
|
64
|
-
it
|
65
|
-
subject.url =
|
66
|
-
expect(subject.url).to eq
|
64
|
+
it 'can be overridden' do
|
65
|
+
subject.url = 'http://some.site.com/schema.rb'
|
66
|
+
expect(subject.url).to eq 'http://some.site.com/schema.rb'
|
67
67
|
end
|
68
68
|
end
|
69
69
|
|
70
|
-
describe
|
71
|
-
it
|
70
|
+
describe '.fetcher' do
|
71
|
+
it 'defaults to Local' do
|
72
72
|
expect(subject.fetcher.class).to eq Slodd::Local
|
73
73
|
end
|
74
74
|
|
75
|
-
it
|
76
|
-
subject.github =
|
77
|
-
subject.token =
|
75
|
+
it 'returns Github if details are supplied' do
|
76
|
+
subject.github = 'errm/awesome_rails_app'
|
77
|
+
subject.token = 'oauth token'
|
78
78
|
expect(subject.fetcher.class).to eq Slodd::Github
|
79
79
|
end
|
80
80
|
|
81
|
-
it
|
82
|
-
subject.github =
|
81
|
+
it 'rasies an argument error if no github token is supplied' do
|
82
|
+
subject.github = 'errm/awesome_rails_app'
|
83
83
|
expect { subject.fetcher }.to raise_error(ArgumentError)
|
84
84
|
end
|
85
85
|
|
86
|
-
it
|
87
|
-
subject.github =
|
88
|
-
subject.token =
|
86
|
+
it 'rasies an argument error if the github string is malformed' do
|
87
|
+
subject.github = 'errm'
|
88
|
+
subject.token = 'oauth token'
|
89
89
|
expect { subject.fetcher }.to raise_error(ArgumentError)
|
90
90
|
end
|
91
91
|
|
92
|
-
it
|
93
|
-
subject.url =
|
92
|
+
it 'returns Http if a url is supplied' do
|
93
|
+
subject.url = 'http://some.url/schema.rb'
|
94
94
|
expect(subject.fetcher.class).to eq Slodd::Http
|
95
95
|
end
|
96
96
|
end
|
97
97
|
|
98
|
-
describe
|
99
|
-
context
|
100
|
-
it
|
101
|
-
subject.github =
|
102
|
-
subject.token =
|
103
|
-
subject.ref =
|
98
|
+
describe '.attributes' do
|
99
|
+
context 'Github' do
|
100
|
+
it 'returns all the arguments needed by github' do
|
101
|
+
subject.github = 'errm/awesome_rails_app'
|
102
|
+
subject.token = 'oauth token'
|
103
|
+
subject.ref = 'my-awesome-branch'
|
104
104
|
attrs = {
|
105
|
-
owner:
|
106
|
-
repo:
|
107
|
-
token:
|
108
|
-
path:
|
109
|
-
ref:
|
105
|
+
owner: 'errm',
|
106
|
+
repo: 'awesome_rails_app',
|
107
|
+
token: 'oauth token',
|
108
|
+
path: 'db/schema.rb',
|
109
|
+
ref: 'my-awesome-branch',
|
110
110
|
}
|
111
111
|
expect(subject.attributes).to eq attrs
|
112
112
|
end
|
113
113
|
end
|
114
114
|
|
115
|
-
context
|
116
|
-
it
|
115
|
+
context 'Local' do
|
116
|
+
it 'returns all the arguments needed by Local' do
|
117
117
|
attrs = {
|
118
|
-
path:
|
118
|
+
path: 'db/schema.rb',
|
119
119
|
}
|
120
120
|
expect(subject.attributes).to eq attrs
|
121
121
|
end
|
122
122
|
end
|
123
123
|
|
124
|
-
context
|
125
|
-
it
|
126
|
-
subject.url =
|
124
|
+
context 'Http' do
|
125
|
+
it 'returns all the arguments needed by Http' do
|
126
|
+
subject.url = 'http://some.url.com/db/schema.rb'
|
127
127
|
attrs = {
|
128
|
-
path:
|
129
|
-
url:
|
128
|
+
path: 'db/schema.rb',
|
129
|
+
url: 'http://some.url.com/db/schema.rb',
|
130
130
|
}
|
131
131
|
expect(subject.attributes).to eq attrs
|
132
132
|
end
|
133
133
|
end
|
134
134
|
end
|
135
135
|
|
136
|
-
describe
|
137
|
-
it
|
136
|
+
describe '.databases' do
|
137
|
+
it 'defaults to empty array' do
|
138
138
|
expect(subject.databases).to eq []
|
139
139
|
end
|
140
140
|
|
141
|
-
it
|
142
|
-
subject.databases =
|
141
|
+
it 'is an array of names' do
|
142
|
+
subject.databases = 'db1 db2 db3'
|
143
143
|
expect(subject.databases).to eq %w(db1 db2 db3)
|
144
144
|
end
|
145
145
|
|
146
|
-
it
|
147
|
-
subject.databases =
|
148
|
-
expect(subject.databases).to eq [
|
146
|
+
it 'is an array of one name' do
|
147
|
+
subject.databases = 'db1'
|
148
|
+
expect(subject.databases).to eq ['db1']
|
149
149
|
end
|
150
150
|
end
|
151
151
|
|
152
|
-
describe
|
153
|
-
context
|
154
|
-
it
|
152
|
+
describe '.database_settings' do
|
153
|
+
context 'without a password' do
|
154
|
+
it 'returns the settings' do
|
155
155
|
settings = {
|
156
|
-
adapter:
|
157
|
-
host:
|
158
|
-
username:
|
156
|
+
adapter: 'mysql2',
|
157
|
+
host: 'localhost',
|
158
|
+
username: 'root',
|
159
159
|
}
|
160
160
|
expect(subject.database_settings).to eq settings
|
161
161
|
end
|
162
162
|
end
|
163
163
|
|
164
|
-
context
|
165
|
-
it
|
166
|
-
subject.password =
|
164
|
+
context 'with a password' do
|
165
|
+
it 'returns the settings' do
|
166
|
+
subject.password = 'brian'
|
167
167
|
settings = {
|
168
|
-
adapter:
|
169
|
-
host:
|
170
|
-
username:
|
171
|
-
password:
|
168
|
+
adapter: 'mysql2',
|
169
|
+
host: 'localhost',
|
170
|
+
username: 'root',
|
171
|
+
password: 'brian',
|
172
172
|
}
|
173
173
|
expect(subject.database_settings).to eq settings
|
174
174
|
end
|
175
175
|
end
|
176
|
+
|
177
|
+
context 'with a database url in the environment' do
|
178
|
+
before do
|
179
|
+
ENV['DATABASE_URL'] = 'mysql2://nova:sekret@127.0.0.1/foo_bar'
|
180
|
+
end
|
181
|
+
|
182
|
+
after do
|
183
|
+
ENV['DATABASE_URL'] = nil
|
184
|
+
end
|
185
|
+
|
186
|
+
it 'returns the settings' do
|
187
|
+
settings = {
|
188
|
+
adapter: 'mysql2',
|
189
|
+
host: '127.0.0.1',
|
190
|
+
username: 'nova',
|
191
|
+
password: 'sekret',
|
192
|
+
}
|
193
|
+
expect(subject.database_settings).to eq settings
|
194
|
+
end
|
195
|
+
|
196
|
+
it 'sets the database' do
|
197
|
+
expect(subject.databases).to eq ['foo_bar']
|
198
|
+
end
|
199
|
+
end
|
176
200
|
end
|
177
201
|
|
178
|
-
describe
|
179
|
-
it
|
180
|
-
expect(subject.host).to eq
|
202
|
+
describe '.host' do
|
203
|
+
it 'defaults to localhost' do
|
204
|
+
expect(subject.host).to eq 'localhost'
|
181
205
|
end
|
182
206
|
|
183
|
-
it
|
184
|
-
subject.host =
|
185
|
-
expect(subject.host).to eq
|
207
|
+
it 'it can be overridden' do
|
208
|
+
subject.host = 'db1.something.com'
|
209
|
+
expect(subject.host).to eq 'db1.something.com'
|
186
210
|
end
|
187
211
|
end
|
188
212
|
end
|
data/spec/lib/gitub_spec.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
-
require
|
2
|
+
require 'spec_helper'
|
3
3
|
|
4
4
|
describe Slodd::Github do
|
5
|
-
let(:owner) {
|
6
|
-
let(:repo) {
|
7
|
-
let(:path) {
|
8
|
-
let(:token) {
|
5
|
+
let(:owner) { 'errm' }
|
6
|
+
let(:repo) { 'awesome_rails_app' }
|
7
|
+
let(:path) { 'database/schema.rb' }
|
8
|
+
let(:token) { 'secret-oauth-token' }
|
9
9
|
let(:ref) { nil }
|
10
10
|
|
11
11
|
let(:schema) { double(read: nil) }
|
@@ -16,7 +16,7 @@ describe Slodd::Github do
|
|
16
16
|
repo: repo,
|
17
17
|
path: path,
|
18
18
|
token: token,
|
19
|
-
ref: ref
|
19
|
+
ref: ref,
|
20
20
|
)
|
21
21
|
end
|
22
22
|
|
@@ -24,8 +24,8 @@ describe Slodd::Github do
|
|
24
24
|
"https://api.github.com/repos/#{owner}/#{repo}/contents/#{path}"
|
25
25
|
end
|
26
26
|
|
27
|
-
describe
|
28
|
-
it
|
27
|
+
describe '#schema' do
|
28
|
+
it 'hits the correct url' do
|
29
29
|
allow(subject).to receive(:open) do |url, _|
|
30
30
|
expect(url).to eq(expected_url)
|
31
31
|
schema
|
@@ -34,10 +34,10 @@ describe Slodd::Github do
|
|
34
34
|
subject.schema
|
35
35
|
end
|
36
36
|
|
37
|
-
context
|
38
|
-
let(:ref) {
|
37
|
+
context 'with a ref' do
|
38
|
+
let(:ref) { 'exciting-feature-branch' }
|
39
39
|
|
40
|
-
it
|
40
|
+
it 'hits a url including the ref param' do
|
41
41
|
allow(subject).to receive(:open) do |url, _|
|
42
42
|
expect(url).to eq(expected_url + "?ref=#{ref}")
|
43
43
|
schema
|
@@ -47,28 +47,28 @@ describe Slodd::Github do
|
|
47
47
|
end
|
48
48
|
end
|
49
49
|
|
50
|
-
it
|
50
|
+
it 'uses the correct token' do
|
51
51
|
allow(subject).to receive(:open) do |_, headers|
|
52
|
-
expect(headers[
|
52
|
+
expect(headers['Authorization']).to eq "token #{token}"
|
53
53
|
schema
|
54
54
|
end
|
55
55
|
|
56
56
|
subject.schema
|
57
57
|
end
|
58
58
|
|
59
|
-
it
|
59
|
+
it 'requests the raw mediatype' do
|
60
60
|
allow(subject).to receive(:open) do |_, headers|
|
61
|
-
expect(headers[
|
61
|
+
expect(headers['Accept']).to eq 'application/vnd.github.3.raw'
|
62
62
|
schema
|
63
63
|
end
|
64
64
|
|
65
65
|
subject.schema
|
66
66
|
end
|
67
67
|
|
68
|
-
it
|
68
|
+
it 'returns the schema' do
|
69
69
|
allow(subject).to receive(:open).and_return(schema)
|
70
|
-
allow(schema).to receive(:read).and_return(
|
71
|
-
expect(subject.schema).to eq
|
70
|
+
allow(schema).to receive(:read).and_return('the schema')
|
71
|
+
expect(subject.schema).to eq 'the schema'
|
72
72
|
end
|
73
73
|
end
|
74
74
|
end
|
data/spec/lib/http_spec.rb
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
-
require
|
2
|
+
require 'spec_helper'
|
3
3
|
|
4
4
|
describe Slodd::Http do
|
5
5
|
let(:url) { double }
|
6
|
-
let(:schema_file) { double(read:
|
6
|
+
let(:schema_file) { double(read: 'the schema') }
|
7
7
|
subject { described_class.new(url: url) }
|
8
8
|
|
9
|
-
describe
|
10
|
-
it
|
9
|
+
describe '#schema' do
|
10
|
+
it 'downloads the schema from the url given' do
|
11
11
|
expect(subject).to receive(:open).with(url).and_return(schema_file)
|
12
|
-
expect(subject.schema).to eq
|
12
|
+
expect(subject.schema).to eq 'the schema'
|
13
13
|
end
|
14
14
|
end
|
15
15
|
end
|
data/spec/lib/local_spec.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
-
require
|
2
|
+
require 'spec_helper'
|
3
3
|
|
4
4
|
describe Slodd::Local do
|
5
5
|
subject { described_class.new(path: schema_path) }
|
6
6
|
|
7
|
-
describe
|
8
|
-
it
|
7
|
+
describe '#schema' do
|
8
|
+
it 'reads the file' do
|
9
9
|
expect(subject.schema).to eq File.read(schema_path)
|
10
10
|
end
|
11
11
|
end
|
data/spec/lib/runner_spec.rb
CHANGED
@@ -1,20 +1,20 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
-
require
|
2
|
+
require 'spec_helper'
|
3
3
|
|
4
4
|
describe Slodd::Runner do
|
5
5
|
subject { described_class }
|
6
6
|
|
7
|
-
describe
|
7
|
+
describe '#run' do
|
8
8
|
before do
|
9
9
|
Slodd::Config.path = schema_path
|
10
|
-
Slodd::Config.databases =
|
10
|
+
Slodd::Config.databases = 'slodd_test'
|
11
11
|
end
|
12
12
|
|
13
13
|
after do
|
14
14
|
Slodd::Config.reset
|
15
15
|
end
|
16
16
|
|
17
|
-
it
|
17
|
+
it 'creates the database ready for testing' do
|
18
18
|
output = capture_stdout do
|
19
19
|
subject.run!
|
20
20
|
end
|
@@ -22,10 +22,10 @@ describe Slodd::Runner do
|
|
22
22
|
expect(output).to match(/create_database\(slodd_test\)/)
|
23
23
|
|
24
24
|
expect(Test.count).to eq 0
|
25
|
-
Test.create(name:
|
25
|
+
Test.create(name: 'James')
|
26
26
|
|
27
27
|
expect(Test.count).to eq 1
|
28
|
-
expect(Test.last.name).to eq
|
28
|
+
expect(Test.last.name).to eq 'James'
|
29
29
|
expect(`mysql -uroot -e "show databases;"`).to match(/slodd_test/)
|
30
30
|
|
31
31
|
capture_stdout do
|
@@ -35,12 +35,12 @@ describe Slodd::Runner do
|
|
35
35
|
expect(Test.count).to eq 0
|
36
36
|
end
|
37
37
|
|
38
|
-
context
|
38
|
+
context 'with multiple databases' do
|
39
39
|
before do
|
40
|
-
Slodd::Config.databases =
|
40
|
+
Slodd::Config.databases = 'slodd_test slodd_test_2'
|
41
41
|
end
|
42
42
|
|
43
|
-
it
|
43
|
+
it 'creates both databases' do
|
44
44
|
output = capture_stdout do
|
45
45
|
subject.run!
|
46
46
|
end
|
@@ -54,13 +54,13 @@ describe Slodd::Runner do
|
|
54
54
|
end
|
55
55
|
end
|
56
56
|
|
57
|
-
context
|
57
|
+
context 'when something is failing' do
|
58
58
|
before do
|
59
59
|
allow(ActiveRecord::Base).to receive(:establish_connection)
|
60
|
-
.and_raise(Mysql2::Error,
|
60
|
+
.and_raise(Mysql2::Error, 'mysql error')
|
61
61
|
end
|
62
62
|
|
63
|
-
it
|
63
|
+
it 'ouputs a usefull message to stderr' do
|
64
64
|
message = capture_stderr do
|
65
65
|
subject.run!
|
66
66
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,15 +1,22 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
-
require
|
2
|
+
require 'simplecov'
|
3
|
+
require 'codeclimate-test-reporter'
|
4
|
+
|
5
|
+
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
|
6
|
+
SimpleCov::Formatter::HTMLFormatter,
|
7
|
+
CodeClimate::TestReporter::Formatter
|
8
|
+
]
|
9
|
+
|
3
10
|
SimpleCov.minimum_coverage 100
|
4
11
|
SimpleCov.start
|
5
12
|
|
6
|
-
require
|
7
|
-
require
|
13
|
+
require 'slodd'
|
14
|
+
require 'stringio'
|
8
15
|
|
9
16
|
RSpec.configure do |config|
|
10
17
|
config.run_all_when_everything_filtered = true
|
11
18
|
config.filter_run :focus
|
12
|
-
config.order =
|
19
|
+
config.order = 'random'
|
13
20
|
end
|
14
21
|
|
15
22
|
module Slodd
|
@@ -49,5 +56,5 @@ ensure
|
|
49
56
|
end
|
50
57
|
|
51
58
|
def schema_path
|
52
|
-
File.join(File.dirname(__FILE__),
|
59
|
+
File.join(File.dirname(__FILE__), 'support', 'schema.rb')
|
53
60
|
end
|
data/spec/support/schema.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: slodd
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ed Robinson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-11-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -67,7 +67,7 @@ dependencies:
|
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
70
|
+
name: codeclimate-test-reporter
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
73
|
- - ">="
|
@@ -81,7 +81,7 @@ dependencies:
|
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
|
-
name:
|
84
|
+
name: reevoocop
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
87
|
- - ">="
|
@@ -105,7 +105,6 @@ extra_rdoc_files: []
|
|
105
105
|
files:
|
106
106
|
- ".gitignore"
|
107
107
|
- ".rspec"
|
108
|
-
- ".rubocop.yml"
|
109
108
|
- ".ruby-version"
|
110
109
|
- ".travis.yml"
|
111
110
|
- Gemfile
|
@@ -147,7 +146,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
147
146
|
version: '0'
|
148
147
|
requirements: []
|
149
148
|
rubyforge_project:
|
150
|
-
rubygems_version: 2.2.
|
149
|
+
rubygems_version: 2.2.5
|
151
150
|
signing_key:
|
152
151
|
specification_version: 4
|
153
152
|
summary: Schema Loading On Dependent Databases
|