ardb 0.28.3 → 0.29.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. checksums.yaml +7 -7
  2. data/Gemfile +4 -9
  3. data/README.md +252 -3
  4. data/ardb.gemspec +8 -7
  5. data/bin/ardb +1 -1
  6. data/lib/ardb.rb +35 -34
  7. data/lib/ardb/adapter/base.rb +34 -30
  8. data/lib/ardb/adapter/mysql.rb +2 -17
  9. data/lib/ardb/adapter/postgresql.rb +24 -30
  10. data/lib/ardb/adapter/sqlite.rb +4 -8
  11. data/lib/ardb/adapter_spy.rb +2 -16
  12. data/lib/ardb/cli.rb +15 -15
  13. data/lib/ardb/cli/clirb.rb +14 -17
  14. data/lib/ardb/cli/commands.rb +204 -114
  15. data/lib/ardb/db_tests.rb +2 -4
  16. data/lib/ardb/default_order_by.rb +3 -13
  17. data/lib/ardb/migration.rb +9 -13
  18. data/lib/ardb/record_spy.rb +7 -26
  19. data/lib/ardb/relation_spy.rb +0 -6
  20. data/lib/ardb/require_autoloaded_active_record_files.rb +103 -58
  21. data/lib/ardb/test_helpers.rb +2 -5
  22. data/lib/ardb/use_db_default.rb +4 -15
  23. data/lib/ardb/version.rb +1 -1
  24. data/script/determine_autoloaded_active_record_files.rb +11 -8
  25. data/test/helper.rb +4 -13
  26. data/test/support/factory.rb +2 -2
  27. data/test/support/postgresql/migrations/{.gitkeep → .keep} +0 -0
  28. data/test/support/postgresql/schema.rb +0 -1
  29. data/test/support/postgresql/setup_test_db.rb +14 -15
  30. data/test/system/.keep +0 -0
  31. data/test/unit/adapter/base_tests.rb +73 -53
  32. data/test/unit/adapter/mysql_tests.rb +2 -19
  33. data/test/unit/adapter/postgresql_tests.rb +14 -23
  34. data/test/unit/adapter/sqlite_tests.rb +3 -11
  35. data/test/unit/adapter_spy_tests.rb +2 -16
  36. data/test/unit/ardb_tests.rb +43 -43
  37. data/test/unit/cli_tests.rb +220 -158
  38. data/test/unit/db_tests_tests.rb +3 -6
  39. data/test/unit/default_order_by_tests.rb +4 -8
  40. data/test/unit/migration_tests.rb +11 -15
  41. data/test/unit/record_spy_tests.rb +17 -22
  42. data/test/unit/relation_spy_tests.rb +17 -46
  43. data/test/unit/test_helpers_tests.rb +3 -14
  44. data/test/unit/use_db_default_tests.rb +7 -11
  45. metadata +100 -84
  46. data/lib/ardb/has_slug.rb +0 -107
  47. data/lib/ardb/migration_helpers.rb +0 -77
  48. data/lib/ardb/pg_json.rb +0 -90
  49. data/test/support/postgresql/pg_json_migrations/20160519133432_create_pg_json_migrate_test.rb +0 -13
  50. data/test/system/pg_json_tests.rb +0 -85
  51. data/test/unit/has_slug_tests.rb +0 -341
  52. data/test/unit/migration_helpers_tests.rb +0 -65
  53. data/test/unit/pg_json_tests.rb +0 -39
@@ -1,10 +1,9 @@
1
- require 'assert'
2
- require 'ardb/test_helpers'
1
+ require "assert"
2
+ require "ardb/test_helpers"
3
3
 
4
- require 'ardb/adapter_spy'
4
+ require "ardb/adapter_spy"
5
5
 
6
6
  module Ardb::TestHelpers
7
-
8
7
  class UnitTests < Assert::Context
9
8
  desc "Ardb::TestHelpers"
10
9
  subject{ Ardb::TestHelpers }
@@ -13,7 +12,6 @@ module Ardb::TestHelpers
13
12
  should have_imeths :create_db!, :create_db, :drop_db!, :drop_db
14
13
  should have_imeths :connect_db!, :connect_db, :migrate_db!, :migrate_db
15
14
  should have_imeths :reset_db, :reset_db!
16
-
17
15
  end
18
16
 
