sequelizer 0.1.4 → 0.1.6

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 (54) hide show
  1. checksums.yaml +4 -4
  2. data/.claude/settings.local.json +64 -0
  3. data/.devcontainer/.p10k.zsh +1713 -0
  4. data/.devcontainer/.zshrc +29 -0
  5. data/.devcontainer/Dockerfile +137 -0
  6. data/.devcontainer/copy-claude-credentials.sh +32 -0
  7. data/.devcontainer/devcontainer.json +102 -0
  8. data/.devcontainer/init-firewall.sh +123 -0
  9. data/.devcontainer/setup-credentials.sh +95 -0
  10. data/.github/workflows/test.yml +1 -1
  11. data/.gitignore +6 -1
  12. data/.overcommit.yml +73 -0
  13. data/.rubocop.yml +167 -0
  14. data/CHANGELOG.md +24 -0
  15. data/CLAUDE.md +219 -0
  16. data/Gemfile +6 -2
  17. data/Gemfile.lock +158 -0
  18. data/Guardfile +1 -1
  19. data/Rakefile +28 -3
  20. data/lib/sequel/extensions/cold_col.rb +436 -0
  21. data/lib/sequel/extensions/db_opts.rb +65 -4
  22. data/lib/sequel/extensions/make_readyable.rb +148 -30
  23. data/lib/sequel/extensions/more_sql.rb +76 -0
  24. data/lib/sequel/extensions/settable.rb +64 -0
  25. data/lib/sequel/extensions/sql_recorder.rb +85 -0
  26. data/lib/sequel/extensions/unionize.rb +169 -0
  27. data/lib/sequel/extensions/usable.rb +30 -1
  28. data/lib/sequelizer/cli.rb +61 -18
  29. data/lib/sequelizer/connection_maker.rb +54 -72
  30. data/lib/sequelizer/env_config.rb +6 -6
  31. data/lib/sequelizer/gemfile_modifier.rb +23 -21
  32. data/lib/sequelizer/monkey_patches/database_in_after_connect.rb +7 -5
  33. data/lib/sequelizer/options.rb +97 -18
  34. data/lib/sequelizer/options_hash.rb +2 -0
  35. data/lib/sequelizer/version.rb +3 -1
  36. data/lib/sequelizer/yaml_config.rb +9 -3
  37. data/lib/sequelizer.rb +65 -9
  38. data/sequelizer.gemspec +12 -7
  39. data/test/lib/sequel/extensions/test_cold_col.rb +251 -0
  40. data/test/lib/sequel/extensions/test_db_opts.rb +10 -8
  41. data/test/lib/sequel/extensions/test_make_readyable.rb +199 -28
  42. data/test/lib/sequel/extensions/test_more_sql.rb +132 -0
  43. data/test/lib/sequel/extensions/test_settable.rb +109 -0
  44. data/test/lib/sequel/extensions/test_sql_recorder.rb +231 -0
  45. data/test/lib/sequel/extensions/test_unionize.rb +76 -0
  46. data/test/lib/sequel/extensions/test_usable.rb +5 -2
  47. data/test/lib/sequelizer/test_connection_maker.rb +21 -17
  48. data/test/lib/sequelizer/test_env_config.rb +5 -2
  49. data/test/lib/sequelizer/test_gemfile_modifier.rb +7 -6
  50. data/test/lib/sequelizer/test_options.rb +14 -9
  51. data/test/lib/sequelizer/test_yaml_config.rb +13 -12
  52. data/test/test_helper.rb +36 -8
  53. metadata +107 -28
  54. data/lib/sequel/extensions/sqls.rb +0 -31
