sunstone 6.1.0.1 → 6.1.0.2

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
  SHA256:
3
- metadata.gz: 70fcfa3e9252509421cfb640f2f0ea0294c37018f6b8a9feeaf4fcb2f9d75161
4
- data.tar.gz: 9dd9af70b45187707817193f5632302005e8e0ede8a8c146db6fae567c706e84
3
+ metadata.gz: 52f0e0a557ddc1ec6d7dcc9728d3cfbf602d8c467d1647571cb887b56755e3cc
4
+ data.tar.gz: 8db1bd8849700b80328ac2cf1248ff5260659d0afc49648e694fae33790c79cc
5
5
  SHA512:
6
- metadata.gz: ac6d53c45d04cf82a891aa9bf736f69492e76847a3748aeecdda6830da80ae04f43f4e9fd981467627d301726ac2459f4297200a57ce917f48b35dc2e8734101
7
- data.tar.gz: d7db042c9710800367267f124d7abc33814ce638409200a080e7c1e27e99e78b41cd84a22dbc160ec2d7c7f739df77cca0bec77b17d92b672c1ae9f69db5dc1b
6
+ metadata.gz: a656ce5545ac0ad4a3f660f61857e8068a9c1f59060d4e9f9f06b1d80d2f6daca73e3317e02b35669a100ea1f8c578695f8ca0cc3a9eb2f00fc908708c1d18ff
7
+ data.tar.gz: 3395da82c6d52adc2029570a459f98cb7311c428a3f92c9f598d61ae8f0b7c5c7a354bb4d88933a6096e2cd5271997f929535f9ad2a35cda2c066d59472dae72
@@ -0,0 +1,141 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches: [ master ]
6
+ pull_request:
7
+ branches: [ master ]
8
+
9
+ jobs:
10
+ sunstone:
11
+ name: Sunstone Test
12
+ runs-on: ubuntu-20.04
13
+
14
+ steps:
15
+ - uses: ruby/setup-ruby@v1
16
+ with:
17
+ ruby-version: 3.0
18
+
19
+ - uses: actions/checkout@v2
20
+
21
+ - run: bundle
22
+
23
+ - run: bundle exec rake test
24
+
25
+ ar-postgresql:
26
+ name: ActiveRecord PostgresQL Test
27
+ strategy:
28
+ matrix:
29
+ rails: [v6.1.3]
30
+
31
+ runs-on: ubuntu-20.04
32
+
33
+ steps:
34
+ - name: Install Postgresql
35
+ run: |
36
+ sudo apt-get install curl ca-certificates gnupg
37
+ curl https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
38
+ sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
39
+ sudo apt-get update
40
+ sudo apt-get install postgresql-13
41
+ sudo systemctl start postgresql@13-main.service
42
+ sudo -u postgres createuser runner --superuser
43
+
44
+ - uses: ruby/setup-ruby@v1
45
+ with:
46
+ ruby-version: 3.0
47
+
48
+ - uses: actions/checkout@v2
49
+
50
+ - name: Download Rails
51
+ run: |
52
+ git clone --branch ${{ matrix.rails }} https://github.com/rails/rails.git ~/rails
53
+ pushd ~/rails
54
+ cat /home/runner/work/_temp/*.sh
55
+ sed -i "s/Gem.ruby, '-w'/Gem.ruby, '-w0'/" ~/rails/activerecord/Rakefile
56
+ sed -i "s/t.warning = true/t.warning = false/g" ~/rails/activerecord/Rakefile
57
+ sed -i "/require 'support\/connection'/a \$LOAD_PATH.unshift\(File.expand_path\(ENV['GITHUB_WORKSPACE']\)\)\nrequire 'sunstone'" ~/rails/activerecord/test/cases/helper.rb
58
+ rm ~/rails/Gemfile.lock
59
+ sed -i "/# Active Record./a gem 'sunstone', path: File.expand_path\(ENV['GITHUB_WORKSPACE']\)" ~/rails/Gemfile
60
+ cat ~/rails/Gemfile
61
+ bundle update --jobs=3 --retry=3
62
+
63
+ - run: |
64
+ pushd ~/rails/activerecord
65
+ bundle exec rake db:postgresql:rebuild postgresql:test
66
+ bundle exec rake db:postgresql:rebuild postgresql:isolated_test
67
+
68
+ ar-sqlite:
69
+ name: ActiveRecord SQLite Test
70
+ strategy:
71
+ matrix:
72
+ rails: [v6.1.3]
73
+
74
+ runs-on: ubuntu-20.04
75
+
76
+ steps:
77
+ - uses: ruby/setup-ruby@v1
78
+ with:
79
+ ruby-version: 3.0
80
+
81
+ - uses: actions/checkout@v2
82
+
83
+ - name: Download Rails
84
+ run: |
85
+ git clone --branch ${{ matrix.rails }} https://github.com/rails/rails.git ~/rails
86
+ pushd ~/rails
87
+ cat /home/runner/work/_temp/*.sh
88
+ sed -i "s/Gem.ruby, '-w'/Gem.ruby, '-w0'/" ~/rails/activerecord/Rakefile
89
+ sed -i "s/t.warning = true/t.warning = false/g" ~/rails/activerecord/Rakefile
90
+ sed -i "/require 'support\/connection'/a \$LOAD_PATH.unshift\(File.expand_path\(ENV['GITHUB_WORKSPACE']\)\)\nrequire 'sunstone'" ~/rails/activerecord/test/cases/helper.rb
91
+ rm ~/rails/Gemfile.lock
92
+ sed -i "/# Active Record./a gem 'sunstone', path: File.expand_path\(ENV['GITHUB_WORKSPACE']\)" ~/rails/Gemfile
93
+ cat ~/rails/Gemfile
94
+ bundle update --jobs=3 --retry=3
95
+
96
+ - run: |
97
+ pushd ~/rails/activerecord
98
+ bundle exec rake sqlite3:test
99
+ rm test/db/*.sqlite3 test/fixtures/*.sqlite3
100
+ bundle exec rake sqlite3:isolated_test
101
+ rm test/db/*.sqlite3 test/fixtures/*.sqlite3
102
+ bundle exec rake sqlite3_mem:test
103
+
104
+ ar-mysql:
105
+ name: ActiveRecord MySQL Test
106
+ strategy:
107
+ matrix:
108
+ rails: [v6.1.3]
109
+
110
+ runs-on: ubuntu-20.04
111
+
112
+ steps:
113
+ - name: Install MySQL
114
+ run: |
115
+ sudo /etc/init.d/mysql start
116
+ mysql -uroot -proot -e "CREATE USER 'rails'@'%';"
117
+ mysql -uroot -proot -e "GRANT ALL PRIVILEGES ON *.* TO 'rails'@'%' WITH GRANT OPTION;"
118
+
119
+ - uses: ruby/setup-ruby@v1
120
+ with:
121
+ ruby-version: 3.0
122
+
123
+ - uses: actions/checkout@v2
124
+
125
+ - name: Download Rails
126
+ run: |
127
+ git clone --branch ${{ matrix.rails }} https://github.com/rails/rails.git ~/rails
128
+ pushd ~/rails
129
+ cat /home/runner/work/_temp/*.sh
130
+ sed -i "s/Gem.ruby, '-w'/Gem.ruby, '-w0'/" ~/rails/activerecord/Rakefile
131
+ sed -i "s/t.warning = true/t.warning = false/g" ~/rails/activerecord/Rakefile
132
+ sed -i "/require 'support\/connection'/a \$LOAD_PATH.unshift\(File.expand_path\(ENV['GITHUB_WORKSPACE']\)\)\nrequire 'sunstone'" ~/rails/activerecord/test/cases/helper.rb
133
+ rm ~/rails/Gemfile.lock
134
+ sed -i "/# Active Record./a gem 'sunstone', path: File.expand_path\(ENV['GITHUB_WORKSPACE']\)" ~/rails/Gemfile
135
+ cat ~/rails/Gemfile
136
+ bundle update --jobs=3 --retry=3
137
+
138
+ - run: |
139
+ pushd ~/rails/activerecord
140
+ bundle exec rake db:mysql:rebuild mysql2:test
141
+ bundle exec rake db:mysql:rebuild mysql2:isolated_test
data/README.md CHANGED
@@ -1,8 +1,44 @@
1
- # Sunstone [![Travis CI](https://travis-ci.org/malomalo/sunstone.svg)](https://travis-ci.org/malomalo/sunstone)
1
+ # Sunstone
2
2
 
3
- An [ActiveRecord](https://rubygems.org/gems/activerecord) adapter for quering
4
- APIs over Standard API (https://github.com/waratuman/standardapi).
3
+ Sunstone is an [ActiveRecord](https://rubygems.org/gems/activerecord) adapter for quering
4
+ APIs conforming to [Standard API](https://github.com/waratuman/standardapi).
5
5
 
6
+ Configuration
7
+ -------------
8
+
9
+ ### Rails
10
+
11
+ Add `sunstone` to your Gemfile:
12
+
13
+ ```ruby
14
+ gem 'sunstone'
15
+ ```
16
+
17
+ Update `config/database.yml`"
18
+
19
+ ```yaml
20
+ development:
21
+ adapter: sunstone
22
+ url: https://mystanda.rd/api
23
+ api_key: ..optional..
24
+ user_agent: ..optional..
25
+ ```
26
+
27
+ ### Standalone ActiveRecord
28
+
29
+ Initialize the connection on `ActiveRecord::Base` or your abstract model (`ApplicationRecord` for example)
30
+
31
+ ```ruby
32
+ ActiveRecord::Base.establish_connection(
33
+ adapter: 'sunstone',
34
+ url: 'https://mystanda.rd/api'
35
+ )
36
+ ```
37
+
38
+ Usage
39
+ -----
40
+
41
+ Mention fitler / etc...
6
42
 
7
43
  TODO:
8
44
  =====
@@ -2,30 +2,22 @@ module ActiveRecord
2
2
  module Calculations
3
3
 
4
4
  def pluck(*column_names)
5
- if loaded? && all_attributes?(column_names)
5
+ if loaded? && (column_names.map(&:to_s) - @klass.attribute_names - @klass.attribute_aliases.keys).empty?
6
6
  return records.pluck(*column_names)
7
7
  end
8
-
8
+
9
9
  if has_include?(column_names.first)
10
10
  relation = apply_join_dependency
11
11
  relation.pluck(*column_names)
12
12
  elsif klass.connection.is_a?(ActiveRecord::ConnectionAdapters::SunstoneAPIAdapter)
13
13
  load
14
- return records.pluck(*column_names.map{|n| n.sub(/^#{klass.table_name}\./, "")})
14
+ return records.pluck(*column_names.map{|n| n.to_s.sub(/^#{klass.table_name}\./, "")})
15
15
  else
16
16
  klass.disallow_raw_sql!(column_names)
17
- columns = arel_columns(column_names)
18
17
  relation = spawn
19
- relation.select_values = columns
20
-
21
- result = skip_query_cache_if_necessary do
22
- if where_clause.contradiction?
23
- ActiveRecord::Result.new([], [])
24
- else
25
- klass.connection.select_all(relation.arel, nil)
26
- end
27
- end
28
- type_cast_pluck_values(result, columns)
18
+ relation.select_values = column_names
19
+ result = skip_query_cache_if_necessary { klass.connection.select_all(relation.arel, nil) }
20
+ result.cast_values(klass.attribute_types)
29
21
  end
30
22
  end
31
23
 
@@ -703,6 +703,7 @@ module Arel
703
703
  {key => value}
704
704
  end
705
705
  end
706
+ alias_method :visit_Arel_Nodes_HomogeneousIn, :visit_Arel_Nodes_In
706
707
 
707
708
  def visit_Arel_Nodes_NotIn o, collector
708
709
  key = visit(o.left, collector)
data/lib/sunstone.rb CHANGED
@@ -41,6 +41,7 @@ require File.expand_path(File.join(__FILE__, '../../ext/active_record/finder_met
41
41
 
42
42
  if ActiveRecord::VERSION::MAJOR == 6 && ActiveRecord::VERSION::MINOR == 1
43
43
  # Patch to allow Rails 6.1 pass url to adapter, all other versions work
44
+ require 'active_record/database_configurations'
44
45
  class ActiveRecord::DatabaseConfigurations::UrlConfig
45
46
  private
46
47
  def build_url_hash
@@ -1,3 +1,3 @@
1
1
  module Sunstone
2
- VERSION = '6.1.0.1'
2
+ VERSION = '6.1.0.2'
3
3
  end
@@ -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/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.1.0.1
4
+ version: 6.1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jon Bracy
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-01-22 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
@@ -255,9 +255,9 @@ executables: []
255
255
  extensions: []
256
256
  extra_rdoc_files: []
257
257
  files:
258
+ - ".github/workflows/main.yml"
258
259
  - ".gitignore"
259
260
  - ".tm_properties"
260
- - ".travis.yml"
261
261
  - Gemfile
262
262
  - LICENSE
263
263
  - README.md
data/.travis.yml DELETED
@@ -1,68 +0,0 @@
1
- dist: bionic
2
- language: ruby
3
- sudo: false
4
-
5
- cache:
6
- bundler: true
7
- directories:
8
- - /home/travis/.rvm/gems
9
-
10
- rvm:
11
- - 2.7
12
- - 3.0
13
-
14
- env:
15
- matrix:
16
- - RAILS_VERSION=v6.1.0 TASK='db:mysql:rebuild mysql2:test'
17
- - RAILS_VERSION=v6.1.0 TASK='db:mysql:rebuild mysql2:isolated_test'
18
- - RAILS_VERSION=v6.1.0 TASK='db:postgresql:rebuild postgresql:test'
19
- - RAILS_VERSION=v6.1.0 TASK='db:postgresql:rebuild postgresql:isolated_test'
20
- - RAILS_VERSION=v6.1.0 TASK='sqlite3:test'
21
- - RAILS_VERSION=v6.1.0 TASK='sqlite3:isolated_test'
22
- - RAILS_VERSION=v6.1.0 TASK='sqlite3_mem:test'
23
-
24
- services:
25
- - mysql
26
- addons:
27
- postgresql: "13"
28
- apt:
29
- packages:
30
- - postgresql-13
31
- - postgresql-client-13
32
-
33
- before_install:
34
- - sudo sed -i 's/port = 5433/port = 5432/' /etc/postgresql/13/main/postgresql.conf
35
- - sudo cp /etc/postgresql/{9.3,13}/main/pg_hba.conf
36
- - sudo pg_ctlcluster 13 main restart
37
- - unset BUNDLE_GEMFILE
38
- - gem update --system
39
- - gem update bundler
40
- - gem install bundler --version 1.17.3
41
- - mysql -e "create user rails@localhost;"
42
- - mysql -e "grant all privileges on activerecord_unittest.* to rails@localhost;"
43
- - mysql -e "grant all privileges on activerecord_unittest2.* to rails@localhost;"
44
- - mysql -e "grant all privileges on inexistent_activerecord_unittest.* to rails@localhost;"
45
- - mysql -e "create database activerecord_unittest default character set utf8mb4;"
46
- - mysql -e "create database activerecord_unittest2 default character set utf8mb4;"
47
-
48
- install:
49
- - git clone --branch $RAILS_VERSION https://github.com/rails/rails.git ~/build/rails
50
-
51
- before_script:
52
- - sed -i "s/t.warning = true/t.warning = false/g" Rakefile
53
- - pushd ~/build/rails
54
- - git status
55
- - sed -i "s/Gem.ruby, '-w'/Gem.ruby, '-w0'/" ~/build/rails/activerecord/Rakefile
56
- - sed -i "s/t.warning = true/t.warning = false/g" ~/build/rails/activerecord/Rakefile
57
- - 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
58
- - cat ~/build/rails/Gemfile
59
- - rm ~/build/rails/Gemfile.lock
60
- - "sed -i \"/# Active Record./a gem 'sunstone', path: File.expand_path\\('~\\/build\\/malomalo\\/sunstone'\\)\" ~/build/rails/Gemfile"
61
- - cat ~/build/rails/Gemfile
62
- - bundle update --jobs=3 --retry=3
63
- - popd
64
- - bundle install --jobs=3 --retry=3
65
-
66
- script:
67
- - bundle exec rake test
68
- - cd ~/build/rails/activerecord && bundle exec rake $TASK