torque-postgresql 2.4.2 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. checksums.yaml +4 -4
  2. data/README.rdoc +0 -17
  3. data/lib/torque/postgresql/adapter/database_statements.rb +32 -74
  4. data/lib/torque/postgresql/adapter/oid/enum_set.rb +1 -1
  5. data/lib/torque/postgresql/adapter/oid.rb +0 -3
  6. data/lib/torque/postgresql/adapter/quoting.rb +12 -20
  7. data/lib/torque/postgresql/adapter/schema_creation.rb +1 -2
  8. data/lib/torque/postgresql/adapter/schema_definitions.rb +0 -37
  9. data/lib/torque/postgresql/adapter/schema_dumper.rb +2 -60
  10. data/lib/torque/postgresql/adapter/schema_statements.rb +2 -74
  11. data/lib/torque/postgresql/adapter.rb +2 -11
  12. data/lib/torque/postgresql/associations/belongs_to_many_association.rb +5 -4
  13. data/lib/torque/postgresql/associations/{association.rb → foreign_association.rb} +1 -4
  14. data/lib/torque/postgresql/associations/preloader/association.rb +53 -26
  15. data/lib/torque/postgresql/associations/preloader/loader_query.rb +36 -0
  16. data/lib/torque/postgresql/associations/preloader.rb +1 -0
  17. data/lib/torque/postgresql/associations.rb +6 -1
  18. data/lib/torque/postgresql/attributes/builder/period.rb +6 -2
  19. data/lib/torque/postgresql/auxiliary_statement/settings.rb +22 -75
  20. data/lib/torque/postgresql/auxiliary_statement.rb +40 -39
  21. data/lib/torque/postgresql/base.rb +13 -33
  22. data/lib/torque/postgresql/config.rb +3 -30
  23. data/lib/torque/postgresql/inheritance.rb +1 -3
  24. data/lib/torque/postgresql/migration/command_recorder.rb +2 -12
  25. data/lib/torque/postgresql/railtie.rb +1 -5
  26. data/lib/torque/postgresql/reflection/abstract_reflection.rb +44 -20
  27. data/lib/torque/postgresql/relation/auxiliary_statement.rb +15 -28
  28. data/lib/torque/postgresql/relation.rb +10 -12
  29. data/lib/torque/postgresql/schema_cache.rb +2 -7
  30. data/lib/torque/postgresql/version.rb +1 -1
  31. data/lib/torque/postgresql.rb +1 -2
  32. data/lib/torque-postgresql.rb +0 -1
  33. data/spec/schema.rb +5 -21
  34. data/spec/spec_helper.rb +1 -2
  35. data/spec/tests/arel_spec.rb +2 -4
  36. data/spec/tests/auxiliary_statement_spec.rb +35 -374
  37. data/spec/tests/belongs_to_many_spec.rb +2 -50
  38. data/spec/tests/enum_set_spec.rb +10 -10
  39. data/spec/tests/enum_spec.rb +0 -90
  40. data/spec/tests/has_many_spec.rb +0 -46
  41. data/spec/tests/table_inheritance_spec.rb +15 -11
  42. metadata +8 -28
  43. data/lib/torque/postgresql/auxiliary_statement/recursive.rb +0 -149
  44. data/lib/torque/postgresql/table_name.rb +0 -41
  45. data/lib/torque/range.rb +0 -22
  46. data/spec/models/category.rb +0 -2
  47. data/spec/models/internal/user.rb +0 -5
  48. data/spec/tests/range_spec.rb +0 -36
  49. data/spec/tests/schema_spec.rb +0 -134
