switch_point 0.2.2 → 0.2.3

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: 80333b18b169594e3d1439b08df9cff562f85eff
4
- data.tar.gz: 9d701fc245dc24a8f1736d4d0adad9bf920de04b
3
+ metadata.gz: 7214878a8ac1b215808ee7fb386f02643ca94961
4
+ data.tar.gz: 05cad4a43106ab868ed8bcc47be9ed881a202f7e
5
5
  SHA512:
6
- metadata.gz: d4ab8f26f462b8bdb96c97c7f39e3bd20befc4c0d94445b7c9bf3f349c06d0218bc6b314ed2ecd6435c5055cff9aaaced2d2e688a7a8d7a6c5299baf1533cb82
7
- data.tar.gz: 5eaf795923f263f0caa615baec1f6687e8c834c80842925cb4a50fca10eb568977dc795d9704edefe7da145f5c8712ad53cb3ec4398e9eee4728025058464c38
6
+ metadata.gz: 6344f088708f67f8bb5bf8d55ed908356469cffda84c7ae65e96e82fa72394f002c26857e576410ee6c3c72b9bfc5e5700e72d07a01e6eab6191a87cd60d1e98
7
+ data.tar.gz: 0cebcc98ac866bddc15bd8bc5b1a85669cf09aaadbadeaca24c0fa0b531a4d9e65986ac4dca65f40e90911f319c7e704b51ffc17ba5a28c4755ab2dac248482c
@@ -1,3 +1,7 @@
1
+ ## 0.2.3 (2014-06-02)
2
+ - Support specifying the same database name within different switch_point
3
+ - Add Proxy#readonly? and Proxy#writable? predicate
4
+
1
5
  ## 0.2.2 (2014-05-30)
2
6
  - Fix nil error on with_{readonly,writable} from non-switch_point model
3
7
 
@@ -14,7 +14,7 @@ module SwitchPoint
14
14
  end
15
15
 
16
16
  def model_name(name, mode)
17
- "#{mode}_#{database_name(name, mode)}".camelize
17
+ "#{name}_#{mode}".camelize
18
18
  end
19
19
 
20
20
  def fetch(name)
@@ -28,10 +28,18 @@ module SwitchPoint
28
28
  @mode = :readonly
29
29
  end
30
30
 
31
+ def readonly?
32
+ @mode == :readonly
33
+ end
34
+
31
35
  def writable!
32
36
  @mode = :writable
33
37
  end
34
38
 
39
+ def writable?
40
+ @mode == :writable
41
+ end
42
+
35
43
  def with_readonly(&block)
36
44
  with_connection(:readonly, &block)
37
45
  end
@@ -1,3 +1,3 @@
1
1
  module SwitchPoint
2
- VERSION = "0.2.2"
2
+ VERSION = "0.2.3"
3
3
  end
@@ -8,6 +8,9 @@ SwitchPoint.configure do |config|
8
8
  config.define_switch_point :comment,
9
9
  readonly: :comment_readonly,
10
10
  writable: :comment_writable
11
+ config.define_switch_point :special,
12
+ readonly: :main_readonly_special,
13
+ writable: :main_writable
11
14
  end
12
15
 
13
16
  class Book < ActiveRecord::Base
@@ -26,6 +29,10 @@ class User < ActiveRecord::Base
26
29
  use_switch_point :user
27
30
  end
28
31
 
32
+ class BigData < ActiveRecord::Base
33
+ use_switch_point :special
34
+ end
35
+
29
36
  class Note < ActiveRecord::Base
30
37
  end
31
38
 
@@ -33,6 +40,7 @@ base = { adapter: 'sqlite3' }
33
40
  ActiveRecord::Base.configurations = {
34
41
  'main_readonly' => base.merge(database: 'main_readonly.sqlite3'),
35
42
  'main_writable' => base.merge(database: 'main_writable.sqlite3'),
43
+ 'main_readonly_special' => base.merge(database: 'main_readonly_special.sqlite3'),
36
44
  'user' => base.merge(database: 'user.sqlite3'),
37
45
  'comment_readonly' => base.merge(database: 'comment_readonly.sqlite3'),
38
46
  'comment_writable' => base.merge(database: 'comment_writable.sqlite3'),
@@ -28,6 +28,7 @@ RSpec.describe SwitchPoint::Model do
28
28
  expect(User).to connect_to('user.sqlite3')
29
29
  expect(Comment).to connect_to('comment_readonly.sqlite3')
30
30
  expect(Note).to connect_to('default.sqlite3')
31
+ expect(Book.switch_point_proxy).to be_readonly
31
32
  end
32
33
 
33
34
  it 'sends destructive queries to writable' do
@@ -56,14 +57,27 @@ RSpec.describe SwitchPoint::Model do
56
57
  expect(Book.connection).to equal(Publisher.connection)
57
58
  end
58
59
  end
60
+
61
+ context 'with the same database name' do
62
+ it 'does NOT shares a connection' do
63
+ expect(Book.connection).to_not equal(BigData.connection)
64
+ Book.with_writable do
65
+ BigData.with_writable do
66
+ expect(Book.connection).to_not equal(BigData.connection)
67
+ end
68
+ end
69
+ end
70
+ end
59
71
  end
60
72
 
61
73
  describe '.with_writable' do
62
74
  it 'changes connection locally' do
63
75
  Book.with_writable do
64
76
  expect(Book).to connect_to('main_writable.sqlite3')
77
+ expect(Book.switch_point_proxy).to be_writable
65
78
  end
66
79
  expect(Book).to connect_to('main_readonly.sqlite3')
80
+ expect(Book.switch_point_proxy).to be_readonly
67
81
  end
68
82
 
69
83
  it 'affects to other models with the same switch point' do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: switch_point
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kohei Suzuki
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-30 00:00:00.000000000 Z
11
+ date: 2014-06-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: appraisal