rom-sql 2.0.0.beta2 → 2.0.0.beta3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (170) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +66 -0
  3. data/lib/rom/plugins/relation/sql/postgres/explain.rb +54 -0
  4. data/lib/rom/sql.rb +1 -1
  5. data/lib/rom/sql/attribute.rb +17 -18
  6. data/lib/rom/sql/errors.rb +3 -0
  7. data/lib/rom/sql/extensions/mysql.rb +1 -1
  8. data/lib/rom/sql/extensions/mysql/type_builder.rb +28 -0
  9. data/lib/rom/sql/extensions/postgres.rb +3 -1
  10. data/lib/rom/sql/extensions/postgres/commands.rb +30 -13
  11. data/lib/rom/sql/extensions/postgres/{attributes_inferrer.rb → type_builder.rb} +24 -28
  12. data/lib/rom/sql/extensions/postgres/type_serializer.rb +39 -0
  13. data/lib/rom/sql/extensions/postgres/types.rb +24 -477
  14. data/lib/rom/sql/extensions/postgres/types/array.rb +163 -0
  15. data/lib/rom/sql/extensions/postgres/types/geometric.rb +135 -0
  16. data/lib/rom/sql/extensions/postgres/types/json.rb +235 -0
  17. data/lib/rom/sql/extensions/postgres/types/network.rb +15 -0
  18. data/lib/rom/sql/extensions/sqlite.rb +1 -1
  19. data/lib/rom/sql/extensions/sqlite/{attributes_inferrer.rb → type_builder.rb} +5 -5
  20. data/lib/rom/sql/extensions/sqlite/types.rb +8 -3
  21. data/lib/rom/sql/foreign_key.rb +17 -0
  22. data/lib/rom/sql/function.rb +86 -8
  23. data/lib/rom/sql/gateway.rb +26 -26
  24. data/lib/rom/sql/index.rb +4 -0
  25. data/lib/rom/sql/migration.rb +3 -3
  26. data/lib/rom/sql/migration/inline_runner.rb +9 -83
  27. data/lib/rom/sql/migration/migrator.rb +35 -12
  28. data/lib/rom/sql/migration/recorder.rb +21 -0
  29. data/lib/rom/sql/migration/runner.rb +115 -0
  30. data/lib/rom/sql/migration/schema_diff.rb +108 -53
  31. data/lib/rom/sql/migration/writer.rb +61 -0
  32. data/lib/rom/sql/relation.rb +2 -1
  33. data/lib/rom/sql/relation/reading.rb +63 -3
  34. data/lib/rom/sql/relation/writing.rb +38 -0
  35. data/lib/rom/sql/schema.rb +9 -3
  36. data/lib/rom/sql/schema/attributes_inferrer.rb +3 -119
  37. data/lib/rom/sql/schema/inferrer.rb +99 -18
  38. data/lib/rom/sql/schema/type_builder.rb +94 -0
  39. data/lib/rom/sql/type_dsl.rb +30 -0
  40. data/lib/rom/sql/type_extensions.rb +11 -6
  41. data/lib/rom/sql/type_serializer.rb +46 -0
  42. data/lib/rom/sql/types.rb +12 -0
  43. data/lib/rom/sql/version.rb +1 -1
  44. metadata +26 -244
  45. data/.codeclimate.yml +0 -15
  46. data/.gitignore +0 -17
  47. data/.rspec +0 -3
  48. data/.travis.yml +0 -39
  49. data/.yardopts +0 -2
  50. data/Gemfile +0 -33
  51. data/Guardfile +0 -24
  52. data/LICENSE.txt +0 -22
  53. data/Rakefile +0 -19
  54. data/circle.yml +0 -10
  55. data/lib/rom/sql/extensions/mysql/attributes_inferrer.rb +0 -10
  56. data/lib/rom/sql/relation/sequel_api.rb +0 -133
  57. data/log/.gitkeep +0 -0
  58. data/rom-sql.gemspec +0 -29
  59. data/spec/extensions/postgres/attribute_spec.rb +0 -217
  60. data/spec/extensions/postgres/integration_spec.rb +0 -59
  61. data/spec/extensions/postgres/types_spec.rb +0 -252
  62. data/spec/extensions/sqlite/types_spec.rb +0 -11
  63. data/spec/fixtures/migrations/20150403090603_create_carrots.rb +0 -8
  64. data/spec/integration/associations/many_to_many/custom_fks_spec.rb +0 -76
  65. data/spec/integration/associations/many_to_many/from_view_spec.rb +0 -88
  66. data/spec/integration/associations/many_to_many_spec.rb +0 -162
  67. data/spec/integration/associations/many_to_one/custom_fks_spec.rb +0 -64
  68. data/spec/integration/associations/many_to_one/from_view_spec.rb +0 -84
  69. data/spec/integration/associations/many_to_one/self_ref_spec.rb +0 -53
  70. data/spec/integration/associations/many_to_one_spec.rb +0 -117
  71. data/spec/integration/associations/one_to_many/custom_fks_spec.rb +0 -54
  72. data/spec/integration/associations/one_to_many/from_view_spec.rb +0 -57
  73. data/spec/integration/associations/one_to_many/self_ref_spec.rb +0 -54
  74. data/spec/integration/associations/one_to_many_spec.rb +0 -86
  75. data/spec/integration/associations/one_to_one_spec.rb +0 -69
  76. data/spec/integration/associations/one_to_one_through_spec.rb +0 -92
  77. data/spec/integration/auto_migrations/errors_spec.rb +0 -31
  78. data/spec/integration/auto_migrations/indexes_spec.rb +0 -253
  79. data/spec/integration/auto_migrations/managing_columns_spec.rb +0 -156
  80. data/spec/integration/auto_migrations/postgres/column_types_spec.rb +0 -63
  81. data/spec/integration/combine_with_spec.rb +0 -43
  82. data/spec/integration/commands/create_spec.rb +0 -304
  83. data/spec/integration/commands/delete_spec.rb +0 -84
  84. data/spec/integration/commands/update_spec.rb +0 -90
  85. data/spec/integration/commands/upsert_spec.rb +0 -83
  86. data/spec/integration/gateway_spec.rb +0 -107
  87. data/spec/integration/migration_spec.rb +0 -55
  88. data/spec/integration/plugins/associates/many_to_many_spec.rb +0 -69
  89. data/spec/integration/plugins/associates_spec.rb +0 -250
  90. data/spec/integration/plugins/auto_restrictions_spec.rb +0 -74
  91. data/spec/integration/relation_schema_spec.rb +0 -271
  92. data/spec/integration/schema/call_spec.rb +0 -24
  93. data/spec/integration/schema/inferrer/mysql_spec.rb +0 -45
  94. data/spec/integration/schema/inferrer/postgres_spec.rb +0 -203
  95. data/spec/integration/schema/inferrer/sqlite_spec.rb +0 -37
  96. data/spec/integration/schema/inferrer_spec.rb +0 -390
  97. data/spec/integration/schema/prefix_spec.rb +0 -16
  98. data/spec/integration/schema/qualified_spec.rb +0 -16
  99. data/spec/integration/schema/rename_spec.rb +0 -21
  100. data/spec/integration/schema/view_spec.rb +0 -29
  101. data/spec/integration/sequel_api_spec.rb +0 -36
  102. data/spec/integration/setup_spec.rb +0 -26
  103. data/spec/integration/support/active_support_notifications_spec.rb +0 -24
  104. data/spec/integration/support/rails_log_subscriber_spec.rb +0 -30
  105. data/spec/integration/wrap_spec.rb +0 -91
  106. data/spec/shared/accounts.rb +0 -48
  107. data/spec/shared/database_setup.rb +0 -70
  108. data/spec/shared/notes.rb +0 -23
  109. data/spec/shared/posts.rb +0 -34
  110. data/spec/shared/puppies.rb +0 -15
  111. data/spec/shared/relations.rb +0 -8
  112. data/spec/shared/users.rb +0 -32
  113. data/spec/shared/users_and_tasks.rb +0 -50
  114. data/spec/spec_helper.rb +0 -122
  115. data/spec/support/env_helper.rb +0 -25
  116. data/spec/support/helpers.rb +0 -24
  117. data/spec/support/oracle/create_users.sql +0 -7
  118. data/spec/support/oracle/set_sys_passwords.sql +0 -2
  119. data/spec/support/test_configuration.rb +0 -16
  120. data/spec/unit/attribute_spec.rb +0 -104
  121. data/spec/unit/function_spec.rb +0 -48
  122. data/spec/unit/gateway_spec.rb +0 -70
  123. data/spec/unit/logger_spec.rb +0 -14
  124. data/spec/unit/migration_tasks_spec.rb +0 -111
  125. data/spec/unit/migrator_spec.rb +0 -25
  126. data/spec/unit/order_dsl_spec.rb +0 -43
  127. data/spec/unit/plugin/associates_spec.rb +0 -94
  128. data/spec/unit/plugin/pagination_spec.rb +0 -91
  129. data/spec/unit/plugin/timestamp_spec.rb +0 -117
  130. data/spec/unit/projection_dsl_spec.rb +0 -110
  131. data/spec/unit/relation/assoc_spec.rb +0 -87
  132. data/spec/unit/relation/associations_spec.rb +0 -27
  133. data/spec/unit/relation/avg_spec.rb +0 -11
  134. data/spec/unit/relation/by_pk_spec.rb +0 -62
  135. data/spec/unit/relation/dataset_spec.rb +0 -50
  136. data/spec/unit/relation/distinct_spec.rb +0 -15
  137. data/spec/unit/relation/exclude_spec.rb +0 -11
  138. data/spec/unit/relation/exist_predicate_spec.rb +0 -25
  139. data/spec/unit/relation/exists_spec.rb +0 -18
  140. data/spec/unit/relation/fetch_spec.rb +0 -21
  141. data/spec/unit/relation/group_spec.rb +0 -61
  142. data/spec/unit/relation/having_spec.rb +0 -22
  143. data/spec/unit/relation/inner_join_spec.rb +0 -158
  144. data/spec/unit/relation/inspect_spec.rb +0 -11
  145. data/spec/unit/relation/instrument_spec.rb +0 -45
  146. data/spec/unit/relation/invert_spec.rb +0 -11
  147. data/spec/unit/relation/left_join_spec.rb +0 -55
  148. data/spec/unit/relation/lock_spec.rb +0 -93
  149. data/spec/unit/relation/map_spec.rb +0 -16
  150. data/spec/unit/relation/max_spec.rb +0 -11
  151. data/spec/unit/relation/min_spec.rb +0 -11
  152. data/spec/unit/relation/order_spec.rb +0 -51
  153. data/spec/unit/relation/pluck_spec.rb +0 -11
  154. data/spec/unit/relation/prefix_spec.rb +0 -29
  155. data/spec/unit/relation/primary_key_spec.rb +0 -27
  156. data/spec/unit/relation/project_spec.rb +0 -24
  157. data/spec/unit/relation/qualified_columns_spec.rb +0 -30
  158. data/spec/unit/relation/qualified_spec.rb +0 -25
  159. data/spec/unit/relation/read_spec.rb +0 -25
  160. data/spec/unit/relation/rename_spec.rb +0 -23
  161. data/spec/unit/relation/right_join_spec.rb +0 -57
  162. data/spec/unit/relation/select_append_spec.rb +0 -21
  163. data/spec/unit/relation/select_spec.rb +0 -40
  164. data/spec/unit/relation/sum_spec.rb +0 -11
  165. data/spec/unit/relation/union_spec.rb +0 -19
  166. data/spec/unit/relation/unique_predicate_spec.rb +0 -18
  167. data/spec/unit/relation/where_spec.rb +0 -133
  168. data/spec/unit/restriction_dsl_spec.rb +0 -34
  169. data/spec/unit/schema_spec.rb +0 -25
  170. data/spec/unit/types_spec.rb +0 -65