@@ -0,0 +1,231 @@
1
+ require_relative '../../../test_helper'
2
+ require 'sequel'
3
+ require 'sequel/extensions/sql_recorder'
4
+
5
+ class TestSqlRecorder < Minitest::Test
6
+
7
+ def setup
8
+ # Use mock database for these tests since we're not conflicting anymore
9
+ @db = Sequel.mock
10
+ @db.extension :sql_recorder
11
+ end
12
+
13
+ def test_extension_registration
14
+ assert_respond_to @db, :sql_recorder
15
+ end
16
+
17
+ def test_sql_recorder_initialized_as_empty_array
18
+ assert_instance_of Array, @db.sql_recorder
19
+ assert_empty @db.sql_recorder
20
+ end
21
+
22
+ def test_records_select_statements
23
+ @db[:users].all
24
+
25
+ assert_operator(@db.sql_recorder.length, :>=, 1, 'Should record at least one SQL statement')
26
+ assert(@db.sql_recorder.any? do |sql|
27
+ sql.include?('SELECT * FROM users') || sql.include?('SELECT * FROM `users`')
28
+ end, 'Should record the SELECT statement')
29
+ end
30
+
31
+ def test_records_insert_statements
32
+ @db[:users].insert(name: 'John', email: 'john@example.com', age: 30)
33
+
34
+ assert_operator(@db.sql_recorder.length, :>=, 1, 'Should record at least one SQL statement')
35
+ assert(@db.sql_recorder.any? do |sql|
36
+ sql.include?('INSERT INTO users') || sql.include?('INSERT INTO `users`')
37
+ end, 'Should record INSERT statement')
38
+ assert(@db.sql_recorder.any? { |sql| sql.include?('John') }, 'Should include the data')
39
+ end
40
+
41
+ def test_records_update_statements
42
+ @db[:users].where(id: 1).update(name: 'Jane')
43
+
44
+ assert_operator(@db.sql_recorder.length, :>=, 1, 'Should record at least one SQL statement')
45
+ assert(@db.sql_recorder.any? do |sql|
46
+ sql.include?('UPDATE users SET') || sql.include?('UPDATE `users` SET')
47
+ end, 'Should record UPDATE statement')
48
+ assert(@db.sql_recorder.any? { |sql| sql.include?('Jane') }, 'Should include the updated data')
49
+ end
50
+
51
+ def test_records_delete_statements
52
+ @db[:users].where(id: 1).delete
53
+
54
+ assert_operator(@db.sql_recorder.length, :>=, 1, 'Should record at least one SQL statement')
55
+ assert(@db.sql_recorder.any? do |sql|
56
+ sql.include?('DELETE FROM users') || sql.include?('DELETE FROM `users`')
57
+ end, 'Should record DELETE statement')
58
+ end
59
+
60
+ def test_records_multiple_sql_statements
61
+ initial_count = @db.sql_recorder.length
62
+
63
+ @db[:users].all
64
+ @db[:posts].where(id: 1).first
65
+ @db[:comments].count
66
+
67
+ assert_operator(@db.sql_recorder.length, :>=, initial_count + 3, 'Should record at least 3 more SQL statements')
68
+ assert(@db.sql_recorder.any? do |sql|
69
+ sql.include?('SELECT * FROM users') || sql.include?('SELECT * FROM `users`')
70
+ end, 'Should record users query')
71
+ assert(@db.sql_recorder.any? do |sql|
72
+ sql.include?('SELECT * FROM posts WHERE (id = 1)')
73
+ end, 'Should record posts query')
74
+ assert(@db.sql_recorder.any? do |sql|
75
+ sql.include?('SELECT count(*) AS count FROM comments')
76
+ end, 'Should record count query')
77
+ end
78
+
79
+ def test_sql_recorder_accumulates_across_multiple_operations
80
+ initial_count = @db.sql_recorder.length
81
+
82
+ @db[:users].all
83
+ count_after_first = @db.sql_recorder.length
84
+
85
+ assert_operator(count_after_first, :>, initial_count, 'Should record first query')
86
+
87
+ @db[:posts].first
88
+ count_after_second = @db.sql_recorder.length
89
+
90
+ assert_operator(count_after_second, :>, count_after_first, 'Should record second query')
91
+
92
+ @db[:comments].insert(text: 'Hello')
93
+ count_after_third = @db.sql_recorder.length
94
+
95
+ assert_operator(count_after_third, :>, count_after_second, 'Should record third query')
96
+ end
97
+
98
+ def test_sql_recorder_persists_until_manually_cleared
99
+ @db[:users].all
100
+ @db[:posts].all
101
+
102
+ assert_operator(@db.sql_recorder.length, :>=, 2, 'Should record multiple statements')
103
+
104
+ # Manually clear (this is how consumers would reset the log)
105
+ @db.sql_recorder.clear
106
+
107
+ assert_empty @db.sql_recorder
108
+
109
+ @db[:comments].all
110
+
111
+ assert_operator(@db.sql_recorder.length, :>=, 1, 'Should record new statements after clear')
112
+ end
113
+
114
+ def test_handles_complex_queries_with_joins
115
+ @db[:users].join(:posts, user_id: :id).where(Sequel[:users][:active] => true).all
116
+
117
+ assert_operator(@db.sql_recorder.length, :>=, 1, 'Should record at least one SQL statement')
118
+ recorded_sql = @db.sql_recorder.join(' ')
119
+
120
+ assert_includes(recorded_sql, 'SELECT', 'Should contain SELECT')
121
+ assert(recorded_sql.include?('FROM users') || recorded_sql.include?('FROM `users`'), 'Should contain FROM users')
122
+ assert_includes(recorded_sql, 'JOIN', 'Should contain JOIN')
123
+ end
124
+
125
+ def test_handles_queries_with_parameters
126
+ @db[:users].where(name: 'John', age: 25).all
127
+
128
+ assert_operator(@db.sql_recorder.length, :>=, 1, 'Should record at least one SQL statement')
129
+ recorded_sql = @db.sql_recorder.join(' ')
130
+
131
+ assert_includes(recorded_sql, 'John', 'Should include name parameter')
132
+ assert_includes(recorded_sql, '25', 'Should include age parameter')
133
+ end
134
+
135
+ def test_thread_safety_with_concurrent_queries
136
+ threads = []
137
+
138
+ 10.times do |i|
139
+ threads << Thread.new do
140
+ @db[:table].where(id: i).first
141
+ end
142
+ end
143
+
144
+ threads.each(&:join)
145
+
146
+ # Should have recorded all 10 queries
147
+ assert_operator(@db.sql_recorder.length, :>=, 10, 'Should record at least 10 queries')
148
+ (0..9).each do |i|
149
+ assert(@db.sql_recorder.any? { |sql| sql.include?("WHERE (id = #{i})") }, "Should record query for id #{i}")
150
+ end
151
+ end
152
+
153
+ def test_module_extension_method_initializes_properly
154
+ # Test the self.extended method directly
155
+ fresh_db = Sequel.mock
156
+ fresh_db.extend(Sequel::SqlRecorder)
157
+ Sequel::SqlRecorder.extended(fresh_db)
158
+
159
+ assert_respond_to fresh_db, :sql_recorder
160
+ assert_instance_of Array, fresh_db.sql_recorder
161
+ assert_instance_of Mutex, fresh_db.instance_variable_get(:@sql_recorder_mutex)
162
+ end
163
+
164
+ def test_sql_recorder_mutex_is_initialized
165
+ assert_instance_of Mutex, @db.instance_variable_get(:@sql_recorder_mutex)
166
+ end
167
+
168
+ def test_extension_can_be_added_to_existing_database
169
+ plain_db = Sequel.mock
170
+
171
+ refute_respond_to plain_db, :sql_recorder
172
+
173
+ plain_db.extension :sql_recorder
174
+
175
+ assert_respond_to plain_db, :sql_recorder
176
+ assert_instance_of Array, plain_db.sql_recorder
177
+ end
178
+
179
+ def test_sql_recorder_does_not_conflict_with_mock_sqls
180
+ # Test that our sql_recorder doesn't interfere with mock's sqls
181
+ mock_db = Sequel.mock
182
+ mock_db.extension :sql_recorder
183
+
184
+ # Both should work independently
185
+ assert_respond_to mock_db, :sqls # Mock's built-in
186
+ assert_respond_to mock_db, :sql_recorder # Our extension
187
+
188
+ # Execute a query
189
+ mock_db[:test].all
190
+
191
+ # Both should record (though possibly differently)
192
+ assert_instance_of Array, mock_db.sqls
193
+ assert_instance_of Array, mock_db.sql_recorder
194
+ end
195
+
196
+ def test_database_extension_registration
197
+ # Test that the extension is properly registered with Sequel
198
+ # Check that we can load the extension without error
199
+ fresh_db = Sequel.mock
200
+ fresh_db.extension :sql_recorder
201
+
202
+ assert_respond_to fresh_db, :sql_recorder
203
+ end
204
+
205
+ def test_attr_reader_sql_recorder_works
206
+ # Directly test the attr_reader
207
+ assert_same @db.instance_variable_get(:@sql_recorder), @db.sql_recorder
208
+ end
209
+
210
+ def test_log_connection_yield_method_exists
211
+ assert_respond_to @db, :log_connection_yield
212
+ assert_includes Sequel::SqlRecorder.instance_methods, :log_connection_yield
213
+ end
214
+
215
+ def test_manual_sql_recording_functionality
216
+ # Test that we can manually record SQL using the method structure
217
+ test_sql = 'SELECT * FROM manual_test'
218
+
219
+ # Verify sql_recorder starts empty or with existing content
220
+ initial_count = @db.sql_recorder.length
221
+
222
+ # Manually add SQL using the same structure as log_connection_yield
223
+ @db.instance_variable_get(:@sql_recorder_mutex).synchronize do
224
+ @db.sql_recorder.push(test_sql)
225
+ end
226
+
227
+ assert_equal initial_count + 1, @db.sql_recorder.length
228
+ assert_includes @db.sql_recorder, test_sql
229
+ end
230
+
231
+ end
@@ -0,0 +1,76 @@
1
+ require_relative '../../../test_helper'
2
+ require 'sequel'
3
+
4
+ class TestUnionize < Minitest::Test
5
+
6
+ def test_should_unionize_a_single_dataset
7
+ db = Sequel.mock(host: :spark).extension(:unionize)
8
+ ds = db.unionize([db[:a]])
9
+
10
+ # No SQL should be executed
11
+ assert_empty(db.sqls)
12
+ # The SQL should be a single select
13
+ assert_equal('SELECT * FROM `a`', ds.sql)
14
+ end
15
+
16
+ def test_should_unionize_two_datasets
17
+ db = Sequel.mock(host: :spark).extension(:unionize)
18
+ ds = db.unionize([db[:a], db[:b]])
19
+
20
+ # No SQL should be executed
21
+ assert_empty(db.sqls)
22
+ # The SQL should be a single select
23
+ assert_equal('SELECT * FROM (SELECT * FROM `a` UNION SELECT * FROM `b`) AS `t1`', ds.sql)
24
+ end
25
+
26
+ def test_should_unionize_two_datasets_and_allow_all_option
27
+ db = Sequel.mock(host: :spark).extension(:unionize)
28
+ ds = db.unionize([db[:a], db[:b]], all: true)
29
+
30
+ # No SQL should be executed
31
+ assert_empty(db.sqls)
32
+ # The SQL should be a single select
33
+ assert_equal('SELECT * FROM (SELECT * FROM `a` UNION ALL SELECT * FROM `b`) AS `t1`', ds.sql)
34
+ end
35
+
36
+ def test_should_unionize_two_datasets_and_allow_from_self_option
37
+ db = Sequel.mock(host: :spark).extension(:unionize)
38
+ ds = db.unionize([db[:a], db[:b]], from_self: false)
39
+
40
+ # No SQL should be executed
41
+ assert_empty(db.sqls)
42
+ # The SQL should be a single select
43
+ assert_equal('SELECT * FROM `a` UNION SELECT * FROM `b`', ds.sql)
44
+ end
45
+
46
+ def test_should_unionize_four_datasets_as_sets_of_two
47
+ db = Sequel.mock(host: :spark).extension(:unionize)
48
+ ds = db.unionize([db[:a], db[:b], db[:c], db[:d]], chunk_size: 2, from_self: false)
49
+
50
+ # Two things should be created
51
+ assert_equal(
52
+ [
53
+ 'CREATE TEMPORARY VIEW `temp_union_ac554bd85a4a6087511d4949f3a3c5a59c110cde` AS SELECT * FROM `a` UNION SELECT * FROM `b`',
54
+ 'CREATE TEMPORARY VIEW `temp_union_1e7e77a914d0b30cd33511f372c48d537ad81084` AS SELECT * FROM `c` UNION SELECT * FROM `d`',
55
+ ], db.sqls
56
+ )
57
+ # The SQL should be a single select
58
+ assert_equal(
59
+ 'SELECT * FROM `temp_union_ac554bd85a4a6087511d4949f3a3c5a59c110cde` UNION SELECT * FROM `temp_union_1e7e77a914d0b30cd33511f372c48d537ad81084`', ds.sql
60
+ )
61
+ end
62
+
63
+ def test_should_unionize_8_datasets_as_sets_of_two_then_another_two
64
+ db = Sequel.mock(host: :spark).extension(:unionize)
65
+ dses = %i[a b c d e f g h].map { |letter| db[letter] }
66
+ ds = db.unionize(dses, chunk_size: 2, from_self: false)
67
+
68
+ # Two things should be created
69
+ assert_equal(6, db.sqls.length)
70
+ # The SQL should be a single select
71
+ assert_equal(
72
+ 'SELECT * FROM `temp_union_07a3e9f8f94e096301b62afd61b4315110ec0c3d` UNION SELECT * FROM `temp_union_ff3e49e7501c97ee5e69f112cc42bb7121f379f1`', ds.sql
73
+ )
74
+ end
75
+
76
+ end
@@ -3,10 +3,13 @@ require 'sequel'
3
3
  require 'sequel/extensions/usable'
