ardb 0.27.3 → 0.29.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -7
- data/Gemfile +4 -5
- data/README.md +252 -3
- data/ardb.gemspec +8 -8
- data/bin/ardb +1 -1
- data/lib/ardb.rb +155 -72
- data/lib/ardb/adapter/base.rb +67 -47
- data/lib/ardb/adapter/mysql.rb +3 -19
- data/lib/ardb/adapter/postgresql.rb +33 -37
- data/lib/ardb/adapter/sqlite.rb +7 -16
- data/lib/ardb/adapter_spy.rb +58 -92
- data/lib/ardb/cli.rb +18 -226
- data/lib/ardb/{clirb.rb → cli/clirb.rb} +16 -18
- data/lib/ardb/cli/commands.rb +365 -0
- data/lib/ardb/db_tests.rb +2 -4
- data/lib/ardb/default_order_by.rb +3 -13
- data/lib/ardb/migration.rb +18 -20
- data/lib/ardb/record_spy.rb +7 -26
- data/lib/ardb/relation_spy.rb +0 -6
- data/lib/ardb/require_autoloaded_active_record_files.rb +103 -58
- data/lib/ardb/test_helpers.rb +2 -5
- data/lib/ardb/use_db_default.rb +4 -15
- data/lib/ardb/version.rb +1 -1
- data/script/determine_autoloaded_active_record_files.rb +11 -8
- data/test/helper.rb +9 -6
- data/test/support/factory.rb +17 -2
- data/test/support/fake_schema.rb +5 -0
- data/test/support/postgresql/migrations/.keep +0 -0
- data/test/support/postgresql/schema.rb +2 -0
- data/test/support/postgresql/setup_test_db.rb +51 -0
- data/test/support/relative_require_test_db_file.rb +2 -0
- data/test/support/require_test_db_file.rb +1 -0
- data/test/system/.keep +0 -0
- data/test/unit/adapter/base_tests.rb +163 -75
- data/test/unit/adapter/mysql_tests.rb +4 -20
- data/test/unit/adapter/postgresql_tests.rb +20 -28
- data/test/unit/adapter/sqlite_tests.rb +9 -12
- data/test/unit/adapter_spy_tests.rb +48 -71
- data/test/unit/ardb_tests.rb +338 -38
- data/test/unit/cli_tests.rb +334 -225
- data/test/unit/db_tests_tests.rb +3 -6
- data/test/unit/default_order_by_tests.rb +4 -8
- data/test/unit/migration_tests.rb +20 -17
- data/test/unit/record_spy_tests.rb +18 -23
- data/test/unit/relation_spy_tests.rb +17 -46
- data/test/unit/test_helpers_tests.rb +5 -20
- data/test/unit/use_db_default_tests.rb +9 -13
- metadata +111 -100
- data/lib/ardb/has_slug.rb +0 -107
- data/lib/ardb/migration_helpers.rb +0 -77
- data/lib/ardb/root_path.rb +0 -15
- data/test/unit/config_tests.rb +0 -58
- data/test/unit/has_slug_tests.rb +0 -341
- data/test/unit/migration_helpers_tests.rb +0 -59
data/test/unit/db_tests_tests.rb
CHANGED
@@ -1,10 +1,9 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require "assert"
|
2
|
+
require "ardb/db_tests"
|
3
3
|
|
4
|
-
require
|
4
|
+
require "active_record"
|
5
5
|
|
6
6
|
class Ardb::DbTests
|
7
|
-
|
8
7
|
class UnitTests < Assert::Context
|
9
8
|
desc "Ardb::DbTests"
|
10
9
|
setup do
|
@@ -31,7 +30,5 @@ class Ardb::DbTests
|
|
31
30
|
assert_true @transaction_called
|
32
31
|
assert_true block_yielded_to
|
33
32
|
end
|
34
|
-
|
35
33
|
end
|
36
|
-
|
37
34
|
end
|
@@ -1,11 +1,10 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require "assert"
|
2
|
+
require "ardb/default_order_by"
|
3
3
|
|
4
|
-
require
|
5
|
-
require
|
4
|
+
require "much-plugin"
|
5
|
+
require "ardb/record_spy"
|
6
6
|
|
7
7
|
module Ardb::DefaultOrderBy
|
8
|
-
|
9
8
|
class UnitTests < Assert::Context
|
10
9
|
desc "Ardb::DefaultOrderBy"
|
11
10
|
setup do
|
@@ -62,7 +61,6 @@ module Ardb::DefaultOrderBy
|
|
62
61
|
assert_equal [:ardb_default_order_by], callback.args
|
63
62
|
assert_equal({ :on => :create }, callback.options)
|
64
63
|
end
|
65
|
-
|
66
64
|
end
|
67
65
|
|
68
66
|
class InitTests < UnitTests
|
@@ -116,7 +114,5 @@ module Ardb::DefaultOrderBy
|
|
116
114
|
|
117
115
|
assert_equal current_order_by, subject.send(@order_by_attribute)
|
118
116
|
end
|
119
|
-
|
120
117
|
end
|
121
|
-
|
122
118
|
end
|
@@ -1,14 +1,17 @@
|
|
1
1
|
require "assert"
|
2
2
|
require "ardb/migration"
|
3
3
|
|
4
|
-
|
4
|
+
# This is needed to call `classify` on a string; if this isn"t manually required
|
5
|
+
# these tests can fail if activesupport hasn"t been loaded by activerecord; the
|
6
|
+
# `Migration` class will error saying `classify` is not a method on `String`
|
7
|
+
require "active_support/core_ext/string/inflections"
|
5
8
|
|
9
|
+
class Ardb::Migration
|
6
10
|
class UnitTests < Assert::Context
|
7
11
|
desc "Ardb::Migration"
|
8
12
|
setup do
|
9
13
|
@migration_class = Ardb::Migration
|
10
14
|
end
|
11
|
-
|
12
15
|
end
|
13
16
|
|
14
17
|
class InitTests < UnitTests
|
@@ -27,16 +30,18 @@ class Ardb::Migration
|
|
27
30
|
block.call(@file_spy)
|
28
31
|
end
|
29
32
|
|
30
|
-
@
|
31
|
-
@
|
33
|
+
@ardb_config = Factory.ardb_config
|
34
|
+
@id = Factory.migration_id
|
35
|
+
@migration = @migration_class.new(@ardb_config, @id)
|
32
36
|
end
|
33
37
|
subject{ @migration }
|
34
38
|
|
35
|
-
should have_readers
|
36
|
-
should have_readers :source
|
39
|
+
should have_readers :migrations_path, :identifier
|
40
|
+
should have_readers :class_name, :file_name, :file_path, :source
|
37
41
|
should have_imeths :save!
|
38
42
|
|
39
43
|
should "know its attrs" do
|
44
|
+
assert_equal @ardb_config.migrations_path, subject.migrations_path
|
40
45
|
assert_equal @id, subject.identifier
|
41
46
|
|
42
47
|
exp = @id.classify.pluralize
|
@@ -45,32 +50,31 @@ class Ardb::Migration
|
|
45
50
|
exp = "#{@time_now.strftime("%Y%m%d%H%M%S")}_#{@id.underscore}"
|
46
51
|
assert_equal exp, subject.file_name
|
47
52
|
|
48
|
-
exp = File.join(
|
53
|
+
exp = File.join(subject.migrations_path, "#{subject.file_name}.rb")
|
49
54
|
assert_equal exp, subject.file_path
|
50
55
|
|
51
|
-
|
52
|
-
|
53
|
-
|
56
|
+
exp_version = ActiveRecord::Migration.current_version
|
57
|
+
exp =
|
58
|
+
"class #{subject.class_name} < ActiveRecord::Migration[#{exp_version}]\n" \
|
54
59
|
" def change\n" \
|
55
|
-
" end\n
|
60
|
+
" end\n" \
|
56
61
|
"end\n"
|
57
62
|
assert_equal exp, subject.source
|
58
63
|
end
|
59
64
|
|
60
65
|
should "complain if no identifier is provided" do
|
61
66
|
assert_raises(NoIdentifierError) do
|
62
|
-
@migration_class.new([nil,
|
67
|
+
@migration_class.new(@ardb_config, [nil, ""].sample)
|
63
68
|
end
|
64
69
|
end
|
65
70
|
|
66
71
|
should "write the migration source to the migrations path on save" do
|
67
72
|
subject.save!
|
68
73
|
|
69
|
-
assert_equal [
|
70
|
-
assert_equal [subject.file_path,
|
71
|
-
assert_equal [subject.source],
|
74
|
+
assert_equal [subject.migrations_path], @mkdir_called_with
|
75
|
+
assert_equal [subject.file_path, "w"], @file_open_called_with
|
76
|
+
assert_equal [subject.source], @file_spy.write_called_with
|
72
77
|
end
|
73
|
-
|
74
78
|
end
|
75
79
|
|
76
80
|
class FileSpy
|
@@ -84,5 +88,4 @@ class Ardb::Migration
|
|
84
88
|
@write_called_with = args
|
85
89
|
end
|
86
90
|
end
|
87
|
-
|
88
91
|
end
|
@@ -1,10 +1,9 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require "assert"
|
2
|
+
require "ardb/record_spy"
|
3
3
|
|
4
|
-
require
|
4
|
+
require "much-plugin"
|
5
5
|
|
6
6
|
module Ardb::RecordSpy
|
7
|
-
|
8
7
|
class UnitTests < Assert::Context
|
9
8
|
desc "Ardb::RecordSpy"
|
10
9
|
setup do
|
@@ -46,8 +45,8 @@ module Ardb::RecordSpy
|
|
46
45
|
end
|
47
46
|
|
48
47
|
should "allow reading and writing the record's table name" do
|
49
|
-
subject.table_name =
|
50
|
-
assert_equal
|
48
|
+
subject.table_name = "my_records"
|
49
|
+
assert_equal "my_records", subject.table_name
|
51
50
|
end
|
52
51
|
|
53
52
|
should "default its associations" do
|
@@ -71,18 +70,18 @@ module Ardb::RecordSpy
|
|
71
70
|
end
|
72
71
|
|
73
72
|
should "add an association config with #has_one" do
|
74
|
-
subject.has_one :linking, :class_name =>
|
73
|
+
subject.has_one :linking, :class_name => "Linking"
|
75
74
|
association = subject.associations.last
|
76
75
|
assert_equal :has_one, association.type
|
77
76
|
assert_equal :linking, association.name
|
78
|
-
assert_equal
|
77
|
+
assert_equal "Linking", association.options[:class_name]
|
79
78
|
end
|
80
79
|
|
81
80
|
should "default its validations" do
|
82
81
|
assert_equal [], subject.validations
|
83
82
|
end
|
84
83
|
|
85
|
-
should "add a validation config for
|
84
|
+
should "add a validation config for \"*_of\" validations" do
|
86
85
|
subject.validates_presence_of :name, :email, :on => :create
|
87
86
|
validation = subject.validations.last
|
88
87
|
assert_equal :presence, validation.type
|
@@ -145,14 +144,14 @@ module Ardb::RecordSpy
|
|
145
144
|
|
146
145
|
should "add a callback config with a block" do
|
147
146
|
subject.before_validation(:on => :create) do
|
148
|
-
self.name =
|
147
|
+
self.name = "test"
|
149
148
|
end
|
150
149
|
callback = subject.callbacks.last
|
151
150
|
assert_equal :before_validation, callback.type
|
152
151
|
assert_equal :create, callback.options[:on]
|
153
152
|
record_spy = subject.new
|
154
153
|
record_spy.instance_eval(&callback.block)
|
155
|
-
assert_equal
|
154
|
+
assert_equal "test", record_spy.name
|
156
155
|
end
|
157
156
|
|
158
157
|
should "default its custom callback types" do
|
@@ -177,7 +176,7 @@ module Ardb::RecordSpy
|
|
177
176
|
assert_respond_to "around_#{name}", subject
|
178
177
|
assert_respond_to "after_#{name}", subject
|
179
178
|
|
180
|
-
callback_name = ["before_#{name}", "around_#{name}", "after_#{name}"].
|
179
|
+
callback_name = ["before_#{name}", "around_#{name}", "after_#{name}"].sample
|
181
180
|
method_name = Factory.string
|
182
181
|
subject.send(callback_name, method_name)
|
183
182
|
callback = subject.callbacks.last
|
@@ -286,7 +285,6 @@ module Ardb::RecordSpy
|
|
286
285
|
subject.only(*only_args)
|
287
286
|
assert_equal only_args, only_called_with
|
288
287
|
end
|
289
|
-
|
290
288
|
end
|
291
289
|
|
292
290
|
class GeneratorTests < UnitTests
|
@@ -305,7 +303,6 @@ module Ardb::RecordSpy
|
|
305
303
|
assert @instance.respond_to? :name
|
306
304
|
assert @instance.respond_to? :name=
|
307
305
|
end
|
308
|
-
|
309
306
|
end
|
310
307
|
|
311
308
|
class InstanceTests < UnitTests
|
@@ -319,20 +316,20 @@ module Ardb::RecordSpy
|
|
319
316
|
should have_imeths :manually_run_callbacks, :run_callbacks
|
320
317
|
|
321
318
|
should "allow spying the update_column method by just writing the value" do
|
322
|
-
assert_not_equal
|
319
|
+
assert_not_equal "updated", subject.name
|
323
320
|
|
324
|
-
subject.update_column(:name,
|
325
|
-
assert_equal
|
321
|
+
subject.update_column(:name, "updated")
|
322
|
+
assert_equal "updated", subject.name
|
326
323
|
end
|
327
324
|
|
328
325
|
should "have accessors for each association defined" do
|
329
326
|
assert_nil subject.bt_thing
|
330
|
-
subject.bt_thing =
|
331
|
-
assert_equal
|
327
|
+
subject.bt_thing = "something"
|
328
|
+
assert_equal "something", subject.bt_thing
|
332
329
|
|
333
330
|
assert_nil subject.ho_thing
|
334
|
-
subject.ho_thing =
|
335
|
-
assert_equal
|
331
|
+
subject.ho_thing = "other thing"
|
332
|
+
assert_equal "other thing", subject.ho_thing
|
336
333
|
|
337
334
|
assert_empty subject.hm_things
|
338
335
|
subject.hm_things = [1,2,3]
|
@@ -355,7 +352,6 @@ module Ardb::RecordSpy
|
|
355
352
|
assert_includes name, subject.manually_run_callbacks
|
356
353
|
assert_true block_called
|
357
354
|
end
|
358
|
-
|
359
355
|
end
|
360
356
|
|
361
357
|
class MyRecord
|
@@ -366,5 +362,4 @@ module Ardb::RecordSpy
|
|
366
362
|
has_one :ho_thing
|
367
363
|
has_many :hm_things
|
368
364
|
end
|
369
|
-
|
370
365
|
end
|
@@ -1,8 +1,7 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require "assert"
|
2
|
+
require "ardb/relation_spy"
|
3
3
|
|
4
4
|
class Ardb::RelationSpy
|
5
|
-
|
6
5
|
class UnitTests < Assert::Context
|
7
6
|
desc "Ardb::RelationSpy"
|
8
7
|
setup do
|
@@ -51,11 +50,11 @@ class Ardb::RelationSpy
|
|
51
50
|
end
|
52
51
|
|
53
52
|
should "build a fake sql string for its applied expressions using `to_sql`" do
|
54
|
-
subject.select
|
55
|
-
subject.from
|
56
|
-
subject.joins
|
53
|
+
subject.select "column"
|
54
|
+
subject.from "table"
|
55
|
+
subject.joins "my_table.my_column ON my_table.my_column = table.column"
|
57
56
|
|
58
|
-
expected = subject.applied.map(&:to_sql).join(
|
57
|
+
expected = subject.applied.map(&:to_sql).join(", ")
|
59
58
|
assert_equal expected, subject.to_sql
|
60
59
|
end
|
61
60
|
|
@@ -70,7 +69,6 @@ class Ardb::RelationSpy
|
|
70
69
|
assert_nil subject.limit_value
|
71
70
|
assert_nil subject.offset_value
|
72
71
|
end
|
73
|
-
|
74
72
|
end
|
75
73
|
|
76
74
|
class SelectTests < UnitTests
|
@@ -85,7 +83,6 @@ class Ardb::RelationSpy
|
|
85
83
|
assert_equal :select, @applied.type
|
86
84
|
assert_equal [ :column_a, :column_b ], @applied.args
|
87
85
|
end
|
88
|
-
|
89
86
|
end
|
90
87
|
|
91
88
|
class FromTests < UnitTests
|
@@ -100,7 +97,6 @@ class Ardb::RelationSpy
|
|
100
97
|
assert_equal :from, @applied.type
|
101
98
|
assert_equal [ "some SQL" ], @applied.args
|
102
99
|
end
|
103
|
-
|
104
100
|
end
|
105
101
|
|
106
102
|
class IncludesTests < UnitTests
|
@@ -115,7 +111,6 @@ class Ardb::RelationSpy
|
|
115
111
|
assert_equal :includes, @applied.type
|
116
112
|
assert_equal [ :table_a, :table_b ], @applied.args
|
117
113
|
end
|
118
|
-
|
119
114
|
end
|
120
115
|
|
121
116
|
class JoinsTests < UnitTests
|
@@ -130,22 +125,20 @@ class Ardb::RelationSpy
|
|
130
125
|
assert_equal :joins, @applied.type
|
131
126
|
assert_equal [ :table_a, :table_b ], @applied.args
|
132
127
|
end
|
133
|
-
|
134
128
|
end
|
135
129
|
|
136
130
|
class WhereTests < UnitTests
|
137
131
|
desc "where"
|
138
132
|
setup do
|
139
|
-
@relation_spy.where :column_a =>
|
133
|
+
@relation_spy.where :column_a => "some value"
|
140
134
|
@applied = subject.applied.first
|
141
135
|
end
|
142
136
|
|
143
137
|
should "add a where applied expression with the passed args" do
|
144
138
|
assert_instance_of AppliedExpression, @applied
|
145
139
|
assert_equal :where, @applied.type
|
146
|
-
assert_equal [ { :column_a =>
|
140
|
+
assert_equal [ { :column_a => "some value" } ], @applied.args
|
147
141
|
end
|
148
|
-
|
149
142
|
end
|
150
143
|
|
151
144
|
class OrderTests < UnitTests
|
@@ -160,7 +153,6 @@ class Ardb::RelationSpy
|
|
160
153
|
assert_equal :order, @applied.type
|
161
154
|
assert_equal [ :column_a, :column_b ], @applied.args
|
162
155
|
end
|
163
|
-
|
164
156
|
end
|
165
157
|
|
166
158
|
class ReverseOrderTests < UnitTests
|
@@ -174,7 +166,6 @@ class Ardb::RelationSpy
|
|
174
166
|
assert_instance_of AppliedExpression, @applied
|
175
167
|
assert_equal :reverse_order, @applied.type
|
176
168
|
end
|
177
|
-
|
178
169
|
end
|
179
170
|
|
180
171
|
class GroupTests < UnitTests
|
@@ -189,22 +180,20 @@ class Ardb::RelationSpy
|
|
189
180
|
assert_equal :group, @applied.type
|
190
181
|
assert_equal [ :column_a, :column_b ], @applied.args
|
191
182
|
end
|
192
|
-
|
193
183
|
end
|
194
184
|
|
195
185
|
class HavingTests < UnitTests
|
196
186
|
desc "having"
|
197
187
|
setup do
|
198
|
-
@relation_spy.having
|
188
|
+
@relation_spy.having "COUNT(column_a) > 0"
|
199
189
|
@applied = subject.applied.first
|
200
190
|
end
|
201
191
|
|
202
192
|
should "add a having applied expression with the passed args" do
|
203
193
|
assert_instance_of AppliedExpression, @applied
|
204
194
|
assert_equal :having, @applied.type
|
205
|
-
assert_equal [
|
195
|
+
assert_equal [ "COUNT(column_a) > 0" ], @applied.args
|
206
196
|
end
|
207
|
-
|
208
197
|
end
|
209
198
|
|
210
199
|
class ReadonlyTests < UnitTests
|
@@ -219,7 +208,6 @@ class Ardb::RelationSpy
|
|
219
208
|
assert_equal :readonly, @applied.type
|
220
209
|
assert_equal [ true ], @applied.args
|
221
210
|
end
|
222
|
-
|
223
211
|
end
|
224
212
|
|
225
213
|
class LimitTests < UnitTests
|
@@ -238,7 +226,6 @@ class Ardb::RelationSpy
|
|
238
226
|
should "set it's limit value" do
|
239
227
|
assert_equal 100, subject.limit_value
|
240
228
|
end
|
241
|
-
|
242
229
|
end
|
243
230
|
|
244
231
|
class OffsetTests < UnitTests
|
@@ -257,13 +244,12 @@ class Ardb::RelationSpy
|
|
257
244
|
should "set it's offset value" do
|
258
245
|
assert_equal 100, subject.offset_value
|
259
246
|
end
|
260
|
-
|
261
247
|
end
|
262
248
|
|
263
249
|
class MergeWithARelationSpyTests < UnitTests
|
264
250
|
desc "merge with a relation spy"
|
265
251
|
setup do
|
266
|
-
@other_relation_spy = Ardb::RelationSpy.new.select(
|
252
|
+
@other_relation_spy = Ardb::RelationSpy.new.select("column").joins("table")
|
267
253
|
@relation_spy.merge @other_relation_spy
|
268
254
|
end
|
269
255
|
|
@@ -272,13 +258,12 @@ class Ardb::RelationSpy
|
|
272
258
|
assert_includes applied, @relation_spy.applied
|
273
259
|
end
|
274
260
|
end
|
275
|
-
|
276
261
|
end
|
277
262
|
|
278
263
|
class MergeWithNonRelationSpyTests < UnitTests
|
279
264
|
desc "merge without a relation spy"
|
280
265
|
setup do
|
281
|
-
@fake_relation =
|
266
|
+
@fake_relation = "relation"
|
282
267
|
@relation_spy.merge @fake_relation
|
283
268
|
@applied = subject.applied.first
|
284
269
|
end
|
@@ -288,27 +273,25 @@ class Ardb::RelationSpy
|
|
288
273
|
assert_equal :merge, @applied.type
|
289
274
|
assert_equal [ @fake_relation ], @applied.args
|
290
275
|
end
|
291
|
-
|
292
276
|
end
|
293
277
|
|
294
278
|
class MergeWithSelfTests < UnitTests
|
295
279
|
desc "merge with itself"
|
296
280
|
setup do
|
297
|
-
@fake_relation =
|
281
|
+
@fake_relation = "relation"
|
298
282
|
@relation_spy.merge @relation_spy
|
299
283
|
end
|
300
284
|
|
301
285
|
should "not alter the applied expressions" do
|
302
286
|
assert_empty subject.applied
|
303
287
|
end
|
304
|
-
|
305
288
|
end
|
306
289
|
|
307
290
|
class WithExpressionsTests < UnitTests
|
308
291
|
setup do
|
309
|
-
@relation_spy.select(
|
310
|
-
@relation_spy.where(:column =>
|
311
|
-
@relation_spy.group(
|
292
|
+
@relation_spy.select("column").includes("table").joins("table")
|
293
|
+
@relation_spy.where(:column => "value").order("column")
|
294
|
+
@relation_spy.group("column").having("count(*) > 1")
|
312
295
|
@relation_spy.limit(1).offset(1)
|
313
296
|
end
|
314
297
|
end
|
@@ -345,7 +328,6 @@ class Ardb::RelationSpy
|
|
345
328
|
relation_spy = subject.except(:offset)
|
346
329
|
assert_nil relation_spy.offset_value
|
347
330
|
end
|
348
|
-
|
349
331
|
end
|
350
332
|
|
351
333
|
class OnlyTests < WithExpressionsTests
|
@@ -380,7 +362,6 @@ class Ardb::RelationSpy
|
|
380
362
|
relation_spy = subject.only(:select)
|
381
363
|
assert_nil relation_spy.offset_value
|
382
364
|
end
|
383
|
-
|
384
365
|
end
|
385
366
|
|
386
367
|
class WithResultsTests < UnitTests
|
@@ -401,11 +382,9 @@ class Ardb::RelationSpy
|
|
401
382
|
should "raise a not found error if a result can't be found" do
|
402
383
|
assert_raises(NotFoundError){ subject.find(1000) }
|
403
384
|
end
|
404
|
-
|
405
385
|
end
|
406
386
|
|
407
387
|
class FirstTests < WithResultsTests
|
408
|
-
|
409
388
|
should "return the first item from `all` using `first`" do
|
410
389
|
assert_equal subject.all.first, subject.first
|
411
390
|
subject.offset 2
|
@@ -418,11 +397,9 @@ class Ardb::RelationSpy
|
|
418
397
|
subject.limit 0
|
419
398
|
assert_raises(NotFoundError){ subject.first! }
|
420
399
|
end
|
421
|
-
|
422
400
|
end
|
423
401
|
|
424
402
|
class LastTests < WithResultsTests
|
425
|
-
|
426
403
|
should "return the last item from `all` using `last`" do
|
427
404
|
assert_equal subject.all.last, subject.last
|
428
405
|
subject.limit 2
|
@@ -435,7 +412,6 @@ class Ardb::RelationSpy
|
|
435
412
|
subject.limit 0
|
436
413
|
assert_raises(NotFoundError){ subject.last! }
|
437
414
|
end
|
438
|
-
|
439
415
|
end
|
440
416
|
|
441
417
|
class AllTests < WithResultsTests
|
@@ -458,7 +434,6 @@ class Ardb::RelationSpy
|
|
458
434
|
subject.offset 2
|
459
435
|
assert_equal @results[2, 2], subject.all
|
460
436
|
end
|
461
|
-
|
462
437
|
end
|
463
438
|
|
464
439
|
class CountTests < WithResultsTests
|
@@ -469,7 +444,6 @@ class Ardb::RelationSpy
|
|
469
444
|
subject.limit 2
|
470
445
|
assert_equal subject.all.size, subject.count
|
471
446
|
end
|
472
|
-
|
473
447
|
end
|
474
448
|
|
475
449
|
class PluckTests < WithResultsTests
|
@@ -484,13 +458,12 @@ class Ardb::RelationSpy
|
|
484
458
|
exp = [@column_value] * @results.size
|
485
459
|
assert_equal exp, @relation_spy.pluck(@column_name)
|
486
460
|
end
|
487
|
-
|
488
461
|
end
|
489
462
|
|
490
463
|
class AppliedExpressionTests < UnitTests
|
491
464
|
desc "AppliedExpression"
|
492
465
|
setup do
|
493
|
-
@applied_expression = AppliedExpression.new(:select,
|
466
|
+
@applied_expression = AppliedExpression.new(:select, "column")
|
494
467
|
end
|
495
468
|
subject{ @applied_expression }
|
496
469
|
|
@@ -501,9 +474,7 @@ class Ardb::RelationSpy
|
|
501
474
|
expected = "#{subject.type}: #{subject.args.inspect}"
|
502
475
|
assert_equal expected, subject.to_sql
|
503
476
|
end
|
504
|
-
|
505
477
|
end
|
506
478
|
|
507
479
|
Result = Struct.new(:id)
|
508
|
-
|
509
480
|
end
|