ardb 0.29.1 → 0.29.2

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.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/.l.yml +8 -0
  3. data/.rubocop.yml +3 -0
  4. data/.t.yml +6 -0
  5. data/Gemfile +4 -2
  6. data/ardb.gemspec +9 -6
  7. data/bin/ardb +2 -0
  8. data/lib/ardb.rb +75 -61
  9. data/lib/ardb/adapter/base.rb +40 -19
  10. data/lib/ardb/adapter/mysql.rb +2 -0
  11. data/lib/ardb/adapter/postgresql.rb +36 -25
  12. data/lib/ardb/adapter/sqlite.rb +7 -7
  13. data/lib/ardb/adapter_spy.rb +16 -14
  14. data/lib/ardb/cli.rb +23 -18
  15. data/lib/ardb/cli/clirb.rb +5 -0
  16. data/lib/ardb/cli/commands.rb +184 -95
  17. data/lib/ardb/db_tests.rb +2 -0
  18. data/lib/ardb/default_order_by.rb +13 -11
  19. data/lib/ardb/migration.rb +7 -4
  20. data/lib/ardb/record_spy.rb +42 -38
  21. data/lib/ardb/relation_spy.rb +27 -25
  22. data/lib/ardb/require_autoloaded_active_record_files.rb +3 -1
  23. data/lib/ardb/test_helpers.rb +11 -9
  24. data/lib/ardb/use_db_default.rb +9 -7
  25. data/lib/ardb/version.rb +3 -1
  26. data/script/determine_autoloaded_active_record_files.rb +22 -20
  27. data/test/helper.rb +2 -0
  28. data/test/support/factory.rb +2 -1
  29. data/test/support/fake_schema.rb +3 -1
  30. data/test/support/postgresql/schema.rb +3 -1
  31. data/test/support/postgresql/setup_test_db.rb +3 -1
  32. data/test/support/relative_require_test_db_file.rb +1 -0
  33. data/test/support/require_test_db_file.rb +1 -0
  34. data/test/unit/adapter/base_tests.rb +9 -5
  35. data/test/unit/adapter/mysql_tests.rb +2 -0
  36. data/test/unit/adapter/postgresql_tests.rb +14 -14
  37. data/test/unit/adapter/sqlite_tests.rb +2 -0
  38. data/test/unit/adapter_spy_tests.rb +4 -1
  39. data/test/unit/ardb_tests.rb +28 -13
  40. data/test/unit/cli_tests.rb +47 -34
  41. data/test/unit/db_tests_tests.rb +4 -1
  42. data/test/unit/default_order_by_tests.rb +18 -13
  43. data/test/unit/migration_tests.rb +8 -5
  44. data/test/unit/record_spy_tests.rb +21 -14
  45. data/test/unit/relation_spy_tests.rb +28 -22
  46. data/test/unit/test_helpers_tests.rb +4 -1
  47. data/test/unit/use_db_default_tests.rb +16 -7
  48. metadata +27 -11
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "assert"
2
4
  require "ardb/cli"
3
5
 
@@ -27,16 +29,19 @@ class Ardb::CLI
27
29
  should "know its commands" do
28
30
  assert_equal 9, COMMANDS.size
29
31
 
