apartment 0.10.0 → 0.10.1
Sign up to get free protection for your applications and to get access to all the features.
- data/HISTORY.md +6 -1
- data/lib/apartment/database.rb +13 -13
- data/lib/apartment/delayed_job/hooks.rb +1 -0
- data/lib/apartment/delayed_job/requirements.rb +3 -2
- data/lib/apartment/version.rb +1 -1
- data/spec/dummy/db/migrate/20110613152810_create_dummy_models.rb +11 -10
- data/spec/integration/delayed_job_integration_spec.rb +6 -1
- data/spec/integration/middleware/subdomain_elevator_spec.rb +2 -2
- data/spec/spec_helper.rb +0 -1
- data/spec/support/apartment_helpers.rb +13 -8
- metadata +3 -4
- data/spec/support/migrate.rb +0 -9
data/HISTORY.md
CHANGED
@@ -1,5 +1,10 @@
|
|
1
|
+
# 0.10.1
|
2
|
+
* Aug 11, 2011
|
3
|
+
|
4
|
+
- Fixed bug in DJ where new objects (that hadn't been pulled from the db) didn't have the proper database assigned
|
5
|
+
|
1
6
|
# 0.10.0
|
2
|
-
* July 29,
|
7
|
+
* July 29, 2011
|
3
8
|
|
4
9
|
- Added better support for Delayed Job
|
5
10
|
- New config option that enables Delayed Job wrappers
|
data/lib/apartment/database.rb
CHANGED
@@ -37,19 +37,19 @@ module Apartment
|
|
37
37
|
@config = nil
|
38
38
|
end
|
39
39
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
40
|
+
private
|
41
|
+
|
42
|
+
def connect_exclusions
|
43
|
+
# Establish a connection for each specific excluded model
|
44
|
+
# Thus all other models will shared a connection (at ActiveRecord::Base) and we can modify at will
|
45
|
+
Apartment.excluded_models.each do |excluded_model|
|
46
|
+
excluded_model.establish_connection config
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def config
|
51
|
+
@config ||= Rails.configuration.database_configuration[Rails.env].symbolize_keys
|
52
|
+
end
|
53
53
|
end
|
54
54
|
|
55
55
|
end
|
@@ -6,6 +6,7 @@ module Apartment
|
|
6
6
|
|
7
7
|
# Before and after hooks for performing Delayed Jobs within a particular apartment database
|
8
8
|
# Include these in your delayed jobs models and make sure provide a @database attr that will be serialized by DJ
|
9
|
+
# Note also that any models that are being serialized need the Apartment::Delayed::Requirements module mixed in to it
|
9
10
|
module Hooks
|
10
11
|
|
11
12
|
attr_accessor :database
|
@@ -3,12 +3,13 @@ require 'apartment/delayed_job/enqueue'
|
|
3
3
|
module Apartment
|
4
4
|
module Delayed
|
5
5
|
|
6
|
-
# Mix this module into any model that gets serialized by DJ
|
6
|
+
# Mix this module into any ActiveRecord model that gets serialized by DJ
|
7
7
|
module Requirements
|
8
8
|
attr_accessor :database
|
9
9
|
|
10
10
|
def self.included(klass)
|
11
|
-
klass.after_find :set_database
|
11
|
+
klass.after_find :set_database # set db when records are pulled so they deserialize properly
|
12
|
+
klass.before_save :set_database # set db before records are saved so that they also get deserialized properly
|
12
13
|
end
|
13
14
|
|
14
15
|
private
|
data/lib/apartment/version.rb
CHANGED
@@ -12,16 +12,16 @@ class CreateDummyModels < ActiveRecord::Migration
|
|
12
12
|
end
|
13
13
|
|
14
14
|
create_table :delayed_jobs do |t|
|
15
|
-
t.integer
|
16
|
-
t.integer
|
17
|
-
t.text
|
18
|
-
t.text
|
19
|
-
t.datetime
|
20
|
-
t.datetime
|
21
|
-
t.datetime
|
22
|
-
t.string
|
23
|
-
t.datetime
|
24
|
-
t.datetime
|
15
|
+
t.integer :priority, :default => 0
|
16
|
+
t.integer :attempts, :default => 0
|
17
|
+
t.text :handler
|
18
|
+
t.text :last_error
|
19
|
+
t.datetime :run_at
|
20
|
+
t.datetime :locked_at
|
21
|
+
t.datetime :failed_at
|
22
|
+
t.string :locked_by
|
23
|
+
t.datetime :created_at
|
24
|
+
t.datetime :updated_at
|
25
25
|
end
|
26
26
|
|
27
27
|
add_index "delayed_jobs", ["priority", "run_at"], :name => "delayed_jobs_priority"
|
@@ -31,5 +31,6 @@ class CreateDummyModels < ActiveRecord::Migration
|
|
31
31
|
def self.down
|
32
32
|
drop_table :companies
|
33
33
|
drop_table :users
|
34
|
+
drop_table :delayed_jobs
|
34
35
|
end
|
35
36
|
end
|
@@ -68,7 +68,7 @@ describe Apartment::Delayed do
|
|
68
68
|
user.database.should == database
|
69
69
|
end
|
70
70
|
|
71
|
-
it "should not overwrite any previous after_initialize declarations" do
|
71
|
+
it "should not overwrite any previous after_initialize declarations" do
|
72
72
|
User.class_eval do
|
73
73
|
after_find :set_name
|
74
74
|
|
@@ -82,6 +82,11 @@ describe Apartment::Delayed do
|
|
82
82
|
user.name.should == "Some Name"
|
83
83
|
end
|
84
84
|
|
85
|
+
it "should set the db on a new record before it saves" do
|
86
|
+
user = User.create
|
87
|
+
user.database.should == database
|
88
|
+
end
|
89
|
+
|
85
90
|
context "serialization" do
|
86
91
|
it "should serialize the proper database attribute" do
|
87
92
|
user_yaml = User.first.to_yaml
|
@@ -32,11 +32,11 @@ describe Apartment::Elevators::Subdomain do
|
|
32
32
|
before do
|
33
33
|
Apartment::Database.create(company2.subdomain)
|
34
34
|
# Create some users for each db
|
35
|
-
Apartment::
|
35
|
+
Apartment::Database.process(company.subdomain) do
|
36
36
|
@c1_user_count = (2 + rand(2)).times{ User.create }
|
37
37
|
end
|
38
38
|
|
39
|
-
Apartment::
|
39
|
+
Apartment::Database.process(company2.subdomain) do
|
40
40
|
@c2_user_count = (@c1_user_count + 2).times{ User.create }
|
41
41
|
end
|
42
42
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,27 +1,32 @@
|
|
1
1
|
module Apartment
|
2
2
|
module Test
|
3
|
-
|
3
|
+
|
4
|
+
extend self
|
5
|
+
|
6
|
+
def reset
|
4
7
|
Apartment::Database.instance_variable_set :@initialized, nil
|
5
8
|
Apartment.excluded_models = nil
|
6
9
|
Apartment.use_postgres_schemas = nil
|
7
10
|
end
|
8
11
|
|
9
|
-
def
|
12
|
+
def drop_schema(schema)
|
10
13
|
ActiveRecord::Base.silence{ ActiveRecord::Base.connection.execute("DROP SCHEMA IF EXISTS #{schema} CASCADE") }
|
11
14
|
end
|
12
15
|
|
13
|
-
def
|
16
|
+
def create_schema(schema)
|
14
17
|
ActiveRecord::Base.connection.execute("CREATE SCHEMA #{schema}")
|
15
18
|
end
|
16
19
|
|
17
|
-
def
|
20
|
+
def load_schema
|
18
21
|
load "#{Rails.root}/db/schema.rb"
|
19
22
|
end
|
20
23
|
|
21
|
-
def
|
22
|
-
|
23
|
-
|
24
|
-
|
24
|
+
def migrate
|
25
|
+
ActiveRecord::Migrator.migrate(Rails.root + ActiveRecord::Migrator.migrations_path)
|
26
|
+
end
|
27
|
+
|
28
|
+
def rollback
|
29
|
+
ActiveRecord::Migrator.rollback(Rails.root + ActiveRecord::Migrator.migrations_path)
|
25
30
|
end
|
26
31
|
|
27
32
|
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: apartment
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.10.
|
5
|
+
version: 0.10.1
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Ryan Brunner
|
@@ -183,7 +183,6 @@ files:
|
|
183
183
|
- spec/support/apartment_helpers.rb
|
184
184
|
- spec/support/capybara_sessions.rb
|
185
185
|
- spec/support/config.rb
|
186
|
-
- spec/support/migrate.rb
|
187
186
|
- spec/tasks/apartment_rake_spec.rb
|
188
187
|
- spec/unit/config_spec.rb
|
189
188
|
- spec/unit/middleware/subdomain_elevator_spec.rb
|
@@ -202,7 +201,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
202
201
|
requirements:
|
203
202
|
- - ">="
|
204
203
|
- !ruby/object:Gem::Version
|
205
|
-
hash:
|
204
|
+
hash: 2437262217849019999
|
206
205
|
segments:
|
207
206
|
- 0
|
208
207
|
version: "0"
|
@@ -211,7 +210,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
211
210
|
requirements:
|
212
211
|
- - ">="
|
213
212
|
- !ruby/object:Gem::Version
|
214
|
-
hash:
|
213
|
+
hash: 2437262217849019999
|
215
214
|
segments:
|
216
215
|
- 0
|
217
216
|
version: "0"
|