sunstone 6.1.0.2 → 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/finder_methods.rb +2 -1
- data/lib/active_record/connection_adapters/sunstone/column.rb +1 -1
- data/lib/sunstone/version.rb +1 -1
- metadata +18 -58
- data/.github/workflows/main.yml +0 -141
- data/.gitignore +0 -31
- data/.tm_properties +0 -1
- data/Gemfile +0 -4
- data/README.md +0 -46
- data/Rakefile +0 -37
- data/TODO.md +0 -89
- data/sunstone.gemspec +0 -40
- 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 -184
- 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 -131
- data/test/active_record/rpc_test.rb +0 -30
- data/test/schema_mock.rb +0 -121
- data/test/sunstone/connection/column_definition_test.rb +0 -30
- 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 -153
@@ -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
|
@@ -1,51 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class ActiveRecord::QueryCountTest < ActiveSupport::TestCase
|
4
|
-
|
5
|
-
schema do
|
6
|
-
create_table "ships", limit: 100 do |t|
|
7
|
-
t.string "name", limit: 255
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
class Fleet < ActiveRecord::Base
|
12
|
-
has_many :ships
|
13
|
-
end
|
14
|
-
|
15
|
-
class Ship < ActiveRecord::Base
|
16
|
-
belongs_to :fleet
|
17
|
-
end
|
18
|
-
|
19
|
-
test '::count' do
|
20
|
-
webmock(:get, "/ships/calculate", select: [{count: "*"}], limit: 100, offset: 0).to_return({
|
21
|
-
body: [10].to_json
|
22
|
-
})
|
23
|
-
|
24
|
-
assert_equal 10, Ship.count
|
25
|
-
end
|
26
|
-
|
27
|
-
test '::count(:column)' do
|
28
|
-
webmock(:get, "/ships/calculate", select: [{count: "id"}], limit: 100, offset: 0).to_return({
|
29
|
-
body: [10].to_json
|
30
|
-
})
|
31
|
-
|
32
|
-
assert_equal 10, Ship.count(:id)
|
33
|
-
end
|
34
|
-
|
35
|
-
test '::count with eager_load' do
|
36
|
-
webmock(:get, "/ships/calculate", select: [{count: "id"}], limit: 100, offset: 0).to_return({
|
37
|
-
body: [10].to_json
|
38
|
-
})
|
39
|
-
|
40
|
-
assert_equal 10, Ship.eager_load(:fleet).count
|
41
|
-
end
|
42
|
-
|
43
|
-
test '::sum(:column)' do
|
44
|
-
webmock(:get, "/ships/calculate", select: [{sum: "weight"}], limit: 100, offset: 0).to_return({
|
45
|
-
body: [10].to_json
|
46
|
-
})
|
47
|
-
|
48
|
-
assert_equal 10, Ship.sum(:weight)
|
49
|
-
end
|
50
|
-
|
51
|
-
end
|
@@ -1,30 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class ActiveRecord::QueryDistinctTest < ActiveSupport::TestCase
|
4
|
-
|
5
|
-
schema do
|
6
|
-
create_table "ships", limit: 100 do |t|
|
7
|
-
t.string "name", limit: 255
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
class Ship < ActiveRecord::Base
|
12
|
-
end
|
13
|
-
|
14
|
-
# Distinct
|
15
|
-
test '::distinct query' do
|
16
|
-
webmock(:get, "/ships", distinct: true, limit: 100, offset: 0).to_return({
|
17
|
-
body: [].to_json
|
18
|
-
})
|
19
|
-
|
20
|
-
assert_equal [], Ship.distinct
|
21
|
-
end
|
22
|
-
|
23
|
-
# TODO: i need arel-extensions....
|
24
|
-
# test '::distinct_on query' do
|
25
|
-
# webmock(:get, "/ships", distinct_on: ['id']).to_return(body: [].to_json)
|
26
|
-
#
|
27
|
-
# assert_equal [], Ship.distinct_on(:id)
|
28
|
-
# end
|
29
|
-
|
30
|
-
end
|
@@ -1,37 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class ActiveRecord::QueryFindTest < ActiveSupport::TestCase
|
4
|
-
|
5
|
-
schema do
|
6
|
-
create_table "ships", limit: 100 do |t|
|
7
|
-
t.string "name", limit: 255
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
class Ship < ActiveRecord::Base
|
12
|
-
end
|
13
|
-
|
14
|
-
test '::find' do
|
15
|
-
webmock(:get, "/ships", { where: {id: 42}, limit: 1 }).to_return({
|
16
|
-
body: [{id: 42}].to_json
|
17
|
-
})
|
18
|
-
|
19
|
-
assert_equal 42, Ship.find(42).id
|
20
|
-
end
|
21
|
-
|
22
|
-
test '::find_each' do
|
23
|
-
requests = []
|
24
|
-
|
25
|
-
requests << webmock(:get, "/ships", { limit: 100, offset: 0, order: [{id: :asc}] }).to_return({
|
26
|
-
body: Array.new(100, { id: 1 }).to_json
|
27
|
-
})
|
28
|
-
requests << webmock(:get, "/ships", { limit: 100, offset: 100, order: [{id: :asc}] }).to_return({
|
29
|
-
body: Array.new(10, { id: 2 }).to_json
|
30
|
-
})
|
31
|
-
|
32
|
-
assert_nil Ship.find_each { |s| s }
|
33
|
-
|
34
|
-
requests.each { |r| assert_requested(r) }
|
35
|
-
end
|
36
|
-
|
37
|
-
end
|