30
- assert_instance_of InvalidCommand, COMMANDS[Factory.string]
31
- assert_instance_of ConnectCommand, COMMANDS["connect"]
32
- assert_instance_of CreateCommand, COMMANDS["create"]
33
- assert_instance_of DropCommand, COMMANDS["drop"]
34
- assert_instance_of GenerateMigrationCommand, COMMANDS["generate-migration"]
35
- assert_instance_of MigrateCommand, COMMANDS["migrate"]
36
- assert_instance_of MigrateUpCommand, COMMANDS["migrate-up"]
37
- assert_instance_of MigrateDownCommand, COMMANDS["migrate-down"]
38
- assert_instance_of MigrateForwardCommand, COMMANDS["migrate-forward"]
39
- assert_instance_of MigrateBackwardCommand, COMMANDS["migrate-backward"]
32
+ assert_instance_of InvalidCommand, COMMANDS[Factory.string]
33
+ assert_instance_of ConnectCommand, COMMANDS["connect"]
34
+ assert_instance_of CreateCommand, COMMANDS["create"]
35
+ assert_instance_of DropCommand, COMMANDS["drop"]
36
+ assert_instance_of(
37
+ GenerateMigrationCommand,
38
+ COMMANDS["generate-migration"],
39
+ )
40
+ assert_instance_of MigrateCommand, COMMANDS["migrate"]
41
+ assert_instance_of MigrateUpCommand, COMMANDS["migrate-up"]
42
+ assert_instance_of MigrateDownCommand, COMMANDS["migrate-down"]
43
+ assert_instance_of MigrateForwardCommand, COMMANDS["migrate-forward"]
44
+ assert_instance_of MigrateBackwardCommand, COMMANDS["migrate-backward"]
40
45
  end
41
46
  end
42
47
 
@@ -58,9 +63,9 @@ class Ardb::CLI
58
63
  setup do
59
64
  @command_name = Factory.string
60
65
  @command_class = Class.new{ include ValidCommand }
61
- Assert.stub(@command_class, :command_name) { @command_name }
66
+ Assert.stub(@command_class, :command_name){ @command_name }
62
67
 
63
- @command_spy = CommandSpy.new(@command_name)
68
+ @command_spy = CommandSpy.new(@command_name)
64
69
  Assert.stub(@command_class, :new){ @command_spy }
65
70
  COMMANDS.add(@command_class)
66
71
 
@@ -143,7 +148,7 @@ class Ardb::CLI
143
148
  class RunWithHelpTests < RunSetupTests
144
149
  desc "and run with the help switch"
145
150
  setup do
146
- @cli.run([ "--help" ])
151
+ @cli.run(["--help"])
147
152
  end
148
153
 
149
154
  should "output the invalid command's help" do
@@ -159,7 +164,7 @@ class Ardb::CLI
159
164
  class RunWithVersionTests < RunSetupTests
160
165
  desc "and run with the version switch"
161
166
  setup do
162
- @cli.run([ "--version" ])
167
+ @cli.run(["--version"])
163
168
  end
164
169
 
165
170
  should "output its version" do
@@ -213,8 +218,8 @@ class Ardb::CLI
213
218
  end
214
219
 
215
220
  should "parse its argv on run" do
216
- assert_raises(CLIRB::HelpExit){ subject.new.run([ "--help" ]) }
217
- assert_raises(CLIRB::VersionExit){ subject.new.run([ "--version" ]) }
221
+ assert_raises(CLIRB::HelpExit){ subject.new.run(["--help"]) }
222
+ assert_raises(CLIRB::VersionExit){ subject.new.run(["--version"]) }
218
223
  end
219
224
 
220
225
  should "raise a help exit if its name is empty" do
@@ -273,7 +278,7 @@ class Ardb::CLI
273
278
 
274
279
  should "take custom CLIRB build procs" do
275
280
  cmd = @command_class.new do
276
- option "test", "testing", :abbrev => "t"
281
+ option "test", "testing", abbrev: "t"
277
282
  end
278
283
  cmd.run(["-t"], @stdout, @stderr)
279
284
  assert_true cmd.clirb.opts["test"]
@@ -290,8 +295,8 @@ class Ardb::CLI
290
295
  end
291
296
 
292
297
  should "know its command help" do
293
- Assert.stub(subject, :command_name) { "some-command" }
294
- Assert.stub(subject, :command_summary) { "some-summary" }
298
+ Assert.stub(subject, :command_name){ "some-command" }
299
+ Assert.stub(subject, :command_summary){ "some-summary" }
295
300
 
296
301
  exp = "Usage: ardb #{subject.command_name} [options]\n\n" \
297
302
  "Options: #{subject.clirb}\n" \
