makara 0.3.8 → 0.3.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a43f7871351a95b0291a4624bdfded3e1e4bccf3
4
- data.tar.gz: feaf04905d1a7293abd47cf32a0f69f23575c609
3
+ metadata.gz: 2285d0c3c177997ec9e9d8568225f3a1ed1bdf28
4
+ data.tar.gz: 953d024813b8bd5bae579665a3988c5770f63d38
5
5
  SHA512:
6
- metadata.gz: 06ce4185196b043f4129039a18a55db3f18816ab8af517372193ac28e2cf8517b4dd0abee9970ab012b0a0f2214fd56e42fcd3fce5643d077a8aa3537bbd4635
7
- data.tar.gz: a45e25f35d71242f954d4a5fdeafeb0907399b496d19c9122e227ad04bd0486986ce37e2390877f191a2adc0e7295a37ecade58278c57991b57f6152da3123b1
6
+ metadata.gz: dc7a2f84b22a57f83d1eb3ef4e615975e405f97b150b6b8d6c4e39b4833b4daa28036f7d838cd2062e64c4cc1ca015f519cf0d91c6c3a8f5f25ea85229e4e3e6
7
+ data.tar.gz: 528f91cff15ebd34a460d4f79f01679dd457641904df4834ae8179d735a461d23e8dfdae59971bffb019e62aaaabacb8aa36f440bd2165e5ca2835e58a69f8e4
@@ -9,6 +9,7 @@ services:
9
9
  before_script:
10
10
  - mysql -e 'create database makara_test;'
11
11
  - psql -c 'create database makara_test;' -U postgres
12
+ - psql -c 'create extension postgis;' -U postgres
12
13
 
13
14
  rvm:
14
15
  - 2.0
@@ -1,6 +1,17 @@
1
1
  # Change Log
2
2
  All notable changes to this project will be documented in this file.
3
3
 
