schema_qualified_tables 1.0.0 → 1.0.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/.gitignore +2 -1
- data/.rvmrc +1 -0
- data/CHANGELOG.markdown +21 -8
- data/Gemfile +36 -0
- data/README.markdown +85 -25
- data/Rakefile +15 -42
- data/ci-exec.sh +51 -0
- data/lib/bcdatabase/active_record/schema_qualified_tables/version.rb +7 -0
- data/lib/bcdatabase/active_record/schema_qualified_tables.rb +7 -1
- data/lib/schema_qualified_tables.rb +1 -0
- data/schema_qualified_tables.gemspec +31 -0
- data/spec/bcdatabase/active_record/schema_qualified_tables_spec.rb +23 -18
- data/spec/spec_helper.rb +44 -8
- metadata +123 -22
- data/VERSION.yml +0 -5
data/.gitignore
CHANGED
data/.rvmrc
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rvm use @sqtables --create
|
data/CHANGELOG.markdown
CHANGED
@@ -1,15 +1,28 @@
|
|
1
|
+
schema_qualified_tables history
|
2
|
+
===============================
|
3
|
+
|
4
|
+
1.0.1
|
5
|
+
-----
|
6
|
+
- ActiveRecord 3.1 support. (#1)
|
7
|
+
- Add top-level require -- you can now require
|
8
|
+
`'schema_qualified_tables'` instead of always having to use
|
9
|
+
`'bcdatabase/active_record/schema_qualified_tables'`. (#2)
|
10
|
+
|
1
11
|
1.0.0
|
2
|
-
|
12
|
+
-----
|
3
13
|
- Split out from NUBIC internal `bcdatabase` project.
|
4
14
|
(Changelog entries below reflect the relevant changes & version numbers from that project.)
|
5
15
|
|
16
|
+
Bcdatabase history
|
17
|
+
==================
|
18
|
+
|
6
19
|
0.6.2
|
7
|
-
|
20
|
+
-----
|
8
21
|
- Fix infinite recursion bug when schema-qualified tables are enabled on a
|
9
22
|
database which doesn't support sequences.
|
10
23
|
|
11
24
|
0.6.1
|
12
|
-
|
25
|
+
-----
|
13
26
|
- Schema-qualified names are dynamically determined, removing the order
|
14
27
|
dependency between setting ActiveRecord::Base.schemas and defining any
|
15
28
|
particular model. Side effect: schema-qualified names do not work with
|
@@ -17,21 +30,21 @@
|
|
17
30
|
circumstances).
|
18
31
|
|
19
32
|
0.6.0
|
20
|
-
|
33
|
+
-----
|
21
34
|
- Make the schema part of SchemaQualifiedTables inherited so that it can be
|
22
35
|
set just once in a base class for a whole hierarchy.
|
23
36
|
- Ensure that set_schema does not throw an exception when invoked before the
|
24
37
|
connection is established.
|
25
38
|
|
26
39
|
0.5.2
|
27
|
-
|
40
|
+
-----
|
28
41
|
- Works with CPKs
|
29
42
|
|
30
43
|
0.5.1
|
31
|
-
|
44
|
+
-----
|
32
45
|
- Support schema-qualified sequence names in SchemaQualifiedTables, too
|
33
46
|
|
34
47
|
0.5.0
|
35
|
-
|
36
|
-
- Extension Bcdatabase:Rails::SchemaQualifiedTables to add schema-qualified
|
48
|
+
-----
|
49
|
+
- Extension Bcdatabase:Rails::SchemaQualifiedTables to add schema-qualified
|
37
50
|
table name support to active record.
|
data/Gemfile
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
source :rubygems
|
2
|
+
|
3
|
+
gemspec
|
4
|
+
|
5
|
+
# for testing against different major releases of ActiveRecord
|
6
|
+
if ENV['ACTIVERECORD_VERSION']
|
7
|
+
version = case ENV['ACTIVERECORD_VERSION']
|
8
|
+
when /2.3-old$/ then '= 2.3.8'
|
9
|
+
when /2.3$/ then '~> 2.3.9'
|
10
|
+
when /3.0$/ then '~> 3.0.0'
|
11
|
+
when /3.1$/ then '~> 3.1.0'
|
12
|
+
else raise "Unsupported ActiveRecord version #{ENV['ACTIVERECORD_VERSION']}"
|
13
|
+
end
|
14
|
+
|
15
|
+
gem 'activerecord', version
|
16
|
+
end
|
17
|
+
|
18
|
+
group :postgresql do
|
19
|
+
platforms :ruby_18, :ruby_19 do
|
20
|
+
gem 'pg', '~> 0.11.0'
|
21
|
+
end
|
22
|
+
|
23
|
+
platforms :jruby do
|
24
|
+
gem 'activerecord-jdbcpostgresql-adapter'
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
if ENV['SQT_ORACLE']
|
29
|
+
group :oracle do
|
30
|
+
gem 'activerecord-oracle_enhanced-adapter'
|
31
|
+
|
32
|
+
platforms :ruby_18, :ruby_19 do
|
33
|
+
gem 'ruby-oci8'
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
data/README.markdown
CHANGED
@@ -1,12 +1,15 @@
|
|
1
1
|
SchemaQualifiedTables
|
2
2
|
=====================
|
3
3
|
|
4
|
-
`Bcdatabase::ActiveRecord::SchemaQualifiedTables` is a mix-in for
|
4
|
+
`Bcdatabase::ActiveRecord::SchemaQualifiedTables` is a mix-in for
|
5
|
+
[ActiveRecord][] 2.3.x and 3.0+. It makes it easier to use AR in an
|
6
|
+
application which contains models which map to tables in different
|
7
|
+
schemas.
|
5
8
|
|
6
9
|
[ActiveRecord]: http://api.rubyonrails.org/files/vendor/rails/activerecord/README.html
|
7
10
|
|
8
11
|
For example
|
9
|
-
|
12
|
+
-----------
|
10
13
|
|
11
14
|
Say you have an application using a legacy schema that has models like this:
|
12
15
|
|
@@ -19,26 +22,36 @@ Say you have an application using a legacy schema that has models like this:
|
|
19
22
|
set_table_name "hr.t_personnel"
|
20
23
|
end
|
21
24
|
|
22
|
-
These models map to tables in two schemas: the default schema, which
|
25
|
+
These models map to tables in two schemas: the default schema, which
|
26
|
+
contains `t_surgeries`; and the schema `hr`, which contains
|
27
|
+
`t_personnel`.
|
23
28
|
|
24
|
-
Contention
|
25
|
-
----------
|
29
|
+
### Contention
|
26
30
|
|
27
|
-
Being explicit about the schema name works for production, but what
|
31
|
+
Being explicit about the schema name works for production, but what
|
32
|
+
about development? You'll need separate database instances for
|
33
|
+
development deployment and for test. Depending on what database
|
34
|
+
you're using, this can be more or less fun (I'm looking at you,
|
35
|
+
Oracle).
|
28
36
|
|
29
|
-
Also consider continuous integration:
|
37
|
+
Also consider continuous integration: if you have several applications
|
38
|
+
in CI which all refer to the `hr` schema, their test data sets will
|
39
|
+
stomp all over each other if you try to run them in parallel.
|
30
40
|
|
31
|
-
Solution
|
32
|
-
--------
|
41
|
+
### Solution
|
33
42
|
|
34
|
-
`SchemaQualifiedTables` solves this problem by letting you configure a
|
43
|
+
`SchemaQualifiedTables` solves this problem by letting you configure a
|
44
|
+
logical schema name for your models which is resolved into the actual
|
45
|
+
schema name based on runtime configuration. In this case, you'd
|
46
|
+
re-write `Person` like so:
|
35
47
|
|
36
48
|
class Person < ActiveRecord::Base
|
37
49
|
set_schema :hr
|
38
50
|
set_table_name :t_personnel
|
39
51
|
end
|
40
52
|
|
41
|
-
Then, if you need to override the actual schema name in some
|
53
|
+
Then, if you need to override the actual schema name in some
|
54
|
+
environments, configure `ActiveRecord::Base.schemas`:
|
42
55
|
|
43
56
|
# in test.rb
|
44
57
|
config.after_initialize do
|
@@ -47,36 +60,83 @@ Then, if you need to override the actual schema name in some environments, confi
|
|
47
60
|
}
|
48
61
|
end
|
49
62
|
|
50
|
-
This way in the test environment, AR will map `Person` to
|
63
|
+
This way in the test environment, AR will map `Person` to
|
64
|
+
`hr_test.t_personnel`. In any environment where you don't provide an
|
65
|
+
explicit override, the logical schema name will be used as the actual
|
66
|
+
schema name — i.e., in development and production, AR will map
|
67
|
+
`Person` to `hr.t_personnel`.
|
51
68
|
|
52
|
-
|
53
|
-
|
69
|
+
Using
|
70
|
+
-----
|
54
71
|
|
55
72
|
Install the gem:
|
56
73
|
|
57
74
|
$ gem install schema_qualified_tables
|
58
75
|
|
59
|
-
If you're using
|
76
|
+
If you're using Rails 2.3, configure it in environment.rb:
|
60
77
|
|
61
|
-
config.gem 'schema_qualified_tables', :version => '>= 1.0.0'
|
62
|
-
:lib => 'bcdatabase/active_record/schema_qualified_tables',
|
63
|
-
:source => 'http://gemcutter.org'
|
78
|
+
config.gem 'schema_qualified_tables', :version => '>= 1.0.0'
|
64
79
|
|
65
|
-
|
80
|
+
If you're using Bundler (e.g., with Rails 3), add it to your Gemfile:
|
81
|
+
|
82
|
+
gem 'schema_qualified_tables', '~> 1.0.0'
|
83
|
+
|
84
|
+
Otherwise, just require 'schema_qualified_tables' sometime during
|
85
|
+
initialization (before your models are loaded).
|
66
86
|
|
67
87
|
Problems?
|
68
|
-
|
88
|
+
---------
|
89
|
+
|
90
|
+
Report bugs or request features on the project's [github issue
|
91
|
+
tracker][issues].
|
92
|
+
|
93
|
+
Send any other questions or feedback to Rhett Sutphin
|
94
|
+
(rhett@detailedbalance.net).
|
95
|
+
|
96
|
+
[issues]: http://github.com/rsutphin/schema_qualified_tables/issues
|
97
|
+
|
98
|
+
Development
|
99
|
+
-----------
|
69
100
|
|
70
|
-
|
101
|
+
This library uses bundler to provide an isolated gem environment for
|
102
|
+
its tests. Use `bundle update` before attempting to run the tests.
|
103
|
+
|
104
|
+
In order to test all the features of `schema_qualified_tables`,
|
105
|
+
ActiveRecord must be given a connection to a database on an RDBMS that
|
106
|
+
supports sequences. The test harness uses [Bcdatabase][] to acquire
|
107
|
+
the credentials for the test database. By default, it looks for the
|
108
|
+
Bcdatabase group `:local_postgresql` and the configuration
|
109
|
+
`:schema_qualified_tables_test`. You can override these by setting
|
110
|
+
environment variables when you run the tests, e.g.:
|
111
|
+
|
112
|
+
SQT_DB_GROUP=local_oracle
|
113
|
+
SQT_DB_ENTRY=sqt_tester
|
114
|
+
|
115
|
+
The test harness supports using PostgreSQL or Oracle. Adding support
|
116
|
+
for another database should be as easy as adding its adapter (or its
|
117
|
+
adapter's dependencies, if it has an adapter built into AR) to the
|
118
|
+
development dependencies in the gemspec and running `bundle
|
119
|
+
update`. The test suite can only be run without failures on a database
|
120
|
+
that supports sequences.
|
121
|
+
|
122
|
+
### On JRuby
|
123
|
+
|
124
|
+
If you want to run the tests on JRuby using a database whose JDBC
|
125
|
+
drivers are not available as a gem (i.e., Oracle), ensure that the
|
126
|
+
JDBC driver is on JRuby's classpath before running the tests. The
|
127
|
+
easiest way to do that is by setting the CLASSPATH environment
|
128
|
+
variable.
|
129
|
+
|
130
|
+
[Bcdatabase]: http://rubydoc.info/gems/bcdatabase/frames
|
71
131
|
|
72
132
|
Credits
|
73
|
-
|
133
|
+
-------
|
74
134
|
|
75
|
-
`SchemaQualifiedTables` was developed at the [Northwestern University
|
135
|
+
`SchemaQualifiedTables` was developed at the [Northwestern University
|
136
|
+
Biomedical Informatics Center][NUBIC].
|
76
137
|
|
77
138
|
[NUBIC]: http://www.nucats.northwestern.edu/centers/nubic/index.html
|
78
139
|
|
79
|
-
Copyright
|
80
|
-
---------
|
140
|
+
### Copyright
|
81
141
|
|
82
142
|
Copyright (c) 2009 Rhett Sutphin and Peter Nyberg. See LICENSE for details.
|
data/Rakefile
CHANGED
@@ -1,54 +1,27 @@
|
|
1
|
-
require '
|
1
|
+
require 'bundler/gem_tasks'
|
2
2
|
require 'rake'
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
Jeweler::Tasks.new do |gem|
|
7
|
-
gem.name = "schema_qualified_tables"
|
8
|
-
gem.summary = %Q{Logical schema names for ActiveRecord models}
|
9
|
-
gem.description = %Q{An ActiveRecord mix-in that makes it easier to use AR in an application which contains models which map to tables in different schemas.}
|
10
|
-
gem.email = "rhett@detailedbalance.net"
|
11
|
-
gem.homepage = "http://github.com/rsutphin/schema_qualified_tables"
|
12
|
-
gem.authors = ["Rhett Sutphin", "Peter Nyberg"]
|
13
|
-
gem.add_development_dependency "rspec", ">= 1.2"
|
14
|
-
gem.add_dependency 'activerecord', '>= 2.3'
|
4
|
+
require 'rspec/core/rake_task'
|
5
|
+
require 'ci/reporter/rake/rspec'
|
15
6
|
|
16
|
-
|
17
|
-
|
18
|
-
Jeweler::GemcutterTasks.new
|
19
|
-
rescue LoadError
|
20
|
-
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
21
|
-
end
|
22
|
-
|
23
|
-
require 'spec/rake/spectask'
|
24
|
-
Spec::Rake::SpecTask.new(:spec) do |spec|
|
25
|
-
spec.libs << 'lib' << 'spec'
|
26
|
-
spec.spec_files = FileList['spec/**/*_spec.rb']
|
7
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
8
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
27
9
|
end
|
28
10
|
|
29
|
-
|
30
|
-
spec.libs << 'lib' << 'spec'
|
11
|
+
RSpec::Core::RakeTask.new(:rcov) do |spec|
|
31
12
|
spec.pattern = 'spec/**/*_spec.rb'
|
32
|
-
|
33
|
-
|
34
|
-
spec.rcov_opts = ['--exclude', "spec/*,/Library/Ruby/*"]
|
13
|
+
# rcov can't tell that /Library/Ruby and RVM are system paths
|
14
|
+
spec.rcov_opts = ['--exclude', "spec/*,/Library/Ruby/*,#{ENV['HOME']}/.rvm/*"]
|
35
15
|
end
|
36
16
|
|
37
|
-
|
17
|
+
desc 'Full CI build'
|
18
|
+
task :ci => ['ci:spec']
|
38
19
|
|
39
|
-
|
20
|
+
namespace :ci do
|
21
|
+
ENV["CI_REPORTS"] = "reports/spec-xml"
|
40
22
|
|
41
|
-
|
42
|
-
|
43
|
-
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
44
|
-
|
45
|
-
rdoc.rdoc_dir = 'rdoc'
|
46
|
-
rdoc.title = "schema_qualified_tables #{version}"
|
47
|
-
rdoc.rdoc_files.include('README*')
|
48
|
-
rdoc.rdoc_files.include('lib/**/*.rb')
|
23
|
+
desc 'Run specs with coverage and ci_reporter'
|
24
|
+
task :spec => ['ci:setup:rspec', 'rake:rcov']
|
49
25
|
end
|
50
26
|
|
51
|
-
|
52
|
-
Rake::Task[:release].prerequisites.delete 'github:release'
|
53
|
-
|
54
|
-
task :build => [:gemspec]
|
27
|
+
task :default => :spec
|
data/ci-exec.sh
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
#!/bin/bash -xe
|
2
|
+
|
3
|
+
BUNDLER_VERSION=1.0.18
|
4
|
+
GEMSET="sqtables"
|
5
|
+
|
6
|
+
if [ -n "${ACTIVERECORD_VERSION}" ]; then
|
7
|
+
GEMSET="${GEMSET}-${ACTIVERECORD_VERSION}"
|
8
|
+
fi
|
9
|
+
|
10
|
+
if [ -n "${CPK}" ]; then
|
11
|
+
GEMSET="${GEMSET}-${CPK}"
|
12
|
+
fi
|
13
|
+
|
14
|
+
if [ -z "$CI_RUBY" ]; then
|
15
|
+
echo "CI_RUBY must be set"
|
16
|
+
exit 1
|
17
|
+
fi
|
18
|
+
|
19
|
+
set +xe
|
20
|
+
echo "Initializing RVM"
|
21
|
+
source ~/.rvm/scripts/rvm
|
22
|
+
set -xe
|
23
|
+
|
24
|
+
# On the overnight build, reinstall all gems
|
25
|
+
if [ `date +%H` -lt 5 ]; then
|
26
|
+
set +xe
|
27
|
+
echo "Purging gemset to verify that all deps can still be installed"
|
28
|
+
rvm --force $CI_RUBY gemset delete $GEMSET
|
29
|
+
set -xe
|
30
|
+
fi
|
31
|
+
|
32
|
+
RVM_CONFIG="${CI_RUBY}@${GEMSET}"
|
33
|
+
set +xe
|
34
|
+
echo "Switching to ${RVM_CONFIG}"
|
35
|
+
rvm use $RVM_CONFIG
|
36
|
+
set -xe
|
37
|
+
|
38
|
+
which ruby
|
39
|
+
ruby -v
|
40
|
+
|
41
|
+
set +e
|
42
|
+
gem list -i bundler -v $BUNDLER_VERSION
|
43
|
+
if [ $? -ne 0 ]; then
|
44
|
+
set -e
|
45
|
+
gem install bundler -v $BUNDLER_VERSION
|
46
|
+
fi
|
47
|
+
set -e
|
48
|
+
|
49
|
+
bundle update
|
50
|
+
|
51
|
+
bundle exec rake ci --trace
|
@@ -6,7 +6,13 @@ module Bcdatabase
|
|
6
6
|
def self.included(clz)
|
7
7
|
clz.instance_eval do
|
8
8
|
extend ClassMethods
|
9
|
-
|
9
|
+
if self.respond_to?(:class_attribute)
|
10
|
+
class_attribute :schema
|
11
|
+
elsif self.respond_to?(:class_inheritable_accessor)
|
12
|
+
class_inheritable_accessor :schema
|
13
|
+
else
|
14
|
+
fail "schema_qualified_tables is apparently not compatible with this version of ActiveRecord. Please report this as a bug."
|
15
|
+
end
|
10
16
|
|
11
17
|
class << self
|
12
18
|
alias_method_chain :set_table_name, :schema
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'bcdatabase/active_record/schema_qualified_tables'
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "bcdatabase/active_record/schema_qualified_tables/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = %q{schema_qualified_tables}
|
7
|
+
s.version = Bcdatabase::ActiveRecord::SchemaQualifiedTables::VERSION
|
8
|
+
|
9
|
+
s.authors = ["Rhett Sutphin", "Peter Nyberg"]
|
10
|
+
s.summary = %q{Logical schema names for ActiveRecord models}
|
11
|
+
s.description = %q{An ActiveRecord mix-in that makes it easier to use AR in an application which contains models which map to tables in different schemas.}
|
12
|
+
s.email = %q{rhett@detailedbalance.net}
|
13
|
+
s.files = `git ls-files`.split("\n")
|
14
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
15
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
16
|
+
s.require_paths = ["lib"]
|
17
|
+
|
18
|
+
s.homepage = %q{http://github.com/NUBIC/schema_qualified_tables}
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
|
21
|
+
s.add_dependency 'activerecord', '>= 2.3'
|
22
|
+
|
23
|
+
s.add_development_dependency 'rake', '~> 0.9.0'
|
24
|
+
s.add_development_dependency 'rspec', '~> 2.6'
|
25
|
+
s.add_development_dependency 'rcov'
|
26
|
+
# the library is tested against CPK, but does not require it
|
27
|
+
s.add_development_dependency 'composite_primary_keys'
|
28
|
+
s.add_development_dependency 'ci_reporter', '~> 1.6.5'
|
29
|
+
s.add_development_dependency 'bcdatabase', '~> 1.2'
|
30
|
+
end
|
31
|
+
|
@@ -2,14 +2,15 @@ require File.expand_path("../../spec_helper", File.dirname(__FILE__))
|
|
2
2
|
require 'active_record'
|
3
3
|
ActiveRecord.load_all! if ActiveRecord.respond_to?(:load_all!) # Lazy loading of active_record was added to rails 2.3.2
|
4
4
|
# so we have to explicitly load it this way for cpk to work.
|
5
|
-
require 'composite_primary_keys'
|
6
|
-
require 'bcdatabase/active_record/schema_qualified_tables'
|
5
|
+
require 'composite_primary_keys' if SqtCpk.test_cpk?
|
7
6
|
|
8
7
|
describe "SchemaQualifiedTables" do
|
9
|
-
before do
|
10
|
-
|
11
|
-
|
12
|
-
|
8
|
+
before(:all) do
|
9
|
+
establish_connection
|
10
|
+
end
|
11
|
+
|
12
|
+
after(:all) do
|
13
|
+
remove_connection
|
13
14
|
end
|
14
15
|
|
15
16
|
after do
|
@@ -204,12 +205,16 @@ describe "SchemaQualifiedTables" do
|
|
204
205
|
|
205
206
|
# TODO: bad, bad, bad copying
|
206
207
|
describe "sequences" do
|
208
|
+
def inferred(table_name='foo')
|
209
|
+
ActiveRecord::Base.connection.default_sequence_name(table_name)
|
210
|
+
end
|
211
|
+
|
207
212
|
describe "with no schema name" do
|
208
213
|
it "uses the inferred sequence name" do
|
209
214
|
class Book < ActiveRecord::Base
|
210
215
|
end
|
211
216
|
|
212
|
-
Book.sequence_name.should == '
|
217
|
+
Book.sequence_name.should == inferred('books')
|
213
218
|
end
|
214
219
|
|
215
220
|
it "uses just the explicit sequencename" do
|
@@ -221,9 +226,7 @@ describe "SchemaQualifiedTables" do
|
|
221
226
|
end
|
222
227
|
|
223
228
|
it "gives nil if the adapter doesn't specify a default sequence name" do
|
224
|
-
|
225
|
-
conn.stub!(:default_sequence_name).and_return(nil)
|
226
|
-
ActiveRecord::Base.connection_handler.stub!(:retrieve_connection).and_return(conn)
|
229
|
+
pending 'Adapter does have a default' if inferred
|
227
230
|
|
228
231
|
class Book < ActiveRecord::Base
|
229
232
|
end
|
@@ -238,13 +241,11 @@ describe "SchemaQualifiedTables" do
|
|
238
241
|
set_schema :reading_material
|
239
242
|
end
|
240
243
|
|
241
|
-
Magazine.sequence_name.should ==
|
244
|
+
Magazine.sequence_name.should == "reading_material.#{inferred 'magazines'}"
|
242
245
|
end
|
243
246
|
|
244
247
|
it "gives nil if the adapter doesn't specify a default sequence name" do
|
245
|
-
|
246
|
-
conn.stub!(:default_sequence_name).and_return(nil)
|
247
|
-
ActiveRecord::Base.connection_handler.stub!(:retrieve_connection).and_return(conn)
|
248
|
+
pending 'Adapter does have a default' if inferred
|
248
249
|
|
249
250
|
class Book < ActiveRecord::Base
|
250
251
|
set_schema :reading_material
|
@@ -254,6 +255,10 @@ describe "SchemaQualifiedTables" do
|
|
254
255
|
end
|
255
256
|
|
256
257
|
describe "with CPK" do
|
258
|
+
before do
|
259
|
+
pending 'Not testing CPK' unless test_cpk?
|
260
|
+
end
|
261
|
+
|
257
262
|
it "doesn't fail when setting the schema" do
|
258
263
|
class Newspaper < ActiveRecord::Base
|
259
264
|
set_primary_keys "address", "telephone"
|
@@ -317,7 +322,7 @@ describe "SchemaQualifiedTables" do
|
|
317
322
|
describe "with name overrides" do
|
318
323
|
before do
|
319
324
|
ActiveRecord::Base.schemas = {
|
320
|
-
:reading_material => '
|
325
|
+
:reading_material => 'rm_test'
|
321
326
|
}
|
322
327
|
end
|
323
328
|
|
@@ -330,7 +335,7 @@ describe "SchemaQualifiedTables" do
|
|
330
335
|
set_schema :reading_material
|
331
336
|
end
|
332
337
|
|
333
|
-
Pamphlet.sequence_name.should == '
|
338
|
+
Pamphlet.sequence_name.should == "rm_test.#{inferred 'pamphlets'}"
|
334
339
|
end
|
335
340
|
|
336
341
|
it "uses the explicit sequence name, if first" do
|
@@ -339,7 +344,7 @@ describe "SchemaQualifiedTables" do
|
|
339
344
|
set_schema :reading_material
|
340
345
|
end
|
341
346
|
|
342
|
-
Pamphlet.sequence_name.should == "
|
347
|
+
Pamphlet.sequence_name.should == "rm_test.some_pamphlets"
|
343
348
|
end
|
344
349
|
|
345
350
|
it "uses the explicit sequence name, if second" do
|
@@ -348,7 +353,7 @@ describe "SchemaQualifiedTables" do
|
|
348
353
|
set_sequence_name "some_pamphlets"
|
349
354
|
end
|
350
355
|
|
351
|
-
Pamphlet.sequence_name.should == "
|
356
|
+
Pamphlet.sequence_name.should == "rm_test.some_pamphlets"
|
352
357
|
end
|
353
358
|
end
|
354
359
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,9 +1,45 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
require '
|
6
|
-
|
7
|
-
|
8
|
-
|
1
|
+
require 'rspec'
|
2
|
+
require 'bcdatabase'
|
3
|
+
|
4
|
+
$LOAD_PATH.unshift(File.expand_path('../lib', __FILE__))
|
5
|
+
require 'schema_qualified_tables'
|
6
|
+
|
7
|
+
module SqtCpk
|
8
|
+
def test_cpk?
|
9
|
+
ENV['CPK'] =~ /y|t/ || ENV['CPK'].nil?
|
10
|
+
end
|
11
|
+
module_function :test_cpk?
|
12
|
+
end
|
13
|
+
|
14
|
+
module DatabaseHelper
|
15
|
+
def establish_connection
|
16
|
+
ActiveRecord::Base.establish_connection(db_params)
|
17
|
+
end
|
18
|
+
|
19
|
+
def remove_connection
|
20
|
+
ActiveRecord::Base.remove_connection
|
21
|
+
end
|
22
|
+
|
23
|
+
def db_params
|
24
|
+
bcdb[bcdb_group, bcdb_entry]
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def bcdb_group
|
30
|
+
ENV['SQT_DB_GROUP'] || :local_postgresql
|
31
|
+
end
|
32
|
+
|
33
|
+
def bcdb_entry
|
34
|
+
ENV['SQT_DB_ENTRY'] || :schema_qualified_tables_test
|
35
|
+
end
|
36
|
+
|
37
|
+
def bcdb
|
38
|
+
@bcdb ||= Bcdatabase.load
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
RSpec.configure do |config|
|
43
|
+
config.include SqtCpk
|
44
|
+
config.include DatabaseHelper
|
9
45
|
end
|
metadata
CHANGED
@@ -1,7 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: schema_qualified_tables
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
hash: 21
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 1
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 1.0.1
|
5
11
|
platform: ruby
|
6
12
|
authors:
|
7
13
|
- Rhett Sutphin
|
@@ -10,73 +16,168 @@ autorequire:
|
|
10
16
|
bindir: bin
|
11
17
|
cert_chain: []
|
12
18
|
|
13
|
-
date:
|
19
|
+
date: 2011-09-01 00:00:00 -05:00
|
14
20
|
default_executable:
|
15
21
|
dependencies:
|
22
|
+
- !ruby/object:Gem::Dependency
|
23
|
+
name: activerecord
|
24
|
+
prerelease: false
|
25
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
26
|
+
none: false
|
27
|
+
requirements:
|
28
|
+
- - ">="
|
29
|
+
- !ruby/object:Gem::Version
|
30
|
+
hash: 5
|
31
|
+
segments:
|
32
|
+
- 2
|
33
|
+
- 3
|
34
|
+
version: "2.3"
|
35
|
+
type: :runtime
|
36
|
+
version_requirements: *id001
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: rake
|
39
|
+
prerelease: false
|
40
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
hash: 59
|
46
|
+
segments:
|
47
|
+
- 0
|
48
|
+
- 9
|
49
|
+
- 0
|
50
|
+
version: 0.9.0
|
51
|
+
type: :development
|
52
|
+
version_requirements: *id002
|
16
53
|
- !ruby/object:Gem::Dependency
|
17
54
|
name: rspec
|
55
|
+
prerelease: false
|
56
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
hash: 15
|
62
|
+
segments:
|
63
|
+
- 2
|
64
|
+
- 6
|
65
|
+
version: "2.6"
|
18
66
|
type: :development
|
19
|
-
|
20
|
-
|
67
|
+
version_requirements: *id003
|
68
|
+
- !ruby/object:Gem::Dependency
|
69
|
+
name: rcov
|
70
|
+
prerelease: false
|
71
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
21
73
|
requirements:
|
22
74
|
- - ">="
|
23
75
|
- !ruby/object:Gem::Version
|
24
|
-
|
25
|
-
|
76
|
+
hash: 3
|
77
|
+
segments:
|
78
|
+
- 0
|
79
|
+
version: "0"
|
80
|
+
type: :development
|
81
|
+
version_requirements: *id004
|
26
82
|
- !ruby/object:Gem::Dependency
|
27
|
-
name:
|
28
|
-
|
29
|
-
|
30
|
-
|
83
|
+
name: composite_primary_keys
|
84
|
+
prerelease: false
|
85
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
86
|
+
none: false
|
31
87
|
requirements:
|
32
88
|
- - ">="
|
33
89
|
- !ruby/object:Gem::Version
|
34
|
-
|
35
|
-
|
90
|
+
hash: 3
|
91
|
+
segments:
|
92
|
+
- 0
|
93
|
+
version: "0"
|
94
|
+
type: :development
|
95
|
+
version_requirements: *id005
|
96
|
+
- !ruby/object:Gem::Dependency
|
97
|
+
name: ci_reporter
|
98
|
+
prerelease: false
|
99
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
100
|
+
none: false
|
101
|
+
requirements:
|
102
|
+
- - ~>
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
hash: 5
|
105
|
+
segments:
|
106
|
+
- 1
|
107
|
+
- 6
|
108
|
+
- 5
|
109
|
+
version: 1.6.5
|
110
|
+
type: :development
|
111
|
+
version_requirements: *id006
|
112
|
+
- !ruby/object:Gem::Dependency
|
113
|
+
name: bcdatabase
|
114
|
+
prerelease: false
|
115
|
+
requirement: &id007 !ruby/object:Gem::Requirement
|
116
|
+
none: false
|
117
|
+
requirements:
|
118
|
+
- - ~>
|
119
|
+
- !ruby/object:Gem::Version
|
120
|
+
hash: 11
|
121
|
+
segments:
|
122
|
+
- 1
|
123
|
+
- 2
|
124
|
+
version: "1.2"
|
125
|
+
type: :development
|
126
|
+
version_requirements: *id007
|
36
127
|
description: An ActiveRecord mix-in that makes it easier to use AR in an application which contains models which map to tables in different schemas.
|
37
128
|
email: rhett@detailedbalance.net
|
38
129
|
executables: []
|
39
130
|
|
40
131
|
extensions: []
|
41
132
|
|
42
|
-
extra_rdoc_files:
|
43
|
-
|
44
|
-
- README.markdown
|
133
|
+
extra_rdoc_files: []
|
134
|
+
|
45
135
|
files:
|
46
136
|
- .gitignore
|
137
|
+
- .rvmrc
|
47
138
|
- CHANGELOG.markdown
|
139
|
+
- Gemfile
|
48
140
|
- LICENSE
|
49
141
|
- README.markdown
|
50
142
|
- Rakefile
|
51
|
-
-
|
143
|
+
- ci-exec.sh
|
52
144
|
- lib/bcdatabase/active_record/schema_qualified_tables.rb
|
145
|
+
- lib/bcdatabase/active_record/schema_qualified_tables/version.rb
|
146
|
+
- lib/schema_qualified_tables.rb
|
147
|
+
- schema_qualified_tables.gemspec
|
53
148
|
- spec/bcdatabase/active_record/schema_qualified_tables_spec.rb
|
54
149
|
- spec/spec_helper.rb
|
55
150
|
has_rdoc: true
|
56
|
-
homepage: http://github.com/
|
151
|
+
homepage: http://github.com/NUBIC/schema_qualified_tables
|
57
152
|
licenses: []
|
58
153
|
|
59
154
|
post_install_message:
|
60
|
-
rdoc_options:
|
61
|
-
|
155
|
+
rdoc_options: []
|
156
|
+
|
62
157
|
require_paths:
|
63
158
|
- lib
|
64
159
|
required_ruby_version: !ruby/object:Gem::Requirement
|
160
|
+
none: false
|
65
161
|
requirements:
|
66
162
|
- - ">="
|
67
163
|
- !ruby/object:Gem::Version
|
164
|
+
hash: 3
|
165
|
+
segments:
|
166
|
+
- 0
|
68
167
|
version: "0"
|
69
|
-
version:
|
70
168
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
169
|
+
none: false
|
71
170
|
requirements:
|
72
171
|
- - ">="
|
73
172
|
- !ruby/object:Gem::Version
|
173
|
+
hash: 3
|
174
|
+
segments:
|
175
|
+
- 0
|
74
176
|
version: "0"
|
75
|
-
version:
|
76
177
|
requirements: []
|
77
178
|
|
78
179
|
rubyforge_project:
|
79
|
-
rubygems_version: 1.3.
|
180
|
+
rubygems_version: 1.3.7
|
80
181
|
signing_key:
|
81
182
|
specification_version: 3
|
82
183
|
summary: Logical schema names for ActiveRecord models
|