@@ -326,7 +331,9 @@ class Ardb::CLI
326
331
  assert_equal [false], @ardb_init_called_with
327
332
  assert_true @adapter_spy.connect_db_called?
328
333
 
329
- exp = "connected to #{Ardb.config.adapter} db #{Ardb.config.database.inspect}\n"
334
+ exp =
335
+ "connected to #{Ardb.config.adapter} "\
336
+ "db #{Ardb.config.database.inspect}\n"
330
337
  assert_equal exp, @stdout.read
331
338
  end
332
339
 
@@ -372,7 +379,8 @@ class Ardb::CLI
372
379
  assert_equal [false], @ardb_init_called_with
373
380
  assert_true @adapter_spy.create_db_called?
374
381
 
375
- exp = "created #{Ardb.config.adapter} db #{Ardb.config.database.inspect}\n"
382
+ exp =
383
+ "created #{Ardb.config.adapter} db #{Ardb.config.database.inspect}\n"
376
384
  assert_equal exp, @stdout.read
377
385
  end
378
386
 
@@ -414,7 +422,8 @@ class Ardb::CLI
414
422
  assert_equal [true], @ardb_init_called_with
415
423
  assert_true @adapter_spy.drop_db_called?
416
424
 
417
- exp = "dropped #{Ardb.config.adapter} db #{Ardb.config.database.inspect}\n"
425
+ exp =
426
+ "dropped #{Ardb.config.adapter} db #{Ardb.config.database.inspect}\n"
418
427
  assert_equal exp, @stdout.read
419
428
  end
420
429
 
@@ -470,19 +479,20 @@ class Ardb::CLI
470
479
  assert_equal exp, @stdout.read
471
480
  end
472
481
 
473
- should "re-raise a specific argument error on migration \"no identifer\" errors" do
474
- Assert.stub(@migration_class, :new){ raise Ardb::Migration::NoIdentifierError }
475
- err = nil
476
- begin
477
- cmd = @command_class.new
478
- cmd.run([])
479
- rescue ArgumentError => err
482
+ should "re-raise a specific argument error on "\
483
+ "migration \"no identifer\" errors" do
484
+ Assert.stub(@migration_class, :new) do
485
+ raise Ardb::Migration::NoIdentifierError
480
486
  end
481
487
 
482
- assert_not_nil err
488
+ ex =
489
+ assert_that{
490
+ cmd = @command_class.new
491
+ cmd.run([])
492
+ }.raises(ArgumentError)
483
493
  exp = "MIGRATION-NAME must be provided"
484
- assert_equal exp, err.message
485
- assert_not_empty err.backtrace
494
+ assert_equal exp, ex.message
495
+ assert_not_empty ex.backtrace
486
496
  end
487
497
 
488
498
  should "output any errors and raise an exit error when run" do
@@ -490,7 +500,9 @@ class Ardb::CLI
490
500
  err.set_backtrace(Factory.integer(3).times.map{ Factory.path })
491
501
  Assert.stub(@migration_class, :new){ raise err }
492
502
 
493
- assert_raises(CommandExitError){ subject.run([@identifier], @stdout, @stderr) }
503
+ assert_raises(CommandExitError) do
504
+ subject.run([@identifier], @stdout, @stderr)
505
+ end
494
506
  err_output = @stderr.read
495
507
 
496
508
  assert_includes err.to_s, err_output
@@ -532,7 +544,8 @@ class Ardb::CLI
532
544
  assert_true @adapter_spy.dump_schema_called?
533
545
  end
534
546
 
535
- should "only init ardb and migrate when run with no schema dump env var set" do
547
+ should "only init ardb and migrate when run with no schema dump "\
548
+ "env var set" do
536
549
  ENV["ARDB_MIGRATE_NO_SCHEMA"] = "yes"
537
550
  subject.run([], @stdout, @stderr)
538
551
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "assert"
2
4
  require "ardb/db_tests"
3
5
 
@@ -19,7 +21,8 @@ class Ardb::DbTests
19
21
  assert subject < Assert::Context
