rom-sql 0.3.2 → 0.4.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.rubocop.yml +55 -18
  4. data/.rubocop_todo.yml +15 -0
  5. data/.travis.yml +10 -5
  6. data/CHANGELOG.md +18 -0
  7. data/Gemfile +8 -1
  8. data/Guardfile +24 -0
  9. data/README.md +14 -22
  10. data/Rakefile +13 -5
  11. data/lib/rom/sql.rb +5 -5
  12. data/lib/rom/sql/commands.rb +7 -49
  13. data/lib/rom/sql/commands/create.rb +29 -0
  14. data/lib/rom/sql/commands/delete.rb +18 -0
  15. data/lib/rom/sql/commands/transaction.rb +17 -0
  16. data/lib/rom/sql/commands/update.rb +54 -0
  17. data/lib/rom/sql/commands_ext/postgres.rb +24 -0
  18. data/lib/rom/sql/header.rb +8 -9
  19. data/lib/rom/sql/migration.rb +26 -0
  20. data/lib/rom/sql/plugin/pagination.rb +93 -0
  21. data/lib/rom/sql/rake_task.rb +2 -0
  22. data/lib/rom/sql/relation.rb +320 -0
  23. data/lib/rom/sql/relation/associations.rb +104 -0
  24. data/lib/rom/sql/relation/class_methods.rb +47 -0
  25. data/lib/rom/sql/relation/inspection.rb +16 -0
  26. data/lib/rom/sql/repository.rb +59 -0
  27. data/lib/rom/sql/support/rails_log_subscriber.rb +1 -1
  28. data/lib/rom/sql/tasks/migration_tasks.rake +56 -0
  29. data/lib/rom/sql/version.rb +1 -1
  30. data/rom-sql.gemspec +2 -3
  31. data/spec/integration/commands/create_spec.rb +66 -8
  32. data/spec/integration/commands/delete_spec.rb +22 -3
  33. data/spec/integration/commands/update_spec.rb +57 -6
  34. data/spec/integration/read_spec.rb +42 -1
  35. data/spec/shared/database_setup.rb +10 -5
  36. data/spec/spec_helper.rb +17 -0
  37. data/spec/support/active_support_notifications_spec.rb +5 -4
  38. data/spec/support/rails_log_subscriber_spec.rb +2 -2
  39. data/spec/unit/logger_spec.rb +5 -3
  40. data/spec/unit/many_to_many_spec.rb +2 -2
  41. data/spec/unit/migration_spec.rb +34 -0
  42. data/spec/unit/migration_tasks_spec.rb +99 -0
  43. data/spec/unit/one_to_many_spec.rb +0 -2
  44. data/spec/unit/plugin/pagination_spec.rb +73 -0
  45. data/spec/unit/relation_spec.rb +49 -3
  46. data/spec/unit/repository_spec.rb +33 -0
  47. data/spec/unit/schema_spec.rb +5 -17
  48. metadata +32 -35
  49. data/lib/rom/sql/adapter.rb +0 -100
  50. data/lib/rom/sql/relation_inclusion.rb +0 -149
  51. data/lib/rom/sql/support/sequel_dataset_ext.rb +0 -33
  52. data/spec/unit/adapter_spec.rb +0 -48
  53. data/spec/unit/config_spec.rb +0 -54
@@ -1,33 +0,0 @@
1
- module Sequel
2
- class Dataset
3
- def header
4
- ROM::SQL::Header.new(opts.fetch(:select) { columns }, opts[:from].first)
5
- end
6
-
7
- def project(*names)
8
- select(*header.project(*names))
9
- end
10
-
11
- def rename(options)
12
- select(*header.rename(options))
13
- end
14
-
15
- def prefix(col_prefix = default_prefix)
16
- rename(header.prefix(col_prefix).to_h)
17
- end
18
-
19
- def qualified
20
- select(*qualified_columns)
21
- end
22
-
23
- def qualified_columns
24
- header.qualified.to_a
25
- end
26
-
27
- private
28
-
29
- def default_prefix
30
- Inflecto.singularize(opts[:from].first)
31
- end
32
- end
33
- end
@@ -1,48 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe ROM::Adapter do
4
- subject(:adapter) { rom.postgres.adapter }
5
-
6
- let(:setup) { ROM.setup(postgres: 'postgres://localhost/rom') }
7
- let(:rom) { setup.finalize }
8
-
9
- describe 'setting up' do
10
- it 'works with database.yml-style hash' do
11
- setup = ROM.setup(adapter: 'postgres', database: 'rom')
12
- expect(setup[:default]).to eql(setup.repositories[:default])
13
- end
14
-
15
- it 'accepts additional options' do
16
- test = false
17
-
18
- setup = ROM.setup(
19
- adapter: 'postgres',
20
- database: 'rom',
21
- test: true,
22
- after_connect: proc { test = true }
23
- )
24
-
25
- setup.finalize
26
-
27
- expect(test).to be(true)
28
- end
29
- end
30
-
31
- describe '#dataset?' do
32
- it 'returns true if a table exists' do
33
- expect(adapter.dataset?(:users)).to be(true)
34
- end
35
-
36
- it 'returns false if a table does not exist' do
37
- expect(adapter.dataset?(:not_here)).to be(false)
38
- end
39
- end
40
-
41
- describe '#disconnect' do
42
- it 'disconnects via sequel connection' do
43
- # FIXME: no idea how to test it in a different way
44
- expect(adapter.connection).to receive(:disconnect)
45
- adapter.disconnect
46
- end
47
- end
48
- end
@@ -1,54 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe ROM::Config do
4
- let(:root) { '/somewhere' }
5
-
6
- describe '.build' do
7
- it 'rewrites database config hash to a URI for sqlite' do
8
- db_config = { adapter: 'sqlite', database: 'testing.sqlite', root: root }
9
-
10
- config = ROM::Config.build(db_config)
11
-
12
- if RUBY_ENGINE == 'jruby'
13
- expect(config)
14
- .to eql(default: "jdbc:sqlite:///somewhere/testing.sqlite")
15
- else
16
- expect(config).to eql(default: "sqlite:///somewhere/testing.sqlite")
17
- end
18
- end
19
-
20
- it 'rewrites database config hash to a URI for mysql' do
21
- db_config = {
22
- adapter: 'mysql',
23
- database: 'testing',
24
- username: 'piotr',
25
- hostname: 'localhost',
26
- password: 'secret',
27
- root: '/foo'
28
- }
29
-
30
- config = ROM::Config.build(db_config)
31
-
32
- if RUBY_ENGINE == 'jruby'
33
- expect(config)
34
- .to eql(default: "jdbc:mysql://piotr:secret@localhost/testing")
35
- else
36
- expect(config)
37
- .to eql(default: "mysql://piotr:secret@localhost/testing")
38
- end
39
-
40
- db_config = {
41
- adapter: 'mysql',
42
- database: 'testing'
43
- }
44
-
45
- config = ROM::Config.build(db_config)
46
-
47
- if RUBY_ENGINE == 'jruby'
48
- expect(config).to eql(default: "jdbc:mysql://localhost/testing")
49
- else
50
- expect(config).to eql(default: "mysql://localhost/testing")
51
- end
52
- end
53
- end
54
- end