apartment 0.12.0 → 0.13.0

Sign up to get free protection for your applications and to get access to all the features.
data/HISTORY.md CHANGED
@@ -1,5 +1,12 @@
1
+ # 0.13.0
2
+ * Oct 25, 2011
3
+
4
+ - `process` will now rescue with reset if the previous schema/db is no longer available
5
+ - `create` now takes an optional block which allows you to process within the newly created db
6
+ - Fixed Rails version >= 3.0.10 and < 3.1 because there have been significant testing problems with 3.1, next version will hopefully fix this
7
+
1
8
  # 0.12.0
2
- * Oct 4, 2001
9
+ * Oct 4, 2011
3
10
 
4
11
  - Added a `drop` method for removing databases/schemas
5
12
  - Refactored abstract adapter to further remove duplication in concrete implementations
data/README.md CHANGED
@@ -1,6 +1,16 @@
1
1
  # Apartment
2
2
  *Multitenancy for Rails 3*
3
3
 
4
+ > IMPORTANT! While I will do everything possible to get Apartment working for Rails 3.1, I haven't, as of yet, had this opportunity.
5
+
6
+ > There have been significant changes in the adapters such as prepared statements that might cause some issues.
7
+
8
+ > If anyone is successfully using Apartment with 3.1 please let me know, but please ensure that you're testing data integrity properly (ie. that queries are made in the right schema) as prepared_statements
9
+ > could really throw a wrench in that one.
10
+
11
+ > I know for a fact that Rails 3.1 missed a patch to make postgresql more schema aware, but it seems to have made it into Rails 3.1.1. So at the very least, use 3.1.1
12
+
13
+
4
14
  Apartment provides tools to help you deal with multiple databases in your Rails
5
15
  application. If you need to have certain data sequestered based on account or company,
6
16
  but still allow some data to exist in a common database, Apartment can help.
data/Rakefile CHANGED
@@ -65,6 +65,7 @@ namespace :mysql do
65
65
 
66
66
  end
67
67
 
68
+ # TODO clean this up
68
69
  def config
69
70
  Apartment::Test.config['connections']
70
71
  end
data/apartment.gemspec CHANGED
@@ -7,7 +7,6 @@ Gem::Specification.new do |s|
7
7
  s.version = Apartment::VERSION
8
8
 
9
9
  s.authors = ["Ryan Brunner", "Brad Robertson"]
10
- s.date = %q{2011-04-18}
11
10
  s.summary = %q{A Ruby gem for managing database multitenancy in Rails applications}
12
11
  s.description = %q{Apartment allows Rails applications to deal with database multitenancy}
13
12
  s.email = %w{ryan@ryanbrunner.com bradleyrobertson@gmail.com}
@@ -19,7 +18,7 @@ Gem::Specification.new do |s|
19
18
  s.require_paths = ["lib"]
20
19
  s.rubygems_version = %q{1.3.7}
21
20
 
22
- s.add_dependency 'rails', '>= 3.0.10'
21
+ s.add_dependency 'rails', '~> 3.0.10' # must be >= 3.0.10 due to poor schema support pre 3.0.10, but < 3.1 because it hasn't been fully tested yet
23
22
  s.add_development_dependency 'rake', '~> 0.8.7'
24
23
  s.add_development_dependency 'sqlite3'
25
24
  s.add_development_dependency 'rspec', '~> 2.6.0'
@@ -27,6 +27,8 @@ module Apartment
27
27
 
28
28
  # Seed data if appropriate
29
29
  seed_data if Apartment.seed_after_create
30
+
31
+ yield if block_given?
30
32
  end
31
33
  end
32
34
 
@@ -69,7 +71,7 @@ module Apartment
69
71
  yield if block_given?
70
72
 
71
73
  ensure
72
- switch(current_db)
74
+ switch(current_db) rescue reset
73
75
  end
74
76
 
75
77
  # Establish a new connection for each specific excluded model
@@ -140,7 +142,7 @@ module Apartment
140
142
  # Import the database schema
141
143
  #
142
144
  def import_database_schema
143
- ActiveRecord::Schema.verbose = false # do not log schema load output. Note that this is slightly duplicated below with silenct_stream, except that this also works with Spork
145
+ ActiveRecord::Schema.verbose = false # do not log schema load output.
144
146
  load_or_abort("#{Rails.root}/db/schema.rb")
145
147
  end
146
148
 
@@ -78,7 +78,7 @@ module Apartment
78
78
  end
79
79
  end
80
80
  end
81
-
81
+
82
82
  # Reset schema search path to the default schema_search_path
83
83
  #
84
84
  # @return {String} default schema search path
@@ -1,3 +1,3 @@
1
1
  module Apartment
2
- VERSION = "0.12.0"
2
+ VERSION = "0.13.0"
3
3
  end
