Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Changed subdomain resolution. Added specs for controller extensions.

  • Loading branch information...
commit 0ee45147484534fb5c7ce36c9e4c012861cfc162 1 parent 5eead22
@ErwinM authored
View
6 CHANGELOG.md
@@ -1,3 +1,9 @@
+0.3.2
+-----
+* correctly support nested models with has_many :through (thx dexion)
+* Support 'www.subdomain.example.com' (thx wtfiwtz)
+* Support setting `tenant_id` on scoped models if the `tenant_id` is nil (thx Matt Wilson)
+
0.3.1
-----
* Added support for Rails 4
View
1  acts_as_tenant.gemspec
@@ -24,6 +24,7 @@ Gem::Specification.new do |s|
#s.add_dependency('request_store', '>= 1.0.5')
s.add_development_dependency('rspec')
+ s.add_development_dependency('rspec-rails')
s.add_development_dependency('database_cleaner')
s.add_development_dependency('sqlite3')
s.add_development_dependency('debugger')
View
2  lib/acts_as_tenant/controller_extensions.rb
@@ -18,7 +18,7 @@ def set_current_tenant_by_subdomain(tenant = :account, column = :subdomain )
private
def find_tenant_by_subdomain
- ActsAsTenant.current_tenant = tenant_class.where(tenant_column => request.subdomains.first).first
+ ActsAsTenant.current_tenant = tenant_class.where(tenant_column => request.subdomains.last).first
end
def current_tenant
View
2  lib/acts_as_tenant/version.rb
@@ -1,3 +1,3 @@
module ActsAsTenant
- VERSION = "0.3.1"
+ VERSION = "0.3.2"
end
View
1  spec/acts_as_tenant/model_extensions_spec.rb
@@ -4,6 +4,7 @@
ActiveRecord::Schema.define(:version => 1) do
create_table :accounts, :force => true do |t|
t.column :name, :string
+ t.column :subdomain, :string
end
create_table :projects, :force => true do |t|
View
33 spec/acts_as_tenant/tenant_by_filter_spec.rb
@@ -0,0 +1,33 @@
+require "spec_helper"
+
+#Setup test specific ApplicationController
+class Account
+ attr_accessor :name
+end
+
+class ApplicationController2 < ActionController::Base
+ include Rails.application.routes.url_helpers
+ set_current_tenant_through_filter
+ before_filter :your_method_that_finds_the_current_tenant
+
+ def your_method_that_finds_the_current_tenant
+ current_account = Account.new
+ current_account.name = 'account1'
+ set_current_tenant(current_account)
+ end
+
+end
+
+# Start testing
+describe ApplicationController2, :type => :controller do
+ controller do
+ def index
+ render :text => "custom called"
+ end
+ end
+
+ it 'Finds the correct tenant using the filter command' do
+ get :index
+ ActsAsTenant.current_tenant.name.should eq 'account1'
+ end
+end
View
32 spec/acts_as_tenant/tenant_by_subdomain_spec.rb
@@ -0,0 +1,32 @@
+require "spec_helper"
+
+#Setup test specific ApplicationController
+class Account; end # this is so the spec will work in isolation
+
+class ApplicationController < ActionController::Base
+ include Rails.application.routes.url_helpers
+ set_current_tenant_by_subdomain
+end
+
+# Start testing
+describe ApplicationController, :type => :controller do
+ controller do
+ def index
+ render :text => "custom called"
+ end
+ end
+
+ it 'Finds the correct tenant with a subdomain.example.com' do
+ @request.host = "account1.example.com"
+ Account.should_receive(:where).with({subdomain: 'account1'}) {['account1']}
+ get :index
+ ActsAsTenant.current_tenant.should eq 'account1'
+ end
+
+ it 'Finds the correct tenant with a www.subdomain.example.com' do
+ @request.host = "www.account1.example.com"
+ Account.should_receive(:where).with({subdomain: 'account1'}) {['account1']}
+ get :index
+ ActsAsTenant.current_tenant.should eq 'account1'
+ end
+end
View
13 spec/spec_helper.rb
@@ -3,6 +3,8 @@
require 'database_cleaner'
require 'acts_as_tenant'
+require 'rspec/rails'
+require 'rails'
config = YAML::load(IO.read(File.join(File.dirname(__FILE__), 'database.yml')))
ActiveRecord::Base.logger = Logger.new(File.join(File.dirname(__FILE__), "debug.log"))
@@ -22,5 +24,14 @@
DatabaseCleaner.clean
ActsAsTenant.current_tenant = nil
end
+
+ config.infer_base_class_for_anonymous_controllers = true
+end
-end
+# Setup a test app
+module Rollcall
+ class Application < Rails::Application; end
+end
+
+Rollcall::Application.config.secret_token = '1234567890123456789012345678901234567890'
+Rollcall::Application.config.secret_key_base = '1234567890123456789012345678901234567890'
Please sign in to comment.
Something went wrong with that request. Please try again.