4
4
 
5
5
  class TestUsable < Minitest::Test
6
+
6
7
  def test_should_call_use
7
8
  db = Sequel.mock(host: :sqlite)
8
9
  db.extension :usable
9
10
  db.use(:some_schema)
10
- assert_equal(db.sqls, ["USE `some_schema`"])
11
+
12
+ assert_equal(['USE `some_schema`'], db.sqls)
11
13
  end
12
- end
14
+
15
+ end
@@ -2,8 +2,9 @@ require_relative '../../test_helper'
2
2
  require 'sequelizer'
3
3
 
4
4
  class TestConnectionMaker < Minitest::Test
5
+
5
6
  def setup
6
- @options = { 'adapter' => 'mock', "host" => "postgres" }
7
+ @options = { 'adapter' => 'mock', 'host' => 'postgres' }
7
8
  end
8
9
 
9
10
  def test_accepts_options_as_params
@@ -12,16 +13,12 @@ class TestConnectionMaker < Minitest::Test
12
13
  end
13
14
  end
14
15
 
15
- def with_ignored_yaml_config(opts = {})
16
- end
17
-
16
+ def with_ignored_yaml_config(opts = {}); end
18
17
 
19
- def with_yaml_config(options = {})
18
+ def with_yaml_config(options = {}, &block)
20
19
  yaml_config = Sequelizer::YamlConfig.new
