activerecord-multi-tenant 0.4.0 → 0.4.1

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: 1c30e8a7b37b923b66c5043fb73f3c9e776cea85
4
- data.tar.gz: 63a2537270723a549cab19a3a75e5c9eaee4fdac
3
+ metadata.gz: 3ed816e4227187f3f64ae1e1b53471c74f220150
4
+ data.tar.gz: acd8708805299354b2516a61fe3365f557ac09d4
5
5
  SHA512:
6
- metadata.gz: 5fe0741bcd4279f6852aa8fc64a25921bb8fb9953cbce564a81ec611602bc0321ca6ededc84ade5053795d64c3e1d3b2a055c6e5c19aa54003ea18c65aa5651e
7
- data.tar.gz: f59653a116f517ceafdd91677518113299bf86b281259a0816c66299c3ac5b2fa8ec2d347078034ace050adb21aeb12c40ff476e36fe8f9e238f695d99c1f3ad
6
+ metadata.gz: 74c9aa0bba774511e236db9e08f830ebc09703b8f58d3d6f39c97454032ac607a0f5b7050ec24a78a6b3322cc7df9b11f658ef61f8ddbbaf0726c8b73c5b32d0
7
+ data.tar.gz: b5f1427977dac05e87491fa72e604a6454067d9d8b3742ee5b63f367de0dc6411bf17386e868a5761a3bce1c9df5166ac00eecc0d1e522e52a64397b91cbb73b
data/.travis.yml CHANGED
@@ -6,6 +6,7 @@ language: ruby
6
6
  rvm:
7
7
  - 2.1
8
8
  - 2.3.3
9
+ - 2.4.0
9
10
 
10
11
  gemfile:
11
12
  - gemfiles/rails_3.2.gemfile
@@ -13,12 +14,21 @@ gemfile:
13
14
  - gemfiles/rails_4.1.gemfile
14
15
  - gemfiles/rails_4.2.gemfile
15
16
  - gemfiles/rails_5.0.gemfile
17
+ - gemfiles/active_record_5.0.gemfile
16
18
 
17
19
  matrix:
18
20
  fast_finish: true
19
21
  exclude:
20
- - gemfile: gemfiles/rails_5.0.gemfile
21
- rvm: 2.1
22
+ - rvm: 2.1
23
+ gemfile: gemfiles/rails_5.0.gemfile
24
+ - rvm: 2.1
25
+ gemfile: gemfiles/active_record_5.0.gemfile
26
+ - rvm: 2.4.0
27
+ gemfile: gemfiles/rails_3.2.gemfile
28
+ - rvm: 2.4.0
29
+ gemfile: gemfiles/rails_4.0.gemfile
30
+ - rvm: 2.4.0
31
+ gemfile: gemfiles/rails_4.1.gemfile
22
32
 
23
33
  services:
24
34
  - docker
data/Appraisals CHANGED
@@ -18,3 +18,7 @@ end
18
18
  appraise 'rails-5.0' do
19
19
  gem 'rails', '5.0.1'
20
20
  end
