apartment 0.10.0 → 0.10.1

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.
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, 2001
7
+ * July 29, 2011
3
8
 
4
9
  - Added better support for Delayed Job
5
10
  - New config option that enables Delayed Job wrappers
@@ -37,19 +37,19 @@ module Apartment
37
37
  @config = nil
38
38
  end
39
39
 
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
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
@@ -1,3 +1,3 @@
1
1
  module Apartment
2
- VERSION = "0.10.0"
2
+ VERSION = "0.10.1"
3
3
  end
@@ -12,16 +12,16 @@ class CreateDummyModels < ActiveRecord::Migration
12
12
  end
13
13
 
14
14
  create_table :delayed_jobs do |t|
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"
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::Test.in_database(company.subdomain) do
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::Test.in_database(company2.subdomain) do
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
@@ -8,7 +8,6 @@ require "rspec/rails"
8
8
  require 'capybara/rspec'
9
9
  require 'capybara/rails'
10
10
 
11
-
12
11
  ActionMailer::Base.delivery_method = :test
13
12
  ActionMailer::Base.perform_deliveries = true
14
13
  ActionMailer::Base.default_url_options[:host] = "test.com"
@@ -1,27 +1,32 @@
1
1
  module Apartment
2
2
  module Test
3
- def self.reset
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 self.drop_schema(schema)
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 self.create_schema(schema)
16
+ def create_schema(schema)
14
17
  ActiveRecord::Base.connection.execute("CREATE SCHEMA #{schema}")
15
18
  end
16
19
 
17
- def self.load_schema
20
+ def load_schema
18
21
  load "#{Rails.root}/db/schema.rb"
19
22
  end
20
23
 
21
- def self.in_database(db)
22
- Apartment::Database.switch db
23
- yield if block_given?
24
- Apartment::Database.reset
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.0
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: -3391988953711779455
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: -3391988953711779455
213
+ hash: 2437262217849019999
215
214
  segments:
216
215
  - 0
217
216
  version: "0"
@@ -1,9 +0,0 @@
1
- module Apartment
2
-
3
- module Test
4
-
5
- def self.migrate
6
- ActiveRecord::Migrator.migrate Rails.root + ActiveRecord::Migrator.migrations_path
7
- end
8
- end
9
- end