acts_as_tenant 0.4.3 → 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (113) hide show
  1. checksums.yaml +5 -5
  2. data/README.md +124 -25
  3. data/Rakefile +5 -3
  4. data/lib/acts_as_tenant/configuration.rb +6 -19
  5. data/lib/acts_as_tenant/controller_extensions/filter.rb +13 -0
  6. data/lib/acts_as_tenant/controller_extensions/subdomain.rb +20 -0
  7. data/lib/acts_as_tenant/controller_extensions/subdomain_or_domain.rb +20 -0
  8. data/lib/acts_as_tenant/controller_extensions.rb +10 -59
  9. data/lib/acts_as_tenant/errors.rb +3 -4
  10. data/lib/acts_as_tenant/model_extensions.rb +59 -136
  11. data/lib/acts_as_tenant/sidekiq.rb +11 -7
  12. data/lib/acts_as_tenant/tenant_helper.rb +7 -0
  13. data/lib/acts_as_tenant/test_tenant_middleware.rb +15 -0
  14. data/lib/acts_as_tenant/version.rb +1 -1
  15. data/lib/acts_as_tenant.rb +112 -14
  16. data/spec/acts_as_tenant/configuration_spec.rb +8 -19
  17. data/spec/acts_as_tenant/sidekiq_spec.rb +14 -19
  18. data/spec/{acts_as_tenant/tenant_by_filter_spec.rb → controllers/filter_spec.rb} +7 -12
  19. data/spec/controllers/subdomain_or_domain_spec.rb +55 -0
  20. data/spec/controllers/subdomain_spec.rb +49 -0
  21. data/spec/dummy/.ruby-version +1 -0
  22. data/spec/dummy/Rakefile +6 -0
  23. data/spec/dummy/app/assets/config/manifest.js +2 -0
  24. data/spec/dummy/app/assets/images/.keep +0 -0
  25. data/spec/dummy/app/assets/stylesheets/application.css +15 -0
  26. data/spec/dummy/app/channels/application_cable/channel.rb +4 -0
  27. data/spec/dummy/app/channels/application_cable/connection.rb +4 -0
  28. data/spec/dummy/app/controllers/application_controller.rb +2 -0
  29. data/spec/dummy/app/controllers/concerns/.keep +0 -0
  30. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  31. data/spec/dummy/app/javascript/packs/application.js +15 -0
  32. data/spec/dummy/app/jobs/application_job.rb +7 -0
  33. data/spec/dummy/app/mailers/application_mailer.rb +4 -0
  34. data/spec/dummy/app/mailers/user_mailer.rb +5 -0
  35. data/spec/dummy/app/models/account.rb +4 -0
  36. data/spec/dummy/app/models/aliased_task.rb +4 -0
  37. data/spec/dummy/app/models/article.rb +3 -0
  38. data/spec/dummy/app/models/comment.rb +5 -0
  39. data/spec/dummy/app/models/concerns/.keep +0 -0
  40. data/spec/dummy/app/models/custom_counter_cache_task.rb +4 -0
  41. data/spec/dummy/app/models/custom_foreign_key_task.rb +4 -0
  42. data/spec/dummy/app/models/custom_primary_key_task.rb +4 -0
  43. data/spec/dummy/app/models/global_project.rb +6 -0
  44. data/spec/dummy/app/models/global_project_with_conditions.rb +6 -0
  45. data/spec/dummy/app/models/global_project_with_if.rb +6 -0
  46. data/spec/dummy/app/models/manager.rb +4 -0
  47. data/spec/dummy/app/models/polymorphic_tenant_comment.rb +5 -0
  48. data/spec/dummy/app/models/project.rb +8 -0
  49. data/spec/dummy/app/models/task.rb +7 -0
  50. data/spec/dummy/app/models/unique_task.rb +5 -0
  51. data/spec/dummy/app/models/unscoped_model.rb +3 -0
  52. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  53. data/spec/dummy/app/views/layouts/mailer.html.erb +13 -0
  54. data/spec/dummy/app/views/layouts/mailer.text.erb +1 -0
  55. data/spec/dummy/bin/rails +4 -0
  56. data/spec/dummy/bin/rake +4 -0
  57. data/spec/dummy/bin/setup +33 -0
  58. data/spec/dummy/config/application.rb +19 -0
  59. data/spec/dummy/config/boot.rb +5 -0
  60. data/spec/dummy/config/cable.yml +10 -0
  61. data/spec/dummy/config/database.yml +19 -0
  62. data/spec/dummy/config/environment.rb +5 -0
  63. data/spec/dummy/config/environments/development.rb +62 -0
  64. data/spec/dummy/config/environments/production.rb +112 -0
  65. data/spec/dummy/config/environments/test.rb +49 -0
  66. data/spec/dummy/config/initializers/application_controller_renderer.rb +8 -0
  67. data/spec/dummy/config/initializers/assets.rb +12 -0
  68. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  69. data/spec/dummy/config/initializers/content_security_policy.rb +28 -0
  70. data/spec/dummy/config/initializers/cookies_serializer.rb +5 -0
  71. data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  72. data/spec/dummy/config/initializers/inflections.rb +16 -0
  73. data/spec/dummy/config/initializers/mime_types.rb +4 -0
  74. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  75. data/spec/dummy/config/locales/en.yml +40 -0
  76. data/spec/dummy/config/puma.rb +38 -0
  77. data/spec/dummy/config/routes.rb +4 -0
  78. data/spec/dummy/config/spring.rb +6 -0
  79. data/spec/dummy/config/storage.yml +34 -0
  80. data/spec/dummy/config.ru +5 -0
  81. data/spec/dummy/db/schema.rb +84 -0
  82. data/spec/dummy/lib/assets/.keep +0 -0
  83. data/spec/dummy/log/.keep +0 -0
  84. data/spec/dummy/public/404.html +67 -0
  85. data/spec/dummy/public/422.html +67 -0
  86. data/spec/dummy/public/500.html +66 -0
  87. data/spec/dummy/public/apple-touch-icon-precomposed.png +0 -0
  88. data/spec/dummy/public/apple-touch-icon.png +0 -0
  89. data/spec/dummy/public/favicon.ico +0 -0
  90. data/spec/dummy/tmp/development_secret.txt +1 -0
  91. data/spec/fixtures/accounts.yml +10 -0
  92. data/spec/fixtures/custom_primary_key_tasks.yml +2 -0
  93. data/spec/fixtures/global_projects.yml +13 -0
  94. data/spec/fixtures/projects.yml +10 -0
  95. data/spec/helpers/tenant_helper_spec.rb +16 -0
  96. data/spec/middlewares/test_tenant_middleware_spec.rb +86 -0
  97. data/spec/models/model_extensions_spec.rb +413 -0
  98. data/spec/spec_helper.rb +9 -13
  99. metadata +205 -41
  100. data/.gitignore +0 -7
  101. data/.travis.yml +0 -4
  102. data/CHANGELOG.md +0 -112
  103. data/Gemfile +0 -4
  104. data/_config.yml +0 -1
  105. data/acts_as_tenant.gemspec +0 -32
  106. data/docs/blog_post.md +0 -67
  107. data/rails/init.rb +0 -2
  108. data/spec/active_record_helper.rb +0 -22
  109. data/spec/active_record_models.rb +0 -116
  110. data/spec/acts_as_tenant/model_extensions_spec.rb +0 -420
  111. data/spec/acts_as_tenant/tenant_by_subdomain_or_domain.rb +0 -46
  112. data/spec/acts_as_tenant/tenant_by_subdomain_spec.rb +0 -32
  113. data/spec/database.yml +0 -3
