milia 0.3.2 → 0.3.7
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +0 -1
- data/Gemfile.lock +7 -9
- data/README.rdoc +18 -7
- data/VERSION +1 -1
- data/lib/milia/base.rb +24 -0
- data/lib/milia/control.rb +10 -3
- data/milia.gemspec +22 -7
- data/test/rails_app/Gemfile +4 -0
- data/test/rails_app/Gemfile.lock +25 -12
- data/test/rails_app/app/controllers/application_controller.rb +15 -0
- data/test/rails_app/app/models/author.rb +9 -0
- data/test/rails_app/app/models/calendar.rb +6 -0
- data/test/rails_app/app/models/post.rb +15 -0
- data/test/rails_app/app/models/team.rb +8 -0
- data/test/rails_app/app/models/team_asset.rb +6 -0
- data/test/rails_app/app/models/user.rb +2 -0
- data/test/rails_app/app/models/zine.rb +6 -0
- data/test/rails_app/config/environments/development.rb +5 -0
- data/test/rails_app/config/environments/test.rb +17 -0
- data/test/rails_app/db/migrate/20111012231923_create_posts.rb +15 -0
- data/test/rails_app/db/migrate/20111013050558_create_calendars.rb +14 -0
- data/test/rails_app/db/migrate/20111013050657_create_zines.rb +12 -0
- data/test/rails_app/db/migrate/20111013050753_create_teams.rb +11 -0
- data/test/rails_app/db/migrate/20111013050837_create_team_assets.rb +14 -0
- data/test/rails_app/db/migrate/20111013053403_create_authors.rb +13 -0
- data/test/rails_app/db/schema.rb +68 -1
- data/test/rails_app/script/rails +0 -0
- data/test/rails_app/test/ctlr_test_helper.rb +8 -0
- data/test/rails_app/test/factories/units_factory.rb +84 -0
- data/test/rails_app/test/functional/home_controller_test.rb +1 -1
- data/test/rails_app/test/test_helper.rb +116 -8
- data/test/rails_app/test/unit/author_test.rb +30 -0
- data/test/rails_app/test/unit/calendar_test.rb +28 -0
- data/test/rails_app/test/unit/helpers/home_helper_test.rb +3 -0
- data/test/rails_app/test/unit/post_test.rb +62 -0
- data/test/rails_app/test/unit/team_test.rb +30 -0
- data/test/rails_app/test/unit/user_test.rb +23 -4
- data/test/rails_app/test/unit/zine_test.rb +28 -0
- data/test/rails_app/vendor/plugins/rails_log_stdout/init.rb +43 -0
- metadata +41 -34
- data/test/rails_app/test/fixtures/tenants.yml +0 -2
- data/test/rails_app/test/fixtures/users.yml +0 -11
@@ -0,0 +1,15 @@
|
|
1
|
+
class Post < ActiveRecord::Base
|
2
|
+
acts_as_tenant
|
3
|
+
|
4
|
+
belongs_to :author
|
5
|
+
belongs_to :zine
|
6
|
+
|
7
|
+
|
8
|
+
def self.get_team_posts( team_id )
|
9
|
+
Post.joins( {:zine => :calendar}, :author)\
|
10
|
+
.where( ["calendars.team_id = ?", team_id] )\
|
11
|
+
.where( where_restrict_tenant(Zine, Calendar, Author) )\
|
12
|
+
.order("authors.name")
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
@@ -19,6 +19,11 @@ RailsApp::Application.configure do
|
|
19
19
|
# Print deprecation notices to the Rails logger
|
20
20
|
config.active_support.deprecation = :stderr
|
21
21
|
|
22
|
+
# See everything in the log (default is :debug)
|
23
|
+
# config.log_level = :debug
|
24
|
+
# config.assets.logger = nil
|
25
|
+
# config.active_record.logger = Logger.new(STDOUT)
|
26
|
+
|
22
27
|
# Only use best-standards-support built into browsers
|
23
28
|
config.action_dispatch.best_standards_support = :builtin
|
24
29
|
|
@@ -21,6 +21,14 @@ RailsApp::Application.configure do
|
|
21
21
|
# Raise exceptions instead of rendering exception templates
|
22
22
|
config.action_dispatch.show_exceptions = false
|
23
23
|
|
24
|
+
# Print deprecation notices to the Rails logger
|
25
|
+
config.active_support.deprecation = :log
|
26
|
+
|
27
|
+
# config.logger = Logger.new(STDOUT)
|
28
|
+
config.log_level = :debug
|
29
|
+
config.assets.logger = nil
|
30
|
+
config.active_record.logger = Logger.new(STDOUT)
|
31
|
+
|
24
32
|
# Disable request forgery protection in test environment
|
25
33
|
config.action_controller.allow_forgery_protection = false
|
26
34
|
|
@@ -29,6 +37,9 @@ RailsApp::Application.configure do
|
|
29
37
|
# ActionMailer::Base.deliveries array.
|
30
38
|
config.action_mailer.delivery_method = :test
|
31
39
|
|
40
|
+
config.action_mailer.default_url_options = { :host => 'localhost:3000' }
|
41
|
+
|
42
|
+
|
32
43
|
# Use SQL instead of Active Record's schema dumper when creating the test database.
|
33
44
|
# This is necessary if your schema can't be completely dumped by the schema dumper,
|
34
45
|
# like if you have constraints or database-specific column types
|
@@ -36,4 +47,10 @@ RailsApp::Application.configure do
|
|
36
47
|
|
37
48
|
# Print deprecation notices to the stderr
|
38
49
|
config.active_support.deprecation = :stderr
|
50
|
+
|
51
|
+
# See everything in the log (default is :debug)
|
52
|
+
# config.log_level = :debug
|
53
|
+
# config.assets.logger = nil
|
54
|
+
# config.active_record.logger = Logger.new(STDOUT)
|
55
|
+
|
39
56
|
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
class CreatePosts < ActiveRecord::Migration
|
2
|
+
def change
|
3
|
+
create_table :posts do |t|
|
4
|
+
t.references :tenant
|
5
|
+
t.references :author
|
6
|
+
t.references :zine
|
7
|
+
t.string :content
|
8
|
+
|
9
|
+
t.timestamps
|
10
|
+
end
|
11
|
+
add_index :posts, :tenant_id
|
12
|
+
add_index :posts, :author_id
|
13
|
+
add_index :posts, :zine_id
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
class CreateCalendars < ActiveRecord::Migration
|
2
|
+
def change
|
3
|
+
create_table :calendars do |t|
|
4
|
+
t.references :tenant
|
5
|
+
t.references :team
|
6
|
+
t.datetime :cal_start
|
7
|
+
t.datetime :cal_end
|
8
|
+
|
9
|
+
t.timestamps
|
10
|
+
end
|
11
|
+
add_index :calendars, :tenant_id
|
12
|
+
add_index :calendars, :team_id
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
class CreateTeamAssets < ActiveRecord::Migration
|
2
|
+
def change
|
3
|
+
create_table :team_assets do |t|
|
4
|
+
t.references :tenant
|
5
|
+
t.references :author
|
6
|
+
t.references :team
|
7
|
+
|
8
|
+
t.timestamps
|
9
|
+
end
|
10
|
+
add_index :team_assets, :tenant_id
|
11
|
+
add_index :team_assets, :author_id
|
12
|
+
add_index :team_assets, :team_id
|
13
|
+
end
|
14
|
+
end
|
data/test/rails_app/db/schema.rb
CHANGED
@@ -11,7 +11,43 @@
|
|
11
11
|
#
|
12
12
|
# It's strongly recommended to check this file into your version control system.
|
13
13
|
|
14
|
-
ActiveRecord::Schema.define(:version =>
|
14
|
+
ActiveRecord::Schema.define(:version => 20111013053403) do
|
15
|
+
|
16
|
+
create_table "authors", :force => true do |t|
|
17
|
+
t.integer "tenant_id"
|
18
|
+
t.integer "user_id"
|
19
|
+
t.string "name"
|
20
|
+
t.datetime "created_at"
|
21
|
+
t.datetime "updated_at"
|
22
|
+
end
|
23
|
+
|
24
|
+
add_index "authors", ["tenant_id"], :name => "index_authors_on_tenant_id"
|
25
|
+
add_index "authors", ["user_id"], :name => "index_authors_on_user_id"
|
26
|
+
|
27
|
+
create_table "calendars", :force => true do |t|
|
28
|
+
t.integer "tenant_id"
|
29
|
+
t.integer "team_id"
|
30
|
+
t.datetime "cal_start"
|
31
|
+
t.datetime "cal_end"
|
32
|
+
t.datetime "created_at"
|
33
|
+
t.datetime "updated_at"
|
34
|
+
end
|
35
|
+
|
36
|
+
add_index "calendars", ["team_id"], :name => "index_calendars_on_team_id"
|
37
|
+
add_index "calendars", ["tenant_id"], :name => "index_calendars_on_tenant_id"
|
38
|
+
|
39
|
+
create_table "posts", :force => true do |t|
|
40
|
+
t.integer "tenant_id"
|
41
|
+
t.integer "author_id"
|
42
|
+
t.integer "zine_id"
|
43
|
+
t.string "content"
|
44
|
+
t.datetime "created_at"
|
45
|
+
t.datetime "updated_at"
|
46
|
+
end
|
47
|
+
|
48
|
+
add_index "posts", ["author_id"], :name => "index_posts_on_author_id"
|
49
|
+
add_index "posts", ["tenant_id"], :name => "index_posts_on_tenant_id"
|
50
|
+
add_index "posts", ["zine_id"], :name => "index_posts_on_zine_id"
|
15
51
|
|
16
52
|
create_table "sessions", :force => true do |t|
|
17
53
|
t.string "session_id", :null => false
|
@@ -23,6 +59,27 @@ ActiveRecord::Schema.define(:version => 20111012060818) do
|
|
23
59
|
add_index "sessions", ["session_id"], :name => "index_sessions_on_session_id"
|
24
60
|
add_index "sessions", ["updated_at"], :name => "index_sessions_on_updated_at"
|
25
61
|
|
62
|
+
create_table "team_assets", :force => true do |t|
|
63
|
+
t.integer "tenant_id"
|
64
|
+
t.integer "author_id"
|
65
|
+
t.integer "team_id"
|
66
|
+
t.datetime "created_at"
|
67
|
+
t.datetime "updated_at"
|
68
|
+
end
|
69
|
+
|
70
|
+
add_index "team_assets", ["author_id"], :name => "index_team_assets_on_author_id"
|
71
|
+
add_index "team_assets", ["team_id"], :name => "index_team_assets_on_team_id"
|
72
|
+
add_index "team_assets", ["tenant_id"], :name => "index_team_assets_on_tenant_id"
|
73
|
+
|
74
|
+
create_table "teams", :force => true do |t|
|
75
|
+
t.integer "tenant_id"
|
76
|
+
t.string "name"
|
77
|
+
t.datetime "created_at"
|
78
|
+
t.datetime "updated_at"
|
79
|
+
end
|
80
|
+
|
81
|
+
add_index "teams", ["tenant_id"], :name => "index_teams_on_tenant_id"
|
82
|
+
|
26
83
|
create_table "tenants", :force => true do |t|
|
27
84
|
t.integer "tenant_id"
|
28
85
|
t.datetime "created_at"
|
@@ -62,4 +119,14 @@ ActiveRecord::Schema.define(:version => 20111012060818) do
|
|
62
119
|
add_index "users", ["email"], :name => "index_users_on_email", :unique => true
|
63
120
|
add_index "users", ["reset_password_token"], :name => "index_users_on_reset_password_token", :unique => true
|
64
121
|
|
122
|
+
create_table "zines", :force => true do |t|
|
123
|
+
t.integer "tenant_id"
|
124
|
+
t.integer "calendar_id"
|
125
|
+
t.datetime "created_at"
|
126
|
+
t.datetime "updated_at"
|
127
|
+
end
|
128
|
+
|
129
|
+
add_index "zines", ["calendar_id"], :name => "index_zines_on_calendar_id"
|
130
|
+
add_index "zines", ["tenant_id"], :name => "index_zines_on_tenant_id"
|
131
|
+
|
65
132
|
end
|
data/test/rails_app/script/rails
CHANGED
File without changes
|
@@ -0,0 +1,84 @@
|
|
1
|
+
FactoryGirl.define do |binding|
|
2
|
+
|
3
|
+
Thread.current[:tenant_id] = nil # reset at start
|
4
|
+
|
5
|
+
# #############################################################################
|
6
|
+
# ************* HELPER METHODS FOR THIS FACTORY *******************************
|
7
|
+
# #############################################################################
|
8
|
+
class << binding
|
9
|
+
|
10
|
+
# current_tenant -- create or work within a default tenant
|
11
|
+
def current_tenant()
|
12
|
+
Thread.current[:tenant_id] ||= Factory(:tenant).id
|
13
|
+
end
|
14
|
+
|
15
|
+
# new_tenant -- switch over to a new tenant to be the default tenant
|
16
|
+
def new_tenant()
|
17
|
+
Thread.current[:tenant_id] = Factory(:tenant).id
|
18
|
+
end
|
19
|
+
|
20
|
+
USERNAMES = %w(demarcus deshaun jemell jermaine jabari kwashaun musa nigel kissamu yona brenden terell treven tyrese adonys)
|
21
|
+
|
22
|
+
# pick_name -- construct a unique user name based on sequence & world
|
23
|
+
def pick_name(n,w)
|
24
|
+
return USERNAMES[ (n % USERNAMES.size) ] + n.to_s + "_w#{w.to_s}"
|
25
|
+
end
|
26
|
+
|
27
|
+
end # anon class extensions
|
28
|
+
# #############################################################################
|
29
|
+
# #############################################################################
|
30
|
+
|
31
|
+
|
32
|
+
factory :tenant do |f|
|
33
|
+
f.tenant_id nil
|
34
|
+
end
|
35
|
+
|
36
|
+
factory :user do |f|
|
37
|
+
w = binding.current_tenant # establish a current tenant for this duration
|
38
|
+
f.tenant_id nil
|
39
|
+
f.sequence( :email ) { |n| "#{binding.pick_name(n,w)}@example.com" }
|
40
|
+
f.password 'MonkeyMocha'
|
41
|
+
f.password_confirmation { |u| u.password }
|
42
|
+
end # user
|
43
|
+
|
44
|
+
factory :author do |f|
|
45
|
+
w = binding.current_tenant
|
46
|
+
f.tenant_id w
|
47
|
+
f.sequence( :name ) { |n| "#{binding.pick_name(n,w)}@example.com" }
|
48
|
+
f.association :user
|
49
|
+
end # :author
|
50
|
+
|
51
|
+
factory :calendar do |f|
|
52
|
+
f.tenant_id binding.current_tenant
|
53
|
+
f.association :team
|
54
|
+
f.cal_start Time.now.at_beginning_of_month
|
55
|
+
f.cal_end Time.now.at_end_of_month
|
56
|
+
end # calendar
|
57
|
+
|
58
|
+
factory :team do |f|
|
59
|
+
f.tenant_id binding.current_tenant
|
60
|
+
f.sequence( :name ) { |n| "team_#{n}" }
|
61
|
+
f.after_create {|team| f.team_assets = 3.times{ Factory(:team_asset, :team => team) } }
|
62
|
+
end # team
|
63
|
+
|
64
|
+
factory :team_asset do |f|
|
65
|
+
f.tenant_id binding.current_tenant
|
66
|
+
f.association :team
|
67
|
+
f.association :author
|
68
|
+
end
|
69
|
+
|
70
|
+
factory :zine do |f|
|
71
|
+
f.tenant_id binding.current_tenant
|
72
|
+
f.association :calendar
|
73
|
+
end
|
74
|
+
|
75
|
+
CONTENT = %w(wild_blue passion_pink mellow_yellow)
|
76
|
+
|
77
|
+
factory :post do |f|
|
78
|
+
f.tenant_id binding.current_tenant
|
79
|
+
f.sequence( :content ) {|n| CONTENT[n % 3] + n.to_s }
|
80
|
+
f.association :author
|
81
|
+
f.association :zine
|
82
|
+
end
|
83
|
+
|
84
|
+
end # FactoryGirl.define
|
@@ -2,15 +2,123 @@ ENV["RAILS_ENV"] = "test"
|
|
2
2
|
require File.expand_path('../../config/environment', __FILE__)
|
3
3
|
require 'rails/test_help'
|
4
4
|
|
5
|
+
# Shoulda looks for RAILS_ROOT before loading shoulda/rails, and Rails 3.1
|
6
|
+
# doesn't have that anymore.
|
7
|
+
|
8
|
+
require 'shoulda/rails'
|
9
|
+
|
5
10
|
class ActiveSupport::TestCase
|
6
|
-
# Setup all fixtures in test/fixtures/*.(yml|csv) for all tests in alphabetical order.
|
7
|
-
#
|
8
|
-
# Note: You'll currently still have to declare fixtures explicitly in integration tests
|
9
|
-
# -- they do not yet inherit this setting
|
10
|
-
fixtures :all
|
11
11
|
|
12
|
-
|
12
|
+
class << self
|
13
|
+
|
14
|
+
def set_tenant( tenant )
|
15
|
+
Thread.current[:tenant_id] = tenant.id
|
16
|
+
end
|
17
|
+
|
18
|
+
def current_tenant()
|
19
|
+
return Thread.current[:tenant_id]
|
20
|
+
end
|
21
|
+
|
22
|
+
def reset_tenant()
|
23
|
+
Thread.current[:tenant_id] = nil # starting point; no tenant
|
24
|
+
end
|
25
|
+
|
26
|
+
def void_tenant()
|
27
|
+
Thread.current[:tenant_id] = 0 # an impossible tenant
|
28
|
+
end
|
29
|
+
|
30
|
+
end # anon class
|
31
|
+
|
32
|
+
# -----------------------------------------------------------------------------
|
33
|
+
# setup_world -- sets up test rig for three tenants, multiple users, authors, etc
|
34
|
+
# -----------------------------------------------------------------------------
|
35
|
+
def setup_world()
|
36
|
+
@Q1 = DateTime.new(2011,1,1,0,0,0)
|
37
|
+
@Q1end = DateTime.new(2011,3,31,23,59,59)
|
38
|
+
|
39
|
+
@Q2 = DateTime.new(2011,4,1,0,0,0)
|
40
|
+
@Q2end = DateTime.new(2011,6,30,23,59,59)
|
41
|
+
|
42
|
+
@Q3 = DateTime.new(2011,7,1,0,0,0)
|
43
|
+
@Q3end = DateTime.new(2011,9,30,23,59,59)
|
44
|
+
|
45
|
+
@Q4 = DateTime.new(2011,10,1,0,0,0)
|
46
|
+
@Q4end = DateTime.new(2011,12,31,23,59,59)
|
47
|
+
|
48
|
+
@max_worlds = 3
|
49
|
+
@max_teams = 2
|
50
|
+
@max_users = 3
|
51
|
+
|
52
|
+
@dates = [
|
53
|
+
[ @Q1, @Q1end],
|
54
|
+
[ @Q2, @Q2end],
|
55
|
+
[ @Q3, @Q3end],
|
56
|
+
[ @Q4, @Q4end],
|
57
|
+
]
|
58
|
+
|
59
|
+
|
60
|
+
# we'll name objects for each of three worlds to be created
|
61
|
+
@worlds = [ ]
|
62
|
+
|
63
|
+
@max_worlds.times do |w|
|
64
|
+
@teams = []
|
65
|
+
@cals = []
|
66
|
+
@zines = []
|
67
|
+
|
68
|
+
world = Factory(:tenant)
|
69
|
+
@worlds << world
|
70
|
+
ActiveSupport::TestCase.set_tenant( world ) # set the tenant
|
71
|
+
|
72
|
+
@max_teams.times do |i|
|
73
|
+
team = Factory(:team)
|
74
|
+
@teams << team
|
75
|
+
|
76
|
+
cal = Factory(:calendar, :team => team, :cal_start => @dates[i % @dates.size][0], :cal_end => @dates[i % @dates.size][1])
|
77
|
+
@cals << cal
|
78
|
+
|
79
|
+
@zines << Factory(:zine, :calendar => cal)
|
80
|
+
|
81
|
+
end # calendars, teams, zines
|
82
|
+
|
83
|
+
|
84
|
+
@max_users.times do |i|
|
85
|
+
user = Factory(:user)
|
86
|
+
|
87
|
+
if (w.zero? && i == 2) # special case for multiple tenants
|
88
|
+
@jemell = user # jemell will be in two different tenants
|
89
|
+
setup_author_posts(@jemell,1,1)
|
90
|
+
end
|
91
|
+
|
92
|
+
# create extra authors w/o associated user
|
93
|
+
@max_teams.times do |j|
|
94
|
+
setup_author_posts(user,i,j)
|
95
|
+
user = nil
|
96
|
+
end
|
97
|
+
|
98
|
+
end # users, authors, posts
|
99
|
+
|
100
|
+
# pick a user and put in multiple tenants
|
101
|
+
if (!@jemell.nil? && w == 2) # last world
|
102
|
+
world.users << @jemell # add to current tenant users
|
103
|
+
setup_author_posts(@jemell,0,0)
|
104
|
+
end
|
105
|
+
|
106
|
+
end # setup each world
|
107
|
+
|
108
|
+
@mangoland = @worlds[0]
|
109
|
+
@limesublime = @worlds[1]
|
110
|
+
@islesmile = @worlds[2]
|
111
|
+
|
112
|
+
end # setup world for testing
|
113
|
+
# -----------------------------------------------------------------------------
|
114
|
+
# -----------------------------------------------------------------------------
|
115
|
+
|
116
|
+
protected
|
117
|
+
def setup_author_posts(user,i,j)
|
118
|
+
author = Factory(:author, :user => user)
|
119
|
+
Factory(:team_asset, :author => author, :team => @teams[i % @max_teams])
|
120
|
+
Factory(:post, :zine => @zines[j], :author => author)
|
121
|
+
end
|
13
122
|
|
14
|
-
include Devise::TestHelpers
|
15
123
|
|
16
|
-
end
|
124
|
+
end # class ActiveSupport::TestCase
|