schema_expectations 0.0.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +3 -0
- data/.travis.yml +19 -5
- data/Appraisals +33 -0
- data/CHANGELOG.md +17 -1
- data/README.md +4 -0
- data/Rakefile +12 -0
- data/gemfiles/activerecord_3.1.gemfile +7 -0
- data/gemfiles/activerecord_3.2.gemfile +7 -0
- data/gemfiles/activerecord_4.0.gemfile +7 -0
- data/gemfiles/activerecord_4.1.gemfile +7 -0
- data/gemfiles/activerecord_4.2.gemfile +7 -0
- data/gemfiles/default.gemfile +5 -0
- data/gemfiles/rspec_3.0.gemfile +7 -0
- data/gemfiles/rspec_3.1.gemfile +7 -0
- data/gemfiles/rspec_3.2.gemfile +7 -0
- data/lib/schema_expectations/active_record/column_reflector.rb +92 -0
- data/lib/schema_expectations/active_record/validation_reflector.rb +59 -0
- data/lib/schema_expectations/config.rb +25 -0
- data/lib/schema_expectations/rspec_matchers/validate_schema_nullable.rb +49 -58
- data/lib/schema_expectations/util.rb +9 -0
- data/lib/schema_expectations/version.rb +1 -1
- data/lib/schema_expectations.rb +1 -0
- data/schema_expectations.gemspec +12 -3
- data/spec/db/database.yml +13 -0
- data/spec/lib/schema_expectations/active_record/column_reflector_spec.rb +150 -0
- data/spec/lib/schema_expectations/active_record/validation_reflector_spec.rb +62 -0
- data/spec/lib/schema_expectations/config_spec.rb +22 -0
- data/spec/lib/schema_expectations/rspec_matchers/validate_schema_nullable_spec.rb +260 -77
- data/spec/lib/schema_expectations/util_spec.rb +16 -0
- data/spec/meta_spec.rb +44 -0
- data/spec/spec_helper.rb +11 -2
- data/spec/support/active_record.rb +34 -12
- data/spec/support/active_record_helpers.rb +51 -0
- data/spec/support/gem_filters.rb +6 -0
- metadata +162 -10
data/spec/spec_helper.rb
CHANGED
@@ -1,5 +1,14 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
if !ENV['BUNDLE_GEMFILE'] || ENV['BUNDLE_GEMFILE'] =~ /default.gemfile\z/
|
2
|
+
if ENV['CI']
|
3
|
+
require 'codeclimate-test-reporter'
|
4
|
+
CodeClimate::TestReporter.start
|
5
|
+
else
|
6
|
+
require 'simplecov'
|
7
|
+
SimpleCov.start do
|
8
|
+
add_filter 'vendor'
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
3
12
|
|
4
13
|
require 'rspec'
|
5
14
|
require 'pry'
|
@@ -1,25 +1,47 @@
|
|
1
|
-
require '
|
1
|
+
require 'yaml'
|
2
|
+
require_relative 'active_record_helpers'
|
2
3
|
|
3
|
-
|
4
|
-
|
4
|
+
RSpec.configure do |config|
|
5
|
+
DATABASE_YAML_FILE = File.join(File.dirname(__FILE__), '../db/database.yml')
|
6
|
+
DATABASE_YAML = YAML::load(File.open(DATABASE_YAML_FILE))
|
7
|
+
DB = (ENV['DB'] || 'sqlite3').to_sym
|
5
8
|
|
6
|
-
|
9
|
+
config.before(:suite) do
|
10
|
+
require 'active_record'
|
7
11
|
|
8
|
-
|
9
|
-
ActiveRecord::Base.connection
|
12
|
+
ActiveRecord::Base.configurations = DATABASE_YAML
|
10
13
|
end
|
11
14
|
|
12
|
-
|
13
|
-
|
15
|
+
DATABASE_YAML.keys.each do |db|
|
16
|
+
config.before(:all, active_record: true, db.to_sym => true) do
|
17
|
+
connect_to_database! db.to_sym
|
18
|
+
end
|
19
|
+
end
|
14
20
|
|
15
|
-
RSpec.configure do |config|
|
16
21
|
config.before(:each, active_record: true) do |example|
|
17
|
-
|
18
|
-
|
22
|
+
require 'database_cleaner'
|
23
|
+
|
24
|
+
already_connected = example.metadata.detect do |meta, value|
|
25
|
+
value && DATABASE_YAML.keys.include?(meta.to_s)
|
26
|
+
end
|
27
|
+
connect_to_database! DB unless already_connected
|
28
|
+
|
29
|
+
DatabaseCleaner.strategy = :transaction
|
30
|
+
DatabaseCleaner.start
|
19
31
|
end
|
20
32
|
|
21
33
|
config.after(:each, active_record: true) do
|
22
|
-
|
34
|
+
DatabaseCleaner.clean
|
35
|
+
|
36
|
+
# mysql can't do tables in transactions properly
|
37
|
+
db_config = ActiveRecord::Base.connection_config
|
38
|
+
if db_config[:adapter] == 'mysql2'
|
39
|
+
ActiveRecord::Base.connection.drop_database(db_config[:database])
|
40
|
+
ActiveRecord::Base.connection.create_database(db_config[:database], db_config)
|
41
|
+
execute "USE #{db_config[:database]}"
|
42
|
+
end
|
43
|
+
|
44
|
+
ActiveRecord::Base.connection.schema_cache.clear!
|
23
45
|
end
|
24
46
|
|
25
47
|
config.include ActiveRecordHelpers, active_record: true
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'active_support/core_ext/hash/keys'
|
2
|
+
|
3
|
+
module ActiveRecordHelpers
|
4
|
+
extend Forwardable
|
5
|
+
|
6
|
+
CONNECTION_DELEGATES = %i(create_table execute)
|
7
|
+
|
8
|
+
def connection
|
9
|
+
ActiveRecord::Base.connection
|
10
|
+
end
|
11
|
+
|
12
|
+
delegate CONNECTION_DELEGATES => :connection
|
13
|
+
|
14
|
+
def setup_postgresql!
|
15
|
+
ActiveRecord::Base.connection.execute <<-SQL
|
16
|
+
CREATE EXTENSION "uuid-ossp";
|
17
|
+
SQL
|
18
|
+
end
|
19
|
+
|
20
|
+
# see https://github.com/pat/combustion/blob/master/lib/combustion/database.rb
|
21
|
+
def connect_to_database!(db)
|
22
|
+
db_config = ActiveRecord::Base.configurations[db.to_s].symbolize_keys
|
23
|
+
|
24
|
+
if ActiveRecord::Base.connected?
|
25
|
+
return if ActiveRecord::Base.connection_config == db_config
|
26
|
+
ActiveRecord::Base.remove_connection
|
27
|
+
end
|
28
|
+
|
29
|
+
case db_config[:adapter]
|
30
|
+
when 'sqlite3'
|
31
|
+
fail 'only support sqlite3 in-memory' unless db_config[:database] == ':memory:'
|
32
|
+
when 'postgresql'
|
33
|
+
ActiveRecord::Base.establish_connection(db_config.merge(database: 'postgres'))
|
34
|
+
ActiveRecord::Base.connection.drop_database(db_config[:database])
|
35
|
+
ActiveRecord::Base.connection.create_database(db_config[:database], db_config)
|
36
|
+
ActiveRecord::Base.remove_connection
|
37
|
+
when 'mysql2'
|
38
|
+
require 'mysql2'
|
39
|
+
ActiveRecord::Base.establish_connection(db_config.merge(database: nil))
|
40
|
+
ActiveRecord::Base.connection.drop_database(db_config[:database])
|
41
|
+
ActiveRecord::Base.connection.create_database(db_config[:database], db_config)
|
42
|
+
ActiveRecord::Base.remove_connection
|
43
|
+
end
|
44
|
+
|
45
|
+
ActiveRecord::Base.establish_connection(db)
|
46
|
+
ActiveRecord::Base.connection # triggers connection to actually happen
|
47
|
+
fail "failed to connect to #{db_config.inspect}" unless ActiveRecord::Base.connected?
|
48
|
+
|
49
|
+
setup_postgresql! if db_config[:adapter] == 'postgresql'
|
50
|
+
end
|
51
|
+
end
|
metadata
CHANGED
@@ -1,29 +1,75 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: schema_expectations
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Emma Borhanian
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-02-
|
11
|
+
date: 2015-02-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '3.1'
|
20
|
+
- - "<"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '4.3'
|
20
23
|
type: :runtime
|
21
24
|
prerelease: false
|
22
25
|
version_requirements: !ruby/object:Gem::Requirement
|
23
26
|
requirements:
|
24
|
-
- - "
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '3.1'
|
30
|
+
- - "<"
|
25
31
|
- !ruby/object:Gem::Version
|
26
|
-
version: '4.
|
32
|
+
version: '4.3'
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: activesupport
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '3.1'
|
40
|
+
- - "<"
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: '4.3'
|
43
|
+
type: :runtime
|
44
|
+
prerelease: false
|
45
|
+
version_requirements: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - ">="
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '3.1'
|
50
|
+
- - "<"
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: '4.3'
|
53
|
+
- !ruby/object:Gem::Dependency
|
54
|
+
name: rspec
|
55
|
+
requirement: !ruby/object:Gem::Requirement
|
56
|
+
requirements:
|
57
|
+
- - ">="
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: '3.0'
|
60
|
+
- - "<"
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '3.3'
|
63
|
+
type: :development
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '3.0'
|
70
|
+
- - "<"
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: '3.3'
|
27
73
|
- !ruby/object:Gem::Dependency
|
28
74
|
name: pry
|
29
75
|
requirement: !ruby/object:Gem::Requirement
|
@@ -67,7 +113,7 @@ dependencies:
|
|
67
113
|
- !ruby/object:Gem::Version
|
68
114
|
version: 0.8.7
|
69
115
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
116
|
+
name: wwtd
|
71
117
|
requirement: !ruby/object:Gem::Requirement
|
72
118
|
requirements:
|
73
119
|
- - ">="
|
@@ -81,19 +127,53 @@ dependencies:
|
|
81
127
|
- !ruby/object:Gem::Version
|
82
128
|
version: '0'
|
83
129
|
- !ruby/object:Gem::Dependency
|
84
|
-
name:
|
130
|
+
name: appraisal
|
85
131
|
requirement: !ruby/object:Gem::Requirement
|
86
132
|
requirements:
|
87
133
|
- - "~>"
|
88
134
|
- !ruby/object:Gem::Version
|
89
|
-
version: '
|
135
|
+
version: '1.0'
|
90
136
|
type: :development
|
91
137
|
prerelease: false
|
92
138
|
version_requirements: !ruby/object:Gem::Requirement
|
93
139
|
requirements:
|
94
140
|
- - "~>"
|
95
141
|
- !ruby/object:Gem::Version
|
96
|
-
version: '
|
142
|
+
version: '1.0'
|
143
|
+
- !ruby/object:Gem::Dependency
|
144
|
+
name: codeclimate-test-reporter
|
145
|
+
requirement: !ruby/object:Gem::Requirement
|
146
|
+
requirements:
|
147
|
+
- - "~>"
|
148
|
+
- !ruby/object:Gem::Version
|
149
|
+
version: '0.4'
|
150
|
+
- - ">="
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: 0.4.6
|
153
|
+
type: :development
|
154
|
+
prerelease: false
|
155
|
+
version_requirements: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - "~>"
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: '0.4'
|
160
|
+
- - ">="
|
161
|
+
- !ruby/object:Gem::Version
|
162
|
+
version: 0.4.6
|
163
|
+
- !ruby/object:Gem::Dependency
|
164
|
+
name: simplecov
|
165
|
+
requirement: !ruby/object:Gem::Requirement
|
166
|
+
requirements:
|
167
|
+
- - ">="
|
168
|
+
- !ruby/object:Gem::Version
|
169
|
+
version: '0'
|
170
|
+
type: :development
|
171
|
+
prerelease: false
|
172
|
+
version_requirements: !ruby/object:Gem::Requirement
|
173
|
+
requirements:
|
174
|
+
- - ">="
|
175
|
+
- !ruby/object:Gem::Version
|
176
|
+
version: '0'
|
97
177
|
- !ruby/object:Gem::Dependency
|
98
178
|
name: guard-rspec
|
99
179
|
requirement: !ruby/object:Gem::Requirement
|
@@ -122,6 +202,48 @@ dependencies:
|
|
122
202
|
- - "~>"
|
123
203
|
- !ruby/object:Gem::Version
|
124
204
|
version: '1.3'
|
205
|
+
- !ruby/object:Gem::Dependency
|
206
|
+
name: pg
|
207
|
+
requirement: !ruby/object:Gem::Requirement
|
208
|
+
requirements:
|
209
|
+
- - "~>"
|
210
|
+
- !ruby/object:Gem::Version
|
211
|
+
version: '0.18'
|
212
|
+
type: :development
|
213
|
+
prerelease: false
|
214
|
+
version_requirements: !ruby/object:Gem::Requirement
|
215
|
+
requirements:
|
216
|
+
- - "~>"
|
217
|
+
- !ruby/object:Gem::Version
|
218
|
+
version: '0.18'
|
219
|
+
- !ruby/object:Gem::Dependency
|
220
|
+
name: mysql2
|
221
|
+
requirement: !ruby/object:Gem::Requirement
|
222
|
+
requirements:
|
223
|
+
- - "~>"
|
224
|
+
- !ruby/object:Gem::Version
|
225
|
+
version: 0.3.18
|
226
|
+
type: :development
|
227
|
+
prerelease: false
|
228
|
+
version_requirements: !ruby/object:Gem::Requirement
|
229
|
+
requirements:
|
230
|
+
- - "~>"
|
231
|
+
- !ruby/object:Gem::Version
|
232
|
+
version: 0.3.18
|
233
|
+
- !ruby/object:Gem::Dependency
|
234
|
+
name: database_cleaner
|
235
|
+
requirement: !ruby/object:Gem::Requirement
|
236
|
+
requirements:
|
237
|
+
- - "~>"
|
238
|
+
- !ruby/object:Gem::Version
|
239
|
+
version: '1.4'
|
240
|
+
type: :development
|
241
|
+
prerelease: false
|
242
|
+
version_requirements: !ruby/object:Gem::Requirement
|
243
|
+
requirements:
|
244
|
+
- - "~>"
|
245
|
+
- !ruby/object:Gem::Version
|
246
|
+
version: '1.4'
|
125
247
|
description: "\n Allows you to test whether your database schema\n matches the
|
126
248
|
validations in your ActiveRecord models.'\n "
|
127
249
|
email: emma.borhanian+schema_expectations@gmail.com
|
@@ -133,21 +255,43 @@ files:
|
|
133
255
|
- ".rspec"
|
134
256
|
- ".ruby-version"
|
135
257
|
- ".travis.yml"
|
258
|
+
- Appraisals
|
136
259
|
- CHANGELOG.md
|
137
260
|
- Gemfile
|
138
261
|
- Guardfile
|
139
262
|
- LICENSE
|
140
263
|
- README.md
|
141
264
|
- Rakefile
|
265
|
+
- gemfiles/activerecord_3.1.gemfile
|
266
|
+
- gemfiles/activerecord_3.2.gemfile
|
267
|
+
- gemfiles/activerecord_4.0.gemfile
|
268
|
+
- gemfiles/activerecord_4.1.gemfile
|
269
|
+
- gemfiles/activerecord_4.2.gemfile
|
270
|
+
- gemfiles/default.gemfile
|
271
|
+
- gemfiles/rspec_3.0.gemfile
|
272
|
+
- gemfiles/rspec_3.1.gemfile
|
273
|
+
- gemfiles/rspec_3.2.gemfile
|
142
274
|
- lib/schema_expectations.rb
|
275
|
+
- lib/schema_expectations/active_record/column_reflector.rb
|
276
|
+
- lib/schema_expectations/active_record/validation_reflector.rb
|
277
|
+
- lib/schema_expectations/config.rb
|
143
278
|
- lib/schema_expectations/rspec.rb
|
144
279
|
- lib/schema_expectations/rspec_matchers.rb
|
145
280
|
- lib/schema_expectations/rspec_matchers/validate_schema_nullable.rb
|
281
|
+
- lib/schema_expectations/util.rb
|
146
282
|
- lib/schema_expectations/version.rb
|
147
283
|
- schema_expectations.gemspec
|
284
|
+
- spec/db/database.yml
|
285
|
+
- spec/lib/schema_expectations/active_record/column_reflector_spec.rb
|
286
|
+
- spec/lib/schema_expectations/active_record/validation_reflector_spec.rb
|
287
|
+
- spec/lib/schema_expectations/config_spec.rb
|
148
288
|
- spec/lib/schema_expectations/rspec_matchers/validate_schema_nullable_spec.rb
|
289
|
+
- spec/lib/schema_expectations/util_spec.rb
|
290
|
+
- spec/meta_spec.rb
|
149
291
|
- spec/spec_helper.rb
|
150
292
|
- spec/support/active_record.rb
|
293
|
+
- spec/support/active_record_helpers.rb
|
294
|
+
- spec/support/gem_filters.rb
|
151
295
|
homepage: https://github.com/emma-borhanian/schema_expectations
|
152
296
|
licenses:
|
153
297
|
- MIT
|
@@ -173,7 +317,15 @@ signing_key:
|
|
173
317
|
specification_version: 4
|
174
318
|
summary: Database Schema Expectations
|
175
319
|
test_files:
|
320
|
+
- spec/db/database.yml
|
321
|
+
- spec/lib/schema_expectations/active_record/column_reflector_spec.rb
|
322
|
+
- spec/lib/schema_expectations/active_record/validation_reflector_spec.rb
|
323
|
+
- spec/lib/schema_expectations/config_spec.rb
|
176
324
|
- spec/lib/schema_expectations/rspec_matchers/validate_schema_nullable_spec.rb
|
325
|
+
- spec/lib/schema_expectations/util_spec.rb
|
326
|
+
- spec/meta_spec.rb
|
177
327
|
- spec/spec_helper.rb
|
178
328
|
- spec/support/active_record.rb
|
329
|
+
- spec/support/active_record_helpers.rb
|
330
|
+
- spec/support/gem_filters.rb
|
179
331
|
has_rdoc:
|