20
22
  end
21
23
 
22
- should "add an around callback that runs tests in a transaction that rolls back" do
24
+ should "add an around callback that runs tests in a transaction that "\
25
+ "rolls back" do
23
26
  assert_equal 1, subject.arounds.size
24
27
  callback = subject.arounds.first
25
28
 
@@ -1,7 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "assert"
2
4
  require "ardb/default_order_by"
3
5
 
4
- require "much-plugin"
6
+ require "much-mixin"
5
7
  require "ardb/record_spy"
6
8
 
7
9
  module Ardb::DefaultOrderBy
@@ -9,7 +11,7 @@ module Ardb::DefaultOrderBy
9
11
  desc "Ardb::DefaultOrderBy"
10
12
  setup do
11
13
  order_by_attribute = @order_by_attribute = Factory.string.to_sym
12
- @scope_proc = proc{ self.class.where(:grouping => self.grouping) }
14
+ @scope_proc = proc{ self.class.where(grouping: grouping) }
13
15
  @record_class = Ardb::RecordSpy.new do
14
16
  include Ardb::DefaultOrderBy
15
17
  attr_accessor order_by_attribute, :grouping
@@ -20,8 +22,8 @@ module Ardb::DefaultOrderBy
20
22
  should have_imeths :default_order_by
21
23
  should have_imeths :ardb_default_order_by_config
22
24
 
23
- should "use much-plugin" do
24
- assert_includes MuchPlugin, Ardb::DefaultOrderBy
25
+ should "use much-mixin" do
26
+ assert_includes MuchMixin, Ardb::DefaultOrderBy
25
27
  end
26
28
 
27
29
  should "know its default attribute, preprocessor and separator" do
@@ -44,8 +46,8 @@ module Ardb::DefaultOrderBy
44
46
 
45
47
  should "allow customizing the config using `default_order_by`" do
46
48
  subject.default_order_by({
47
- :attribute => @order_by_attribute,
48
- :scope => @scope_proc
49
+ attribute: @order_by_attribute,
50
+ scope: @scope_proc,
49
51
  })
50
52
 
51
53
  config = subject.ardb_default_order_by_config
@@ -59,7 +61,7 @@ module Ardb::DefaultOrderBy
59
61
  callback = subject.callbacks.find{ |v| v.type == :before_validation }
60
62
  assert_not_nil callback
61
63
  assert_equal [:ardb_default_order_by], callback.args
62
- assert_equal({ :on => :create }, callback.options)
64
+ assert_equal({ on: :create }, callback.options)
63
65
  end
64
66
  end
65
67
 
@@ -67,11 +69,12 @@ module Ardb::DefaultOrderBy
67
69
  desc "when init"
68
70
  setup do
69
71
  @record_class.default_order_by({
70
- :attribute => @order_by_attribute,
71
- :scope => @scope_proc
72
+ attribute: @order_by_attribute,
73
+ scope: @scope_proc,
72
74
  })
73
75
  @current_max = Factory.integer
74
- @record_class.relation_spy.maximum_values[@order_by_attribute] = @current_max
76
+ @record_class.relation_spy.maximum_values[@order_by_attribute] =
77
+ @current_max
75
78
 
76
79
  @record = @record_class.new
77
80
  @record.grouping = Factory.string
@@ -84,7 +87,8 @@ module Ardb::DefaultOrderBy
84
87
  assert_equal @current_max + 1, subject.send(@order_by_attribute)
85
88
  end
86
89
 
87
- should "reset its order-by to a start value when there isn't a current max" do
90
+ should "reset its order-by to a start value when there isn't a "\
91
+ "current max" do
88
92
  @record_class.relation_spy.maximum_values.delete(@order_by_attribute)
89
93
 
90
94
  subject.instance_eval{ reset_order_by }
@@ -98,7 +102,7 @@ module Ardb::DefaultOrderBy
98
102
  assert_equal 1, @record_class.relation_spy.applied.size
