schema_qualified_tables 1.0.1 → 1.1.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,6 +1,13 @@
1
1
  schema_qualified_tables history
2
2
  ===============================
3
3
 
4
+ 1.1.0
5
+ -----
6
+
7
+ - ActiveRecord 3.2 support. (#3)
8
+ Previous versions worked with AR 3.2 but this version eliminates the
9
+ deprecation warnings arising from the use of `set_table_name`, etc.
10
+
4
11
  1.0.1
5
12
  -----
6
13
  - ActiveRecord 3.1 support. (#1)
data/Gemfile CHANGED
@@ -7,8 +7,9 @@ if ENV['ACTIVERECORD_VERSION']
7
7
  version = case ENV['ACTIVERECORD_VERSION']
8
8
  when /2.3-old$/ then '= 2.3.8'
9
9
  when /2.3$/ then '~> 2.3.9'
10
- when /3.0$/ then '~> 3.0.0'
10
+ when /3.0$/ then '~> 3.0.10'
11
11
  when /3.1$/ then '~> 3.1.0'
12
+ when /3.2$/ then '~> 3.2.0'
12
13
  else raise "Unsupported ActiveRecord version #{ENV['ACTIVERECORD_VERSION']}"
13
14
  end
14
15
 
@@ -50,14 +50,28 @@ re-write `Person` like so:
50
50
  set_table_name :t_personnel
51
51
  end
52
52
 
53
+ # For Rails 3.2+ this syntax is also supported
54
+ class Person < ActiveRecord::Base
55
+ self.schema = :hr
56
+ self.table_name = :t_personnel
57
+ end
58
+
53
59
  Then, if you need to override the actual schema name in some
54
60
  environments, configure `ActiveRecord::Base.schemas`:
55
61
 
56
62
  # in test.rb
63
+
64
+ # For Rails 2.3
57
65
  config.after_initialize do
58
- ActiveRecord::Base.schemas = {
59
- :hr => 'hr_test',
60
- }
66
+ ActiveRecord::Base.schemas = { :hr => 'hr_test' }
67
+ end
68
+
69
+ # For Rails 3.x
70
+ MyApp::Application.configure do
71
+ ...
72
+ # _not_ within an after_initialize block
73
+ ActiveRecord::Base.schemas = { :hr => 'hr_test' }
74
+ ...
61
75
  end
62
76
 
63
77
  This way in the test environment, AR will map `Person` to
@@ -114,10 +128,14 @@ environment variables when you run the tests, e.g.:
114
128
 
115
129
  The test harness supports using PostgreSQL or Oracle. Adding support
116
130
  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.
131
+ adapter's dependencies, if it has an adapter built into AR) to a group
132
+ the Gemfile and running `bundle update`. The test suite can only be
133
+ run without failures on a database that supports sequences.
134
+
135
+ (N.b.: since it's relatively difficult to install the supporting
136
+ library for Oracle, it isn't included in the Gemfile by default. If
137
+ you want to test against Oracle, set `SQT_ORACLE=true` in your
138
+ environment before running `bundle update` and the tests.)
121
139
 
122
140
  ### On JRuby
123
141
 
data/Rakefile CHANGED
@@ -8,20 +8,14 @@ RSpec::Core::RakeTask.new(:spec) do |spec|
8
8
  spec.pattern = 'spec/**/*_spec.rb'
9
9
  end
10
10
 
11
- RSpec::Core::RakeTask.new(:rcov) do |spec|
12
- spec.pattern = 'spec/**/*_spec.rb'
13
- # rcov can't tell that /Library/Ruby and RVM are system paths
14
- spec.rcov_opts = ['--exclude', "spec/*,/Library/Ruby/*,#{ENV['HOME']}/.rvm/*"]
15
- end
16
-
17
11
  desc 'Full CI build'
18
12
  task :ci => ['ci:spec']
19
13
 
20
14
  namespace :ci do
21
15
  ENV["CI_REPORTS"] = "reports/spec-xml"
22
16
 
23
- desc 'Run specs with coverage and ci_reporter'
24
- task :spec => ['ci:setup:rspec', 'rake:rcov']
17
+ desc 'Run specs with ci_reporter'
18
+ task :spec => ['ci:setup:rspec', 'rake:spec']
25
19
  end
26
20
 
27
21
  task :default => :spec
@@ -1,86 +1,6 @@
1
- require 'active_record'
2
-
3
- module Bcdatabase
4
- module ActiveRecord
5
- module SchemaQualifiedTables
6
- def self.included(clz)
7
- clz.instance_eval do
8
- extend ClassMethods
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
16
-
17
- class << self
18
- alias_method_chain :set_table_name, :schema
19
- alias_method_chain :set_sequence_name, :schema
20
- end
21
- end
22
- end
23
-
24
- module ClassMethods
25
- attr_accessor :schemas
26
-
27
- def set_schema(schema)
28
- self.schema = schema
29
- unless abstract_class?
30
- begin
31
- update_qualified_table_name
32
- update_qualified_sequence_name unless self.respond_to?(:primary_keys)
33
- rescue ::ActiveRecord::ConnectionNotEstablished
34
- # Defer
35
- end
36
- end
37
- end
38
-
39
- def set_table_name_with_schema(name)
40
- update_qualified_table_name(name)
41
- end
42
-
43
- def set_sequence_name_with_schema(name)
44
- if name
45
- update_qualified_sequence_name(name)
46
- else
47
- set_sequence_name_without_schema(name)
48
- end
49
- end
50
-
51
- def schemas
52
- @schemas ||= { }
53
- end
54
-
55
- protected
56
-
57
- def schema_name
58
- ::ActiveRecord::Base.schemas[self.schema] || self.schema
59
- end
60
-
61
- def update_qualified_table_name(table = nil)
62
- update_qualified(:table_name, table)
63
- end
64
-
65
- def update_qualified_sequence_name(sequence = nil)
66
- update_qualified(:sequence_name, sequence)
67
- end
68
-
69
- def update_qualified(thing, new_value)
70
- unless new_value
71
- current = self.send(thing) # invoke once only because of side effects
72
- new_value =
73
- if current.respond_to?(:include?) && current.include?('.')
74
- current.split('.', 2).last
75
- else
76
- current
77
- end
78
- end
79
- self.send(:"set_#{thing}_without_schema", nil) { new_value ? [schema_name, new_value].compact.join('.') : nil }
80
- end
81
- end
82
- end
83
- end
84
- end
85
-
86
- ::ActiveRecord::Base.send(:include, Bcdatabase::ActiveRecord::SchemaQualifiedTables)
1
+ begin
2
+ Gem::Specification.find_by_name('activerecord', '>=3.2')
3
+ require 'bcdatabase/active_record/schema_qualified_tables_override_getters'
4
+ rescue Gem::LoadError
5
+ require 'bcdatabase/active_record/schema_qualified_tables_override_setters'
6
+ end
@@ -1,7 +1,7 @@
1
1
  module Bcdatabase
2
2
  module ActiveRecord
3
3
  module SchemaQualifiedTables
4
- VERSION = '1.0.1'
4
+ VERSION = '1.1.0'
5
5
  end
6
6
  end
7
7
  end
@@ -0,0 +1,62 @@
1
+ require 'active_record'
2
+
3
+ module Bcdatabase
4
+ module ActiveRecord
5
+ module SchemaQualifiedTables
6
+ def self.included(clz)
7
+ clz.instance_eval do
8
+ extend ClassMethods
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
16
+ end
17
+ end
18
+
19
+ module ClassMethods
20
+ attr_accessor :schemas
21
+ attr_writer :schema
22
+
23
+ def table_name
24
+ unless abstract_class?
25
+ if schema_name
26
+ "#{schema_name}.#{super}"
27
+ else
28
+ super
29
+ end
30
+ end
31
+ end
32
+
33
+ def sequence_name
34
+ unless abstract_class?
35
+ if schema_name && (super =~ /^#{schema_name}\./).nil?
36
+ "#{schema_name}.#{super}"
37
+ else
38
+ super
39
+ end
40
+ end
41
+ end
42
+
43
+ # Support pre-rails 3.2 style setter
44
+ def set_schema(schema)
45
+ self.schema = schema
46
+ end
47
+
48
+ def schemas
49
+ @schemas ||= { }
50
+ end
51
+
52
+ protected
53
+
54
+ def schema_name
55
+ ::ActiveRecord::Base.schemas[self.schema] || self.schema
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end
61
+
62
+ ::ActiveRecord::Base.send(:include, Bcdatabase::ActiveRecord::SchemaQualifiedTables)
@@ -0,0 +1,86 @@
1
+ require 'active_record'
2
+
3
+ module Bcdatabase
4
+ module ActiveRecord
5
+ module SchemaQualifiedTables
6
+ def self.included(clz)
7
+ clz.instance_eval do
8
+ extend ClassMethods
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
16
+
17
+ class << self
18
+ alias_method_chain :set_table_name, :schema
19
+ alias_method_chain :set_sequence_name, :schema
20
+ end
21
+ end
22
+ end
23
+
24
+ module ClassMethods
25
+ attr_accessor :schemas
26
+
27
+ def set_schema(schema)
28
+ self.schema = schema
29
+ unless abstract_class?
30
+ begin
31
+ update_qualified_table_name
32
+ update_qualified_sequence_name unless self.respond_to?(:primary_keys)
33
+ rescue ::ActiveRecord::ConnectionNotEstablished
34
+ # Defer
35
+ end
36
+ end
37
+ end
38
+
39
+ def set_table_name_with_schema(name)
40
+ update_qualified_table_name(name)
41
+ end
42
+
43
+ def set_sequence_name_with_schema(name)
44
+ if name
45
+ update_qualified_sequence_name(name)
46
+ else
47
+ set_sequence_name_without_schema(name)
48
+ end
49
+ end
50
+
51
+ def schemas
52
+ @schemas ||= { }
53
+ end
54
+
55
+ protected
56
+
57
+ def schema_name
58
+ ::ActiveRecord::Base.schemas[self.schema] || self.schema
59
+ end
60
+
61
+ def update_qualified_table_name(table = nil)
62
+ update_qualified(:table_name, table)
63
+ end
64
+
65
+ def update_qualified_sequence_name(sequence = nil)
66
+ update_qualified(:sequence_name, sequence)
67
+ end
68
+
69
+ def update_qualified(thing, new_value)
70
+ unless new_value
71
+ current = self.send(thing) # invoke once only because of side effects
72
+ new_value =
73
+ if current.respond_to?(:include?) && current.include?('.')
74
+ current.split('.', 2).last
75
+ else
76
+ current
77
+ end
78
+ end
79
+ self.send(:"set_#{thing}_without_schema", nil) { new_value ? [schema_name, new_value].compact.join('.') : nil }
80
+ end
81
+ end
82
+ end
83
+ end
84
+ end
85
+
86
+ ::ActiveRecord::Base.send(:include, Bcdatabase::ActiveRecord::SchemaQualifiedTables)
@@ -21,8 +21,7 @@ Gem::Specification.new do |s|
21
21
  s.add_dependency 'activerecord', '>= 2.3'
22
22
 
23
23
  s.add_development_dependency 'rake', '~> 0.9.0'
24
- s.add_development_dependency 'rspec', '~> 2.6'
25
- s.add_development_dependency 'rcov'
24
+ s.add_development_dependency 'rspec', '~> 2.10.0'
26
25
  # the library is tested against CPK, but does not require it
27
26
  s.add_development_dependency 'composite_primary_keys'
28
27
  s.add_development_dependency 'ci_reporter', '~> 1.6.5'
@@ -1,5 +1,6 @@
1
1
  require File.expand_path("../../spec_helper", File.dirname(__FILE__))
2
2
  require 'active_record'
3
+
3
4
  ActiveRecord.load_all! if ActiveRecord.respond_to?(:load_all!) # Lazy loading of active_record was added to rails 2.3.2
4
5
  # so we have to explicitly load it this way for cpk to work.
5
6
  require 'composite_primary_keys' if SqtCpk.test_cpk?
@@ -13,6 +14,14 @@ describe "SchemaQualifiedTables" do
13
14
  remove_connection
14
15
  end
15
16
 
17
+ before(:each, :without_connection => true) do
18
+ remove_connection
19
+ end
20
+
21
+ after(:each, :without_connection => true) do
22
+ establish_connection
23
+ end
24
+
16
25
  after do
17
26
  Object.class_eval do
18
27
  %w(ReadingMaterialBase Book Magazine Newspaper Pamphlet).each do |clazz|
@@ -32,7 +41,7 @@ describe "SchemaQualifiedTables" do
32
41
 
33
42
  it "uses just the explicit tablename" do
34
43
  class Novel < ActiveRecord::Base
35
- set_table_name "books"
44
+ sqt_table_name("books")
36
45
  end
37
46
 
38
47
  Novel.table_name.should == 'books'
@@ -42,7 +51,7 @@ describe "SchemaQualifiedTables" do
42
51
  describe "with schema name" do
43
52
  it "uses the inferred table name" do
44
53
  class Magazine < ActiveRecord::Base
45
- set_schema :reading_material
54
+ sqt_schema_name(:reading_material)
46
55
  end
47
56
 
48
57
  Magazine.table_name.should == 'reading_material.magazines'
@@ -50,8 +59,8 @@ describe "SchemaQualifiedTables" do
50
59
 
51
60
  it "uses the explicit table name, if first" do
52
61
  class Magazine < ActiveRecord::Base
53
- set_table_name "some_magazines"
54
- set_schema :reading_material
62
+ sqt_table_name("some_magazines")
63
+ sqt_schema_name(:reading_material)
55
64
  end
56
65
 
57
66
  Magazine.table_name.should == "reading_material.some_magazines"
@@ -59,8 +68,8 @@ describe "SchemaQualifiedTables" do
59
68
 
60
69
  it "uses the explicit table name, if second" do
61
70
  class Magazine < ActiveRecord::Base
62
- set_schema :reading_material
63
- set_table_name "some_magazines"
71
+ sqt_schema_name(:reading_material)
72
+ sqt_table_name("some_magazines")
64
73
  end
65
74
 
66
75
  Magazine.table_name.should == "reading_material.some_magazines"
@@ -68,10 +77,10 @@ describe "SchemaQualifiedTables" do
68
77
 
69
78
  it "preserves the schema name if the table name is set several times" do
70
79
  class Magazine < ActiveRecord::Base
71
- set_schema :reading_material
72
- set_table_name "some_magazines"
80
+ sqt_schema_name(:reading_material)
81
+ sqt_table_name("some_magazines")
73
82
 
74
- set_table_name "other_magazines"
83
+ sqt_table_name("other_magazines")
75
84
  end
76
85
 
77
86
  Magazine.table_name.should == "reading_material.other_magazines"
@@ -79,20 +88,18 @@ describe "SchemaQualifiedTables" do
79
88
 
80
89
  it "uses the last schema if set several times" do
81
90
  class Magazine < ActiveRecord::Base
82
- set_schema :reading_material
83
- set_table_name "some_magazines"
84
- set_schema :periodicals
91
+ sqt_schema_name(:reading_material)
92
+ sqt_table_name("some_magazines")
93
+ sqt_schema_name(:periodicals)
85
94
  end
86
95
 
87
96
  Magazine.table_name.should == "periodicals.some_magazines"
88
97
  end
89
98
 
90
- it "works if set_schema is called without a connection" do
91
- ActiveRecord::Base.connection_handler.should_receive(:retrieve_connection).
92
- and_raise(ActiveRecord::ConnectionNotEstablished)
99
+ it "works if set_schema is called without a connection", :without_connection do
93
100
  lambda {
94
101
  class Magazine < ActiveRecord::Base
95
- set_schema :periodicals
102
+ sqt_schema_name(:periodicals)
96
103
  end
97
104
  }.should_not raise_error
98
105
 
@@ -103,13 +110,13 @@ describe "SchemaQualifiedTables" do
103
110
  before do
104
111
  class ReadingMaterialBase < ActiveRecord::Base
105
112
  self.abstract_class = true
106
- set_schema :reading_material
113
+ sqt_schema_name(:reading_material)
107
114
  end
108
115
  end
109
116
 
110
117
  it "inherits the schema from its parent class" do
111
118
  class Magazine < ReadingMaterialBase
112
- set_table_name "some_magazines"
119
+ sqt_table_name("some_magazines")
113
120
  end
114
121
 
115
122
  Magazine.schema.should == :reading_material
@@ -117,11 +124,14 @@ describe "SchemaQualifiedTables" do
117
124
  end
118
125
 
119
126
  it "uses the inferred table name for a child" do
120
- pending "bug in ActiveRecord::Base.reset_table_name"
127
+ unless active_record_32_or_greater?
128
+ pending "bug in ActiveRecord::Base.reset_table_name"
121
129
  # Fails because the first call to reset_table_name
122
130
  # always returns just the inferred table name. Usually
123
131
  # the first call is during set_table_name or set_schema.
124
132
  # In this spec, it is in the call to table_name, below.
133
+ end
134
+
125
135
  class Newspaper < ReadingMaterialBase; end
126
136
 
127
137
  Newspaper.schema.should == :reading_material
@@ -130,11 +140,11 @@ describe "SchemaQualifiedTables" do
130
140
 
131
141
  it "uses separate schemas for subclasses" do
132
142
  class Magazine < ReadingMaterialBase
133
- set_table_name "some_magazines"
134
- set_schema :periodicals
143
+ sqt_table_name("some_magazines")
144
+ sqt_schema_name(:periodicals)
135
145
  end
136
146
  class Newspaper < ReadingMaterialBase
137
- set_schema :deprecated
147
+ sqt_schema_name(:deprecated)
138
148
  end
139
149
 
140
150
  Magazine.table_name.should == "periodicals.some_magazines"
@@ -155,7 +165,7 @@ describe "SchemaQualifiedTables" do
155
165
 
156
166
  it "uses the inferred table name" do
157
167
  class Pamphlet < ActiveRecord::Base
158
- set_schema :reading_material
168
+ sqt_schema_name(:reading_material)
159
169
  end
160
170
 
161
171
  Pamphlet.table_name.should == 'reading_material_test.pamphlets'
@@ -163,8 +173,8 @@ describe "SchemaQualifiedTables" do
163
173
 
164
174
  it "uses the explicit table name, if first" do
165
175
  class Pamphlet < ActiveRecord::Base
166
- set_table_name "some_pamphlets"
167
- set_schema :reading_material
176
+ sqt_table_name("some_pamphlets")
177
+ sqt_schema_name(:reading_material)
168
178
  end
169
179
 
170
180
  Pamphlet.table_name.should == "reading_material_test.some_pamphlets"
@@ -172,8 +182,8 @@ describe "SchemaQualifiedTables" do
172
182
 
173
183
  it "uses the explicit table name, if second" do
174
184
  class Pamphlet < ActiveRecord::Base
175
- set_schema :reading_material
176
- set_table_name "some_pamphlets"
185
+ sqt_schema_name(:reading_material)
186
+ sqt_table_name("some_pamphlets")
177
187
  end
178
188
 
179
189
  Pamphlet.table_name.should == "reading_material_test.some_pamphlets"
@@ -181,8 +191,8 @@ describe "SchemaQualifiedTables" do
181
191
 
182
192
  it "applies name overrides that come after the model is loaded" do
183
193
  class Newspaper < ActiveRecord::Base
184
- set_table_name "newspaperos"
185
- set_schema :periodicals
194
+ sqt_table_name("newspaperos")
195
+ sqt_schema_name(:periodicals)
186
196
  end
187
197
 
188
198
  ActiveRecord::Base.schemas = { :periodicals => "periodicals_test" }
@@ -192,7 +202,7 @@ describe "SchemaQualifiedTables" do
192
202
 
193
203
  it "applies name overrides that come after the model is loaded when using the inferred table name" do
194
204
  class Newspaper < ActiveRecord::Base
195
- set_schema :periodicals
205
+ sqt_schema_name(:periodicals)
196
206
  end
197
207
 
198
208
  ActiveRecord::Base.schemas = { :periodicals => "periodicals_test" }
@@ -219,7 +229,7 @@ describe "SchemaQualifiedTables" do
219
229
 
220
230
  it "uses just the explicit sequencename" do
221
231
  class Novel < ActiveRecord::Base
222
- set_sequence_name "books"
232
+ sqt_sequence_name("books")
223
233
  end
224
234
 
225
235
  Novel.sequence_name.should == 'books'
@@ -238,7 +248,7 @@ describe "SchemaQualifiedTables" do
238
248
  describe "with schema name" do
239
249
  it "uses the inferred sequence name" do
240
250
  class Magazine < ActiveRecord::Base
241
- set_schema :reading_material
251
+ sqt_schema_name(:reading_material)
242
252
  end
243
253
 
244
254
  Magazine.sequence_name.should == "reading_material.#{inferred 'magazines'}"
@@ -248,7 +258,7 @@ describe "SchemaQualifiedTables" do
248
258
  pending 'Adapter does have a default' if inferred
249
259
 
250
260
  class Book < ActiveRecord::Base
251
- set_schema :reading_material
261
+ sqt_schema_name(:reading_material)
252
262
  end
253
263
 
254
264
  Book.sequence_name.should be_nil
@@ -261,16 +271,16 @@ describe "SchemaQualifiedTables" do
261
271
 
262
272
  it "doesn't fail when setting the schema" do
263
273
  class Newspaper < ActiveRecord::Base
264
- set_primary_keys "address", "telephone"
265
- set_schema :reading_material
274
+ sqt_primary_keys("address", "telephone")
275
+ sqt_schema_name(:reading_material)
266
276
  end
267
277
  end
268
278
  end
269
279
 
270
280
  it "uses the explicit sequence name, if first" do
271
281
  class Magazine < ActiveRecord::Base
272
- set_sequence_name "some_magazines_seq"
273
- set_schema :reading_material
282
+ sqt_sequence_name("some_magazines_seq")
283
+ sqt_schema_name(:reading_material)
274
284
  end
275
285
 
276
286
  Magazine.sequence_name.should == "reading_material.some_magazines_seq"
@@ -278,8 +288,8 @@ describe "SchemaQualifiedTables" do
278
288
 
279
289
  it "uses the explicit sequence name, if second" do
280
290
  class Magazine < ActiveRecord::Base
281
- set_schema :reading_material
282
- set_sequence_name "some_magazines_seq"
291
+ sqt_schema_name(:reading_material)
292
+ sqt_sequence_name("some_magazines_seq")
283
293
  end
284
294
 
285
295
  Magazine.sequence_name.should == "reading_material.some_magazines_seq"
@@ -287,10 +297,10 @@ describe "SchemaQualifiedTables" do
287
297
 
288
298
  it "preserves the schema name if the sequence name is set several times" do
289
299
  class Magazine < ActiveRecord::Base
290
- set_schema :reading_material
291
- set_sequence_name "some_magazines_seq"
300
+ sqt_schema_name(:reading_material)
301
+ sqt_sequence_name("some_magazines_seq")
292
302
 
293
- set_sequence_name "other_magazines_seq"
303
+ sqt_sequence_name("other_magazines_seq")
294
304
  end
295
305
 
296
306
  Magazine.sequence_name.should == "reading_material.other_magazines_seq"
@@ -298,21 +308,19 @@ describe "SchemaQualifiedTables" do
298
308
 
299
309
  it "uses the last schema if set several times" do
300
310
  class Magazine < ActiveRecord::Base
301
- set_schema :reading_material
302
- set_sequence_name "some_magazines_seq"
303
- set_schema :periodicals
311
+ sqt_schema_name(:reading_material)
312
+ sqt_sequence_name("some_magazines_seq")
313
+ sqt_schema_name(:periodicals)
304
314
  end
305
315
 
306
316
  Magazine.sequence_name.should == "periodicals.some_magazines_seq"
307
317
  end
308
318
 
309
- it "works if set_schema is called without a connection" do
310
- ActiveRecord::Base.connection_handler.should_receive(:retrieve_connection).
311
- and_raise(ActiveRecord::ConnectionNotEstablished)
319
+ it "works if set_schema is called without a connection", :without_connection do
312
320
  lambda {
313
321
  class Magazine < ActiveRecord::Base
314
- set_schema :periodicals
315
- set_sequence_name 'mag_seq'
322
+ sqt_schema_name(:periodicals)
323
+ sqt_sequence_name("mag_seq")
316
324
  end
317
325
  }.should_not raise_error
318
326
 
@@ -332,7 +340,7 @@ describe "SchemaQualifiedTables" do
332
340
 
333
341
  it "uses the inferred sequence name" do
334
342
  class Pamphlet < ActiveRecord::Base
335
- set_schema :reading_material
343
+ sqt_schema_name(:reading_material)
336
344
  end
337
345
 
338
346
  Pamphlet.sequence_name.should == "rm_test.#{inferred 'pamphlets'}"
@@ -340,8 +348,8 @@ describe "SchemaQualifiedTables" do
340
348
 
341
349
  it "uses the explicit sequence name, if first" do
342
350
  class Pamphlet < ActiveRecord::Base
343
- set_sequence_name "some_pamphlets"
344
- set_schema :reading_material
351
+ sqt_sequence_name("some_pamphlets")
352
+ sqt_schema_name(:reading_material)
345
353
  end
346
354
 
347
355
  Pamphlet.sequence_name.should == "rm_test.some_pamphlets"
@@ -349,8 +357,8 @@ describe "SchemaQualifiedTables" do
349
357
 
350
358
  it "uses the explicit sequence name, if second" do
351
359
  class Pamphlet < ActiveRecord::Base
352
- set_schema :reading_material
353
- set_sequence_name "some_pamphlets"
360
+ sqt_schema_name(:reading_material)
361
+ sqt_sequence_name("some_pamphlets")
354
362
  end
355
363
 
356
364
  Pamphlet.sequence_name.should == "rm_test.some_pamphlets"
@@ -359,4 +367,3 @@ describe "SchemaQualifiedTables" do
359
367
  end
360
368
  end
361
369
  end
362
-
@@ -39,7 +39,65 @@ module DatabaseHelper
39
39
  end
40
40
  end
41
41
 
42
+ module ARVersion
43
+ def active_record_32_or_greater?
44
+ begin
45
+ Gem::Specification.find_by_name('activerecord', '>=3.2')
46
+ true
47
+ rescue Gem::LoadError
48
+ false
49
+ end
50
+ end
51
+ end
52
+ include ARVersion
53
+
54
+ module SqtHelper
55
+ module ClassMethods
56
+ if active_record_32_or_greater?
57
+ def sqt_table_name(name)
58
+ self.table_name = name
59
+ end
60
+
61
+ def sqt_sequence_name(name)
62
+ self.sequence_name = name
63
+ end
64
+
65
+ def sqt_schema_name(name)
66
+ self.schema = name
67
+ end
68
+
69
+ def sqt_primary_keys(*keys)
70
+ self.primary_keys = keys
71
+ end
72
+ else
73
+ def sqt_table_name(name)
74
+ set_table_name(name)
75
+ end
76
+
77
+ def sqt_sequence_name(name)
78
+ set_sequence_name(name)
79
+ end
80
+
81
+ def sqt_schema_name(name)
82
+ set_schema(name)
83
+ end
84
+
85
+ def sqt_primary_keys(*keys)
86
+ set_primary_keys(*keys)
87
+ end
88
+ end
89
+ end
90
+
91
+ def self.included(base)
92
+ base.extend(ClassMethods)
93
+ end
94
+ end
95
+
96
+ ::ActiveRecord::Base.send(:include, SqtHelper)
97
+
42
98
  RSpec.configure do |config|
43
99
  config.include SqtCpk
44
100
  config.include DatabaseHelper
45
- end
101
+ config.include ARVersion
102
+ config.treat_symbols_as_metadata_keys_with_true_values = true
103
+ end
metadata CHANGED
@@ -1,138 +1,120 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: schema_qualified_tables
3
- version: !ruby/object:Gem::Version
4
- hash: 21
5
- prerelease: false
6
- segments:
7
- - 1
8
- - 0
9
- - 1
10
- version: 1.0.1
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.1.0
5
+ prerelease:
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Rhett Sutphin
14
9
  - Peter Nyberg
15
10
  autorequire:
16
11
  bindir: bin
17
12
  cert_chain: []
18
-
19
- date: 2011-09-01 00:00:00 -05:00
20
- default_executable:
21
- dependencies:
22
- - !ruby/object:Gem::Dependency
13
+ date: 2012-10-08 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
23
16
  name: activerecord
24
- prerelease: false
25
- requirement: &id001 !ruby/object:Gem::Requirement
17
+ requirement: !ruby/object:Gem::Requirement
26
18
  none: false
27
- requirements:
28
- - - ">="
29
- - !ruby/object:Gem::Version
30
- hash: 5
31
- segments:
32
- - 2
33
- - 3
34
- version: "2.3"
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
22
+ version: '2.3'
35
23
  type: :runtime
36
- version_requirements: *id001
37
- - !ruby/object:Gem::Dependency
38
- name: rake
39
24
  prerelease: false
40
- requirement: &id002 !ruby/object:Gem::Requirement
25
+ version_requirements: !ruby/object:Gem::Requirement
41
26
  none: false
42
- requirements:
27
+ requirements:
28
+ - - ! '>='
29
+ - !ruby/object:Gem::Version
30
+ version: '2.3'
31
+ - !ruby/object:Gem::Dependency
32
+ name: rake
33
+ requirement: !ruby/object:Gem::Requirement
34
+ none: false
35
+ requirements:
43
36
  - - ~>
44
- - !ruby/object:Gem::Version
45
- hash: 59
46
- segments:
47
- - 0
48
- - 9
49
- - 0
37
+ - !ruby/object:Gem::Version
50
38
  version: 0.9.0
51
39
  type: :development
52
- version_requirements: *id002
53
- - !ruby/object:Gem::Dependency
54
- name: rspec
55
40
  prerelease: false
56
- requirement: &id003 !ruby/object:Gem::Requirement
41
+ version_requirements: !ruby/object:Gem::Requirement
57
42
  none: false
58
- requirements:
43
+ requirements:
59
44
  - - ~>
60
- - !ruby/object:Gem::Version
61
- hash: 15
62
- segments:
63
- - 2
64
- - 6
65
- version: "2.6"
45
+ - !ruby/object:Gem::Version
46
+ version: 0.9.0
47
+ - !ruby/object:Gem::Dependency
48
+ name: rspec
49
+ requirement: !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 2.10.0
66
55
  type: :development
67
- version_requirements: *id003
68
- - !ruby/object:Gem::Dependency
69
- name: rcov
70
56
  prerelease: false
71
- requirement: &id004 !ruby/object:Gem::Requirement
57
+ version_requirements: !ruby/object:Gem::Requirement
72
58
  none: false
73
- requirements:
74
- - - ">="
75
- - !ruby/object:Gem::Version
76
- hash: 3
77
- segments:
78
- - 0
79
- version: "0"
80
- type: :development
81
- version_requirements: *id004
82
- - !ruby/object:Gem::Dependency
59
+ requirements:
60
+ - - ~>
61
+ - !ruby/object:Gem::Version
62
+ version: 2.10.0
63
+ - !ruby/object:Gem::Dependency
83
64
  name: composite_primary_keys
84
- prerelease: false
85
- requirement: &id005 !ruby/object:Gem::Requirement
65
+ requirement: !ruby/object:Gem::Requirement
86
66
  none: false
87
- requirements:
88
- - - ">="
89
- - !ruby/object:Gem::Version
90
- hash: 3
91
- segments:
92
- - 0
93
- version: "0"
67
+ requirements:
68
+ - - ! '>='
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
94
71
  type: :development
95
- version_requirements: *id005
96
- - !ruby/object:Gem::Dependency
97
- name: ci_reporter
98
72
  prerelease: false
99
- requirement: &id006 !ruby/object:Gem::Requirement
73
+ version_requirements: !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ! '>='
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ - !ruby/object:Gem::Dependency
80
+ name: ci_reporter
81
+ requirement: !ruby/object:Gem::Requirement
100
82
  none: false
101
- requirements:
83
+ requirements:
102
84
  - - ~>
103
- - !ruby/object:Gem::Version
104
- hash: 5
105
- segments:
106
- - 1
107
- - 6
108
- - 5
85
+ - !ruby/object:Gem::Version
109
86
  version: 1.6.5
110
87
  type: :development
111
- version_requirements: *id006
112
- - !ruby/object:Gem::Dependency
113
- name: bcdatabase
114
88
  prerelease: false
115
- requirement: &id007 !ruby/object:Gem::Requirement
89
+ version_requirements: !ruby/object:Gem::Requirement
90
+ none: false
91
+ requirements:
92
+ - - ~>
93
+ - !ruby/object:Gem::Version
94
+ version: 1.6.5
95
+ - !ruby/object:Gem::Dependency
96
+ name: bcdatabase
97
+ requirement: !ruby/object:Gem::Requirement
116
98
  none: false
117
- requirements:
99
+ requirements:
118
100
  - - ~>
119
- - !ruby/object:Gem::Version
120
- hash: 11
121
- segments:
122
- - 1
123
- - 2
124
- version: "1.2"
101
+ - !ruby/object:Gem::Version
102
+ version: '1.2'
125
103
  type: :development
126
- version_requirements: *id007
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.
104
+ prerelease: false
105
+ version_requirements: !ruby/object:Gem::Requirement
106
+ none: false
107
+ requirements:
108
+ - - ~>
109
+ - !ruby/object:Gem::Version
110
+ version: '1.2'
111
+ description: An ActiveRecord mix-in that makes it easier to use AR in an application
112
+ which contains models which map to tables in different schemas.
128
113
  email: rhett@detailedbalance.net
129
114
  executables: []
130
-
131
115
  extensions: []
132
-
133
116
  extra_rdoc_files: []
134
-
135
- files:
117
+ files:
136
118
  - .gitignore
137
119
  - .rvmrc
138
120
  - CHANGELOG.markdown
@@ -143,44 +125,42 @@ files:
143
125
  - ci-exec.sh
144
126
  - lib/bcdatabase/active_record/schema_qualified_tables.rb
145
127
  - lib/bcdatabase/active_record/schema_qualified_tables/version.rb
128
+ - lib/bcdatabase/active_record/schema_qualified_tables_override_getters.rb
129
+ - lib/bcdatabase/active_record/schema_qualified_tables_override_setters.rb
146
130
  - lib/schema_qualified_tables.rb
147
131
  - schema_qualified_tables.gemspec
148
132
  - spec/bcdatabase/active_record/schema_qualified_tables_spec.rb
149
133
  - spec/spec_helper.rb
150
- has_rdoc: true
151
134
  homepage: http://github.com/NUBIC/schema_qualified_tables
152
135
  licenses: []
153
-
154
136
  post_install_message:
155
137
  rdoc_options: []
156
-
157
- require_paths:
138
+ require_paths:
158
139
  - lib
159
- required_ruby_version: !ruby/object:Gem::Requirement
140
+ required_ruby_version: !ruby/object:Gem::Requirement
160
141
  none: false
161
- requirements:
162
- - - ">="
163
- - !ruby/object:Gem::Version
164
- hash: 3
165
- segments:
142
+ requirements:
143
+ - - ! '>='
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ segments:
166
147
  - 0
167
- version: "0"
168
- required_rubygems_version: !ruby/object:Gem::Requirement
148
+ hash: -3344378071871990966
149
+ required_rubygems_version: !ruby/object:Gem::Requirement
169
150
  none: false
170
- requirements:
171
- - - ">="
172
- - !ruby/object:Gem::Version
173
- hash: 3
174
- segments:
151
+ requirements:
152
+ - - ! '>='
153
+ - !ruby/object:Gem::Version
154
+ version: '0'
155
+ segments:
175
156
  - 0
176
- version: "0"
157
+ hash: -3344378071871990966
177
158
  requirements: []
178
-
179
159
  rubyforge_project:
180
- rubygems_version: 1.3.7
160
+ rubygems_version: 1.8.24
181
161
  signing_key:
182
162
  specification_version: 3
183
163
  summary: Logical schema names for ActiveRecord models
184
- test_files:
164
+ test_files:
185
165
  - spec/bcdatabase/active_record/schema_qualified_tables_spec.rb
186
166
  - spec/spec_helper.rb