merb_activerecord 0.9.2 → 0.9.3
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/Rakefile +2 -2
- data/lib/active_record/merbtasks.rb +3 -3
- data/lib/merb/orms/active_record/connection.rb +13 -12
- data/specs/merb_active_record_spec.rb +64 -4
- data/specs/spec_helper.rb +4 -1
- metadata +3 -3
data/Rakefile
CHANGED
@@ -3,7 +3,7 @@ require 'rake/gempackagetask'
|
|
3
3
|
|
4
4
|
PLUGIN = "merb_activerecord"
|
5
5
|
NAME = "merb_activerecord"
|
6
|
-
VERSION = "0.9.
|
6
|
+
VERSION = "0.9.3"
|
7
7
|
AUTHOR = "Duane Johnson"
|
8
8
|
EMAIL = "canadaduane@gmail.com"
|
9
9
|
HOMEPAGE = "http://merbivore.com"
|
@@ -20,7 +20,7 @@ spec = Gem::Specification.new do |s|
|
|
20
20
|
s.author = AUTHOR
|
21
21
|
s.email = EMAIL
|
22
22
|
s.homepage = HOMEPAGE
|
23
|
-
s.add_dependency("merb-core", ">= 0.9.
|
23
|
+
s.add_dependency("merb-core", ">= 0.9.3")
|
24
24
|
s.require_path = "lib"
|
25
25
|
s.autorequire = PLUGIN
|
26
26
|
s.files = %w(LICENSE README Rakefile TODO) + Dir.glob("{lib,specs,activerecord_generators}/**/*")
|
@@ -284,8 +284,8 @@ namespace :db do
|
|
284
284
|
ActiveRecord::Base.connection.recreate_database(config[:database])
|
285
285
|
when "postgresql"
|
286
286
|
ENV['PGHOST'] = config[:host] if config[:host]
|
287
|
-
ENV['PGPORT'] =
|
288
|
-
ENV['PGPASSWORD'] =
|
287
|
+
ENV['PGPORT'] = config[:port].to_s if config[:port]
|
288
|
+
ENV['PGPASSWORD'] = config[:password].to_s if config[:password]
|
289
289
|
enc_option = "-E #{config[:encoding]}" if config[:encoding]
|
290
290
|
ActiveRecord::Base.clear_active_connections!
|
291
291
|
`dropdb -U "#{config[:username]}" #{config[:database]}`
|
@@ -307,7 +307,7 @@ namespace :db do
|
|
307
307
|
end
|
308
308
|
|
309
309
|
desc "Prepare the test database and load the schema"
|
310
|
-
task :prepare
|
310
|
+
task :prepare do
|
311
311
|
if defined?(ActiveRecord::Base) && !Merb::Orms::ActiveRecord.configurations.blank?
|
312
312
|
Rake::Task[{ :sql => "db:test:clone_structure", :ruby => "db:test:clone" }[ActiveRecord::Base.schema_format]].invoke
|
313
313
|
end
|
@@ -4,7 +4,7 @@ require 'active_record'
|
|
4
4
|
module Merb
|
5
5
|
module Orms
|
6
6
|
module ActiveRecord
|
7
|
-
|
7
|
+
|
8
8
|
# Start a transaction.
|
9
9
|
#
|
10
10
|
# Used by Merb::Rack::Console#open_sandbox!
|
@@ -12,30 +12,30 @@ module Merb
|
|
12
12
|
::ActiveRecord::Base.send :increment_open_transactions
|
13
13
|
::ActiveRecord::Base.connection.begin_db_transaction
|
14
14
|
end
|
15
|
-
|
15
|
+
|
16
16
|
# Rollback a transaction.
|
17
17
|
#
|
18
|
-
# Used by Merb::Rack::Console#
|
18
|
+
# Used by Merb::Rack::Console#close_sandbox!
|
19
19
|
def self.close_sandbox!
|
20
20
|
::ActiveRecord::Base.connection.rollback_db_transaction
|
21
21
|
::ActiveRecord::Base.send :decrement_open_transactions
|
22
|
-
end
|
23
|
-
|
22
|
+
end
|
23
|
+
|
24
24
|
class << self
|
25
25
|
def config_file() Merb.dir_for(:config) / "database.yml" end
|
26
26
|
def sample_dest() Merb.dir_for(:config) / "database.yml.sample" end
|
27
27
|
def sample_source() File.dirname(__FILE__) / "database.yml.sample" end
|
28
|
-
|
28
|
+
|
29
29
|
def copy_sample_config
|
30
30
|
FileUtils.cp sample_source, sample_dest unless File.exists?(sample_dest)
|
31
31
|
end
|
32
|
-
|
32
|
+
|
33
33
|
def config
|
34
34
|
@config ||= (Merb::Plugins.config[:merb_active_record] = configurations[Merb.environment.to_sym])
|
35
35
|
end
|
36
36
|
|
37
37
|
def configurations
|
38
|
-
@configurations ||=
|
38
|
+
@configurations ||=
|
39
39
|
begin
|
40
40
|
#A proc that will recursively intern(a.k.a symbolize) the keys of the hash
|
41
41
|
intern_keys = lambda { |x|
|
@@ -43,8 +43,8 @@ module Merb
|
|
43
43
|
y[k.to_sym || k] = v.is_a?(Hash) ? intern_keys.call(v) : v
|
44
44
|
y
|
45
45
|
end
|
46
|
-
}
|
47
|
-
intern_keys.call(Erubis.load_yaml_file(config_file))
|
46
|
+
}
|
47
|
+
intern_keys.call(Erubis.load_yaml_file(config_file))
|
48
48
|
end
|
49
49
|
end
|
50
50
|
|
@@ -57,6 +57,7 @@ module Merb
|
|
57
57
|
|
58
58
|
::ActiveRecord::Base.verification_timeout = 14400
|
59
59
|
::ActiveRecord::Base.logger = Merb.logger
|
60
|
+
::ActiveRecord::Base.configurations = configurations
|
60
61
|
::ActiveRecord::Base.establish_connection config
|
61
62
|
else
|
62
63
|
copy_sample_config
|
@@ -65,7 +66,7 @@ module Merb
|
|
65
66
|
exit(1)
|
66
67
|
end
|
67
68
|
end
|
68
|
-
|
69
|
+
|
69
70
|
# Registering this ORM lets the user choose active_record as a session
|
70
71
|
# in merb.yml's session_store: option.
|
71
72
|
def register_session_type
|
@@ -76,4 +77,4 @@ module Merb
|
|
76
77
|
end
|
77
78
|
end
|
78
79
|
end
|
79
|
-
end
|
80
|
+
end
|
@@ -1,7 +1,67 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/spec_helper'
|
2
2
|
|
3
|
-
describe
|
4
|
-
it "
|
5
|
-
|
3
|
+
describe Merb::Orms::ActiveRecord::Connect do
|
4
|
+
it "is loaded at plugin bootstrap" do
|
5
|
+
defined?(Merb::Orms::ActiveRecord::Connect).should == "constant"
|
6
6
|
end
|
7
|
-
|
7
|
+
|
8
|
+
it "is a merb bootloader" do
|
9
|
+
Merb::Orms::ActiveRecord::Connect.superclass.should == Merb::BootLoader
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
|
14
|
+
|
15
|
+
describe "Merb ActiveRecord extension" do
|
16
|
+
before :all do
|
17
|
+
@wd = Dir.pwd
|
18
|
+
Merb.stub!(:dir_for).with(:config).and_return(@wd)
|
19
|
+
@config_file_path = @wd / "database.yml"
|
20
|
+
@sample_file_path = @wd / "database.yml.sample"
|
21
|
+
|
22
|
+
@sample_source = Merb::Orms::ActiveRecord.sample_source
|
23
|
+
@config_sample = Erubis.load_yaml_file(@sample_source)
|
24
|
+
end
|
25
|
+
|
26
|
+
it "is loaded at plugin booststrap" do
|
27
|
+
defined?(Merb::Orms::ActiveRecord).should == "constant"
|
28
|
+
end
|
29
|
+
|
30
|
+
it "loads config from Merb configurations directory" do
|
31
|
+
Merb::Orms::ActiveRecord.config_file.should == @config_file_path
|
32
|
+
end
|
33
|
+
|
34
|
+
it "loads config sample from Merb configurations directory" do
|
35
|
+
Merb::Orms::ActiveRecord.sample_dest.should == @sample_file_path
|
36
|
+
end
|
37
|
+
|
38
|
+
it "provides a sample database.yml with development environment" do
|
39
|
+
@config_sample[:development].should be_an_instance_of(Hash)
|
40
|
+
end
|
41
|
+
|
42
|
+
it "provides a sample database.yml with test environment" do
|
43
|
+
@config_sample[:test].should be_an_instance_of(Hash)
|
44
|
+
end
|
45
|
+
|
46
|
+
it "provides a sample database.yml with production environment" do
|
47
|
+
@config_sample[:production].should be_an_instance_of(Hash)
|
48
|
+
end
|
49
|
+
|
50
|
+
it "uses Unicode and localhost in sample" do
|
51
|
+
@config_sample[:development][:host].should == "localhost"
|
52
|
+
@config_sample[:development][:encoding].should == "utf8"
|
53
|
+
end
|
54
|
+
|
55
|
+
it "stores configurations from config file" do
|
56
|
+
Erubis.should_receive(:load_yaml_file).with(@config_file_path).and_return(@config_sample)
|
57
|
+
Merb::Orms::ActiveRecord.configurations[:development][:database].should == "sample_development"
|
58
|
+
end
|
59
|
+
|
60
|
+
it "provides Rack with a way to start a transcantion" do
|
61
|
+
Merb::Orms::ActiveRecord.should respond_to(:open_sandbox!)
|
62
|
+
end
|
63
|
+
|
64
|
+
it "provides Rack with a way to stop a transcantion" do
|
65
|
+
Merb::Orms::ActiveRecord.should respond_to(:close_sandbox!)
|
66
|
+
end
|
67
|
+
end
|
data/specs/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: merb_activerecord
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Duane Johnson
|
@@ -9,7 +9,7 @@ autorequire: merb_activerecord
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-
|
12
|
+
date: 2008-05-04 00:00:00 -05:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -19,7 +19,7 @@ dependencies:
|
|
19
19
|
requirements:
|
20
20
|
- - ">="
|
21
21
|
- !ruby/object:Gem::Version
|
22
|
-
version: 0.9.
|
22
|
+
version: 0.9.3
|
23
23
|
version:
|
24
24
|
description: Merb plugin that provides ActiveRecord support for Merb
|
25
25
|
email: canadaduane@gmail.com
|