sunstone 6.1.0.2 → 7.0.0

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.
Files changed (49) hide show
  1. checksums.yaml +4 -4
  2. data/ext/active_record/associations/collection_association.rb +1 -1
  3. data/ext/active_record/attribute_methods.rb +7 -1
  4. data/ext/active_record/finder_methods.rb +14 -13
  5. data/ext/active_record/persistence.rb +6 -3
  6. data/ext/active_record/relation/calculations.rb +11 -4
  7. data/ext/active_record/relation/query_methods.rb +1 -1
  8. data/ext/active_record/statement_cache.rb +0 -1
  9. data/ext/arel/nodes/select_statement.rb +3 -3
  10. data/lib/active_record/connection_adapters/sunstone/column.rb +1 -1
  11. data/lib/active_record/connection_adapters/sunstone/database_statements.rb +8 -9
  12. data/lib/active_record/connection_adapters/sunstone/schema_statements.rb +31 -14
  13. data/lib/active_record/connection_adapters/sunstone_adapter.rb +17 -7
  14. data/lib/arel/collectors/sunstone.rb +25 -4
  15. data/lib/arel/visitors/sunstone.rb +21 -26
  16. data/lib/sunstone/connection.rb +40 -13
  17. data/lib/sunstone/version.rb +1 -1
  18. metadata +21 -61
  19. data/.github/workflows/main.yml +0 -141
  20. data/.gitignore +0 -31
  21. data/.tm_properties +0 -1
  22. data/Gemfile +0 -4
  23. data/README.md +0 -46
  24. data/Rakefile +0 -37
  25. data/TODO.md +0 -89
  26. data/sunstone.gemspec +0 -40
  27. data/test/active_record/associations/belongs_to_test.rb +0 -162
  28. data/test/active_record/associations/has_and_belongs_to_many_test.rb +0 -125
  29. data/test/active_record/associations/has_many_test.rb +0 -244
  30. data/test/active_record/eager_loading_test.rb +0 -62
  31. data/test/active_record/persistance_test.rb +0 -184
  32. data/test/active_record/preload_test.rb +0 -51
  33. data/test/active_record/query/all_test.rb +0 -33
  34. data/test/active_record/query/count_test.rb +0 -51
  35. data/test/active_record/query/distinct_test.rb +0 -30
  36. data/test/active_record/query/find_test.rb +0 -37
  37. data/test/active_record/query/limit_test.rb +0 -19
  38. data/test/active_record/query/order_test.rb +0 -27
  39. data/test/active_record/query/where_test.rb +0 -79
  40. data/test/active_record/query_test.rb +0 -131
  41. data/test/active_record/rpc_test.rb +0 -30
  42. data/test/schema_mock.rb +0 -121
  43. data/test/sunstone/connection/column_definition_test.rb +0 -30
  44. data/test/sunstone/connection/configuration_test.rb +0 -44
  45. data/test/sunstone/connection/cookie_store_test.rb +0 -37
  46. data/test/sunstone/connection/request_helper_test.rb +0 -105
  47. data/test/sunstone/connection/send_request_test.rb +0 -164
  48. data/test/sunstone/connection_test.rb +0 -23
  49. data/test/test_helper.rb +0 -153