99
103
  applied_expression = @record_class.relation_spy.applied.last
100
104
  assert_equal :where, applied_expression.type
101
- assert_equal [{ :grouping => subject.grouping }], applied_expression.args
105
+ assert_equal [{ grouping: subject.grouping }], applied_expression.args
102
106
  end
103
107
 
104
108
  should "reset its order-by using `ardb_default_order_by`" do
@@ -107,7 +111,8 @@ module Ardb::DefaultOrderBy
107
111
  assert_equal @current_max + 1, subject.send(@order_by_attribute)
108
112
  end
109
113
 
110
- should "not reset its order-by if its already set using `ardb_default_order_by`" do
114
+ should "not reset its order-by if its already set using "\
115
+ "`ardb_default_order_by`" do
111
116
  current_order_by = Factory.integer
112
117
  subject.send("#{@order_by_attribute}=", current_order_by)
113
118
  subject.instance_eval{ ardb_default_order_by }
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "assert"
2
4
  require "ardb/migration"
3
5
 
@@ -36,7 +38,7 @@ class Ardb::Migration
36
38
  end
37
39
  subject{ @migration }
38
40
 
39
- should have_readers :migrations_path, :identifier
41
+ should have_readers :migrations_path, :identifier
40
42
  should have_readers :class_name, :file_name, :file_path, :source
41
43
  should have_imeths :save!
42
44
 
@@ -55,10 +57,11 @@ class Ardb::Migration
55
57
 
56
58
  exp_version = ActiveRecord::Migration.current_version
57
59
  exp =
58
- "class #{subject.class_name} < ActiveRecord::Migration[#{exp_version}]\n" \
59
- " def change\n" \
60
- " end\n" \
61
- "end\n"
60
+ "class #{subject.class_name} "\
61
+ "< ActiveRecord::Migration[#{exp_version}]\n" \
62
+ " def change\n" \
63
+ " end\n" \
64
+ "end\n"
62
65
  assert_equal exp, subject.source
63
66
  end
64
67
 
@@ -1,7 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "assert"
2
4
  require "ardb/record_spy"
3
5
 
4
- require "much-plugin"
6
+ require "much-mixin"
5
7
 
6
8
  module Ardb::RecordSpy
7
9
  class UnitTests < Assert::Context
@@ -40,8 +42,8 @@ module Ardb::RecordSpy
40
42
  should have_imeths :group, :having, :order, :reverse_order, :readonly
41
43
  should have_imeths :limit, :offset, :merge, :except, :only
42
44
 
43
- should "use much-plugin" do
44
- assert_includes MuchPlugin, Ardb::RecordSpy
45
+ should "use much-mixin" do
46
+ assert_includes MuchMixin, Ardb::RecordSpy
45
47
  end
46
48
 
47
49
  should "allow reading and writing the record's table name" do
@@ -54,7 +56,7 @@ module Ardb::RecordSpy
54
56
  end
55
57
 
56
58
  should "add an association config with #belongs_to" do
57
- subject.belongs_to :area, :foreign_key => :area_id
59
+ subject.belongs_to :area, foreign_key: :area_id
58
60
  association = subject.associations.last
59
61
  assert_equal :belongs_to, association.type
60
62
  assert_equal :area, association.name
@@ -62,7 +64,7 @@ module Ardb::RecordSpy
62
64
  end
63
65
 
64
66
  should "add an association config with #has_many" do
65
- subject.has_many :comments, :as => :parent
67
+ subject.has_many :comments, as: :parent
66
68
  association = subject.associations.last
67
69
  assert_equal :has_many, association.type
68
70
  assert_equal :comments, association.name
@@ -70,7 +72,7 @@ module Ardb::RecordSpy
70
72
  end
71
73
 
72
74
  should "add an association config with #has_one" do
73
- subject.has_one :linking, :class_name => "Linking"
75
+ subject.has_one :linking, class_name: "Linking"
74
76
  association = subject.associations.last
75
77
  assert_equal :has_one, association.type