19
17
  class UsageTests < UnitTests
@@ -21,7 +19,6 @@ module Ardb::TestHelpers
21
19
  @adapter_spy = Ardb::AdapterSpy.new
22
20
  Assert.stub(Ardb, :adapter){ @adapter_spy }
23
21
  end
24
-
25
22
  end
26
23
 
27
24
  class DropTablesTests < UsageTests
@@ -32,7 +29,6 @@ module Ardb::TestHelpers
32
29
  subject.drop_tables
33
30
  assert_equal 1, @adapter_spy.drop_tables_called_count
34
31
  end
35
-
36
32
  end
37
33
 
38
34
  class LoadSchemaTests < UsageTests
@@ -43,7 +39,6 @@ module Ardb::TestHelpers
43
39
  subject.load_schema
44
40
  assert_equal 1, @adapter_spy.load_schema_called_count
45
41
  end
46
-
47
42
  end
48
43
 
49
44
  class CreateDbTests < UsageTests
@@ -64,7 +59,6 @@ module Ardb::TestHelpers
64
59
  subject.create_db!
65
60
  assert_equal 2, @adapter_spy.create_db_called_count
66
61
  end
67
-
68
62
  end
69
63
 
70
64
  class DropDbTests < UsageTests
@@ -85,7 +79,6 @@ module Ardb::TestHelpers
85
79
  subject.drop_db!
86
80
  assert_equal 2, @adapter_spy.drop_db_called_count
87
81
  end
88
-
89
82
  end
90
83
 
91
84
  class ConnectDbTests < UsageTests
@@ -106,7 +99,6 @@ module Ardb::TestHelpers
106
99
  subject.connect_db!
107
100
  assert_equal 2, @adapter_spy.connect_db_called_count
108
101
  end
109
-
110
102
  end
111
103
 
112
104
  class MigrateDbTests < UsageTests
@@ -127,7 +119,6 @@ module Ardb::TestHelpers
127
119
  subject.migrate_db!
128
120
  assert_equal 2, @adapter_spy.migrate_db_called_count
129
121
  end
130
-
131
122
  end
132
123
 
133
124
  class ResetDbTests < UsageTests
@@ -168,7 +159,5 @@ module Ardb::TestHelpers
168
159
  assert_equal 2, @adapter_spy.create_db_called_count
169
160
  assert_equal 2, @adapter_spy.load_schema_called_count
170
161
  end
171
-
172
162
  end
173
-
174
163
  end
@@ -1,11 +1,10 @@
1
- require 'assert'
2
- require 'ardb/use_db_default'
1
+ require "assert"
2
+ require "ardb/use_db_default"
3
3
 
4
- require 'much-plugin'
5
- require 'ardb/record_spy'
4
+ require "much-plugin"
5
+ require "ardb/record_spy"
6
6
 
7
7
  module Ardb::UseDbDefault
8
-
9
8
  class UnitTests < Assert::Context
10
9
  desc "Ardb::UseDbDefault"
11
10
  setup do
@@ -27,9 +26,9 @@ module Ardb::UseDbDefault
27
26
  end
28
27
 
29
28
  should "add use db default attributes using `use_db_default`" do
30
- attr_name = Factory.string
31
- subject.use_db_default(attr_name)
32
- assert_includes attr_name, subject.ardb_use_db_default_attrs
29
+ an_attr_name = Factory.string
30
+ subject.use_db_default(an_attr_name)
31
+ assert_includes an_attr_name, subject.ardb_use_db_default_attrs
33
32
 
34
33
  attr_names = [Factory.string, Factory.string.to_sym]
35
34
  subject.use_db_default(*attr_names)
@@ -58,7 +57,6 @@ module Ardb::UseDbDefault
58
57
  exp = [:ardb_allow_db_to_default_attrs]
59
58
  assert_equal exp, callback.args
60
59
  end
61
-
62
60
  end
63
61
 
64
62
  class InitTests < UnitTests
@@ -132,7 +130,6 @@ module Ardb::UseDbDefault
132
130
  assert_equal @original_attrs[name], subject.attributes[name]
133
131
  end
134
132
  end
135
-
136
133
  end
137
134
 
138
135
  module UseDbDefaultRecordSpy
@@ -156,5 +153,4 @@ module Ardb::UseDbDefault
156
153
  end
157
154
  end
158
155
  end