21
20
  yaml_config.stub(:options, options) do
22
- Sequelizer::YamlConfig.stub :new, yaml_config do
23
- yield
24
- end
21
+ Sequelizer::YamlConfig.stub :new, yaml_config, &block
25
22
  end
26
23
  end
27
24
 
@@ -51,7 +48,8 @@ class TestConnectionMaker < Minitest::Test
51
48
  with_env_config do
52
49
  conn = Sequelizer::ConnectionMaker.new.connection
53
50
  conn.test_connection
54
- assert_equal(["SET flim=flam"], conn.sqls)
51
+
52
+ assert_equal(['SET flim=flam'], conn.sqls)
55
53
  end
56
54
  end
57
55
  end
@@ -61,7 +59,8 @@ class TestConnectionMaker < Minitest::Test
61
59
  with_env_config do
62
60
  conn = Sequelizer::ConnectionMaker.new.connection
63
61
  conn.test_connection
64
- assert_equal(["SET flim=flam"] * 2, conn.sqls)
62
+
63
+ assert_equal(['SET flim=flam'] * 2, conn.sqls)
65
64
  end
66
65
  end
67
66
  end
@@ -83,12 +82,13 @@ class TestConnectionMaker < Minitest::Test
83
82
  end
84
83
 
85
84
  def test_applies_configuration_to_connection