@@ -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
@@ -1,62 +0,0 @@
1
- require 'test_helper'
2
-
3
- class ActiveRecord::EagerLoadingTest < 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
-
15
- create_table "sailors" do |t|
16
- t.string "name", limit: 255
17
- end
18
-
19
- create_table "sailors_ships", id: false do |t|
20
- t.integer "ship_id", null: false
21
- t.integer "sailor_id", null: false
22
- end
23
-
24
- end
25
-
26
- class Fleet < ActiveRecord::Base
27
- has_many :ships
28
- end
29
-
30
- class Ship < ActiveRecord::Base
31
- belongs_to :fleet
32
-
33
- has_and_belongs_to_many :sailors
34
- end
35
-
36
- class Sailor < ActiveRecord::Base
37
- has_and_belongs_to_many :ships
38
- end
39
-
40
- test '#eager_load' do
41
- webmock(:get, "/fleets", include: [{:ships => :sailors}]).to_return(body: [{
42
- id: 1, ships: [{id: 1, fleet_id: 1}]
43
- }].to_json)
44
-
45
- fleets = Fleet.eager_load(ships: :sailors)
46
- assert_equal [1], fleets.map(&:id)
47
- assert_equal [1], fleets.first.ships.map(&:id)
48
- end
49
-
50
-
51
- test '#eager_loads' do
52
- skip
53
- assert_equal <<-SQL, Fleet.eager_load(ships: :sailors).limit(2).to_sql
54
- SELECT DISTINCT "fleets"."id"
55
- FROM "fleets"
56
- LEFT OUTER JOIN "ships" ON "ships"."fleet_id" = "fleets"."id"
57
- LEFT OUTER JOIN "sailors" ON "sailors"."ship_id" = "ships"."id"
58
- LIMIT 2
59
- SQL
60
- end
61
-
62
- end
@@ -1,184 +0,0 @@
1
- require 'test_helper'
2
-
3
- class ActiveRecord::PersistanceTest < 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
-
15
- create_table "sailors" do |t|
16
- t.string "name", limit: 255
17
- t.text "assignment"
18
- end
19
-
20
- create_table "sailors_ships", id: false do |t|
21
- t.integer "ship_id", null: false
22
- t.integer "sailor_id", null: false
23
- end
24
-
25
- end
26
-
27
- class Fleet < ActiveRecord::Base
28
- has_many :ships
29
- end
30
-
31
- class Ship < ActiveRecord::Base
32
- belongs_to :fleet
33
-
34
- has_and_belongs_to_many :sailors
35
- end
36
-
37
- class Sailor < ActiveRecord::Base
38
- has_and_belongs_to_many :ships
39
- end
40
-
41
- class TestModelA < ActiveRecord::Base
42
- end
43
-
44
- class TestModelB < ActiveRecord::Base
45
- before_save do
46
- TestModelA.create
47
- end
48
- end
49
-
50
- class TestModelC < ActiveRecord::Base
51
- end
52
-
53
- test '#create with errors' do
54
- req_stub = webmock(:post, "/fleets").with(
55
- body: { fleet: {} }.to_json
56
- ).to_return(
57
- status: 400,
58
- body: {name: 'Armada Uno', errors: {name: 'is required'}}.to_json
59
- )
60
-
61
- fleet = Fleet.create()
62
- assert_equal ["is required"], fleet.errors[:name]
63
- assert_requested req_stub
64
- end
65
-
66
- test '#create' do
67
- req_stub = webmock(:post, "/fleets").with(
68
- body: { fleet: {name: 'Armada Uno'} }.to_json
69
- ).to_return(
70
- body: {id: 1, name: 'Armada Uno'}.to_json
71
- )
72
-
73
- Fleet.create(name: 'Armada Uno')
74
-
75
- assert_requested req_stub
76
- end
77
-
78
- test '#save w/o changes does not trigger a request' do
79
- webmock(:get, '/fleets', where: {id: 1}, limit: 1).to_return(
80
- body: [{id: 1, name: 'Armada Duo'}].to_json
81
- )
82
-
83
- fleet = Fleet.find(1)
84
- fleet.save
85
-
86
- assert fleet.save
87
- assert_equal 1, fleet.id
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
101
- end
102
-
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
- )
113
- webmock(:get, '/test_model_bs/schema').to_return(
114
- body: {
115
- columns: {
116
- id: {type: 'integer', primary_key: true, null: false, array: false},
117
- name: {type: 'string', primary_key: false, null: true, array: false}
118
- }
119
- }.to_json,
120
- headers: { 'StandardAPI-Version' => '5.0.0.5' }
121
- )
122
- webmock(:get, '/test_model_as/schema').to_return(
123
- body: {
124
- columns: {
125
- id: {type: 'integer', primary_key: true, null: false, array: false},
126
- name: {type: 'string', primary_key: false, null: true, array: false}
127
- }
128
- }.to_json,
129
- headers: { 'StandardAPI-Version' => '5.0.0.5' }
130
- )
131
-
132
- assert_raises ActiveRecord::StatementInvalid do
133
- TestModelB.create
134
- end
135
- end
136
-
137
-
138
-
139
- test '#update clears belongs_to relationship' do
140
- webmock(:get, "/ships", where: {id: 1}, limit: 1).to_return(
141
- body: [{id: 1, fleet_id: 1, name: 'Armada Uno'}].to_json
142
- )
143
- req_stub = webmock(:patch, '/ships/1').with(
144
- body: {ship: {fleet_id: nil}}.to_json
145
- ).to_return(
146
- body: {id: 1, name: 'Armada Uno'}.to_json
147
- )
148
-
149
- ship = Ship.find(1)
150
- assert ship.update(fleet: nil)
151
- assert_requested req_stub
152
- end
153
-
154
- test '#update' do
155
- webmock(:get, "/ships", where: {id: 1}, limit: 1).to_return(
156
- body: [{id: 1, fleet_id: nil, name: 'Armada Uno'}].to_json
157
- )
158
- req_stub = webmock(:patch, "/ships").with(
159
- body: { ship: { name: 'Armada Trio' } }.to_json
160
- ).to_return(
161
- body: {id: 1, name: 'Armada Trio'}.to_json
162
- )
163
-
164
- Ship.find(1).update(name: 'Armada Trio')
165
-
166
- assert_requested req_stub
167
- end
168
-
169
- test '#update!' do
170
- webmock(:get, "/ships", where: {id: 1}, limit: 1).to_return(
171
- body: [{id: 1, fleet_id: nil, name: 'Armada Uno'}].to_json
172
- )
173
- req_stub = webmock(:patch, "/ships").with(
174
- body: { ship: { name: 'Armada Trio' } }.to_json
175
- ).to_return(
176
- body: {id: 1, name: 'Armada Trio'}.to_json
177
- )
178
-
179
- Ship.find(1).update!(name: 'Armada Trio')
180
-
181
- assert_requested req_stub
182
- end
183
-
184
- end
@@ -1,51 +0,0 @@
1
- require 'test_helper'
2
-
3
- class ActiveRecord::PreloadTest < 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
-
15
- create_table "sailors" do |t|
16
- t.string "name", limit: 255
17
- end
18
-
19
- create_table "sailors_ships", id: false do |t|
20
- t.integer "ship_id", null: false
21
- t.integer "sailor_id", null: false
22
- end
23
-
24
- end
25
-
26
- class Fleet < ActiveRecord::Base
27
- has_many :ships
28
- end
29
-
30
- class Ship < ActiveRecord::Base
31
- belongs_to :fleet
32
-
33
- has_and_belongs_to_many :sailors
34
- end
35
-
36
- class Sailor < ActiveRecord::Base
37
- has_and_belongs_to_many :ships
38
- end
39
-
40
- test '#preload' do
41
- webmock(:get, "/fleets").to_return(body: [{id: 1}].to_json)
42
- webmock(:get, "/ships", where: {fleet_id: 1}).to_return(body: [{id: 1, fleet_id: 1}].to_json)
43
- webmock(:get, "/sailors_ships", where: {ship_id: 1}).to_return(body: [{ship_id: 1, sailor_id: 1}].to_json)
44
- webmock(:get, "/sailors", where: {id: 1}).to_return(body: [{id: 1}].to_json)
45
-
46
- fleets = Fleet.preload(:ships => :sailors)
47
- assert_equal [1], fleets.map(&:id)
48
- assert_equal [1], fleets.first.ships.map(&:id)
49
- end
50
-
51
- end
@@ -1,33 +0,0 @@
1
- require 'test_helper'
2
-
3
- class ActiveRecord::QueryAllTest < ActiveSupport::TestCase
4
- schema do
5
- create_table "ships" do |t|
6
- t.string "name", limit: 255
7
- end
8
-
9
- create_table "cars", limit: 100 do |t|
10
- t.string "name", limit: 255
11
- end
12
- end
13
-
14
- class Ship < ActiveRecord::Base
15
- end
16
-
17
- class Car < ActiveRecord::Base
18
- end
19
-
20
- test '::all' do
21
- webmock(:get, "/ships").to_return(body: [{id: 42}].to_json)
22
- assert_equal [Ship.new(id: 42)], Ship.all
23
- end
24
-
25
- test '::all w/resource_limit' do
26
- cars = []
27
- 101.times { |i| cars << Car.new(id: i) }
28
- webmock(:get, "/cars", { limit: 100, offset: 0 }).to_return(body: cars[0..100].to_json)
29
- webmock(:get, "/cars", { limit: 100, offset: 100 }).to_return(body: cars[101..-1].to_json)
30
- assert_equal cars, Car.all
31
- end
32
-
33
- end