sunstone 6.0.0.5 → 6.0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +3 -3
- data/ext/active_record/finder_methods.rb +3 -13
- data/ext/active_record/statement_cache.rb +2 -3
- data/lib/active_record/connection_adapters/sunstone/database_statements.rb +5 -5
- data/lib/active_record/connection_adapters/sunstone/schema_statements.rb +15 -7
- data/lib/active_record/connection_adapters/sunstone/type/binary.rb +34 -0
- data/lib/active_record/connection_adapters/sunstone_adapter.rb +37 -24
- data/lib/arel/visitors/sunstone.rb +8 -5
- data/lib/sunstone.rb +0 -1
- data/lib/sunstone/version.rb +1 -1
- data/sunstone.gemspec +3 -2
- data/test/active_record/persistance_test.rb +17 -5
- data/test/schema_mock.rb +26 -26
- data/test/sunstone/connection/column_definition_test.rb +30 -0
- metadata +23 -7
- data/ext/arel/attributes/relation.rb +0 -31
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6c4334de568780ae0f1bfff51878a34df6efc921931b3b8369d4c3dbf0212fc3
|
4
|
+
data.tar.gz: 16ffa50224484c100d4161a77cb9618ac206ab56b9c11dbf5f78e5d4863b693b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1ae9e8e867434bdaa2df09eda49c69d80394b1a3f662a2d1fe7e01ea506379e03ad1092782ce87d9059ad64bc84cee590b7c5e0bd4000245c15a0a143279d1c1
|
7
|
+
data.tar.gz: ca3fc4d00c10174a3ec7d6255e04f957e69ecaa9f0d3e6d2c7019774b42922980cafa574f90afeace08f6b35cbd7b79e9e7b22cc64e6a5ea964ab2bd77bb0e61
|
data/.travis.yml
CHANGED
@@ -12,9 +12,9 @@ rvm:
|
|
12
12
|
|
13
13
|
env:
|
14
14
|
matrix:
|
15
|
-
- RAILS_VERSION=v6.0.0
|
16
|
-
- RAILS_VERSION=v6.0.0
|
17
|
-
- RAILS_VERSION=v6.0.0
|
15
|
+
- RAILS_VERSION=v6.0.0 GEM=activerecord:mysql2
|
16
|
+
- RAILS_VERSION=v6.0.0 GEM=activerecord:sqlite3
|
17
|
+
- RAILS_VERSION=v6.0.0 GEM=activerecord:postgresql
|
18
18
|
|
19
19
|
services:
|
20
20
|
- mysql
|
@@ -1,15 +1,3 @@
|
|
1
|
-
module Arel
|
2
|
-
module Visitors
|
3
|
-
class ToSql < Arel::Visitors::Visitor
|
4
|
-
|
5
|
-
def visit_Arel_Attributes_Relation o, collector
|
6
|
-
visit(o.relation, collector)
|
7
|
-
end
|
8
|
-
|
9
|
-
end
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
1
|
module ActiveRecord
|
14
2
|
class PredicateBuilder # :nodoc:
|
15
3
|
|
@@ -202,7 +190,9 @@ module ActiveRecord
|
|
202
190
|
relation = except(:includes, :eager_load, :preload)
|
203
191
|
relation.arel.eager_load = Arel::Nodes::EagerLoad.new(eager_load_values)
|
204
192
|
else
|
205
|
-
join_dependency = construct_join_dependency(
|
193
|
+
join_dependency = construct_join_dependency(
|
194
|
+
eager_load_values + includes_values, Arel::Nodes::OuterJoin
|
195
|
+
)
|
206
196
|
relation = except(:includes, :eager_load, :preload).joins!(join_dependency)
|
207
197
|
end
|
208
198
|
|
@@ -5,10 +5,9 @@ module ActiveRecord
|
|
5
5
|
def initialize(values, sunstone=false)
|
6
6
|
@values = values
|
7
7
|
@indexes = if sunstone
|
8
|
-
|
9
8
|
else
|
10
|
-
values.each_with_index.find_all { |thing,i|
|
11
|
-
|
9
|
+
values.each_with_index.find_all { |thing, i|
|
10
|
+
Substitute === thing
|
12
11
|
}.map(&:last)
|
13
12
|
end
|
14
13
|
end
|
@@ -47,15 +47,15 @@ module ActiveRecord
|
|
47
47
|
# can be used to query the database repeatedly.
|
48
48
|
def cacheable_query(klass, arel) # :nodoc:
|
49
49
|
if prepared_statements
|
50
|
-
sql, binds = visitor.
|
50
|
+
sql, binds = visitor.compile(arel.ast, collector)
|
51
51
|
query = klass.query(sql)
|
52
52
|
elsif self.is_a?(ActiveRecord::ConnectionAdapters::SunstoneAPIAdapter)
|
53
53
|
collector = SunstonePartialQueryCollector.new(self.collector)
|
54
|
-
parts, binds = visitor.
|
54
|
+
parts, binds = visitor.compile(arel.ast, collector)
|
55
55
|
query = StatementCache::PartialQuery.new(parts, true)
|
56
56
|
else
|
57
|
-
collector =
|
58
|
-
parts, binds = visitor.
|
57
|
+
collector = klass.partial_query_collector
|
58
|
+
parts, binds = visitor.compile(arel.ast, collector)
|
59
59
|
query = klass.partial_query(parts)
|
60
60
|
end
|
61
61
|
[query, binds]
|
@@ -142,7 +142,7 @@ module ActiveRecord
|
|
142
142
|
|
143
143
|
if sars[0].instance_variable_defined?(:@sunstone_calculation) && sars[0].instance_variable_get(:@sunstone_calculation)
|
144
144
|
# this is a count, min, max.... yea i know..
|
145
|
-
ActiveRecord::Result.new(['all'], [result], {:all => type_map.lookup('integer')})
|
145
|
+
ActiveRecord::Result.new(['all'], [result], {:all => type_map.lookup('integer', {})})
|
146
146
|
elsif result.is_a?(Array)
|
147
147
|
ActiveRecord::Result.new(result[0] ? result[0].keys : [], result.map{|r| r.values})
|
148
148
|
else
|
@@ -31,7 +31,11 @@ module ActiveRecord
|
|
31
31
|
|
32
32
|
version = Gem::Version.create(response['StandardAPI-Version'] || '5.0.0.4')
|
33
33
|
|
34
|
-
@definitions[table_name] = if (version >= Gem::Version.create('
|
34
|
+
@definitions[table_name] = if (version >= Gem::Version.create('6.0.0.29'))
|
35
|
+
schema = JSON.parse(response.body)
|
36
|
+
schema['columns'] = schema.delete('attributes')
|
37
|
+
schema
|
38
|
+
elsif (version >= Gem::Version.create('5.0.0.5'))
|
35
39
|
JSON.parse(response.body)
|
36
40
|
else
|
37
41
|
{ 'columns' => JSON.parse(response.body), 'limit' => nil }
|
@@ -58,28 +62,32 @@ module ActiveRecord
|
|
58
62
|
def tables
|
59
63
|
JSON.parse(@connection.get('/tables').body)
|
60
64
|
end
|
61
|
-
|
65
|
+
|
62
66
|
def views
|
63
67
|
[]
|
64
68
|
end
|
65
|
-
|
69
|
+
|
66
70
|
def new_column(name, options)
|
67
71
|
sql_type_metadata = fetch_type_metadata(options)
|
68
72
|
SunstoneColumn.new(name, sql_type_metadata, options)
|
69
73
|
end
|
70
|
-
|
74
|
+
|
75
|
+
def lookup_cast_type(options)
|
76
|
+
type_map.lookup(options['type'], options.symbolize_keys)
|
77
|
+
end
|
78
|
+
|
71
79
|
def fetch_type_metadata(options)
|
72
|
-
cast_type = lookup_cast_type(options
|
80
|
+
cast_type = lookup_cast_type(options)
|
73
81
|
simple_type = SqlTypeMetadata.new(
|
74
82
|
sql_type: options['type'],
|
75
83
|
type: cast_type.type,
|
76
84
|
limit: cast_type.limit,
|
77
85
|
precision: cast_type.precision,
|
78
|
-
scale: cast_type.scale
|
86
|
+
scale: cast_type.scale
|
79
87
|
)
|
80
88
|
SunstoneSQLTypeMetadata.new(simple_type, options)
|
81
89
|
end
|
82
|
-
|
90
|
+
|
83
91
|
def column_name_for_operation(operation, node) # :nodoc:
|
84
92
|
visitor.accept(node, collector).first[operation.to_sym]
|
85
93
|
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'base64'
|
2
|
+
|
3
|
+
module ActiveRecord
|
4
|
+
module ConnectionAdapters
|
5
|
+
module Sunstone
|
6
|
+
module Type
|
7
|
+
class Binary < ActiveRecord::Type::Binary
|
8
|
+
|
9
|
+
# Converts a value from database input to the appropriate ruby type. The
|
10
|
+
# return value of this method will be returned from
|
11
|
+
# ActiveRecord::AttributeMethods::Read#read_attribute. The default
|
12
|
+
# implementation just calls Value#cast.
|
13
|
+
#
|
14
|
+
# +value+ The raw input, as provided from the database.
|
15
|
+
def deserialize(value)
|
16
|
+
value.nil? ? nil : Base64.strict_decode64(value)
|
17
|
+
end
|
18
|
+
|
19
|
+
# Casts a value from the ruby type to a type that the database knows how
|
20
|
+
# to understand. The returned value from this method should be a
|
21
|
+
# +String+, +Numeric+, +Date+, +Time+, +Symbol+, +true+, +false+, or
|
22
|
+
# +nil+.
|
23
|
+
def serialize(value)
|
24
|
+
if limit && value.bytesize > limit
|
25
|
+
raise ActiveModel::RangeError, "value is out of range for #{self.class} with limit #{limit} bytes"
|
26
|
+
end
|
27
|
+
Base64.strict_encode64(value)
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'active_record/connection_adapters/abstract_adapter'
|
2
2
|
|
3
|
-
|
3
|
+
require 'arel/nodes/relation'
|
4
|
+
require 'arel/visitors/to_sql_extensions'
|
4
5
|
|
5
6
|
require 'active_record/connection_adapters/sunstone/database_statements'
|
6
7
|
require 'active_record/connection_adapters/sunstone/schema_statements'
|
@@ -9,6 +10,7 @@ require 'active_record/connection_adapters/sunstone/column'
|
|
9
10
|
|
10
11
|
require 'active_record/connection_adapters/sunstone/type/date_time'
|
11
12
|
require 'active_record/connection_adapters/sunstone/type/array'
|
13
|
+
require 'active_record/connection_adapters/sunstone/type/binary'
|
12
14
|
require 'active_record/connection_adapters/sunstone/type/uuid'
|
13
15
|
require 'active_record/connection_adapters/sunstone/type/json'
|
14
16
|
|
@@ -30,7 +32,7 @@ module ActiveRecord
|
|
30
32
|
conn_params[:port] ||= uri.port
|
31
33
|
conn_params[:use_ssl] ||= (uri.scheme == 'https')
|
32
34
|
end
|
33
|
-
|
35
|
+
|
34
36
|
# Forward only valid config params to Sunstone::Connection
|
35
37
|
conn_params.slice!(*VALID_SUNSTONE_CONN_PARAMS)
|
36
38
|
|
@@ -78,9 +80,9 @@ module ActiveRecord
|
|
78
80
|
|
79
81
|
# Initializes and connects a SunstoneAPI adapter.
|
80
82
|
def initialize(connection, logger, connection_parameters, config)
|
81
|
-
super(connection, logger, config)
|
83
|
+
super(connection, logger, config.reverse_merge(prepared_statements: false))
|
82
84
|
|
83
|
-
@
|
85
|
+
@prepared_statement_status = Concurrent::ThreadLocalVar.new(false)
|
84
86
|
@connection_parameters = connection_parameters
|
85
87
|
|
86
88
|
# @type_map = Type::HashLookupTypeMap.new
|
@@ -95,12 +97,12 @@ module ActiveRecord
|
|
95
97
|
super
|
96
98
|
@connection.reconnect!
|
97
99
|
end
|
98
|
-
|
100
|
+
|
99
101
|
def disconnect!
|
100
102
|
super
|
101
103
|
@connection.disconnect!
|
102
104
|
end
|
103
|
-
|
105
|
+
|
104
106
|
# Executes the delete statement and returns the number of rows affected.
|
105
107
|
def delete(arel, name = nil, binds = [])
|
106
108
|
r = exec_delete(arel, name, binds)
|
@@ -122,27 +124,28 @@ module ActiveRecord
|
|
122
124
|
def update_table_definition(table_name, base) #:nodoc:
|
123
125
|
SunstoneAPI::Table.new(table_name, base)
|
124
126
|
end
|
125
|
-
|
127
|
+
|
126
128
|
def arel_visitor
|
127
129
|
Arel::Visitors::Sunstone.new
|
128
130
|
end
|
129
|
-
|
131
|
+
|
130
132
|
def collector
|
131
133
|
Arel::Collectors::Sunstone.new
|
132
134
|
end
|
133
|
-
|
135
|
+
|
134
136
|
def server_config
|
135
137
|
JSON.parse(@connection.get("/configuration").body)
|
136
138
|
end
|
137
|
-
|
139
|
+
|
138
140
|
def lookup_cast_type_from_column(column) # :nodoc:
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
141
|
+
cast_type = type_map.lookup(column.sql_type, {
|
142
|
+
limit: column.limit,
|
143
|
+
precision: column.precision,
|
144
|
+
scale: column.scale
|
145
|
+
})
|
146
|
+
column.array ? Sunstone::Type::Array.new(cast_type) : cast_type
|
144
147
|
end
|
145
|
-
|
148
|
+
|
146
149
|
def transaction(requires_new: nil, isolation: nil, joinable: true)
|
147
150
|
Thread.current[:sunstone_transaction_count] ||= 0
|
148
151
|
Thread.current[:sunstone_request_sent] = nil if Thread.current[:sunstone_transaction_count] == 0
|
@@ -159,7 +162,7 @@ module ActiveRecord
|
|
159
162
|
rescue ActiveRecord::Rollback
|
160
163
|
# rollbacks are silently swallowed
|
161
164
|
end
|
162
|
-
|
165
|
+
|
163
166
|
def supports_json?
|
164
167
|
true
|
165
168
|
end
|
@@ -176,24 +179,34 @@ module ActiveRecord
|
|
176
179
|
exec_insert(arel, name, binds, pk, sequence_name)
|
177
180
|
end
|
178
181
|
alias create insert
|
179
|
-
|
182
|
+
|
180
183
|
# Should be the defuat insert, but rails escapes if for SQL so we'll just
|
181
184
|
# catch the string "DEFATUL VALUES" in the visitor
|
182
185
|
# def empty_insert_statement_value
|
183
186
|
# {}
|
184
187
|
# end
|
185
|
-
|
188
|
+
|
186
189
|
private
|
187
190
|
|
188
191
|
def initialize_type_map(m) # :nodoc:
|
189
192
|
m.register_type 'boolean', Type::Boolean.new
|
190
|
-
m.register_type 'string',
|
191
|
-
|
192
|
-
|
193
|
+
m.register_type 'string' do |_, options|
|
194
|
+
Type::String.new(**options.slice(:limit))
|
195
|
+
end
|
196
|
+
m.register_type 'integer' do |_, options|
|
197
|
+
Type::Integer.new(**options.slice(:limit))
|
198
|
+
end
|
199
|
+
m.register_type 'decimal' do |_, options|
|
200
|
+
Type::Decimal.new(**options.slice(:precision, :scale))
|
201
|
+
end
|
202
|
+
m.register_type 'binary' do |_, options|
|
203
|
+
Sunstone::Type::Binary.new(**options.slice(:limit))
|
204
|
+
end
|
205
|
+
|
193
206
|
m.register_type 'datetime', Sunstone::Type::DateTime.new
|
194
207
|
m.register_type 'json', Sunstone::Type::Json.new
|
195
208
|
m.register_type 'uuid', Sunstone::Type::Uuid.new
|
196
|
-
|
209
|
+
|
197
210
|
if defined?(Sunstone::Type::EWKB)
|
198
211
|
m.register_type 'ewkb', Sunstone::Type::EWKB.new
|
199
212
|
end
|
@@ -202,7 +215,7 @@ module ActiveRecord
|
|
202
215
|
def create_table_definition(name, temporary, options, as = nil) # :nodoc:
|
203
216
|
SunstoneAPI::TableDefinition.new native_database_types, name, temporary, options, as
|
204
217
|
end
|
205
|
-
|
218
|
+
|
206
219
|
ActiveRecord::Type.add_modifier({ array: true }, Sunstone::Type::Array, adapter: :sunstone)
|
207
220
|
# ActiveRecord::Type.add_modifier({ range: true }, OID::Range, adapter: :postgresql)
|
208
221
|
end
|
@@ -10,10 +10,10 @@ module Arel
|
|
10
10
|
module Visitors
|
11
11
|
class Sunstone < Arel::Visitors::Visitor
|
12
12
|
|
13
|
-
def compile
|
14
|
-
accept(node,
|
13
|
+
def compile(node, collector = Arel::Collectors::Sunstone.new)
|
14
|
+
accept(node, collector).value
|
15
15
|
end
|
16
|
-
|
16
|
+
|
17
17
|
def preparable
|
18
18
|
false
|
19
19
|
end
|
@@ -925,9 +925,12 @@ module Arel
|
|
925
925
|
value = if o.relation.is_a?(Arel::Attributes::Relation)
|
926
926
|
{ o.name => visit_Arel_Attributes_Relation(o.relation, collector, false) }
|
927
927
|
else
|
928
|
-
|
928
|
+
if o.relation.is_a?(Arel::Attributes::Attribute)
|
929
|
+
{ o.name => o.relation.name }
|
930
|
+
else
|
931
|
+
visit(o.relation, collector)
|
932
|
+
end
|
929
933
|
end
|
930
|
-
# value = value.to_s.split('.').last if !value.is_a?(Hash)
|
931
934
|
|
932
935
|
if o.collection
|
933
936
|
ary = []
|
data/lib/sunstone.rb
CHANGED
@@ -35,7 +35,6 @@ require File.expand_path(File.join(__FILE__, '../../ext/active_support/core_ext/
|
|
35
35
|
|
36
36
|
require File.expand_path(File.join(__FILE__, '../../ext/arel/select_manager'))
|
37
37
|
require File.expand_path(File.join(__FILE__, '../../ext/arel/nodes/eager_load'))
|
38
|
-
require File.expand_path(File.join(__FILE__, '../../ext/arel/attributes/relation'))
|
39
38
|
require File.expand_path(File.join(__FILE__, '../../ext/arel/attributes/empty_relation'))
|
40
39
|
require File.expand_path(File.join(__FILE__, '../../ext/arel/nodes/select_statement'))
|
41
40
|
require File.expand_path(File.join(__FILE__, '../../ext/active_record/finder_methods'))
|
data/lib/sunstone/version.rb
CHANGED
data/sunstone.gemspec
CHANGED
@@ -30,10 +30,11 @@ Gem::Specification.new do |s|
|
|
30
30
|
s.add_development_dependency 'rgeo'
|
31
31
|
s.add_development_dependency 'simplecov'
|
32
32
|
s.add_development_dependency 'byebug'
|
33
|
-
s.add_development_dependency 'activesupport', '>= 6.0.0
|
33
|
+
s.add_development_dependency 'activesupport', '>= 6.0.0'
|
34
34
|
|
35
35
|
# Runtime
|
36
36
|
s.add_runtime_dependency 'msgpack'
|
37
37
|
s.add_runtime_dependency 'cookie_store'
|
38
|
-
s.add_runtime_dependency 'activerecord', '>= 6.0.0
|
38
|
+
s.add_runtime_dependency 'activerecord', '>= 6.0.0'
|
39
|
+
s.add_runtime_dependency 'arel-extensions', '>= 6.0.0.5'
|
39
40
|
end
|
@@ -11,7 +11,7 @@ class ActiveRecord::PersistanceTest < ActiveSupport::TestCase
|
|
11
11
|
create_table "fleets" do |t|
|
12
12
|
t.string "name", limit: 255
|
13
13
|
end
|
14
|
-
|
14
|
+
|
15
15
|
create_table "sailors" do |t|
|
16
16
|
t.string "name", limit: 255
|
17
17
|
end
|
@@ -22,7 +22,7 @@ class ActiveRecord::PersistanceTest < ActiveSupport::TestCase
|
|
22
22
|
end
|
23
23
|
|
24
24
|
end
|
25
|
-
|
25
|
+
|
26
26
|
class Fleet < ActiveRecord::Base
|
27
27
|
has_many :ships
|
28
28
|
end
|
@@ -36,16 +36,19 @@ class ActiveRecord::PersistanceTest < ActiveSupport::TestCase
|
|
36
36
|
class Sailor < ActiveRecord::Base
|
37
37
|
has_and_belongs_to_many :ships
|
38
38
|
end
|
39
|
-
|
39
|
+
|
40
40
|
class TestModelA < ActiveRecord::Base
|
41
41
|
end
|
42
|
-
|
42
|
+
|
43
43
|
class TestModelB < ActiveRecord::Base
|
44
44
|
before_save do
|
45
45
|
TestModelA.create
|
46
46
|
end
|
47
47
|
end
|
48
48
|
|
49
|
+
class TestModelC < ActiveRecord::Base
|
50
|
+
end
|
51
|
+
|
49
52
|
test '#create with errors' do
|
50
53
|
req_stub = webmock(:post, "/fleets").with(
|
51
54
|
body: { fleet: {} }.to_json
|
@@ -85,6 +88,15 @@ class ActiveRecord::PersistanceTest < ActiveSupport::TestCase
|
|
85
88
|
end
|
86
89
|
|
87
90
|
test '#save attempts another request while in transaction' do
|
91
|
+
webmock(:get, '/test_model_cs/schema').to_return(
|
92
|
+
body: {
|
93
|
+
attributes: {
|
94
|
+
id: {type: 'integer', primary_key: true, null: false, array: false},
|
95
|
+
name: {type: 'string', primary_key: false, null: true, array: false}
|
96
|
+
}
|
97
|
+
}.to_json,
|
98
|
+
headers: { 'StandardAPI-Version' => '6.0.0.29' }
|
99
|
+
)
|
88
100
|
webmock(:get, '/test_model_bs/schema').to_return(
|
89
101
|
body: {
|
90
102
|
columns: {
|
@@ -156,4 +168,4 @@ class ActiveRecord::PersistanceTest < ActiveSupport::TestCase
|
|
156
168
|
assert_requested req_stub
|
157
169
|
end
|
158
170
|
|
159
|
-
end
|
171
|
+
end
|
data/test/schema_mock.rb
CHANGED
@@ -1,23 +1,23 @@
|
|
1
1
|
class ActiveSupport::TestCase
|
2
2
|
class Schema
|
3
|
-
|
3
|
+
|
4
4
|
class Table
|
5
|
-
|
5
|
+
|
6
6
|
class Column
|
7
|
-
|
7
|
+
|
8
8
|
def initialize(name, type, options={})
|
9
9
|
@name = name
|
10
10
|
@type = type
|
11
11
|
@options = options
|
12
12
|
end
|
13
|
-
|
13
|
+
|
14
14
|
def as_json
|
15
15
|
{type: @type, primary_key: false, null: true, array: false}.merge(@options)
|
16
16
|
end
|
17
17
|
end
|
18
|
-
|
18
|
+
|
19
19
|
attr_accessor :name, :options, :columns
|
20
|
-
|
20
|
+
|
21
21
|
def initialize(name, options={}, &block)
|
22
22
|
@name = name
|
23
23
|
@options = options
|
@@ -30,7 +30,7 @@ class ActiveSupport::TestCase
|
|
30
30
|
|
31
31
|
block.call(self)
|
32
32
|
end
|
33
|
-
|
33
|
+
|
34
34
|
def string(name, options={})
|
35
35
|
@columns[name] = Column.new(name, :string, options)
|
36
36
|
end
|
@@ -38,28 +38,28 @@ class ActiveSupport::TestCase
|
|
38
38
|
def datetime(name, options={})
|
39
39
|
@columns[name] = Column.new(name, :datetime, options)
|
40
40
|
end
|
41
|
-
|
41
|
+
|
42
42
|
def integer(name, options={})
|
43
43
|
@columns[name] = Column.new(name, :integer, options)
|
44
44
|
end
|
45
|
-
|
45
|
+
|
46
46
|
def to_json
|
47
47
|
json = @options.slice(:limit)
|
48
|
-
json[:
|
48
|
+
json[:attributes] = {}
|
49
49
|
@columns.each do |name, column|
|
50
|
-
json[:
|
50
|
+
json[:attributes][name] = column.as_json
|
51
51
|
end
|
52
52
|
json.to_json
|
53
53
|
end
|
54
|
-
|
54
|
+
|
55
55
|
end
|
56
|
-
|
56
|
+
|
57
57
|
attr_accessor :tables
|
58
|
-
|
58
|
+
|
59
59
|
def initialize
|
60
60
|
@tables = {}
|
61
61
|
end
|
62
|
-
|
62
|
+
|
63
63
|
def self.define(&block)
|
64
64
|
i = new
|
65
65
|
i.define(&block)
|
@@ -69,21 +69,21 @@ class ActiveSupport::TestCase
|
|
69
69
|
def define(&block)
|
70
70
|
instance_eval(&block)
|
71
71
|
end
|
72
|
-
|
72
|
+
|
73
73
|
def create_table(name, options={}, &block)
|
74
74
|
@tables[name] = Table.new(name, options, &block)
|
75
75
|
end
|
76
|
-
|
76
|
+
|
77
77
|
end
|
78
|
-
|
78
|
+
|
79
79
|
def self.schema(&block)
|
80
80
|
self.class_variable_set(:@@schema, Schema.define(&block))
|
81
81
|
end
|
82
|
-
|
82
|
+
|
83
83
|
set_callback(:setup, :before) do
|
84
84
|
if !instance_variable_defined?(:@suite_setup_run) && self.class.class_variable_defined?(:@@schema)
|
85
85
|
ActiveRecord::Base.establish_connection(adapter: 'sunstone', url: 'http://example.com')
|
86
|
-
|
86
|
+
|
87
87
|
req_stub = stub_request(:get, /^http:\/\/example.com/).with do |req|
|
88
88
|
case req.uri.path
|
89
89
|
when '/tables'
|
@@ -94,24 +94,24 @@ class ActiveSupport::TestCase
|
|
94
94
|
false
|
95
95
|
end
|
96
96
|
end
|
97
|
-
|
97
|
+
|
98
98
|
req_stub.to_return do |req|
|
99
99
|
case req.uri.path
|
100
100
|
when '/tables'
|
101
101
|
{
|
102
102
|
body: self.class.class_variable_get(:@@schema).tables.keys.to_json,
|
103
|
-
headers: { 'StandardAPI-Version' => '
|
103
|
+
headers: { 'StandardAPI-Version' => '6.0.0.29' }
|
104
104
|
}
|
105
105
|
when /^\/(\w+)\/schema$/i
|
106
106
|
{
|
107
107
|
body: self.class.class_variable_get(:@@schema).tables[$1].to_json,
|
108
|
-
headers: { 'StandardAPI-Version' => '
|
108
|
+
headers: { 'StandardAPI-Version' => '6.0.0.29' }
|
109
109
|
}
|
110
110
|
end
|
111
111
|
end
|
112
|
-
|
112
|
+
|
113
113
|
end
|
114
114
|
@suite_setup_run = true
|
115
115
|
end
|
116
|
-
|
117
|
-
end
|
116
|
+
|
117
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class Sunstone::Connection::ColumnDefinitionTest < ActiveSupport::TestCase
|
4
|
+
|
5
|
+
schema do
|
6
|
+
create_table "ships", limit: 100 do |t|
|
7
|
+
t.string "name", limit: 255
|
8
|
+
t.integer "guns", limit: 8
|
9
|
+
t.integer "sailor_count"
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
class Ship < ActiveRecord::Base
|
14
|
+
end
|
15
|
+
|
16
|
+
test "default limit on column" do
|
17
|
+
assert_nil Ship.columns_hash['sailor_count'].limit
|
18
|
+
end
|
19
|
+
|
20
|
+
test "custom limit on column" do
|
21
|
+
assert_equal 8, Ship.columns_hash['guns'].limit
|
22
|
+
end
|
23
|
+
|
24
|
+
test "custom limit on string column" do
|
25
|
+
assert_equal 255, Ship.columns_hash['name'].limit
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
|
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: 6.0.0.
|
4
|
+
version: 6.0.0.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jon Bracy
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-12-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -184,14 +184,14 @@ dependencies:
|
|
184
184
|
requirements:
|
185
185
|
- - ">="
|
186
186
|
- !ruby/object:Gem::Version
|
187
|
-
version: 6.0.0
|
187
|
+
version: 6.0.0
|
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: 6.0.0
|
194
|
+
version: 6.0.0
|
195
195
|
- !ruby/object:Gem::Dependency
|
196
196
|
name: msgpack
|
197
197
|
requirement: !ruby/object:Gem::Requirement
|
@@ -226,14 +226,28 @@ dependencies:
|
|
226
226
|
requirements:
|
227
227
|
- - ">="
|
228
228
|
- !ruby/object:Gem::Version
|
229
|
-
version: 6.0.0
|
229
|
+
version: 6.0.0
|
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: 6.0.0
|
236
|
+
version: 6.0.0
|
237
|
+
- !ruby/object:Gem::Dependency
|
238
|
+
name: arel-extensions
|
239
|
+
requirement: !ruby/object:Gem::Requirement
|
240
|
+
requirements:
|
241
|
+
- - ">="
|
242
|
+
- !ruby/object:Gem::Version
|
243
|
+
version: 6.0.0.5
|
244
|
+
type: :runtime
|
245
|
+
prerelease: false
|
246
|
+
version_requirements: !ruby/object:Gem::Requirement
|
247
|
+
requirements:
|
248
|
+
- - ">="
|
249
|
+
- !ruby/object:Gem::Version
|
250
|
+
version: 6.0.0.5
|
237
251
|
description: A library for interacting with REST APIs. Similar to ActiveResource
|
238
252
|
email:
|
239
253
|
- jonbracy@gmail.com
|
@@ -262,7 +276,6 @@ files:
|
|
262
276
|
- ext/active_record/transactions.rb
|
263
277
|
- ext/active_support/core_ext/object/to_query.rb
|
264
278
|
- ext/arel/attributes/empty_relation.rb
|
265
|
-
- ext/arel/attributes/relation.rb
|
266
279
|
- ext/arel/nodes/eager_load.rb
|
267
280
|
- ext/arel/nodes/select_statement.rb
|
268
281
|
- ext/arel/select_manager.rb
|
@@ -271,6 +284,7 @@ files:
|
|
271
284
|
- lib/active_record/connection_adapters/sunstone/schema_dumper.rb
|
272
285
|
- lib/active_record/connection_adapters/sunstone/schema_statements.rb
|
273
286
|
- lib/active_record/connection_adapters/sunstone/type/array.rb
|
287
|
+
- lib/active_record/connection_adapters/sunstone/type/binary.rb
|
274
288
|
- lib/active_record/connection_adapters/sunstone/type/date_time.rb
|
275
289
|
- lib/active_record/connection_adapters/sunstone/type/ewkb.rb
|
276
290
|
- lib/active_record/connection_adapters/sunstone/type/json.rb
|
@@ -301,6 +315,7 @@ files:
|
|
301
315
|
- test/active_record/query_test.rb
|
302
316
|
- test/active_record/rpc_test.rb
|
303
317
|
- test/schema_mock.rb
|
318
|
+
- test/sunstone/connection/column_definition_test.rb
|
304
319
|
- test/sunstone/connection/configuration_test.rb
|
305
320
|
- test/sunstone/connection/cookie_store_test.rb
|
306
321
|
- test/sunstone/connection/request_helper_test.rb
|
@@ -346,6 +361,7 @@ test_files:
|
|
346
361
|
- test/active_record/query_test.rb
|
347
362
|
- test/active_record/rpc_test.rb
|
348
363
|
- test/schema_mock.rb
|
364
|
+
- test/sunstone/connection/column_definition_test.rb
|
349
365
|
- test/sunstone/connection/configuration_test.rb
|
350
366
|
- test/sunstone/connection/cookie_store_test.rb
|
351
367
|
- test/sunstone/connection/request_helper_test.rb
|
@@ -1,31 +0,0 @@
|
|
1
|
-
module Arel
|
2
|
-
module Attributes
|
3
|
-
class Relation < Attribute
|
4
|
-
|
5
|
-
attr_accessor :collection, :for_write
|
6
|
-
|
7
|
-
def initialize(relation, name, collection = false, for_write=false)
|
8
|
-
self[:relation] = relation
|
9
|
-
self[:name] = name
|
10
|
-
@collection = collection
|
11
|
-
@for_write = for_write
|
12
|
-
end
|
13
|
-
|
14
|
-
def able_to_type_cast?
|
15
|
-
false
|
16
|
-
end
|
17
|
-
|
18
|
-
def table_name
|
19
|
-
nil
|
20
|
-
end
|
21
|
-
|
22
|
-
def eql? other
|
23
|
-
self.class == other.class &&
|
24
|
-
self.relation == other.relation &&
|
25
|
-
self.name == other.name &&
|
26
|
-
self.collection == other.collection
|
27
|
-
end
|
28
|
-
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|