apartment 0.20.0 → 0.21.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,3 +1,25 @@
1
+ <% if defined?(JRUBY_VERSION) %>
2
+ connections:
3
+ postgresql:
4
+ adapter: postgresql
5
+ database: apartment_postgresql_test
6
+ username: postgres
7
+ min_messages: WARNING
8
+ driver: org.postgresql.Driver
9
+ url: jdbc:postgresql://localhost:5432/apartment_postgresql_test
10
+ timeout: 5000
11
+ pool: 5
12
+
13
+ mysql:
14
+ adapter: mysql
15
+ database: apartment_mysql_test
16
+ username: root
17
+ min_messages: WARNING
18
+ driver: com.mysql.jdbc.Driver
19
+ url: jdbc:mysql://localhost:3306/apartment_mysql_test
20
+ timeout: 5000
21
+ pool: 5
22
+ <% else %>
1
23
  connections:
2
24
  postgresql:
3
25
  adapter: postgresql
@@ -12,3 +34,4 @@ connections:
12
34
  database: apartment_mysql_test
13
35
  username: root
14
36
  password:
37
+ <% end %>
@@ -1,6 +1,27 @@
1
1
  # Warning: The database defined as "test" will be erased and
2
2
  # re-generated from your development database when you run "rake".
3
3
  # Do not set this db to the same as development or production.
4
+ <% if defined?(JRUBY_VERSION) %>
5
+ test:
6
+ adapter: postgresql
7
+ database: apartment_postgresql_test
8
+ username: postgres
9
+ min_messages: WARNING
10
+ driver: org.postgresql.Driver
11
+ url: jdbc:postgresql://localhost:5432/apartment_postgresql_test
12
+ timeout: 5000
13
+ pool: 5
14
+
15
+ development:
16
+ adapter: postgresql
17
+ database: apartment_postgresql_development
18
+ username: postgres
19
+ min_messages: WARNING
20
+ driver: org.postgresql.Driver
21
+ url: jdbc:postgresql://localhost:5432/apartment_postgresql_development
22
+ timeout: 5000
23
+ pool: 5
24
+ <% else %>
4
25
  test:
5
26
  adapter: postgresql
6
27
  database: apartment_postgresql_test
@@ -14,3 +35,4 @@ development:
14
35
  min_messages: WARNING
15
36
  pool: 5
16
37
  timeout: 5000
38
+ <% end %>
@@ -3,85 +3,87 @@ require 'delayed_job'
3
3
  require 'delayed_job_active_record'
4
4
 
5
5
  describe Apartment::Delayed do
6
+ unless defined?(JRUBY_VERSION)
6
7
 
7
- # See apartment.yml file in dummy app config
8
+ # See apartment.yml file in dummy app config
8
9
 
9
- let(:config){ Apartment::Test.config['connections']['postgresql'].symbolize_keys }
10
- let(:database){ Apartment::Test.next_db }
11
- let(:database2){ Apartment::Test.next_db }
10
+ let(:config) { Apartment::Test.config['connections']['postgresql'].symbolize_keys }
11
+ let(:database) { Apartment::Test.next_db }
12
+ let(:database2) { Apartment::Test.next_db }
12
13
 
13
- before do
14
- ActiveRecord::Base.establish_connection config
15
- Apartment::Test.load_schema # load the Rails schema in the public db schema
16
- Apartment::Database.stub(:config).and_return config # Use postgresql database config for this test
17
-
18
- Apartment.configure do |config|
19
- config.use_schemas = true
20
- end
21
-
22
- Apartment::Database.create database
23
- Apartment::Database.create database2
24
- end
25
-
26
- after do
27
- Apartment::Test.drop_schema database
28
- Apartment::Test.drop_schema database2
29
- Apartment.reset
30
- end
14
+ before do
15
+ ActiveRecord::Base.establish_connection config
16
+ Apartment::Test.load_schema # load the Rails schema in the public db schema
17
+ Apartment::Database.stub(:config).and_return config # Use postgresql database config for this test
31
18
 
32
- describe Apartment::Delayed::Requirements do
19
+ Apartment.configure do |config|
20
+ config.use_schemas = true
21
+ end
33
22
 
34
- before do
35
- Apartment::Database.switch database
36
- User.send(:include, Apartment::Delayed::Requirements)
37
- User.create
23
+ Apartment::Database.create database
24
+ Apartment::Database.create database2
38
25
  end
39
26
 
40
- it "should initialize a database attribute on a class" do
41
- user = User.first
42
- user.database.should == database
27
+ after do
28
+ Apartment::Test.drop_schema database
29
+ Apartment::Test.drop_schema database2
30
+ Apartment.reset
43
31
  end
44
32
 
45
- it "should not overwrite any previous after_initialize declarations" do
46
- User.class_eval do
47
- after_find :set_name
33
+ describe Apartment::Delayed::Requirements do
48
34
 
49
- def set_name
50
- self.name = "Some Name"
51
- end
35
+ before do
36
+ Apartment::Database.switch database
37
+ User.send(:include, Apartment::Delayed::Requirements)
38
+ User.create
52
39
  end