159
-
160
156
  end
metadata CHANGED
@@ -1,78 +1,108 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: ardb
3
- version: !ruby/object:Gem::Version
4
- version: 0.28.3
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.29.0
5
5
  platform: ruby
6
- authors:
6
+ authors:
7
7
  - Kelly Redding
8
8
  - Collin Redding
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
-
13
- date: 2016-08-18 00:00:00 Z
14
- dependencies:
15
- - !ruby/object:Gem::Dependency
12
+ date: 2020-12-17 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
16
15
  name: assert
17
- prerelease: false
18
- requirement: &id001 !ruby/object:Gem::Requirement
19
- requirements:
20
- - - ~>
21
- - !ruby/object:Gem::Version
22
- version: 2.16.1
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: 2.18.1
23
21
  type: :development
24
- version_requirements: *id001
25
- - !ruby/object:Gem::Dependency
26
- name: activerecord
27
22
  prerelease: false
28
- requirement: &id002 !ruby/object:Gem::Requirement
29
- requirements:
30
- - - ~>
31
- - &id003 !ruby/object:Gem::Version
32
- version: "3.2"
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: 2.18.1
28
+ - !ruby/object:Gem::Dependency
29
+ name: activerecord
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">"
33
+ - !ruby/object:Gem::Version
34
+ version: '5.0'
35
+ - - "<"
36
+ - !ruby/object:Gem::Version
37
+ version: '7.0'
33
38
  type: :runtime
34
- version_requirements: *id002
35
- - !ruby/object:Gem::Dependency
36
- name: activesupport
37
39
  prerelease: false
38
- requirement: &id004 !ruby/object:Gem::Requirement
39
- requirements:
40
- - - ~>
41
- - *id003
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ requirements:
42
+ - - ">"
43
+ - !ruby/object:Gem::Version
44
+ version: '5.0'
45
+ - - "<"
46
+ - !ruby/object:Gem::Version
47
+ version: '7.0'
48
+ - !ruby/object:Gem::Dependency
49
+ name: activesupport
50
+ requirement: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">"
53
+ - !ruby/object:Gem::Version
54
+ version: '5.0'
55
+ - - "<"
56
+ - !ruby/object:Gem::Version
57
+ version: '7.0'
42
58
  type: :runtime
43
- version_requirements: *id004
44
- - !ruby/object:Gem::Dependency
45
- name: much-plugin
46
59
  prerelease: false
47
- requirement: &id005 !ruby/object:Gem::Requirement
48
- requirements:
49
- - - ~>
50
- - !ruby/object:Gem::Version
51
- version: 0.2.0
60
+ version_requirements: !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - - ">"
63
+ - !ruby/object:Gem::Version
64
+ version: '5.0'
65
+ - - "<"
66
+ - !ruby/object:Gem::Version
67
+ version: '7.0'
68
+ - !ruby/object:Gem::Dependency
69
+ name: much-plugin
70
+ requirement: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: 0.2.1
52
75
  type: :runtime
53
- version_requirements: *id005
54
- - !ruby/object:Gem::Dependency
55
- name: scmd
56
76
  prerelease: false
57
- requirement: &id006 !ruby/object:Gem::Requirement
58
- requirements:
59
- - - ~>
60
- - !ruby/object:Gem::Version
61
- version: 3.0.2
77
+ version_requirements: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - "~>"
80
+ - !ruby/object:Gem::Version
81
+ version: 0.2.1
82
+ - !ruby/object:Gem::Dependency
83
+ name: scmd
84
+ requirement: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - "~>"
87
+ - !ruby/object:Gem::Version
88
+ version: 3.0.3
62
89
  type: :runtime
63
- version_requirements: *id006
90
+ prerelease: false
91
+ version_requirements: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - "~>"
94
+ - !ruby/object:Gem::Version
95
+ version: 3.0.3
64
96
  description: Activerecord database tools.
65
- email:
97
+ email:
66
98
  - kelly@kellyredding.com
67
99
  - collin.redding@me.com
68
- executables:
100
+ executables:
69
101
  - ardb
70
102
  extensions: []
71
-
72
103
  extra_rdoc_files: []
73
-
74
- files:
75
- - .gitignore
104
+ files:
105
+ - ".gitignore"
76
106
  - Gemfile
77
107
  - LICENSE
78
108
  - README.md
