dbee-active_record 1.0.3 → 1.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 75589214484b7918c7ae021e2f1cc2815c44b0fd472e61668197f96acb730031
4
- data.tar.gz: a5155b0007182721e669a1930b4f313a28b19935b83b7a0084cbc7c65db07d01
3
+ metadata.gz: c7ae7d990153562e5ccd108e3887538cc4f18d76ba2f23006b51a4f0db05a015
4
+ data.tar.gz: 4cd401ef186816cb562c43979c0063f72943021147e91c9f610787c23516c820
5
5
  SHA512:
6
- metadata.gz: 609909bbc0f1baab5d1dd36296ef86d47aac62f6f13e1a22d8bd674dacd22212e26e16d213fea797e31f90b8c90c1e78738596dad6b3c8b6d1da32ad82dbc476
7
- data.tar.gz: c4815033dd066cd1c99faa3e0887467ec017400305bf0046041ec5b689d5b6c14b97ab5ec3d01a5c34bc6d88ad2bbe9089573ba6a92ad823b202a58418f445c0
6
+ metadata.gz: d325a985ecae65475fa8f36380a93fcae5f9ec9aabec2ee0d70527c1a8cd83be70b9c18b60b26f9f6f5ea651be07699b3a43d80eea2486084f5f7e5e269233ce
7
+ data.tar.gz: dfb0d7414def705b8a8d07bd78c1e0662a93de6c633c9bd315a6c40f317e7a605e484652725b900a9ac08781d8c1dde3daa39683da501a21ab4a7bbb1bdf29e3
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ # 1.0.4 (August 27th, 2019)
2
+
3
+ * Added support for Dbee static constraint against the parent part of an association.
4
+
1
5
  # 1.0.3 (August 27th, 2019)
2
6
 
3
7
  * Raises MissingConstraintError when trying to join to a table without at least one constraint.
data/README.md CHANGED
@@ -53,6 +53,22 @@ Also, do not forget to run Rubocop:
53
53
  bundle exec rubocop
54
54
  ````
55
55
 
56
+ ### ActiveRecord Dependency
57
+
58
+ This library supports both ActiveRecord 5 and 6. Tests are adapted for both versions and should be ran against both to ensure compatibility. By default the latest 6 will be chosen unless overridden.
59
+
60
+ To install gems targeting version 5, run rubocop, and run rspec:
61
+
62
+ ````shell
63
+ AR_VERSION=5 bundle update; AR_VERSION=5 bundle exec rake
64
+ ````
65
+
66
+ To install gems targeting version 6, run rubocop, and run rspec:
67
+
68
+ ````shell
69
+ AR_VERSION=6 bundle update; AR_VERSION=5 bundle exec rake
70
+ ````
71
+
56
72
  ### Publishing
57
73
 
58
74
  Note: ensure you have proper authorization before trying to publish new versions.
@@ -34,7 +34,7 @@ Gem::Specification.new do |s|
34
34
  end
35
35
 
36
36
  s.add_dependency('activerecord', activerecord_version)
37
- s.add_dependency('dbee', '~>1', '>=1.0.2')
37
+ s.add_dependency('dbee', '~>1', '>=1.0.3')
38
38
 
39
39
  s.add_development_dependency('guard-rspec', '~>4.7')
40
40
  s.add_development_dependency('mysql2', '~>0.5')
@@ -24,11 +24,20 @@ module Dbee
24
24
 
25
25
  CONCAT_METHOD.call(on, table[name], previous_table[parent])
26
26
  end,
27
- Model::Constraints::Static => lambda do |constraint, on, table, _previous_table|
28
- name = constraint.name
27
+ Model::Constraints::Static => lambda do |constraint, on, table, previous_table|
29
28
  value = constraint.value
30
29
 
31
- CONCAT_METHOD.call(on, table[name], value)
30
+ unless constraint.name.empty?
31
+ column_name = constraint.name
32
+ on = CONCAT_METHOD.call(on, table[column_name], value)
33
+ end
34
+
35
+ unless constraint.parent.empty?
36
+ column_name = constraint.parent
37
+ on = CONCAT_METHOD.call(on, previous_table[column_name], value)
38
+ end
39
+
40
+ on
32
41
  end
