dbee-active_record 1.0.2 → 1.0.3

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: ec33481a6a1eb0dd9ddb60ace985456f5e8d085559d8923607bb252c013498de
4
- data.tar.gz: 49fe65ebf0caeb1f0e87482309352ed0e258cfd57c2ab26e2c3867d2c7e4a27a
3
+ metadata.gz: 75589214484b7918c7ae021e2f1cc2815c44b0fd472e61668197f96acb730031
4
+ data.tar.gz: a5155b0007182721e669a1930b4f313a28b19935b83b7a0084cbc7c65db07d01
5
5
  SHA512:
6
- metadata.gz: 44d6130ac9b617fddc0943caeabc65576e5617eac9bad7367757ab8ddff1dc98e3e542b9ec564da20f4d1c3c3e1094b8c4e8e27156e76ddea248d12afb38e570
7
- data.tar.gz: 7288cd2c2cbb0ee5e57278aa0d5ec308dc0c3dfeb8fe032cb5a50c5e9c42f2110388fd3933d2a46199fea901fda10509359c422e19d9be9d55e9228e449a292a
6
+ metadata.gz: 609909bbc0f1baab5d1dd36296ef86d47aac62f6f13e1a22d8bd674dacd22212e26e16d213fea797e31f90b8c90c1e78738596dad6b3c8b6d1da32ad82dbc476
7
+ data.tar.gz: c4815033dd066cd1c99faa3e0887467ec017400305bf0046041ec5b689d5b6c14b97ab5ec3d01a5c34bc6d88ad2bbe9089573ba6a92ad823b202a58418f445c0
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ # 1.0.3 (August 27th, 2019)
2
+
3
+ * Raises MissingConstraintError when trying to join to a table without at least one constraint.
4
+
1
5
  # 1.0.2 (August 26th, 2019)
2
6
 
3
7
  * Only support Dbee version 1.0.2 and above
@@ -19,6 +19,8 @@ module Dbee
19
19
  class ExpressionBuilder
20
20
  extend Forwardable
21
21
 
22
+ class MissingConstraintError < StandardError; end
23
+
22
24
  def_delegators :statement, :to_sql
23
25
 
24
26
  def initialize(model, table_alias_maker, column_alias_maker)
@@ -127,8 +129,10 @@ module Dbee
127
129
 
128
130
  on = constraint_maker.make(model.constraints, table, previous_table)
129
131
 
132
+ raise MissingConstraintError, "for: #{name}" unless on
133
+
130
134
  @statement = statement.join(table, ::Arel::Nodes::OuterJoin)
131
- @statement = statement.on(on) if on
135
+ @statement = statement.on(on)
132
136
 
133
137
  tables[name] = table
134
138
  end
@@ -10,7 +10,7 @@
10
10
  module Dbee
11
11
  module Providers
12
12
  class ActiveRecordProvider
13
- VERSION = '1.0.2'
13
+ VERSION = '1.0.3'
14
14
  end
15
15
  end
16
16
  end
@@ -13,6 +13,35 @@ require 'db_helper'
13
13
  describe Dbee::Providers::ActiveRecordProvider do
14
14
  let(:models) { yaml_fixture('models.yaml') }
15
15
 
16
+ describe '#sql' do
17
+ before(:all) do
18
+ connect_to_db(:sqlite)
19
+ end
20
+
21
+ it 'errors when joining tables with no constraints' do
22
+ model_hash = {
23
+ name: :users,
24
+ models: [
25
+ { name: :logins }
26
+ ]
27
+ }
28
+
29
+ query_hash = {
30
+ fields: [
31
+ { key_path: 'id' },
32
+ { key_path: 'logins.id' }
33
+ ]
34
+ }
35
+
36
+ query = Dbee::Query.make(query_hash)
37
+ model = Dbee::Model.make(model_hash)
38
+
39
+ error_class = Dbee::Providers::ActiveRecordProvider::ExpressionBuilder::MissingConstraintError
40
+
41
+ expect { described_class.new.sql(model, query) }.to raise_error(error_class)
42
+ end
43
+ end
44
+
16
45
  describe 'Snapshot' do
17
46
  context 'Generating SQL' do
18
47
  %w[sqlite mysql].each do |dbms|
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.2
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matthew Ruggio
@@ -19,7 +19,7 @@ dependencies:
19
19
  version: 5.2.1
20
20
  - - "<"
21
21
  - !ruby/object:Gem::Version
22
- version: '6'
22
+ version: '7'
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
@@ -29,7 +29,7 @@ dependencies:
29
29
  version: 5.2.1
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
- version: '6'
32
+ version: '7'
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: dbee
35
35
  requirement: !ruby/object:Gem::Requirement