@@ -89,10 +119,7 @@ files:
89
119
  - lib/ardb/cli/commands.rb
90
120
  - lib/ardb/db_tests.rb
91
121
  - lib/ardb/default_order_by.rb
92
- - lib/ardb/has_slug.rb
93
122
  - lib/ardb/migration.rb
94
- - lib/ardb/migration_helpers.rb
95
- - lib/ardb/pg_json.rb
96
123
  - lib/ardb/record_spy.rb
97
124
  - lib/ardb/relation_spy.rb
98
125
  - lib/ardb/require_autoloaded_active_record_files.rb
@@ -104,13 +131,12 @@ files:
104
131
  - test/helper.rb
105
132
  - test/support/factory.rb
106
133
  - test/support/fake_schema.rb
107
- - test/support/postgresql/migrations/.gitkeep
108
- - test/support/postgresql/pg_json_migrations/20160519133432_create_pg_json_migrate_test.rb
134
+ - test/support/postgresql/migrations/.keep
109
135
  - test/support/postgresql/schema.rb
110
136
  - test/support/postgresql/setup_test_db.rb
111
137
  - test/support/relative_require_test_db_file.rb
112
138
  - test/support/require_test_db_file.rb
113
- - test/system/pg_json_tests.rb
139
+ - test/system/.keep
114
140
  - test/unit/adapter/base_tests.rb
115
141
  - test/unit/adapter/mysql_tests.rb
116
142
  - test/unit/adapter/postgresql_tests.rb
@@ -120,52 +146,45 @@ files:
120
146
  - test/unit/cli_tests.rb
121
147
  - test/unit/db_tests_tests.rb
122
148
  - test/unit/default_order_by_tests.rb
123
- - test/unit/has_slug_tests.rb
124
- - test/unit/migration_helpers_tests.rb
125
149
  - test/unit/migration_tests.rb
126
- - test/unit/pg_json_tests.rb
127
150
  - test/unit/record_spy_tests.rb
128
151
  - test/unit/relation_spy_tests.rb
129
152
  - test/unit/test_helpers_tests.rb
130
153
  - test/unit/use_db_default_tests.rb
131
154
  - tmp/.gitkeep
132
155
  homepage: http://github.com/redding/ardb
133
- licenses:
156
+ licenses:
134
157
  - MIT
135
158
  metadata: {}
136
-
137
159
  post_install_message:
138
160
  rdoc_options: []
139
-
140
- require_paths:
161
+ require_paths:
141
162
  - lib
142
- required_ruby_version: !ruby/object:Gem::Requirement
143
- requirements:
144
- - &id007
145
- - ">="
146
- - !ruby/object:Gem::Version
147
- version: "0"
148
- required_rubygems_version: !ruby/object:Gem::Requirement
149
- requirements:
150
- - *id007
163
+ required_ruby_version: !ruby/object:Gem::Requirement
164
+ requirements:
165
+ - - "~>"
166
+ - !ruby/object:Gem::Version
167
+ version: '2.4'
168
+ required_rubygems_version: !ruby/object:Gem::Requirement
169
+ requirements:
170
+ - - ">="
171
+ - !ruby/object:Gem::Version
172
+ version: '0'
151
173
  requirements: []
152
-
153
- rubyforge_project:
154
- rubygems_version: 2.5.1
174
+ rubygems_version: 3.1.2
155
175
  signing_key:
156
176
  specification_version: 4
157
177
  summary: Activerecord database tools.
158
- test_files:
178
+ test_files:
159
179
  - test/helper.rb
160
180
  - test/support/factory.rb
161
181
  - test/support/fake_schema.rb
162
- - test/support/postgresql/migrations/.gitkeep
163
- - test/support/postgresql/pg_json_migrations/20160519133432_create_pg_json_migrate_test.rb
182
+ - test/support/postgresql/migrations/.keep
164
183
  - test/support/postgresql/schema.rb
165
184
  - test/support/postgresql/setup_test_db.rb
166
185
  - test/support/relative_require_test_db_file.rb
167
186
  - test/support/require_test_db_file.rb
168
- - test/system/pg_json_tests.rb
187
+ - test/system/.keep
169
188
  - test/unit/adapter/base_tests.rb
170
189
  - test/unit/adapter/mysql_tests.rb
171
190
  - test/unit/adapter/postgresql_tests.rb