33
42
  }.freeze
34
43
 
@@ -10,7 +10,7 @@
10
10
  module Dbee
11
11
  module Providers
12
12
  class ActiveRecordProvider
13
- VERSION = '1.0.3'
13
+ VERSION = '1.0.4'
14
14
  end
15
15
  end
16
16
  end
data/spec/db_helper.rb CHANGED
@@ -52,5 +52,22 @@ def load_schema
52
52
  t.column :favorite, :boolean, default: false, null: false
53
53
  t.timestamps
54
54
  end
55
+
56
+ create_table :animals do |t|
57
+ t.column :toy_id, :integer
58
+ t.column :type, :string
59
+ t.column :name, :string
60
+ t.timestamps
61
+ end
62
+
63
+ create_table :dog_toys do |t|
64
+ t.column :squishy, :boolean
65
+ t.timestamps
66
+ end
67
+
68
+ create_table :cat_toys do |t|
69
+ t.column :laser, :boolean
70
+ t.timestamps
71
+ end
55
72
  end
56
73
  end
@@ -42,10 +42,10 @@ describe Dbee::Providers::ActiveRecordProvider do
42
42
  end
43
43
  end
44
44
 
45
- describe 'Snapshot' do
46
- context 'Generating SQL' do
45
+ describe 'snapshot' do
46
+ context 'sql' do
47
47
  %w[sqlite mysql].each do |dbms|
48
- context dbms do
48
+ context "using #{dbms}" do
49
49
  before(:all) do
50
50
  connect_to_db(dbms)
51
51
  end
@@ -0,0 +1,58 @@
1
+ model_name: Reverse Polymorphic Example
2
+ query:
3
+ fields:
4
+ - key_path: id
5
+ - key_path: type
6
+ - key_path: name
7
+ - key_path: dog_toy.id
8
+ - key_path: dog_toy.squishy
9
+ - key_path: cat_toy.id
10
+ - key_path: cat_toy.laser
11
+ sqlite_readable: |+
12
+ SELECT
13
+ "animals"."id" AS 'id',
14
+ "animals"."type" AS 'type',
15
+ "animals"."name" AS 'name',
16
+ "dog_toy"."id" AS 'dog_toy_id',
17
+ "dog_toy"."squishy" AS 'dog_toy_squishy',
18
+ "cat_toy"."id" AS 'cat_toy_id',
19
+ "cat_toy"."laser" AS 'cat_toy_laser'
20
+ FROM "animals" "animals"
21
+ LEFT OUTER JOIN "dog_toys" "dog_toy" ON "dog_toy"."id" = "animals"."toy_id" AND "animals"."type" = 'Dog'
22
+ LEFT OUTER JOIN "cat_toys" "cat_toy" ON "cat_toy"."id" = "animals"."toy_id" AND "animals"."type" = 'Cat'
23
+ sqlite_not_readable: |+
24
+ SELECT
25
+ "t0"."id" AS 'c0',
26
+ "t0"."type" AS 'c1',
27
+ "t0"."name" AS 'c2',
28
+ "t1"."id" AS 'c3',
29
+ "t1"."squishy" AS 'c4',
30
+ "t2"."id" AS 'c5',
31
+ "t2"."laser" AS 'c6'
32
+ FROM "animals" "t0"
33
+ LEFT OUTER JOIN "dog_toys" "t1" ON "t1"."id" = "t0"."toy_id" AND "t0"."type" = 'Dog'
34
+ LEFT OUTER JOIN "cat_toys" "t2" ON "t2"."id" = "t0"."toy_id" AND "t0"."type" = 'Cat'
35
+ mysql_readable: |+
36
+ SELECT
37
+ `animals`.`id` AS 'id',
38
+ `animals`.`type` AS 'type',
39
+ `animals`.`name` AS 'name',
40
+ `dog_toy`.`id` AS 'dog_toy_id',
41
+ `dog_toy`.`squishy` AS 'dog_toy_squishy',
42
+ `cat_toy`.`id` AS 'cat_toy_id',
43
+ `cat_toy`.`laser` AS 'cat_toy_laser'
44
+ FROM `animals` `animals`
45
+ LEFT OUTER JOIN `dog_toys` `dog_toy` ON `dog_toy`.`id` = `animals`.`toy_id` AND `animals`.`type` = 'Dog'
46
+ LEFT OUTER JOIN `cat_toys` `cat_toy` ON `cat_toy`.`id` = `animals`.`toy_id` AND `animals`.`type` = 'Cat'
47
+ mysql_not_readable: |+
48
+ SELECT
49
+ `t0`.`id` AS 'c0',
50
+ `t0`.`type` AS 'c1',
51
+ `t0`.`name` AS 'c2',
52
+ `t1`.`id` AS 'c3',
53
+ `t1`.`squishy` AS 'c4',
54
+ `t2`.`id` AS 'c5',
55
+ `t2`.`laser` AS 'c6'
56
+ FROM `animals` `t0`
57
+ LEFT OUTER JOIN `dog_toys` `t1` ON `t1`.`id` = `t0`.`toy_id` AND `t0`.`type` = 'Dog'
58
+ LEFT OUTER JOIN `cat_toys` `t2` ON `t2`.`id` = `t0`.`toy_id` AND `t0`.`type` = 'Cat'
@@ -58,3 +58,25 @@ Theaters, Members, and Movies:
58
58
  - type: static
