tenancy 0.2.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
metadata CHANGED
@@ -1,141 +1,83 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tenancy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
- - chamnap
7
+ - Chamnap Chhorn
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-11-13 00:00:00.000000000 Z
11
+ date: 2014-02-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: rspec
14
+ name: activesupport
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 2.12.0
20
- type: :development
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - ~>
25
- - !ruby/object:Gem::Version
26
- version: 2.12.0
27
- - !ruby/object:Gem::Dependency
28
- name: shoulda
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ~>
32
- - !ruby/object:Gem::Version
33
- version: 3.5.0
34
- type: :development
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - ~>
39
- - !ruby/object:Gem::Version
40
- version: 3.5.0
41
- - !ruby/object:Gem::Dependency
42
- name: pry
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - ~>
46
- - !ruby/object:Gem::Version
47
- version: 0.9.12
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - ~>
53
- - !ruby/object:Gem::Version
54
- version: 0.9.12
55
- - !ruby/object:Gem::Dependency
56
- name: sqlite3
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - ~>
60
- - !ruby/object:Gem::Version
61
- version: 1.3.7
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - ~>
67
- - !ruby/object:Gem::Version
68
- version: 1.3.7
69
- - !ruby/object:Gem::Dependency
70
- name: rake
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - '>='
74
- - !ruby/object:Gem::Version
75
- version: '0'
76
- type: :development
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - '>='
81
- - !ruby/object:Gem::Version
82
- version: '0'
83
- - !ruby/object:Gem::Dependency
84
- name: activerecord
85
- requirement: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - '>='
88
- - !ruby/object:Gem::Version
89
- version: 3.2.13
19
+ version: '3.2'
90
20
  type: :runtime
91
21
  prerelease: false
92
22
  version_requirements: !ruby/object:Gem::Requirement
93
23
  requirements:
94
- - - '>='
24
+ - - ">="
95
25
  - !ruby/object:Gem::Version
96
- version: 3.2.13
26
+ version: '3.2'
97
27
  - !ruby/object:Gem::Dependency
98
28
  name: request_store
99
29
  requirement: !ruby/object:Gem::Requirement
100
30
  requirements:
101
- - - ~>
31
+ - - "~>"
102
32
  - !ruby/object:Gem::Version
103
33
  version: 1.0.5
104
34
  type: :runtime
105
35
  prerelease: false
106
36
  version_requirements: !ruby/object:Gem::Requirement
107
37
  requirements:
108
- - - ~>
38
+ - - "~>"
109
39
  - !ruby/object:Gem::Version
110
40
  version: 1.0.5
111
- description: A simple multitenancy with activerecord through scoping
41
+ description: A simple multitenancy with activerecord/mongoid through scoping
112
42
  email:
113
43
  - chamnapchhorn@gmail.com
114
44
  executables: []
115
45
  extensions: []
116
46
  extra_rdoc_files: []
117
47
  files:
118
- - .gitignore
119
- - .rspec
120
- - .rvmrc
121
- - .travis.yml
48
+ - ".coveralls.yml"
49
+ - ".gitignore"
50
+ - ".rspec"
51
+ - ".rvmrc"
52
+ - ".travis.yml"
53
+ - CHANGELOG.md
122
54
  - Gemfile
123
55
  - LICENSE.txt
124
56
  - README.md
125
57
  - Rakefile
126
58
  - gemfiles/active_record_32.gemfile
127
59
  - gemfiles/active_record_40.gemfile
60
+ - gemfiles/mongoid_3.gemfile
61
+ - gemfiles/mongoid_4.gemfile
128
62
  - lib/tenancy.rb
129
63
  - lib/tenancy/matchers.rb
130
64
  - lib/tenancy/resource.rb
131
65
  - lib/tenancy/resource_scope.rb