4
+ ## v0.3.8 - 2016-07-11
5
+
6
+ [Full Changelog](https://github.com/taskrabbit/makara/compare/v0.3.7...v0.3.8)
7
+
8
+ Changed
9
+ - Rails 5.1 compatibility [#150](https://github.com/taskrabbit/makara/pull/150) Jeremy Daer
10
+ - Minimize redundant context cache requests [#157](https://github.com/taskrabbit/makara/issues/157) Greg Patrick
11
+ - thread-local cache for previous context stickiness [#158](https://github.com/taskrabbit/makara/issues/158) Jeremy Daer
12
+ - Configurable cookie options [#159](https://github.com/taskrabbit/makara/pull/159) Jeremy Daer
13
+ - Test against Rails 5.x and Ruby 2.x [#160](https://github.com/taskrabbit/makara/pull/160) Jeremy Daer
14
+
4
15
  ## v0.3.7 - 2016-09-22
5
16
 
6
17
  [Full Changelog](https://github.com/taskrabbit/makara/compare/v0.3.6...v0.3.7)
data/Gemfile CHANGED
@@ -12,7 +12,8 @@ gem 'rack', '1.6.0'
12
12
 
13
13
  gem 'mysql2', :platform => :ruby
14
14
  gem 'pg', :platform => :ruby
15
+ gem 'activerecord-postgis-adapter', :platform => :ruby
16
+ gem 'rgeo', :platform => :ruby
15
17
 
16
18
  gem 'activerecord-jdbcmysql-adapter', :platform => :jruby
17
19
  gem 'activerecord-jdbcpostgresql-adapter', :platform => :jruby
18
-
@@ -12,6 +12,8 @@ gem 'i18n', '~> 0.5.0'
12
12
  gem 'mysql2', '0.2.11', :platform => :ruby
13
13
  gem 'activerecord-jdbcmysql-adapter', :platform => :jruby
14
14
  gem 'activerecord-jdbcpostgresql-adapter', :platform => :jruby
15
+ gem 'activerecord-postgis-adapter', :platform => :ruby
16
+ gem 'rgeo', :platform => :ruby
15
17
 
16
18
 
17
19
  rmajor, rminor, rpatch = RUBY_VERSION.split(/[^\d]/)[0..2].map(&:to_i)
@@ -12,6 +12,8 @@ gem 'i18n', '~> 0.6.0'
12
12
  gem 'mysql2', '~> 0.3.10', :platform => :ruby
13
13
  gem 'activerecord-jdbcmysql-adapter', :platform => :jruby
14
14
  gem 'activerecord-jdbcpostgresql-adapter', :platform => :jruby
15
+ gem 'activerecord-postgis-adapter', :platform => :ruby
16
+ gem 'rgeo', :platform => :ruby
15
17
 
16
18
  rmajor, rminor, rpatch = RUBY_VERSION.split(/[^\d]/)[0..2].map(&:to_i)
17
19
 
@@ -12,6 +12,8 @@ gem 'i18n', '~> 0.6.0'
12
12
  gem 'mysql2', '~> 0.3.10', :platform => :ruby
13
13
  gem 'activerecord-jdbcmysql-adapter', :platform => :jruby
14
14
  gem 'activerecord-jdbcpostgresql-adapter', :platform => :jruby
15
+ gem 'activerecord-postgis-adapter', :platform => :ruby
16
+ gem 'rgeo', :platform => :ruby
15
17
 
16
18
  rmajor, rminor, rpatch = RUBY_VERSION.split(/[^\d]/)[0..2].map(&:to_i)
17
19
 
@@ -13,3 +13,5 @@ gem 'mysql2', '~> 0.3.10', :platform => :ruby
13
13
  gem 'activerecord-jdbcmysql-adapter', :platform => :jruby
14
14
  gem 'pg', :platform => :ruby
15
15
  gem 'activerecord-jdbcpostgresql-adapter', :platform => :jruby
16
+ gem 'activerecord-postgis-adapter', :platform => :ruby
17
+ gem 'rgeo', :platform => :ruby
@@ -13,3 +13,5 @@ gem 'mysql2', '~> 0.3.10', :platform => :ruby
13
13
  gem 'activerecord-jdbcmysql-adapter', :platform => :jruby
14
14
  gem 'pg', :platform => :ruby
15
15
  gem 'activerecord-jdbcpostgresql-adapter', :platform => :jruby
16
+ gem 'activerecord-postgis-adapter', :platform => :ruby
17
+ gem 'rgeo', :platform => :ruby
@@ -13,3 +13,5 @@ gem 'mysql2', '~> 0.3.10', :platform => :ruby
13
13
  gem 'activerecord-jdbcmysql-adapter', :platform => :jruby
14
14
  gem 'pg', :platform => :ruby
15
15
  gem 'activerecord-jdbcpostgresql-adapter', :platform => :jruby
16
+ gem 'activerecord-postgis-adapter', :platform => :ruby
17
+ gem 'rgeo', :platform => :ruby
@@ -0,0 +1,41 @@
1
+ require 'active_record/connection_adapters/makara_abstract_adapter'
2
+ require 'active_record/connection_adapters/postgis_adapter'
3
+
4
+ if ActiveRecord::VERSION::MAJOR >= 4
5
+
6
+ module ActiveRecord
7
+ module ConnectionHandling
8
+ def makara_postgis_connection(config)
9
+ ActiveRecord::ConnectionAdapters::MakaraPostgisAdapter.new(config)
10
+ end
11
+ end
12
+ end
13
+
14
+ else
15
+
16
+ module ActiveRecord
17
+ class Base
18
+ def self.makara_postgis_connection(config)
19
+ ActiveRecord::ConnectionAdapters::MakaraPostgisAdapter.new(config)
20
+ end
21
+ end
22
+ end
23
+
24
+ end
25
+
26
+
27
+ module ActiveRecord
28
+ module ConnectionAdapters
29
+ class MakaraPostgisAdapter < ActiveRecord::ConnectionAdapters::MakaraAbstractAdapter
30
+ def self.visitor_for(*args)
31
+ ActiveRecord::ConnectionAdapters::PostGISAdapter.visitor_for(*args)
32
+ end
33
+
34
+ protected
35
+
36
+ def active_record_connection_for(config)
37
+ ::ActiveRecord::Base.postgis_connection(config)
38
+ end
39
+ end
40
+ end
41
+ end
@@ -3,7 +3,7 @@ module Makara
3
3
 
4
4
  MAJOR = 0
5
5
  MINOR = 3
6
- PATCH = 8
6
+ PATCH = 9
7
7
  PRE = nil
8
8
 
9
9
  def self.to_s
@@ -0,0 +1,150 @@
1
+ # RGeo doesn't play well with JRuby and to avoid complicated test setup
2
+ # we're only testing ActiveRecord version ~> 4.2
3
+ if RUBY_ENGINE == 'ruby' &&
4
+ ActiveRecord::VERSION::MAJOR == 4 &&
5
+ ActiveRecord::VERSION::MINOR >= 2
6
+
7
+ require 'spec_helper'
8
+ require 'rgeo'
9
+ require 'activerecord-postgis-adapter'
10
+ require 'active_record/connection_adapters/postgis_adapter'
11
+
12
+ describe 'MakaraPostgisAdapter' do
13
+ let(:db_username){ ENV['TRAVIS'] ? 'postgres' : `whoami`.chomp }
14
+
15
+ let(:config) do
16
+ base = YAML.load_file(File.expand_path('spec/support/postgis_database.yml'))['test']
17
+ base['username'] = db_username
18
+ base
19
+ end
20
+
21
+ let(:connection) { ActiveRecord::Base.connection }
22
+
23
+ before :each do
24
+ ActiveRecord::Base.clear_all_connections!
25
+ change_context
26
+ end
27
+
28
+ it 'should allow a connection to be established' do
29
+ ActiveRecord::Base.establish_connection(config)
30
+ expect(ActiveRecord::Base.connection)
31
+ .to be_instance_of(ActiveRecord::ConnectionAdapters::MakaraPostgisAdapter)
32
+ end
33
+
34
+ context 'with the connection established and schema loaded' do
35
+ before do
36
+ ActiveRecord::Base.establish_connection(config)
37
+ load(File.dirname(__FILE__) + '/../../support/schema.rb')
38
+ load(File.dirname(__FILE__) + '/../../support/postgis_schema.rb')
39
+ change_context
40
+ RGeo::ActiveRecord::SpatialFactoryStore.instance.tap do |config|
41
+ # By default, use the GEOS implementation for spatial columns.
42
+ config.default = RGeo::Geos.factory_generator
43
+
44
+ # But use a geographic implementation for point columns.
45
+ config.register(RGeo::Geographic.spherical_factory(srid: 4326), geo_type: "point")
46
+ end
47
+ end
48
+
49
+ let(:town_class) do
50
+ Class.new(ActiveRecord::Base) do
51
+ self.table_name = :towns
52
+ end
53
+ end
54
+
55
+ it 'should have one master and two slaves' do
56
+ expect(connection.master_pool.connection_count).to eq(1)
57
+ expect(connection.slave_pool.connection_count).to eq(2)
58
+ end
59
+
60
+ it 'should allow real queries to work' do
61
+ connection.execute('INSERT INTO users (name) VALUES (\'John\')')
62
+
63
+ connection.master_pool.connections.each do |master|
64
+ expect(master).to receive(:execute).never
65
+ end
66
+
67
+ change_context
68
+ res = connection.execute('SELECT name FROM users ORDER BY id DESC LIMIT 1')
69
+
70
+ expect(res.to_a[0]['name']).to eq('John')
71
+ end
72
+
73
+ it 'should send SET operations to each connection' do
74
+ connection.master_pool.connections.each do |con|
75
+ expect(con).to receive(:execute).with("SET TimeZone = 'UTC'").once
76
+ end
77
+
78
+ connection.slave_pool.connections.each do |con|
79
+ expect(con).to receive(:execute).with("SET TimeZone = 'UTC'").once
80
+ end
81
+ connection.execute("SET TimeZone = 'UTC'")
82
+ end
83
+
84
+ it 'should send reads to the slave' do
85
+ # ensure the next connection will be the first one
86
+ connection.slave_pool
87
+ .strategy
88
+ .instance_variable_set('@current_idx',
89
+ connection.slave_pool.connections.length)
90
+
91
+ con = connection.slave_pool.connections.first
92
+ expect(con).to receive(:execute).with('SELECT * FROM users').once
93
+
94
+ connection.execute('SELECT * FROM users')
95
+ end
96
+
97
+ it 'should send writes to master' do
98
+ con = connection.master_pool.connections.first
99
+ expect(con).to receive(:execute).with('UPDATE users SET name = "bob" WHERE id = 1')
100
+ connection.execute('UPDATE users SET name = "bob" WHERE id = 1')
101
+ end
102
+
103
+ it 'should interpret points correctly' do
104
+ town_class.create!(location: 'Point(1 2)')
105
+ town = town_class.last
106
+ expect(town.location.x).to eq 1
107
+ expect(town.location.y).to eq 2
108
+ end
109
+ end
110
+
111
+ context 'without live connections' do
112
+ it 'should raise errors on read or write' do
113
+ allow(ActiveRecord::Base).to receive(:postgis_connection).and_raise(StandardError.new('could not connect to server: Connection refused'))
114
+
115
+ ActiveRecord::Base.establish_connection(config)
116
+ expect { connection.execute('SELECT * FROM users') }.to raise_error(Makara::Errors::NoConnectionsAvailable)
117
+ expect { connection.execute('INSERT INTO users (name) VALUES (\'John\')') }.to raise_error(Makara::Errors::NoConnectionsAvailable)
118
+ end
119
+ end
120
+
121
+ context 'with only master connection' do
122
+ it 'should not raise errors on read and write' do
123
+ custom_config = config.deep_dup
124
+ custom_config['makara']['connections'].select{|h| h['role'] == 'slave' }.each{|h| h['port'] = '1'}
125
+
126
+ ActiveRecord::Base.establish_connection(custom_config)
127
+ load(File.dirname(__FILE__) + '/../../support/schema.rb')
128
+
129
+ connection.execute('SELECT * FROM users')
130
+ connection.execute('INSERT INTO users (name) VALUES (\'John\')')
131
+ end
132
+ end
133
+
134
+ context 'with only slave connection' do
135
+ it 'should raise error only on write' do
136
+ ActiveRecord::Base.establish_connection(config)
137
+ load(File.dirname(__FILE__) + '/../../support/schema.rb')
138
+ ActiveRecord::Base.clear_all_connections!
139
+
140
+ custom_config = config.deep_dup
141
+ custom_config['makara']['connections'].select{|h| h['role'] == 'master' }.each{|h| h['port'] = '1'}
142
+
143
+ ActiveRecord::Base.establish_connection(custom_config)
144
+
145
+ connection.execute('SELECT * FROM users')
146
+ expect { connection.execute('INSERT INTO users (name) VALUES (\'John\')') }.to raise_error(Makara::Errors::NoConnectionsAvailable)
147
+ end
148
+ end
149
+ end
150
+ end
@@ -5,11 +5,11 @@ describe 'MakaraPostgreSQLAdapter' do
5
5
 
6
6
  let(:db_username){ ENV['TRAVIS'] ? 'postgres' : `whoami`.chomp }
7
7
 
8
- let(:config){
8
+ let(:config) do
9
9
  base = YAML.load_file(File.expand_path('spec/support/postgresql_database.yml'))['test']
10
10
  base['username'] = db_username
11
11
  base
12
- }
12
+ end
13
13
 
14
14
  let(:connection) { ActiveRecord::Base.connection }
15
15
 
@@ -97,8 +97,7 @@ describe Makara::ConfigParser do
97
97
  :top_level => 'value',
98
98
  :sticky => true,
99
99
  :blacklist_duration => 30,
100
- :master_ttl => 5,
101
- :sticky => true
100
+ :master_ttl => 5
102
101
  }
103
102
  ])
104
103
  expect(parser.slave_configs).to eq([
@@ -107,16 +106,14 @@ describe Makara::ConfigParser do
107
106
  :top_level => 'value',
108
107
  :sticky => true,
109
108
  :blacklist_duration => 30,
110
- :master_ttl => 5,
111
- :sticky => true
109
+ :master_ttl => 5
112
110
  },
113
111
  {
114
112
  :name => 'slave2',
115
113
  :top_level => 'value',
116
114
  :sticky => true,
117
115
  :blacklist_duration => 30,
118
- :master_ttl => 5,
119
- :sticky => true
116
+ :master_ttl => 5
120
117
  }
121
118
  ])
122
119
  end
@@ -133,8 +130,7 @@ describe Makara::ConfigParser do
133
130
  :top_level => 'value',
134
131
  :sticky => true,
135
132
  :blacklist_duration => 456,
136
- :master_ttl => 5,
137
- :sticky => true
133
+ :master_ttl => 5
138
134
  }
139
135
  ])