@@ -175,10 +194,7 @@ test_files:
175
194
  - test/unit/cli_tests.rb
176
195
  - test/unit/db_tests_tests.rb
177
196
  - test/unit/default_order_by_tests.rb
178
- - test/unit/has_slug_tests.rb
179
- - test/unit/migration_helpers_tests.rb
180
197
  - test/unit/migration_tests.rb
181
- - test/unit/pg_json_tests.rb
182
198
  - test/unit/record_spy_tests.rb
183
199
  - test/unit/relation_spy_tests.rb
184
200
  - test/unit/test_helpers_tests.rb
@@ -1,107 +0,0 @@
1
- require 'much-plugin'
2
-
3
- module Ardb
4
-
5
- module HasSlug
6
- include MuchPlugin
7
-
8
- DEFAULT_ATTRIBUTE = :slug
9
- DEFAULT_PREPROCESSOR = :downcase
10
- DEFAULT_SEPARATOR = '-'.freeze
11
-
12
- plugin_included do
13
- extend ClassMethods
14
- include InstanceMethods
15
-
16
- @ardb_has_slug_configs = Hash.new{ |h, k| h[k] = {} }
17
- end
18
-
19
- module ClassMethods
20
-
21
- def has_slug(options = nil)
22
- options ||= {}
23
- raise(ArgumentError, "a source must be provided") unless options[:source]
24
-
25
- attribute = (options[:attribute] || DEFAULT_ATTRIBUTE).to_sym
26
- @ardb_has_slug_configs[attribute].merge!({
27
- :source_proc => options[:source].to_proc,
28
- :preprocessor_proc => (options[:preprocessor] || DEFAULT_PREPROCESSOR).to_proc,
29
- :separator => options[:separator] || DEFAULT_SEPARATOR,
30
- :allow_underscores => !!options[:allow_underscores]
31
- })
32
-
33
- # since the slug isn't written till an after callback we can't always
34
- # validate presence of it
35
- validates_presence_of(attribute, :on => :update)
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
43
-
44
- after_create :ardb_has_slug_generate_slugs
45
- after_update :ardb_has_slug_generate_slugs
46
- end
47
-
48
- def ardb_has_slug_configs
49
- @ardb_has_slug_configs
50
- end
51
-
52
- end
53
-
54
- module InstanceMethods
55
-
56
- private
57
-
58
- def reset_slug(attribute = nil)
59
- attribute ||= DEFAULT_ATTRIBUTE
60
- self.send("#{attribute}=", nil)
61
- end
62
-
63
- def ardb_has_slug_generate_slugs
64
- self.class.ardb_has_slug_configs.each do |attr_name, config|
65
- slug_source = if !self.send(attr_name) || self.send(attr_name).to_s.empty?
66
- self.instance_eval(&config[:source_proc])
67
- else
68
- self.send(attr_name)
69
- end
70
-
71
- generated_slug = Slug.new(slug_source, {
72
- :preprocessor => config[:preprocessor_proc],
73
- :separator => config[:separator],
74
- :allow_underscores => config[:allow_underscores]
75
- })
76
- next if self.send(attr_name) == generated_slug
77
- self.send("#{attr_name}=", generated_slug)
78
- self.update_column(attr_name, generated_slug)
79
- end
80
- end
81
-
82
- end
83
-
84
- module Slug
85
- def self.new(string, options = nil)
86
- options ||= {}
87
- preprocessor = options[:preprocessor]
88
- separator = options[:separator]
89
- allow_underscores = options[:allow_underscores]
90
- regexp_escaped_sep = Regexp.escape(separator)
91
-
92
- slug = preprocessor.call(string.to_s.dup)
93
- # Turn unwanted chars into the separator
94
- slug.gsub!(/[^\w#{regexp_escaped_sep}]+/, separator)
95
- # Turn underscores into the separator, unless allowing
96
- slug.gsub!(/_/, separator) unless allow_underscores
97
- # No more than one of the separator in a row.
98
- slug.gsub!(/#{regexp_escaped_sep}{2,}/, separator)
99
- # Remove leading/trailing separator.
100
- slug.gsub!(/\A#{regexp_escaped_sep}|#{regexp_escaped_sep}\z/, '')
101
- slug
102
- end
103
- end
104
-
105
- end
106
-
107
- end