sequel_oracle_extensions 0.5.2 → 0.5.3
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/sequel/oracle_extensions/hints.rb +71 -71
- data/lib/sequel/oracle_extensions/merge.rb +204 -204
- data/lib/sequel/oracle_extensions/schemata.rb +148 -123
- data/lib/sequel/oracle_extensions.rb +4 -4
- data/lib/sequel_oracle_extensions.rb +1 -1
- data/sequel_oracle_extensions.gemspec +62 -56
- data/spec/sequel/oracle_extensions/hints_spec.rb +148 -148
- data/spec/sequel/oracle_extensions/merge_spec.rb +8 -8
- data/spec/spec_helper.rb +24 -24
- metadata +10 -8
@@ -1,157 +1,157 @@
|
|
1
|
-
require File.expand_path('../../../spec_helper', __FILE__)
|
2
|
-
require 'sequel/oracle_extensions/merge'
|
3
|
-
require 'sequel/oracle_extensions/hints'
|
4
|
-
|
5
|
-
describe "Sequel::OracleExtensions::Hints" do
|
6
|
-
|
7
|
-
CLAUSES = %w(SELECT INSERT UPDATE DELETE MERGE)
|
8
|
-
TYPES = CLAUSES.map{|clause| clause.downcase.intern}
|
9
|
-
|
10
|
-
before(:all) do
|
11
|
-
@db = Sequel.connect(DATABASE_URL)
|
12
|
-
end
|
13
|
-
|
14
|
-
def apply_hints!(*args)
|
15
|
-
@old_hints = @ds.opts[:hints]
|
16
|
-
@new_ds = @ds.__send__(@method, *args)
|
17
|
-
|
1
|
+
require File.expand_path('../../../spec_helper', __FILE__)
|
2
|
+
require 'sequel/oracle_extensions/merge'
|
3
|
+
require 'sequel/oracle_extensions/hints'
|
4
|
+
|
5
|
+
describe "Sequel::OracleExtensions::Hints" do
|
6
|
+
|
7
|
+
CLAUSES = %w(SELECT INSERT UPDATE DELETE MERGE)
|
8
|
+
TYPES = CLAUSES.map{|clause| clause.downcase.intern}
|
9
|
+
|
10
|
+
before(:all) do
|
11
|
+
@db = Sequel.connect(DATABASE_URL)
|
12
|
+
end
|
13
|
+
|
14
|
+
def apply_hints!(*args)
|
15
|
+
@old_hints = @ds.opts[:hints]
|
16
|
+
@new_ds = @ds.__send__(@method, *args)
|
17
|
+
|
18
18
|
@new_ds.should be_kind_of(Sequel::Dataset)
|
19
|
-
@new_ds.opts[:hints].should_not be_empty
|
20
|
-
end
|
21
|
-
|
22
|
-
it "hooks into dataset clause methods" do
|
23
|
-
[Sequel::Dataset, Sequel::Oracle::DatasetMethods].each do |klass|
|
24
|
-
CLAUSES.each do |clause|
|
25
|
-
next unless klass.const_defined?(k = :"#{clause}_CLAUSE_METHODS")
|
26
|
-
klass.const_get(k).first.should == "#{clause.downcase}_hint_sql".intern
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
share_examples_for "dataset modifying" do
|
32
|
-
after(:each) do
|
19
|
+
@new_ds.opts[:hints].should_not be_empty
|
20
|
+
end
|
21
|
+
|
22
|
+
it "hooks into dataset clause methods" do
|
23
|
+
[Sequel::Dataset, Sequel::Oracle::DatasetMethods].each do |klass|
|
24
|
+
CLAUSES.each do |clause|
|
25
|
+
next unless klass.const_defined?(k = :"#{clause}_CLAUSE_METHODS")
|
26
|
+
klass.const_get(k).first.should == "#{clause.downcase}_hint_sql".intern
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
share_examples_for "dataset modifying" do
|
32
|
+
after(:each) do
|
33
33
|
@ds.should equal(@new_ds)
|
34
|
-
@ds.opts[:hints].should_not == @old_hints
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
share_examples_for "dataset cloning" do
|
39
|
-
after(:each) do
|
34
|
+
@ds.opts[:hints].should_not == @old_hints
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
share_examples_for "dataset cloning" do
|
39
|
+
after(:each) do
|
40
40
|
@ds.should_not equal(@new_ds)
|
41
|
-
@ds.opts[:hints].should == @old_hints
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
share_examples_for "standard callspec" do
|
46
|
-
it "callspec (String) applies :select hints" do
|
47
|
-
apply_hints! @hints.first
|
41
|
+
@ds.opts[:hints].should == @old_hints
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
share_examples_for "standard callspec" do
|
46
|
+
it "callspec (String) applies :select hints" do
|
47
|
+
apply_hints! @hints.first
|
48
48
|
hints_to_check(@new_ds, :select, @hints[0,1]).should == @hints[0,1]
|
49
|
-
end
|
50
|
-
it "callspec (String, ...) applies :select hints" do
|
51
|
-
apply_hints! *@hints
|
49
|
+
end
|
50
|
+
it "callspec (String, ...) applies :select hints" do
|
51
|
+
apply_hints! *@hints
|
52
52
|
hints_to_check(@new_ds, :select, @hints).should == @hints
|
53
|
-
end
|
54
|
-
it "callspec (clause, String) applies clause hints" do
|
55
|
-
TYPES.each do |type|
|
56
|
-
apply_hints! type, @hints.first
|
53
|
+
end
|
54
|
+
it "callspec (clause, String) applies clause hints" do
|
55
|
+
TYPES.each do |type|
|
56
|
+
apply_hints! type, @hints.first
|
57
57
|
hints_to_check(@new_ds, type, @hints[0,1]).should == @hints[0,1]
|
58
|
-
end
|
59
|
-
end
|
60
|
-
it "callspec (clause, String, ...) applies clause hints" do
|
61
|
-
TYPES.each do |type|
|
62
|
-
apply_hints! type, *@hints
|
58
|
+
end
|
59
|
+
end
|
60
|
+
it "callspec (clause, String, ...) applies clause hints" do
|
61
|
+
TYPES.each do |type|
|
62
|
+
apply_hints! type, *@hints
|
63
63
|
hints_to_check(@new_ds, type, @hints).should == @hints
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
share_examples_for "clause-specific callspec" do
|
69
|
-
it "callspec (String) applies hints" do
|
70
|
-
apply_hints! @hints.first
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
share_examples_for "clause-specific callspec" do
|
69
|
+
it "callspec (String) applies hints" do
|
70
|
+
apply_hints! @hints.first
|
71
71
|
hints_to_check(@new_ds, @clause, @hints[0,1]).should == @hints[0,1]
|
72
|
-
end
|
73
|
-
it "callspec (String, ...) applies hints" do
|
74
|
-
apply_hints! *@hints
|
72
|
+
end
|
73
|
+
it "callspec (String, ...) applies hints" do
|
74
|
+
apply_hints! *@hints
|
75
75
|
hints_to_check(@new_ds, @clause, @hints).should == @hints
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
describe "hints" do
|
80
|
-
before(:each){ @ds, @hints = @db[:dual], ['foo', 'bar'] }
|
81
|
-
|
82
|
-
COMMON_GROUP_BODY = Proc.new do |group,name|
|
83
|
-
group.class_eval do
|
84
|
-
describe "##{name}" do
|
85
|
-
before(:each){ @method = :"#{name}" }
|
86
|
-
it_should_behave_like "dataset cloning"
|
87
|
-
it_should_behave_like "standard callspec"
|
88
|
-
end
|
89
|
-
describe "##{name}!" do
|
90
|
-
before(:each){ @method = :"#{name}!" }
|
91
|
-
it_should_behave_like "dataset modifying"
|
92
|
-
it_should_behave_like "standard callspec"
|
93
|
-
end
|
94
|
-
TYPES.each do |clause|
|
95
|
-
describe "##{clause}_#{name}" do
|
96
|
-
before(:each){ @clause, @method = clause, :"#{clause}_#{name}"}
|
97
|
-
it_should_behave_like "dataset cloning"
|
98
|
-
it_should_behave_like "clause-specific callspec"
|
99
|
-
end
|
100
|
-
describe "##{clause}_#{name}!" do
|
101
|
-
before(:each){ @clause, @method = clause, :"#{clause}_#{name}!"}
|
102
|
-
it_should_behave_like "dataset modifying"
|
103
|
-
it_should_behave_like "clause-specific callspec"
|
104
|
-
end
|
105
|
-
end
|
106
|
-
end
|
107
|
-
end
|
108
|
-
|
109
|
-
describe "adding hints" do
|
110
|
-
def hints_to_check(ds, type, input)
|
111
|
-
ds.opts[:hints][type][(@orig_hints[type].length rescue 0), input.length]
|
112
|
-
end
|
113
|
-
COMMON_GROUP_BODY.call self, :hint
|
114
|
-
end
|
115
|
-
|
116
|
-
describe "overwriting hints" do
|
117
|
-
def hints_to_check(ds, type, input)
|
118
|
-
ds.opts[:hints][type]
|
119
|
-
end
|
120
|
-
COMMON_GROUP_BODY.call self, :hints
|
121
|
-
end
|
122
|
-
|
123
|
-
describe "#hint_sql" do
|
124
|
-
it "generates clause-specific hint SQL" do
|
125
|
-
# set them all up front so we can test whether they get mixed up.
|
126
|
-
TYPES.each do |type| @ds.hints! type, "hint for #{type}" end
|
127
|
-
TYPES.each do |type|
|
128
|
-
sql = (clause = type.to_s.upcase).dup
|
129
|
-
@ds.hint_sql(type, sql).should equal(sql)
|
130
|
-
sql.should == "#{clause} /*+ hint for #{type} */"
|
131
|
-
end
|
132
|
-
end
|
133
|
-
|
134
|
-
it "skips empty hints" do
|
135
|
-
TYPES.each do |type|
|
136
|
-
sql = (clause = type.to_s.upcase).dup
|
137
|
-
@ds.hint_sql(type, sql).should be_nil
|
138
|
-
sql.should == clause
|
139
|
-
end
|
140
|
-
end
|
141
|
-
|
142
|
-
TYPES.each do |type|
|
143
|
-
it "is called by ##{type}_hint_sql" do
|
144
|
-
clause = type.to_s.upcase
|
145
|
-
@ds.should_receive(:hint_sql).with(type, clause)
|
146
|
-
@ds.__send__ :"#{type}_hint_sql", clause
|
147
|
-
end
|
148
|
-
it "is called by ##{type}_sql" do
|
149
|
-
args, clause = [], type.to_s.upcase
|
150
|
-
@ds.should_receive(:hint_sql).with(type, clause)
|
151
|
-
args.push :dual, :dual, :x if type == :merge
|
152
|
-
@ds.__send__ :"#{type}_sql", *args
|
153
|
-
end
|
154
|
-
end
|
155
|
-
end
|
156
|
-
end
|
157
|
-
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
describe "hints" do
|
80
|
+
before(:each){ @ds, @hints = @db[:dual], ['foo', 'bar'] }
|
81
|
+
|
82
|
+
COMMON_GROUP_BODY = Proc.new do |group,name|
|
83
|
+
group.class_eval do
|
84
|
+
describe "##{name}" do
|
85
|
+
before(:each){ @method = :"#{name}" }
|
86
|
+
it_should_behave_like "dataset cloning"
|
87
|
+
it_should_behave_like "standard callspec"
|
88
|
+
end
|
89
|
+
describe "##{name}!" do
|
90
|
+
before(:each){ @method = :"#{name}!" }
|
91
|
+
it_should_behave_like "dataset modifying"
|
92
|
+
it_should_behave_like "standard callspec"
|
93
|
+
end
|
94
|
+
TYPES.each do |clause|
|
95
|
+
describe "##{clause}_#{name}" do
|
96
|
+
before(:each){ @clause, @method = clause, :"#{clause}_#{name}"}
|
97
|
+
it_should_behave_like "dataset cloning"
|
98
|
+
it_should_behave_like "clause-specific callspec"
|
99
|
+
end
|
100
|
+
describe "##{clause}_#{name}!" do
|
101
|
+
before(:each){ @clause, @method = clause, :"#{clause}_#{name}!"}
|
102
|
+
it_should_behave_like "dataset modifying"
|
103
|
+
it_should_behave_like "clause-specific callspec"
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
describe "adding hints" do
|
110
|
+
def hints_to_check(ds, type, input)
|
111
|
+
ds.opts[:hints][type][(@orig_hints[type].length rescue 0), input.length]
|
112
|
+
end
|
113
|
+
COMMON_GROUP_BODY.call self, :hint
|
114
|
+
end
|
115
|
+
|
116
|
+
describe "overwriting hints" do
|
117
|
+
def hints_to_check(ds, type, input)
|
118
|
+
ds.opts[:hints][type]
|
119
|
+
end
|
120
|
+
COMMON_GROUP_BODY.call self, :hints
|
121
|
+
end
|
122
|
+
|
123
|
+
describe "#hint_sql" do
|
124
|
+
it "generates clause-specific hint SQL" do
|
125
|
+
# set them all up front so we can test whether they get mixed up.
|
126
|
+
TYPES.each do |type| @ds.hints! type, "hint for #{type}" end
|
127
|
+
TYPES.each do |type|
|
128
|
+
sql = (clause = type.to_s.upcase).dup
|
129
|
+
@ds.hint_sql(type, sql).should equal(sql)
|
130
|
+
sql.should == "#{clause} /*+ hint for #{type} */"
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
it "skips empty hints" do
|
135
|
+
TYPES.each do |type|
|
136
|
+
sql = (clause = type.to_s.upcase).dup
|
137
|
+
@ds.hint_sql(type, sql).should be_nil
|
138
|
+
sql.should == clause
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
TYPES.each do |type|
|
143
|
+
it "is called by ##{type}_hint_sql" do
|
144
|
+
clause = type.to_s.upcase
|
145
|
+
@ds.should_receive(:hint_sql).with(type, clause)
|
146
|
+
@ds.__send__ :"#{type}_hint_sql", clause
|
147
|
+
end
|
148
|
+
it "is called by ##{type}_sql" do
|
149
|
+
args, clause = [], type.to_s.upcase
|
150
|
+
@ds.should_receive(:hint_sql).with(type, clause)
|
151
|
+
args.push :dual, :dual, :x if type == :merge
|
152
|
+
@ds.__send__ :"#{type}_sql", *args
|
153
|
+
end
|
154
|
+
end
|
155
|
+
end
|
156
|
+
end
|
157
|
+
end
|
@@ -1,8 +1,8 @@
|
|
1
|
-
require File.expand_path('../../../spec_helper', __FILE__)
|
2
|
-
require 'sequel/oracle_extensions/merge'
|
3
|
-
|
4
|
-
describe "Sequel::OracleExtensions::Merge" do
|
5
|
-
before(:all) do
|
6
|
-
@db = Sequel.connect(DATABASE_URL)
|
7
|
-
end
|
8
|
-
end
|
1
|
+
require File.expand_path('../../../spec_helper', __FILE__)
|
2
|
+
require 'sequel/oracle_extensions/merge'
|
3
|
+
|
4
|
+
describe "Sequel::OracleExtensions::Merge" do
|
5
|
+
before(:all) do
|
6
|
+
@db = Sequel.connect(DATABASE_URL)
|
7
|
+
end
|
8
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,25 +1,25 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'pp'
|
3
|
-
begin require 'win32console' and include Win32::Console::ANSI
|
4
|
-
rescue LoadError
|
5
|
-
end if RUBY_PLATFORM =~ /msvc|mingw|cygwin|win32/
|
6
|
-
|
7
|
-
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
8
|
-
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
9
|
-
require 'sequel'
|
10
|
-
require "rspec"
|
11
|
-
|
12
|
-
DATABASE_URL = begin
|
13
|
-
user = ENV['DATABASE_USER'] || 'hr'
|
14
|
-
password = ENV['DATABASE_PASSWORD'] || 'hr'
|
15
|
-
name = ENV['DATABASE_NAME'] || 'xe'
|
16
|
-
host = ENV['DATABASE_HOST'] || 'localhost'
|
17
|
-
port = ':'+ENV['DATABASE_PORT'] rescue nil
|
18
|
-
"oracle://#{user}:#{password}@#{host}#{port}/#{name}"
|
1
|
+
require 'rubygems'
|
2
|
+
require 'pp'
|
3
|
+
begin require 'win32console' and include Win32::Console::ANSI
|
4
|
+
rescue LoadError
|
5
|
+
end if RUBY_PLATFORM =~ /msvc|mingw|cygwin|win32/
|
6
|
+
|
7
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
8
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
9
|
+
require 'sequel'
|
10
|
+
require "rspec"
|
11
|
+
|
12
|
+
DATABASE_URL = begin
|
13
|
+
user = ENV['DATABASE_USER'] || 'hr'
|
14
|
+
password = ENV['DATABASE_PASSWORD'] || 'hr'
|
15
|
+
name = ENV['DATABASE_NAME'] || 'xe'
|
16
|
+
host = ENV['DATABASE_HOST'] || 'localhost'
|
17
|
+
port = ':'+ENV['DATABASE_PORT'] rescue nil
|
18
|
+
"oracle://#{user}:#{password}@#{host}#{port}/#{name}"
|
19
|
+
end
|
20
|
+
|
21
|
+
RSpec.configure do |config|
|
22
|
+
require 'rspec/expectations'
|
23
|
+
config.include RSpec::Matchers
|
24
|
+
config.mock_with :rspec
|
19
25
|
end
|
20
|
-
|
21
|
-
Rspec.configure do |config|
|
22
|
-
require 'rspec/expectations'
|
23
|
-
config.include Rspec::Matchers
|
24
|
-
config.mock_with :rspec
|
25
|
-
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sequel_oracle_extensions
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
5
|
-
prerelease:
|
4
|
+
hash: 13
|
5
|
+
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 5
|
9
|
-
-
|
10
|
-
version: 0.5.
|
9
|
+
- 3
|
10
|
+
version: 0.5.3
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Joe Khoobyar
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-08-
|
18
|
+
date: 2011-08-17 00:00:00 -04:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -105,9 +105,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
105
105
|
requirements: []
|
106
106
|
|
107
107
|
rubyforge_project:
|
108
|
-
rubygems_version: 1.
|
108
|
+
rubygems_version: 1.3.7
|
109
109
|
signing_key:
|
110
110
|
specification_version: 3
|
111
111
|
summary: Oracle MERGE, optimizer hints, an schema extensions for Sequel
|
112
|
-
test_files:
|
113
|
-
|
112
|
+
test_files:
|
113
|
+
- spec/sequel/oracle_extensions/hints_spec.rb
|
114
|
+
- spec/sequel/oracle_extensions/merge_spec.rb
|
115
|
+
- spec/spec_helper.rb
|