140
136
  expect(parser.slave_configs).to eq([
@@ -143,16 +139,14 @@ describe Makara::ConfigParser do
143
139
  :top_level => 'slave value',
144
140
  :sticky => true,
145
141
  :blacklist_duration => 123,
146
- :master_ttl => 5,
147
- :sticky => true
142
+ :master_ttl => 5
148
143
  },
149
144
  {
150
145
  :name => 'slave2',
151
146
  :top_level => 'value',
152
147
  :sticky => true,
153
148
  :blacklist_duration => 123,
154
- :master_ttl => 5,
155
- :sticky => true
149
+ :master_ttl => 5
156
150
  }
157
151
  ])
158
152
  end
@@ -0,0 +1,13 @@
1
+ test:
2
+ adapter: 'makara_postgis'
3
+ database: 'makara_test'
4
+ username: 'root'
5
+ password: ''
6
+
7
+ makara:
8
+ blacklist_duration: 2
9
+ master_ttl: 5
10
+ connections:
11
+ - role: master
12
+ - role: slave
13
+ - role: slave
@@ -0,0 +1,8 @@
1
+
2
+ ActiveRecord::Schema.define(:version => 20160518161227) do
3
+ execute "create extension if not exists postgis"
4
+
5
+ create_table "towns", :force => true do |t|
6
+ t.st_point "location"
7
+ end
8
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: makara
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.8
4
+ version: 0.3.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Nelson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-07-11 00:00:00.000000000 Z
11
+ date: 2017-08-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -55,6 +55,7 @@ files:
55
55
  - lib/active_record/connection_adapters/makara_jdbcmysql_adapter.rb