53
40
 
54
- user = User.first
55
- user.database.should == database
56
- user.name.should == "Some Name"
57
- end
41
+ it "should initialize a database attribute on a class" do
42
+ user = User.first
43
+ user.database.should == database
44
+ end
58
45
 
59
- it "should set the db on a new record before it saves" do
60
- user = User.create
61
- user.database.should == database
62
- end
46
+ it "should not overwrite any previous after_initialize declarations" do
47
+ User.class_eval do
48
+ after_find :set_name
49
+
50
+ def set_name
51
+ self.name = "Some Name"
52
+ end
53
+ end
63
54
 
64
- context "serialization" do
65
- it "should serialize the proper database attribute" do
66
- user_yaml = User.first.to_yaml
67
- Apartment::Database.switch database2
68
- user = YAML.load user_yaml
55
+ user = User.first
69
56
  user.database.should == database
57
+ user.name.should == "Some Name"
58
+ end
59
+
60
+ it "should set the db on a new record before it saves" do
61
+ user = User.create
62
+ user.database.should == database
63
+ end
64
+
65
+ context "serialization" do
66
+ it "should serialize the proper database attribute" do
67
+ user_yaml = User.first.to_yaml
68
+ Apartment::Database.switch database2
69
+ user = YAML.load user_yaml
70
+ user.database.should == database
71
+ end
70
72
  end
71
73
  end
72
- end
73
74
 
74
- describe Apartment::Delayed::Job::Hooks do
75
+ describe Apartment::Delayed::Job::Hooks do
75
76
 
76
- let(:worker){ Delayed::Worker.new }
77
- let(:job){ Delayed::Job.enqueue User.new }
77
+ let(:worker) { Delayed::Worker.new }
78
+ let(:job) { Delayed::Job.enqueue User.new }
78
79
 
79
- it "should switch to previous db" do
80
- Apartment::Database.switch database
81
- worker.run(job)
80
+ it "should switch to previous db" do
81
+ Apartment::Database.switch database
82
+ worker.run(job)
82
83
 
83
- Apartment::Database.current_database.should == database
84
+ Apartment::Database.current_database.should == database
85
+ end
84
86
  end
85
- end
86
87
 
88
+ end
87
89
  end
data/spec/spec_helper.rb CHANGED
@@ -3,13 +3,16 @@ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
3
  # Configure Rails Environment
4
4
  ENV["RAILS_ENV"] = "test"
5
5
 
6
- require File.expand_path("../dummy/config/environment.rb", __FILE__)
6
+ require File.expand_path("../dummy/config/environment.rb", __FILE__)
7
7
  require "rspec/rails"
8
8
  require 'capybara/rspec'
9
9
  require 'capybara/rails'
10
- require 'pry'
11
10
 
12
- silence_warnings{ IRB = Pry }
11
+ begin
12
+ require 'pry'
13
+ silence_warnings{ IRB = Pry }
14
+ rescue LoadError
15
+ end
13
16
 
14
17
  ActionMailer::Base.delivery_method = :test
15
18
  ActionMailer::Base.perform_deliveries = true
@@ -4,7 +4,7 @@ module Apartment
4
4
  module Test
5
5
 
6
6
  def self.config
7
- @config ||= YAML.load_file('spec/config/database.yml')
7
+ @config ||= YAML.load(ERB.new(IO.read('spec/config/database.yml')).result)
8
8
  end
9
9
  end
10
10
  end
@@ -10,6 +10,8 @@ describe Apartment::Migrator do
10
10
  ActiveRecord::Base.establish_connection config
11
11
  Apartment::Database.stub(:config).and_return config # Use postgresql config for this test
12
12
  @original_schema = ActiveRecord::Base.connection.schema_search_path
13
+ # Necessary because the JDBC adapter returns $user in the search path
14
+ @original_schema.gsub!(/"\$user",/, '') if defined?(JRUBY_VERSION)
13
15
 
14
16
  Apartment.configure do |config|
15
17
  config.use_schemas = true
metadata CHANGED
@@ -1,51 +1,50 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: apartment
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.20.0
5
- prerelease:
4
+ prerelease:
5
+ version: 0.21.0
6
6
  platform: ruby
7
7
  authors:
8
8
  - Ryan Brunner
9
9
  - Brad Robertson
10
- autorequire:
10
+ autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2013-02-13 00:00:00.000000000 Z
13
+ date: 2013-04-25 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activerecord
17
- requirement: !ruby/object:Gem::Requirement
18
- none: false
17
+ version_requirements: !ruby/object:Gem::Requirement
19
18
  requirements:
20
- - - ! '>='
19
+ - - ">="
21
20
  - !ruby/object:Gem::Version
22
21
  version: 3.1.2
23
- type: :runtime
24
- prerelease: false
25
- version_requirements: !ruby/object:Gem::Requirement
26
22
  none: false
23
+ requirement: !ruby/object:Gem::Requirement
27
24
  requirements:
