milia 0.3.7 → 0.3.8
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +31 -31
- data/VERSION +1 -1
- data/app/controllers/registrations_controller.rb +9 -0
- data/lib/milia/base.rb +42 -9
- data/milia.gemspec +3 -2
- data/pkg/milia-0.3.8.gem +0 -0
- data/test/rails_app/Gemfile.lock +1 -1
- data/test/rails_app/config/environments/test.rb +1 -1
- data/test/rails_app/test/factories/units_factory.rb +1 -1
- data/test/rails_app/test/test_helper.rb +5 -5
- data/test/rails_app/test/unit/post_test.rb +21 -4
- metadata +22 -21
data/Gemfile.lock
CHANGED
@@ -1,42 +1,42 @@
|
|
1
1
|
GEM
|
2
2
|
remote: http://rubygems.org/
|
3
3
|
specs:
|
4
|
-
actionmailer (3.1.
|
5
|
-
actionpack (= 3.1.
|
4
|
+
actionmailer (3.1.3)
|
5
|
+
actionpack (= 3.1.3)
|
6
6
|
mail (~> 2.3.0)
|
7
|
-
actionpack (3.1.
|
8
|
-
activemodel (= 3.1.
|
9
|
-
activesupport (= 3.1.
|
7
|
+
actionpack (3.1.3)
|
8
|
+
activemodel (= 3.1.3)
|
9
|
+
activesupport (= 3.1.3)
|
10
10
|
builder (~> 3.0.0)
|
11
11
|
erubis (~> 2.7.0)
|
12
12
|
i18n (~> 0.6)
|
13
|
-
rack (~> 1.3.
|
13
|
+
rack (~> 1.3.5)
|
14
14
|
rack-cache (~> 1.1)
|
15
15
|
rack-mount (~> 0.8.2)
|
16
16
|
rack-test (~> 0.6.1)
|
17
|
-
sprockets (~> 2.0.
|
18
|
-
activemodel (3.1.
|
19
|
-
activesupport (= 3.1.
|
17
|
+
sprockets (~> 2.0.3)
|
18
|
+
activemodel (3.1.3)
|
19
|
+
activesupport (= 3.1.3)
|
20
20
|
builder (~> 3.0.0)
|
21
21
|
i18n (~> 0.6)
|
22
|
-
activerecord (3.1.
|
23
|
-
activemodel (= 3.1.
|
24
|
-
activesupport (= 3.1.
|
22
|
+
activerecord (3.1.3)
|
23
|
+
activemodel (= 3.1.3)
|
24
|
+
activesupport (= 3.1.3)
|
25
25
|
arel (~> 2.2.1)
|
26
26
|
tzinfo (~> 0.3.29)
|
27
|
-
activeresource (3.1.
|
28
|
-
activemodel (= 3.1.
|
29
|
-
activesupport (= 3.1.
|
30
|
-
activesupport (3.1.
|
27
|
+
activeresource (3.1.3)
|
28
|
+
activemodel (= 3.1.3)
|
29
|
+
activesupport (= 3.1.3)
|
30
|
+
activesupport (3.1.3)
|
31
31
|
multi_json (~> 1.0)
|
32
|
-
ansi (1.
|
32
|
+
ansi (1.4.1)
|
33
33
|
arel (2.2.1)
|
34
34
|
bcrypt-ruby (3.0.1)
|
35
35
|
builder (3.0.0)
|
36
|
-
devise (1.
|
36
|
+
devise (1.5.1)
|
37
37
|
bcrypt-ruby (~> 3.0)
|
38
38
|
orm_adapter (~> 0.0.3)
|
39
|
-
warden (~> 1.
|
39
|
+
warden (~> 1.1)
|
40
40
|
erubis (2.7.0)
|
41
41
|
git (1.2.5)
|
42
42
|
hike (1.2.1)
|
@@ -64,17 +64,17 @@ GEM
|
|
64
64
|
rack
|
65
65
|
rack-test (0.6.1)
|
66
66
|
rack (>= 1.0)
|
67
|
-
rails (3.1.
|
68
|
-
actionmailer (= 3.1.
|
69
|
-
actionpack (= 3.1.
|
70
|
-
activerecord (= 3.1.
|
71
|
-
activeresource (= 3.1.
|
72
|
-
activesupport (= 3.1.
|
67
|
+
rails (3.1.3)
|
68
|
+
actionmailer (= 3.1.3)
|
69
|
+
actionpack (= 3.1.3)
|
70
|
+
activerecord (= 3.1.3)
|
71
|
+
activeresource (= 3.1.3)
|
72
|
+
activesupport (= 3.1.3)
|
73
73
|
bundler (~> 1.0)
|
74
|
-
railties (= 3.1.
|
75
|
-
railties (3.1.
|
76
|
-
actionpack (= 3.1.
|
77
|
-
activesupport (= 3.1.
|
74
|
+
railties (= 3.1.3)
|
75
|
+
railties (3.1.3)
|
76
|
+
actionpack (= 3.1.3)
|
77
|
+
activesupport (= 3.1.3)
|
78
78
|
rack-ssl (~> 1.3.2)
|
79
79
|
rake (>= 0.8.7)
|
80
80
|
rdoc (~> 3.4)
|
@@ -95,8 +95,8 @@ GEM
|
|
95
95
|
polyglot (>= 0.3.1)
|
96
96
|
turn (0.8.3)
|
97
97
|
ansi
|
98
|
-
tzinfo (0.3.
|
99
|
-
warden (1.0
|
98
|
+
tzinfo (0.3.31)
|
99
|
+
warden (1.1.0)
|
100
100
|
rack (>= 1.0)
|
101
101
|
|
102
102
|
PLATFORMS
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.3.
|
1
|
+
0.3.8
|
@@ -8,6 +8,8 @@ module Milia
|
|
8
8
|
# ------------------------------------------------------------------------------
|
9
9
|
# create -- intercept the POST create action upon new sign-up
|
10
10
|
# new tenant account is vetted, then created, then proceed with devise create user
|
11
|
+
# CALLBACK: Tenant.create_new_tenant -- prior to completing user account
|
12
|
+
# CALLBACK: Tenant.tenant_signup -- after completing user account
|
11
13
|
# ------------------------------------------------------------------------------
|
12
14
|
def create
|
13
15
|
|
@@ -18,6 +20,13 @@ module Milia
|
|
18
20
|
|
19
21
|
initiate_tenant( @tenant ) # first time stuff for new tenant
|
20
22
|
super # do the rest of the user account creation
|
23
|
+
|
24
|
+
if user_signed_in?
|
25
|
+
Tenant.tenant_signup(current_user,@tenant,params[:coupon])
|
26
|
+
else
|
27
|
+
puts ">>>>>>>>>>>>> [milia create] false assumption that user signed in upon new registrations <<<<<<<<<<<<"
|
28
|
+
raise RuntimeError, "Milia false assumption in reg_ctlr#create"
|
29
|
+
end
|
21
30
|
|
22
31
|
else
|
23
32
|
@user = User.new(params[:user])
|
data/lib/milia/base.rb
CHANGED
@@ -100,17 +100,50 @@ module Milia
|
|
100
100
|
# ------------------------------------------------------------------------
|
101
101
|
# ------------------------------------------------------------------------
|
102
102
|
def acts_as_universal_and_determines_tenant()
|
103
|
-
|
103
|
+
has_and_belongs_to_many :users
|
104
104
|
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
105
|
+
acts_as_universal()
|
106
|
+
|
107
|
+
before_destroy do |old_tenant|
|
108
|
+
old_tenant.users.clear # remove all users from this tenant
|
109
|
+
true
|
110
|
+
end # before_destroy do
|
112
111
|
end
|
113
112
|
|
113
|
+
# ------------------------------------------------------------------------
|
114
|
+
# current_tenant -- returns tenant obj for current tenant
|
115
|
+
# ------------------------------------------------------------------------
|
116
|
+
def current_tenant()
|
117
|
+
return Tenant.find( Thread.current[:tenant_id] )
|
118
|
+
end
|
119
|
+
|
120
|
+
# ------------------------------------------------------------------------
|
121
|
+
# current_tenant_id -- returns tenant_id for current tenant
|
122
|
+
# ------------------------------------------------------------------------
|
123
|
+
def current_tenant_id()
|
124
|
+
return Thread.current[:tenant_id]
|
125
|
+
end
|
126
|
+
|
127
|
+
# ------------------------------------------------------------------------
|
128
|
+
# set_current_tenant -- model-level ability to set the current tenant
|
129
|
+
# NOTE: *USE WITH CAUTION* normally this should *NEVER* be done from
|
130
|
+
# the models ... it's only useful and safe WHEN performed at the start
|
131
|
+
# of a background job (DelayedJob#perform)
|
132
|
+
# ------------------------------------------------------------------------
|
133
|
+
def set_current_tenant( tenant )
|
134
|
+
# able to handle tenant obj or tenant_id
|
135
|
+
case tenant
|
136
|
+
when Tenant then tenant_id = tenant.id
|
137
|
+
when Integer then tenant_id = tenant
|
138
|
+
else
|
139
|
+
raise ArgumentError, "invalid tenant object or id"
|
140
|
+
end # case
|
141
|
+
|
142
|
+
Thread.current[:tenant_id] = tenant_id
|
143
|
+
end
|
144
|
+
# ------------------------------------------------------------------------
|
145
|
+
# ------------------------------------------------------------------------
|
146
|
+
|
114
147
|
# ------------------------------------------------------------------------
|
115
148
|
# where_restrict_tenant -- gens tenant restrictive where clause for each klass
|
116
149
|
# NOTE: subordinate join tables will not get the default scope by Rails
|
@@ -137,4 +170,4 @@ module Milia
|
|
137
170
|
# #############################################################################
|
138
171
|
|
139
172
|
end # module Base
|
140
|
-
end # module Milia
|
173
|
+
end # module Milia
|
data/milia.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "milia"
|
8
|
-
s.version = "0.3.
|
8
|
+
s.version = "0.3.8"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["David Anderson"]
|
12
|
-
s.date = "2011-11-
|
12
|
+
s.date = "2011-11-24"
|
13
13
|
s.description = "Transparent Multi-tenanting for hosted Rails 3.1+/Ruby 1.9.2 applications"
|
14
14
|
s.email = "dsaronin@gmail.com"
|
15
15
|
s.extra_rdoc_files = [
|
@@ -34,6 +34,7 @@ Gem::Specification.new do |s|
|
|
34
34
|
"lib/milia/railtie.rb",
|
35
35
|
"lib/milia/tasks.rb",
|
36
36
|
"milia.gemspec",
|
37
|
+
"pkg/milia-0.3.8.gem",
|
37
38
|
"test/helper.rb",
|
38
39
|
"test/rails_app/.gitignore",
|
39
40
|
"test/rails_app/Gemfile",
|
data/pkg/milia-0.3.8.gem
ADDED
Binary file
|
data/test/rails_app/Gemfile.lock
CHANGED
@@ -27,7 +27,7 @@ RailsApp::Application.configure do
|
|
27
27
|
# config.logger = Logger.new(STDOUT)
|
28
28
|
config.log_level = :debug
|
29
29
|
config.assets.logger = nil
|
30
|
-
config.active_record.logger = Logger.new(STDOUT)
|
30
|
+
# config.active_record.logger = Logger.new(STDOUT)
|
31
31
|
|
32
32
|
# Disable request forgery protection in test environment
|
33
33
|
config.action_controller.allow_forgery_protection = false
|
@@ -76,7 +76,7 @@ FactoryGirl.define do |binding|
|
|
76
76
|
|
77
77
|
factory :post do |f|
|
78
78
|
f.tenant_id binding.current_tenant
|
79
|
-
f.sequence( :content ) {|n| CONTENT[n % 3] + n
|
79
|
+
f.sequence( :content ) {|n| CONTENT[n % 3] + "_#{n}" }
|
80
80
|
f.association :author
|
81
81
|
f.association :zine
|
82
82
|
end
|
@@ -85,8 +85,8 @@ class ActiveSupport::TestCase
|
|
85
85
|
user = Factory(:user)
|
86
86
|
|
87
87
|
if (w.zero? && i == 2) # special case for multiple tenants
|
88
|
-
@
|
89
|
-
setup_author_posts(@
|
88
|
+
@target = user # jemell will be in two different tenants
|
89
|
+
setup_author_posts(@target,1,1)
|
90
90
|
end
|
91
91
|
|
92
92
|
# create extra authors w/o associated user
|
@@ -98,9 +98,9 @@ class ActiveSupport::TestCase
|
|
98
98
|
end # users, authors, posts
|
99
99
|
|
100
100
|
# pick a user and put in multiple tenants
|
101
|
-
if (!@
|
102
|
-
world.users << @
|
103
|
-
setup_author_posts(@
|
101
|
+
if (!@target.nil? && w == 2) # last world
|
102
|
+
world.users << @target # add to current tenant users
|
103
|
+
setup_author_posts(@target,0,0)
|
104
104
|
end
|
105
105
|
|
106
106
|
end # setup each world
|
@@ -32,7 +32,8 @@ class PostTest < ActiveSupport::TestCase
|
|
32
32
|
|
33
33
|
should "get only author posts in mangoland" do
|
34
34
|
ActiveSupport::TestCase.set_tenant( @mangoland )
|
35
|
-
x = Author.all
|
35
|
+
x = Author.all.detect{|a| !a.user.nil? } # pick an author
|
36
|
+
assert x
|
36
37
|
assert_equal 1, x.posts.size
|
37
38
|
end
|
38
39
|
|
@@ -43,10 +44,13 @@ class PostTest < ActiveSupport::TestCase
|
|
43
44
|
end
|
44
45
|
|
45
46
|
should "see jemell in two tenants with dif posts" do
|
46
|
-
ActiveSupport::TestCase.set_tenant( @mangoland )
|
47
|
-
assert_equal 2, @jemell.posts.size
|
48
47
|
ActiveSupport::TestCase.set_tenant( @islesmile )
|
49
|
-
assert_equal 1, @
|
48
|
+
assert_equal 1, @target.posts.size
|
49
|
+
assert_equal 'mellow_yellow', @target.posts.first.content.sub(/_\d+/,"")
|
50
|
+
|
51
|
+
ActiveSupport::TestCase.set_tenant( @mangoland )
|
52
|
+
assert_equal 2, @target.posts.size
|
53
|
+
assert_equal %w(mellow_yellow wild_blue), @target.posts.map{|p| p.content.sub(/_\d+/,"") }.sort
|
50
54
|
end
|
51
55
|
|
52
56
|
should "zoom get all team posts" do
|
@@ -55,6 +59,19 @@ class PostTest < ActiveSupport::TestCase
|
|
55
59
|
assert_equal 3,list.size
|
56
60
|
end
|
57
61
|
|
62
|
+
should "exception if tenant not set up yet" do
|
63
|
+
ActiveSupport::TestCase.void_tenant
|
64
|
+
assert_raise(ActiveRecord::RecordNotFound,"should RecordNotFound if world incorrect"){Post.find( @post.id )}
|
65
|
+
end
|
66
|
+
|
67
|
+
should "exception if tenant different" do
|
68
|
+
ActiveSupport::TestCase.set_tenant( @mangoland )
|
69
|
+
assert_raise(ActiveRecord::RecordNotFound,"should RecordNotFound if world incorrect"){Post.find( @post.id )}
|
70
|
+
end
|
71
|
+
|
72
|
+
|
73
|
+
|
74
|
+
|
58
75
|
end # context post
|
59
76
|
|
60
77
|
# _____________________________________________________________________________
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: milia
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.8
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-11-
|
12
|
+
date: 2011-11-24 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
16
|
-
requirement: &
|
16
|
+
requirement: &75971770 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '3.1'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *75971770
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: devise
|
27
|
-
requirement: &
|
27
|
+
requirement: &75971150 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: 1.4.8
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *75971150
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: pg
|
38
|
-
requirement: &
|
38
|
+
requirement: &75970060 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *75970060
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: shoulda
|
49
|
-
requirement: &
|
49
|
+
requirement: &75967630 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *75967630
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: bundler
|
60
|
-
requirement: &
|
60
|
+
requirement: &75966580 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ~>
|
@@ -65,10 +65,10 @@ dependencies:
|
|
65
65
|
version: 1.0.0
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *75966580
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: jeweler
|
71
|
-
requirement: &
|
71
|
+
requirement: &75965900 !ruby/object:Gem::Requirement
|
72
72
|
none: false
|
73
73
|
requirements:
|
74
74
|
- - ~>
|
@@ -76,10 +76,10 @@ dependencies:
|
|
76
76
|
version: 1.6.4
|
77
77
|
type: :development
|
78
78
|
prerelease: false
|
79
|
-
version_requirements: *
|
79
|
+
version_requirements: *75965900
|
80
80
|
- !ruby/object:Gem::Dependency
|
81
81
|
name: rcov
|
82
|
-
requirement: &
|
82
|
+
requirement: &75965430 !ruby/object:Gem::Requirement
|
83
83
|
none: false
|
84
84
|
requirements:
|
85
85
|
- - ! '>='
|
@@ -87,10 +87,10 @@ dependencies:
|
|
87
87
|
version: '0'
|
88
88
|
type: :development
|
89
89
|
prerelease: false
|
90
|
-
version_requirements: *
|
90
|
+
version_requirements: *75965430
|
91
91
|
- !ruby/object:Gem::Dependency
|
92
92
|
name: rdoc
|
93
|
-
requirement: &
|
93
|
+
requirement: &75964970 !ruby/object:Gem::Requirement
|
94
94
|
none: false
|
95
95
|
requirements:
|
96
96
|
- - ! '>='
|
@@ -98,10 +98,10 @@ dependencies:
|
|
98
98
|
version: '0'
|
99
99
|
type: :development
|
100
100
|
prerelease: false
|
101
|
-
version_requirements: *
|
101
|
+
version_requirements: *75964970
|
102
102
|
- !ruby/object:Gem::Dependency
|
103
103
|
name: turn
|
104
|
-
requirement: &
|
104
|
+
requirement: &75996480 !ruby/object:Gem::Requirement
|
105
105
|
none: false
|
106
106
|
requirements:
|
107
107
|
- - ! '>='
|
@@ -109,7 +109,7 @@ dependencies:
|
|
109
109
|
version: '0'
|
110
110
|
type: :development
|
111
111
|
prerelease: false
|
112
|
-
version_requirements: *
|
112
|
+
version_requirements: *75996480
|
113
113
|
description: Transparent Multi-tenanting for hosted Rails 3.1+/Ruby 1.9.2 applications
|
114
114
|
email: dsaronin@gmail.com
|
115
115
|
executables: []
|
@@ -135,6 +135,7 @@ files:
|
|
135
135
|
- lib/milia/railtie.rb
|
136
136
|
- lib/milia/tasks.rb
|
137
137
|
- milia.gemspec
|
138
|
+
- pkg/milia-0.3.8.gem
|
138
139
|
- test/helper.rb
|
139
140
|
- test/rails_app/.gitignore
|
140
141
|
- test/rails_app/Gemfile
|
@@ -237,7 +238,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
237
238
|
version: '0'
|
238
239
|
segments:
|
239
240
|
- 0
|
240
|
-
hash: -
|
241
|
+
hash: -965767377
|
241
242
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
242
243
|
none: false
|
243
244
|
requirements:
|