sunstone 6.0.0.5 → 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/associations.rb +2 -2
- data/ext/active_record/attribute_methods.rb +2 -2
- data/ext/active_record/callbacks.rb +1 -1
- data/ext/active_record/finder_methods.rb +42 -36
- data/ext/active_record/persistence.rb +2 -0
- data/ext/active_record/relation/calculations.rb +2 -2
- data/ext/active_record/statement_cache.rb +9 -5
- data/ext/active_record/transactions.rb +8 -15
- data/ext/arel/attributes/empty_relation.rb +31 -31
- data/ext/arel/nodes/select_statement.rb +1 -1
- data/lib/active_record/connection_adapters/sunstone/column.rb +3 -3
- data/lib/active_record/connection_adapters/sunstone/database_statements.rb +5 -5
- data/lib/active_record/connection_adapters/sunstone/schema_statements.rb +18 -8
- data/lib/active_record/connection_adapters/sunstone/type/binary.rb +34 -0
- data/lib/active_record/connection_adapters/sunstone_adapter.rb +39 -26
- data/lib/arel/visitors/sunstone.rb +13 -15
- data/lib/sunstone.rb +16 -2
- data/lib/sunstone/connection.rb +1 -1
- data/lib/sunstone/version.rb +1 -1
- metadata +40 -64
- data/.gitignore +0 -31
- data/.tm_properties +0 -1
- data/.travis.yml +0 -49
- data/Gemfile +0 -4
- data/README.md +0 -10
- data/Rakefile +0 -37
- data/TODO.md +0 -89
- data/ext/arel/attributes/relation.rb +0 -31
- data/sunstone.gemspec +0 -39
- 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 -159
- 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 -123
- data/test/active_record/rpc_test.rb +0 -30
- data/test/schema_mock.rb +0 -117
- 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 -152
|
@@ -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
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
require 'test_helper'
|
|
2
|
-
|
|
3
|
-
class ActiveRecord::LimitTest < ActiveSupport::TestCase
|
|
4
|
-
schema do
|
|
5
|
-
create_table "ships" do |t|
|
|
6
|
-
t.string "name", limit: 255
|
|
7
|
-
end
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
class Ship < ActiveRecord::Base
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
test '::limit' do
|
|
14
|
-
webmock(:get, "/ships", {limit: 5000}).to_return(body: [{id: 42}].to_json)
|
|
15
|
-
assert_equal Ship.limit(5000).map(&:id), [42]
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
end
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
require 'test_helper'
|
|
2
|
-
|
|
3
|
-
class ActiveRecord::OrderTest < 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 '::order(COLUMN)' do
|
|
15
|
-
webmock(:get, "/ships", { limit: 1, order: [{id: :asc}] }).to_return({
|
|
16
|
-
body: [{id: 42}].to_json
|
|
17
|
-
})
|
|
18
|
-
|
|
19
|
-
assert_equal 42, Ship.order(:id).first.id
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
# TODO: Uses Arel::Nodes::RandomOrdering from:
|
|
23
|
-
# https://github.com/malomalo/activerecord-sort
|
|
24
|
-
# which should probably go into arel-extensions?
|
|
25
|
-
test '::order(:random)'
|
|
26
|
-
|
|
27
|
-
end
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
require 'test_helper'
|
|
2
|
-
|
|
3
|
-
class ActiveRecord::QueryWhereTest < ActiveSupport::TestCase
|
|
4
|
-
|
|
5
|
-
schema do
|
|
6
|
-
create_table "ships", limit: 100 do |t|
|
|
7
|
-
t.string "name", limit: 255
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
create_table "fleets" do |t|
|
|
11
|
-
t.string "name", limit: 255
|
|
12
|
-
t.integer "fleet_id"
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
create_table "sailors" do |t|
|
|
16
|
-
t.string "name", limit: 255
|
|
17
|
-
t.integer "ship_id"
|
|
18
|
-
end
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
class Fleet < ActiveRecord::Base
|
|
22
|
-
has_many :ships
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
class Ship < ActiveRecord::Base
|
|
26
|
-
belongs_to :fleet
|
|
27
|
-
has_many :sailors
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
class Sailor < ActiveRecord::Base
|
|
31
|
-
belongs_to :ship
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
test '::where on columns' do
|
|
35
|
-
webmock(:get, "/ships", { where: { id: 10 }, limit: 100, offset: 0 }).to_return(body: [].to_json)
|
|
36
|
-
|
|
37
|
-
assert_equal [], Ship.where(id: 10).to_a
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
test '::where column is nil' do
|
|
41
|
-
webmock(:get, "/ships", { where: { fleet_id: nil }, limit: 100, offset: 0 }).to_return(body: [].to_json)
|
|
42
|
-
|
|
43
|
-
assert_equal [], Ship.where(fleet_id: nil).to_a
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
test '::where on belongs_to relation' do
|
|
47
|
-
webmock(:get, "/ships", where: {fleet: { id: {eq: 1} } }, limit: 100, offset: 0).to_return(body: [].to_json)
|
|
48
|
-
|
|
49
|
-
assert_equal [], Ship.where(fleet: {id: 1}).to_a
|
|
50
|
-
end
|
|
51
|
-
|
|
52
|
-
test '::where on has_many relation' do
|
|
53
|
-
webmock(:get, "/fleets", where: {ships: { id: {eq: 1} } }).to_return(body: [].to_json)
|
|
54
|
-
|
|
55
|
-
assert_equal [], Fleet.where(ships: {id: 1}).to_a
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
test '::where on has_and_belongs_to_many relation' do
|
|
59
|
-
webmock(:get, "/ships", where: {sailors: { id: {eq: 1} } }, limit: 100, offset: 0).to_return(body: [].to_json)
|
|
60
|
-
|
|
61
|
-
assert_equal [], Ship.where(sailors: {id: 1}).to_a
|
|
62
|
-
end
|
|
63
|
-
|
|
64
|
-
# Polymorphic
|
|
65
|
-
test '::where on a has_many throught a polymorphic source' do
|
|
66
|
-
webmock(:get, "/ships", where: { nations: { id: {eq: 1} } }, limit: 10).to_return(body: [].to_json)
|
|
67
|
-
|
|
68
|
-
assert_equal [], Ship.where(nations: {id: 1}).limit(10).to_a
|
|
69
|
-
end
|
|
70
|
-
### end polymorphic test
|
|
71
|
-
|
|
72
|
-
test '::where on nested relationship' do
|
|
73
|
-
webmock(:get, "/fleets", where: { ships: {sailors: { id: {eq: 1} } } }, limit: 10).to_return(body: [].to_json)
|
|
74
|
-
|
|
75
|
-
assert_equal [], Fleet.where(ships: {sailors: {id: 1}}).limit(10).to_a
|
|
76
|
-
end
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
end
|
|
@@ -1,123 +0,0 @@
|
|
|
1
|
-
require 'test_helper'
|
|
2
|
-
|
|
3
|
-
class ActiveRecord::QueryTest < ActiveSupport::TestCase
|
|
4
|
-
|
|
5
|
-
schema do
|
|
6
|
-
create_table "ships", limit: 100 do |t|
|
|
7
|
-
t.string "name", limit: 255
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
create_table "ownerships" do |t|
|
|
11
|
-
t.string "asset_type"
|
|
12
|
-
t.integer "asset_id"
|
|
13
|
-
end
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
class Ship < ActiveRecord::Base
|
|
17
|
-
has_many :ownerships, as: :asset
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
class Ownership < ActiveRecord::Base
|
|
21
|
-
belongs_to :asset, polymorphic: true
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
test '::first' do
|
|
25
|
-
webmock(:get, "/ships", { limit: 1, order: [{id: :asc}] }).to_return({
|
|
26
|
-
body: [].to_json
|
|
27
|
-
})
|
|
28
|
-
|
|
29
|
-
assert_nil Ship.first
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
test '::first!' do
|
|
33
|
-
webmock(:get, "/ships", { limit: 1, order: [{id: :asc}] }).to_return({
|
|
34
|
-
body: [].to_json
|
|
35
|
-
})
|
|
36
|
-
|
|
37
|
-
assert_raises ActiveRecord::RecordNotFound do
|
|
38
|
-
Ship.first!
|
|
39
|
-
end
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
test '::last' do
|
|
43
|
-
webmock(:get, "/ships", { limit: 1, order: [{id: :desc}] }).to_return({
|
|
44
|
-
body: [].to_json
|
|
45
|
-
})
|
|
46
|
-
|
|
47
|
-
assert_nil Ship.last
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
test '::where on the same column multiple times with symbols and strings' do
|
|
51
|
-
webmock(:get, "/ships", { where: [{ id: {gt: 10} }, 'AND', {id: {gt: 11}}], limit: 100, offset: 0 }).to_return(body: [].to_json)
|
|
52
|
-
|
|
53
|
-
arel_table = Ship.arel_table
|
|
54
|
-
assert_equal [], Ship.where(arel_table[:id].gt(10)).where(arel_table['id'].gt(11)).to_a
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
test '::where(AND CONDITION)' do
|
|
58
|
-
webmock(:get, "/ships", { where: {id: 10, name: 'name'}, limit: 1, order: [{id: :asc}] }).to_return({
|
|
59
|
-
body: [{id: 42}].to_json
|
|
60
|
-
})
|
|
61
|
-
|
|
62
|
-
arel_table = Ship.arel_table
|
|
63
|
-
assert_equal 42, Ship.where(arel_table[:id].eq(10).and(arel_table[:name].eq('name'))).first.id
|
|
64
|
-
end
|
|
65
|
-
|
|
66
|
-
test '::where(OR CONDITION)' do
|
|
67
|
-
webmock(:get, "/ships", { where: [{id: 10}, 'OR', {name: 'name'}], limit: 1, order: [{id: :asc}] }).to_return({
|
|
68
|
-
body: [{id: 42}].to_json
|
|
69
|
-
})
|
|
70
|
-
|
|
71
|
-
arel_table = Ship.arel_table
|
|
72
|
-
assert_equal 42, Ship.where(arel_table[:id].eq(10).or(arel_table[:name].eq('name'))).first.id
|
|
73
|
-
end
|
|
74
|
-
|
|
75
|
-
test '::where(AND & OR CONDITION)' do
|
|
76
|
-
webmock(:get, "/ships", { where: [{id: 10}, 'AND', [{id: 10}, 'OR', {name: 'name'}]], limit: 1, order: [{id: :asc}] }).to_return({
|
|
77
|
-
body: [{id: 42}].to_json
|
|
78
|
-
})
|
|
79
|
-
|
|
80
|
-
arel_table = Ship.arel_table
|
|
81
|
-
assert_equal 42, Ship.where(arel_table[:id].eq(10).and(arel_table[:id].eq(10).or(arel_table[:name].eq('name')))).first.id
|
|
82
|
-
end
|
|
83
|
-
|
|
84
|
-
test '::where(....big get request turns into post...)' do
|
|
85
|
-
name = 'q' * 3000
|
|
86
|
-
webmock(:post, "/ships").with(
|
|
87
|
-
headers: {'X-Http-Method-Override' => 'GET'},
|
|
88
|
-
body: {where: { name: name }, limit: 100, offset: 0 }.to_json
|
|
89
|
-
).to_return(body: [{id: 42}].to_json)
|
|
90
|
-
|
|
91
|
-
assert_equal 42, Ship.where(name: name)[0].id
|
|
92
|
-
end
|
|
93
|
-
|
|
94
|
-
test '::where with JOIN' do
|
|
95
|
-
webmock(:get, "/ships", {where: { ownerships: {id: {eq: 1}} }, limit: 100, offset: 0 }).to_return({
|
|
96
|
-
body: [{id: 42}].to_json
|
|
97
|
-
})
|
|
98
|
-
|
|
99
|
-
arel = Ownership.arel_table[:id].eq(1)
|
|
100
|
-
assert_equal 42, Ship.joins(:ownerships).where(arel)[0].id
|
|
101
|
-
end
|
|
102
|
-
|
|
103
|
-
# Relation test
|
|
104
|
-
|
|
105
|
-
test '#to_sql' do
|
|
106
|
-
assert_equal "SELECT ships.* FROM ships WHERE ships.id = 10", Ship.where(:id => 10).to_sql
|
|
107
|
-
end
|
|
108
|
-
|
|
109
|
-
test '#to_sql binds correctly when joining' do
|
|
110
|
-
assert_equal 'SELECT ships.* FROM ships INNER JOIN ownerships ON ownerships.asset_id = ships.id AND ownerships.asset_type = \'ActiveRecord::QueryTest::Ship\' WHERE ownerships.id = 1', Ship.joins(:ownerships).where({ ownerships: { id: 1 } }).to_sql
|
|
111
|
-
end
|
|
112
|
-
|
|
113
|
-
test '#to_sar' do
|
|
114
|
-
assert_equal "/ships?%81%A5where%81%A2id%0A", Ship.where(:id => 10).to_sar.path
|
|
115
|
-
end
|
|
116
|
-
|
|
117
|
-
test 'bind params get eaten when joining' do
|
|
118
|
-
uri = URI(Ship.joins(:ownerships).where({ ownerships: { id: 1 } }).to_sar.path)
|
|
119
|
-
query = MessagePack.unpack(CGI.unescape(uri.query))
|
|
120
|
-
assert_equal({"where"=>{"ownerships"=>{"id"=>{"eq"=>1}}}}, query)
|
|
121
|
-
end
|
|
122
|
-
|
|
123
|
-
end
|