sunstone 6.0.0.5 → 6.1.3
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/ext/active_record/associations.rb +2 -2
- data/ext/active_record/attribute_methods.rb +2 -2
- data/ext/active_record/callbacks.rb +1 -1
- data/ext/active_record/finder_methods.rb +42 -36
- data/ext/active_record/persistence.rb +2 -0
- data/ext/active_record/relation/calculations.rb +2 -2
- data/ext/active_record/statement_cache.rb +9 -5
- data/ext/active_record/transactions.rb +8 -15
- data/ext/arel/attributes/empty_relation.rb +31 -31
- data/ext/arel/nodes/select_statement.rb +1 -1
- data/lib/active_record/connection_adapters/sunstone/column.rb +3 -3
- data/lib/active_record/connection_adapters/sunstone/database_statements.rb +5 -5
- data/lib/active_record/connection_adapters/sunstone/schema_statements.rb +18 -8
- data/lib/active_record/connection_adapters/sunstone/type/binary.rb +34 -0
- data/lib/active_record/connection_adapters/sunstone_adapter.rb +39 -26
- data/lib/arel/visitors/sunstone.rb +13 -15
- data/lib/sunstone.rb +16 -2
- data/lib/sunstone/connection.rb +1 -1
- data/lib/sunstone/version.rb +1 -1
- metadata +40 -64
- data/.gitignore +0 -31
- data/.tm_properties +0 -1
- data/.travis.yml +0 -49
- data/Gemfile +0 -4
- data/README.md +0 -10
- data/Rakefile +0 -37
- data/TODO.md +0 -89
- data/ext/arel/attributes/relation.rb +0 -31
- data/sunstone.gemspec +0 -39
- data/test/active_record/associations/belongs_to_test.rb +0 -162
- data/test/active_record/associations/has_and_belongs_to_many_test.rb +0 -125
- data/test/active_record/associations/has_many_test.rb +0 -244
- data/test/active_record/eager_loading_test.rb +0 -62
- data/test/active_record/persistance_test.rb +0 -159
- data/test/active_record/preload_test.rb +0 -51
- data/test/active_record/query/all_test.rb +0 -33
- data/test/active_record/query/count_test.rb +0 -51
- data/test/active_record/query/distinct_test.rb +0 -30
- data/test/active_record/query/find_test.rb +0 -37
- data/test/active_record/query/limit_test.rb +0 -19
- data/test/active_record/query/order_test.rb +0 -27
- data/test/active_record/query/where_test.rb +0 -79
- data/test/active_record/query_test.rb +0 -123
- data/test/active_record/rpc_test.rb +0 -30
- data/test/schema_mock.rb +0 -117
- data/test/sunstone/connection/configuration_test.rb +0 -44
- data/test/sunstone/connection/cookie_store_test.rb +0 -37
- data/test/sunstone/connection/request_helper_test.rb +0 -105
- data/test/sunstone/connection/send_request_test.rb +0 -164
- data/test/sunstone/connection_test.rb +0 -23
- data/test/test_helper.rb +0 -152
data/.gitignore
DELETED
@@ -1,31 +0,0 @@
|
|
1
|
-
*.gem
|
2
|
-
*.rbc
|
3
|
-
/.config
|
4
|
-
/coverage/
|
5
|
-
/InstalledFiles
|
6
|
-
/pkg/
|
7
|
-
/spec/reports/
|
8
|
-
/test/tmp/
|
9
|
-
/test/version_tmp/
|
10
|
-
/tmp/
|
11
|
-
.DS_Store
|
12
|
-
|
13
|
-
## Documentation cache and generated files:
|
14
|
-
/.yardoc/
|
15
|
-
/_yardoc/
|
16
|
-
/doc/
|
17
|
-
/rdoc/
|
18
|
-
|
19
|
-
## Environment normalisation:
|
20
|
-
/.bundle/
|
21
|
-
/lib/bundler/man/
|
22
|
-
|
23
|
-
# for a library or gem, you might want to ignore these files since the code is
|
24
|
-
# intended to run in multiple environments; otherwise, check them in:
|
25
|
-
Gemfile.lock
|
26
|
-
.ruby-version
|
27
|
-
.ruby-gemset
|
28
|
-
|
29
|
-
# Text Editor scraps
|
30
|
-
*~
|
31
|
-
.byebug_history
|
data/.tm_properties
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
exclude = '{$exclude,log,bin,tmp,.tm_properties,coverage}'
|
data/.travis.yml
DELETED
@@ -1,49 +0,0 @@
|
|
1
|
-
dist: xenial
|
2
|
-
language: ruby
|
3
|
-
sudo: false
|
4
|
-
|
5
|
-
cache:
|
6
|
-
bundler: true
|
7
|
-
directories:
|
8
|
-
- /home/travis/.rvm/gems
|
9
|
-
|
10
|
-
rvm:
|
11
|
-
- 2.6
|
12
|
-
|
13
|
-
env:
|
14
|
-
matrix:
|
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
|
-
|
19
|
-
services:
|
20
|
-
- mysql
|
21
|
-
addons:
|
22
|
-
postgresql: "10"
|
23
|
-
|
24
|
-
before_install:
|
25
|
-
- unset BUNDLE_GEMFILE
|
26
|
-
- gem update --system
|
27
|
-
- gem update bundler
|
28
|
-
|
29
|
-
install:
|
30
|
-
- git clone --branch $RAILS_VERSION https://github.com/rails/rails.git ~/build/rails
|
31
|
-
|
32
|
-
before_script:
|
33
|
-
- sed -i "s/t.warning = true/t.warning = false/g" Rakefile
|
34
|
-
- pushd ~/build/rails
|
35
|
-
- git status
|
36
|
-
- sed -i "s/Gem.ruby, '-w'/Gem.ruby, '-w0'/" ~/build/rails/activerecord/Rakefile
|
37
|
-
- sed -i "s/t.warning = true/t.warning = false/g" ~/build/rails/activerecord/Rakefile
|
38
|
-
- sed -i "/require 'support\/connection'/a \$LOAD_PATH.unshift\(File.expand_path\('~\/build\/malomalo\/sunstone\/lib'\)\)\nrequire 'sunstone'" ~/build/rails/activerecord/test/cases/helper.rb
|
39
|
-
- cat ~/build/rails/Gemfile
|
40
|
-
- rm ~/build/rails/Gemfile.lock
|
41
|
-
- "sed -i \"/# Active Record./a gem 'sunstone', path: File.expand_path\\('~\\/build\\/malomalo\\/sunstone'\\)\" ~/build/rails/Gemfile"
|
42
|
-
- cat ~/build/rails/Gemfile
|
43
|
-
- bundle update --jobs=3 --retry=3
|
44
|
-
- popd
|
45
|
-
- bundle install --jobs=3 --retry=3
|
46
|
-
|
47
|
-
script:
|
48
|
-
- bundle exec rake test
|
49
|
-
- cd ~/build/rails && ci/travis.rb
|
data/Gemfile
DELETED
data/README.md
DELETED
@@ -1,10 +0,0 @@
|
|
1
|
-
# Sunstone [](https://travis-ci.org/malomalo/sunstone)
|
2
|
-
|
3
|
-
An [ActiveRecord](https://rubygems.org/gems/activerecord) adapter for quering
|
4
|
-
APIs over Standard API (https://github.com/waratuman/standardapi).
|
5
|
-
|
6
|
-
|
7
|
-
TODO:
|
8
|
-
=====
|
9
|
-
Make `cookie_store` and optional
|
10
|
-
stream building model instances with wankel
|
data/Rakefile
DELETED
@@ -1,37 +0,0 @@
|
|
1
|
-
require 'bundler/setup'
|
2
|
-
require "bundler/gem_tasks"
|
3
|
-
Bundler.require(:development)
|
4
|
-
require 'rake/testtask'
|
5
|
-
require 'rdoc/task'
|
6
|
-
|
7
|
-
task :console do
|
8
|
-
exec 'irb -I lib -r sunstone.rb'
|
9
|
-
end
|
10
|
-
task :c => :console
|
11
|
-
|
12
|
-
Rake::TestTask.new do |t|
|
13
|
-
t.libs << 'test'
|
14
|
-
t.test_files = FileList['test/**/*_test.rb']
|
15
|
-
t.warning = true
|
16
|
-
#t.verbose = true
|
17
|
-
end
|
18
|
-
|
19
|
-
Rake::RDocTask.new do |rd|
|
20
|
-
rd.main = 'README.md'
|
21
|
-
rd.title = 'Sunstone Documentation'
|
22
|
-
rd.rdoc_dir = 'doc'
|
23
|
-
|
24
|
-
rd.options << '-f' << 'sdoc'
|
25
|
-
rd.options << '-T' << '42floors'
|
26
|
-
rd.options << '-g' # Generate github links
|
27
|
-
|
28
|
-
rd.rdoc_files.include('README.rdoc')
|
29
|
-
rd.rdoc_files.include('lib/**/*.rb')
|
30
|
-
end
|
31
|
-
|
32
|
-
desc "Run tests"
|
33
|
-
task :default => :test
|
34
|
-
|
35
|
-
namespace :pages do
|
36
|
-
#TODO: https://github.com/defunkt/sdoc-helpers/blob/master/lib/sdoc_helpers/pages.rb
|
37
|
-
end
|
data/TODO.md
DELETED
@@ -1,89 +0,0 @@
|
|
1
|
-
- Check if `Sunstone#to_key` needs to be added
|
2
|
-
|
3
|
-
- Add `Sunstone::Model::Persistance` with the following methods:
|
4
|
-
|
5
|
-
- `#new_record?`
|
6
|
-
- `#persisted?`
|
7
|
-
- `#save`
|
8
|
-
- `#save!`
|
9
|
-
- `#update`
|
10
|
-
- `#update!`
|
11
|
-
- `#create`
|
12
|
-
- `#to_param` ?
|
13
|
-
- `::all`
|
14
|
-
- `::where` (probably goes in an Arel like engine)
|
15
|
-
- `::build`
|
16
|
-
- `::create!`
|
17
|
-
- `#==`
|
18
|
-
- `::create`
|
19
|
-
|
20
|
-
```ruby
|
21
|
-
# Creates an object and saves it to the MLS. The resulting object is returned
|
22
|
-
# whether or no the object was saved successfully to the MLS or not.
|
23
|
-
#
|
24
|
-
# ==== Examples
|
25
|
-
# #!ruby
|
26
|
-
# # Create a single new object
|
27
|
-
# User.create(:first_name => 'Jamie')
|
28
|
-
#
|
29
|
-
# # Create a single object and pass it into a block to set other attributes.
|
30
|
-
# User.create(:first_name => 'Jamie') do |u|
|
31
|
-
# u.is_admin = false
|
32
|
-
# end
|
33
|
-
def self.create(attributes={}, &block) # TODO: testme
|
34
|
-
model = self.new(attributes)
|
35
|
-
yield(model) if block_given?
|
36
|
-
model.save
|
37
|
-
model
|
38
|
-
end
|
39
|
-
|
40
|
-
|
41
|
-
- Look at https://gist.github.com/malomalo/91f360fe52db3dbe1c99 files for inspiration, came from
|
42
|
-
Rails code I think
|
43
|
-
|
44
|
-
- Simplify `Sunstone::Type::Value` to `Sunstone::Type`
|
45
|
-
|
46
|
-
- Add a `find_class(type)` in `Sunstone::Schema`
|
47
|
-
|
48
|
-
- Possibly use Classes to hold information about each attribute in addition to the type
|
49
|
-
|
50
|
-
```ruby
|
51
|
-
class MLS::Attribute
|
52
|
-
|
53
|
-
DEFAULT_OPTIONS = { :serialize => true }
|
54
|
-
|
55
|
-
attr_reader :model, :name, :instance_variable_name, :options, :default
|
56
|
-
attr_reader :reader_visibility, :writer_visibility
|
57
|
-
|
58
|
-
def initialize(name, options={})
|
59
|
-
@name = name
|
60
|
-
@instance_variable_name = "@#{@name}".freeze
|
61
|
-
@options = DEFAULT_OPTIONS.merge(options)
|
62
|
-
|
63
|
-
@default = @options[:default]
|
64
|
-
@reader_visibility = @options[:reader] || :public
|
65
|
-
@writer_visibility = @options[:writer] || :public
|
66
|
-
end
|
67
|
-
end
|
68
|
-
```
|
69
|
-
|
70
|
-
- Use Association classes to model the association:
|
71
|
-
|
72
|
-
```ruby
|
73
|
-
class MLS::Association
|
74
|
-
class BelongsTo
|
75
|
-
attr_reader :klass, :foreign_key, :foreign_type, :primary_key, :polymorphic
|
76
|
-
|
77
|
-
def initialize(name, options={})
|
78
|
-
@name = name
|
79
|
-
@klass = options[:class_name] ? options[:class_name].constantize : name.camelize.constantize
|
80
|
-
|
81
|
-
@polymorphic = options[:polymorphic] || false
|
82
|
-
@foreign_key = options[:foreign_key] || "#{name}_id".to_sym
|
83
|
-
@foreign_type = options[:foreign_type] || "#{name}_type".to_sym
|
84
|
-
@primary_key = options[:primary_key] || :id
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
|
-
end
|
89
|
-
```
|
@@ -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
|
data/sunstone.gemspec
DELETED
@@ -1,39 +0,0 @@
|
|
1
|
-
require File.expand_path("../lib/sunstone/version", __FILE__)
|
2
|
-
|
3
|
-
Gem::Specification.new do |s|
|
4
|
-
s.name = "sunstone"
|
5
|
-
s.version = Sunstone::VERSION
|
6
|
-
s.authors = ["Jon Bracy"]
|
7
|
-
s.email = ["jonbracy@gmail.com"]
|
8
|
-
s.homepage = "http://sunstonerb.com"
|
9
|
-
s.summary = %q{A library for interacting with REST APIs}
|
10
|
-
s.description = %q{A library for interacting with REST APIs. Similar to ActiveResource}
|
11
|
-
|
12
|
-
s.files = `git ls-files`.split("\n")
|
13
|
-
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
14
|
-
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
15
|
-
s.require_paths = ["lib"]
|
16
|
-
s.required_ruby_version = '>= 2.6'
|
17
|
-
|
18
|
-
# Developoment
|
19
|
-
s.add_development_dependency 'rake'
|
20
|
-
s.add_development_dependency 'rdoc'
|
21
|
-
# s.add_development_dependency 'sdoc'
|
22
|
-
s.add_development_dependency 'bundler'
|
23
|
-
s.add_development_dependency 'minitest'
|
24
|
-
s.add_development_dependency 'minitest-reporters'
|
25
|
-
s.add_development_dependency 'mocha'
|
26
|
-
s.add_development_dependency 'faker'
|
27
|
-
s.add_development_dependency 'factory_bot'
|
28
|
-
s.add_development_dependency 'webmock'
|
29
|
-
#s.add_development_dependency 'sdoc-templates-42floors'
|
30
|
-
s.add_development_dependency 'rgeo'
|
31
|
-
s.add_development_dependency 'simplecov'
|
32
|
-
s.add_development_dependency 'byebug'
|
33
|
-
s.add_development_dependency 'activesupport', '>= 6.0.0.rc1'
|
34
|
-
|
35
|
-
# Runtime
|
36
|
-
s.add_runtime_dependency 'msgpack'
|
37
|
-
s.add_runtime_dependency 'cookie_store'
|
38
|
-
s.add_runtime_dependency 'activerecord', '>= 6.0.0.rc1'
|
39
|
-
end
|
@@ -1,162 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class ActiveRecord::Associations::BelongsToTest < ActiveSupport::TestCase
|
4
|
-
|
5
|
-
schema do
|
6
|
-
create_table "ships" do |t|
|
7
|
-
t.string "name", limit: 255
|
8
|
-
t.integer "fleet_id"
|
9
|
-
end
|
10
|
-
|
11
|
-
create_table "fleets" do |t|
|
12
|
-
t.string "name", limit: 255
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
class Fleet < ActiveRecord::Base
|
17
|
-
has_many :ships
|
18
|
-
end
|
19
|
-
|
20
|
-
class Ship < ActiveRecord::Base
|
21
|
-
belongs_to :fleet
|
22
|
-
end
|
23
|
-
|
24
|
-
# Save includes =============================================================
|
25
|
-
|
26
|
-
test '#save new record includes new belongs_to associations' do
|
27
|
-
ship = Ship.new(name: 'Definant', fleet: Fleet.new(name: 'Armada Duo'))
|
28
|
-
|
29
|
-
req_stub = webmock(:post, '/ships', {include: :fleet}).with(
|
30
|
-
body: {
|
31
|
-
ship: { name: 'Definant', fleet_attributes: { name: 'Armada Duo' } }
|
32
|
-
}.to_json
|
33
|
-
).to_return(
|
34
|
-
body: {
|
35
|
-
id: 2,
|
36
|
-
fleet_id: 3,
|
37
|
-
name: 'Definant 001',
|
38
|
-
fleet: { id: 3, name: 'Armada 2' }
|
39
|
-
}.to_json
|
40
|
-
)
|
41
|
-
|
42
|
-
assert ship.save
|
43
|
-
assert_equal 2, ship.id
|
44
|
-
assert_equal 3, ship.fleet_id
|
45
|
-
assert_equal 3, ship.fleet.id
|
46
|
-
assert_equal 'Definant 001', ship.name
|
47
|
-
assert_equal 'Armada 2', ship.fleet.name
|
48
|
-
|
49
|
-
assert_requested req_stub
|
50
|
-
end
|
51
|
-
|
52
|
-
test '#save new record doesnt include persisted/unmodified belongs_to associations' do
|
53
|
-
webmock(:get, "/fleets", where: {id: 1}, limit: 1).to_return(
|
54
|
-
body: [{id: 1, name: 'Armada Original'}].to_json
|
55
|
-
)
|
56
|
-
|
57
|
-
fleet = Fleet.find(1)
|
58
|
-
ship = Ship.new(name: 'Definant', fleet: fleet)
|
59
|
-
|
60
|
-
req_stub = webmock(:post, '/ships').with(
|
61
|
-
body: {
|
62
|
-
ship: { name: 'Definant', fleet_id: 1 }
|
63
|
-
}.to_json
|
64
|
-
).to_return(
|
65
|
-
body: {
|
66
|
-
id: 2,
|
67
|
-
fleet_id: 1,
|
68
|
-
name: 'Definant 001'
|
69
|
-
}.to_json
|
70
|
-
)
|
71
|
-
|
72
|
-
assert ship.save
|
73
|
-
assert_equal 2, ship.id
|
74
|
-
assert_equal 1, ship.fleet_id
|
75
|
-
|
76
|
-
assert_requested req_stub
|
77
|
-
end
|
78
|
-
|
79
|
-
test '#save persisted record includes new belongs_to associations' do
|
80
|
-
webmock(:get, "/ships", where: {id: 1}, limit: 1).to_return(
|
81
|
-
body: [{id: 1, fleet_id: nil, name: 'Ship Uno'}].to_json
|
82
|
-
)
|
83
|
-
|
84
|
-
req_stub = webmock(:patch, '/ships/1', {include: :fleet}).with(
|
85
|
-
body: {
|
86
|
-
ship: { fleet_attributes: { name: 'Armada Duo' } }
|
87
|
-
}.to_json
|
88
|
-
).to_return(
|
89
|
-
body: {
|
90
|
-
id: 1, fleet_id: 2, name: 'Ship Uno',
|
91
|
-
fleet: { id: 2, name: 'Armada Duo' }
|
92
|
-
}.to_json
|
93
|
-
)
|
94
|
-
|
95
|
-
ship = Ship.find(1)
|
96
|
-
ship.fleet = Fleet.new(name: 'Armada Duo')
|
97
|
-
|
98
|
-
ship.save
|
99
|
-
|
100
|
-
assert_requested req_stub
|
101
|
-
end
|
102
|
-
|
103
|
-
test '#save persisted record doesnt include persisted/unmodified belongs_to associations but updates belongs_to key' do
|
104
|
-
webmock(:get, "/ships", where: {id: 1}, limit: 1).to_return(
|
105
|
-
body: [{id: 1, fleet_id: nil, name: 'Ship Uno'}].to_json
|
106
|
-
)
|
107
|
-
webmock(:get, "/fleets", where: {id: 1}, limit: 1).to_return(
|
108
|
-
body: [{id: 1, name: 'Armada Original'}].to_json
|
109
|
-
)
|
110
|
-
|
111
|
-
fleet = Fleet.find(1)
|
112
|
-
ship = Ship.find(1)
|
113
|
-
|
114
|
-
req_stub = webmock(:patch, '/ships/1').with(
|
115
|
-
body: {
|
116
|
-
ship: { fleet_id: 1 }
|
117
|
-
}.to_json
|
118
|
-
).to_return(
|
119
|
-
body: {
|
120
|
-
id: 1,
|
121
|
-
fleet_id: 1,
|
122
|
-
name: 'My Ship'
|
123
|
-
}.to_json
|
124
|
-
)
|
125
|
-
|
126
|
-
ship.fleet = fleet
|
127
|
-
assert ship.save
|
128
|
-
assert_equal 1, ship.id
|
129
|
-
assert_equal 1, ship.fleet_id
|
130
|
-
assert_equal 'My Ship', ship.name
|
131
|
-
|
132
|
-
assert_requested req_stub
|
133
|
-
end
|
134
|
-
|
135
|
-
test '#save persisted record doesnt include loaded belongs_to association' do
|
136
|
-
webmock(:get, "/ships", where: {id: 1}, limit: 1, include: [:fleet]).to_return(
|
137
|
-
body: [{id: 1, fleet_id: 1, name: 'Ship Uno', fleet: {id: 1, name: 'Armada Original'}}].to_json
|
138
|
-
)
|
139
|
-
|
140
|
-
ship = Ship.eager_load(:fleet).find(1)
|
141
|
-
|
142
|
-
req_stub = webmock(:patch, '/ships/1').with(
|
143
|
-
body: {
|
144
|
-
ship: { name: 'New NAME!!' }
|
145
|
-
}.to_json
|
146
|
-
).to_return(
|
147
|
-
body: {
|
148
|
-
id: 1,
|
149
|
-
fleet_id: 1,
|
150
|
-
name: 'New NAME!!'
|
151
|
-
}.to_json
|
152
|
-
)
|
153
|
-
|
154
|
-
|
155
|
-
assert ship.association(:fleet).loaded?
|
156
|
-
ship.name = 'New NAME!!'
|
157
|
-
assert ship.save
|
158
|
-
|
159
|
-
assert_requested req_stub
|
160
|
-
end
|
161
|
-
|
162
|
-
end
|