56
56
  - lib/active_record/connection_adapters/makara_jdbcpostgresql_adapter.rb
57
57
  - lib/active_record/connection_adapters/makara_mysql2_adapter.rb
58
+ - lib/active_record/connection_adapters/makara_postgis_adapter.rb
58
59
  - lib/active_record/connection_adapters/makara_postgresql_adapter.rb
59
60
  - lib/active_record/connection_adapters/mysql2_makara_adapter.rb
60
61
  - lib/active_record/connection_adapters/postgresql_makara_adapter.rb
@@ -84,6 +85,7 @@ files:
84
85
  - spec/active_record/connection_adapters/makara_abstract_adapter_error_handling_spec.rb
85
86
  - spec/active_record/connection_adapters/makara_abstract_adapter_spec.rb
86
87
  - spec/active_record/connection_adapters/makara_mysql2_adapter_spec.rb
88
+ - spec/active_record/connection_adapters/makara_postgis_adapter_spec.rb
87
89
  - spec/active_record/connection_adapters/makara_postgresql_adapter_spec.rb
88
90
  - spec/cache_spec.rb
89
91
  - spec/config_parser_spec.rb
@@ -101,6 +103,8 @@ files:
101
103
  - spec/support/mysql2_database.yml
102
104
  - spec/support/mysql2_database_with_custom_errors.yml
