slodd 0.1.6 → 0.1.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +3 -4
- data/Gemfile +1 -1
- data/Rakefile +3 -3
- data/bin/gurl +6 -6
- data/bin/slodd +11 -11
- data/lib/slodd.rb +6 -6
- data/lib/slodd/config.rb +11 -11
- data/lib/slodd/github.rb +3 -3
- data/lib/slodd/http.rb +1 -1
- data/lib/slodd/runner.rb +3 -3
- data/lib/slodd/version.rb +1 -1
- data/slodd.gemspec +16 -16
- data/spec/lib/config_spec.rb +97 -97
- data/spec/lib/gitub_spec.rb +17 -17
- 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 +6 -6
- data/spec/support/schema.rb +2 -2
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 41ea0b47a25d03552f7460b8dfec224c00a468db
|
4
|
+
data.tar.gz: 8a8e3fcd60153e2d5751a861f76b78bde6d36046
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6ebe9b9e37493ffab87582baa12a1d7ec4682e5e6be00da0c2041934c9ac78bd775fae669214bc8da8e7be2a5c5a75cc50f57930afa9f247ea3ea9a0d7e67ff8
|
7
|
+
data.tar.gz: 2fd6c384321317eae5e7bfc8d38e457781d0be64ac3eecf216a90b402ed64b734ec30007fa9ec4d5faf5cb053a5ac6391dc29d7013acf8640c86a546efb7b332
|
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
data/Rakefile
CHANGED
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,17 +1,17 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
-
require
|
3
|
-
require
|
2
|
+
require "active_support/core_ext/module/attribute_accessors"
|
3
|
+
require "uri"
|
4
4
|
|
5
5
|
module Slodd
|
6
6
|
module Config
|
7
7
|
mattr_accessor :path, :github, :username, :password,
|
8
|
-
|
8
|
+
:host, :url, :token, :ref
|
9
9
|
mattr_writer :databases
|
10
10
|
|
11
11
|
def self.defaults
|
12
|
-
self.path =
|
13
|
-
self.username =
|
14
|
-
self.host =
|
12
|
+
self.path = "db/schema.rb"
|
13
|
+
self.username = "root"
|
14
|
+
self.host = "localhost"
|
15
15
|
self.databases = nil
|
16
16
|
end
|
17
17
|
|
@@ -27,11 +27,11 @@ module Slodd
|
|
27
27
|
end
|
28
28
|
|
29
29
|
def self.owner
|
30
|
-
github.split(
|
30
|
+
github.split("/")[0] if github
|
31
31
|
end
|
32
32
|
|
33
33
|
def self.repo
|
34
|
-
github.split(
|
34
|
+
github.split("/")[1] if github
|
35
35
|
end
|
36
36
|
|
37
37
|
def self.fetcher
|
@@ -74,12 +74,12 @@ module Slodd
|
|
74
74
|
end
|
75
75
|
|
76
76
|
def self.database_uri
|
77
|
-
return unless ENV[
|
78
|
-
@_database_uri ||= URI.parse(ENV[
|
77
|
+
return unless ENV["DATABASE_URL"]
|
78
|
+
@_database_uri ||= URI.parse(ENV["DATABASE_URL"])
|
79
79
|
end
|
80
80
|
|
81
81
|
def self.settings_from_args
|
82
|
-
settings = { adapter:
|
82
|
+
settings = { adapter: "mysql2", host: host, username: username }
|
83
83
|
settings.merge!(password: password) if password
|
84
84
|
settings
|
85
85
|
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
|
@@ -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,26 +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
|
5
|
-
require
|
4
|
+
require "slodd/version"
|
5
|
+
require "English"
|
6
6
|
|
7
7
|
Gem::Specification.new do |gem|
|
8
|
-
gem.name =
|
8
|
+
gem.name = "slodd"
|
9
9
|
gem.version = Slodd::VERSION
|
10
|
-
gem.authors = [
|
11
|
-
gem.email = [
|
12
|
-
gem.description =
|
13
|
-
gem.summary =
|
14
|
-
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"
|
15
15
|
|
16
16
|
gem.files = `git ls-files`.split($RS)
|
17
17
|
gem.executables = gem.files.grep(/^bin\//).map { |f| File.basename(f) }
|
18
18
|
gem.test_files = gem.files.grep(/^(test|spec|features)\//)
|
19
|
-
gem.require_paths = [
|
20
|
-
gem.add_dependency(
|
21
|
-
gem.add_dependency(
|
22
|
-
gem.add_development_dependency(
|
23
|
-
gem.add_development_dependency(
|
24
|
-
gem.add_development_dependency(
|
25
|
-
gem.add_development_dependency(
|
19
|
+
gem.require_paths = ["lib"]
|
20
|
+
gem.add_dependency("activerecord", "~> 3.2.22")
|
21
|
+
gem.add_dependency("mysql2", "~> 0.3.10")
|
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")
|
26
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,205 +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
176
|
|
177
|
-
context
|
177
|
+
context "with a database url in the environment" do
|
178
178
|
before do
|
179
|
-
ENV[
|
179
|
+
ENV["DATABASE_URL"] = "mysql2://nova:sekret@127.0.0.1/foo_bar"
|
180
180
|
end
|
181
181
|
|
182
182
|
after do
|
183
|
-
ENV[
|
183
|
+
ENV["DATABASE_URL"] = nil
|
184
184
|
end
|
185
185
|
|
186
|
-
it
|
186
|
+
it "returns the settings" do
|
187
187
|
settings = {
|
188
|
-
adapter:
|
189
|
-
host:
|
190
|
-
username:
|
191
|
-
password:
|
188
|
+
adapter: "mysql2",
|
189
|
+
host: "127.0.0.1",
|
190
|
+
username: "nova",
|
191
|
+
password: "sekret",
|
192
192
|
}
|
193
193
|
expect(subject.database_settings).to eq settings
|
194
194
|
end
|
195
195
|
|
196
|
-
it
|
197
|
-
expect(subject.databases).to eq [
|
196
|
+
it "sets the database" do
|
197
|
+
expect(subject.databases).to eq ["foo_bar"]
|
198
198
|
end
|
199
199
|
end
|
200
200
|
end
|
201
201
|
|
202
|
-
describe
|
203
|
-
it
|
204
|
-
expect(subject.host).to eq
|
202
|
+
describe ".host" do
|
203
|
+
it "defaults to localhost" do
|
204
|
+
expect(subject.host).to eq "localhost"
|
205
205
|
end
|
206
206
|
|
207
|
-
it
|
208
|
-
subject.host =
|
209
|
-
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"
|
210
210
|
end
|
211
211
|
end
|
212
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) }
|
@@ -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,6 +1,6 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
-
require
|
3
|
-
require
|
2
|
+
require "simplecov"
|
3
|
+
require "codeclimate-test-reporter"
|
4
4
|
|
5
5
|
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
|
6
6
|
SimpleCov::Formatter::HTMLFormatter,
|
@@ -10,13 +10,13 @@ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
|
|
10
10
|
SimpleCov.minimum_coverage 100
|
11
11
|
SimpleCov.start
|
12
12
|
|
13
|
-
require
|
14
|
-
require
|
13
|
+
require "slodd"
|
14
|
+
require "stringio"
|
15
15
|
|
16
16
|
RSpec.configure do |config|
|
17
17
|
config.run_all_when_everything_filtered = true
|
18
18
|
config.filter_run :focus
|
19
|
-
config.order =
|
19
|
+
config.order = "random"
|
20
20
|
end
|
21
21
|
|
22
22
|
module Slodd
|
@@ -56,5 +56,5 @@ ensure
|
|
56
56
|
end
|
57
57
|
|
58
58
|
def schema_path
|
59
|
-
File.join(File.dirname(__FILE__),
|
59
|
+
File.join(File.dirname(__FILE__), "support", "schema.rb")
|
60
60
|
end
|
data/spec/support/schema.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
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.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ed Robinson
|
@@ -28,16 +28,16 @@ dependencies:
|
|
28
28
|
name: mysql2
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: 0.3.10
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
40
|
+
version: 0.3.10
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rspec
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|