ardb 0.26.0 → 0.27.0
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.
- data/ardb.gemspec +1 -0
- data/bin/ardb +1 -1
- data/lib/ardb.rb +1 -1
- data/lib/ardb/adapter/base.rb +73 -66
- data/lib/ardb/adapter/sqlite.rb +1 -1
- data/lib/ardb/adapter_spy.rb +18 -5
- data/lib/ardb/cli.rb +239 -76
- data/lib/ardb/clirb.rb +58 -0
- data/lib/ardb/default_order_by.rb +59 -0
- data/lib/ardb/has_slug.rb +7 -6
- data/lib/ardb/migration.rb +42 -0
- data/lib/ardb/migration_helpers.rb +56 -53
- data/lib/ardb/record_spy.rb +5 -5
- data/lib/ardb/relation_spy.rb +13 -2
- data/lib/ardb/root_path.rb +7 -4
- data/lib/ardb/test_helpers.rb +56 -42
- data/lib/ardb/use_db_default.rb +8 -7
- data/lib/ardb/version.rb +1 -1
- data/test/support/factory.rb +5 -0
- data/test/unit/adapter/base_tests.rb +22 -5
- data/test/unit/adapter/mysql_tests.rb +1 -1
- data/test/unit/adapter/sqlite_tests.rb +2 -2
- data/test/unit/adapter_spy_tests.rb +19 -6
- data/test/unit/cli_tests.rb +610 -0
- data/test/unit/default_order_by_tests.rb +122 -0
- data/test/unit/has_slug_tests.rb +5 -0
- data/test/unit/migration_tests.rb +88 -0
- data/test/unit/record_spy_tests.rb +6 -0
- data/test/unit/test_helpers_tests.rb +26 -3
- data/test/unit/use_db_default_tests.rb +5 -0
- metadata +31 -25
- data/lib/ardb/runner.rb +0 -50
- data/lib/ardb/runner/connect_command.rb +0 -20
- data/lib/ardb/runner/create_command.rb +0 -25
- data/lib/ardb/runner/drop_command.rb +0 -25
- data/lib/ardb/runner/generate_command.rb +0 -64
- data/lib/ardb/runner/migrate_command.rb +0 -28
- data/test/unit/runner/connect_command_tests.rb +0 -17
- data/test/unit/runner/create_command_tests.rb +0 -67
- data/test/unit/runner/drop_command_tests.rb +0 -68
- data/test/unit/runner/generate_command_tests.rb +0 -46
- data/test/unit/runner/migrate_command_tests.rb +0 -96
- data/test/unit/runner_tests.rb +0 -69
@@ -0,0 +1,122 @@
|
|
1
|
+
require 'assert'
|
2
|
+
require 'ardb/default_order_by'
|
3
|
+
|
4
|
+
require 'much-plugin'
|
5
|
+
require 'ardb/record_spy'
|
6
|
+
|
7
|
+
module Ardb::DefaultOrderBy
|
8
|
+
|
9
|
+
class UnitTests < Assert::Context
|
10
|
+
desc "Ardb::DefaultOrderBy"
|
11
|
+
setup do
|
12
|
+
order_by_attribute = @order_by_attribute = Factory.string.to_sym
|
13
|
+
@scope_proc = proc{ self.class.where(:grouping => self.grouping) }
|
14
|
+
@record_class = Ardb::RecordSpy.new do
|
15
|
+
include Ardb::DefaultOrderBy
|
16
|
+
attr_accessor order_by_attribute, :grouping
|
17
|
+
end
|
18
|
+
end
|
19
|
+
subject{ @record_class }
|
20
|
+
|
21
|
+
should have_imeths :default_order_by
|
22
|
+
should have_imeths :ardb_default_order_by_config
|
23
|
+
|
24
|
+
should "use much-plugin" do
|
25
|
+
assert_includes MuchPlugin, Ardb::DefaultOrderBy
|
26
|
+
end
|
27
|
+
|
28
|
+
should "know its default attribute, preprocessor and separator" do
|
29
|
+
assert_equal :order_by, DEFAULT_ATTRIBUTE
|
30
|
+
record = subject.new
|
31
|
+
assert_equal subject.scoped, record.instance_eval(&DEFAULT_SCOPE_PROC)
|
32
|
+
end
|
33
|
+
|
34
|
+
should "not have any default-order-by config by default" do
|
35
|
+
assert_equal({}, subject.ardb_default_order_by_config)
|
36
|
+
end
|
37
|
+
|
38
|
+
should "default its config using `default_order_by`" do
|
39
|
+
subject.default_order_by
|
40
|
+
|
41
|
+
config = subject.ardb_default_order_by_config
|
42
|
+
assert_equal DEFAULT_ATTRIBUTE, config[:attribute]
|
43
|
+
assert_same DEFAULT_SCOPE_PROC, config[:scope_proc]
|
44
|
+
end
|
45
|
+
|
46
|
+
should "allow customizing the config using `default_order_by`" do
|
47
|
+
subject.default_order_by({
|
48
|
+
:attribute => @order_by_attribute,
|
49
|
+
:scope => @scope_proc
|
50
|
+
})
|
51
|
+
|
52
|
+
config = subject.ardb_default_order_by_config
|
53
|
+
assert_equal @order_by_attribute, config[:attribute]
|
54
|
+
assert_same @scope_proc, config[:scope_proc]
|
55
|
+
end
|
56
|
+
|
57
|
+
should "add callbacks using `default_order_by`" do
|
58
|
+
subject.default_order_by
|
59
|
+
|
60
|
+
callback = subject.callbacks.find{ |v| v.type == :before_validation }
|
61
|
+
assert_not_nil callback
|
62
|
+
assert_equal [:ardb_default_order_by], callback.args
|
63
|
+
assert_equal({ :on => :create }, callback.options)
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
67
|
+
|
68
|
+
class InitTests < UnitTests
|
69
|
+
desc "when init"
|
70
|
+
setup do
|
71
|
+
@record_class.default_order_by({
|
72
|
+
:attribute => @order_by_attribute,
|
73
|
+
:scope => @scope_proc
|
74
|
+
})
|
75
|
+
@current_max = Factory.integer
|
76
|
+
@record_class.relation_spy.maximum_values[@order_by_attribute] = @current_max
|
77
|
+
|
78
|
+
@record = @record_class.new
|
79
|
+
@record.grouping = Factory.string
|
80
|
+
end
|
81
|
+
subject{ @record }
|
82
|
+
|
83
|
+
should "allow resetting its order-by to the current max + 1" do
|
84
|
+
assert_not_equal @current_max + 1, subject.send(@order_by_attribute)
|
85
|
+
subject.instance_eval{ reset_order_by }
|
86
|
+
assert_equal @current_max + 1, subject.send(@order_by_attribute)
|
87
|
+
end
|
88
|
+
|
89
|
+
should "reset its order-by to a start value when there isn't a current max" do
|
90
|
+
@record_class.relation_spy.maximum_values.delete(@order_by_attribute)
|
91
|
+
|
92
|
+
subject.instance_eval{ reset_order_by }
|
93
|
+
assert_equal 1, subject.send(@order_by_attribute)
|
94
|
+
end
|
95
|
+
|
96
|
+
should "use the configured scope when resetting its order-by" do
|
97
|
+
assert_empty @record_class.relation_spy.applied
|
98
|
+
subject.instance_eval{ reset_order_by }
|
99
|
+
|
100
|
+
assert_equal 1, @record_class.relation_spy.applied.size
|
101
|
+
applied_expression = @record_class.relation_spy.applied.last
|
102
|
+
assert_equal :where, applied_expression.type
|
103
|
+
assert_equal [{ :grouping => subject.grouping }], applied_expression.args
|
104
|
+
end
|
105
|
+
|
106
|
+
should "reset its order-by using `ardb_default_order_by`" do
|
107
|
+
assert_not_equal @current_max + 1, subject.send(@order_by_attribute)
|
108
|
+
subject.instance_eval{ ardb_default_order_by }
|
109
|
+
assert_equal @current_max + 1, subject.send(@order_by_attribute)
|
110
|
+
end
|
111
|
+
|
112
|
+
should "not reset its order-by if its already set using `ardb_default_order_by`" do
|
113
|
+
current_order_by = Factory.integer
|
114
|
+
subject.send("#{@order_by_attribute}=", current_order_by)
|
115
|
+
subject.instance_eval{ ardb_default_order_by }
|
116
|
+
|
117
|
+
assert_equal current_order_by, subject.send(@order_by_attribute)
|
118
|
+
end
|
119
|
+
|
120
|
+
end
|
121
|
+
|
122
|
+
end
|
data/test/unit/has_slug_tests.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'assert'
|
2
2
|
require 'ardb/has_slug'
|
3
3
|
|
4
|
+
require 'much-plugin'
|
4
5
|
require 'ardb/record_spy'
|
5
6
|
|
6
7
|
module Ardb::HasSlug
|
@@ -29,6 +30,10 @@ module Ardb::HasSlug
|
|
29
30
|
should have_imeths :has_slug
|
30
31
|
should have_imeths :ardb_has_slug_config
|
31
32
|
|
33
|
+
should "use much-plugin" do
|
34
|
+
assert_includes MuchPlugin, Ardb::UseDbDefault
|
35
|
+
end
|
36
|
+
|
32
37
|
should "know its default attribute, preprocessor and separator" do
|
33
38
|
assert_equal :slug, DEFAULT_ATTRIBUTE
|
34
39
|
assert_equal :downcase, DEFAULT_PREPROCESSOR
|
@@ -0,0 +1,88 @@
|
|
1
|
+
require "assert"
|
2
|
+
require "ardb/migration"
|
3
|
+
|
4
|
+
class Ardb::Migration
|
5
|
+
|
6
|
+
class UnitTests < Assert::Context
|
7
|
+
desc "Ardb::Migration"
|
8
|
+
setup do
|
9
|
+
@migration_class = Ardb::Migration
|
10
|
+
end
|
11
|
+
|
12
|
+
end
|
13
|
+
|
14
|
+
class InitTests < UnitTests
|
15
|
+
desc "when init"
|
16
|
+
setup do
|
17
|
+
@time_now = Time.now
|
18
|
+
Assert.stub(Time, :now){ @time_now }
|
19
|
+
|
20
|
+
@mkdir_called_with = []
|
21
|
+
Assert.stub(FileUtils, :mkdir_p){ |*args| @mkdir_called_with = args }
|
22
|
+
|
23
|
+
@file_spy = FileSpy.new
|
24
|
+
@file_open_called_with = []
|
25
|
+
Assert.stub(File, :open) do |*args, &block|
|
26
|
+
@file_open_called_with = args
|
27
|
+
block.call(@file_spy)
|
28
|
+
end
|
29
|
+
|
30
|
+
@id = Factory.migration_id
|
31
|
+
@migration = @migration_class.new(@id)
|
32
|
+
end
|
33
|
+
subject{ @migration }
|
34
|
+
|
35
|
+
should have_readers :identifier, :class_name, :file_name, :file_path
|
36
|
+
should have_readers :source
|
37
|
+
should have_imeths :save!
|
38
|
+
|
39
|
+
should "know its attrs" do
|
40
|
+
assert_equal @id, subject.identifier
|
41
|
+
|
42
|
+
exp = @id.classify.pluralize
|
43
|
+
assert_equal exp, subject.class_name
|
44
|
+
|
45
|
+
exp = "#{@time_now.strftime("%Y%m%d%H%M%S")}_#{@id.underscore}"
|
46
|
+
assert_equal exp, subject.file_name
|
47
|
+
|
48
|
+
exp = File.join(Ardb.config.migrations_path, "#{subject.file_name}.rb")
|
49
|
+
assert_equal exp, subject.file_path
|
50
|
+
|
51
|
+
exp = "require 'ardb/migration_helpers'\n\n" \
|
52
|
+
"class #{subject.class_name} < ActiveRecord::Migration\n" \
|
53
|
+
" include Ardb::MigrationHelpers\n\n" \
|
54
|
+
" def change\n" \
|
55
|
+
" end\n\n" \
|
56
|
+
"end\n"
|
57
|
+
assert_equal exp, subject.source
|
58
|
+
end
|
59
|
+
|
60
|
+
should "complain if no identifier is provided" do
|
61
|
+
assert_raises(NoIdentifierError) do
|
62
|
+
@migration_class.new([nil, ''].choice)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
should "write the migration source to the migrations path on save" do
|
67
|
+
subject.save!
|
68
|
+
|
69
|
+
assert_equal [Ardb.config.migrations_path], @mkdir_called_with
|
70
|
+
assert_equal [subject.file_path, 'w'], @file_open_called_with
|
71
|
+
assert_equal [subject.source], @file_spy.write_called_with
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|
75
|
+
|
76
|
+
class FileSpy
|
77
|
+
attr_reader :write_called_with
|
78
|
+
|
79
|
+
def initialize
|
80
|
+
@write_called_with = nil
|
81
|
+
end
|
82
|
+
|
83
|
+
def write(*args)
|
84
|
+
@write_called_with = args
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
end
|
@@ -1,6 +1,8 @@
|
|
1
1
|
require 'assert'
|
2
2
|
require 'ardb/record_spy'
|
3
3
|
|
4
|
+
require 'much-plugin'
|
5
|
+
|
4
6
|
module Ardb::RecordSpy
|
5
7
|
|
6
8
|
class UnitTests < Assert::Context
|
@@ -39,6 +41,10 @@ module Ardb::RecordSpy
|
|
39
41
|
should have_imeths :group, :having, :order, :reverse_order, :readonly
|
40
42
|
should have_imeths :limit, :offset, :merge, :except, :only
|
41
43
|
|
44
|
+
should "use much-plugin" do
|
45
|
+
assert_includes MuchPlugin, Ardb::RecordSpy
|
46
|
+
end
|
47
|
+
|
42
48
|
should "allow reading and writing the record's table name" do
|
43
49
|
subject.table_name = 'my_records'
|
44
50
|
assert_equal 'my_records', subject.table_name
|
@@ -1,16 +1,18 @@
|
|
1
1
|
require 'assert'
|
2
|
-
require 'ardb/adapter_spy'
|
3
2
|
require 'ardb/test_helpers'
|
4
3
|
|
4
|
+
require 'ardb/adapter_spy'
|
5
|
+
|
5
6
|
module Ardb::TestHelpers
|
6
7
|
|
7
8
|
class UnitTests < Assert::Context
|
8
|
-
desc "Ardb
|
9
|
+
desc "Ardb::TestHelpers"
|
9
10
|
subject{ Ardb::TestHelpers }
|
10
11
|
|
11
12
|
should have_imeths :drop_tables, :load_schema
|
12
13
|
should have_imeths :create_db!, :create_db, :drop_db!, :drop_db
|
13
|
-
should have_imeths :
|
14
|
+
should have_imeths :connect_db!, :connect_db, :migrate_db!, :migrate_db
|
15
|
+
should have_imeths :reset_db, :reset_db!
|
14
16
|
|
15
17
|
end
|
16
18
|
|
@@ -90,6 +92,27 @@ module Ardb::TestHelpers
|
|
90
92
|
|
91
93
|
end
|
92
94
|
|
95
|
+
class ConnectDbTests < UsageTests
|
96
|
+
desc "connect db methods"
|
97
|
+
|
98
|
+
should "tell the adapter to connect to the db only once" do
|
99
|
+
assert_equal 0, @adapter_spy.connect_db_called_count
|
100
|
+
subject.connect_db
|
101
|
+
assert_equal 1, @adapter_spy.connect_db_called_count
|
102
|
+
subject.connect_db
|
103
|
+
assert_equal 1, @adapter_spy.connect_db_called_count
|
104
|
+
end
|
105
|
+
|
106
|
+
should "force the adapter to connect to the db" do
|
107
|
+
assert_equal 0, @adapter_spy.connect_db_called_count
|
108
|
+
subject.connect_db!
|
109
|
+
assert_equal 1, @adapter_spy.connect_db_called_count
|
110
|
+
subject.connect_db!
|
111
|
+
assert_equal 2, @adapter_spy.connect_db_called_count
|
112
|
+
end
|
113
|
+
|
114
|
+
end
|
115
|
+
|
93
116
|
class MigrateDbTests < UsageTests
|
94
117
|
desc "migrate db methods"
|
95
118
|
|
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'assert'
|
2
2
|
require 'ardb/use_db_default'
|
3
3
|
|
4
|
+
require 'much-plugin'
|
4
5
|
require 'ardb/record_spy'
|
5
6
|
|
6
7
|
module Ardb::UseDbDefault
|
@@ -17,6 +18,10 @@ module Ardb::UseDbDefault
|
|
17
18
|
|
18
19
|
should have_imeths :use_db_default, :ardb_use_db_default_attrs
|
19
20
|
|
21
|
+
should "use much-plugin" do
|
22
|
+
assert_includes MuchPlugin, Ardb::UseDbDefault
|
23
|
+
end
|
24
|
+
|
20
25
|
should "know its use db default attrs" do
|
21
26
|
assert_equal [], subject.ardb_use_db_default_attrs
|
22
27
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ardb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 115
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
8
|
+
- 27
|
9
9
|
- 0
|
10
|
-
version: 0.
|
10
|
+
version: 0.27.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Kelly Redding
|
@@ -16,7 +16,7 @@ autorequire:
|
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
18
|
|
19
|
-
date: 2015-12-
|
19
|
+
date: 2015-12-18 00:00:00 Z
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
22
22
|
requirement: &id001 !ruby/object:Gem::Requirement
|
@@ -65,6 +65,21 @@ dependencies:
|
|
65
65
|
prerelease: false
|
66
66
|
- !ruby/object:Gem::Dependency
|
67
67
|
requirement: &id004 !ruby/object:Gem::Requirement
|
68
|
+
none: false
|
69
|
+
requirements:
|
70
|
+
- - ~>
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
hash: 9
|
73
|
+
segments:
|
74
|
+
- 0
|
75
|
+
- 1
|
76
|
+
version: "0.1"
|
77
|
+
type: :runtime
|
78
|
+
name: much-plugin
|
79
|
+
version_requirements: *id004
|
80
|
+
prerelease: false
|
81
|
+
- !ruby/object:Gem::Dependency
|
82
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
68
83
|
none: false
|
69
84
|
requirements:
|
70
85
|
- - ~>
|
@@ -76,10 +91,10 @@ dependencies:
|
|
76
91
|
version: "1.1"
|
77
92
|
type: :runtime
|
78
93
|
name: ns-options
|
79
|
-
version_requirements: *
|
94
|
+
version_requirements: *id005
|
80
95
|
prerelease: false
|
81
96
|
- !ruby/object:Gem::Dependency
|
82
|
-
requirement: &
|
97
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
83
98
|
none: false
|
84
99
|
requirements:
|
85
100
|
- - ~>
|
@@ -91,7 +106,7 @@ dependencies:
|
|
91
106
|
version: "3.0"
|
92
107
|
type: :runtime
|
93
108
|
name: scmd
|
94
|
-
version_requirements: *
|
109
|
+
version_requirements: *id006
|
95
110
|
prerelease: false
|
96
111
|
description: Activerecord database tools.
|
97
112
|
email:
|
@@ -118,17 +133,14 @@ files:
|
|
118
133
|
- lib/ardb/adapter/sqlite.rb
|
119
134
|
- lib/ardb/adapter_spy.rb
|
120
135
|
- lib/ardb/cli.rb
|
136
|
+
- lib/ardb/clirb.rb
|
137
|
+
- lib/ardb/default_order_by.rb
|
121
138
|
- lib/ardb/has_slug.rb
|
139
|
+
- lib/ardb/migration.rb
|
122
140
|
- lib/ardb/migration_helpers.rb
|
123
141
|
- lib/ardb/record_spy.rb
|
124
142
|
- lib/ardb/relation_spy.rb
|
125
143
|
- lib/ardb/root_path.rb
|
126
|
-
- lib/ardb/runner.rb
|
127
|
-
- lib/ardb/runner/connect_command.rb
|
128
|
-
- lib/ardb/runner/create_command.rb
|
129
|
-
- lib/ardb/runner/drop_command.rb
|
130
|
-
- lib/ardb/runner/generate_command.rb
|
131
|
-
- lib/ardb/runner/migrate_command.rb
|
132
144
|
- lib/ardb/test_helpers.rb
|
133
145
|
- lib/ardb/use_db_default.rb
|
134
146
|
- lib/ardb/version.rb
|
@@ -141,17 +153,14 @@ files:
|
|
141
153
|
- test/unit/adapter/sqlite_tests.rb
|
142
154
|
- test/unit/adapter_spy_tests.rb
|
143
155
|
- test/unit/ardb_tests.rb
|
156
|
+
- test/unit/cli_tests.rb
|
144
157
|
- test/unit/config_tests.rb
|
158
|
+
- test/unit/default_order_by_tests.rb
|
145
159
|
- test/unit/has_slug_tests.rb
|
146
160
|
- test/unit/migration_helpers_tests.rb
|
161
|
+
- test/unit/migration_tests.rb
|
147
162
|
- test/unit/record_spy_tests.rb
|
148
163
|
- test/unit/relation_spy_tests.rb
|
149
|
-
- test/unit/runner/connect_command_tests.rb
|
150
|
-
- test/unit/runner/create_command_tests.rb
|
151
|
-
- test/unit/runner/drop_command_tests.rb
|
152
|
-
- test/unit/runner/generate_command_tests.rb
|
153
|
-
- test/unit/runner/migrate_command_tests.rb
|
154
|
-
- test/unit/runner_tests.rb
|
155
164
|
- test/unit/test_helpers_tests.rb
|
156
165
|
- test/unit/use_db_default_tests.rb
|
157
166
|
- tmp/.gitkeep
|
@@ -209,16 +218,13 @@ test_files:
|
|
209
218
|
- test/unit/adapter/sqlite_tests.rb
|
210
219
|
- test/unit/adapter_spy_tests.rb
|
211
220
|
- test/unit/ardb_tests.rb
|
221
|
+
- test/unit/cli_tests.rb
|
212
222
|
- test/unit/config_tests.rb
|
223
|
+
- test/unit/default_order_by_tests.rb
|
213
224
|
- test/unit/has_slug_tests.rb
|
214
225
|
- test/unit/migration_helpers_tests.rb
|
226
|
+
- test/unit/migration_tests.rb
|
215
227
|
- test/unit/record_spy_tests.rb
|
216
228
|
- test/unit/relation_spy_tests.rb
|
217
|
-
- test/unit/runner/connect_command_tests.rb
|
218
|
-
- test/unit/runner/create_command_tests.rb
|
219
|
-
- test/unit/runner/drop_command_tests.rb
|
220
|
-
- test/unit/runner/generate_command_tests.rb
|
221
|
-
- test/unit/runner/migrate_command_tests.rb
|
222
|
-
- test/unit/runner_tests.rb
|
223
229
|
- test/unit/test_helpers_tests.rb
|
224
230
|
- test/unit/use_db_default_tests.rb
|