103
105
  - spec/support/pool_extensions.rb
106
+ - spec/support/postgis_database.yml
107
+ - spec/support/postgis_schema.rb
104
108
  - spec/support/postgresql_database.yml
105
109
  - spec/support/proxy_extensions.rb
106
110
  - spec/support/schema.rb
@@ -131,6 +135,7 @@ test_files:
131
135
  - spec/active_record/connection_adapters/makara_abstract_adapter_error_handling_spec.rb
132
136
  - spec/active_record/connection_adapters/makara_abstract_adapter_spec.rb
133
137
  - spec/active_record/connection_adapters/makara_mysql2_adapter_spec.rb
138
+ - spec/active_record/connection_adapters/makara_postgis_adapter_spec.rb
134
139
  - spec/active_record/connection_adapters/makara_postgresql_adapter_spec.rb
135
140
  - spec/cache_spec.rb
136
141
  - spec/config_parser_spec.rb
@@ -148,6 +153,8 @@ test_files:
148
153
  - spec/support/mysql2_database.yml
149
154
  - spec/support/mysql2_database_with_custom_errors.yml
150
155
  - spec/support/pool_extensions.rb
156
+ - spec/support/postgis_database.yml
157
+ - spec/support/postgis_schema.rb
151
158
  - spec/support/postgresql_database.yml
152
159
  - spec/support/proxy_extensions.rb
153
160
  - spec/support/schema.rb