59
59
  name: genre
60
60
  value: comedy
61
+ Reverse Polymorphic Example:
62
+ # In this example, an animal has a toy, but that toy is either a dog or cat toy, depending on
63
+ # the type of the animal. So for this to work in this direction, static constraints pointed
64
+ # at the parent (animals) is needed.
65
+ name: animals
66
+ models:
67
+ - name: dog_toy
68
+ table: dog_toys
69
+ constraints:
70
+ - parent: toy_id
71
+ name: id
72
+ - type: static
73
+ parent: type
74
+ value: Dog
75
+ - name: cat_toy
76
+ table: cat_toys
77
+ constraints:
78
+ - parent: toy_id
79
+ name: id
80
+ - type: static
81
+ parent: type
82
+ value: Cat
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dbee-active_record
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matthew Ruggio
@@ -39,7 +39,7 @@ dependencies:
39
39
  version: '1'
40
40
  - - ">="
41
41
  - !ruby/object:Gem::Version
42
- version: 1.0.2
42
+ version: 1.0.3
43
43
  type: :runtime
44
44
  prerelease: false
45
45
  version_requirements: !ruby/object:Gem::Requirement
@@ -49,7 +49,7 @@ dependencies:
49
49
  version: '1'
50
50
  - - ">="
51
51
  - !ruby/object:Gem::Version
52
- version: 1.0.2
52
+ version: 1.0.3
53
53
  - !ruby/object:Gem::Dependency
54
54
  name: guard-rspec
55
55
  requirement: !ruby/object:Gem::Requirement
@@ -219,6 +219,7 @@ files:
219
219
  - spec/fixtures/active_record_snapshots/one_table_query_with_filters.yaml
220
220
  - spec/fixtures/active_record_snapshots/one_table_query_with_limit.yaml
221
221
  - spec/fixtures/active_record_snapshots/one_table_query_with_multiple_sorts.yaml
222
+ - spec/fixtures/active_record_snapshots/reverse_polymorphic_query.yaml
222
223
  - spec/fixtures/active_record_snapshots/two_table_query.yaml
223
224
  - spec/fixtures/models.yaml
224
225
  - spec/spec_helper.rb
@@ -257,6 +258,7 @@ test_files:
257
258
  - spec/fixtures/active_record_snapshots/one_table_query_with_filters.yaml
258
259
  - spec/fixtures/active_record_snapshots/one_table_query_with_limit.yaml
259
260
  - spec/fixtures/active_record_snapshots/one_table_query_with_multiple_sorts.yaml
261
+ - spec/fixtures/active_record_snapshots/reverse_polymorphic_query.yaml
260
262
  - spec/fixtures/active_record_snapshots/two_table_query.yaml
261
263
  - spec/fixtures/models.yaml
262
264
  - spec/spec_helper.rb