sunstone 6.0.0.4 → 6.1.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/lib/sunstone.rb CHANGED
@@ -35,7 +35,21 @@ 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
- require File.expand_path(File.join(__FILE__, '../../ext/active_record/finder_methods'))
40
+ require File.expand_path(File.join(__FILE__, '../../ext/active_record/finder_methods'))
41
+
42
+ if ActiveRecord::VERSION::MAJOR == 6 && ActiveRecord::VERSION::MINOR == 1
43
+ # Patch to allow Rails 6.1 pass url to adapter, all other versions work
44
+ require 'active_record/database_configurations'
45
+ class ActiveRecord::DatabaseConfigurations::UrlConfig
46
+ private
47
+ def build_url_hash
48
+ if url.nil? || %w(jdbc: http: https:).any? { |protocol| url.start_with?(protocol) }
49
+ { url: url }
50
+ else
51
+ ConnectionUrlResolver.new(url).to_hash
52
+ end
53
+ end
54
+ end
55
+ end
@@ -348,7 +348,7 @@ module Sunstone
348
348
  headers = Thread.current[:sunstone_headers]&.clone || {}
349
349
  headers['Accept'] = 'application/json'
350
350
  headers['User-Agent'] = user_agent
351
- headers['Api-Version'] = '0.1.0'
351
+ headers['Api-Version'] = '0.2.0'
352
352
  headers['Connection'] = 'keep-alive'
353
353
 
354
354
  request_api_key = Thread.current[:sunstone_api_key] || api_key
@@ -1,3 +1,3 @@
1
1
  module Sunstone
2
- VERSION = '6.0.0.4'
2
+ VERSION = '6.1.0.2'
3
3
  end
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.rc1'
33
+ s.add_development_dependency 'activesupport', '>= 6.1.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.rc1'
38
+ s.add_runtime_dependency 'activerecord', '>= 6.1.0'
39
+ s.add_runtime_dependency 'arel-extensions', '>= 6.1.0'
39
40
  end
@@ -11,9 +11,10 @@ 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
+ t.text "assignment"
17
18
  end
18
19
 
19
20
  create_table "sailors_ships", id: false do |t|
@@ -22,7 +23,7 @@ class ActiveRecord::PersistanceTest < ActiveSupport::TestCase
22
23
  end
23
24
 
24
25
  end
25
-
26
+
26
27
  class Fleet < ActiveRecord::Base
27
28
  has_many :ships
28
29
  end
@@ -36,16 +37,19 @@ class ActiveRecord::PersistanceTest < ActiveSupport::TestCase
36
37
  class Sailor < ActiveRecord::Base
37
38
  has_and_belongs_to_many :ships
38
39
  end
39
-
40
+
40
41
  class TestModelA < ActiveRecord::Base
41
42
  end
42
-
43
+
43
44
  class TestModelB < ActiveRecord::Base
44
45
  before_save do
45
46
  TestModelA.create
46
47
  end
47
48
  end
48
49
 
50
+ class TestModelC < ActiveRecord::Base
51
+ end
52
+
49
53
  test '#create with errors' do
