sunstone 5.0.0.2 → 5.0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 251b8b254f40eac45d625f004fe405db180eefe0
4
- data.tar.gz: e06aa5cf5ce843ccfe6c495fd5e0e7d7ec3d5685
3
+ metadata.gz: ca2db5a6c3ea14865f367dbb2e47581ac78dcf5d
4
+ data.tar.gz: 8c7c0ea51ded30b1b39fb09eee852989f588574f
5
5
  SHA512:
6
- metadata.gz: 1ad88a3734db407224aa3addb478b5eaabfd9b5ad1ae0e3effe18c67e783a6131c652b58cbb55508f300a630f0c3aea259904743418cc711af0f8ab356bfc546
7
- data.tar.gz: 628039ec1b81d9f4630a85dca9decd0e455e47d45d2386721cb96765628c86f19a5372275e52e1d6bdd0ac42082da8ee3ba2e4104969731a524448e10caabdbb
6
+ metadata.gz: 7fc4a0e6209543012c12f674a33b10c3a1a27a21e3bb6cc0a7f647f28a83490caddfe619546df1b86caf759504616588978ab42e7d1e65623f3c9d5a690089f5
7
+ data.tar.gz: 33421456a4d97c91a606f250914a4b4c15ae889fee4ae33a6f08e13409b28fd10128edc9ca00cf482735169f28809587e7bc227b274f6f7874553260f7de73e6
data/.gitignore CHANGED
@@ -28,3 +28,4 @@ Gemfile.lock
28
28
 
29
29
  # Text Editor scraps
30
30
  *~
31
+ .byebug_history
@@ -3,30 +3,47 @@ module ActiveRecord
3
3
 
4
4
  def to_sql
5
5
  @to_sql ||= begin
6
- relation = self
7
- connection = klass.connection
8
- visitor = if connection.visitor.is_a?(Arel::Visitors::Sunstone)
9
- Arel::Visitors::ToSql.new(connection)
10
- else
11
- connection.visitor
12
- end
6
+ relation = self
7
+ connection = klass.connection
8
+ visitor = if connection.visitor.is_a?(Arel::Visitors::Sunstone)
9
+ Arel::Visitors::ToSql.new(connection)
10
+ else
11
+ connection.visitor
12
+ end
13
13
 
14
- if eager_loading?
15
- find_with_associations { |rel| relation = rel }
16
- end
14
+ if eager_loading?
15
+ find_with_associations { |rel| relation = rel }
16
+ end
17
17
 
18
- binds = if connection.visitor.is_a?(Arel::Visitors::Sunstone)
19
- relation.arel.bind_values + relation.bound_attributes
20
- else
21
- relation.bound_attributes
22
- end
23
- binds = connection.prepare_binds_for_database(binds)
24
- binds.map! { |value| connection.quote(value) }
25
- collect = visitor.accept(relation.arel.ast, Arel::Collectors::Bind.new)
26
- collect.substitute_binds(binds).join
27
- end
18
+ binds = relation.bound_attributes
19
+ binds = connection.prepare_binds_for_database(binds)
20
+ binds.map! { |value| connection.quote(value) }
21
+ collect = visitor.accept(relation.arel.ast, Arel::Collectors::Bind.new)
22
+ collect.substitute_binds(binds).join
23
+ end
24
+ end
25
+
26
+ def to_sar
27
+ @to_sar ||= begin
28
+ relation = self
29
+ connection = klass.connection
30
+ visitor = if connection.visitor.is_a?(Arel::Visitors::ToSql)
31
+ Arel::Visitors::Sunstone.new(connection)
32
+ else
33
+ connection.visitor
34
+ end
35
+
36
+ if eager_loading?
37
+ find_with_associations { |rel| relation = rel }
38
+ end
39
+
40
+ binds = relation.bound_attributes
41
+ binds = connection.prepare_binds_for_database(binds)
42
+ binds.map! { |value| connection.quote(value) }
43
+ collect = visitor.accept(relation.arel.ast, Arel::Collectors::Sunstone.new)
44
+ collect.compile binds
45
+ end
28
46
  end
29
-
30
47
 
31
48
  end
32
- end
49
+ end
@@ -6,6 +6,9 @@ module Arel
6
6
 
7
7
  attr_accessor :request_type, :table, :where, :limit, :offset, :order, :operation, :columns, :updates, :eager_loads, :id, :distinct, :distinct_on
8
8
 
9
+ # This is used to removed an bind values. It is not used in the request
10
+ attr_accessor :join_source
11
+
9
12
  def cast_attribute(v)
10
13
  if (v.is_a?(ActiveRecord::Attribute))
11
14
  v.value_for_database
@@ -70,6 +73,10 @@ module Arel
70
73
  }
71
74
  end
72
75
 
76
+ if join_source
77
+ substitute_binds(join_source.clone, bvs)
78
+ end
79
+
73
80
  params = {}
74
81
  if where
75
82
  params[:where] = substitute_binds(where.clone, bvs)
@@ -77,7 +84,7 @@ module Arel
77
84
  params[:where] = params[:where].pop
78
85
  end
79
86
  end
80
-
87
+
81
88
  if eager_loads
82
89
  params[:include] = eager_loads.clone
83
90
  end
@@ -94,14 +101,14 @@ module Arel
94
101
  params[:limit] = limit