76
78
  assert_equal :linking, association.name
@@ -82,7 +84,7 @@ module Ardb::RecordSpy
82
84
  end
83
85
 
84
86
  should "add a validation config for \"*_of\" validations" do
85
- subject.validates_presence_of :name, :email, :on => :create
87
+ subject.validates_presence_of :name, :email, on: :create
86
88
  validation = subject.validations.last
87
89
  assert_equal :presence, validation.type
88
90
  assert_equal :create, validation.options[:on]
@@ -109,7 +111,7 @@ module Ardb::RecordSpy
109
111
  end
110
112
 
111
113
  should "add a validation config with #validates_each" do
112
- block = proc{ }
114
+ block = proc{}
113
115
  subject.validates_each(:name, :email, &block)
114
116
  validation = subject.validations.last
115
117
  assert_equal :each, validation.type
@@ -124,7 +126,7 @@ module Ardb::RecordSpy
124
126
  assert_equal :custom, validation.type
125
127
  assert_equal :some_method, validation.method_name
126
128
 
127
- block = proc{ }
129
+ block = proc{}
128
130
  subject.validate(&block)
129
131
  validation = subject.validations.last
130
132
  assert_equal :custom, validation.type
@@ -143,7 +145,7 @@ module Ardb::RecordSpy
143
145
  end
144
146
 
145
147
  should "add a callback config with a block" do
146
- subject.before_validation(:on => :create) do
148
+ subject.before_validation(on: :create) do
147
149
  self.name = "test"
148
150
  end
149
151
  callback = subject.callbacks.last
@@ -176,7 +178,12 @@ module Ardb::RecordSpy
176
178
  assert_respond_to "around_#{name}", subject
177
179
  assert_respond_to "after_#{name}", subject
178
180
 
179
- callback_name = ["before_#{name}", "around_#{name}", "after_#{name}"].sample
181
+ callback_name =
182
+ [
183
+ "before_#{name}",
184
+ "around_#{name}",
185
+ "after_#{name}",
186
+ ].sample
180
187
  method_name = Factory.string
181
188
  subject.send(callback_name, method_name)
182
189
  callback = subject.callbacks.last
@@ -184,7 +191,7 @@ module Ardb::RecordSpy
184
191
  assert_equal [method_name], callback.args
185
192
 
186
193
  name = Factory.string
187
- subject.define_model_callbacks(name, :only => [:before])
194
+ subject.define_model_callbacks(name, only: [:before])
188
195
 
189
196
  assert_respond_to "before_#{name}", subject
190
197
  assert_not_respond_to "around_#{name}", subject
@@ -332,8 +339,8 @@ module Ardb::RecordSpy
332
339
  assert_equal "other thing", subject.ho_thing
333
340
 
334
341
  assert_empty subject.hm_things
335
- subject.hm_things = [1,2,3]
336
- assert_equal [1,2,3], subject.hm_things
342
+ subject.hm_things = [1, 2, 3]
343
+ assert_equal [1, 2, 3], subject.hm_things
337
344
  end
338
345
 
339
346
  should "default its manually run callbacks" do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "assert"
2
4
  require "ardb/relation_spy"
3
5
 
@@ -49,7 +51,8 @@ class Ardb::RelationSpy
49
51
  assert_equal other_relation, subject
50
52
  end
51
53
 
52
- should "build a fake sql string for its applied expressions using `to_sql`" do
54
+ should "build a fake sql string for its applied expressions using "\
55
+ "`to_sql`" do
53
56
  subject.select "column"
54
57
  subject.from "table"
55
58
  subject.joins "my_table.my_column ON my_table.my_column = table.column"
@@ -81,7 +84,7 @@ class Ardb::RelationSpy
81
84
  should "add a select applied expression with the passed args" do
82
85
  assert_instance_of AppliedExpression, @applied
83
86
  assert_equal :select, @applied.type
84
- assert_equal [ :column_a, :column_b ], @applied.args
87
+ assert_equal [:column_a, :column_b], @applied.args
85
88
  end