21
+
22
+ appraise 'active-record-5.0' do
23
+ gem 'activerecord', '5.0.2'
24
+ end
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.4.1 2017-03-23
4
+
5
+ * Allow use outside of Rails, e.g. when using Sinatra with ActiveRecord [@nathanstitt](https://github.com/nathanstitt) [#5](https://github.com/citusdata/activerecord-multi-tenant/pull/5)
6
+
7
+
3
8
  ## 0.4.0 2017-03-22
4
9
 
5
10
  * Infer multi_tenant setting from parent classes [@webandtech](https://github.com/webandtech) [#6](https://github.com/citusdata/activerecord-multi-tenant/pull/6)
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- activerecord-multi-tenant (0.4.0)
4
+ activerecord-multi-tenant (0.4.1)
5
5
  rails (>= 3.1)
6
6
  request_store (>= 1.0.5)
7
7
 
@@ -0,0 +1,8 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "appraisal"
6
+ gem "activerecord", "5.0.2"
7
+
8
+ gemspec :path => "../"
@@ -0,0 +1,154 @@
1
+ PATH
2
+ remote: ../
3
+ specs:
4
+ activerecord-multi-tenant (0.4.1)
5
+ rails (>= 3.1)
6
+ request_store (>= 1.0.5)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ actioncable (5.0.2)
12
+ actionpack (= 5.0.2)
13
+ nio4r (>= 1.2, < 3.0)
14
+ websocket-driver (~> 0.6.1)
15
+ actionmailer (5.0.2)
16
+ actionpack (= 5.0.2)
17
+ actionview (= 5.0.2)
18
+ activejob (= 5.0.2)
19
+ mail (~> 2.5, >= 2.5.4)
20
+ rails-dom-testing (~> 2.0)
21
+ actionpack (5.0.2)
22
+ actionview (= 5.0.2)
23
+ activesupport (= 5.0.2)
24
+ rack (~> 2.0)
25
+ rack-test (~> 0.6.3)
26
+ rails-dom-testing (~> 2.0)
27
+ rails-html-sanitizer (~> 1.0, >= 1.0.2)
28
+ actionview (5.0.2)
29
+ activesupport (= 5.0.2)
30
+ builder (~> 3.1)
31
+ erubis (~> 2.7.0)
32
+ rails-dom-testing (~> 2.0)
33
+ rails-html-sanitizer (~> 1.0, >= 1.0.3)
34
+ activejob (5.0.2)
35
+ activesupport (= 5.0.2)
36
+ globalid (>= 0.3.6)
37
+ activemodel (5.0.2)
38
+ activesupport (= 5.0.2)
39
+ activerecord (5.0.2)
40
+ activemodel (= 5.0.2)
41
+ activesupport (= 5.0.2)
42
+ arel (~> 7.0)
43
+ activesupport (5.0.2)
44
+ concurrent-ruby (~> 1.0, >= 1.0.2)
45
+ i18n (~> 0.7)
46
+ minitest (~> 5.1)
47
+ tzinfo (~> 1.1)
48
+ appraisal (2.1.0)
49
+ bundler
50
+ rake
51
+ thor (>= 0.14.0)
52
+ arel (7.1.4)
53
+ builder (3.2.3)
54
+ concurrent-ruby (1.0.5)
55
+ database_cleaner (1.3.0)
56
+ diff-lcs (1.3)
57
+ erubis (2.7.0)
58
+ globalid (0.3.7)
59
+ activesupport (>= 4.1.0)
60
+ i18n (0.8.1)
61
+ loofah (2.0.3)
62
+ nokogiri (>= 1.5.9)
63
+ mail (2.6.4)
64
+ mime-types (>= 1.16, < 4)
65
+ method_source (0.8.2)
66
+ mime-types (3.1)
67
+ mime-types-data (~> 3.2015)
68
+ mime-types-data (3.2016.0521)
69
+ mini_portile2 (2.1.0)
70
+ minitest (5.10.1)
71
+ nio4r (2.0.0)
72
+ nokogiri (1.7.1)
73
+ mini_portile2 (~> 2.1.0)
74
+ pg (0.20.0)
75
+ rack (2.0.1)
76
+ rack-test (0.6.3)
77
+ rack (>= 1.0)
78
+ rails (5.0.2)
79
+ actioncable (= 5.0.2)
80
+ actionmailer (= 5.0.2)
81
+ actionpack (= 5.0.2)
82
+ actionview (= 5.0.2)
83
+ activejob (= 5.0.2)
84
+ activemodel (= 5.0.2)
85
+ activerecord (= 5.0.2)
86
+ activesupport (= 5.0.2)
87
+ bundler (>= 1.3.0, < 2.0)
88
+ railties (= 5.0.2)
89
+ sprockets-rails (>= 2.0.0)
90
+ rails-dom-testing (2.0.2)
91
+ activesupport (>= 4.2.0, < 6.0)
92
+ nokogiri (~> 1.6)
93
+ rails-html-sanitizer (1.0.3)
94
+ loofah (~> 2.0)
95
+ railties (5.0.2)
96
+ actionpack (= 5.0.2)
97
+ activesupport (= 5.0.2)
98
+ method_source
99
+ rake (>= 0.8.7)
100
+ thor (>= 0.18.1, < 2.0)
101
+ rake (12.0.0)
102
+ request_store (1.3.2)
103
+ rspec (3.5.0)
104
+ rspec-core (~> 3.5.0)
105
+ rspec-expectations (~> 3.5.0)
106
+ rspec-mocks (~> 3.5.0)
107
+ rspec-core (3.5.4)
108
+ rspec-support (~> 3.5.0)
109
+ rspec-expectations (3.5.0)
110
+ diff-lcs (>= 1.2.0, < 2.0)
111
+ rspec-support (~> 3.5.0)
112
+ rspec-mocks (3.5.0)
113
+ diff-lcs (>= 1.2.0, < 2.0)
114
+ rspec-support (~> 3.5.0)
115
+ rspec-rails (3.5.2)
116
+ actionpack (>= 3.0)
117
+ activesupport (>= 3.0)
118
+ railties (>= 3.0)
119
+ rspec-core (~> 3.5.0)
120
+ rspec-expectations (~> 3.5.0)
121
+ rspec-mocks (~> 3.5.0)
122
+ rspec-support (~> 3.5.0)
123
+ rspec-support (3.5.0)
124
+ sprockets (3.7.1)
125
+ concurrent-ruby (~> 1.0)
126
+ rack (> 1, < 3)
127
+ sprockets-rails (3.2.0)
128
+ actionpack (>= 4.0)
129
+ activesupport (>= 4.0)
130
+ sprockets (>= 3.0.0)
131
+ thor (0.19.4)
132
+ thread_safe (0.3.6)
133
+ tzinfo (1.2.2)
134
+ thread_safe (~> 0.1)
135
+ websocket-driver (0.6.5)
136
+ websocket-extensions (>= 0.1.0)
137
+ websocket-extensions (0.1.2)
138
+
139
+ PLATFORMS
140
+ ruby
141
+
142
+ DEPENDENCIES
143
+ activerecord (= 5.0.2)
144
+ activerecord-multi-tenant!
145
+ appraisal
146
+ database_cleaner (~> 1.3.0)
147
+ pg
148
+ rake
149
+ rspec (>= 3.0)
150
+ rspec-rails
151
+ thor
152
+
153
+ BUNDLED WITH
154
+ 1.14.5
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ../
3
3
  specs:
4
- activerecord-multi-tenant (0.4.0)
4
+ activerecord-multi-tenant (0.4.1)
5
5
  rails (>= 3.1)
6
6
  request_store (>= 1.0.5)
7
7
 
@@ -115,7 +115,7 @@ GEM
115
115
  treetop (1.4.15)
116
116
  polyglot
117
117
  polyglot (>= 0.3.1)
118
- tzinfo (0.3.52)
118
+ tzinfo (0.3.53)
119
119
 
120
120
  PLATFORMS
121
121
  ruby
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ../
3
3
  specs:
4
- activerecord-multi-tenant (0.4.0)
4
+ activerecord-multi-tenant (0.4.1)
5
5
  rails (>= 3.1)
6
6
  request_store (>= 1.0.5)
7
7
 
@@ -99,7 +99,7 @@ GEM
99
99
  sprockets (>= 2.8, < 4.0)
100
100
  thor (0.19.4)
101
101
  thread_safe (0.3.6)
102
- tzinfo (0.3.52)
102
+ tzinfo (0.3.53)
103
103
 
104
104
  PLATFORMS
105
105
  ruby
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ../
3
3
  specs:
4
- activerecord-multi-tenant (0.4.0)
4
+ activerecord-multi-tenant (0.4.1)
5
5
  rails (>= 3.1)
6
6
  request_store (>= 1.0.5)
7
7
 
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ../
3
3
  specs:
4
- activerecord-multi-tenant (0.4.0)
4
+ activerecord-multi-tenant (0.4.1)
5
5
  rails (>= 3.1)
6
6
  request_store (>= 1.0.5)
7
7
 
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ../
3
3
  specs:
4
- activerecord-multi-tenant (0.4.0)
4
+ activerecord-multi-tenant (0.4.1)
5
5
  rails (>= 3.1)
6
6
  request_store (>= 1.0.5)
7
7
 
@@ -1,9 +1,11 @@
1
- require 'activerecord-multi-tenant/controller_extensions'
2
- require 'activerecord-multi-tenant/copy_from_client'
3
- require 'activerecord-multi-tenant/default_scope'
4
- require 'activerecord-multi-tenant/migrations'
5
- require 'activerecord-multi-tenant/model_extensions'
6
- require 'activerecord-multi-tenant/multi_tenant'
7
- require 'activerecord-multi-tenant/referential_integrity'
8
- require 'activerecord-multi-tenant/version'
9
- require 'activerecord-multi-tenant/with_lock'
1
+ if Object.const_defined?(:ActionController)
2
+ require_relative 'activerecord-multi-tenant/controller_extensions'
3
+ end
4
+ require_relative 'activerecord-multi-tenant/copy_from_client'
5
+ require_relative 'activerecord-multi-tenant/default_scope'
6
+ require_relative 'activerecord-multi-tenant/migrations'
7
+ require_relative 'activerecord-multi-tenant/model_extensions'
8
+ require_relative 'activerecord-multi-tenant/multi_tenant'
9
+ require_relative 'activerecord-multi-tenant/referential_integrity'
10
+ require_relative 'activerecord-multi-tenant/version'
11
+ require_relative 'activerecord-multi-tenant/with_lock'
@@ -1,3 +1,5 @@
1
+ require 'active_record'
2
+
1
3
  class ActiveRecord::Base
2
4
  class << self
3
5
  alias :unscoped_orig :unscoped
@@ -45,7 +45,7 @@ module MultiTenant
45
45
  if MultiTenant.current_tenant_id
46
46
  where(arel_table[partition_key].eq(MultiTenant.current_tenant_id))
47
47
  else
48
- Rails::VERSION::MAJOR < 4 ? scoped : all
48
+ ActiveRecord::VERSION::MAJOR < 4 ? scoped : all
49
49
  end
50
50
  }
51
51
 
@@ -1,3 +1,3 @@
1
1
  module MultiTenant
2
- VERSION = '0.4.0'
2
+ VERSION = '0.4.1'
3
3
  end
@@ -6,7 +6,7 @@ class ActiveRecord::Base
6
6
  def lock!(lock = true)
7
7
  if lock && persisted? && self.class.respond_to?(:scoped_by_tenant?) && MultiTenant.current_tenant_id && MultiTenant.with_lock_workaround_enabled?
8
8
  self.class.unscoped.where(id: id).update_all(id: id) # No-op UPDATE that locks the row
9
- reload # This is just to act similar to the default Rails approach, in case someone relies on the reload
9
+ reload # This is just to act similar to the default ActiveRecord approach, in case someone relies on the reload
10
10
  self
11
11
  else
12
12
  lock_orig(lock)
@@ -1,48 +1,19 @@
1
1
  require 'spec_helper'
2
2
 
3
- class Account
4
- attr_accessor :name
5
- end
6
-
7
- class ApplicationController < ActionController::Base
8
- include Rails.application.routes.url_helpers
9
- set_current_tenant_through_filter
10
-
11
- if Rails::VERSION::MAJOR < 4
12
- before_filter :your_method_that_finds_the_current_tenant
13
- else
14
- before_action :your_method_that_finds_the_current_tenant
3
+ describe "Controller Extensions", type: :controller do
4
+ class Account
5
+ attr_accessor :name
15
6
  end
16
7
 
17
- def your_method_that_finds_the_current_tenant
18
- current_account = Account.new
19
- current_account.name = 'account1'
20
- set_current_tenant(current_account)
21
- end
22
- end
23
-
24
- describe ApplicationController, type: :controller do
25
- controller do
26
- def index
27
- if Rails::VERSION::MAJOR >= 5
28
- render body: 'custom called'
29
- else
30
- render text: 'custom called'
31
- end
32
- end
33
- end
34
-
35
- it 'Finds the correct tenant using the filter command' do
36
- get :index
37
- expect(MultiTenant.current_tenant.name).to eq 'account1'
38
- end
39
- end
40
-
41
- if Rails::VERSION::MAJOR >= 5
42
- class APIApplicationController < ActionController::API
8
+ class ApplicationController < ActionController::Base
43
9
  include Rails.application.routes.url_helpers
44
10
  set_current_tenant_through_filter
45
- before_action :your_method_that_finds_the_current_tenant
11
+
12
+ if ActionPack::VERSION::MAJOR < 4
13
+ before_filter :your_method_that_finds_the_current_tenant
14
+ else
15
+ before_action :your_method_that_finds_the_current_tenant
16
+ end
46
17
 
47
18
  def your_method_that_finds_the_current_tenant
48
19
  current_account = Account.new
@@ -51,10 +22,14 @@ if Rails::VERSION::MAJOR >= 5
51
22
  end
52
23
  end
53
24
 
54
- describe APIApplicationController, type: :controller do
25
+ describe ApplicationController, type: :controller do
55
26
  controller do
56
27
  def index
57
- render body: 'custom called'
28
+ if ActionPack::VERSION::MAJOR >= 5
29
+ render body: 'custom called'
30
+ else
31
+ render text: 'custom called'
32
+ end
58
33
  end
59
34
  end
60
35
 
@@ -63,4 +38,31 @@ if Rails::VERSION::MAJOR >= 5
63
38
  expect(MultiTenant.current_tenant.name).to eq 'account1'
64
39
  end
65
40
  end
41
+
42
+ if ActionPack::VERSION::MAJOR >= 5
43
+ class APIApplicationController < ActionController::API
44
+ include Rails.application.routes.url_helpers
45
+ set_current_tenant_through_filter
46
+ before_action :your_method_that_finds_the_current_tenant
47
+
48
+ def your_method_that_finds_the_current_tenant
49
+ current_account = Account.new
50
+ current_account.name = 'account1'
51
+ set_current_tenant(current_account)
52
+ end
53
+ end
54
+
55
+ describe APIApplicationController, type: :controller do
56
+ controller do
57
+ def index
58
+ render body: 'custom called'
59
+ end
60
+ end
61
+
62
+ it 'Finds the correct tenant using the filter command' do
63
+ get :index
64
+ expect(MultiTenant.current_tenant.name).to eq 'account1'
65
+ end
66
+ end
67
+ end
66
68
  end
data/spec/schema.rb CHANGED
@@ -83,7 +83,7 @@ class Project < ActiveRecord::Base
83
83
  has_many :tasks
84
84
  has_many :sub_tasks, through: :tasks
85
85
 
86
- if Rails::VERSION::MAJOR < 4
86
+ if ActiveRecord::VERSION::MAJOR < 4
87
87
  validates_uniqueness_of :name, scope: [:account_id]
88
88
  else
89
89
  validates_uniqueness_of :name, scope: [:account]
@@ -126,7 +126,7 @@ end
126
126
  class CustomPartitionKeyTask < ActiveRecord::Base
127
127
  multi_tenant :account, partition_key: 'accountID'
128
128
 
129
- if Rails::VERSION::MAJOR < 4
129
+ if ActiveRecord::VERSION::MAJOR < 4
130
130
  validates_uniqueness_of :name, scope: [:accountID]
131
131
  else
132
132
  validates_uniqueness_of :name, scope: [:account]
@@ -141,7 +141,7 @@ class Comment < ActiveRecord::Base
141
141
  multi_tenant :account
142
142
  belongs_to :commentable, polymorphic: true
143
143
 
144
- if Rails::VERSION::MAJOR >= 4
144
+ if ActiveRecord::VERSION::MAJOR >= 4
145
145
  belongs_to :task, -> { where(comments: { commentable_type: 'Task' }) }, foreign_key: 'commentable_id'
146
146
  end
147
147
  end
data/spec/spec_helper.rb CHANGED
@@ -15,6 +15,7 @@ ActiveRecord::Base.establish_connection(dbconfig['test'])
15
15
  RSpec.configure do |config|
16
16
  config.infer_base_class_for_anonymous_controllers = true
17
17
  config.use_transactional_fixtures = false
18
+ config.filter_run_excluding type: :controller unless Object.const_defined?(:ActionController)
18
19
 
19
20
  config.after(:each) do
20
21
  MultiTenant.current_tenant = nil
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord-multi-tenant
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Citus Data
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-03-23 00:00:00.000000000 Z
11
+ date: 2017-03-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: request_store
@@ -138,6 +138,8 @@ files:
138
138
  - Rakefile
139
139
  - activerecord-multi-tenant.gemspec
140
140
  - docker-compose.yml
141
+ - gemfiles/active_record_5.0.gemfile
142
+ - gemfiles/active_record_5.0.gemfile.lock
141
143
  - gemfiles/rails_3.2.gemfile
142
144
  - gemfiles/rails_3.2.gemfile.lock
143
145
  - gemfiles/rails_4.0.gemfile