ardb 0.27.2 → 0.27.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile +0 -1
- data/{LICENSE.txt → LICENSE} +0 -0
- data/ardb.gemspec +5 -5
- data/lib/ardb.rb +13 -7
- data/lib/ardb/adapter/base.rb +8 -0
- data/lib/ardb/db_tests.rb +15 -0
- data/lib/ardb/has_slug.rb +7 -4
- data/lib/ardb/version.rb +1 -1
- data/test/unit/adapter/base_tests.rb +24 -0
- data/test/unit/ardb_tests.rb +22 -3
- data/test/unit/config_tests.rb +9 -7
- data/test/unit/db_tests_tests.rb +37 -0
- data/test/unit/has_slug_tests.rb +10 -0
- metadata +10 -8
- data/Rakefile +0 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: efed4edb38eade9eaa2de6263e30f163b4ffa3db
|
4
|
+
data.tar.gz: 41bb43c7936a806124cdeb747d78c6a4de2393e4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ba2ed871805feac6de258476b78dc906c63b6a4491b8ab24925dc87447e19f4e89f073b6642729d8ec863a3b760257293da95ed4aa7e8d2b3f7d09aedc86cefe
|
7
|
+
data.tar.gz: f521735072f0ce180c0073593af0aefc5ae16cc3bcab8ed5c0dcf7677f1da6d818fa8b051c1f91fa07b18626582b4beeec021810a51223f6ca538d503c9fb7bb
|
data/Gemfile
CHANGED
data/{LICENSE.txt → LICENSE}
RENAMED
File without changes
|
data/ardb.gemspec
CHANGED
@@ -8,8 +8,8 @@ Gem::Specification.new do |gem|
|
|
8
8
|
gem.version = Ardb::VERSION
|
9
9
|
gem.authors = ["Kelly Redding", "Collin Redding"]
|
10
10
|
gem.email = ["kelly@kellyredding.com", "collin.redding@me.com"]
|
11
|
-
gem.description = %q{Activerecord database tools.}
|
12
11
|
gem.summary = %q{Activerecord database tools.}
|
12
|
+
gem.description = %q{Activerecord database tools.}
|
13
13
|
gem.homepage = "http://github.com/redding/ardb"
|
14
14
|
gem.license = 'MIT'
|
15
15
|
|
@@ -18,12 +18,12 @@ Gem::Specification.new do |gem|
|
|
18
18
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
19
19
|
gem.require_paths = ["lib"]
|
20
20
|
|
21
|
-
gem.add_development_dependency("assert", ["~> 2.15"])
|
21
|
+
gem.add_development_dependency("assert", ["~> 2.15.1"])
|
22
22
|
|
23
23
|
gem.add_dependency('activerecord', ["~> 3.2"])
|
24
24
|
gem.add_dependency('activesupport', ["~> 3.2"])
|
25
|
-
gem.add_dependency('much-plugin', ["~> 0.1"])
|
26
|
-
gem.add_dependency('ns-options', ["~> 1.1"])
|
27
|
-
gem.add_dependency('scmd', ["~> 3.0"])
|
25
|
+
gem.add_dependency('much-plugin', ["~> 0.1.0"])
|
26
|
+
gem.add_dependency('ns-options', ["~> 1.1.6"])
|
27
|
+
gem.add_dependency('scmd', ["~> 3.0.1"])
|
28
28
|
|
29
29
|
end
|
data/lib/ardb.rb
CHANGED
@@ -35,17 +35,23 @@ module Ardb
|
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
38
|
+
def self.escape_like_pattern(pattern, escape_char = nil)
|
39
|
+
self.adapter.escape_like_pattern(pattern, escape_char)
|
40
|
+
end
|
41
|
+
|
38
42
|
class Config
|
39
43
|
include NsOptions::Proxy
|
40
44
|
|
41
45
|
namespace :db do
|
42
|
-
option :adapter,
|
43
|
-
option :database,
|
44
|
-
option :encoding,
|
45
|
-
option :host,
|
46
|
-
option :port,
|
47
|
-
option :username,
|
48
|
-
option :password,
|
46
|
+
option :adapter, String, :required => true
|
47
|
+
option :database, String, :required => true
|
48
|
+
option :encoding, String, :required => false
|
49
|
+
option :host, String, :required => false
|
50
|
+
option :port, Integer, :required => false
|
51
|
+
option :username, String, :required => false
|
52
|
+
option :password, String, :required => false
|
53
|
+
option :pool, Integer, :required => false
|
54
|
+
option :checkout_timeout, Integer, :required => false
|
49
55
|
end
|
50
56
|
|
51
57
|
option :db_file, Pathname, :default => ENV['ARDB_DB_FILE']
|
data/lib/ardb/adapter/base.rb
CHANGED
@@ -15,6 +15,14 @@ class Ardb::Adapter
|
|
15
15
|
@sql_schema_path = "#{schema_path}.sql"
|
16
16
|
end
|
17
17
|
|
18
|
+
def escape_like_pattern(pattern, escape_char = nil)
|
19
|
+
escape_char ||= "\\"
|
20
|
+
pattern = pattern.to_s.dup
|
21
|
+
pattern.gsub!(escape_char){ escape_char * 2 }
|
22
|
+
# don't allow custom wildcards
|
23
|
+
pattern.gsub!(/%|_/){ |wildcard_char| "#{escape_char}#{wildcard_char}" }
|
24
|
+
end
|
25
|
+
|
18
26
|
def foreign_key_add_sql(*args); raise NotImplementedError; end
|
19
27
|
def foreign_key_drop_sql(*args); raise NotImplementedError; end
|
20
28
|
|
data/lib/ardb/has_slug.rb
CHANGED
@@ -33,10 +33,13 @@ module Ardb
|
|
33
33
|
# since the slug isn't written till an after callback we can't always
|
34
34
|
# validate presence of it
|
35
35
|
validates_presence_of(attribute, :on => :update)
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
36
|
+
|
37
|
+
if options[:skip_unique_validation] != true
|
38
|
+
validates_uniqueness_of(attribute, {
|
39
|
+
:case_sensitive => true,
|
40
|
+
:scope => options[:unique_scope]
|
41
|
+
})
|
42
|
+
end
|
40
43
|
|
41
44
|
after_create :ardb_has_slug_generate_slugs
|
42
45
|
after_update :ardb_has_slug_generate_slugs
|
data/lib/ardb/version.rb
CHANGED
@@ -12,6 +12,7 @@ class Ardb::Adapter::Base
|
|
12
12
|
|
13
13
|
should have_readers :config_settings, :database
|
14
14
|
should have_readers :ruby_schema_path, :sql_schema_path
|
15
|
+
should have_imeths :escape_like_pattern
|
15
16
|
should have_imeths :foreign_key_add_sql, :foreign_key_drop_sql
|
16
17
|
should have_imeths :create_db, :drop_db, :connect_db, :migrate_db
|
17
18
|
should have_imeths :load_schema, :load_ruby_schema, :load_sql_schema
|
@@ -30,6 +31,29 @@ class Ardb::Adapter::Base
|
|
30
31
|
assert_equal "#{Ardb.config.schema_path}.sql", subject.sql_schema_path
|
31
32
|
end
|
32
33
|
|
34
|
+
should "know how to escape like patterns" do
|
35
|
+
pattern = "#{Factory.string}%" \
|
36
|
+
"#{Factory.string}_" \
|
37
|
+
"#{Factory.string}\\" \
|
38
|
+
"#{Factory.string} " \
|
39
|
+
"#{Factory.string}"
|
40
|
+
exp = pattern.gsub("\\"){ "\\\\" }.gsub('%', "\\%").gsub('_', "\\_")
|
41
|
+
assert_equal exp, subject.escape_like_pattern(pattern)
|
42
|
+
end
|
43
|
+
|
44
|
+
should "allow using a custom escape char when escaping like patterns" do
|
45
|
+
escape_char = '#'
|
46
|
+
pattern = "#{Factory.string}%" \
|
47
|
+
"#{Factory.string}_" \
|
48
|
+
"#{Factory.string}\\" \
|
49
|
+
"#{Factory.string}#{escape_char}" \
|
50
|
+
"#{Factory.string} " \
|
51
|
+
"#{Factory.string}"
|
52
|
+
exp = pattern.gsub(escape_char, "#{escape_char}#{escape_char}")
|
53
|
+
exp = exp.gsub('%', "#{escape_char}%").gsub('_', "#{escape_char}_")
|
54
|
+
assert_equal exp, subject.escape_like_pattern(pattern, escape_char)
|
55
|
+
end
|
56
|
+
|
33
57
|
should "not implement the foreign key sql meths" do
|
34
58
|
assert_raises(NotImplementedError){ subject.foreign_key_add_sql }
|
35
59
|
assert_raises(NotImplementedError){ subject.foreign_key_drop_sql }
|
data/test/unit/ardb_tests.rb
CHANGED
@@ -5,16 +5,20 @@ module Ardb
|
|
5
5
|
|
6
6
|
class UnitTests < Assert::Context
|
7
7
|
desc "Ardb"
|
8
|
-
subject{ Ardb }
|
9
8
|
setup do
|
10
9
|
@orig_ar_logger = ActiveRecord::Base.logger
|
10
|
+
Adapter.reset
|
11
|
+
|
12
|
+
@module = Ardb
|
11
13
|
end
|
12
14
|
teardown do
|
13
15
|
Adapter.reset
|
14
16
|
ActiveRecord::Base.logger = @orig_ar_logger
|
15
17
|
end
|
18
|
+
subject{ @module }
|
16
19
|
|
17
20
|
should have_imeths :config, :configure, :adapter, :validate!, :init
|
21
|
+
should have_imeths :escape_like_pattern
|
18
22
|
|
19
23
|
should "return its `Config` class with the `config` method" do
|
20
24
|
assert_same Config, subject.config
|
@@ -23,12 +27,11 @@ module Ardb
|
|
23
27
|
should "complain if init'ing and not all configs are set" do
|
24
28
|
orig_adapter = Ardb.config.db.adapter
|
25
29
|
Ardb.config.db.adapter = nil
|
26
|
-
assert_raises(NotConfiguredError)
|
30
|
+
assert_raises(NotConfiguredError){ subject.init }
|
27
31
|
Ardb.config.db.adapter = orig_adapter
|
28
32
|
end
|
29
33
|
|
30
34
|
should "init the adapter on init" do
|
31
|
-
Adapter.reset
|
32
35
|
assert_nil Adapter.current
|
33
36
|
begin
|
34
37
|
subject.init
|
@@ -53,4 +56,20 @@ module Ardb
|
|
53
56
|
|
54
57
|
end
|
55
58
|
|
59
|
+
class InitTests < UnitTests
|
60
|
+
desc "when init"
|
61
|
+
setup do
|
62
|
+
# don't establish connection, otherwise this errors if it can't connect to
|
63
|
+
# an actual DB
|
64
|
+
@module.init(false)
|
65
|
+
end
|
66
|
+
|
67
|
+
should "demeter its adapter" do
|
68
|
+
pattern = "%#{Factory.string}\\#{Factory.string}_"
|
69
|
+
exp = subject.adapter.escape_like_pattern(pattern)
|
70
|
+
assert_equal exp, subject.escape_like_pattern(pattern)
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
74
|
+
|
56
75
|
end
|
data/test/unit/config_tests.rb
CHANGED
@@ -43,13 +43,15 @@ class Ardb::Config
|
|
43
43
|
desc "db namespace"
|
44
44
|
subject{ Ardb::Config.db }
|
45
45
|
|
46
|
-
should have_option :adapter,
|
47
|
-
should have_option :database,
|
48
|
-
should have_option :encoding,
|
49
|
-
should have_option :host,
|
50
|
-
should have_option :port,
|
51
|
-
should have_option :username,
|
52
|
-
should have_option :password,
|
46
|
+
should have_option :adapter, String, :required => true
|
47
|
+
should have_option :database, String, :required => true
|
48
|
+
should have_option :encoding, String, :required => false
|
49
|
+
should have_option :host, String, :required => false
|
50
|
+
should have_option :port, Integer, :required => false
|
51
|
+
should have_option :username, String, :required => false
|
52
|
+
should have_option :password, String, :required => false
|
53
|
+
should have_option :pool, Integer, :required => false
|
54
|
+
should have_option :checkout_timeout, Integer, :required => false
|
53
55
|
|
54
56
|
end
|
55
57
|
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'assert'
|
2
|
+
require 'ardb/db_tests'
|
3
|
+
|
4
|
+
require 'active_record'
|
5
|
+
|
6
|
+
class Ardb::DbTests
|
7
|
+
|
8
|
+
class UnitTests < Assert::Context
|
9
|
+
desc "Ardb::DbTests"
|
10
|
+
setup do
|
11
|
+
@transaction_called = false
|
12
|
+
Assert.stub(ActiveRecord::Base, :transaction) do |&block|
|
13
|
+
@transaction_called = true
|
14
|
+
block.call
|
15
|
+
end
|
16
|
+
end
|
17
|
+
subject{ Ardb::DbTests }
|
18
|
+
|
19
|
+
should "be an assert context" do
|
20
|
+
assert subject < Assert::Context
|
21
|
+
end
|
22
|
+
|
23
|
+
should "add an around callback that runs tests in a transaction that rolls back" do
|
24
|
+
assert_equal 1, subject.arounds.size
|
25
|
+
callback = subject.arounds.first
|
26
|
+
|
27
|
+
block_yielded_to = false
|
28
|
+
assert_raises(ActiveRecord::Rollback) do
|
29
|
+
callback.call(proc{ block_yielded_to = true })
|
30
|
+
end
|
31
|
+
assert_true @transaction_called
|
32
|
+
assert_true block_yielded_to
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
data/test/unit/has_slug_tests.rb
CHANGED
@@ -102,6 +102,16 @@ module Ardb::HasSlug
|
|
102
102
|
assert_nil validation.options[:scope]
|
103
103
|
end
|
104
104
|
|
105
|
+
should "not add a unique validation if skipping unique validation" do
|
106
|
+
subject.has_slug({
|
107
|
+
:source => @source_attribute,
|
108
|
+
:skip_unique_validation => true
|
109
|
+
})
|
110
|
+
|
111
|
+
validation = subject.validations.find{ |v| v.type == :uniqueness }
|
112
|
+
assert_nil validation
|
113
|
+
end
|
114
|
+
|
105
115
|
should "allow customizing its validations using `has_slug`" do
|
106
116
|
unique_scope = Factory.string.to_sym
|
107
117
|
subject.has_slug({
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ardb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.27.
|
4
|
+
version: 0.27.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kelly Redding
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2016-
|
13
|
+
date: 2016-04-07 00:00:00 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: assert
|
@@ -19,7 +19,7 @@ dependencies:
|
|
19
19
|
requirements:
|
20
20
|
- - ~>
|
21
21
|
- !ruby/object:Gem::Version
|
22
|
-
version:
|
22
|
+
version: 2.15.1
|
23
23
|
type: :development
|
24
24
|
version_requirements: *id001
|
25
25
|
- !ruby/object:Gem::Dependency
|
@@ -48,7 +48,7 @@ dependencies:
|
|
48
48
|
requirements:
|
49
49
|
- - ~>
|
50
50
|
- !ruby/object:Gem::Version
|
51
|
-
version:
|
51
|
+
version: 0.1.0
|
52
52
|
type: :runtime
|
53
53
|
version_requirements: *id005
|
54
54
|
- !ruby/object:Gem::Dependency
|
@@ -58,7 +58,7 @@ dependencies:
|
|
58
58
|
requirements:
|
59
59
|
- - ~>
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
61
|
+
version: 1.1.6
|
62
62
|
type: :runtime
|
63
63
|
version_requirements: *id006
|
64
64
|
- !ruby/object:Gem::Dependency
|
@@ -68,7 +68,7 @@ dependencies:
|
|
68
68
|
requirements:
|
69
69
|
- - ~>
|
70
70
|
- !ruby/object:Gem::Version
|
71
|
-
version:
|
71
|
+
version: 3.0.1
|
72
72
|
type: :runtime
|
73
73
|
version_requirements: *id007
|
74
74
|
description: Activerecord database tools.
|
@@ -84,9 +84,8 @@ extra_rdoc_files: []
|
|
84
84
|
files:
|
85
85
|
- .gitignore
|
86
86
|
- Gemfile
|
87
|
-
- LICENSE
|
87
|
+
- LICENSE
|
88
88
|
- README.md
|
89
|
-
- Rakefile
|
90
89
|
- ardb.gemspec
|
91
90
|
- bin/ardb
|
92
91
|
- lib/ardb.rb
|
@@ -97,6 +96,7 @@ files:
|
|
97
96
|
- lib/ardb/adapter_spy.rb
|
98
97
|
- lib/ardb/cli.rb
|
99
98
|
- lib/ardb/clirb.rb
|
99
|
+
- lib/ardb/db_tests.rb
|
100
100
|
- lib/ardb/default_order_by.rb
|
101
101
|
- lib/ardb/has_slug.rb
|
102
102
|
- lib/ardb/migration.rb
|
@@ -120,6 +120,7 @@ files:
|
|
120
120
|
- test/unit/ardb_tests.rb
|
121
121
|
- test/unit/cli_tests.rb
|
122
122
|
- test/unit/config_tests.rb
|
123
|
+
- test/unit/db_tests_tests.rb
|
123
124
|
- test/unit/default_order_by_tests.rb
|
124
125
|
- test/unit/has_slug_tests.rb
|
125
126
|
- test/unit/migration_helpers_tests.rb
|
@@ -178,6 +179,7 @@ test_files:
|
|
178
179
|
- test/unit/ardb_tests.rb
|
179
180
|
- test/unit/cli_tests.rb
|
180
181
|
- test/unit/config_tests.rb
|
182
|
+
- test/unit/db_tests_tests.rb
|
181
183
|
- test/unit/default_order_by_tests.rb
|
182
184
|
- test/unit/has_slug_tests.rb
|
183
185
|
- test/unit/migration_helpers_tests.rb
|
data/Rakefile
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
require "bundler/gem_tasks"
|