sunstone 6.1.0.2 → 6.1.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (36) hide show
  1. checksums.yaml +4 -4
  2. data/ext/active_record/finder_methods.rb +2 -1
  3. data/lib/active_record/connection_adapters/sunstone/column.rb +1 -1
  4. data/lib/sunstone/version.rb +1 -1
  5. metadata +18 -58
  6. data/.github/workflows/main.yml +0 -141
  7. data/.gitignore +0 -31
  8. data/.tm_properties +0 -1
  9. data/Gemfile +0 -4
  10. data/README.md +0 -46
  11. data/Rakefile +0 -37
  12. data/TODO.md +0 -89
  13. data/sunstone.gemspec +0 -40
  14. data/test/active_record/associations/belongs_to_test.rb +0 -162
  15. data/test/active_record/associations/has_and_belongs_to_many_test.rb +0 -125
  16. data/test/active_record/associations/has_many_test.rb +0 -244
  17. data/test/active_record/eager_loading_test.rb +0 -62
  18. data/test/active_record/persistance_test.rb +0 -184
  19. data/test/active_record/preload_test.rb +0 -51
  20. data/test/active_record/query/all_test.rb +0 -33
  21. data/test/active_record/query/count_test.rb +0 -51
  22. data/test/active_record/query/distinct_test.rb +0 -30
  23. data/test/active_record/query/find_test.rb +0 -37
  24. data/test/active_record/query/limit_test.rb +0 -19
  25. data/test/active_record/query/order_test.rb +0 -27
  26. data/test/active_record/query/where_test.rb +0 -79
  27. data/test/active_record/query_test.rb +0 -131
  28. data/test/active_record/rpc_test.rb +0 -30
  29. data/test/schema_mock.rb +0 -121
  30. data/test/sunstone/connection/column_definition_test.rb +0 -30
  31. data/test/sunstone/connection/configuration_test.rb +0 -44
  32. data/test/sunstone/connection/cookie_store_test.rb +0 -37
  33. data/test/sunstone/connection/request_helper_test.rb +0 -105
  34. data/test/sunstone/connection/send_request_test.rb +0 -164
  35. data/test/sunstone/connection_test.rb +0 -23
  36. data/test/test_helper.rb +0 -153