86
- opts = @options.merge(postgres_db_opt_search_path: "searchy", impala_db_opt_search_path: "searchy2")
85
+ opts = @options.merge(postgres_db_opt_search_path: 'searchy', impala_db_opt_search_path: 'searchy2')
87
86
  with_yaml_config(opts) do
88
87
  conn = Sequelizer::ConnectionMaker.new.connection
89
88
  conn.test_connection
90
- assert_equal({ search_path: "searchy" }, conn.db_opts.to_hash)
91
- assert_equal(["SET search_path=searchy"], conn.db_opts.sql_statements)
89
+
90
+ assert_equal({ search_path: 'searchy' }, conn.db_opts.to_hash)
91
+ assert_equal(['SET search_path=searchy'], conn.db_opts.sql_statements)
92
92
  end
93
93
  end
94
94
 
@@ -96,16 +96,18 @@ class TestConnectionMaker < Minitest::Test
96
96
  Sequelizer::YamlConfig.stub :user_config_path, Pathname.new('/completely/made/up/path/that/does/not/exist') do
97
97
  conn = Sequelizer::ConnectionMaker.new(@options).connection
98
98
  conn.test_connection
99
- assert_equal({}, conn.db_opts.to_hash)
100
- assert_equal([], conn.db_opts.sql_statements)
99
+
100
+ assert_empty(conn.db_opts.to_hash)
101
+ assert_empty(conn.db_opts.sql_statements)
101
102
  end
