sequelizer 0.2.0 → 0.3.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.
Files changed (59) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +43 -0
  3. data/LICENSE +21 -0
  4. data/README.md +28 -14
  5. data/lib/sequel/extensions/cold_col.rb +39 -15
  6. data/lib/sequel/extensions/funky.rb +1 -1
  7. data/lib/sequel/extensions/make_readyable.rb +18 -8
  8. data/lib/sequel/extensions/platform.rb +8 -9
  9. data/lib/sequel/extensions/smart_select_remove.rb +101 -0
  10. data/lib/sequelizer/options.rb +10 -5
  11. data/lib/sequelizer/version.rb +1 -1
  12. metadata +7 -52
  13. data/.beads/.gitignore +0 -54
  14. data/.beads/.jsonl.lock +0 -0
  15. data/.beads/.migration-hint-ts +0 -1
  16. data/.beads/README.md +0 -81
  17. data/.beads/config.yaml +0 -42
  18. data/.beads/issues.jsonl +0 -20
  19. data/.beads/metadata.json +0 -7
  20. data/.coderabbit.yaml +0 -94
  21. data/.devcontainer/.p10k.zsh +0 -1713
  22. data/.devcontainer/.zshrc +0 -29
  23. data/.devcontainer/Dockerfile +0 -137
  24. data/.devcontainer/copy-claude-credentials.sh +0 -32
  25. data/.devcontainer/devcontainer.json +0 -102
  26. data/.devcontainer/init-firewall.sh +0 -123
  27. data/.devcontainer/setup-credentials.sh +0 -95
  28. data/.github/dependabot.yml +0 -18
  29. data/.github/workflows/dependabot-auto-merge.yml +0 -36
  30. data/.github/workflows/test.yml +0 -49
  31. data/.gitignore +0 -40
  32. data/.overcommit.yml +0 -73
  33. data/.rubocop.yml +0 -167
  34. data/AGENTS.md +0 -126
  35. data/CLAUDE.md +0 -230
  36. data/Gemfile +0 -12
  37. data/Gemfile.lock +0 -189
  38. data/Guardfile +0 -28
  39. data/LICENSE.txt +0 -22
  40. data/Rakefile +0 -35
  41. data/examples/database.with_one_set_of_options.yml +0 -15
  42. data/examples/database.yml +0 -30
  43. data/examples/dot_env.txt +0 -10
  44. data/sequelizer.gemspec +0 -38
  45. data/test/lib/sequel/extensions/test_cold_col.rb +0 -251
  46. data/test/lib/sequel/extensions/test_db_opts.rb +0 -42
  47. data/test/lib/sequel/extensions/test_make_readyable.rb +0 -258
  48. data/test/lib/sequel/extensions/test_more_sql.rb +0 -132
  49. data/test/lib/sequel/extensions/test_platform.rb +0 -222
  50. data/test/lib/sequel/extensions/test_settable.rb +0 -109
  51. data/test/lib/sequel/extensions/test_sql_recorder.rb +0 -231
  52. data/test/lib/sequel/extensions/test_unionize.rb +0 -76
  53. data/test/lib/sequel/extensions/test_usable.rb +0 -15
  54. data/test/lib/sequelizer/test_connection_maker.rb +0 -123
  55. data/test/lib/sequelizer/test_env_config.rb +0 -37
  56. data/test/lib/sequelizer/test_gemfile_modifier.rb +0 -88
  57. data/test/lib/sequelizer/test_options.rb +0 -111
  58. data/test/lib/sequelizer/test_yaml_config.rb +0 -83
  59. data/test/test_helper.rb +0 -45