95
102
  end
96
103
 
104
+ params[:order] = substitute_binds(order, bvs) if order
105
+
97
106
  if offset.is_a?(Arel::Nodes::BindParam)
98
107
  params[:offset] = substitute_binds(offset, bvs)
99
108
  elsif offset
100
109
  params[:offset] = offset
101
110
  end
102
111
 
103
- params[:order] = substitute_binds(order, bvs) if order
104
-
105
112
  case operation
106
113
  when :count
107
114
  path += "/#{operation}"
@@ -143,6 +150,3 @@ module Arel
143
150
  end
144
151
  end
145
152
  end
146
-
147
-
148
-
@@ -58,7 +58,7 @@ module Arel
58
58
  collector = maybe_visit o.set_quantifier, collector
59
59
 
60
60
  if o.source && !o.source.empty?
61
- collector.table = o.source.left.name
61
+ collector = visit o.source, collector
62
62
  end
63
63
 
64
64
  if !o.wheres.empty?
@@ -628,11 +628,14 @@ module Arel
628
628
  #
629
629
  def visit_Arel_Nodes_JoinSource o, collector
630
630
  if o.left
631
- collector = visit o.left, collector
631
+ collector.table = o.left.name
632
632
  end
633
633
  if o.right.any?
634
- collector << " " if o.left
635
- collector = inject_join o.right, collector, ' '
634
+ # We need to visit the right to get remove bind values, but we don't
635
+ # add it to the collector
636
+ # collector << " " if o.left
637
+ # collector = inject_join o.right, collector, ' '
638
+ collector.join_source = inject_join(o.right, Arel::Collectors::Sunstone.new, ' ')
636
639
  end
637
640
  collector
638
641
  end
@@ -663,23 +666,20 @@ module Arel
663
666
  # def visit_Arel_Nodes_RightOuterJoin o
664
667
  # "RIGHT OUTER JOIN #{visit o.left} #{visit o.right}"
665
668
  # end
666
- #
667
- # def visit_Arel_Nodes_InnerJoin o, collector
668
- # collector << "INNER JOIN "
669
- # collector = visit o.left, collector
670
- # if o.right
671
- # collector << SPACE
672
- # visit(o.right, collector)
673
- # else
674
- # collector
675
- # end
676
- # end
677
- #
678
- # def visit_Arel_Nodes_On o, collector
679
- # collector << "ON "
680
- # visit o.expr, collector
681
- # end
682
- #
669
+
670
+ def visit_Arel_Nodes_InnerJoin o, collector
671
+ collector = visit o.left, collector
672
+ if o.right
673
+ visit(o.right, collector)
674
+ else
675
+ collector
676
+ end
677
+ end
678
+
679
+ def visit_Arel_Nodes_On o, collector
680
+ visit o.expr, collector
681
+ end
682
+
683
683
  # def visit_Arel_Nodes_Not o, collector
684
684
  # collector << "NOT ("
685
685
  # visit(o.expr, collector) << ")"
@@ -1,3 +1,3 @@
1
1
  module Sunstone
2
- VERSION = '5.0.0.2'
2
+ VERSION = '5.0.0.4'
3
3
  end
@@ -35,7 +35,7 @@ class ActiveRecord::QueryTest < Minitest::Test
35
35
 
36
36
  assert_nil Ship.first
37
37
  end
38
-
38
+
39
39
  test '::last' do
40
40
  webmock(:get, "/ships", { limit: 1, order: [{id: :desc}] }).to_return(body: [].to_json)
41
41
 
@@ -134,5 +134,19 @@ class ActiveRecord::QueryTest < Minitest::Test
134
134
  test '#to_sql' do
135
135
  assert_equal "SELECT ships.* FROM ships WHERE ships.id = 10", Ship.where(:id => 10).to_sql
136
136
  end
137
-
137
+
138
+ test '#to_sql binds correctly when joining' do
139
+ assert_equal 'SELECT ships.* FROM ships INNER JOIN ownerships ON ownerships.asset_id = ships.id AND ownerships.asset_type = \'Ship\' WHERE ownerships.id = 1', Ship.joins(:ownerships).where({ ownerships: { id: 1 } }).to_sql
140
+ end
141
+
142
+ test '#to_sar' do
143
+ assert_equal "/ships?%81%A5where%81%A2id%A210", Ship.where(:id => 10).to_sar.path
144
+ end
145
+
146
+ test 'bind params get eaten when joining' do
147
+ uri = URI(Ship.joins(:ownerships).where({ ownerships: { id: 1 } }).to_sar.path)
148
+ query = MessagePack.unpack(CGI.unescape(uri.query))
149
+ assert_equal({"where"=>{"ownerships"=>{"id"=>{"eq"=>"1"}}}}, query)
150
+ end
151
+
138
152
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sunstone
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.0.0.2
4
+ version: 5.0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jon Bracy
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-11-28 00:00:00.000000000 Z
11
+ date: 2016-11-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -344,7 +344,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
344
344
  version: '0'
345
345
  requirements: []
346
346
  rubyforge_project:
347
- rubygems_version: 2.6.4
347
+ rubygems_version: 2.5.1
348
348
  signing_key:
349
349
  specification_version: 4
350
350
  summary: A library for interacting with REST APIs