sunstone 6.0.0.5 → 6.1.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. checksums.yaml +4 -4
  2. data/ext/active_record/associations.rb +2 -2
  3. data/ext/active_record/attribute_methods.rb +2 -2
  4. data/ext/active_record/callbacks.rb +1 -1
  5. data/ext/active_record/finder_methods.rb +42 -36
  6. data/ext/active_record/persistence.rb +2 -0
  7. data/ext/active_record/relation/calculations.rb +2 -2
  8. data/ext/active_record/statement_cache.rb +9 -5
  9. data/ext/active_record/transactions.rb +8 -15
  10. data/ext/arel/attributes/empty_relation.rb +31 -31
  11. data/ext/arel/nodes/select_statement.rb +1 -1
  12. data/lib/active_record/connection_adapters/sunstone/column.rb +3 -3
  13. data/lib/active_record/connection_adapters/sunstone/database_statements.rb +5 -5
  14. data/lib/active_record/connection_adapters/sunstone/schema_statements.rb +18 -8
  15. data/lib/active_record/connection_adapters/sunstone/type/binary.rb +34 -0
  16. data/lib/active_record/connection_adapters/sunstone_adapter.rb +39 -26
  17. data/lib/arel/visitors/sunstone.rb +13 -15
  18. data/lib/sunstone.rb +16 -2
  19. data/lib/sunstone/connection.rb +1 -1
  20. data/lib/sunstone/version.rb +1 -1
  21. metadata +40 -64
  22. data/.gitignore +0 -31
  23. data/.tm_properties +0 -1
  24. data/.travis.yml +0 -49
  25. data/Gemfile +0 -4
  26. data/README.md +0 -10
  27. data/Rakefile +0 -37
  28. data/TODO.md +0 -89
  29. data/ext/arel/attributes/relation.rb +0 -31
  30. data/sunstone.gemspec +0 -39
  31. data/test/active_record/associations/belongs_to_test.rb +0 -162
  32. data/test/active_record/associations/has_and_belongs_to_many_test.rb +0 -125
  33. data/test/active_record/associations/has_many_test.rb +0 -244
  34. data/test/active_record/eager_loading_test.rb +0 -62
  35. data/test/active_record/persistance_test.rb +0 -159
  36. data/test/active_record/preload_test.rb +0 -51
  37. data/test/active_record/query/all_test.rb +0 -33
  38. data/test/active_record/query/count_test.rb +0 -51
  39. data/test/active_record/query/distinct_test.rb +0 -30
  40. data/test/active_record/query/find_test.rb +0 -37
  41. data/test/active_record/query/limit_test.rb +0 -19
  42. data/test/active_record/query/order_test.rb +0 -27
  43. data/test/active_record/query/where_test.rb +0 -79
  44. data/test/active_record/query_test.rb +0 -123
  45. data/test/active_record/rpc_test.rb +0 -30
  46. data/test/schema_mock.rb +0 -117
  47. data/test/sunstone/connection/configuration_test.rb +0 -44
  48. data/test/sunstone/connection/cookie_store_test.rb +0 -37
  49. data/test/sunstone/connection/request_helper_test.rb +0 -105
  50. data/test/sunstone/connection/send_request_test.rb +0 -164
  51. data/test/sunstone/connection_test.rb +0 -23
  52. data/test/test_helper.rb +0 -152
@@ -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,159 +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
- 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
- class TestModelA < ActiveRecord::Base
41
- end
42
-
43
- class TestModelB < ActiveRecord::Base
44
- before_save do
45
- TestModelA.create
46
- end
47
- end
48
-
49
- test '#create with errors' do
50
- req_stub = webmock(:post, "/fleets").with(
51
- body: { fleet: {} }.to_json
52
- ).to_return(
53
- status: 400,
54
- body: {name: 'Armada Uno', errors: {name: 'is required'}}.to_json
55
- )
56
-
57
- fleet = Fleet.create()
58
- assert_equal ["is required"], fleet.errors[:name]
59
- assert_requested req_stub
60
- end
61
-
62
- test '#create' do
63
- req_stub = webmock(:post, "/fleets").with(
64
- body: { fleet: {name: 'Armada Uno'} }.to_json
65
- ).to_return(
66
- body: {id: 1, name: 'Armada Uno'}.to_json
67
- )
68
-
69
- Fleet.create(name: 'Armada Uno')
70
-
71
- assert_requested req_stub
72
- end
73
-
74
- test '#save w/o changes' do
75
- webmock(:get, '/fleets', where: {id: 1}, limit: 1).to_return(
76
- body: [{id: 1, name: 'Armada Duo'}].to_json
77
- )
78
-
79
- fleet = Fleet.find(1)
80
- fleet.save
81
-
82
- assert fleet.save
83
- assert_equal 1, fleet.id
84
- assert_equal 'Armada Duo', fleet.name
85
- end
86
-
87
- test '#save attempts another request while in transaction' do
88
- webmock(:get, '/test_model_bs/schema').to_return(
89
- body: {
90
- columns: {
91
- id: {type: 'integer', primary_key: true, null: false, array: false},
92
- name: {type: 'string', primary_key: false, null: true, array: false}
93
- }
94
- }.to_json,
95
- headers: { 'StandardAPI-Version' => '5.0.0.5' }
96
- )
97
- webmock(:get, '/test_model_as/schema').to_return(
98
- body: {
99
- columns: {
100
- id: {type: 'integer', primary_key: true, null: false, array: false},
101
- name: {type: 'string', primary_key: false, null: true, array: false}
102
- }
103
- }.to_json,
104
- headers: { 'StandardAPI-Version' => '5.0.0.5' }
105
- )
106
-
107
- assert_raises ActiveRecord::StatementInvalid do
108
- TestModelB.create
109
- end
110
- end
111
-
112
-
113
-
114
- test '#update clears belongs_to relationship' do
115
- webmock(:get, "/ships", where: {id: 1}, limit: 1).to_return(
116
- body: [{id: 1, fleet_id: 1, name: 'Armada Uno'}].to_json
117
- )
118
- req_stub = webmock(:patch, '/ships/1').with(
119
- body: {ship: {fleet_id: nil}}.to_json
120
- ).to_return(
121
- body: {id: 1, name: 'Armada Uno'}.to_json
122
- )
123
-
124
- ship = Ship.find(1)
125
- assert ship.update(fleet: nil)
126
- assert_requested req_stub
127
- end
128
-
129
- test '#update' do
130
- webmock(:get, "/ships", where: {id: 1}, limit: 1).to_return(
131
- body: [{id: 1, fleet_id: nil, name: 'Armada Uno'}].to_json
132
- )
133
- req_stub = webmock(:patch, "/ships").with(
134
- body: { ship: { name: 'Armada Trio' } }.to_json
135
- ).to_return(
136
- body: {id: 1, name: 'Armada Trio'}.to_json
137
- )
138
-
139
- Ship.find(1).update(name: 'Armada Trio')
140
-
141
- assert_requested req_stub
142
- end
143
-
144
- test '#update!' do
145
- webmock(:get, "/ships", where: {id: 1}, limit: 1).to_return(
146
- body: [{id: 1, fleet_id: nil, name: 'Armada Uno'}].to_json
147
- )
148
- req_stub = webmock(:patch, "/ships").with(
149
- body: { ship: { name: 'Armada Trio' } }.to_json
150
- ).to_return(
151
- body: {id: 1, name: 'Armada Trio'}.to_json
152
- )
153
-
154
- Ship.find(1).update!(name: 'Armada Trio')
155
-
156
- assert_requested req_stub
157
- end
158
-
159
- end