sunstone 5.2.1 → 6.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 +4 -4
- data/.travis.yml +8 -6
- data/ext/active_record/attribute_methods.rb +3 -15
- data/ext/active_record/finder_methods.rb +17 -12
- data/ext/active_record/persistence.rb +23 -8
- data/ext/active_record/relation/calculations.rb +2 -4
- data/ext/active_record/statement_cache.rb +1 -1
- data/ext/active_record/transactions.rb +8 -1
- data/ext/arel/nodes/select_statement.rb +1 -1
- data/lib/active_record/connection_adapters/sunstone/type/array.rb +9 -8
- data/lib/arel/visitors/sunstone.rb +62 -12
- data/lib/sunstone/connection.rb +7 -5
- data/lib/sunstone/exception.rb +3 -0
- data/lib/sunstone/version.rb +1 -1
- data/sunstone.gemspec +3 -2
- data/test/active_record/eager_loading_test.rb +10 -8
- data/test/active_record/rpc_test.rb +30 -0
- metadata +14 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5ecbeb6967817d2f58c9602526839eeee2b9aa161dc00adf1f962549874c49af
|
4
|
+
data.tar.gz: 7759fa8e537ae1dd04009dca78ae7ffad19cbb6166629e99778f2b22aa982837
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c72e778804a92ea85dadd3f7adbae2f5171ca63c47da09b065dcb9c14202a8d78e9ecd95ad15f7b2f0bfe7384a858497a1758b056112f703cc87fb8dd91607dd
|
7
|
+
data.tar.gz: 26d94406a0f9b50ad8429c0dd5d49d3da1fd182e1b8b12d87d6e0f0604f343f0920a10b6f0597b4830e3d6856cf62e36b65382e081381f6d5e9b196e94f28c72
|
data/.travis.yml
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
dist: xenial
|
1
2
|
language: ruby
|
2
3
|
sudo: false
|
3
4
|
|
@@ -7,17 +8,18 @@ cache:
|
|
7
8
|
- /home/travis/.rvm/gems
|
8
9
|
|
9
10
|
rvm:
|
10
|
-
- 2.
|
11
|
-
- 2.5.1
|
11
|
+
- 2.6
|
12
12
|
|
13
13
|
env:
|
14
14
|
matrix:
|
15
|
-
- RAILS_VERSION=
|
16
|
-
- RAILS_VERSION=
|
17
|
-
- RAILS_VERSION=
|
15
|
+
- RAILS_VERSION=v6.0.0.rc1 GEM=activerecord:mysql2
|
16
|
+
- RAILS_VERSION=v6.0.0.rc1 GEM=activerecord:sqlite3
|
17
|
+
- RAILS_VERSION=v6.0.0.rc1 GEM=activerecord:postgresql
|
18
18
|
|
19
|
+
services:
|
20
|
+
- mysql
|
19
21
|
addons:
|
20
|
-
postgresql: "
|
22
|
+
postgresql: "10"
|
21
23
|
|
22
24
|
before_install:
|
23
25
|
- unset BUNDLE_GEMFILE
|
@@ -46,11 +46,7 @@ module ActiveRecord
|
|
46
46
|
record.destroy
|
47
47
|
elsif autosave != false
|
48
48
|
if record.new_record? || (autosave && record.changed_for_autosave?)
|
49
|
-
|
50
|
-
attrs["#{reflection.name}_attributes"] = record.send(:attributes_with_values_for_create, record.attribute_names)
|
51
|
-
else
|
52
|
-
attrs["#{reflection.name}_attributes"] = record.send(:attributes_with_values_for_update, record.attribute_names)
|
53
|
-
end
|
49
|
+
attrs["#{reflection.name}_attributes"] = record.send(:attributes_with_values, record.new_record? ? (record.attribute_names - ['id']) : record.attribute_names)
|
54
50
|
end
|
55
51
|
end
|
56
52
|
end
|
@@ -79,11 +75,7 @@ module ActiveRecord
|
|
79
75
|
record[reflection.foreign_key] = key
|
80
76
|
end
|
81
77
|
|
82
|
-
|
83
|
-
attrs["#{reflection.name}_attributes"] = record.send(:attributes_with_values_for_create, record.attribute_names)
|
84
|
-
else
|
85
|
-
attrs["#{reflection.name}_attributes"] = record.send(:attributes_with_values_for_update, record.attribute_names)
|
86
|
-
end
|
78
|
+
attrs["#{reflection.name}_attributes"] = record.send(:attributes_with_values, record.new_record? ? (record.attribute_names - ['id']): record.attribute_names)
|
87
79
|
end
|
88
80
|
end
|
89
81
|
end
|
@@ -105,11 +97,7 @@ module ActiveRecord
|
|
105
97
|
[]
|
106
98
|
else
|
107
99
|
association.target.select { |r| !r.destroyed? }.map do |record|
|
108
|
-
|
109
|
-
record.send(:attributes_with_values_for_create, record.send(:keys_for_partial_write) + [record.class.primary_key])
|
110
|
-
else
|
111
|
-
record.send(:attributes_with_values_for_update, record.send(:keys_for_partial_write) + [record.class.primary_key])
|
112
|
-
end
|
100
|
+
record.send(:attributes_with_values, record.send(:attribute_names_for_partial_writes) + (record.new_record? ? [] : [record.class.primary_key]))
|
113
101
|
end
|
114
102
|
end
|
115
103
|
|
@@ -1,6 +1,6 @@
|
|
1
1
|
module Arel
|
2
2
|
module Visitors
|
3
|
-
class ToSql < Arel::Visitors::
|
3
|
+
class ToSql < Arel::Visitors::Visitor
|
4
4
|
|
5
5
|
def visit_Arel_Attributes_Relation o, collector
|
6
6
|
visit(o.relation, collector)
|
@@ -19,7 +19,7 @@ module ActiveRecord
|
|
19
19
|
attributes.flat_map do |key, value|
|
20
20
|
if value.is_a?(Hash) && !table.has_column?(key)
|
21
21
|
ka = associated_predicate_builder(key).expand_from_hash(value)
|
22
|
-
if self.table.instance_variable_get(:@klass).connection.is_a?(ActiveRecord::ConnectionAdapters::SunstoneAPIAdapter)
|
22
|
+
if self.send(:table).instance_variable_get(:@klass).connection.is_a?(ActiveRecord::ConnectionAdapters::SunstoneAPIAdapter)
|
23
23
|
ka.each { |k|
|
24
24
|
if k.left.is_a?(Arel::Attributes::Attribute) || k.left.is_a?(Arel::Attributes::Relation)
|
25
25
|
k.left = Arel::Attributes::Relation.new(k.left, key)
|
@@ -49,16 +49,21 @@ module ActiveRecord
|
|
49
49
|
queries.reduce(&:or)
|
50
50
|
elsif table.aggregated_with?(key)
|
51
51
|
mapping = table.reflect_on_aggregation(key).mapping
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
52
|
+
values = value.nil? ? [nil] : Array.wrap(value)
|
53
|
+
if mapping.length == 1 || values.empty?
|
54
|
+
column_name, aggr_attr = mapping.first
|
55
|
+
values = values.map do |object|
|
56
|
+
object.respond_to?(aggr_attr) ? object.public_send(aggr_attr) : object
|
57
|
+
end
|
58
|
+
build(table.arel_attribute(column_name), values)
|
59
|
+
else
|
60
|
+
queries = values.map do |object|
|
61
|
+
mapping.map do |field_attr, aggregate_attr|
|
62
|
+
build(table.arel_attribute(field_attr), object.try!(aggregate_attr))
|
63
|
+
end.reduce(&:and)
|
64
|
+
end
|
65
|
+
queries.reduce(&:or)
|
60
66
|
end
|
61
|
-
queries.reduce(&:or)
|
62
67
|
else
|
63
68
|
build(table.arel_attribute(key), value)
|
64
69
|
end
|
@@ -197,7 +202,7 @@ module ActiveRecord
|
|
197
202
|
relation = except(:includes, :eager_load, :preload)
|
198
203
|
relation.arel.eager_load = Arel::Nodes::EagerLoad.new(eager_load_values)
|
199
204
|
else
|
200
|
-
join_dependency = construct_join_dependency
|
205
|
+
join_dependency = construct_join_dependency(eager_load_values + includes_values)
|
201
206
|
relation = except(:includes, :eager_load, :preload).joins!(join_dependency)
|
202
207
|
end
|
203
208
|
|
@@ -2,6 +2,22 @@ module ActiveRecord
|
|
2
2
|
# = Active Record \Persistence
|
3
3
|
module Persistence
|
4
4
|
|
5
|
+
module ClassMethods
|
6
|
+
def rpc(name)
|
7
|
+
define_method("#{name}!") do
|
8
|
+
req = Net::HTTP::Post.new("/#{self.class.table_name}/#{CGI.escape(id.to_s)}/#{CGI.escape(name.to_s)}")
|
9
|
+
self.class.connection.instance_variable_get(:@connection).send_request(req) do |response|
|
10
|
+
JSON.parse(response.body).each do |k,v|
|
11
|
+
if self.class.column_names.include?(k)
|
12
|
+
@attributes.write_from_database(k, v)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
true
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
5
21
|
def update!(attributes)
|
6
22
|
@no_save_transaction = true
|
7
23
|
with_transaction_returning_status do
|
@@ -14,14 +30,14 @@ module ActiveRecord
|
|
14
30
|
|
15
31
|
private
|
16
32
|
|
17
|
-
def create_or_update(
|
33
|
+
def create_or_update(**, &block)
|
18
34
|
_raise_readonly_record_error if readonly?
|
19
35
|
return false if destroyed?
|
20
36
|
|
21
37
|
@updating = new_record? ? :creating : :updating
|
22
38
|
Thread.current[:sunstone_updating_model] = self
|
23
39
|
|
24
|
-
result = new_record? ? _create_record(&block) : _update_record(
|
40
|
+
result = new_record? ? _create_record(&block) : _update_record(&block)
|
25
41
|
|
26
42
|
if self.class.connection.is_a?(ActiveRecord::ConnectionAdapters::SunstoneAPIAdapter) && result != 0
|
27
43
|
row_hash = result.rows.first
|
@@ -64,7 +80,7 @@ module ActiveRecord
|
|
64
80
|
# and returns its id.
|
65
81
|
def _create_record(attribute_names = self.attribute_names)
|
66
82
|
attribute_names &= self.class.column_names
|
67
|
-
attributes_values =
|
83
|
+
attributes_values = attributes_with_values(attribute_names)
|
68
84
|
|
69
85
|
new_id = self.class._insert_record(attributes_values)
|
70
86
|
|
@@ -79,14 +95,13 @@ module ActiveRecord
|
|
79
95
|
end
|
80
96
|
|
81
97
|
def _update_record(attribute_names = self.attribute_names)
|
82
|
-
|
83
|
-
attributes_values = attributes_with_values_for_update(attribute_names)
|
98
|
+
attribute_values = attributes_with_values(attribute_names)
|
84
99
|
|
85
|
-
if
|
100
|
+
if attribute_values.empty?
|
86
101
|
affected_rows = 0
|
87
102
|
@_trigger_update_callback = true
|
88
103
|
else
|
89
|
-
affected_rows = self.class._update_record(
|
104
|
+
affected_rows = self.class._update_record( attribute_values, self.class.primary_key => id_in_database )
|
90
105
|
@_trigger_update_callback = affected_rows == 1
|
91
106
|
end
|
92
107
|
|
@@ -94,7 +109,7 @@ module ActiveRecord
|
|
94
109
|
|
95
110
|
affected_rows
|
96
111
|
end
|
97
|
-
|
112
|
+
|
98
113
|
#!!!! TODO: I am duplicated from finder_methods.....
|
99
114
|
def construct(parent, relations, seen, model_cache)
|
100
115
|
relations.each do |key, attributes|
|
@@ -13,11 +13,9 @@ module ActiveRecord
|
|
13
13
|
load
|
14
14
|
return records.pluck(*column_names.map{|n| n.sub(/^#{klass.table_name}\./, "")})
|
15
15
|
else
|
16
|
-
|
16
|
+
klass.disallow_raw_sql!(column_names)
|
17
17
|
relation = spawn
|
18
|
-
relation.select_values = column_names
|
19
|
-
@klass.has_attribute?(cn) || @klass.attribute_alias?(cn) ? arel_attribute(cn) : cn
|
20
|
-
}
|
18
|
+
relation.select_values = column_names
|
21
19
|
result = skip_query_cache_if_necessary { klass.connection.select_all(relation.arel, nil) }
|
22
20
|
result.cast_values(klass.attribute_types)
|
23
21
|
end
|
@@ -18,8 +18,8 @@ module ActiveRecord
|
|
18
18
|
binds.map!(&:value_for_database)
|
19
19
|
@values
|
20
20
|
else
|
21
|
-
casted_binds = binds.map(&:value_for_database)
|
22
21
|
val = @values.dup
|
22
|
+
casted_binds = binds.map(&:value_for_database)
|
23
23
|
@indexes.each { |i| val[i] = connection.quote(casted_binds.shift) }
|
24
24
|
val.join
|
25
25
|
end
|
@@ -41,7 +41,14 @@ module ActiveRecord
|
|
41
41
|
status
|
42
42
|
else
|
43
43
|
self.class.transaction do
|
44
|
-
|
44
|
+
if has_transactional_callbacks?
|
45
|
+
add_to_transaction
|
46
|
+
else
|
47
|
+
sync_with_transaction_state if @transaction_state&.finalized?
|
48
|
+
@transaction_state = self.class.connection.transaction_state
|
49
|
+
end
|
50
|
+
remember_transaction_record_state
|
51
|
+
|
45
52
|
status = yield
|
46
53
|
raise ActiveRecord::Rollback unless status
|
47
54
|
end
|
@@ -3,10 +3,10 @@ module ActiveRecord
|
|
3
3
|
module Sunstone
|
4
4
|
module Type
|
5
5
|
class Array < ActiveRecord::Type::Value
|
6
|
-
include
|
6
|
+
include ActiveModel::Type::Helpers::Mutable
|
7
7
|
|
8
8
|
attr_reader :subtype
|
9
|
-
delegate :type, :user_input_in_time_zone, :limit, to: :subtype
|
9
|
+
delegate :type, :user_input_in_time_zone, :limit, :precision, :scale, to: :subtype
|
10
10
|
|
11
11
|
def initialize(subtype)
|
12
12
|
@subtype = subtype
|
@@ -47,13 +47,14 @@ module ActiveRecord
|
|
47
47
|
def map(value, &block)
|
48
48
|
value.map(&block)
|
49
49
|
end
|
50
|
+
|
51
|
+
def changed_in_place?(raw_old_value, new_value)
|
52
|
+
deserialize(raw_old_value) != new_value
|
53
|
+
end
|
50
54
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
#
|
55
|
-
# JSON.parse(string)
|
56
|
-
# end
|
55
|
+
def force_equality?(value)
|
56
|
+
value.is_a?(::Array)
|
57
|
+
end
|
57
58
|
|
58
59
|
private
|
59
60
|
|
@@ -8,7 +8,7 @@ end
|
|
8
8
|
|
9
9
|
module Arel
|
10
10
|
module Visitors
|
11
|
-
class Sunstone < Arel::Visitors::
|
11
|
+
class Sunstone < Arel::Visitors::Visitor
|
12
12
|
|
13
13
|
def compile node, &block
|
14
14
|
accept(node, Arel::Collectors::SQLString.new, &block).value
|
@@ -66,11 +66,29 @@ module Arel
|
|
66
66
|
|
67
67
|
collector
|
68
68
|
end
|
69
|
-
|
69
|
+
|
70
70
|
def visit_Arel_Nodes_Overlaps o, collector
|
71
|
-
|
71
|
+
key = visit(o.left, collector)
|
72
|
+
value = { overlaps: visit(o.right, collector) }
|
73
|
+
if key.is_a?(Hash)
|
74
|
+
add_to_bottom_of_hash_or_array(key, value)
|
75
|
+
key
|
76
|
+
else
|
77
|
+
{key => value}
|
78
|
+
end
|
72
79
|
end
|
73
|
-
|
80
|
+
|
81
|
+
def visit_Arel_Nodes_NotOverlaps o, collector
|
82
|
+
key = visit(o.left, collector)
|
83
|
+
value = { not_overlaps: visit(o.right, collector) }
|
84
|
+
if key.is_a?(Hash)
|
85
|
+
add_to_bottom_of_hash_or_array(key, value)
|
86
|
+
key
|
87
|
+
else
|
88
|
+
{key => value}
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
74
92
|
def visit_Arel_Nodes_InsertStatement o, collector
|
75
93
|
collector.request_type = Net::HTTP::Post
|
76
94
|
collector.table = o.relation.name
|
@@ -80,14 +98,12 @@ module Arel
|
|
80
98
|
if o.values.is_a?(Arel::Nodes::SqlLiteral) && o.values == 'DEFAULT VALUES'
|
81
99
|
collector.updates = {}
|
82
100
|
else
|
83
|
-
keys = o.values.right.map { |x| visit(x, collector) }
|
84
|
-
values = o.values.left
|
85
101
|
collector.updates = {}
|
86
|
-
|
87
|
-
|
88
|
-
|
102
|
+
|
103
|
+
o.values.expr[0].each_with_index do |value, i|
|
104
|
+
k = value.value.name
|
89
105
|
if k.is_a?(Hash)
|
90
|
-
add_to_bottom_of_hash_or_array(k,
|
106
|
+
add_to_bottom_of_hash_or_array(k, value)
|
91
107
|
collector.updates.deep_merge!(k) { |key, v1, v2|
|
92
108
|
if (v1.is_a?(Array) && v2.is_a?(Array))
|
93
109
|
v2.each_with_index do |v, j|
|
@@ -103,7 +119,7 @@ module Arel
|
|
103
119
|
end
|
104
120
|
}
|
105
121
|
else
|
106
|
-
collector.updates[k] = visit(
|
122
|
+
collector.updates[k] = visit(value, collector)
|
107
123
|
end
|
108
124
|
end
|
109
125
|
end
|
@@ -867,7 +883,41 @@ module Arel
|
|
867
883
|
{ key => value }
|
868
884
|
end
|
869
885
|
end
|
870
|
-
|
886
|
+
|
887
|
+
def visit_Arel_Nodes_HasKeys o, collector
|
888
|
+
key = visit(o.left, collector)
|
889
|
+
value = { has_keys: visit(o.right, collector) }
|
890
|
+
|
891
|
+
if key.is_a?(Hash)
|
892
|
+
okey = key
|
893
|
+
while okey.values.first.is_a?(Hash)
|
894
|
+
okey = okey.values.first
|
895
|
+
end
|
896
|
+
nkey = okey.keys.first
|
897
|
+
nvalue = okey.values.first
|
898
|
+
okey[nkey] = { nvalue => value }
|
899
|
+
else
|
900
|
+
{ key => value }
|
901
|
+
end
|
902
|
+
end
|
903
|
+
|
904
|
+
def visit_Arel_Nodes_HasAnyKey o, collector
|
905
|
+
key = visit(o.left, collector)
|
906
|
+
value = { has_any_key: visit(o.right, collector) }
|
907
|
+
|
908
|
+
if key.is_a?(Hash)
|
909
|
+
okey = key
|
910
|
+
while okey.values.first.is_a?(Hash)
|
911
|
+
okey = okey.values.first
|
912
|
+
end
|
913
|
+
nkey = okey.keys.first
|
914
|
+
nvalue = okey.values.first
|
915
|
+
okey[nkey] = { nvalue => value }
|
916
|
+
else
|
917
|
+
{ key => value }
|
918
|
+
end
|
919
|
+
end
|
920
|
+
|
871
921
|
def visit_Arel_Nodes_NotEqual o, collector
|
872
922
|
{
|
873
923
|
visit(o.left, collector) => { :not => visit(o.right, collector) }
|
data/lib/sunstone/connection.rb
CHANGED
@@ -32,6 +32,12 @@ module Sunstone
|
|
32
32
|
end
|
33
33
|
|
34
34
|
@connection = Net::HTTP.new(host, port)
|
35
|
+
@connection.max_retries = 0
|
36
|
+
@connection.open_timeout = 5
|
37
|
+
@connection.read_timeout = 30
|
38
|
+
@connection.write_timeout = 5
|
39
|
+
@connection.ssl_timeout = 5
|
40
|
+
@connection.keep_alive_timeout = 30
|
35
41
|
@connection.use_ssl = use_ssl
|
36
42
|
if use_ssl && config[:ca_cert]
|
37
43
|
@connection.cert_store = OpenSSL::X509::Store.new
|
@@ -166,7 +172,6 @@ module Sunstone
|
|
166
172
|
end
|
167
173
|
|
168
174
|
return_value = nil
|
169
|
-
retry_count = 0
|
170
175
|
begin
|
171
176
|
close_connection = false
|
172
177
|
@connection.request(request) do |response|
|
@@ -195,9 +200,6 @@ module Sunstone
|
|
195
200
|
end
|
196
201
|
end
|
197
202
|
@connection.finish if close_connection
|
198
|
-
rescue ActiveRecord::ConnectionNotEstablished
|
199
|
-
retry_count += 1
|
200
|
-
retry_count == 1 ? retry : raise
|
201
203
|
end
|
202
204
|
|
203
205
|
return_value
|
@@ -396,7 +398,7 @@ module Sunstone
|
|
396
398
|
when 301
|
397
399
|
raise Sunstone::Exception::MovedPermanently, response.body
|
398
400
|
when 502
|
399
|
-
raise
|
401
|
+
raise Sunstone::Exception::BadGateway, response.body
|
400
402
|
when 500..599
|
401
403
|
raise Sunstone::ServerError, response.body
|
402
404
|
else
|
data/lib/sunstone/exception.rb
CHANGED
data/lib/sunstone/version.rb
CHANGED
data/sunstone.gemspec
CHANGED
@@ -13,6 +13,7 @@ Gem::Specification.new do |s|
|
|
13
13
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
14
14
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
15
15
|
s.require_paths = ["lib"]
|
16
|
+
s.required_ruby_version = '>= 2.6'
|
16
17
|
|
17
18
|
# Developoment
|
18
19
|
s.add_development_dependency 'rake'
|
@@ -29,10 +30,10 @@ Gem::Specification.new do |s|
|
|
29
30
|
s.add_development_dependency 'rgeo'
|
30
31
|
s.add_development_dependency 'simplecov'
|
31
32
|
s.add_development_dependency 'byebug'
|
32
|
-
s.add_development_dependency 'activesupport', '
|
33
|
+
s.add_development_dependency 'activesupport', '>= 6.0.0.rc1'
|
33
34
|
|
34
35
|
# Runtime
|
35
36
|
s.add_runtime_dependency 'msgpack'
|
36
37
|
s.add_runtime_dependency 'cookie_store'
|
37
|
-
s.add_runtime_dependency 'activerecord', '
|
38
|
+
s.add_runtime_dependency 'activerecord', '>= 6.0.0.rc1'
|
38
39
|
end
|
@@ -42,19 +42,21 @@ class ActiveRecord::EagerLoadingTest < ActiveSupport::TestCase
|
|
42
42
|
id: 1, ships: [{id: 1, fleet_id: 1}]
|
43
43
|
}].to_json)
|
44
44
|
|
45
|
-
fleets = Fleet.eager_load(:
|
45
|
+
fleets = Fleet.eager_load(ships: :sailors)
|
46
46
|
assert_equal [1], fleets.map(&:id)
|
47
47
|
assert_equal [1], fleets.first.ships.map(&:id)
|
48
48
|
end
|
49
49
|
|
50
50
|
|
51
51
|
test '#eager_loads' do
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
52
|
+
skip
|
53
|
+
assert_equal <<-SQL, Fleet.eager_load(ships: :sailors).limit(2).to_sql
|
54
|
+
SELECT DISTINCT "fleets"."id"
|
55
|
+
FROM "fleets"
|
56
|
+
LEFT OUTER JOIN "ships" ON "ships"."fleet_id" = "fleets"."id"
|
57
|
+
LEFT OUTER JOIN "sailors" ON "sailors"."ship_id" = "ships"."id"
|
58
|
+
LIMIT 2
|
59
|
+
SQL
|
58
60
|
end
|
59
|
-
|
61
|
+
|
60
62
|
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class ActiveRecord::RPCTest < ActiveSupport::TestCase
|
4
|
+
|
5
|
+
schema do
|
6
|
+
create_table "ships", limit: 100 do |t|
|
7
|
+
t.string "name", limit: 255
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
class Ship < ActiveRecord::Base
|
12
|
+
rpc :self_destruct
|
13
|
+
end
|
14
|
+
|
15
|
+
test '::rpc calls custom controller function' do
|
16
|
+
webmock(:get, "/ships", { limit: 1, order: [{id: :asc}] }).to_return({
|
17
|
+
body: [{id: 3, name: 'Sivar'}].to_json
|
18
|
+
})
|
19
|
+
|
20
|
+
webmock(:post, '/ships/3/self_destruct').to_return({
|
21
|
+
body: {name: 'DESTROYED'}.to_json
|
22
|
+
})
|
23
|
+
|
24
|
+
ship = Ship.first
|
25
|
+
assert ship.self_destruct!
|
26
|
+
assert_equal 'DESTROYED', ship.name
|
27
|
+
assert ship.changes.empty?
|
28
|
+
end
|
29
|
+
|
30
|
+
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:
|
4
|
+
version: 6.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:
|
11
|
+
date: 2019-07-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -182,16 +182,16 @@ dependencies:
|
|
182
182
|
name: activesupport
|
183
183
|
requirement: !ruby/object:Gem::Requirement
|
184
184
|
requirements:
|
185
|
-
- - "
|
185
|
+
- - ">="
|
186
186
|
- !ruby/object:Gem::Version
|
187
|
-
version:
|
187
|
+
version: 6.0.0.rc1
|
188
188
|
type: :development
|
189
189
|
prerelease: false
|
190
190
|
version_requirements: !ruby/object:Gem::Requirement
|
191
191
|
requirements:
|
192
|
-
- - "
|
192
|
+
- - ">="
|
193
193
|
- !ruby/object:Gem::Version
|
194
|
-
version:
|
194
|
+
version: 6.0.0.rc1
|
195
195
|
- !ruby/object:Gem::Dependency
|
196
196
|
name: msgpack
|
197
197
|
requirement: !ruby/object:Gem::Requirement
|
@@ -224,16 +224,16 @@ dependencies:
|
|
224
224
|
name: activerecord
|
225
225
|
requirement: !ruby/object:Gem::Requirement
|
226
226
|
requirements:
|
227
|
-
- - "
|
227
|
+
- - ">="
|
228
228
|
- !ruby/object:Gem::Version
|
229
|
-
version:
|
229
|
+
version: 6.0.0.rc1
|
230
230
|
type: :runtime
|
231
231
|
prerelease: false
|
232
232
|
version_requirements: !ruby/object:Gem::Requirement
|
233
233
|
requirements:
|
234
|
-
- - "
|
234
|
+
- - ">="
|
235
235
|
- !ruby/object:Gem::Version
|
236
|
-
version:
|
236
|
+
version: 6.0.0.rc1
|
237
237
|
description: A library for interacting with REST APIs. Similar to ActiveResource
|
238
238
|
email:
|
239
239
|
- jonbracy@gmail.com
|
@@ -299,6 +299,7 @@ files:
|
|
299
299
|
- test/active_record/query/order_test.rb
|
300
300
|
- test/active_record/query/where_test.rb
|
301
301
|
- test/active_record/query_test.rb
|
302
|
+
- test/active_record/rpc_test.rb
|
302
303
|
- test/schema_mock.rb
|
303
304
|
- test/sunstone/connection/configuration_test.rb
|
304
305
|
- test/sunstone/connection/cookie_store_test.rb
|
@@ -317,15 +318,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
317
318
|
requirements:
|
318
319
|
- - ">="
|
319
320
|
- !ruby/object:Gem::Version
|
320
|
-
version: '
|
321
|
+
version: '2.6'
|
321
322
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
322
323
|
requirements:
|
323
324
|
- - ">="
|
324
325
|
- !ruby/object:Gem::Version
|
325
326
|
version: '0'
|
326
327
|
requirements: []
|
327
|
-
|
328
|
-
rubygems_version: 2.7.4
|
328
|
+
rubygems_version: 3.0.3
|
329
329
|
signing_key:
|
330
330
|
specification_version: 4
|
331
331
|
summary: A library for interacting with REST APIs
|
@@ -344,6 +344,7 @@ test_files:
|
|
344
344
|
- test/active_record/query/order_test.rb
|
345
345
|
- test/active_record/query/where_test.rb
|
346
346
|
- test/active_record/query_test.rb
|
347
|
+
- test/active_record/rpc_test.rb
|
347
348
|
- test/schema_mock.rb
|
348
349
|
- test/sunstone/connection/configuration_test.rb
|
349
350
|
- test/sunstone/connection/cookie_store_test.rb
|