102
103
  end
103
104
 
104
105
  def test_applies_quotes_when_necessary
105
106
  Sequelizer::YamlConfig.stub :user_config_path, Pathname.new('/completely/made/up/path/that/does/not/exist') do
106
- @options.merge!(postgres_db_opt_search_path: "searchy,path")
107
+ @options.merge!(postgres_db_opt_search_path: 'searchy,path')
107
108
  conn = Sequelizer::ConnectionMaker.new(@options).connection
108
109
  conn.test_connection
110
+
109
111
  assert_equal({ search_path: "'searchy,path'" }, conn.db_opts.to_hash)
110
112
  assert_equal(["SET search_path='searchy,path'"], conn.db_opts.sql_statements)
111
113
  end
@@ -113,7 +115,9 @@ class TestConnectionMaker < Minitest::Test
113
115
 
114
116
  def test_applies_extensions
115
117
  with_yaml_config(@options.merge(extension_error_sql: 1)) do
116
- assert Sequelizer::ConnectionMaker.new.connection.send(:instance_variable_get, "@loaded_extensions".to_sym).include?(:error_sql), "Extension wasn't set"
118
+ assert_includes Sequelizer::ConnectionMaker.new.connection.send(:instance_variable_get, :@loaded_extensions), :error_sql,
119
+ "Extension wasn't set"
117
120
  end
118
121
  end
122
+
119
123
  end
@@ -1,8 +1,8 @@
1
1
  require_relative '../../test_helper'
2
2
  require 'sequelizer'
3
3
 
4
-
5
4
  class TestEnvConfig < Minitest::Test
5
+
6
6
  def setup
7
7
  @env_config = Sequelizer::EnvConfig.new
8
8
  end
@@ -17,18 +17,21 @@ class TestEnvConfig < Minitest::Test
17
17
  end
18
18
 
19
19
  def test_options_default_to_empty_hash
20
- assert_equal(@env_config.options, {})
20
+ assert_empty(@env_config.options)
21
21
  end
22
22
 
23
23
  def test_converts_sequelizer_vars_to_options
24
24
  ENV['SEQUELIZER_ADAPTER'] = 'sqlite'
25
+
25
26
  assert_equal({ 'adapter' => 'sqlite' }, @env_config.options)
26
27
  ENV.delete('SEQUELIZER_ADAPTER')
27
28
  end
28
29
 
29
30
  def test_converts_db_opts_to_options
30
31
  ENV['POSTGRES_DB_OPT_HEY'] = 'there'
32
+
31
33
  assert_equal({ 'postgres_db_opt_hey' => 'there' }, @env_config.options)
32
34
  ENV.delete('POSTGRES_DB_OPT_HEY')
33
35
  end
36
+
34
37
  end
@@ -2,13 +2,15 @@ require_relative '../../test_helper'
2
2
  require 'sequelizer/gemfile_modifier'
3
3
 
4
4
  class TestGemfileModifier < Minitest::Test
5
+
5
6
  def setup
6
7
  @gm = Sequelizer::GemfileModifier.new
7
8
  end
8
9
 
9
- def test_dies_if_Gemfile_missing
10
+ def test_dies_if_gemfile_missing
10
11
  pn_mock = Minitest::Mock.new
11
12
  pn_mock.expect(:exist?, false)
13
+
12
14
  Pathname.stub(:new, pn_mock) do
