milia 1.2.1 → 1.3.1.beta1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/app/controllers/confirmations_controller.rb +7 -7
- data/app/controllers/registrations_controller.rb +13 -19
- data/app/views/devise/registrations/new.html.haml +53 -0
- data/lib/generators/milia/install_generator.rb +44 -41
- data/lib/generators/milia/templates/devise_permitted_parameters.rb +18 -0
- data/lib/generators/milia/templates/initializer.rb +3 -9
- data/lib/milia.rb +3 -22
- data/lib/milia/base.rb +88 -109
- data/lib/milia/control.rb +25 -25
- data/lib/milia/invite_member.rb +6 -6
- data/lib/milia/version.rb +1 -1
- metadata +16 -184
- data/.document +0 -5
- data/.gitignore +0 -94
- data/.ruby-gemset +0 -1
- data/.ruby-version +0 -1
- data/.slugignore +0 -2
- data/.travis.yml +0 -4
- data/Gemfile +0 -4
- data/LICENSE.txt +0 -20
- data/README.md +0 -1207
- data/Rakefile +0 -1
- data/doc/gemfile_addition.txt +0 -28
- data/doc/manual_sample.sh +0 -816
- data/doc/ref_notes.txt +0 -155
- data/doc/sample.sh +0 -276
- data/markdown.rb +0 -38
- data/milia.gemspec +0 -29
- data/test/.ruby-gemset +0 -1
- data/test/.ruby-version +0 -1
- data/test/Gemfile +0 -81
- data/test/Gemfile.lock +0 -223
- data/test/README.md +0 -83
- data/test/Rakefile +0 -6
- data/test/app/assets/javascripts/application.js +0 -16
- data/test/app/assets/stylesheets/application.css +0 -13
- data/test/app/controllers/application_controller.rb +0 -13
- data/test/app/controllers/home_controller.rb +0 -10
- data/test/app/helpers/application_helper.rb +0 -2
- data/test/app/models/member.rb +0 -34
- data/test/app/models/post.rb +0 -14
- data/test/app/models/team.rb +0 -9
- data/test/app/models/team_asset.rb +0 -6
- data/test/app/models/tenant.rb +0 -54
- data/test/app/models/user.rb +0 -14
- data/test/app/models/zine.rb +0 -8
- data/test/app/views/home/index.html.erb +0 -2
- data/test/app/views/home/show.html.erb +0 -2
- data/test/app/views/layouts/application.html.erb +0 -14
- data/test/bin/bundle +0 -3
- data/test/bin/rails +0 -4
- data/test/bin/rake +0 -4
- data/test/config/application.rb +0 -36
- data/test/config/boot.rb +0 -4
- data/test/config/database.yml +0 -25
- data/test/config/environment.rb +0 -5
- data/test/config/environments/development.rb +0 -48
- data/test/config/environments/production.rb +0 -95
- data/test/config/environments/test.rb +0 -42
- data/test/config/initializers/backtrace_silencers.rb +0 -7
- data/test/config/initializers/devise.rb +0 -254
- data/test/config/initializers/filter_parameter_logging.rb +0 -4
- data/test/config/initializers/inflections.rb +0 -16
- data/test/config/initializers/milia.rb +0 -51
- data/test/config/initializers/mime_types.rb +0 -5
- data/test/config/initializers/secret_token.rb +0 -12
- data/test/config/initializers/session_store.rb +0 -3
- data/test/config/initializers/wrap_parameters.rb +0 -14
- data/test/config/locales/en.yml +0 -23
- data/test/config/routes.rb +0 -77
- data/test/db/migrate/20111012050200_add_sessions_table.rb +0 -12
- data/test/db/migrate/20111012050340_devise_create_users.rb +0 -48
- data/test/db/migrate/20111012050532_create_tenants.rb +0 -11
- data/test/db/migrate/20111012050600_create_tenants_users_join_table.rb +0 -8
- data/test/db/migrate/20111012050650_create_members.rb +0 -12
- data/test/db/migrate/20111012231923_create_posts.rb +0 -12
- data/test/db/migrate/20111013050657_create_zines.rb +0 -10
- data/test/db/migrate/20111013050753_create_teams.rb +0 -10
- data/test/db/migrate/20111013050837_create_team_assets.rb +0 -11
- data/test/db/schema.rb +0 -126
- data/test/db/seeds.rb +0 -7
- data/test/test/controllers/home_controller_test.rb +0 -132
- data/test/test/ctlr_test_helper.rb +0 -11
- data/test/test/fixtures/members.yml +0 -35
- data/test/test/fixtures/posts.yml +0 -96
- data/test/test/fixtures/team_assets.yml +0 -30
- data/test/test/fixtures/teams.yml +0 -17
- data/test/test/fixtures/tenants.yml +0 -12
- data/test/test/fixtures/tenants_users.yml +0 -15
- data/test/test/fixtures/users.yml +0 -33
- data/test/test/fixtures/zines.yml +0 -25
- data/test/test/models/member_test.rb +0 -75
- data/test/test/models/post_test.rb +0 -66
- data/test/test/models/team_test.rb +0 -49
- data/test/test/models/tenant_test.rb +0 -228
- data/test/test/models/user_test.rb +0 -182
- data/test/test/models/zine_test.rb +0 -40
- data/test/test/test_helper.rb +0 -31
@@ -1,96 +0,0 @@
|
|
1
|
-
post_apple_1_1_a:
|
2
|
-
tenant_id: 1
|
3
|
-
member: quentin_1
|
4
|
-
zine: zine_1_a
|
5
|
-
|
6
|
-
post_peach_1_1_a:
|
7
|
-
tenant_id: 1
|
8
|
-
member: quentin_1
|
9
|
-
zine: zine_1_a
|
10
|
-
|
11
|
-
post_plum_1_1_b:
|
12
|
-
tenant_id: 1
|
13
|
-
member: quentin_1
|
14
|
-
zine: zine_1_b
|
15
|
-
|
16
|
-
post_apricot_1_1_b:
|
17
|
-
tenant_id: 1
|
18
|
-
member: quentin_1
|
19
|
-
zine: zine_1_b
|
20
|
-
|
21
|
-
post_pear_1_1_c:
|
22
|
-
tenant_id: 1
|
23
|
-
member: quentin_1
|
24
|
-
zine: zine_1_c
|
25
|
-
|
26
|
-
post_cherry_1_1_c:
|
27
|
-
tenant_id: 1
|
28
|
-
member: quentin_1
|
29
|
-
zine: zine_1_c
|
30
|
-
|
31
|
-
post_berry_1_1_c:
|
32
|
-
tenant_id: 1
|
33
|
-
member: quentin_1
|
34
|
-
zine: zine_1_c
|
35
|
-
|
36
|
-
# ------------------------------------
|
37
|
-
|
38
|
-
post_apple_2_1_a:
|
39
|
-
tenant_id: 2
|
40
|
-
member: quentin_2
|
41
|
-
zine: zine_2_a
|
42
|
-
|
43
|
-
post_berry_2_1_a:
|
44
|
-
tenant_id: 2
|
45
|
-
member: demarcus_2
|
46
|
-
zine: zine_2_a
|
47
|
-
|
48
|
-
post_peach_2_1_a:
|
49
|
-
tenant_id: 2
|
50
|
-
member: demarcus_2
|
51
|
-
zine: zine_2_a
|
52
|
-
|
53
|
-
post_plum_2_1_b:
|
54
|
-
tenant_id: 2
|
55
|
-
member: quentin_2
|
56
|
-
zine: zine_2_b
|
57
|
-
|
58
|
-
post_apricot_2_1_b:
|
59
|
-
tenant_id: 2
|
60
|
-
member: jermaine_2
|
61
|
-
zine: zine_2_b
|
62
|
-
|
63
|
-
# ------------------------------------
|
64
|
-
|
65
|
-
post_apple_3_1_a:
|
66
|
-
tenant_id: 3
|
67
|
-
member: jermaine_3
|
68
|
-
zine: zine_3_a
|
69
|
-
|
70
|
-
post_peach_3_1_a:
|
71
|
-
tenant_id: 3
|
72
|
-
member: jermaine_3
|
73
|
-
zine: zine_3_a
|
74
|
-
|
75
|
-
post_plum_3_1_a:
|
76
|
-
tenant_id: 3
|
77
|
-
member: jermaine_3
|
78
|
-
zine: zine_3_a
|
79
|
-
|
80
|
-
post_apricot_3_1_a:
|
81
|
-
tenant_id: 3
|
82
|
-
member: jermaine_3
|
83
|
-
zine: zine_3_a
|
84
|
-
|
85
|
-
post_pear_3_1_a:
|
86
|
-
tenant_id: 3
|
87
|
-
member: jermaine_3
|
88
|
-
zine: zine_3_a
|
89
|
-
|
90
|
-
post_cherry_3_1_a:
|
91
|
-
tenant_id: 3
|
92
|
-
member: jermaine_3
|
93
|
-
zine: zine_3_a
|
94
|
-
|
95
|
-
|
96
|
-
|
@@ -1,30 +0,0 @@
|
|
1
|
-
ta_1_q_a:
|
2
|
-
tenant_id: 1
|
3
|
-
member: quentin_1
|
4
|
-
team: team_1_a
|
5
|
-
|
6
|
-
ta_2_q_a:
|
7
|
-
tenant_id: 2
|
8
|
-
member: quentin_2
|
9
|
-
team: team_2_a
|
10
|
-
|
11
|
-
ta_2_q_b:
|
12
|
-
tenant_id: 2
|
13
|
-
member: quentin_2
|
14
|
-
team: team_2_b
|
15
|
-
|
16
|
-
ta_2_d_a:
|
17
|
-
tenant_id: 2
|
18
|
-
member: demarcus_2
|
19
|
-
team: team_2_a
|
20
|
-
|
21
|
-
ta_2_j_b:
|
22
|
-
tenant_id: 2
|
23
|
-
member: jermaine_2
|
24
|
-
team: team_2_b
|
25
|
-
|
26
|
-
ta_3_j_a:
|
27
|
-
tenant_id: 3
|
28
|
-
member: jermaine_3
|
29
|
-
team: team_3_a
|
30
|
-
|
@@ -1,33 +0,0 @@
|
|
1
|
-
|
2
|
-
quentin:
|
3
|
-
id: 1
|
4
|
-
email: quentin@example.com
|
5
|
-
encrypted_password: "$2a$10$aiN/4aMQ/VlsIK8Y1GdJq.SPCcNmS3s5d7rgm7y7.VVLoVYmRf0Re" # 'MonkeyMocha'
|
6
|
-
created_at: <%= 5.days.ago.to_s :db %>
|
7
|
-
confirmation_token:
|
8
|
-
confirmed_at: <%= 5.days.ago.to_s :db %>
|
9
|
-
confirmation_sent_at: <%= 5.days.ago.to_s :db %>
|
10
|
-
authentication_token: 1b6453892473a467d07372d45eb05abc20316470
|
11
|
-
reset_password_token: "BJDxuZzBanQKrATjrDeP"
|
12
|
-
reset_password_sent_at: <%= 1.hours.ago.to_s :db %>
|
13
|
-
|
14
|
-
# raw_confirmation_token for below: BJDxuZzBanQKrATjrDeP
|
15
|
-
# demarcus is unconfirmed here
|
16
|
-
demarcus:
|
17
|
-
id: 2
|
18
|
-
email: demarcus@example.com
|
19
|
-
encrypted_password: "$2a$10$aiN/4aMQ/VlsIK8Y1GdJq.SPCcNmS3s5d7rgm7y7.VVLoVYmRf0Re" # 'MonkeyMocha'
|
20
|
-
created_at: <%= 1.days.ago.to_s :db %>
|
21
|
-
confirmation_token: '31da0519d68761dab9b6cb160a918227035baffd56498873bd5eb74b4e00a8ed'
|
22
|
-
authentication_token: 1b6453892473a467d07372d45eb05abc2031647a
|
23
|
-
|
24
|
-
jermaine:
|
25
|
-
id: 3
|
26
|
-
email: jermaine@example.com
|
27
|
-
encrypted_password: "$2a$10$aiN/4aMQ/VlsIK8Y1GdJq.SPCcNmS3s5d7rgm7y7.VVLoVYmRf0Re" # 'MonkeyMocha'
|
28
|
-
created_at: <%= 5.days.ago.to_s :db %>
|
29
|
-
confirmation_token:
|
30
|
-
confirmed_at: <%= 5.days.ago.to_s :db %>
|
31
|
-
confirmation_sent_at: <%= 5.days.ago.to_s :db %>
|
32
|
-
authentication_token: 1b6453892473a467d07372d45eb05abc2031647b
|
33
|
-
|
@@ -1,25 +0,0 @@
|
|
1
|
-
zine_1_a:
|
2
|
-
tenant_id: 1
|
3
|
-
team: team_1_a
|
4
|
-
|
5
|
-
zine_1_b:
|
6
|
-
tenant_id: 1
|
7
|
-
team: team_1_a
|
8
|
-
|
9
|
-
zine_1_c:
|
10
|
-
tenant_id: 1
|
11
|
-
team: team_1_a
|
12
|
-
|
13
|
-
zine_2_a:
|
14
|
-
tenant_id: 2
|
15
|
-
team: team_2_a
|
16
|
-
|
17
|
-
zine_2_b:
|
18
|
-
tenant_id: 2
|
19
|
-
team: team_2_b
|
20
|
-
|
21
|
-
zine_3_a:
|
22
|
-
tenant_id: 3
|
23
|
-
team: team_3_a
|
24
|
-
|
25
|
-
|
@@ -1,75 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class MemberTest < ActiveSupport::TestCase
|
4
|
-
|
5
|
-
context "a member" do
|
6
|
-
|
7
|
-
setup do
|
8
|
-
Tenant.set_current_tenant( tenants( :tenant_1 ).id )
|
9
|
-
@member = members(:quentin_1)
|
10
|
-
end
|
11
|
-
|
12
|
-
# validate multi-tenanting structure
|
13
|
-
should have_db_column(:tenant_id)
|
14
|
-
should "define the current tenant" do
|
15
|
-
assert Thread.current[:tenant_id]
|
16
|
-
end
|
17
|
-
should "match the current tenant" do
|
18
|
-
a_member = Member.first
|
19
|
-
assert_equal a_member.tenant_id, Thread.current[:tenant_id]
|
20
|
-
end
|
21
|
-
|
22
|
-
# validate the model
|
23
|
-
should belong_to( :user )
|
24
|
-
should have_many( :posts )
|
25
|
-
should have_many( :zines ).through( :posts )
|
26
|
-
should have_many( :team_assets )
|
27
|
-
should have_many( :teams ).through( :team_assets )
|
28
|
-
|
29
|
-
# validate specific member methods
|
30
|
-
should 'create new member for new admin' do
|
31
|
-
# setup new world
|
32
|
-
tenant = Tenant.create_new_tenant(
|
33
|
-
{name: "Mangoland"},
|
34
|
-
{email: "billybob@bob.com"},
|
35
|
-
{coupon: "FreeTrial"}
|
36
|
-
)
|
37
|
-
assert tenant.errors.empty?
|
38
|
-
Tenant.set_current_tenant( tenant ) # change world to new tenant
|
39
|
-
|
40
|
-
# setup new user
|
41
|
-
user = User.new(email: "limesublime@example.com")
|
42
|
-
assert user.save_and_invite_member
|
43
|
-
assert user.errors.empty?
|
44
|
-
|
45
|
-
# setup new member
|
46
|
-
member = nil
|
47
|
-
assert_nothing_raised {
|
48
|
-
member = Member.create_org_admin( user )
|
49
|
-
assert member.errors.empty?
|
50
|
-
}
|
51
|
-
|
52
|
-
assert_equal Member::DEFAULT_ADMIN[:first_name],member.first_name
|
53
|
-
assert_equal Member::DEFAULT_ADMIN[:last_name],member.last_name
|
54
|
-
assert_equal tenant.id, member.tenant_id
|
55
|
-
assert_equal user.member,member
|
56
|
-
|
57
|
-
end # should do
|
58
|
-
|
59
|
-
should 'create new member for existing tenant' do
|
60
|
-
tenant = tenants( :tenant_1 )
|
61
|
-
user = users( :quentin )
|
62
|
-
member = Member.create_new_member( user, {last_name: 'Blue', first_name: 'Wild'} )
|
63
|
-
assert member.errors.empty?
|
64
|
-
assert_equal tenant.id, member.tenant_id
|
65
|
-
assert_equal user.member,member
|
66
|
-
end # should do
|
67
|
-
|
68
|
-
should "not get any non-world member" do
|
69
|
-
x = users(:demarcus)
|
70
|
-
assert x.member.nil?
|
71
|
-
end
|
72
|
-
|
73
|
-
end # context member
|
74
|
-
|
75
|
-
end # class member
|
@@ -1,66 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class PostTest < ActiveSupport::TestCase
|
4
|
-
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
5
|
-
|
6
|
-
context "a post" do
|
7
|
-
|
8
|
-
setup do
|
9
|
-
Tenant.set_current_tenant( tenants( :tenant_1 ).id )
|
10
|
-
@zine = Zine.first
|
11
|
-
end
|
12
|
-
|
13
|
-
# validate multi-tenanting structure
|
14
|
-
should have_db_column(:tenant_id)
|
15
|
-
should "match the current tenant" do
|
16
|
-
assert_equal @zine.tenant_id, Thread.current[:tenant_id]
|
17
|
-
end
|
18
|
-
|
19
|
-
# validate the model
|
20
|
-
should belong_to( :member )
|
21
|
-
should belong_to( :zine )
|
22
|
-
should have_one(:team).through(:zine)
|
23
|
-
|
24
|
-
# model-specific tests
|
25
|
-
should "get all posts within tenant" do
|
26
|
-
assert_equal 7, Post.count
|
27
|
-
end
|
28
|
-
|
29
|
-
should "get only member posts in tenant" do
|
30
|
-
Tenant.set_current_tenant( tenants( :tenant_2 ).id )
|
31
|
-
|
32
|
-
x = members(:quentin_2)
|
33
|
-
assert_equal 2, x.posts.size
|
34
|
-
end
|
35
|
-
|
36
|
-
should "see jermaine in two tenants with dif posts" do
|
37
|
-
jermaine = users( :jermaine )
|
38
|
-
Tenant.set_current_tenant( tenants( :tenant_2 ).id )
|
39
|
-
assert_equal 1, jermaine.member.posts.size
|
40
|
-
|
41
|
-
Tenant.set_current_tenant( tenants( :tenant_3 ).id )
|
42
|
-
jermaine.reload
|
43
|
-
assert_equal 6, jermaine.member.posts.size
|
44
|
-
end
|
45
|
-
|
46
|
-
should "get all team posts" do
|
47
|
-
Tenant.set_current_tenant( tenants( :tenant_2 ).id )
|
48
|
-
team = teams( :team_2_b )
|
49
|
-
assert_equal 2, team.posts.size
|
50
|
-
end
|
51
|
-
|
52
|
-
should 'match team in a post' do
|
53
|
-
Tenant.set_current_tenant( tenants( :tenant_2 ).id )
|
54
|
-
assert_equal posts(:post_plum_2_1_b).team, teams(:team_2_b)
|
55
|
-
end # should do
|
56
|
-
|
57
|
-
should 'match a posts zine with tenant' do
|
58
|
-
Tenant.set_current_tenant( tenants( :tenant_2 ).id )
|
59
|
-
assert_equal 2,posts(:post_plum_2_1_b).zine.tenant_id
|
60
|
-
end # should do
|
61
|
-
|
62
|
-
end # context post
|
63
|
-
|
64
|
-
# _____________________________________________________________________________
|
65
|
-
|
66
|
-
end # class test
|
@@ -1,49 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class TeamTest < ActiveSupport::TestCase
|
4
|
-
|
5
|
-
context "a team" do
|
6
|
-
|
7
|
-
setup do
|
8
|
-
Tenant.set_current_tenant( tenants( :tenant_2 ).id )
|
9
|
-
@team = Team.first
|
10
|
-
end
|
11
|
-
|
12
|
-
|
13
|
-
# validate multi-tenanting structure
|
14
|
-
should have_db_column(:tenant_id)
|
15
|
-
should "match the current tenant" do
|
16
|
-
assert_equal @team.tenant_id, Thread.current[:tenant_id]
|
17
|
-
end
|
18
|
-
|
19
|
-
should have_many( :team_assets )
|
20
|
-
should have_many( :team_members ).through( :team_assets )
|
21
|
-
|
22
|
-
should have_many( :zines )
|
23
|
-
should have_many( :posts ).through( :zines )
|
24
|
-
|
25
|
-
# validate the particular associations in the model
|
26
|
-
should 'find team members through teams' do
|
27
|
-
assert_equal 2, teams( :team_2_b ).team_members.count
|
28
|
-
end #should do
|
29
|
-
|
30
|
-
should 'find posts' do
|
31
|
-
assert_equal 3, teams( :team_2_a ).posts.count
|
32
|
-
end #should do
|
33
|
-
|
34
|
-
should 'match a team with tenant' do
|
35
|
-
assert_equal 2,teams( :team_2_b ).tenant_id
|
36
|
-
end # should do
|
37
|
-
|
38
|
-
should 'check team assets' do
|
39
|
-
assert_equal 2, teams( :team_2_a ).team_assets.count
|
40
|
-
end # should do
|
41
|
-
|
42
|
-
should 'check zines' do
|
43
|
-
assert_equal 1, teams( :team_2_b ).zines.count
|
44
|
-
end # should do
|
45
|
-
|
46
|
-
|
47
|
-
end # context team
|
48
|
-
|
49
|
-
end # team
|
@@ -1,228 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
# #############################################################################
|
4
|
-
# Note: this tests not only the methods in models/tenant.rb but
|
5
|
-
# also all of the milia-injected methods from base.rb
|
6
|
-
# #############################################################################
|
7
|
-
|
8
|
-
class TenantTest < ActiveSupport::TestCase
|
9
|
-
|
10
|
-
|
11
|
-
context "a tenant" do
|
12
|
-
|
13
|
-
# ------------------------------------------------------------------------
|
14
|
-
setup do
|
15
|
-
@tenant =tenants( :tenant_1 )
|
16
|
-
Tenant.set_current_tenant( @tenant.id )
|
17
|
-
end
|
18
|
-
|
19
|
-
# #############################################################################
|
20
|
-
# #############################################################################
|
21
|
-
# ------------------------------------------------------------------------
|
22
|
-
# validate multi-tenanting structure
|
23
|
-
# ------------------------------------------------------------------------
|
24
|
-
should have_db_column(:tenant_id)
|
25
|
-
should have_db_column(:name)
|
26
|
-
should have_many( :posts )
|
27
|
-
should have_many( :zines )
|
28
|
-
should have_many( :team_assets )
|
29
|
-
should have_many( :teams )
|
30
|
-
should have_many( :members )
|
31
|
-
should have_and_belong_to_many( :users )
|
32
|
-
|
33
|
-
# ------------------------------------------------------------------------
|
34
|
-
# validate tenant creation callbacks, validators
|
35
|
-
# ------------------------------------------------------------------------
|
36
|
-
should 'have a new_signups_not_permitted' do
|
37
|
-
assert Tenant.respond_to? :new_signups_not_permitted?
|
38
|
-
assert !Tenant.new_signups_not_permitted?( {} )
|
39
|
-
end # should do
|
40
|
-
|
41
|
-
should 'create new tenant' do
|
42
|
-
|
43
|
-
assert_difference( 'Tenant.count' ) do
|
44
|
-
# setup new world
|
45
|
-
tenant = Tenant.create_new_tenant(
|
46
|
-
{name: "Mangoland"},
|
47
|
-
{email: "billybob@bob.com"},
|
48
|
-
{coupon: "FreeTrial"}
|
49
|
-
)
|
50
|
-
assert_not_nil tenant
|
51
|
-
assert_kind_of Tenant,tenant
|
52
|
-
assert tenant.errors.empty?
|
53
|
-
assert_equal "Mangoland", tenant.name
|
54
|
-
end
|
55
|
-
|
56
|
-
end # should do
|
57
|
-
|
58
|
-
should 'tenant signup callback' do
|
59
|
-
# setup new world
|
60
|
-
tenant = Tenant.create_new_tenant(
|
61
|
-
{name: "Mangoland"},
|
62
|
-
{email: "billybob@bob.com"},
|
63
|
-
{coupon: "FreeTrial"}
|
64
|
-
)
|
65
|
-
assert tenant.errors.empty?
|
66
|
-
Tenant.set_current_tenant( tenant ) # change world to new tenant
|
67
|
-
|
68
|
-
# setup new user
|
69
|
-
user = User.new(email: "limesublime@example.com")
|
70
|
-
assert user.save_and_invite_member
|
71
|
-
assert user.errors.empty?
|
72
|
-
|
73
|
-
# setup new member
|
74
|
-
member = nil
|
75
|
-
assert_difference( 'Member.count' ) do
|
76
|
-
assert_nothing_raised {
|
77
|
-
member = Tenant.tenant_signup(user, tenant)
|
78
|
-
assert member.errors.empty?
|
79
|
-
}
|
80
|
-
end # new Member DB records created
|
81
|
-
|
82
|
-
assert_equal Member::DEFAULT_ADMIN[:first_name],member.first_name
|
83
|
-
assert_equal Member::DEFAULT_ADMIN[:last_name],member.last_name
|
84
|
-
assert_equal tenant.id, member.tenant_id
|
85
|
-
assert_equal user.member,member
|
86
|
-
|
87
|
-
end # should do
|
88
|
-
|
89
|
-
# #############################################################################
|
90
|
-
# #### acts_as_universal_and_determines_tenant injected methods #############
|
91
|
-
# #############################################################################
|
92
|
-
|
93
|
-
should 'current_tenant_id - non nil' do
|
94
|
-
tid = Tenant.current_tenant_id
|
95
|
-
assert_kind_of Integer,tid
|
96
|
-
assert_equal tenants( :tenant_1 ).id,tid
|
97
|
-
end # should do
|
98
|
-
|
99
|
-
should 'current_tenant - nil' do
|
100
|
-
# force the current_tenant to be nil
|
101
|
-
Thread.current[:tenant_id] = nil
|
102
|
-
|
103
|
-
tenant = Tenant.current_tenant
|
104
|
-
assert_nil tenant
|
105
|
-
|
106
|
-
end # should do
|
107
|
-
|
108
|
-
should 'current_tenant - valid tid' do
|
109
|
-
tenant = Tenant.current_tenant
|
110
|
-
assert_kind_of Tenant,tenant
|
111
|
-
assert_equal tenants( :tenant_1 ),tenant
|
112
|
-
end # should do
|
113
|
-
|
114
|
-
should 'current_tenant - invalid tid' do
|
115
|
-
# force the current_tenant to be nil
|
116
|
-
Thread.current[:tenant_id] = 500
|
117
|
-
|
118
|
-
assert_nothing_raised {
|
119
|
-
assert_nil Tenant.current_tenant
|
120
|
-
}
|
121
|
-
|
122
|
-
end # should do
|
123
|
-
|
124
|
-
should 'set current tenant - tenant obj' do
|
125
|
-
assert_equal tenants( :tenant_1 ).id, Tenant.current_tenant_id
|
126
|
-
Tenant.set_current_tenant( tenants( :tenant_3 ) )
|
127
|
-
assert_equal tenants( :tenant_3 ).id, Tenant.current_tenant_id
|
128
|
-
end # should do
|
129
|
-
|
130
|
-
should 'set current tenant - tenant id' do
|
131
|
-
assert_equal tenants( :tenant_1 ).id, Tenant.current_tenant_id
|
132
|
-
Tenant.set_current_tenant( tenants( :tenant_3 ).id )
|
133
|
-
assert_equal tenants( :tenant_3 ).id, Tenant.current_tenant_id
|
134
|
-
end # should do
|
135
|
-
|
136
|
-
should 'NOT set current tenant - invalid arg' do
|
137
|
-
assert_equal tenants( :tenant_1 ).id, Tenant.current_tenant_id
|
138
|
-
assert_raise(ArgumentError) {
|
139
|
-
Tenant.set_current_tenant( '2' )
|
140
|
-
}
|
141
|
-
assert_equal tenants( :tenant_1 ).id, Tenant.current_tenant_id
|
142
|
-
end # should do
|
143
|
-
|
144
|
-
RESTRICT_SNIPPET = 'posts.tenant_id = 1 AND zines.tenant_id = 1'
|
145
|
-
should 'prepare a restrict tenant snippet' do
|
146
|
-
assert_equal RESTRICT_SNIPPET, Tenant.where_restrict_tenant( Post, Zine )
|
147
|
-
end # should do
|
148
|
-
|
149
|
-
should 'clear tenant.users when tenant destroyed' do
|
150
|
-
target = tenants(:tenant_2)
|
151
|
-
Tenant.set_current_tenant( target )
|
152
|
-
quentin = users(:quentin)
|
153
|
-
assert_equal 2,quentin.tenants.count
|
154
|
-
|
155
|
-
assert_difference( "Tenant.count", -1 ) do
|
156
|
-
target.destroy
|
157
|
-
end
|
158
|
-
|
159
|
-
quentin.reload
|
160
|
-
assert_equal 1,quentin.tenants.count
|
161
|
-
|
162
|
-
end # should do
|
163
|
-
|
164
|
-
|
165
|
-
# #############################################################################
|
166
|
-
# #### acts_as_tenant injected methods #############
|
167
|
-
# #############################################################################
|
168
|
-
|
169
|
-
should "raise exception if tenant is different" do
|
170
|
-
target = members(:quentin_1)
|
171
|
-
# now force tenant to invalid
|
172
|
-
Tenant.set_current_tenant( 0 )
|
173
|
-
|
174
|
-
assert_raise(::Milia::Control::InvalidTenantAccess,
|
175
|
-
"InvalidTenantAccess if tenants dont match"){
|
176
|
-
target.update_attributes( :first_name => "duck walk" )
|
177
|
-
}
|
178
|
-
end # should do
|
179
|
-
|
180
|
-
should 'raise exception if tenanted tid not nil - destroy' do
|
181
|
-
target = members(:quentin_1)
|
182
|
-
assert_no_difference('Member.count') do
|
183
|
-
assert_raise(::Milia::Control::InvalidTenantAccess) {
|
184
|
-
target.tenant_id = 3
|
185
|
-
target.destroy
|
186
|
-
}
|
187
|
-
end # no diff do
|
188
|
-
end # should do
|
189
|
-
|
190
|
-
# #############################################################################
|
191
|
-
# #### acts_as_universal injected methods #############
|
192
|
-
# #############################################################################
|
193
|
-
should 'always force universal tenant id to nil' do
|
194
|
-
# setup new world
|
195
|
-
tenant = Tenant.create_new_tenant(
|
196
|
-
{name: "Mangoland", tenant_id: 1},
|
197
|
-
{email: "billybob@bob.com"},
|
198
|
-
{coupon: "FreeTrial"}
|
199
|
-
)
|
200
|
-
assert tenant.errors.empty?
|
201
|
-
assert_nil tenant.tenant_id
|
202
|
-
end # should do
|
203
|
-
|
204
|
-
|
205
|
-
should 'raise exception if tid not nil - save' do
|
206
|
-
tenant = tenants(:tenant_1)
|
207
|
-
assert_raise(::Milia::Control::InvalidTenantAccess) {
|
208
|
-
tenant.update_attributes( tenant_id: 3, name: 'wild blue2' )
|
209
|
-
}
|
210
|
-
|
211
|
-
end # should do
|
212
|
-
|
213
|
-
should 'raise exception if tid not nil - destroy' do
|
214
|
-
tenant = tenants(:tenant_1)
|
215
|
-
assert_no_difference('Tenant.count') do
|
216
|
-
assert_raise(::Milia::Control::InvalidTenantAccess) {
|
217
|
-
tenant.tenant_id = 3
|
218
|
-
tenant.destroy
|
219
|
-
}
|
220
|
-
end # no diff do
|
221
|
-
end # should do
|
222
|
-
|
223
|
-
# #############################################################################
|
224
|
-
|
225
|
-
end # context
|
226
|
-
|
227
|
-
# #############################################################################
|
228
|
-
end # class test
|