apartment 0.17.0 → 0.17.1

Sign up to get free protection for your applications and to get access to all the features.
data/HISTORY.md CHANGED
@@ -1,3 +1,8 @@
1
+ # 0.17.1
2
+ * Oct 30, 2012
3
+
4
+ - Fixed a bug where switching to an unknown db in mysql2 would crash the app [Frodotus]
5
+
1
6
  # 0.17.0
2
7
  * Sept 26, 2012
3
8
 
data/README.md CHANGED
@@ -231,3 +231,7 @@ All jobs *must* stored in the global (public) namespace, so add it to the list o
231
231
  * Rake tasks (see the Rakefile) will help you setup your dbs necessary to run tests
232
232
  * Please issue pull requests to the `development` branch. All development happens here, master is used for releases
233
233
  * Ensure that your code is accompanied with tests. No code will be merged without tests
234
+
235
+ ## License
236
+
237
+ Apartment is released under the [MIT License](http://www.opensource.org/licenses/MIT).
@@ -22,6 +22,7 @@ module Apartment
22
22
  def connect_to_new(database)
23
23
  super
24
24
  rescue Mysql2::Error
25
+ Apartment::Database.reset
25
26
  raise DatabaseNotFound, "Cannot find database #{environmentify(database)}"
26
27
  end
27
28
  end
@@ -1,3 +1,3 @@
1
1
  module Apartment
2
- VERSION = "0.17.0"
2
+ VERSION = "0.17.1"
3
3
  end
@@ -0,0 +1,5 @@
1
+ Description:
2
+ Creates an initializer for apartment.
3
+
4
+ Example:
5
+ `rails generate apartment:install`
@@ -0,0 +1,10 @@
1
+ module Apartment
2
+ class InstallGenerator < Rails::Generators::Base
3
+ source_root File.expand_path('../templates', __FILE__)
4
+
5
+ def copy_files
6
+ template "apartment.rb", File.join("config", "initializers", "apartment.rb")
7
+ end
8
+
9
+ end
10
+ end
@@ -0,0 +1,35 @@
1
+ ##
2
+ # Apartment Configuration
3
+ Apartment.configure do |config|
4
+
5
+ # these models will not be multi-tenanted,
6
+ # but remain in the global (public) namespace
7
+ config.excluded_models = %w{
8
+ ActiveRecord::SessionStore::Session
9
+ }
10
+
11
+ # use postgres schemas?
12
+ config.use_postgres_schemas = true
13
+
14
+ # configure persistent schemas (E.g. hstore )
15
+ # config.persistent_schemas = %w{ hstore }
16
+
17
+ # add the Rails environment to database names?
18
+ # config.prepend_environment = true
19
+ # config.append_environment = true
20
+
21
+ # supply list of database names
22
+ config.database_names = lambda{ ToDo_Tenant_Or_User_Model.scoped.collect(&:database) }
23
+
24
+ end
25
+
26
+ ##
27
+ # Elevator Configuration
28
+
29
+ # Rails.application.config.middleware.use 'Apartment::Elevators::Domain'
30
+
31
+ # Rails.application.config.middleware.use 'Apartment::Elevators::Subdomain'
32
+
33
+ Rails.application.config.middleware.use 'Apartment::Elevators::Generic', Proc.new { |request|
34
+ # TODO: supply generic implementation
35
+ }
@@ -9,7 +9,7 @@ describe Apartment::Database do
9
9
  before do
10
10
  ActiveRecord::Base.establish_connection config
11
11
  Apartment::Test.load_schema # load the Rails schema in the public db schema
12
- subject.stub(:config).and_return config # Use postgresql database config for this test
12
+ subject.stub(:config).and_return config # Use mysql database config for this test
13
13
  end
14
14
 
15
15
  describe "#adapter" do
@@ -21,6 +21,27 @@ describe Apartment::Database do
21
21
  subject.adapter
22
22
  Apartment::Adapters::Mysql2Adapter.should be_a(Class)
23
23
  end
24
+ end
25
+
26
+ # TODO this doesn't belong here, but there aren't integration tests currently for mysql
27
+ # where to put???
28
+ describe "#exception recovery", :type => :request do
29
+ let(:database1){ Apartment::Test.next_db }
30
+
31
+ before do
32
+ subject.reload!
33
+ subject.create database1
34
+ end
35
+ after{ subject.drop database1 }
36
+
37
+ it "should recover from incorrect database" do
38
+ session = Capybara::Session.new(:rack_test, Capybara.app)
39
+ session.visit("http://#{database1}.com")
40
+ expect {
41
+ session.visit("http://this-database-should-not-exist.com")
42
+ }.to raise_error
43
+ session.visit("http://#{database1}.com")
44
+ end
24
45
 
25
46
  end
26
47
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: apartment
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.17.0
4
+ version: 0.17.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-09-26 00:00:00.000000000 Z
13
+ date: 2012-10-30 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activerecord
@@ -259,6 +259,9 @@ files:
259
259
  - lib/apartment/sidekiq/client/database_middleware.rb
260
260
  - lib/apartment/sidekiq/server/database_middleware.rb
261
261
  - lib/apartment/version.rb
262
+ - lib/generators/apartment/install/USAGE
263
+ - lib/generators/apartment/install/install_generator.rb
264
+ - lib/generators/apartment/install/templates/apartment.rb
262
265
  - lib/tasks/apartment.rake
263
266
  - spec/adapters/mysql2_adapter_spec.rb
264
267
  - spec/adapters/postgresql_adapter_spec.rb
@@ -336,7 +339,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
336
339
  version: '0'
337
340
  segments:
338
341
  - 0
339
- hash: 345291853530360169
342
+ hash: -4170403971247658822
340
343
  required_rubygems_version: !ruby/object:Gem::Requirement
341
344
  none: false
342
345
  requirements:
@@ -345,7 +348,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
345
348
  version: '0'
346
349
  segments:
347
350
  - 0
348
- hash: 345291853530360169
351
+ hash: -4170403971247658822
349
352
  requirements: []
350
353
  rubyforge_project:
351
354
  rubygems_version: 1.8.24