@@ -0,0 +1,7 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces.
4
+ # Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ }
5
+
6
+ # You can also remove all the silencers if you're trying to debug a problem that might stem from framework code.
7
+ # Rails.backtrace_cleaner.remove_silencers!
@@ -0,0 +1,28 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Define an application-wide content security policy
4
+ # For further information see the following documentation
5
+ # https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy
6
+
7
+ # Rails.application.config.content_security_policy do |policy|
8
+ # policy.default_src :self, :https
9
+ # policy.font_src :self, :https, :data
10
+ # policy.img_src :self, :https, :data
11
+ # policy.object_src :none
12
+ # policy.script_src :self, :https
13
+ # policy.style_src :self, :https
14
+
15
+ # # Specify URI for violation reports
16
+ # # policy.report_uri "/csp-violation-report-endpoint"
17
+ # end
18
+
19
+ # If you are using UJS then enable automatic nonce generation
20
+ # Rails.application.config.content_security_policy_nonce_generator = -> request { SecureRandom.base64(16) }
21
+
22
+ # Set the nonce only to specific directives
23
+ # Rails.application.config.content_security_policy_nonce_directives = %w(script-src)
24
+
25
+ # Report CSP violations to a specified URI
26
+ # For further information see the following documentation:
27
+ # https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy-Report-Only
28
+ # Rails.application.config.content_security_policy_report_only = true
@@ -0,0 +1,5 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Specify a serializer for the signed and encrypted cookie jars.
4
+ # Valid options are :json, :marshal, and :hybrid.
5
+ Rails.application.config.action_dispatch.cookies_serializer = :json
@@ -0,0 +1,4 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Configure sensitive parameters which will be filtered from the log file.
4
+ Rails.application.config.filter_parameters += [:password]
@@ -0,0 +1,16 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Add new inflection rules using the following format. Inflections
4
+ # are locale specific, and you may define rules for as many different
5
+ # locales as you wish. All of these examples are active by default:
6
+ # ActiveSupport::Inflector.inflections(:en) do |inflect|
7
+ # inflect.plural /^(ox)$/i, '\1en'
8
+ # inflect.singular /^(ox)en/i, '\1'
9
+ # inflect.irregular 'person', 'people'
10
+ # inflect.uncountable %w( fish sheep )
11
+ # end
12
+
13
+ # These inflection rules are supported but not enabled by default:
14
+ # ActiveSupport::Inflector.inflections(:en) do |inflect|
15
+ # inflect.acronym 'RESTful'
16
+ # end
@@ -0,0 +1,4 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Add new mime types for use in respond_to blocks:
4
+ # Mime::Type.register "text/richtext", :rtf
@@ -0,0 +1,14 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # This file contains settings for ActionController::ParamsWrapper which
4
+ # is enabled by default.
5
+
6
+ # Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array.
7
+ ActiveSupport.on_load(:action_controller) do
8
+ wrap_parameters format: [:json]
9
+ end
10
+
11
+ # To enable root element in JSON for ActiveRecord objects.
12
+ # ActiveSupport.on_load(:active_record) do
13
+ # self.include_root_in_json = true
14
+ # end
@@ -0,0 +1,40 @@
1
+ # Files in the config/locales directory are used for internationalization
2
+ # and are automatically loaded by Rails. If you want to use locales other
3
+ # than English, add the necessary files in this directory.
4
+ #
5
+ # To use the locales, use `I18n.t`:
6
+ #
7
+ # I18n.t 'hello'
8
+ #
9
+ # In views, this is aliased to just `t`:
10
+ #
11
+ # <%= t('hello') %>
12
+ #
13
+ # To use a different locale, set it with `I18n.locale`:
14
+ #
15
+ # I18n.locale = :es
16
+ #
17
+ # This would use the information in config/locales/es.yml.
18
+ #
19
+ # The following keys must be escaped otherwise they will not be retrieved by
20
+ # the default I18n backend:
21
+ #
22
+ # true, false, on, off, yes, no
23
+ #
24
+ # Instead, surround them with single quotes.
25
+ #
26
+ # en:
27
+ # 'true': 'foo'
28
+ #
29
+ # To learn more, please read the Rails Internationalization guide
30
+ # available at https://guides.rubyonrails.org/i18n.html.
31
+
32
+ en:
33
+ hello: "Hello world"
34
+ notifications:
35
+ noticed/i18n_example:
36
+ message: "This is a notification"
37
+ noticed:
38
+ scoped_i18n_example:
39
+ message: "This is a custom scoped trnaslation"
40
+
@@ -0,0 +1,38 @@
1
+ # Puma can serve each request in a thread from an internal thread pool.
2
+ # The `threads` method setting takes two numbers: a minimum and maximum.
3
+ # Any libraries that use thread pools should be configured to match
4
+ # the maximum value specified for Puma. Default is set to 5 threads for minimum
5
+ # and maximum; this matches the default thread size of Active Record.
6
+ #
7
+ max_threads_count = ENV.fetch("RAILS_MAX_THREADS", 5)
8
+ min_threads_count = ENV.fetch("RAILS_MIN_THREADS", max_threads_count)
9
+ threads min_threads_count, max_threads_count
10
+
11
+ # Specifies the `port` that Puma will listen on to receive requests; default is 3000.
12
+ #
13
+ port ENV.fetch("PORT", 3000)
14
+
15
+ # Specifies the `environment` that Puma will run in.
16
+ #
17
+ environment ENV.fetch("RAILS_ENV", "development")
18
+
19
+ # Specifies the `pidfile` that Puma will use.
20
+ pidfile ENV.fetch("PIDFILE", "tmp/pids/server.pid")
21
+
22
+ # Specifies the number of `workers` to boot in clustered mode.
23
+ # Workers are forked web server processes. If using threads and workers together
24
+ # the concurrency of the application would be max `threads` * `workers`.
25
+ # Workers do not work on JRuby or Windows (both of which do not support
26
+ # processes).
27
+ #
28
+ # workers ENV.fetch("WEB_CONCURRENCY") { 2 }
29
+
30
+ # Use the `preload_app!` method when specifying a `workers` number.
31
+ # This directive tells Puma to first boot the application and load code
32
+ # before forking the application. This takes advantage of Copy On Write
33
+ # process behavior so workers use less memory.
34
+ #
35
+ # preload_app!
36
+
37
+ # Allow puma to be restarted by `rails restart` command.
38
+ plugin :tmp_restart
@@ -0,0 +1,4 @@
1
+ Rails.application.routes.draw do
2
+ # For details on the DSL available within this file, see https://guides.rubyonrails.org/routing.html
3
+ root to: "main#index"
4
+ end
@@ -0,0 +1,6 @@
1
+ Spring.watch(
2
+ ".ruby-version",
3
+ ".rbenv-vars",
4
+ "tmp/restart.txt",
5
+ "tmp/caching-dev.txt"
6
+ )
@@ -0,0 +1,34 @@
1
+ test:
2
+ service: Disk
3
+ root: <%= Rails.root.join("tmp/storage") %>
4
+
5
+ local:
6
+ service: Disk
7
+ root: <%= Rails.root.join("storage") %>
8
+
9
+ # Use rails credentials:edit to set the AWS secrets (as aws:access_key_id|secret_access_key)
10
+ # amazon:
11
+ # service: S3
12
+ # access_key_id: <%= Rails.application.credentials.dig(:aws, :access_key_id) %>
13
+ # secret_access_key: <%= Rails.application.credentials.dig(:aws, :secret_access_key) %>
14
+ # region: us-east-1
15
+ # bucket: your_own_bucket
16
+
17
+ # Remember not to checkin your GCS keyfile to a repository
18
+ # google:
19
+ # service: GCS
20
+ # project: your_project
21
+ # credentials: <%= Rails.root.join("path/to/gcs.keyfile") %>
22
+ # bucket: your_own_bucket
23
+
24
+ # Use rails credentials:edit to set the Azure Storage secret (as azure_storage:storage_access_key)
25
+ # microsoft:
26
+ # service: AzureStorage
27
+ # storage_account_name: your_account_name
28
+ # storage_access_key: <%= Rails.application.credentials.dig(:azure_storage, :storage_access_key) %>
29
+ # container: your_container_name
30
+
31
+ # mirror:
32
+ # service: Mirror
33
+ # primary: local
34
+ # mirrors: [ amazon, google, microsoft ]
@@ -0,0 +1,5 @@
1
+ # This file is used by Rack-based servers to start the application.
2
+
3
+ require_relative "config/environment"
4
+
5
+ run Rails.application
@@ -0,0 +1,84 @@
1
+ # This file is auto-generated from the current state of the database. Instead
2
+ # of editing this file, please use the migrations feature of Active Record to
3
+ # incrementally modify your database, and then regenerate this schema definition.
4
+ #
5
+ # This file is the source Rails uses to define your schema when running `rails
6
+ # db:schema:load`. When creating a new database, `rails db:schema:load` tends to
7
+ # be faster and is potentially less error prone than running all of your
8
+ # migrations from scratch. Old migrations may fail to apply correctly if those
9
+ # migrations use external dependencies or application code.
10
+ #
11
+ # It's strongly recommended that you check this file into your version control system.
12
+
13
+ ActiveRecord::Schema.define(version: 1) do
14
+ create_table :accounts, force: true do |t|
15
+ t.column :name, :string
16
+ t.column :subdomain, :string
17
+ t.column :domain, :string
18
+ t.column :projects_count, :integer, default: 0
19
+ end
20
+
21
+ create_table :projects, force: true do |t|
22
+ t.column :name, :string
23
+ t.column :account_id, :integer
24
+ end
25
+
26
+ create_table :managers, force: true do |t|
27
+ t.column :name, :string
28
+ t.column :project_id, :integer
29
+ t.column :account_id, :integer
30
+ end
31
+
32
+ create_table :tasks, force: true do |t|
33
+ t.column :name, :string
34
+ t.column :account_id, :integer
35
+ t.column :project_id, :integer
36
+ t.column :completed, :boolean
37
+ end
38
+
39
+ create_table :countries, force: true do |t|
40
+ t.column :name, :string
41
+ end
42
+
43
+ create_table :unscoped_models, force: true do |t|
44
+ t.column :name, :string
45
+ end
46
+
47
+ create_table :aliased_tasks, force: true do |t|
48
+ t.column :name, :string
49
+ t.column :project_alias_id, :integer
50
+ t.column :account_id, :integer
51
+ end
52
+
53
+ create_table :unique_tasks, force: true do |t|
54
+ t.column :name, :string
55
+ t.column :user_defined_scope, :string
56
+ t.column :project_id, :integer
57
+ t.column :account_id, :integer
58
+ end
59
+
60
+ create_table :custom_foreign_key_tasks, force: true do |t|
61
+ t.column :name, :string
62
+ t.column :accountID, :integer
63
+ end
64
+
65
+ create_table :custom_primary_key_tasks, force: true do |t|
66
+ t.column :name, :string
67
+ end
68
+
69
+ create_table :articles, force: true do |t|
70
+ t.column :title, :string
71
+ end
72
+
73
+ create_table :comments, force: true do |t|
74
+ t.column :commentable_id, :integer
75
+ t.column :commentable_type, :string
76
+ t.column :account_id, :integer
77
+ end
78
+
79
+ create_table :polymorphic_tenant_comments, force: true do |t|
80
+ t.column :polymorphic_tenant_commentable_id, :integer
81
+ t.column :polymorphic_tenant_commentable_type, :string
82
+ t.column :account_id, :integer
83
+ end
84
+ end
File without changes
File without changes
@@ -0,0 +1,67 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The page you were looking for doesn't exist (404)</title>
5
+ <meta name="viewport" content="width=device-width,initial-scale=1">
6
+ <style>
7
+ .rails-default-error-page {
8
+ background-color: #EFEFEF;
9
+ color: #2E2F30;
10
+ text-align: center;
11
+ font-family: arial, sans-serif;
12
+ margin: 0;
13
+ }
14
+
15
+ .rails-default-error-page div.dialog {
16
+ width: 95%;
17
+ max-width: 33em;
18
+ margin: 4em auto 0;
19
+ }
20
+
21
+ .rails-default-error-page div.dialog > div {
22
+ border: 1px solid #CCC;
23
+ border-right-color: #999;
24
+ border-left-color: #999;
25
+ border-bottom-color: #BBB;
26
+ border-top: #B00100 solid 4px;
27
+ border-top-left-radius: 9px;
28
+ border-top-right-radius: 9px;
29
+ background-color: white;
30
+ padding: 7px 12% 0;
31
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
32
+ }
33
+
34
+ .rails-default-error-page h1 {
35
+ font-size: 100%;
36
+ color: #730E15;
37
+ line-height: 1.5em;
38
+ }
39
+
40
+ .rails-default-error-page div.dialog > p {
41
+ margin: 0 0 1em;
42
+ padding: 1em;
43
+ background-color: #F7F7F7;
44
+ border: 1px solid #CCC;
45
+ border-right-color: #999;
46
+ border-left-color: #999;
47
+ border-bottom-color: #999;
48
+ border-bottom-left-radius: 4px;
49
+ border-bottom-right-radius: 4px;
50
+ border-top-color: #DADADA;
51
+ color: #666;
52
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
53
+ }
54
+ </style>
55
+ </head>
56
+
57
+ <body class="rails-default-error-page">
58
+ <!-- This file lives in public/404.html -->
59
+ <div class="dialog">
60
+ <div>
61
+ <h1>The page you were looking for doesn't exist.</h1>
62
+ <p>You may have mistyped the address or the page may have moved.</p>
63
+ </div>
64
+ <p>If you are the application owner check the logs for more information.</p>
65
+ </div>
66
+ </body>
67
+ </html>
@@ -0,0 +1,67 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The change you wanted was rejected (422)</title>
5
+ <meta name="viewport" content="width=device-width,initial-scale=1">
6
+ <style>
7
+ .rails-default-error-page {
8
+ background-color: #EFEFEF;
9
+ color: #2E2F30;
10
+ text-align: center;
11
+ font-family: arial, sans-serif;
12
+ margin: 0;
13
+ }
14
+
15
+ .rails-default-error-page div.dialog {
16
+ width: 95%;
17
+ max-width: 33em;
18
+ margin: 4em auto 0;
19
+ }
20
+
21
+ .rails-default-error-page div.dialog > div {
22
+ border: 1px solid #CCC;
23
+ border-right-color: #999;
24
+ border-left-color: #999;
25
+ border-bottom-color: #BBB;
26
+ border-top: #B00100 solid 4px;
27
+ border-top-left-radius: 9px;
28
+ border-top-right-radius: 9px;
29
+ background-color: white;
30
+ padding: 7px 12% 0;
31
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
32
+ }
33
+
34
+ .rails-default-error-page h1 {
35
+ font-size: 100%;
36
+ color: #730E15;
37
+ line-height: 1.5em;
38
+ }
39
+
40
+ .rails-default-error-page div.dialog > p {
41
+ margin: 0 0 1em;
42
+ padding: 1em;
43
+ background-color: #F7F7F7;
44
+ border: 1px solid #CCC;
45
+ border-right-color: #999;
46
+ border-left-color: #999;
47
+ border-bottom-color: #999;
48
+ border-bottom-left-radius: 4px;
49
+ border-bottom-right-radius: 4px;
50
+ border-top-color: #DADADA;
51
+ color: #666;
52
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
53
+ }
54
+ </style>
55
+ </head>
56
+
57
+ <body class="rails-default-error-page">
58
+ <!-- This file lives in public/422.html -->
59
+ <div class="dialog">
60
+ <div>
61
+ <h1>The change you wanted was rejected.</h1>
62
+ <p>Maybe you tried to change something you didn't have access to.</p>
63
+ </div>
64
+ <p>If you are the application owner check the logs for more information.</p>
65
+ </div>
66
+ </body>
67
+ </html>
@@ -0,0 +1,66 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>We're sorry, but something went wrong (500)</title>
5
+ <meta name="viewport" content="width=device-width,initial-scale=1">
6
+ <style>
7
+ .rails-default-error-page {
8
+ background-color: #EFEFEF;
9
+ color: #2E2F30;
10
+ text-align: center;
11
+ font-family: arial, sans-serif;
12
+ margin: 0;
13
+ }
14
+
15
+ .rails-default-error-page div.dialog {
16
+ width: 95%;
17
+ max-width: 33em;
18
+ margin: 4em auto 0;
19
+ }
20
+
21
+ .rails-default-error-page div.dialog > div {
22
+ border: 1px solid #CCC;
23
+ border-right-color: #999;
24
+ border-left-color: #999;
25
+ border-bottom-color: #BBB;
26
+ border-top: #B00100 solid 4px;
27
+ border-top-left-radius: 9px;
28
+ border-top-right-radius: 9px;
29
+ background-color: white;
30
+ padding: 7px 12% 0;
31
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
32
+ }
33
+
34
+ .rails-default-error-page h1 {
35
+ font-size: 100%;
36
+ color: #730E15;
37
+ line-height: 1.5em;
38
+ }
39
+
40
+ .rails-default-error-page div.dialog > p {
41
+ margin: 0 0 1em;
42
+ padding: 1em;
43
+ background-color: #F7F7F7;
44
+ border: 1px solid #CCC;
45
+ border-right-color: #999;
46
+ border-left-color: #999;
47
+ border-bottom-color: #999;
48
+ border-bottom-left-radius: 4px;
49
+ border-bottom-right-radius: 4px;
50
+ border-top-color: #DADADA;
51
+ color: #666;
52
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
53
+ }
54
+ </style>
55
+ </head>
56
+
57
+ <body class="rails-default-error-page">
58
+ <!-- This file lives in public/500.html -->
59
+ <div class="dialog">
60
+ <div>
61
+ <h1>We're sorry, but something went wrong.</h1>
62
+ </div>
63
+ <p>If you are the application owner check the logs for more information.</p>
64
+ </div>
65
+ </body>
66
+ </html>
File without changes
File without changes
@@ -0,0 +1 @@
1
+ f1e8981c98a3cd825ba410f2080160547945e8c380645e0dfaeba509fa55291dcd4e317d6c2ba08bc94a4110b6c567987a66f616f67e3b5f62e11a4b216820e6
@@ -0,0 +1,10 @@
1
+ foo:
2
+ name: foo
3
+
4
+ bar:
5
+ name: bar
6
+
7
+ with_domain:
8
+ name: domain
9
+ subdomain: domain
10
+ domain: domain.com
@@ -0,0 +1,2 @@
1
+ without_account:
2
+ name: "bar"
@@ -0,0 +1,13 @@
1
+ global:
2
+ name: "global"
3
+
4
+ global2:
5
+ name: "global 2"
6
+
7
+ global_foo:
8
+ account: foo
9
+ name: "global foo"
10
+
11
+ global_bar:
12
+ account: bar
13
+ name: "global bar"
@@ -0,0 +1,10 @@
1
+ without_account:
2
+ name: without_account
3
+
4
+ foo:
5
+ account: foo
6
+ name: foo
7
+
8
+ bar:
9
+ account: bar
10
+ name: bar
@@ -0,0 +1,16 @@
1
+ require "spec_helper"
2
+
3
+ describe ActionView::Base, type: :helper do
4
+ it "responds ot current_tenant" do
5
+ expect(helper).to respond_to(:current_tenant)
6
+ end
7
+
8
+ it "returns nil if no tenant set" do
9
+ expect(helper.current_tenant).to be_nil
10
+ end
11
+
12
+ it "returns the current tenant" do
13
+ ActsAsTenant.current_tenant = accounts(:foo)
14
+ expect(helper.current_tenant).to eq(accounts(:foo))
15
+ end
16
+ end
@@ -0,0 +1,86 @@
1
+ require "spec_helper"
2
+ require "acts_as_tenant/test_tenant_middleware"
3
+
4
+ class TestRackApp1
5
+ def call(_env)
6
+ ActsAsTenant.current_tenant = Account.first
7
+ TestReceiver.assert_current_id(ActsAsTenant.current_tenant.id)
8
+ ActsAsTenant.current_tenant = nil
9
+ [200, {}, ["OK"]]
10
+ end
11
+ end
12
+
13
+ class TestRackApp2
14
+ def call(_env)
15
+ TestReceiver.assert_current_id(ActsAsTenant.current_tenant.try(:id))
16
+ [200, {}, ["OK"]]
17
+ end
18
+ end
19
+
20
+ class TestReceiver
21
+ def self.assert_current_id(id)
22
+ end
23
+ end
24
+
25
+ describe ActsAsTenant::TestTenantMiddleware do
26
+ fixtures :accounts
27
+ after { ActsAsTenant.test_tenant = nil }
28
+
29
+ subject { request.get("/some/path") }
30
+
31
+ let(:middleware) { described_class.new(app) }
32
+ let(:request) { Rack::MockRequest.new(middleware) }
33
+
34
+ let!(:account1) { accounts(:foo) }
35
+ let!(:account2) { accounts(:bar) }
36
+
37
+ context "when test_tenant is nil before processing" do
38
+ context "that switches tenancies" do
39
+ let(:app) { TestRackApp1.new }
40
+
41
+ it "should remain nil after processing" do
42
+ expect(ActsAsTenant.current_tenant).to be_nil
43
+ expect(TestReceiver).to receive(:assert_current_id).with(account1.id)
44
+ expect(subject.status).to eq 200
45
+ expect(ActsAsTenant.current_tenant).to be_nil
46
+ end
47
+ end
48
+
49
+ context "that does not switch tenancies" do
50
+ let(:app) { TestRackApp2.new }
51
+
52
+ it "should remain nil after processing" do
53
+ expect(ActsAsTenant.current_tenant).to be_nil
54
+ expect(TestReceiver).to receive(:assert_current_id).with(nil)
55
+ expect(subject.status).to eq 200
56
+ expect(ActsAsTenant.current_tenant).to be_nil
57
+ end
58
+ end
59
+ end
60
+
61
+ context "when test_tenant is assigned before processing" do
62
+ before { ActsAsTenant.test_tenant = account2 }
63
+
64
+ context "that switches tenancies" do
65
+ let(:app) { TestRackApp1.new }
66
+
67
+ it "should remain assigned after processing" do
68
+ expect(ActsAsTenant.current_tenant).to eq account2
69
+ expect(TestReceiver).to receive(:assert_current_id).with(account1.id)
70
+ expect(subject.status).to eq 200
71
+ expect(ActsAsTenant.current_tenant).to eq account2
72
+ end
73
+ end
74
+
75
+ context "that does not switch tenancies" do
76
+ let(:app) { TestRackApp2.new }
77
+
78
+ it "should remain assigned after processing" do
79
+ expect(ActsAsTenant.current_tenant).to eq account2
80
+ expect(TestReceiver).to receive(:assert_current_id).with(nil)
81
+ expect(subject.status).to eq 200
82
+ expect(ActsAsTenant.current_tenant).to eq account2
83
+ end
84
+ end
85
+ end
86
+ end