86
89
  end
87
90
 
@@ -95,7 +98,7 @@ class Ardb::RelationSpy
95
98
  should "add a from applied expression with the passed args" do
96
99
  assert_instance_of AppliedExpression, @applied
97
100
  assert_equal :from, @applied.type
98
- assert_equal [ "some SQL" ], @applied.args
101
+ assert_equal ["some SQL"], @applied.args
99
102
  end
100
103
  end
101
104
 
@@ -109,7 +112,7 @@ class Ardb::RelationSpy
109
112
  should "add an includes applied expression with the passed args" do
110
113
  assert_instance_of AppliedExpression, @applied
111
114
  assert_equal :includes, @applied.type
112
- assert_equal [ :table_a, :table_b ], @applied.args
115
+ assert_equal [:table_a, :table_b], @applied.args
113
116
  end
114
117
  end
115
118
 
@@ -123,21 +126,21 @@ class Ardb::RelationSpy
123
126
  should "add a joins applied expression with the passed args" do
124
127
  assert_instance_of AppliedExpression, @applied
125
128
  assert_equal :joins, @applied.type
126
- assert_equal [ :table_a, :table_b ], @applied.args
129
+ assert_equal [:table_a, :table_b], @applied.args
127
130
  end
128
131
  end
129
132
 
130
133
  class WhereTests < UnitTests
131
134
  desc "where"
132
135
  setup do
133
- @relation_spy.where :column_a => "some value"
136
+ @relation_spy.where column_a: "some value"
134
137
  @applied = subject.applied.first
135
138
  end
136
139
 
137
140
  should "add a where applied expression with the passed args" do
138
141
  assert_instance_of AppliedExpression, @applied
139
142
  assert_equal :where, @applied.type
140
- assert_equal [ { :column_a => "some value" } ], @applied.args
143
+ assert_equal [{ column_a: "some value" }], @applied.args
141
144
  end
142
145
  end
143
146
 
@@ -151,7 +154,7 @@ class Ardb::RelationSpy
151
154
  should "add an order applied expression with the passed args" do
152
155
  assert_instance_of AppliedExpression, @applied
153
156
  assert_equal :order, @applied.type
154
- assert_equal [ :column_a, :column_b ], @applied.args
157
+ assert_equal [:column_a, :column_b], @applied.args
155
158
  end
156
159
  end
157
160
 
@@ -178,7 +181,7 @@ class Ardb::RelationSpy
178
181
  should "add a group applied expression with the passed args" do
179
182
  assert_instance_of AppliedExpression, @applied
180
183
  assert_equal :group, @applied.type
181
- assert_equal [ :column_a, :column_b ], @applied.args
184
+ assert_equal [:column_a, :column_b], @applied.args
182
185
  end
183
186
  end
184
187
 
@@ -192,7 +195,7 @@ class Ardb::RelationSpy
192
195
  should "add a having applied expression with the passed args" do
193
196
  assert_instance_of AppliedExpression, @applied
194
197
  assert_equal :having, @applied.type
195
- assert_equal [ "COUNT(column_a) > 0" ], @applied.args
198
+ assert_equal ["COUNT(column_a) > 0"], @applied.args
196
199
  end
197
200
  end
198
201
 
@@ -206,7 +209,7 @@ class Ardb::RelationSpy
206
209
  should "add a readonly applied expression with the passed args" do
207
210
  assert_instance_of AppliedExpression, @applied
208
211
  assert_equal :readonly, @applied.type
209
- assert_equal [ true ], @applied.args
212
+ assert_equal [true], @applied.args
210
213
  end
211
214
  end
212
215
 
@@ -220,7 +223,7 @@ class Ardb::RelationSpy
220
223
  should "add a limit applied expression with the passed args" do
221
224
  assert_instance_of AppliedExpression, @applied
222
225
  assert_equal :limit, @applied.type
223
- assert_equal [ 100 ], @applied.args
226
+ assert_equal [100], @applied.args
224
227
  end