50
54
  req_stub = webmock(:post, "/fleets").with(
51
55
  body: { fleet: {} }.to_json
@@ -71,7 +75,7 @@ class ActiveRecord::PersistanceTest < ActiveSupport::TestCase
71
75
  assert_requested req_stub
72
76
  end
73
77
 
74
- test '#save w/o changes' do
78
+ test '#save w/o changes does not trigger a request' do
75
79
  webmock(:get, '/fleets', where: {id: 1}, limit: 1).to_return(
76
80
  body: [{id: 1, name: 'Armada Duo'}].to_json
77
81
  )
@@ -82,9 +86,30 @@ class ActiveRecord::PersistanceTest < ActiveSupport::TestCase
82
86
  assert fleet.save
83
87
  assert_equal 1, fleet.id
84
88
  assert_equal 'Armada Duo', fleet.name
89
+
90
+
91
+ webmock(:get, '/sailors', where: {id: 1}, limit: 1).to_return(
92
+ body: [{id: 1, name: 'Nandor', assignment: 'stay alert'}].to_json
93
+ )
94
+
95
+ fleet = Sailor.find(1)
96
+ fleet.save
97
+
98
+ assert fleet.save
99
+ assert_equal 1, fleet.id
100
+ assert_equal 'stay alert', fleet.assignment
85
101
  end
86
102
 
87
103
  test '#save attempts another request while in transaction' do
104
+ webmock(:get, '/test_model_cs/schema').to_return(
105
+ body: {
106
+ attributes: {
107
+ id: {type: 'integer', primary_key: true, null: false, array: false},
108
+ name: {type: 'string', primary_key: false, null: true, array: false}
109
+ }
110
+ }.to_json,
111
+ headers: { 'StandardAPI-Version' => '6.0.0.29' }
112
+ )
88
113
  webmock(:get, '/test_model_bs/schema').to_return(
89
114
  body: {
90
115
  columns: {
@@ -156,4 +181,4 @@ class ActiveRecord::PersistanceTest < ActiveSupport::TestCase
156
181
  assert_requested req_stub
157
182
  end
158
183
 
159
- end
184
+ end
@@ -107,7 +107,7 @@ class ActiveRecord::QueryTest < ActiveSupport::TestCase
107
107
  end
108
108
 
109
109
  test '#to_sql binds correctly when joining' do
110
- assert_equal 'SELECT ships.* FROM ships INNER JOIN ownerships ON ownerships.asset_id = ships.id AND ownerships.asset_type = \'ActiveRecord::QueryTest::Ship\' WHERE ownerships.id = 1', Ship.joins(:ownerships).where({ ownerships: { id: 1 } }).to_sql
110
+ assert_equal 'SELECT ships.* FROM ships INNER JOIN ownerships ON ownerships.asset_type = \'ActiveRecord::QueryTest::Ship\' AND ownerships.asset_id = ships.id WHERE ownerships.id = 1', Ship.joins(:ownerships).where({ ownerships: { id: 1 } }).to_sql
111
111
  end
112
112
 
113
113
  test '#to_sar' do
@@ -119,5 +119,13 @@ class ActiveRecord::QueryTest < ActiveSupport::TestCase
119
119
  query = MessagePack.unpack(CGI.unescape(uri.query))
120
120
  assert_equal({"where"=>{"ownerships"=>{"id"=>{"eq"=>1}}}}, query)
121
121
  end
122
+
123
+ test 'Arel::Nodes::HomogeneousIn' do
124
+ webmock(:get, "/ships", { where: {id: {in: [10,12]} }, limit: 100, offset: 0 }).to_return({
125
+ body: [].to_json
126
+ })
127
+
128
+ Ship.where(id: [10,12]).to_a
129
+ end
122
130
 
123
131
  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,36 +30,40 @@ 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
37
+
38
+ def text(name, options={})
39
+ @columns[name] = Column.new(name, :text, options)
40
+ end
37
41
 
38
42
  def datetime(name, options={})
39
43
  @columns[name] = Column.new(name, :datetime, options)
40
44
  end
41
-
45
+
42
46
  def integer(name, options={})
43
47
  @columns[name] = Column.new(name, :integer, options)
44
48
  end
45
-
49
+
46
50
  def to_json
47
51
  json = @options.slice(:limit)
48
- json[:columns] = {}
52
+ json[:attributes] = {}
49
53
  @columns.each do |name, column|
50
- json[:columns][name] = column.as_json
54
+ json[:attributes][name] = column.as_json
51
55
  end
52
56
  json.to_json
53
57
  end
54
-
58
+
55
59
  end
56
-
60
+
57
61
  attr_accessor :tables
58
-
62
+
59
63
  def initialize
60
64
  @tables = {}
61
65
  end
62
-
66
+
63
67
  def self.define(&block)
64
68
  i = new
65
69
  i.define(&block)
@@ -69,21 +73,21 @@ class ActiveSupport::TestCase
69
73
  def define(&block)
70
74
  instance_eval(&block)
71
75
  end
72
-
76
+
73
77
  def create_table(name, options={}, &block)
74
78
  @tables[name] = Table.new(name, options, &block)
75
79
  end
76
-
80
+
77
81
  end
78
-
82
+
79
83
  def self.schema(&block)
80
84
  self.class_variable_set(:@@schema, Schema.define(&block))
81
85
  end
82
-
86
+
83
87
  set_callback(:setup, :before) do
84
88
  if !instance_variable_defined?(:@suite_setup_run) && self.class.class_variable_defined?(:@@schema)
85
89
  ActiveRecord::Base.establish_connection(adapter: 'sunstone', url: 'http://example.com')
86
-
90
+
87
91
  req_stub = stub_request(:get, /^http:\/\/example.com/).with do |req|
88
92
  case req.uri.path
89
93
  when '/tables'
@@ -94,24 +98,24 @@ class ActiveSupport::TestCase
94
98
  false
95
99
  end
96
100
  end
97
-
101
+
98
102
  req_stub.to_return do |req|
99
103
  case req.uri.path
100
104
  when '/tables'
101
105
  {
102
106
  body: self.class.class_variable_get(:@@schema).tables.keys.to_json,
103
- headers: { 'StandardAPI-Version' => '5.0.0.5' }
107
+ headers: { 'StandardAPI-Version' => '6.0.0.29' }
104
108
  }
105
109
  when /^\/(\w+)\/schema$/i
106
110
  {
107
111
  body: self.class.class_variable_get(:@@schema).tables[$1].to_json,
108
- headers: { 'StandardAPI-Version' => '5.0.0.5' }
112
+ headers: { 'StandardAPI-Version' => '6.0.0.29' }
109
113
  }
110
114
  end
111
115
  end
112
-
116
+
113
117
  end
114
118
  @suite_setup_run = true
115
119
  end
116
-
117
- end
120
+
121
+ 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
+
data/test/test_helper.rb CHANGED
@@ -69,6 +69,7 @@ class ActiveSupport::TestCase
69
69
 
70
70
  stub_request(method, /^#{ActiveRecord::Base.connection.instance_variable_get(:@connection).url}/).with do |req|
71
71
  if query
72
+ puts unpack(req&.uri&.query&.sub(/=true$/, '')) if req&.uri&.query
72
73
  req&.uri&.path == path && req.uri.query && unpack(req.uri.query.sub(/=true$/, '')) == query
73
74
  else
74
75
  req&.uri&.path == path && req.uri.query.nil?
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
4
+ version: 6.1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jon Bracy
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-07-25 00:00:00.000000000 Z
11
+ date: 2021-03-23 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.rc1
187
+ version: 6.1.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.rc1
194
+ version: 6.1.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.rc1
229
+ version: 6.1.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.rc1
236
+ version: 6.1.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.1.0
244
+ type: :runtime
245
+ prerelease: false
246
+ version_requirements: !ruby/object:Gem::Requirement
247
+ requirements:
248
+ - - ">="
249
+ - !ruby/object:Gem::Version
250
+ version: 6.1.0
237
251
  description: A library for interacting with REST APIs. Similar to ActiveResource
238
252
  email:
239
253
  - jonbracy@gmail.com
@@ -241,9 +255,9 @@ executables: []
241
255
  extensions: []
242
256
  extra_rdoc_files: []
243
257
  files:
258
+ - ".github/workflows/main.yml"
244
259
  - ".gitignore"
245
260
  - ".tm_properties"
246
- - ".travis.yml"
247
261
  - Gemfile
248
262
  - LICENSE
249
263
  - README.md
@@ -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
@@ -310,7 +325,7 @@ files:
310
325
  homepage: http://sunstonerb.com
311
326
  licenses: []
312
327
  metadata: {}
313
- post_install_message:
328
+ post_install_message:
314
329
  rdoc_options: []
315
330
  require_paths:
316
331
  - lib
@@ -325,8 +340,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
325
340
  - !ruby/object:Gem::Version
326
341
  version: '0'
327
342
  requirements: []
328
- rubygems_version: 3.0.3
329
- signing_key:
343
+ rubygems_version: 3.2.3
344
+ signing_key:
330
345
  specification_version: 4
331
346
  summary: A library for interacting with REST APIs
332
347
  test_files:
@@ -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