@@ -1,36 +0,0 @@
1
- require 'spec_helper'
2
-
3
- RSpec.xdescribe 'Range' do
4
- let(:sample) { (5..15) }
5
-
6
- it 'has intersection' do
7
- expect { sample.intersection(10) }.to raise_error(ArgumentError, /Range/)
8
-
9
- result = sample & (10..15)
10
- expect(result).to be_a(Range)
11
- expect(result.min).to be_eql(10)
12
- expect(result.max).to be_eql(15)
13
-
14
- result = sample & (15..20)
15
- expect(result).to be_a(Range)
16
- expect(result.min).to be_eql(15)
17
- expect(result.max).to be_eql(15)
18
-
19
- result = sample & (0..10)
20
- expect(result).to be_a(Range)
21
- expect(result.min).to be_eql(5)
22
- expect(result.max).to be_eql(10)
23
-
24
- result = sample & (-10..0)
25
- expect(result).to be_nil
26
- end
27
-
28
- it 'has union' do
29
- expect { sample.union(10) }.to raise_error(ArgumentError, /Range/)
30
-
31
- result = sample | (0..10)
32
- expect(result).to be_a(Range)
33
- expect(result.min).to be_eql(0)
34
- expect(result.max).to be_eql(15)
35
- end
36
- end
@@ -1,134 +0,0 @@
1
- require 'spec_helper'
2
-
3
- RSpec.describe 'Schema' do
4
- let(:connection) { ActiveRecord::Base.connection }
5
-
6
- before do
7
- connection.instance_variable_set(:@schmeas_blacklist, nil)
8
- connection.instance_variable_set(:@schmeas_whitelist, nil)
9
- end
10
-
11
- context 'on migration' do
12
- it 'can check for existance' do
13
- expect(connection.schema_exists?(:information_schema)).to be_falsey
14
- expect(connection.schema_exists?(:information_schema, filtered: false)).to be_truthy
15
- end
16
-
17
- it 'can be created' do
18
- expect(connection.schema_exists?(:legacy, filtered: false)).to be_falsey
19
- connection.create_schema(:legacy)
20
- expect(connection.schema_exists?(:legacy, filtered: false)).to be_truthy
21
- end
22
-
23
- it 'can be deleted' do
24
- expect(connection.schema_exists?(:legacy, filtered: false)).to be_falsey
25
-
26
- connection.create_schema(:legacy)
27
- expect(connection.schema_exists?(:legacy, filtered: false)).to be_truthy
28
-
29
- connection.drop_schema(:legacy)
30
- expect(connection.schema_exists?(:legacy, filtered: false)).to be_falsey
31
- end
32
-
33
- it 'works with whitelist' do
34
- expect(connection.schema_exists?(:legacy)).to be_falsey
35
- connection.create_schema(:legacy)
36
-
37
- expect(connection.schema_exists?(:legacy)).to be_falsey
38
- expect(connection.schema_exists?(:legacy, filtered: false)).to be_truthy
39
-
40
- connection.schemas_whitelist.push('legacy')
41
- expect(connection.schema_exists?(:legacy)).to be_truthy
42
- end
43
-
44
- context 'reverting' do
45
- let(:migration) { ActiveRecord::Migration::Current.new('Testing') }
46
-
47
- before { connection.create_schema(:legacy) }
48
-
49
- it 'reverts the creation of a schema' do
50
- expect(connection.schema_exists?(:legacy, filtered: false)).to be_truthy
51
- migration.revert { migration.connection.create_schema(:legacy) }
52
- expect(connection.schema_exists?(:legacy, filtered: false)).to be_falsey
53
- end
54
-
55
- it 'reverts the creation of a table' do
56
- connection.create_table(:users, schema: :legacy) { |t| t.string(:name) }
57
-
58
- expect(connection.table_exists?('legacy.users')).to be_truthy
59
- migration.revert { migration.connection.create_table(:users, schema: :legacy) }
60
- expect(connection.table_exists?('legacy.users')).to be_falsey
61
- end
62
- end
63
- end
64
-
65
- context 'on schema' do
66
- let(:dump_result) do
67
- ActiveRecord::SchemaDumper.dump(connection, (dump_result = StringIO.new))
68
- dump_result.string
69
- end
70
-
71
- it 'does not add when there is no extra schemas' do
72
- connection.drop_schema(:internal, force: :cascade)
73
- expect(dump_result).not_to match /Custom schemas defined in this database/
74
- end
75
-
76
- it 'does not include tables from blacklisted schemas' do
77
- connection.schemas_blacklist.push('internal')
78
- expect(dump_result).not_to match /create_table \"users\",.*schema: +"internal"/
79
- end
80
-
81
- context 'with internal schema whitelisted' do
82
- before { connection.schemas_whitelist.push('internal') }
83
-
84
- it 'dumps the schemas' do
85
- expect(dump_result).to match /create_schema \"internal\"/
86
- end
87
-
88
- it 'shows the internal users table in the connection tables list' do
89
- expect(connection.tables).to include('internal.users')
90
- end
91
-
92
- it 'dumps tables on whitelisted schemas' do
93
- expect(dump_result).to match /create_table \"users\",.*schema: +"internal"/
94
- end
95
- end
96
-
97
- it 'does not affect serial ids' do
98
- connection.create_table(:primary_keys, id: :serial) do |t|
99
- t.string :title
100
- end
101
-
102
- parts = '"primary_keys", id: :serial, force: :cascade'
103
- expect(dump_result).to match(/create_table #{parts} do /)
104
- end
105
- end
106
-
107
- context 'on relation' do
108
- let(:model) { Internal::User }
109
- let(:table_name) { Torque::PostgreSQL::TableName.new(model, 'users') }
110
-
111
- it 'adds the schema to the query' do
112
- model.reset_table_name
113
- expect(table_name.to_s).to eq('internal.users')
114
- expect(model.all.to_sql).to match(/FROM "internal"."users"/)
115
- end
116
-
117
- it 'can load the schema from the module' do
118
- allow(Internal).to receive(:schema).and_return('internal')
119
- allow(model).to receive(:schema).and_return(nil)
120
-
121
- model.reset_table_name
122
- expect(table_name.to_s).to eq('internal.users')
123
- expect(model.all.to_sql).to match(/FROM "internal"."users"/)
124
- end
125
-
126
- it 'does not change anything if the model has not configured a schema' do
127
- allow(model).to receive(:schema).and_return(nil)
128
-
129
- model.reset_table_name
130
- expect(table_name.to_s).to eq('users')
131
- expect(model.all.to_sql).to match(/FROM "users"/)
132
- end
133
- end
134
- end