data/sunstone.gemspec DELETED
@@ -1,40 +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.1.0'
34
-
35
- # Runtime
36
- s.add_runtime_dependency 'msgpack'
37
- s.add_runtime_dependency 'cookie_store'
38
- s.add_runtime_dependency 'activerecord', '>= 6.1.0'
39
- s.add_runtime_dependency 'arel-extensions', '>= 6.1.0'
40
- 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
@@ -1,125 +0,0 @@
1
- require 'test_helper'
2
-
3
- class ActiveRecord::Associations::HasAndBelongsToManyTest < ActiveSupport::TestCase
4
-
5
- schema do
6
- create_table "ships" do |t|
7
- t.string "name", limit: 255
8
- end
9
-
10
- create_table "sailors" do |t|
11
- t.string "name", limit: 255
12
- end
13
-
14
- create_table "sailors_ships", id: false do |t|
15
- t.integer "ship_id", null: false
16
- t.integer "sailor_id", null: false
17
- end
18
- end
19
-
20
- class Ship < ActiveRecord::Base
21
- has_and_belongs_to_many :sailors
22
- end
23
-
24
- class Sailor < ActiveRecord::Base
25
- has_and_belongs_to_many :ships
26
- end
27
-
28
- test '#relation_ids' do
29
- webmock(:get, "/ships", where: {id: 42}, limit: 1).to_return(body: [{id: 42, name: "The Niña"}].to_json)
30
- webmock(:get, "/sailors", where: {sailors_ships: {ship_id: {eq: 42}}}).to_return(body: [{id: 43, name: "Chris"}].to_json)
31
-
32
- assert_equal [43], Ship.find(42).sailor_ids
33
- end
34
-
35
- test '#update habtm relationships' do
36
- webmock(:get, "/ships", where: {id: 1}, limit: 1).to_return(
37
- body: [{id: 1, fleet_id: nil, name: 'Armada Uno'}].to_json
38
- )
39
- webmock(:get, "/sailors", where: {id: 1}, limit: 1).to_return(
40
- body: [{id: 1, name: 'Captain'}].to_json
41
- )
42
- webmock(:get, "/sailors", where: {sailors_ships: {ship_id: {eq: 1}}}).to_return(
43
- body: [].to_json
44
- )
45
- req_stub = webmock(:patch, '/ships/1').with(
46
- body: {ship: {sailors_attributes: [{id: 1}]}}.to_json
47
- ).to_return(
48
- body: {id: 1, name: 'Armada Uno'}.to_json
49
- )
50
-
51
- ship = Ship.find(1)
52
- assert ship.update(sailors: [Sailor.find(1)])
53
- assert_requested req_stub
54
- end
55
-
56
- test '#update clears habtm relationship' do
57
- webmock(:get, "/ships", where: {id: 1}, limit: 1).to_return(
58
- body: [{id: 1, fleet_id: nil, name: 'Armada Uno'}].to_json
59
- )
60
- webmock(:get, "/sailors", where: {id: 1}, limit: 1).to_return(
61
- body: [{id: 1, name: 'Captain'}].to_json
62
- )
63
- webmock(:get, "/sailors", where: {sailors_ships: {ship_id: {eq: 1}}}).to_return(
64
- body: [{id: 1, name: 'Captain'}].to_json
65
- )
66
- req_stub = webmock(:patch, '/ships/1').with(
67
- body: {ship: {sailors_attributes: []}}.to_json
68
- ).to_return(
69
- body: {id: 1, name: 'Armada Uno'}.to_json
70
- )
71
-
72
- ship = Ship.find(1)
73
- assert ship.update(sailors: [])
74
- assert_requested req_stub
75
- end
76
-
77
- test '#save persisted record doesnt include loaded habtm association' do
78
- webmock(:get, "/ships", where: {id: 1}, limit: 1).to_return(
79
- body: [{id: 1, name: 'Armada Uno'}].to_json
80
- )
81
- webmock(:get, "/sailors", where: {id: 1}, limit: 1).to_return(
82
- body: [{id: 1, name: 'Captain'}].to_json
83
- )
84
- webmock(:get, "/sailors", where: {sailors_ships: {ship_id: {eq: 1}}}).to_return(
85
- body: [{id: 1, name: 'Captain'}].to_json
86
- )
87
-
88
- ship = Ship.find(1)
89
-
90
-
91
- req_stub = webmock(:patch, '/ships/1').with(
92
- body: {
93
- ship: { name: 'New NAME!!' }
94
- }.to_json
95
- ).to_return(
96
- body: {
97
- id: 1,
98
- name: 'New NAME!!'
99
- }.to_json
100
- )
101
-
102
- ship.sailors.load
103
- assert ship.sailors.loaded?
104
- ship.name = 'New NAME!!'
105
- assert ship.save
106
-
107
- assert_requested req_stub
108
- end
109
-
110
-
111
- test "#destroy with habtm relationship" do
112
- webmock(:get, "/ships", where: {id: 1}, limit: 1).to_return(
113
- body: [{id: 1, fleet_id: nil, name: 'Armada Uno'}].to_json
114
- )
115
- req_stub = webmock(:delete, '/ships/1').to_return(
116
- status: 204
117
- )
118
-
119
- ship = Ship.find(1)
120
- assert ship.destroy
121
- assert_requested req_stub
122
- end
123
-
124
-
125
- end
@@ -1,244 +0,0 @@
1
- require 'test_helper'
2
-
3
- class ActiveRecord::Associations::HasManyTest < 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
- # ID Setters ================================================================
25
-
26
- test '#create with has_many_ids=' do
27
- webmock(:get, "/ships", where: {id: 2}).to_return(body: [{id: 2, fleet_id: nil, name: 'Duo'}].to_json)
28
- webmock(:post, "/fleets").with(
29
- body: {
30
- fleet: {
31
- name: 'Spanish Armada',
32
- ships_attributes: [{id: 2}]
33
- }
34
- }
35
- ).to_return(body: {id: 42, name: "Spanish Armada"}.to_json)
36
-
37
- Fleet.create(name: 'Spanish Armada', ship_ids: [2])
38
- end
39
-
40
-
41
- test '#update with has_many_ids=' do
42
- webmock(:get, "/fleets", where: {id: 42}, limit: 1).to_return(body: [{id: 42, name: "Spanish Armada"}].to_json)
43
- webmock(:get, "/ships", where: {id: 2}).to_return(body: [{id: 2, fleet_id: nil, name: 'Duo'}].to_json)
44
- webmock(:get, "/ships", where: {fleet_id: 42}).to_return(body: [].to_json)
45
-
46
- webmock(:patch, "/fleets/42").with(
47
- body: {
48
- fleet: {
49
- ships_attributes: [{id: 2}]
50
- }
51
- }).to_return(body: {id: 42, name: "Spanish Armada"}.to_json)
52
-
53
- Fleet.find(42).update(ship_ids: ["2"])
54
- end
55
-
56
- # Modifing relationship ====================================================
57
-
58
- test '#save persisted records includes has_many associations when new record added' do
59
- webmock(:get, '/fleets', where: {id: 1}, limit: 1, include: [:ships]).to_return({
60
- body: [{
61
- id: 1,
62
- name: 'Armada Trio',
63
- ships: [
64
- {id: 2, fleet_id: 1, name: 'Definant'}
65
- ]
66
- }].to_json
67
- })
68
-
69
- webmock(:get, '/ships', where: {id: 3}, limit: 1).to_return({
70
- body: [{id: 3, fleet_id: nil, name: 'Enterprise'}].to_json
71
- })
72
-
73
- req_stub = webmock(:patch, '/fleets/1').with(
74
- body: {
75
- fleet: {
76
- ships_attributes: [{ id: 2 }, {id: 3 }]
77
- }
78
- }.to_json
79
- ).to_return(
80
- body: {
81
- id: 1,
82
- name: 'Armada Trio',
83
- ships: [{ id: 2, fleet_id: 1, name: 'Voyager' }]
84
- }.to_json
85
- )
86
-
87
- # fleet.ships = [ship]
88
- fleet = Fleet.eager_load(:ships).find(1)
89
- fleet.update(ships: fleet.ships + [Ship.find(3)])
90
-
91
- assert_requested req_stub
92
- end
93
-
94
- test '#save persisted records includes has_many associations when replaced with new record' do
95
- webmock(:get, '/fleets', where: {id: 1}, limit: 1, include: [:ships]).to_return({
96
- body: [{
97
- id: 1,
98
- name: 'Armada Trio',
99
- ships: [
100
- {id: 2, fleet_id: 1, name: 'Definant'}
101
- ]
102
- }].to_json
103
- })
104
-
105
- req_stub = webmock(:patch, '/fleets/1').with(
106
- body: {
107
- fleet: {
108
- ships_attributes: [{ name: 'Voyager' }]
109
- }
110
- }.to_json
111
- ).to_return(
112
- body: {
113
- id: 1,
114
- name: 'Armada Trio',
115
- ships: [{ id: 3, fleet_id: 1, name: 'Voyager' }]
116
- }.to_json
117
- )
118
-
119
- fleet = Fleet.eager_load(:ships).find(1)
120
- assert fleet.update(ships: [Ship.new(name: 'Voyager')])
121
- assert_equal 1, fleet.id
122
- assert_equal [3], fleet.ships.map(&:id)
123
-
124
- assert_requested req_stub
125
- end
126
-
127
- test '#save persisted records includes has_many associations when updating record in relationship' do
128
- webmock(:get, '/fleets', where: {id: 1}, limit: 1, include: [:ships]).to_return({
129
- body: [{
130
- id: 1,
131
- name: 'Armada Trio',
132
- ships: [
133
- {id: 2, fleet_id: 1, name: 'Definant'}, {id: 3, fleet_id: 1, name: 'Enterprise'}
134
- ]
135
- }].to_json
136
- })
137
-
138
- req_stub = webmock(:patch, '/fleets/1').with(
139
- body: {
140
- fleet: {
141
- ships_attributes: [{ name: 'Voyager', id: 2 }, {id: 3}]
142
- }
143
- }.to_json
144
- ).to_return(
145
- body: {
146
- id: 1,
147
- name: 'Armada Trio',
148
- ships: [{ id: 2, fleet_id: 1, name: 'Voyager' }, {id: 3, fleet_id: 1, name: 'Enterprise'}]
149
- }.to_json
150
- )
151
-
152
- fleet = Fleet.eager_load(:ships).find(1)
153
- fleet.ships.first.name = 'Voyager'
154
- fleet.save
155
-
156
- assert_requested req_stub
157
- end
158
-
159
- test '#save persisted records doesnt include any loaded has_many associations' do
160
- webmock(:get, '/fleets', where: {id: 1}, limit: 1, include: [:ships]).to_return({
161
- body: [{
162
- id: 1,
163
- name: 'Armada Trio',
164
- ships: [
165
- {id: 2, fleet_id: 1, name: 'Definant'}, {id: 3, fleet_id: 1, name: 'Enterprise'}
166
- ]
167
- }].to_json
168
- })
169
-
170
- req_stub = webmock(:patch, '/fleets/1').with(
171
- body: { fleet: { name: 'New NAME!!' } }.to_json
172
- ).to_return(
173
- body: {
174
- id: 1,
175
- name: 'New NAME!!'
176
- }.to_json
177
- )
178
-
179
- # fleet.ships = [ship]
180
- fleet = Fleet.eager_load(:ships).find(1)
181
- assert fleet.ships.loaded?
182
- fleet.name = 'New NAME!!'
183
- fleet.save
184
-
185
- assert_requested req_stub
186
- end
187
-
188
- test '#update persisted record doesnt include any unchanged associations' do
189
- webmock(:get, '/fleets', where: {id: 1}, limit: 1, include: [:ships]).to_return({
190
- body: [{
191
- id: 1,
192
- name: 'Armada Trio',
193
- ships: [
194
- {id: 2, fleet_id: 1, name: 'Definant'}, {id: 3, fleet_id: 1, name: 'Enterprise'}
195
- ]
196
- }].to_json
197
- })
198
-
199
- req_stub = webmock(:patch, '/fleets/1').with(
200
- body: { fleet: { name: 'New NAME!!' } }.to_json
201
- ).to_return(
202
- body: {
203
- id: 1,
204
- name: 'New NAME!!'
205
- }.to_json
206
- )
207
-
208
- # fleet.ships = [ship]
209
- fleet = Fleet.eager_load(:ships).find(1)
210
- assert fleet.ships.loaded?
211
- #[{id: 2, fleet_id: 1, name: 'Definant'}, {id: 3, fleet_id: 1, name: 'Enterprise'}]
212
- fleet.update(name: 'New NAME!!', ships: fleet.ships)
213
- fleet.save
214
-
215
- assert_requested req_stub
216
- end
217
-
218
- # Clearing the relationship =================================================
219
-
220
- test '#update clears has_many relationship' do
221
- webmock(:get, "/fleets", where: {id: 1}, limit: 1).to_return(
222
- body: [{id: 1, name: 'Armada Uno'}].to_json
223
- )
224
- webmock(:get, "/ships", where: {fleet_id: 1}).to_return(
225
- body: [{id: 1, name: 'Saucer Trio'}].to_json
226
- )
227
- req_stub = webmock(:patch, '/fleets/1').with(
228
- body: {fleet: {ships_attributes: []}}.to_json
229
- ).to_return(
230
- body: {id: 1, name: 'Armada Uno'}.to_json
231
- )
232
-
233
- fleet = Fleet.find(1)
234
- assert fleet.update(ships: [])
235
- assert_requested req_stub
236
- end
237
-
238
-
239
- # test 'relation#delete_all' do
240
- # webmock(:get, "/fleets", where: {id: 42}, limit: 1).to_return(body: [{id: 42, name: "Spanish Armada"}].to_json)
241
- # Fleet.find(42).ships.delete_all
242
- # end
243
-
244
- end