225
228
 
226
229
  should "set it's limit value" do
@@ -238,7 +241,7 @@ class Ardb::RelationSpy
238
241
  should "add an offset applied expression with the passed args" do
239
242
  assert_instance_of AppliedExpression, @applied
240
243
  assert_equal :offset, @applied.type
241
- assert_equal [ 100 ], @applied.args
244
+ assert_equal [100], @applied.args
242
245
  end
243
246
 
244
247
  should "set it's offset value" do
@@ -249,7 +252,8 @@ class Ardb::RelationSpy
249
252
  class MergeWithARelationSpyTests < UnitTests
250
253
  desc "merge with a relation spy"
251
254
  setup do
252
- @other_relation_spy = Ardb::RelationSpy.new.select("column").joins("table")
255
+ @other_relation_spy =
256
+ Ardb::RelationSpy.new.select("column").joins("table")
253
257
  @relation_spy.merge @other_relation_spy
254
258
  end
255
259
 
@@ -271,7 +275,7 @@ class Ardb::RelationSpy
271
275
  should "add a merge applied expression with the passed args" do
272
276
  assert_instance_of AppliedExpression, @applied
273
277
  assert_equal :merge, @applied.type
274
- assert_equal [ @fake_relation ], @applied.args
278
+ assert_equal [@fake_relation], @applied.args
275
279
  end
276
280
  end
277
281
 
@@ -290,7 +294,7 @@ class Ardb::RelationSpy
290
294
  class WithExpressionsTests < UnitTests
291
295
  setup do
292
296
  @relation_spy.select("column").includes("table").joins("table")
293
- @relation_spy.where(:column => "value").order("column")
297
+ @relation_spy.where(column: "value").order("column")
294
298
  @relation_spy.group("column").having("count(*) > 1")
295
299
  @relation_spy.limit(1).offset(1)
296
300
  end
@@ -307,10 +311,10 @@ class Ardb::RelationSpy
307
311
  should "remove any applied expressions in the passed types" do
308
312
  relation_spy = subject.except(:includes, :where, :group, :offset)
309
313
  applied_types = relation_spy.applied.map(&:type)
310
- [ :select, :joins, :order, :having, :limit ].each do |type|
314
+ [:select, :joins, :order, :having, :limit].each do |type|
311
315
  assert_includes type, applied_types
312
316
  end
313
- [ :includes, :where, :group, :offset ].each do |type|
317
+ [:includes, :where, :group, :offset].each do |type|
314
318
  assert_not_includes type, applied_types
315
319
  end
316
320
  end
@@ -341,22 +345,24 @@ class Ardb::RelationSpy
341
345
  should "remove any applied expressions not in the passed types" do
342
346
  relation_spy = subject.only(:includes, :where, :group, :offset)
343
347
  applied_types = relation_spy.applied.map(&:type)
344
- [ :includes, :where, :group, :offset ].each do |type|
348
+ [:includes, :where, :group, :offset].each do |type|
345
349
  assert_includes type, applied_types
346
350
  end
347
- [ :select, :joins, :order, :having, :limit ].each do |type|
351
+ [:select, :joins, :order, :having, :limit].each do |type|
348
352
  assert_not_includes type, applied_types
349
353
  end
350
354
  end
351
355
 
352
- should "unset the limit value if limit is not included in the passed types" do
356
+ should "unset the limit value if limit is not included in the passed "\
357
+ "types" do
353
358
  relation_spy = subject.only(:limit)
354
359
  assert_not_nil relation_spy.limit_value
355
360
  relation_spy = subject.only(:select)
356
361
  assert_nil relation_spy.limit_value
357
362
  end
358
363
 
359
- should "unset the offset value if offset is not included in the passed types" do
364
+ should "unset the offset value if offset is not included in the passed "\
365
+ "types" do
360
366
  relation_spy = subject.only(:offset)
361
367
  assert_not_nil relation_spy.offset_value
362
368
  relation_spy = subject.only(:select)