@@ -1,109 +0,0 @@
1
- require_relative '../../../test_helper'
2
- require 'sequel'
3
- require 'sequel/extensions/settable'
4
-
5
- class TestSettable < Minitest::Test
6
-
7
- def test_should_register_extension
8
- db = Sequel.mock(host: :sqlite)
9
-
10
- assert_respond_to db, :extension
11
- db.extension :settable
12
-
13
- assert_respond_to db, :set
14
- end
15
-
16
- def test_set_with_single_option
17
- db = Sequel.mock(host: :sqlite)
18
- db.extension :settable
19
- db.set(search_path: 'public')
20
-
21
- assert_equal(['SET search_path=public'], db.sqls)
22
- end
23
-
24
- def test_set_with_multiple_options
25
- db = Sequel.mock(host: :sqlite)
26
- db.extension :settable
27
- db.set(search_path: 'public', timezone: 'UTC')
28
-
29
- expected_sqls = ['SET search_path=public', 'SET timezone=UTC']
30
-
31
- assert_equal expected_sqls, db.sqls
32
- end
33
-
34
- def test_set_with_empty_hash
35
- db = Sequel.mock(host: :sqlite)
36
- db.extension :settable
37
- db.set({})
38
-
39
- assert_empty(db.sqls)
40
- end
41
-
42
- def test_set_with_no_arguments
43
- db = Sequel.mock(host: :sqlite)
44
- db.extension :settable
45
- db.set
46
-
47
- assert_empty(db.sqls)
48
- end
49
-
50
- def test_set_with_string_values
51
- db = Sequel.mock(host: :sqlite)
52
- db.extension :settable
53
- db.set(work_mem: '256MB', statement_timeout: '30s')
54
-
55
- expected_sqls = ['SET work_mem=256MB', 'SET statement_timeout=30s']
56
-
57
- assert_equal expected_sqls, db.sqls
58
- end
59
-
60
- def test_set_with_numeric_values
61
- db = Sequel.mock(host: :sqlite)
62
- db.extension :settable
63
- db.set(port: 5432, max_connections: 100)
64
-
65
- expected_sqls = ['SET port=5432', 'SET max_connections=100']
66
-
67
- assert_equal expected_sqls, db.sqls
68
- end
69
-
70
- def test_set_with_boolean_values
71
- db = Sequel.mock(host: :sqlite)
72
- db.extension :settable
73
- db.set(autocommit: true, log_statement: false)
74
-
75
- expected_sqls = ['SET autocommit=true', 'SET log_statement=false']
76
-
77
- assert_equal expected_sqls, db.sqls
78
- end
79
-
80
- def test_set_with_nil_values
81
- db = Sequel.mock(host: :sqlite)
82
- db.extension :settable
83
- db.set(timezone: nil, search_path: nil)
84
-
85
- expected_sqls = ['SET timezone=', 'SET search_path=']
86
-
87
- assert_equal expected_sqls, db.sqls
88
- end
89
-
90
- def test_set_sql_private_method
91
- db = Sequel.mock(host: :sqlite)
92
- db.extension :settable
93
-
94
- refute_respond_to db, :set_sql
95
- end
96
-
97
- def test_multiple_set_calls
98
- db = Sequel.mock(host: :sqlite)
99
- db.extension :settable
100
-
101
- db.set(timezone: 'UTC')
102
- db.set(search_path: 'public')
103
-
104
- expected_sqls = ['SET timezone=UTC', 'SET search_path=public']
105
-
106
- assert_equal expected_sqls, db.sqls
107
- end
108
-
109
- end
@@ -1,231 +0,0 @@
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
@@ -1,76 +0,0 @@
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
@@ -1,15 +0,0 @@
1
- require_relative '../../../test_helper'
2
- require 'sequel'
3
- require 'sequel/extensions/usable'
4
-
5
- class TestUsable < Minitest::Test
6
-
7
- def test_should_call_use
8
- db = Sequel.mock(host: :sqlite)
9
- db.extension :usable
10
- db.use(:some_schema)
11
-
12
- assert_equal(['USE `some_schema`'], db.sqls)
13
- end
14
-
15
- end
@@ -1,123 +0,0 @@
1
- require_relative '../../test_helper'
2
- require 'sequelizer'
3
-
4
- class TestConnectionMaker < Minitest::Test
5
-
6
- def setup
7
- @options = { 'adapter' => 'mock', 'host' => 'postgres' }
8
- end
9
-
10
- def test_accepts_options_as_params
11
- Sequelizer::YamlConfig.stub :user_config_path, Pathname.new('/completely/made/up/path/that/does/not/exist') do
12
- assert_equal :postgres, Sequelizer::ConnectionMaker.new(@options).connection.database_type
13
- end
14
- end
15
-
16
- def with_ignored_yaml_config(opts = {}); end
17
-
18
- def with_yaml_config(options = {}, &)
19
- yaml_config = Sequelizer::YamlConfig.new
20
- yaml_config.stub(:options, options) do
21
- Sequelizer::YamlConfig.stub(:new, yaml_config, &)
22
- end
23
- end
24
-
25
- def with_env_config(options = {})
26
- env_config = Sequelizer::EnvConfig.new
27
- env_config.stub(:options, options) do
28
- Sequelizer::EnvConfig.stub :new, env_config do
29
- yield env_config
30
- end
31
- end
32
- end
33
-
34
- def test_reads_options_from_yaml_config
35
- with_yaml_config(@options) do
36
- assert_equal :postgres, Sequelizer::ConnectionMaker.new.connection.database_type
37
- end
38
- end
39
-
40
- def test_ignores_options_from_yaml_config_when_asked
41
- with_yaml_config(@options) do
42
- assert_nil Sequelizer::ConnectionMaker.new(ignore_yaml: true).options.to_hash[:adapter]
43
- end
44
- end
45
-
46
- def test_applies_settings_if_given
47
- with_yaml_config(@options.merge(postgres_db_opt_flim: :flam)) do
48
- with_env_config do
49
- conn = Sequelizer::ConnectionMaker.new.connection
50
- conn.test_connection
51
-
52
- assert_equal(['SET flim=flam'], conn.sqls)
53
- end
54
- end
55
- end
56
-
57
- def test_applies_settings_for_all_connections_if_given
58
- with_yaml_config(@options.merge(postgres_db_opt_flim: :flam, max_connections: 2, preconnect: :concurrent)) do
59
- with_env_config do
60
- conn = Sequelizer::ConnectionMaker.new.connection
61
- conn.test_connection
62
-
63
- assert_equal(['SET flim=flam'] * 2, conn.sqls)
64
- end
65
- end
66
- end
67
-
68
- def test_reads_options_from_env_config_if_no_yaml_config
69
- with_yaml_config do
70
- with_env_config(@options) do
71
- assert_equal :postgres, Sequelizer::ConnectionMaker.new.connection.database_type
72
- end
73
- end
74
- end
75
-
76
- def test_ignores_options_from_env_config_if_no_yaml_config
77
- with_yaml_config do
78
- with_env_config(@options) do
79
- assert_nil Sequelizer::ConnectionMaker.new(ignore_env: true).options.to_hash[:adapter]
80
- end
81
- end
82
- end
83
-
84
- def test_applies_configuration_to_connection
85
- opts = @options.merge(postgres_db_opt_search_path: 'searchy', impala_db_opt_search_path: 'searchy2')
86
- with_yaml_config(opts) do
87
- conn = Sequelizer::ConnectionMaker.new.connection
88
- conn.test_connection
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
- end
93
- end
94
-
95
- def test_applies_nothing_when_no_configuration
96
- Sequelizer::YamlConfig.stub :user_config_path, Pathname.new('/completely/made/up/path/that/does/not/exist') do
97
- conn = Sequelizer::ConnectionMaker.new(@options).connection
98
- conn.test_connection
99
-
100
- assert_empty(conn.db_opts.to_hash)
101
- assert_empty(conn.db_opts.sql_statements)
102
- end
103
- end
104
-
105
- def test_applies_quotes_when_necessary
106
- Sequelizer::YamlConfig.stub :user_config_path, Pathname.new('/completely/made/up/path/that/does/not/exist') do
107
- @options.merge!(postgres_db_opt_search_path: 'searchy,path')
108
- conn = Sequelizer::ConnectionMaker.new(@options).connection
109
- conn.test_connection
110
-
111
- assert_equal({ search_path: "'searchy,path'" }, conn.db_opts.to_hash)
112
- assert_equal(["SET search_path='searchy,path'"], conn.db_opts.sql_statements)
113
- end
114
- end
115
-
116
- def test_applies_extensions
117
- with_yaml_config(@options.merge(extension_error_sql: 1)) do
118
- assert_includes Sequelizer::ConnectionMaker.new.connection.send(:instance_variable_get, :@loaded_extensions), :error_sql,
119
- "Extension wasn't set"
120
- end
121
- end
122
-
123
- end
@@ -1,37 +0,0 @@
1
- require_relative '../../test_helper'
2
- require 'sequelizer'
3
-
4
- class TestEnvConfig < Minitest::Test
5
-
6
- def setup
7
- @env_config = Sequelizer::EnvConfig.new
8
- end
9
-
10
- def test_loads_dotenv
11
- mock = Minitest::Mock.new
12
- stub_const(Sequelizer::EnvConfig, :Dotenv, mock) do
13
- mock.expect :load, nil
14
- @env_config.options
15
- mock.verify
16
- end
17
- end
18
-
19
- def test_options_default_to_empty_hash
20
- assert_empty(@env_config.options)
21
- end
22
-
23
- def test_converts_sequelizer_vars_to_options
24
- ENV['SEQUELIZER_ADAPTER'] = 'sqlite'
25
-
26
- assert_equal({ 'adapter' => 'sqlite' }, @env_config.options)
27
- ENV.delete('SEQUELIZER_ADAPTER')
28
- end
29
-
30
- def test_converts_db_opts_to_options
31
- ENV['POSTGRES_DB_OPT_HEY'] = 'there'
32
-
33
- assert_equal({ 'postgres_db_opt_hey' => 'there' }, @env_config.options)
34
- ENV.delete('POSTGRES_DB_OPT_HEY')
35
- end
36
-
37
- end
@@ -1,88 +0,0 @@
1
- require_relative '../../test_helper'
2
- require 'sequelizer/gemfile_modifier'
3
-
4
- class TestGemfileModifier < Minitest::Test
5
-
6
- def setup
7
- @gm = Sequelizer::GemfileModifier.new
8
- end
9
-
10
- def test_dies_if_gemfile_missing
11
- pn_mock = Minitest::Mock.new
12
- pn_mock.expect(:exist?, false)
13
-
14
- Pathname.stub(:new, pn_mock) do
15
- assert_raises(RuntimeError) { @gm.modify }
16
- end
17
- pn_mock.verify
18
- end
19
-
20
- def test_quits_if_no_modification_needed
21
- opts_mock = Minitest::Mock.new
22
- pn_mock = standard_pn_mock
23
- opts_mock.expect(:adapter, 'postgres')
24
- file_mock = Minitest::Mock.new
25
- file_mock.expect(:readlines, ["gem 'pg'"], [pn_mock])
26
-
27
- Pathname.stub(:new, pn_mock) do
28
- Sequelizer::Options.stub(:new, opts_mock) do
29
- stub_const(Sequelizer::GemfileModifier, :File, file_mock) do
30
- stub_modifying_methods(@gm) do
31
- @gm.modify
32
- end
33
- end
34
- end
35
- end
36
- end
37
-
38
- def test_quits_if_no_modification_needed2
39
- opts_mock = Minitest::Mock.new
40
- pn_mock = standard_pn_mock
41
- opts_mock.expect(:adapter, 'postgres')
42
- file_mock = Minitest::Mock.new
43
- file_mock.expect(:readlines, ["gem 'pg' # ADDED BY SEQUELIZER"], [pn_mock])
44
-
45
- Pathname.stub(:new, pn_mock) do
46
- Sequelizer::Options.stub(:new, opts_mock) do
47
- stub_const(Sequelizer::GemfileModifier, :File, file_mock) do
48
- stub_modifying_methods(@gm) do
49
- @gm.modify
50
- end
51
- end
52
- end
53
- end
54
- end
55
-
56
- def test_writes_if_modification_needed
57
- opts_mock = Minitest::Mock.new
58
- pn_mock = standard_pn_mock
59
- opts_mock.expect(:adapter, 'postgres')
60
- file_mock = Minitest::Mock.new
61
- file_mock.expect(:readlines, ['#comment line', "gem 'sqlite3' # ADDED BY SEQUELIZER"], [pn_mock])
62
- file_mock.expect(:write, nil, [pn_mock, ['#comment line', "gem 'pg' # ADDED BY SEQUELIZER"].join("\n")])
63
-
64
- Pathname.stub(:new, pn_mock) do
65
- Sequelizer::Options.stub(:new, opts_mock) do
66
- stub_const(Sequelizer::GemfileModifier, :File, file_mock) do
67
- stub_modifying_methods(@gm) do
68
- @gm.modify
69
- end
70
- end
71
- end
72
- end
73
- end
74
-
75
- private
76
-
77
- def standard_pn_mock
78
- pn_mock = Minitest::Mock.new
79
- pn_mock.expect(:exist?, true)
80
- end
81
-
82
- def stub_modifying_methods(obj, &)
83
- obj.stub(:system, nil) do
84
- obj.stub(:puts, nil, &)
85
- end
86
- end
87
-
88
- end