@@ -1,15 +0,0 @@
1
- RSpec.shared_context 'puppies' do
2
- before do
3
- inferrable_relations.concat %i(puppies)
4
- end
5
-
6
- before do
7
- conn.create_table :puppies do
8
- primary_key :id
9
- String :name, null: false
10
- boolean :cute, null: false, default: true
11
- end
12
-
13
- conf.relation(:puppies) { schema(infer: true) }
14
- end
15
- end
@@ -1,8 +0,0 @@
1
- RSpec.shared_context 'relations' do
2
- include_context 'users and tasks'
3
-
4
- before do
5
- conf.relation(:users) { schema(infer: true) }
6
- conf.relation(:tasks) { schema(infer: true) }
7
- end
8
- end
data/spec/shared/users.rb DELETED
@@ -1,32 +0,0 @@
1
- RSpec.shared_context 'users' do
2
- include_context 'database setup'
3
-
4
- before do
5
- inferrable_relations.concat %i(users)
6
- end
7
-
8
- let(:users) { container.relations[:users] }
9
- let(:user_commands) { container.commands[:users] }
10
-
11
- let(:jane_id) { 1 }
12
- let(:joe_id) { 2 }
13
-
14
- before do |example|
15
- ctx = self
16
-
17
- conn.create_table :users do
18
- primary_key :id
19
- String :name, text: false, null: false
20
- check { char_length(name) > 2 } if ctx.postgres?(example)
21
- end
22
-
23
- conf.relation(:users) { schema(infer: true) }
24
- end
25
-
26
- before do |example|
27
- next if example.metadata[:seeds] == false
28
-
29
- conn[:users].insert name: 'Jane'
30
- conn[:users].insert name: 'Joe'
31
- end
32
- end
@@ -1,50 +0,0 @@
1
- RSpec.shared_context 'users and tasks' do
2
- include_context 'users'
3
-
4
- let(:tasks) { container.relations[:tasks] }
5
- let(:tags) { container.relations[:tags] }
6
-
7
- let(:task_commands) { container.commands[:tasks] }
8
- let(:tag_commands) { container.commands[:tags] }
9
-
10
- before do
11
- inferrable_relations.concat %i(tasks tags task_tags)
12
- end
13
-
14
- before do |example|
15
- ctx = self
16
-
17
- conn.create_table :tasks do
18
- primary_key :id
19
- foreign_key :user_id, :users
20
- String :title, text: false
21
- constraint(:title_length) { char_length(title) > 1 } if ctx.postgres?(example)
22
- constraint(:title_length) { length(title) > 1 } if ctx.sqlite?(example)
23
- end
24
-
25
- conn.create_table :tags do
26
- primary_key :id
27
- String :name
28
- end
29
-
30
- conn.create_table :task_tags do
31
- primary_key [:tag_id, :task_id]
32
- Integer :tag_id
33
- Integer :task_id
34
- end
35
-
36
- conf.relation(:tasks) { schema(infer: true) }
37
- conf.relation(:task_tags) { schema(infer: true) }
38
- conf.relation(:tags) { schema(infer: true) }
39
- end
40
-
41
- before do |example|
42
- next if example.metadata[:seeds] == false
43
-
44
- conn[:tasks].insert id: 1, user_id: 2, title: "Joe's task"
45
- conn[:tasks].insert id: 2, user_id: 1, title: "Jane's task"
46
-
47
- conn[:tags].insert id: 1, name: 'important'
48
- conn[:task_tags].insert(tag_id: 1, task_id: 1)
49
- end
50
- end
data/spec/spec_helper.rb DELETED
@@ -1,122 +0,0 @@
1
- require 'bundler'
2
- Bundler.setup
3
-
4
- if RUBY_ENGINE == 'ruby' && ENV['COVERAGE'] == 'true'
5
- require 'yaml'
6
- rubies = YAML.load(File.read(File.join(__dir__, '..', '.travis.yml')))['rvm']
7
- latest_mri = rubies.select { |v| v =~ /\A\d+\.\d+.\d+\z/ }.max
8
-
9
- if RUBY_VERSION == latest_mri
10
- require 'simplecov'
11
- SimpleCov.start do
12
- add_filter '/spec/'
13
- end
14
- end
15
- end
16
-
17
- require 'rom-sql'
18
- require 'rom/sql/rake_task'
19
-
20
- require 'logger'
21
- require 'tempfile'
22
-
23
- begin
24
- require ENV['DEBUGGER'] || 'byebug'
25
- rescue LoadError
26
- require 'pry'
27
- end
28
-
29
- LOGGER = Logger.new(File.open('./log/test.log', 'a'))
30
- ENV['TZ'] ||= 'UTC'
31
-
32
- oracle_settings = {
33
- db_name: ENV.fetch('ROM_ORACLE_DATABASE', 'xe'),
34
- host: ENV.fetch('ROM_ORACLE_HOST', 'localhost'),
35
- port: Integer(ENV.fetch('ROM_ORACLE_PORT', '1521'))
36
- }
37
-
38
- if defined? JRUBY_VERSION
39
- DB_URIS = {
40
- sqlite: 'jdbc:sqlite:::memory',
41
- postgres: 'jdbc:postgresql://localhost/rom_sql',
42
- mysql: 'jdbc:mysql://localhost/rom_sql?user=root&sql_mode=STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION',
43
- oracle: ENV['ROM_USE_ORACLE'] ? fail('Setup Oracle for JRuby!') : nil
44
- }
45
- else
46
- DB_URIS = {
47
- sqlite: 'sqlite::memory',
48
- postgres: 'postgres://localhost/rom_sql',
49
- mysql: 'mysql2://root@localhost/rom_sql?sql_mode=STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION',
50
- oracle: "oracle://#{ oracle_settings[:host] }:#{ oracle_settings[:port] }/" \
51
- "#{ oracle_settings[:db_name] }?username=rom_sql&password=rom_sql&autosequence=true"
52
- }
53
- end
54
-
55
- ADAPTERS = ENV['ROM_USE_ORACLE'] ? DB_URIS.keys : DB_URIS.keys - %i(oracle)
56
- PG_LTE_95 = ENV.fetch('PG_LTE_95', 'true') == 'true'
57
-
58
- SPEC_ROOT = root = Pathname(__FILE__).dirname
59
-
60
- TMP_PATH = root.join('../tmp')
61
-
62
- # quiet in specs
63
- ROM::SQL::Relation.tap { |r| r.schema_inferrer(r.schema_inferrer.suppress_errors) }
64
-
65
- require 'dry/core/deprecations'
66
- Dry::Core::Deprecations.set_logger!(root.join('../log/deprecations.log'))
67
-
68
- ROM::SQL.load_extensions(:postgres, :sqlite)
69
-
70
- require 'dry-types'
71
- module Types
72
- include Dry::Types.module
73
- end
74
-
75
- def with_adapters(*args, &block)
76
- reset_adapter = Hash[*ADAPTERS.flat_map { |a| [a, false] }]
77
- adapters = args.empty? || args[0] == :all ? ADAPTERS : (args & ADAPTERS)
78
-
79
- adapters.each do |adapter|
80
- context("with #{adapter}", **reset_adapter, adapter => true, &block)
81
- end
82
- end
83
-
84
- warning_api_available = RUBY_VERSION >= '2.4.0'
85
-
86
- module SileneceWarnings
87
- def warn(str)
88
- if str['/sequel/'] || str['/rspec-core']
89
- nil
90
- else
91
- super
92
- end
93
- end
94
- end
95
-
96
- Warning.extend(SileneceWarnings) if warning_api_available
97
-
98
- RSpec.configure do |config|
99
- config.disable_monkey_patching!
100
- config.warnings = warning_api_available
101
-
102
- config.before(:suite) do
103
- tmp_test_dir = TMP_PATH.join('test')
104
- FileUtils.rm_r(tmp_test_dir) if File.exist?(tmp_test_dir)
105
- FileUtils.mkdir_p(tmp_test_dir)
106
- end
107
-
108
- config.before do
109
- module Test
110
- end
111
- end
112
-
113
- config.after do
114
- Object.send(:remove_const, :Test)
115
- end
116
-
117
- Dir[root.join('shared/**/*.rb')].each { |f| require f }
118
- Dir[root.join('support/**/*.rb')].each { |f| require f }
119
-
120
- config.include(Helpers, helpers: true)
121
- config.include ENVHelper
122
- end
@@ -1,25 +0,0 @@
1
- module ENVHelper
2
- def db?(type, example)
3
- example.metadata[type]
4
- end
5
-
6
- def postgres?(example)
7
- db?(:postgres, example)
8
- end
9
-
10
- def mysql?(example)
11
- db?(:mysql, example)
12
- end
13
-
14
- def sqlite?(example)
15
- db?(:sqlite, example)
16
- end
17
-
18
- def oracle?(example)
19
- db?(:oracle, example)
20
- end
21
-
22
- def jruby?
23
- defined? JRUBY_VERSION
24
- end
25
- end
@@ -1,24 +0,0 @@
1
- module Helpers
2
- def assoc_name(*args)
3
- ROM::Relation::Name[*args]
4
- end
5
-
6
- def define_schema(name, attrs = [])
7
- relation_name = ROM::Relation::Name.new(name)
8
- ROM::SQL::Schema.define(
9
- relation_name,
10
- attributes: attrs.map { |key, value| value.meta(name: key, source: relation_name) },
11
- attr_class: ROM::SQL::Attribute
12
- )
13
- end
14
-
15
- def define_attribute(name, id, **opts)
16
- ROM::SQL::Attribute.new(ROM::Types.const_get(id).meta(name: name, **opts))
17
- end
18
-
19
- def build_assoc(type, *args)
20
- klass = Dry::Core::Inflector.classify(type)
21
- definition = ROM::Associations::Definitions.const_get(klass).new(*args)
22
- ROM::SQL::Associations.const_get(definition.type).new(definition, relations)
23
- end
24
- end
@@ -1,7 +0,0 @@
1
- alter database default tablespace USERS;
2
-
3
- CREATE USER rom_sql IDENTIFIED BY rom_sql;
4
-
5
- GRANT unlimited tablespace, create session, create table, create sequence,
6
- create procedure, create trigger, create view, create materialized view,
7
- create database link, create synonym, create type, ctxapp TO rom_sql;
@@ -1,2 +0,0 @@
1
- -- alter user sys identified by admin;
2
- -- alter user system identified by admin;
@@ -1,16 +0,0 @@
1
- require 'rom/configuration'
2
-
3
- class TestConfiguration < ROM::Configuration
4
- def relation(name, &block)
5
- if registered_relation_names.include?(name)
6
- setup.relation_classes.delete_if do |klass|
7
- klass.relation_name.relation == name
8
- end
9
- end
10
- super
11
- end
12
-
13
- def registered_relation_names
14
- setup.relation_classes.map(&:relation_name).map(&:relation)
15
- end
16
- end
@@ -1,104 +0,0 @@
1
- require 'spec_helper'
2
-
3
- RSpec.describe ROM::SQL::Attribute, :postgres do
4
- include_context 'users and tasks'
5
-
6
- let(:ds) { users.dataset }
7
-
8
- describe '#is' do
9
- context 'with a standard value' do
10
- it 'returns a boolean expression' do
11
- expect(users[:id].is(1).sql_literal(ds)).to eql('("id" = 1)')
12
- end
13
-
14
- it 'returns a boolean equality expression for qualified attribute' do
15
- expect((users[:id].qualified.is(1)).sql_literal(ds)).to eql('("users"."id" = 1)')
16
- end
17
- end
18
-
19
- context 'with a nil value' do
20
- it 'returns an IS NULL expression' do
21
- expect(users[:id].is(nil).sql_literal(ds)).to eql('("id" IS NULL)')
22
- end
23
-
24
- it 'returns an IS NULL expression for qualified attribute' do
25
- expect((users[:id].qualified.is(nil)).sql_literal(ds)).to eql('("users"."id" IS NULL)')
26
- end
27
- end
28
-
29
- context 'with a boolean true' do
30
- it 'returns an IS TRUE expression' do
31
- expect(users[:id].is(true).sql_literal(ds)).to eql('("id" IS TRUE)')
32
- end
33
-
34
- it 'returns an IS TRUE expression for qualified attribute' do
35
- expect((users[:id].qualified.is(true)).sql_literal(ds)).to eql('("users"."id" IS TRUE)')
36
- end
37
- end
38
-
39
- context 'with a boolean false' do
40
- it 'returns an IS FALSE expression' do
41
- expect(users[:id].is(false).sql_literal(ds)).to eql('("id" IS FALSE)')
42
- end
43
-
44
- it 'returns an IS FALSE expression for qualified attribute' do
45
- expect((users[:id].qualified.is(false)).sql_literal(ds)).to eql('("users"."id" IS FALSE)')
46
- end
47
- end
48
- end
49
-
50
- describe '#not' do
51
- context 'with a standard value' do
52
- it 'returns a negated boolean equality expression' do
53
- expect(users[:id].not(1).sql_literal(ds)).to eql('("id" != 1)')
54
- end
55
-
56
- it 'returns a negated boolean equality expression for qualified attribute' do
57
- expect((users[:id].qualified.not(1)).sql_literal(ds)).to eql('("users"."id" != 1)')
58
- end
59
- end
60
-
61
- context 'with a nil value' do
62
- it 'returns an IS NOT NULL expression' do
63
- expect(users[:id].not(nil).sql_literal(ds)).to eql('("id" IS NOT NULL)')
64
- end
65
-
66
- it 'returns an IS NOT NULL expression for qualified attribute' do
67
- expect((users[:id].qualified.not(nil)).sql_literal(ds)).to eql('("users"."id" IS NOT NULL)')
68
- end
69
- end
70
-
71
- context 'with a boolean true' do
72
- it 'returns an IS NOT TRUE expression' do
73
- expect(users[:id].not(true).sql_literal(ds)).to eql('("id" IS NOT TRUE)')
74
- end
75
-
76
- it 'returns an IS NOT TRUE expression for qualified attribute' do
77
- expect((users[:id].qualified.not(true)).sql_literal(ds)).to eql('("users"."id" IS NOT TRUE)')
78
- end
79
- end
80
-
81
- context 'with a boolean false' do
82
- it 'returns an IS NOT FALSE expression' do
83
- expect(users[:id].not(false).sql_literal(ds)).to eql('("id" IS NOT FALSE)')
84
- end
85
-
86
- it 'returns an IS NOT FALSE expression for qualified attribute' do
87
- expect((users[:id].qualified.not(false)).sql_literal(ds)).to eql('("users"."id" IS NOT FALSE)')
88
- end
89
- end
90
- end
91
-
92
- describe '#!' do
93
- it 'returns a new attribute with negated sql expr' do
94
- expect((!users[:id].is(1)).sql_literal(ds)).to eql('("id" != 1)')
95
- end
96
- end
97
-
98
- describe '#concat' do
99
- it 'returns a concat function attribute' do
100
- expect(users[:id].concat(users[:name]).as(:uid).sql_literal(ds)).
101
- to eql(%(CONCAT("id", ' ', "name") AS "uid"))
102
- end
103
- end
104
- end
@@ -1,48 +0,0 @@
1
- require 'rom/sql/function'
2
-
3
- RSpec.describe ROM::SQL::Function, :postgres do
4
- subject(:func) { ROM::SQL::Function.new(type) }
5
-
6
- include_context 'database setup'
7
-
8
- let(:ds) { container.gateways[:default][:users] }
9
- let(:type) { ROM::SQL::Types::Int }
10
-
11
- describe '#sql_literal' do
12
- context 'without alias' do
13
- specify do
14
- expect(func.count(:id).sql_literal(ds)).to eql(%(COUNT("id")))
15
- end
16
- end
17
-
18
- context 'with alias' do
19
- specify do
20
- expect(func.count(:id).as(:count).sql_literal(ds)).to eql(%(COUNT("id") AS "count"))
21
- end
22
- end
23
- end
24
-
25
- describe '#is' do
26
- it 'returns an sql boolean expression' do
27
- expect(ds.literal(func.count(:id).is(1))).to eql(%((COUNT("id") = 1)))
28
- end
29
- end
30
-
31
- describe '#method_missing' do
32
- it 'responds to anything when not set' do
33
- expect(func.count(:id)).to be_instance_of(func.class)
34
- end
35
-
36
- it 'raises error when is set already' do
37
- expect { func.count(:id).upper.sql_literal(ds) }.
38
- to raise_error(NoMethodError, /upper/)
39
- end
40
- end
41
-
42
- describe '#cast' do
43
- it 'transforms data' do
44
- expect(func.cast(:id, 'varchar').sql_literal(ds)).
45
- to eql(%(CAST("id" AS varchar(255))))
46
- end
47
- end
48
- end