13
15
  assert_raises(RuntimeError) { @gm.modify }
14
16
  end
@@ -71,17 +73,16 @@ class TestGemfileModifier < Minitest::Test
71
73
  end
72
74
 
73
75
  private
76
+
74
77
  def standard_pn_mock
75
78
  pn_mock = Minitest::Mock.new
76
79
  pn_mock.expect(:exist?, true)
77
80
  end
78
81
 
79
- def stub_modifying_methods(obj)
82
+ def stub_modifying_methods(obj, &block)
80
83
  obj.stub(:system, nil) do
81
- obj.stub(:puts, nil) do
82
- yield
83
- end
84
+ obj.stub(:puts, nil, &block)
84
85
  end
85
86
  end
86
- end
87
87
 
88
+ end
@@ -1,8 +1,8 @@
1
1
  require_relative '../../test_helper'
2
2
  require 'sequelizer/options'
3
3
 
4
-
5
4
  class TestOptions < Minitest::Test
5
+
6
6
  def test_changes_postgresql_adapter_to_postgres
7
7
  options = Sequelizer::Options.new(Sequelizer::OptionsHash.new(adapter: 'postgresql'))
8
8
 
@@ -30,19 +30,22 @@ class TestOptions < Minitest::Test
30
30
  end
31
31
 
32
32
  def test_prefers_search_path_over_schema_search_path
33
- options = Sequelizer::Options.new(Sequelizer::OptionsHash.new(adapter: 'postgres', search_path: 'path', schema_search_path: 'path2'))
33
+ options = Sequelizer::Options.new(Sequelizer::OptionsHash.new(adapter: 'postgres', search_path: 'path',
34
+ schema_search_path: 'path2'))
34
35
 
35
36
  assert_equal('path', options.search_path)
36
37
  end
37
38
 
38
39
  def test_returns_timeout_as_an_integer_even_if_given_string
39
- options = Sequelizer::Options.new({timeout: "30"})
40
+ options = Sequelizer::Options.new({ timeout: '30' })
41
+
40
42
  assert_equal(30, options.to_hash[:timeout])
41
43
  end
42
44
 
43
45
  def test_returns_a_hash_even_if_given_nil
44
46
  Sequelizer::YamlConfig.stub :user_config_path, Pathname.new('/completely/made/up/path/that/does/not/exist') do
45
47
  options = Sequelizer::Options.new
48
+
46
49
  assert_equal(1, options.to_hash.length)
47
50
  assert_instance_of(Proc, options.to_hash[:after_connect])
48
51
  end
@@ -50,6 +53,7 @@ class TestOptions < Minitest::Test
50
53
 
51
54
  def test_handles_symbolized_search_path
52
55
  options = Sequelizer::Options.new(search_path: 'passed', adapter: 'postgres')
56
+
53
57
  assert_equal 'passed', options.search_path
54
58
  end
55
59
 
@@ -60,19 +64,20 @@ class TestOptions < Minitest::Test
60
64
  conny.expect :db, db
61
65
  conny.expect :db, db
62
66
 
63
- procky = Proc.new { |conn| conn.db[:table].to_a }
67
+ procky = proc { |conn| conn.db[:table].to_a }
64
68
 
65
69
  options = Sequelizer::Options.new(after_connect: procky)
66
70
  options.to_hash[:after_connect].call(conny, :default, db)
67
71
 
68
- assert_equal(["SELECT * FROM \"table\""], db.sqls)
72
+ assert_equal(['SELECT * FROM "table"'], db.sqls)
69
73
  end
70
74
 
71
75
  def test_handles_extensions_passed_in
72
- options = Sequelizer::Options.new(extension_example_1: 1, extension_example_2: 1, not_an_extension_example: 1)
76
+ options = Sequelizer::Options.new(extension_example_one: 1, extension_example_two: 1, not_an_extension_example: 1)
77
+
73
78
  assert_equal 1, options.to_hash[:not_an_extension_example]
74
- assert options.extensions.include?(:example_1), "Failed to find example_1 in extensions"
75
- assert options.extensions.include?(:example_2), "Failed to find example_2 in extensions"
79
+ assert_includes options.extensions, :example_one, 'Failed to find example_one in extensions'
80
+ assert_includes options.extensions, :example_two, 'Failed to find example_two in extensions'
76
81
  end