@@ -23,10 +23,13 @@ describe Apartment::Adapters::PostgresqlAdapter do
23
23
  before do
24
24
  Apartment.use_postgres_schemas = true
25
25
  subject.create(schema)
26
+ subject.create(schema2)
26
27
  end
27
28
 
28
29
  after do
29
- Apartment::Test.drop_schema(schema)
30
+ # sometimes we manually drop these schemas in testing, dont' care if we can't drop hence rescue
31
+ subject.drop(schema) rescue true
32
+ subject.drop(schema2) rescue true
30
33
  end
31
34
 
32
35
  describe "#create" do
@@ -43,12 +46,26 @@ describe Apartment::Adapters::PostgresqlAdapter do
43
46
  it "should reset connection when finished" do
44
47
  ActiveRecord::Base.connection.schema_search_path.should_not == schema
45
48
  end
49
+
50
+ it "should yield to block if passed" do
51
+ Apartment::Test.migrate # ensure we have latest schema in the public
52
+ subject.drop(schema2) # so we don't get errors on creation
53
+
54
+ @count = 0 # set our variable so its visible in and outside of blocks
55
+
56
+ subject.create(schema2) do
57
+ @count = User.count
58
+ ActiveRecord::Base.connection.schema_search_path.should == schema2
59
+ User.create
60
+ end
61
+
62
+ subject.process(schema2){ User.count.should == @count + 1 }
63
+ end
46
64
  end
47
65
 
48
66
  describe "#drop" do
49
67
 
50
68
  it "should delete the database" do
51
- subject.create schema2
52
69
  subject.switch schema # can't drop db we're currently connected to, ensure these are different
53
70
  subject.drop schema2
54
71
 
@@ -74,6 +91,16 @@ describe Apartment::Adapters::PostgresqlAdapter do
74
91
  subject.process(schema)
75
92
  ActiveRecord::Base.connection.schema_search_path.should == @schema_search_path
76
93
  end
94
+
95
+ # We're often finding when using Apartment in tests, the `current_database` (ie the previously attached to schema)
96
+ # gets dropped, but process will try to return to that schema in a test. We should just reset if it doesnt exist
97
+ it "should not throw exception if current_database (schema) is no longer accessible" do
98
+ subject.switch(schema2)
99
+
100
+ expect {
101
+ subject.process(schema){ subject.drop(schema2) }
102
+ }.to_not raise_error(Apartment::SchemaNotFound)
103
+ end
77
104
  end
78
105
 
79
106
  describe "#reset" do
@@ -19,7 +19,7 @@ describe "apartment rake tasks" do
19
19
 
20
20
  before do
21
21
  Apartment.configure do |config|
22
- config.excluded_models = [Company]
22
+ config.excluded_models = ["Company"]
23
23
  config.database_names = lambda{ Company.scoped.collect(&:database) }
24
24
  end
25
25
  end
@@ -26,7 +26,7 @@ describe Apartment::Database do
26
26
 
27
27
  it "should process model exclusions" do
28
28
  Apartment.configure do |config|
29
- config.excluded_models = [Company]
29
+ config.excluded_models = ["Company"]
30
30
  end
31
31
 
32
32
  Apartment::Database.init
@@ -162,7 +162,7 @@ describe Apartment::Database do
162
162
 
163
163
  before do
164
164
  Apartment.configure do |config|
165
- config.excluded_models = [Company]
165
+ config.excluded_models = ["Company"]
166
166
  end
167
167
  Apartment::Database.init
168
168
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: apartment
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.12.0
5
+ version: 0.13.0
6
6
  platform: ruby
7
7
  authors:
8
8
  - Ryan Brunner
@@ -11,7 +11,7 @@ autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
13
 
14
- date: 2011-04-18 00:00:00 -04:00
14
+ date: 2011-10-25 00:00:00 -04:00
15
15
  default_executable:
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
@@ -19,7 +19,7 @@ dependencies:
19
19
  requirement: &id001 !ruby/object:Gem::Requirement
20
20
  none: false
21
21
  requirements:
22
- - - ">="
22
+ - - ~>
23
23
  - !ruby/object:Gem::Version
24
24
  version: 3.0.10
25
25
  type: :runtime
@@ -226,7 +226,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
226
226
  requirements:
227
227
  - - ">="
228
228
  - !ruby/object:Gem::Version
229
- hash: 1213020352034196308
229
+ hash: 2098096062583104418
230
230
  segments:
231
231
  - 0
232
232
  version: "0"
@@ -235,7 +235,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
235
235
  requirements:
236
236
  - - ">="
237
237
  - !ruby/object:Gem::Version
238
- hash: 1213020352034196308
238
+ hash: 2098096062583104418
239
239
  segments:
240
240
  - 0
241
241
  version: "0"