66
+ - lib/tenancy/scoping.rb
67
+ - lib/tenancy/scoping/active_record.rb
68
+ - lib/tenancy/scoping/mongoid.rb
69
+ - lib/tenancy/tenant.rb
132
70
  - lib/tenancy/version.rb
133
- - spec/lib/resource_scope_spec.rb
134
71
  - spec/lib/resource_spec.rb
72
+ - spec/lib/scoping/active_record_spec.rb
73
+ - spec/lib/scoping/mongoid_spec.rb
135
74
  - spec/lib/shoulda_matchers_spec.rb
136
75
  - spec/spec_helper.rb
137
- - spec/support/models.rb
138
- - spec/support/schema.rb
76
+ - spec/support/active_record/models.rb
77
+ - spec/support/active_record/schema.rb
78
+ - spec/support/mongoid/connection.rb
79
+ - spec/support/mongoid/models.rb
80
+ - spec/support/mongoid/mongoid.yml
139
81
  - tenancy.gemspec
140
82
  homepage: https://github.com/yoolk/tenancy
141
83
  licenses:
@@ -147,24 +89,28 @@ require_paths:
147
89
  - lib
148
90
  required_ruby_version: !ruby/object:Gem::Requirement
149
91
  requirements:
150
- - - '>='
92
+ - - ">="
151
93
  - !ruby/object:Gem::Version
152
- version: '0'
94
+ version: 1.9.3
153
95
  required_rubygems_version: !ruby/object:Gem::Requirement
154
96
  requirements:
155
- - - '>='
97
+ - - ">="
156
98
  - !ruby/object:Gem::Version
157
- version: '0'
99
+ version: 1.8.11
158
100
  requirements: []
159
101
  rubyforge_project:
160
- rubygems_version: 2.1.10
102
+ rubygems_version: 2.2.0
161
103
  signing_key:
162
104
  specification_version: 4
163
- summary: A simple multitenancy with activerecord through scoping
105
+ summary: A simple multitenancy with activerecord/mongoid through scoping
164
106
  test_files:
165
- - spec/lib/resource_scope_spec.rb
166
107
  - spec/lib/resource_spec.rb
108
+ - spec/lib/scoping/active_record_spec.rb
109
+ - spec/lib/scoping/mongoid_spec.rb
167
110
  - spec/lib/shoulda_matchers_spec.rb
168
111
  - spec/spec_helper.rb