77
- end
78
82
 
83
+ end
@@ -1,21 +1,19 @@
1
1
  require_relative '../../test_helper'
2
2
  require 'sequelizer/yaml_config'
3
3
 
4
-
5
4
  class TestYamlConfig < Minitest::Test
5
+
6
6
  def setup
7
7
  @yaml_config = Sequelizer::YamlConfig.new
8
8
  end
9
9
 
10
- def with_empty_env
10
+ def with_empty_env(&)
11
11
  env_mock = Minitest::Mock.new
12
12
  env_mock.expect :[], nil, ['SEQUELIZER_ENV']
13
13
  env_mock.expect :[], nil, ['RAILS_ENV']
14
14
  env_mock.expect :[], nil, ['RACK_ENV']
15
15
 
16
- stub_const(Sequelizer::YamlConfig, :ENV, env_mock) do
17
- yield
18
- end
16
+ stub_const(Sequelizer::YamlConfig, :ENV, env_mock, &)
19
17
 
20
18
  env_mock.verify
21
19
  end
@@ -41,7 +39,7 @@ class TestYamlConfig < Minitest::Test
41
39
  file_mock = Minitest::Mock.new
42
40
  file_mock.expect :exist?, true
43
41
  @yaml_config.stub :config_file_path, file_mock do
44
- @yaml_config.stub :config, {'development' => { 'adapter' => 'sqlite' }} do
42
+ @yaml_config.stub :config, { 'development' => { 'adapter' => 'sqlite' } } do
45
43
  with_empty_env do
46
44
  assert_equal({ 'adapter' => 'sqlite' }, @yaml_config.options)
47
45
  end
@@ -51,27 +49,29 @@ class TestYamlConfig < Minitest::Test
51
49
  end
52
50
 
53
51
  def test_options_default_to_empty_hash
54
- assert_equal(@yaml_config.options, {})
52
+ assert_empty(@yaml_config.options)
55
53
  end
56
54
 
57
55
  def test_path_defaults_to_local_config
58
- assert_equal(@yaml_config.config_file_path, Pathname.pwd + "config" + "sequelizer.yml")
56
+ assert_equal(@yaml_config.config_file_path, Pathname.pwd.join('config', 'sequelizer.yml'))
59
57
  end
60
58
 
61
59
  def test_path_can_be_fed_pathanem_from_initialize
62
- assert_equal(Sequelizer::YamlConfig.new(Pathname.new("~") + ".config").config_file_path, Pathname.new("~").expand_path + ".config")
60
+ assert_equal(Sequelizer::YamlConfig.new(Pathname.new('~').join('.config')).config_file_path,
61
+ Pathname.new('~').expand_path.join('.config'))
63
62
  end
64
63
 
65
64
  def test_path_can_be_fed_string_from_initialize
66
- assert_equal(Sequelizer::YamlConfig.new("~/.config").config_file_path, Pathname.new("~").expand_path + ".config")
65
+ assert_equal(Sequelizer::YamlConfig.new('~/.config').config_file_path, Pathname.new('~/.config').expand_path)
67
66
  end
68
67
 
69
68
  def test_local_is_current_directory
70
- assert_equal(Sequelizer::YamlConfig.local_config.config_file_path, Pathname.pwd + "config" + "sequelizer.yml")
69
+ assert_equal(Sequelizer::YamlConfig.local_config.config_file_path, Pathname.pwd.join('config', 'sequelizer.yml'))
71
70
  end
72
71
 
73
72
  def test_home_uses_home_directory
74
- assert_equal(Sequelizer::YamlConfig.user_config.config_file_path, Pathname.new("~").expand_path + ".config" + "sequelizer" + "database.yml")
73
+ assert_equal(Sequelizer::YamlConfig.user_config.config_file_path,
74
+ Pathname.new(Dir.home).join('.config', 'sequelizer', 'database.yml'))
75
75
  end
76
76
 
77
77
  def test_environment_checks_environment_variables
@@ -79,4 +79,5 @@ class TestYamlConfig < Minitest::Test
79
79
  assert_equal 'development', @yaml_config.environment
80
80
  end
81
81
  end
82
+
82
83
  end