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
@@ -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,131 +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_type = \'ActiveRecord::QueryTest::Ship\' AND ownerships.asset_id = ships.id 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
- test 'Arel::Nodes::HomogeneousIn' do
124
- webmock(:get, "/ships", { where: {id: {in: [10,12]} }, limit: 100, offset: 0 }).to_return({
125
- body: [].to_json
126
- })
127
-
128
- Ship.where(id: [10,12]).to_a
129
- end
130
-
131
- end
@@ -1,30 +0,0 @@
1
- require 'test_helper'
2
-
3
- class ActiveRecord::RPCTest < 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
- rpc :self_destruct
13
- end
14
-
15
- test '::rpc calls custom controller function' do
16
- webmock(:get, "/ships", { limit: 1, order: [{id: :asc}] }).to_return({
17
- body: [{id: 3, name: 'Sivar'}].to_json
18
- })
19
-
20
- webmock(:post, '/ships/3/self_destruct').to_return({
21
- body: {name: 'DESTROYED'}.to_json
22
- })
23
-
24
- ship = Ship.first
25
- assert ship.self_destruct!
26
- assert_equal 'DESTROYED', ship.name
27
- assert ship.changes.empty?
28
- end
29
-
30
- end
data/test/schema_mock.rb DELETED
@@ -1,121 +0,0 @@
1
- class ActiveSupport::TestCase
2
- class Schema
3
-
4
- class Table
5
-
6
- class Column
7
-
8
- def initialize(name, type, options={})
9
- @name = name
10
- @type = type
11
- @options = options
12
- end
13
-
14
- def as_json
15
- {type: @type, primary_key: false, null: true, array: false}.merge(@options)
16
- end
17
- end
18
-
19
- attr_accessor :name, :options, :columns
20
-
21
- def initialize(name, options={}, &block)
22
- @name = name
23
- @options = options
24
- @columns = {}
25
- case options[:id]
26
- when false
27
- else
28
- integer('id', primary_key: true, null: false)
29
- end
30
-
31
- block.call(self)
32
- end
33
-
34
- def string(name, options={})
35
- @columns[name] = Column.new(name, :string, options)
36
- end
37
-
38
- def text(name, options={})
39
- @columns[name] = Column.new(name, :text, options)
40
- end
41
-
42
- def datetime(name, options={})
43
- @columns[name] = Column.new(name, :datetime, options)
44
- end
45
-
46
- def integer(name, options={})
47
- @columns[name] = Column.new(name, :integer, options)
48
- end
49
-
50
- def to_json
51
- json = @options.slice(:limit)
52
- json[:attributes] = {}
53
- @columns.each do |name, column|
54
- json[:attributes][name] = column.as_json
55
- end
56
- json.to_json
57
- end
58
-
59
- end
60
-
61
- attr_accessor :tables
62
-
63
- def initialize
64
- @tables = {}
65
- end
66
-
67
- def self.define(&block)
68
- i = new
69
- i.define(&block)
70
- i
71
- end
72
-
73
- def define(&block)
74
- instance_eval(&block)
75
- end
76
-
77
- def create_table(name, options={}, &block)
78
- @tables[name] = Table.new(name, options, &block)
79
- end
80
-
81
- end
82
-
83
- def self.schema(&block)
84
- self.class_variable_set(:@@schema, Schema.define(&block))
85
- end
86
-
87
- set_callback(:setup, :before) do
88
- if !instance_variable_defined?(:@suite_setup_run) && self.class.class_variable_defined?(:@@schema)
89
- ActiveRecord::Base.establish_connection(adapter: 'sunstone', url: 'http://example.com')
90
-
91
- req_stub = stub_request(:get, /^http:\/\/example.com/).with do |req|
92
- case req.uri.path
93
- when '/tables'
94
- true
95
- when /^\/\w+\/schema$/i
96
- true
97
- else
98
- false
99
- end
100
- end
101
-
102
- req_stub.to_return do |req|
103
- case req.uri.path
104
- when '/tables'
105
- {
106
- body: self.class.class_variable_get(:@@schema).tables.keys.to_json,
107
- headers: { 'StandardAPI-Version' => '6.0.0.29' }
108
- }
109
- when /^\/(\w+)\/schema$/i
110
- {
111
- body: self.class.class_variable_get(:@@schema).tables[$1].to_json,
112
- headers: { 'StandardAPI-Version' => '6.0.0.29' }
113
- }
114
- end
115
- end
116
-
117
- end
118
- @suite_setup_run = true
119
- end
120
-
121
- end
@@ -1,30 +0,0 @@
1
- require 'test_helper'
2
-
3
- class Sunstone::Connection::ColumnDefinitionTest < ActiveSupport::TestCase
4
-
5
- schema do
6
- create_table "ships", limit: 100 do |t|
7
- t.string "name", limit: 255
8
- t.integer "guns", limit: 8
9
- t.integer "sailor_count"
10
- end
11
- end
12
-
13
- class Ship < ActiveRecord::Base
14
- end
15
-
16
- test "default limit on column" do
17
- assert_nil Ship.columns_hash['sailor_count'].limit
18
- end
19
-
20
- test "custom limit on column" do
21
- assert_equal 8, Ship.columns_hash['guns'].limit
22
- end
23
-
24
- test "custom limit on string column" do
25
- assert_equal 255, Ship.columns_hash['name'].limit
26
- end
27
-
28
- end
29
-
30
-
@@ -1,44 +0,0 @@
1
- require 'test_helper'
2
-
3
- class Sunstone::Connection::ConfigurationTest < ActiveSupport::TestCase
4
-
5
- test "setting the url sets the api_key" do
6
- connection = Sunstone::Connection.new(url: 'http://my_api_key@localhost')
7
- assert_equal('my_api_key', connection.api_key)
8
- end
9
-
10
- test "setting the url sets the host" do
11
- connection = Sunstone::Connection.new(url: 'https://example.com')
12
- assert_equal('example.com', connection.host)
13
- end
14
-
15
- test "setting the url sets the port" do
16
- connection = Sunstone::Connection.new(url: 'http://localhost')
17
- assert_equal(80, connection.port)
18
-
19
- connection = Sunstone::Connection.new(url: 'https://localhost')
20
- assert_equal(443, connection.port)
21
-
22
- connection = Sunstone::Connection.new(url: 'https://localhost:4321')
23
- assert_equal(4321, connection.port)
24
- end
25
-
26
- test "setting the url sets the use_ssl option" do
27
- connection = Sunstone::Connection.new(url: 'http://localhost')
28
- assert_equal(false, connection.use_ssl)
29
-
30
- connection = Sunstone::Connection.new(url: 'https://localhost')
31
- assert_equal(true, connection.use_ssl)
32
- end
33
-
34
- test "setting the user_agent appends it to the User-Agent" do
35
- connection = Sunstone::Connection.new(url: 'http://localhost')
36
- assert_equal("Sunstone/#{Sunstone::VERSION} Ruby/#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL} #{RUBY_PLATFORM}", connection.user_agent)
37
-
38
- connection = Sunstone::Connection.new(url: 'http://localhost', user_agent: "MyGem/3.14")
39
- assert_equal("MyGem/3.14 Sunstone/#{Sunstone::VERSION} Ruby/#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL} #{RUBY_PLATFORM}", connection.user_agent)
40
- end
41
-
42
- end
43
-
44
-