rails_multitenant 0.3.1 → 0.4.0

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: 0d9d1830ec790f9afd698f90dab03a3758940e64
4
- data.tar.gz: a2e30e84291bc0080fbf75be97b676f576e2347c
3
+ metadata.gz: ff528a38b03db9f83d9665fc802a577fa10cc0cb
4
+ data.tar.gz: d75fb03a0907977a6f18cf1fdc8a32a183179e88
5
5
  SHA512:
6
- metadata.gz: db8809d3660df19cae83d21b9e39d6f816c85eef587890a04042c0bdeb36a0919a052158cef1fc47b59d4741b18d71f9209a17cb3191ec0796ee8efeac09a177
7
- data.tar.gz: d188d1dbabb872fca6ec705714a704cbf3c87513d37fb88357f680637f8aba242519b460479042133f30819506e9f73127e584e57de6529f2bab98b3375422c3
6
+ metadata.gz: a3fd2430828d14280bd19414b20079814babd2ae01d67eb783b2130e2ddb029bde5521ee3dd6cec73ed2e7150637be99ab83c4d635db0d450f072ec28a3a8688
7
+ data.tar.gz: dd556073c42ef36665285a03018e2042375b815195a879687ddbe8c65d79f643a612c359425d88d6f006e0f16813b34c3e95e4d519af82cf79409b8b4c5ce43a
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --color
2
+ --format documentation
3
+ --require spec_helper
data/.travis.yml CHANGED
@@ -1,10 +1,9 @@
1
1
  language: ruby
2
2
  sudo: false
3
3
  env:
4
- - RAILS_VERSION="~> 3.2.22"
5
- - RAILS_VERSION="~> 4.0.13"
6
- - RAILS_VERSION="~> 4.1.13"
7
- - RAILS_VERSION="~> 4.2.4"
4
+ - RAILS_VERSION="~> 4.1.16"
5
+ - RAILS_VERSION="~> 4.2.7"
6
+ - RAILS_VERSION="~> 5.0.0"
8
7
  rvm:
9
- - 2.2.3
10
- before_install: gem install bundler -v 1.10.6
8
+ - 2.3.1
9
+ before_install: gem install bundler -v 1.12.5
data/CHANGELOG.md CHANGED
@@ -1,6 +1,11 @@
1
1
  # Changelog
2
2
 
3
- ### 0.3.1 (unreleased)
3
+ ### 0.4.0
4
+ * Fix be_multitenant_on matcher to handle models that don't include the `RailsMultitenant::MultitenantModel` module.
5
+ * Fix `context_entity_id_field` to work with inheritance.
6
+ * Drop Rails 3.2 and 4.0 support since `unscope` doesn't work propertly with default scopes.
7
+
8
+ ### 0.3.1
4
9
  * Fix strip_<entity>_scope
5
10
 
6
11
  ### 0.3.0
@@ -3,9 +3,7 @@ module RailsMultitenant
3
3
  extend ActiveSupport::Concern
4
4
 
5
5
  included do
6
- class << self
7
- attr_accessor :context_entity_id_field
8
- end
6
+ class_attribute :context_entity_id_field
9
7
  end
10
8
 
11
9
  module ClassMethods
@@ -1,5 +1,5 @@
1
1
  RSpec::Matchers.define(:be_multitenant_on) do |expected|
2
2
  match do |actual|
3
- actual.context_entity_id_field == expected
3
+ actual.respond_to?(:context_entity_id_field) && actual.context_entity_id_field == expected
4
4
  end
5
5
  end
@@ -1,3 +1,3 @@
1
1
  module RailsMultitenant
2
- VERSION = '0.3.1'
2
+ VERSION = '0.4.0'
3
3
  end
@@ -19,8 +19,8 @@ Gem::Specification.new do |spec|
19
19
 
20
20
  spec.add_development_dependency "bundler", "~> 1.10"
21
21
 
22
- spec.add_dependency 'activerecord', ENV.fetch('RAILS_VERSION', ['>= 3.2', '< 4.3'])
23
- spec.add_dependency 'activesupport', ENV.fetch('RAILS_VERSION', ['>= 3.2', '< 4.3'])
22
+ spec.add_dependency 'activerecord', ENV.fetch('RAILS_VERSION', ['>= 4.1', '< 5.1'])
23
+ spec.add_dependency 'activesupport', ENV.fetch('RAILS_VERSION', ['>= 4.1', '< 5.1'])
24
24
 
25
25
  spec.add_development_dependency 'coveralls'
26
26
  spec.add_development_dependency 'database_cleaner', '>= 1.2'
@@ -1,4 +1,3 @@
1
- require 'spec_helper'
2
1
  require 'rails_multitenant/rspec'
3
2
 
4
3
  describe "be_multitenant_on matcher" do
@@ -9,4 +8,8 @@ describe "be_multitenant_on matcher" do
9
8
  it "rejects an invalid context field id" do
10
9
  expect(ExternalItem).not_to be_multitenant_on(:other_field)
11
10
  end
11
+
12
+ it "rejects classes that don't have a context field id" do
13
+ expect(String).not_to be_multitenant_on(:other_field)
14
+ end
12
15
  end
data/spec/db/schema.rb CHANGED
@@ -6,6 +6,7 @@ ActiveRecord::Schema.define(version: 0) do
6
6
 