28
- - - ! '>='
25
+ - - ">="
29
26
  - !ruby/object:Gem::Version
30
27
  version: 3.1.2
28
+ none: false
29
+ prerelease: false
30
+ type: :runtime
31
31
  - !ruby/object:Gem::Dependency
32
32
  name: rack
33
- requirement: !ruby/object:Gem::Requirement
34
- none: false
33
+ version_requirements: !ruby/object:Gem::Requirement
35
34
  requirements:
36
- - - ! '>='
35
+ - - ">="
37
36
  - !ruby/object:Gem::Version
38
37
  version: 1.3.6
39
- type: :runtime
40
- prerelease: false
41
- version_requirements: !ruby/object:Gem::Requirement
42
38
  none: false
39
+ requirement: !ruby/object:Gem::Requirement
43
40
  requirements:
44
- - - ! '>='
41
+ - - ">="
45
42
  - !ruby/object:Gem::Version
46
43
  version: 1.3.6
47
- description: Apartment allows Rack applications to deal with database multitenancy
48
- through ActiveRecord
44
+ none: false
45
+ prerelease: false
46
+ type: :runtime
47
+ description: Apartment allows Rack applications to deal with database multitenancy through ActiveRecord
49
48
  email:
50
49
  - ryan@influitive.com
51
50
  - brad@influitive.com
@@ -53,19 +52,26 @@ executables: []
53
52
  extensions: []
54
53
  extra_rdoc_files: []
55
54
  files:
56
- - .gitignore
57
- - .pryrc
58
- - .rspec
59
- - .rvmrc
60
- - .travis.yml
55
+ - ".gitignore"
56
+ - ".pryrc"
57
+ - ".rspec"
58
+ - ".rvmrc"
59
+ - ".travis.yml"
60
+ - ".vagrant"
61
+ - Cheffile
62
+ - Cheffile.lock
61
63
  - Gemfile
62
64
  - HISTORY.md
63
65
  - README.md
64
66
  - Rakefile
67
+ - Vagrantfile
65
68
  - apartment.gemspec
66
69
  - circle.yml
67
70
  - lib/apartment.rb
68
71
  - lib/apartment/adapters/abstract_adapter.rb
72
+ - lib/apartment/adapters/abstract_jdbc_adapter.rb
73
+ - lib/apartment/adapters/jdbc_mysql_adapter.rb
74
+ - lib/apartment/adapters/jdbc_postgresql_adapter.rb
69
75
  - lib/apartment/adapters/mysql2_adapter.rb
70
76
  - lib/apartment/adapters/postgis_adapter.rb
71
77
  - lib/apartment/adapters/postgresql_adapter.rb
@@ -90,6 +96,8 @@ files:
90
96
  - lib/generators/apartment/install/install_generator.rb
91
97
  - lib/generators/apartment/install/templates/apartment.rb
92
98
  - lib/tasks/apartment.rake
99
+ - spec/adapters/jdbc_mysql_adapter_spec.rb
100
+ - spec/adapters/jdbc_postgresql_adapter_spec.rb
93
101
  - spec/adapters/mysql2_adapter_spec.rb
94
102
  - spec/adapters/postgresql_adapter_spec.rb
95
103
  - spec/apartment_spec.rb
@@ -155,35 +163,39 @@ files:
155
163
  homepage: https://github.com/influitive/apartment
156
164
  licenses:
157
165
  - MIT
158
- post_install_message:
166
+ post_install_message:
159
167
  rdoc_options: []
160
168
  require_paths:
161
169
  - lib
162
170
  required_ruby_version: !ruby/object:Gem::Requirement
163
- none: false
164
171
  requirements:
165
- - - ! '>='
172
+ - - ">="
166
173
  - !ruby/object:Gem::Version
167
- version: '0'
168
174
  segments:
169
175
  - 0
170
- hash: 1986473667684990578
171
- required_rubygems_version: !ruby/object:Gem::Requirement
176
+ hash: 2
177
+ version: !binary |-
178
+ MA==
172
179
  none: false
180
+ required_rubygems_version: !ruby/object:Gem::Requirement
173
181
  requirements:
174
- - - ! '>='
182
+ - - ">="
175
183
  - !ruby/object:Gem::Version
176
- version: '0'
177
184
  segments:
178
185
  - 0
179
- hash: 1986473667684990578
186
+ hash: 2
187
+ version: !binary |-
188
+ MA==
189
+ none: false
180
190
  requirements: []
181
- rubyforge_project:
191
+ rubyforge_project:
182
192
  rubygems_version: 1.8.24
183
- signing_key:
193
+ signing_key:
184
194
  specification_version: 3
185
195
  summary: A Ruby gem for managing database multitenancy
186
196
  test_files:
197
+ - spec/adapters/jdbc_mysql_adapter_spec.rb
198
+ - spec/adapters/jdbc_postgresql_adapter_spec.rb
187
199
  - spec/adapters/mysql2_adapter_spec.rb
188
200
  - spec/adapters/postgresql_adapter_spec.rb
189
201
  - spec/apartment_spec.rb