169
- - spec/support/models.rb
170
- - spec/support/schema.rb
112
+ - spec/support/active_record/models.rb
113
+ - spec/support/active_record/schema.rb
114
+ - spec/support/mongoid/connection.rb
115
+ - spec/support/mongoid/models.rb
116
+ - spec/support/mongoid/mongoid.yml
@@ -1,125 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe "Tenancy::ResourceScope" do
4
- let(:camyp) { Portal.create(domain_name: 'yp.com.kh') }
5
- let(:panpages) { Portal.create(domain_name: 'panpages.com') }
6
- let(:listing) { Listing.create(name: 'Listing 1', portal_id: camyp.id) }
7
-
8
- after(:all) do
9
- Portal.delete_all
10
- end
11
-
12
- describe Listing do
13
- it { should belong_to(:portal) }
14
-
15
- it { should validate_presence_of(:portal) }
16
-
17
- it { should validate_uniqueness_of(:name).scoped_to(:portal_id).case_insensitive }
18
-
19
- it "have default_scope with :portal_id field" do
20
- Portal.current = camyp
21
-
22
- expect(Listing.where(nil).to_sql).to eq(Listing.where(portal_id: Portal.current_id).to_sql)
23
- end
24
-
25
- it "doesn't have default_scope when it doesn't have current portal" do
26
- Portal.current = nil
27
-
28
- expect(Listing.where(nil).to_sql).not_to include(%{"listings"."portal_id" = #{Portal.current_id}})
29
- end
30
- end
31
-
32
- describe Communication do
33
- it { should belong_to(:portal) }
34
-
35
- it { should validate_presence_of(:portal) }
36
-
37
- it { should belong_to(:listing) }
38
-
39
- it { should validate_presence_of(:listing) }
40
-
41
- it { should validate_uniqueness_of(:value).scoped_to(:portal_id, :listing_id) }
42
-
43
- it "have default_scope with :portal_id field" do
44
- Portal.current = camyp
45
- Listing.current = listing
46
-
47
- Communication.where(nil).to_sql.should == Communication.where(portal_id: Portal.current_id, listing_id: Listing.current_id).to_sql
48
- end
49
-
50
- it "doesn't have default_scope when it doesn't have current portal and listing" do
51
- Portal.current = nil
52
- Listing.current = nil
53
-
54
- expect(Communication.where(nil).to_sql).not_to include(%{"communications"."portal_id" = #{Portal.current_id}})
55
- expect(Communication.where(nil).to_sql).not_to include(%{"communications"."listing_id" = #{Listing.current_id}})
56
- end
57
- end
58
-
59
- describe ExtraCommunication do
60
- it { should belong_to(:portal) }
61
-
62
- it { should belong_to(:listing) }
63
-
64
- it "raise exception when passing two resources and options" do
65
- expect { ExtraCommunication.scope_to(:portal, :listing, class_name: 'Listing') }.to raise_error(ArgumentError)
66
- end
67
-
68
- it "uses the correct scope" do
69
- listing2 = Listing.create(name: 'Name 2', portal: camyp)
70
-
71
- Portal.current = camyp
72
- Listing.current = listing2
73
-
74
- extra_communication = ExtraCommunication.new
75
- expect(extra_communication.listing_id).to eq(listing2.id)
76
- expect(extra_communication.portal_id).to eq(camyp.id)
77
- end
78
- end
79
-
80
- describe "belongs_to method override" do
81
- before(:each) { Portal.current = camyp }
82
- after(:each) { Portal.current = nil }
83
-
84
- it "reload belongs_to when passes true" do
85
- listing.portal.domain_name = 'abc.com'
86
- expect(listing.portal(true).object_id).not_to eq(Portal.current.object_id)
87
- end
88
-
89
- it "doesn't reload belongs_to" do
90
- listing.portal.domain_name = 'abc.com'
91
- expect(listing.portal.object_id).to eq(Portal.current.object_id)
92
- end
93
-
94
- it "returns different object" do
95
- listing.portal_id = panpages.id
96
- expect(listing.portal.object_id).not_to eq(Portal.current.object_id)
97
- end
98
-
99
- it "doesn't touch db" do
100
- current_listing = listing
101
-
102
- Portal.establish_connection(adapter: "sqlite3", database: "spec/invalid.sqlite3")
103
- expect(current_listing.portal.object_id).to eq(Portal.current.object_id)
104
-
105
- Portal.establish_connection(ActiveRecord::Base.connection_config)
106
- end
107
- end
108
-
109
- describe "#without_scope" do
110
- before(:each) { Portal.current = camyp }
111
- after(:each) { Portal.current = nil and Listing.current = nil }
112
-
113
- it "unscopes :current_portal" do
114
- expect(Listing.without_scope(:portal).to_sql).not_to include(%{"listings"."portal_id" = #{Portal.current_id}})
115
- end
116
-
117
- it "unscopes :current_portal and :current_listing" do
118
- Listing.current = listing
119
-
120
- expect(Communication.without_scope(:portal).to_sql).not_to include(%{"communications"."portal_id" = #{Portal.current_id}})
121
- expect(Communication.without_scope(:listing).to_sql).not_to include(%{"communications"."listing_id" = #{Listing.current_id}})
122
- expect(Communication.without_scope(:portal, :listing).to_sql).to eq(%{SELECT "communications".* FROM "communications" WHERE "communications"."is_active" = 't'})
123
- end
124
- end
125
- end