7
7
  create_table(:items, force: true) do |t|
8
8
  t.integer :organization_id
9
+ t.string :type
9
10
  end
10
11
 
11
12
  create_table(:external_items, force: true) do |t|
@@ -22,6 +23,10 @@ class Item < ActiveRecord::Base
22
23
  multitenant_on_model :organization
23
24
  end
24
25
 
26
+ class ItemSubtype < Item
27
+
28
+ end
29
+
25
30
  class ExternalItem < ActiveRecord::Base
26
31
  include RailsMultitenant::MultitenantModel
27
32
  multitenant_on :external_organization_id
@@ -1,4 +1,3 @@
1
- require 'spec_helper'
2
1
  include RailsMultitenant
3
2
 
4
3
  describe ExternalItem do
@@ -1,4 +1,3 @@
1
- require 'spec_helper'
2
1
  include RailsMultitenant
3
2
 
4
3
  describe GlobalContextRegistry do
data/spec/item_spec.rb CHANGED
@@ -2,8 +2,6 @@
2
2
  # Create an item in each
3
3
  # Make sure you can only see one org's item in one org
4
4
 
5
- require 'spec_helper'
6
-
7
5
  describe Item do
8
6
 
9
7
  let!(:item1) { Item.create! }
@@ -0,0 +1,37 @@
1
+ # Create multiple orgs
2
+ # Create an item in each
3
+ # Make sure you can only see one org's item in one org
4
+
5
+ describe ItemSubtype do
6
+
7
+ let!(:item1) { ItemSubtype.create! }
8
+
9
+ let!(:org2) { Organization.create! }
10
+ let!(:item2) { org2.as_current { ItemSubtype.create! } }
11
+ let!(:item3) { org2.as_current { ItemSubtype.create! } }
12
+
13
+ it 'inherits the multitenant settings from its parent class' do
14
+ expect(ItemSubtype).to be_multitenant_on(:organization_id)
15
+ end
16
+
17
+ specify 'default org should have one item' do
18
+ expect(ItemSubtype.all).to eq([item1])
19
+ end
20
+
21
+ it 'does not return item2' do
22
+ expect(ItemSubtype.where(id: item2.id)).to eq([])
23
+ end
24
+
25
+ specify 'org2 should have two items' do
26
+ org2.as_current do
27
+ expect(ItemSubtype.all).to eq([item2, item3])
28
+ end
29
+ end
30
+
31
+ it 'does not return item1' do
32
+ org2.as_current do
33
+ expect(ItemSubtype.where(id: item1.id)).to eq([])
34
+ end
35
+ end
36
+
37
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_multitenant
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pat Breault
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-05-02 00:00:00.000000000 Z
11
+ date: 2016-07-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -30,40 +30,40 @@ dependencies:
30
30
  requirements:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: '3.2'
33
+ version: '4.1'
34
34
  - - "<"
35
35
  - !ruby/object:Gem::Version
36
- version: '4.3'
36
+ version: '5.1'
37
37
  type: :runtime
38
38
  prerelease: false
39
39
  version_requirements: !ruby/object:Gem::Requirement
40
40
  requirements:
41
41
  - - ">="
42
42
  - !ruby/object:Gem::Version
43
- version: '3.2'
43
+ version: '4.1'
44
44
  - - "<"
45
45
  - !ruby/object:Gem::Version
46
- version: '4.3'
46
+ version: '5.1'
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: activesupport
49
49
  requirement: !ruby/object:Gem::Requirement
50
50
  requirements:
51
51
  - - ">="
52
52
  - !ruby/object:Gem::Version
53
- version: '3.2'
53
+ version: '4.1'
54
54
  - - "<"
55
55
  - !ruby/object:Gem::Version
56
- version: '4.3'
56
+ version: '5.1'
57
57
  type: :runtime
58
58
  prerelease: false
59
59
  version_requirements: !ruby/object:Gem::Requirement
60
60
  requirements:
61
61
  - - ">="
62
62
  - !ruby/object:Gem::Version
63
- version: '3.2'
63
+ version: '4.1'
64
64
  - - "<"
65
65
  - !ruby/object:Gem::Version
66
- version: '4.3'
66
+ version: '5.1'
67
67
  - !ruby/object:Gem::Dependency
68
68
  name: coveralls
69
69
  requirement: !ruby/object:Gem::Requirement
@@ -156,6 +156,7 @@ extensions: []
156
156
  extra_rdoc_files: []
157
157
  files:
158
158
  - ".gitignore"
159
+ - ".rspec"
159
160
  - ".ruby-version"
160
161
  - ".travis.yml"
161
162
  - CHANGELOG.md
@@ -177,6 +178,7 @@ files:
177
178
  - spec/external_item_spec.rb
178
179
  - spec/global_context_registry_spec.rb
179
180
  - spec/item_spec.rb
181
+ - spec/item_subtype_spec.rb
180
182
  - spec/spec_helper.rb
181
183
  homepage: https://github.com/salsify/rails_multitenant
182
184
  licenses:
@@ -209,4 +211,5 @@ test_files:
209
211
  - spec/external_item_spec.rb
210
212
  - spec/global_context_registry_spec.rb
211
213
  - spec/item_spec.rb
214
+ - spec/item_subtype_spec.rb
212
215
  - spec/spec_helper.rb