dumbo 0.0.1 → 0.0.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.
Files changed (56) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/Gemfile +1 -1
  4. data/bin/dumbo +65 -24
  5. data/config/boot.rb +2 -3
  6. data/dumbo.gemspec +1 -2
  7. data/lib/dumbo.rb +17 -16
  8. data/lib/dumbo/aggregate.rb +3 -5
  9. data/lib/dumbo/base_type.rb +17 -17
  10. data/lib/dumbo/binding_loader.rb +50 -0
  11. data/lib/dumbo/cast.rb +5 -5
  12. data/lib/dumbo/composite_type.rb +4 -4
  13. data/lib/dumbo/db_task.rb +6 -5
  14. data/lib/dumbo/dependency_resolver.rb +17 -18
  15. data/lib/dumbo/enum_type.rb +3 -4
  16. data/lib/dumbo/extension.rb +64 -20
  17. data/lib/dumbo/extension_migrator.rb +11 -11
  18. data/lib/dumbo/extension_version.rb +29 -11
  19. data/lib/dumbo/function.rb +21 -21
  20. data/lib/dumbo/operator.rb +4 -6
  21. data/lib/dumbo/pg_object.rb +17 -21
  22. data/lib/dumbo/rake_task.rb +63 -53
  23. data/lib/dumbo/range_type.rb +6 -9
  24. data/lib/dumbo/test.rb +8 -0
  25. data/lib/dumbo/test/fixture.rb +51 -0
  26. data/lib/dumbo/test/helper.rb +64 -0
  27. data/lib/dumbo/test/matchers.rb +76 -0
  28. data/lib/dumbo/test/regression_helper.rb +20 -0
  29. data/lib/dumbo/test/silence_unknown_oid.rb +12 -0
  30. data/lib/dumbo/type.rb +3 -4
  31. data/lib/dumbo/version.rb +1 -1
  32. data/spec/aggregate_spec.rb +9 -10
  33. data/spec/cast_spec.rb +5 -5
  34. data/spec/{Makefile → dumbo_sample/Makefile} +4 -0
  35. data/spec/{dumbo_sample--0.0.1.sql → dumbo_sample/dumbo_sample--0.0.1.sql} +0 -0
  36. data/spec/{dumbo_sample--0.0.2.sql → dumbo_sample/dumbo_sample--0.0.2.sql} +0 -0
  37. data/spec/dumbo_sample/dumbo_sample--0.0.3.sql +7 -0
  38. data/spec/dumbo_sample/dumbo_sample--0.0.4.sql +13 -0
  39. data/spec/{dumbo_sample.control → dumbo_sample/dumbo_sample.control} +0 -0
  40. data/spec/dumbo_sample/src/dumbo_sample.c +13 -0
  41. data/spec/dumbo_sample/src/dumbo_sample.h +17 -0
  42. data/spec/extension_migrator_spec.rb +12 -11
  43. data/spec/extension_spec.rb +41 -12
  44. data/spec/extension_version_spec.rb +27 -0
  45. data/spec/operator_spec.rb +6 -7
  46. data/spec/spec_helper.rb +15 -9
  47. data/spec/support/extension_helper.rb +31 -0
  48. data/spec/support/silence_unknown_oid.rb +12 -0
  49. data/spec/type_spec.rb +59 -55
  50. data/template/Rakefile +6 -6
  51. data/template/spec/sample_spec.rb.erb +1 -1
  52. metadata +33 -31
  53. data/config/database.yml +0 -31
  54. data/lib/tasks/db.rake +0 -52
  55. data/lib/tasks/dumbo.rake +0 -23
  56. data/spec/support/sql_helper.rb +0 -23
@@ -1,6 +1,6 @@
1
1
  module Dumbo
2
2
  class Type < PgObject
3
- attr_accessor :name, :type, :typrelid
3
+ attr_accessor :name, :type, :typrelid
4
4
  identfied_by :name
5
5
 
6
6
  def load_attributes
@@ -24,8 +24,7 @@ module Dumbo
24
24
  end
25
25
 
26
26
  def drop
27
- "DROP TYPE #{name}"
27
+ "DROP TYPE #{name};"
28
28
  end
29
-
30
29
  end
31
- end
30
+ end
@@ -1,3 +1,3 @@
1
1
  module Dumbo
2
- VERSION = "0.0.1"
2
+ VERSION = '0.0.3'
3
3
  end
@@ -1,24 +1,23 @@
1
1
  require 'spec_helper'
2
2
  describe Dumbo::Aggregate do
3
3
  let(:avg) do
4
- oid = sql("SELECT p.oid
4
+ oid = query("SELECT p.oid
5
5
  FROM pg_proc p
6
6
  JOIN pg_aggregate ag ON p.oid = ag.aggfnoid
7
- WHERE proname='avg' AND pg_get_function_arguments(p.oid) = 'integer'",'oid').first
7
+ WHERE proname='avg' AND pg_get_function_arguments(p.oid) = 'integer'").first['oid']
8
8
  Dumbo::Aggregate.new(oid)
9
9
  end
10
10
 
11
11
  let(:min) do
12
- oid = sql("SELECT p.oid
12
+ oid = query("SELECT p.oid
13
13
  FROM pg_proc p
14
14
  JOIN pg_aggregate ag ON p.oid = ag.aggfnoid
15
- WHERE proname='min' AND pg_get_function_arguments(p.oid) = 'integer'",'oid').first
15
+ WHERE proname='min' AND pg_get_function_arguments(p.oid) = 'integer'").first['oid']
16
16
  Dumbo::Aggregate.new(oid)
17
17
  end
18
18
 
19
-
20
- it "avg should have a sql representation" do
21
- avg.to_sql.should eq <<-SQL.gsub(/^ {6}/, '')
19
+ it 'avg should have a sql representation' do
20
+ expect(avg.to_sql).to eq <<-SQL.gsub(/^ {6}/, '')
22
21
  CREATE AGGREGATE avg(integer) (
23
22
  SFUNC = int4_avg_accum,
24
23
  STYPE = int8[],
@@ -28,8 +27,8 @@ describe Dumbo::Aggregate do
28
27
  SQL
29
28
  end
30
29
 
31
- it "min should have a sql representation" do
32
- min.to_sql.should eq <<-SQL.gsub(/^ {6}/, '')
30
+ it 'min should have a sql representation' do
31
+ expect(min.to_sql).to eq <<-SQL.gsub(/^ {6}/, '')
33
32
  CREATE AGGREGATE min(integer) (
34
33
  SFUNC = int4smaller,
35
34
  STYPE = int4,
@@ -38,4 +37,4 @@ describe Dumbo::Aggregate do
38
37
  SQL
39
38
  end
40
39
 
41
- end
40
+ end
@@ -1,20 +1,20 @@
1
1
  require 'spec_helper'
2
2
  describe Dumbo::Cast do
3
3
  let(:cast) do
4
- oid = sql("SELECT ca.oid
4
+ oid = query("SELECT ca.oid
5
5
  FROM pg_cast ca
6
6
  JOIN pg_type st ON st.oid=castsource
7
7
  JOIN pg_type tt ON tt.oid=casttarget
8
8
  WHERE format_type(st.oid,NULL) = 'bigint'
9
- AND format_type(tt.oid,tt.typtypmod) = 'integer';",'oid').first
9
+ AND format_type(tt.oid,tt.typtypmod) = 'integer';").first['oid']
10
10
  Dumbo::Cast.new(oid)
11
11
  end
12
12
 
13
- it "should have a sql representation" do
14
- cast.to_sql.should eq <<-SQL.gsub(/^ {6}/, '')
13
+ it 'should have a sql representation' do
14
+ expect(cast.to_sql).to eq <<-SQL.gsub(/^ {6}/, '')
15
15
  CREATE CAST (bigint AS integer)
16
16
  WITH FUNCTION int4(bigint)
17
17
  AS ASSIGNMENT;
18
18
  SQL
19
19
  end
20
- end
20
+ end
@@ -2,5 +2,9 @@
2
2
  EXTENSION = dumbo_sample
3
3
  PG_CONFIG ?= pg_config
4
4
  DATA = $(wildcard *--*.sql)
5
+
6
+ MODULE_big = dumbo_sample
7
+ OBJS = src/dumbo_sample.o
8
+
5
9
  PGXS := $(shell $(PG_CONFIG) --pgxs)
6
10
  include $(PGXS)
@@ -0,0 +1,7 @@
1
+ -- Testing Composite, Range, Enum Types handling.
2
+
3
+ CREATE TYPE elephant_composite AS (weight integer, name text);
4
+
5
+ CREATE TYPE elephant_range AS RANGE (subtype = float8, subtype_diff = float8mi);
6
+
7
+ CREATE TYPE elephant_enum AS ENUM ('infant', 'child', 'adult');
@@ -0,0 +1,13 @@
1
+ -- Testing Base Types handling.
2
+ CREATE TYPE elephant_base;
3
+
4
+ CREATE FUNCTION elephant_in(cstring) RETURNS elephant_base AS
5
+ '$libdir/dumbo_sample' LANGUAGE C;
6
+
7
+ CREATE FUNCTION elephant_out(elephant_base) RETURNS cstring AS
8
+ '$libdir/dumbo_sample' LANGUAGE C;
9
+
10
+ CREATE TYPE elephant_base (
11
+ INPUT = elephant_in,
12
+ OUTPUT = elephant_out
13
+ );
@@ -0,0 +1,13 @@
1
+ #include "dumbo_sample.h"
2
+
3
+ Datum elephant_in(PG_FUNCTION_ARGS)
4
+ {
5
+ int *result = palloc0(sizeof(int));
6
+ PG_RETURN_POINTER(result);
7
+ }
8
+
9
+ Datum elephant_out(PG_FUNCTION_ARGS)
10
+ {
11
+ char *result = palloc0(sizeof(char));
12
+ PG_RETURN_POINTER(result);
13
+ }
@@ -0,0 +1,17 @@
1
+ #ifndef _DUMBO_SAMPLE_H
2
+ #define _DUMBO_SAMPLE_H
3
+
4
+ #include "postgres.h"
5
+ #include "fmgr.h"
6
+
7
+ #ifdef PG_MODULE_MAGIC
8
+ PG_MODULE_MAGIC;
9
+ #endif
10
+
11
+ PG_FUNCTION_INFO_V1(elephant_in);
12
+ PG_FUNCTION_INFO_V1(elephant_out);
13
+
14
+ Datum elephant_in(PG_FUNCTION_ARGS);
15
+ Datum elephant_out(PG_FUNCTION_ARGS);
16
+
17
+ #endif
@@ -1,15 +1,16 @@
1
+ require 'spec_helper'
2
+
1
3
  describe Dumbo::ExtensionMigrator do
2
- before(:all) do
3
- system('cd spec && make clean && make && make install')
4
- end
5
- after (:all) do
6
- system('cd spec && make clean && make uninstall')
4
+ around(:each) do |example|
5
+ install_testing_extension
6
+ example.run
7
+ uninstall_testing_extension
7
8
  end
8
9
 
9
- let(:migrator){Dumbo::ExtensionMigrator.new('dumbo_sample','0.0.1','0.0.2')}
10
+ let(:migrator) { Dumbo::ExtensionMigrator.new('dumbo_sample', '0.0.1', '0.0.2') }
10
11
 
11
- it "should provide upgrade sql" do
12
- migrator.upgrade.should eq <<-SQL.gsub(/^ {4}/, '')
12
+ it 'should provide upgrade sql' do
13
+ expect(migrator.upgrade).to eq <<-SQL.gsub(/^ {4}/, '')
13
14
  ----functions----
14
15
  CREATE OR REPLACE FUNCTION foo(integer)
15
16
  RETURNS integer
@@ -23,8 +24,8 @@ describe Dumbo::ExtensionMigrator do
23
24
  SQL
24
25
  end
25
26
 
26
- it "should provide downgrade sql" do
27
- migrator.downgrade.should eq <<-SQL.gsub(/^ {4}/, '')
27
+ it 'should provide downgrade sql' do
28
+ expect(migrator.downgrade).to eq <<-SQL.gsub(/^ {4}/, '')
28
29
  ----functions----
29
30
  CREATE OR REPLACE FUNCTION foo(integer)
30
31
  RETURNS integer
@@ -37,4 +38,4 @@ describe Dumbo::ExtensionMigrator do
37
38
  $function$
38
39
  SQL
39
40
  end
40
- end
41
+ end
@@ -1,19 +1,48 @@
1
1
  require 'spec_helper'
2
+ include ExtensionHelper
2
3
  describe Dumbo::Extension do
3
- let(:extension){Dumbo::Extension.new('hstore','1.1')}
4
- before(:all) do
5
- Dumbo::Extension.new('hstore','1.1').install
6
- end
4
+ describe 'extension setup' do
5
+ let(:extension) { described_class.new('dumbo_sample', '0.0.3') }
7
6
 
8
- it "should return extension obj_id" do
9
- extension.obj_id.should ~ /\d+/
10
- end
7
+ around(:each) do |example|
8
+ install_testing_extension
9
+ extension.create
10
+ example.run
11
+ uninstall_testing_extension
12
+ end
13
+
14
+ it 'should return extension obj_id' do
15
+ expect(extension.obj_id).to match /\d+/
16
+ end
17
+
18
+ it 'should return a list of objects' do
19
+ expect(extension.objects.size).to be 5
20
+ end
21
+
22
+ describe 'handling types' do
23
+ let(:names) { %w(elephant_composite elephant_range elephant_enum) }
11
24
 
12
- it 'should return a list of objects' do
13
- extension.objects.size.should eq 86
25
+ let(:classes) { [Dumbo::EnumType, Dumbo::CompositeType, Dumbo::RangeType] }
26
+
27
+ subject { extension.types }
28
+
29
+ it { expect(subject.map(&:class)).to match_array classes }
30
+ it { expect(subject.map(&:name)).to match_array names }
31
+ end
14
32
  end
15
33
 
16
- it 'should return a list of types' do
17
- extension.types.select{|t| t.name == 'hstore'}.should_not be_empty
34
+ describe '#versions' do
35
+ let(:releases) do
36
+ ['ext--abc.sql', 'ext--0.10.7.sql', 'ext--0.11.0.sql',
37
+ 'ext--1.0.0.sql', 'ext--0.12.sql', 'ext--0.10.5.sql']
38
+ end
39
+
40
+ before do
41
+ expect_any_instance_of(described_class).to receive(:releases){releases}
42
+ end
43
+
44
+ subject { described_class.new.versions.map(&:to_s) }
45
+
46
+ it { is_expected.to match_array ['0.10.5', '0.10.7', '0.11.0', '0.12', '1.0.0'] }
18
47
  end
19
- end
48
+ end
@@ -0,0 +1,27 @@
1
+ require 'spec_helper'
2
+ describe Dumbo::ExtensionVersion do
3
+ context 'handling full version levels' do
4
+ let(:version) { described_class.new(0, 1, 11) }
5
+
6
+ it { expect(version.to_s).to eq '0.1.11' }
7
+
8
+ it { expect(version.bump(:patch).to_s).to eq '0.1.12' }
9
+ it { expect(version.bump(:minor).to_s).to eq '0.2.0' }
10
+ it { expect(version.bump(:major).to_s).to eq '1.0.0' }
11
+
12
+ it { expect(version).to be < version.bump(:patch) }
13
+
14
+ it { expect(version.bump(:patch)).to be < version.bump(:minor) }
15
+ it { expect(version.bump(:patch)).to be < version.bump(:major) }
16
+ it { expect(version.bump(:minor)).to be < version.bump(:major) }
17
+ end
18
+
19
+ context 'handling incomplete version levels' do
20
+ let(:version) { described_class.new(0, 1) }
21
+
22
+ it { expect(version.to_s).to eq '0.1' }
23
+
24
+ it { expect(version.bump(:patch).to_s).to eq '0.1.1' }
25
+ it { expect(version.bump(:minor).to_s).to eq '0.2.0' }
26
+ end
27
+ end
@@ -1,12 +1,12 @@
1
1
  require 'spec_helper'
2
2
  describe Dumbo::Operator do
3
3
  let(:operator) do
4
- oid = sql("SELECT oid FROM pg_operator WHERE oprname = '&&' AND format_type(oprleft,NULL) = 'box' AND format_type(oprright,NULL) ='box'",'oid').first
4
+ oid = query("SELECT oid FROM pg_operator WHERE oprname = '&&' AND format_type(oprleft,NULL) = 'box' AND format_type(oprright,NULL) ='box'").first['oid']
5
5
  Dumbo::Operator.new(oid).get
6
6
  end
7
7
 
8
- it "should have a sql representation" do
9
- operator.to_sql.should eq <<-SQL.gsub(/^ {4}/, '')
8
+ it 'should have a sql representation' do
9
+ expect(operator.to_sql).to eq <<-SQL.gsub(/^ {4}/, '')
10
10
  CREATE OPERATOR && (
11
11
  PROCEDURE = box_overlap,
12
12
  LEFTARG = box,
@@ -19,11 +19,11 @@ describe Dumbo::Operator do
19
19
  end
20
20
 
21
21
  it 'should have a uniq identfier' do
22
- operator.identify.should eq ['&&', 'box', 'box']
22
+ expect(operator.identify).to eq ['&&', 'box', 'box']
23
23
  end
24
24
 
25
25
  it 'should have upgrade sql' do
26
- operator.upgrade(nil).should eq <<-SQL.gsub(/^ {4}/, '')
26
+ expect(operator.upgrade(nil)).to eq <<-SQL.gsub(/^ {4}/, '')
27
27
  CREATE OPERATOR && (
28
28
  PROCEDURE = box_overlap,
29
29
  LEFTARG = box,
@@ -36,7 +36,6 @@ describe Dumbo::Operator do
36
36
  end
37
37
 
38
38
  it 'should have downgrade sql' do
39
- operator.downgrade(nil).should eq "DROP OPERATOR &&;"
39
+ expect(operator.downgrade(nil)).to eq 'DROP OPERATOR &&;'
40
40
  end
41
41
  end
42
-
@@ -1,28 +1,34 @@
1
1
  require 'rubygems'
2
- require 'factory_girl'
2
+ require 'dumbo/test'
3
3
 
4
4
  ENV['DUMBO_ENV'] ||= 'test'
5
5
  require File.expand_path('../../config/boot', __FILE__)
6
6
 
7
+ require 'dumbo/test/silence_unknown_oid'
8
+
7
9
  ActiveRecord::Base.logger.level = 0 if ActiveRecord::Base.logger
8
10
 
9
- Dir.glob("spec/support/**/*.rb").each { |f| require f }
11
+ Dir.glob('spec/support/**/*.rb').each { |f| require f }
10
12
 
11
13
  RSpec.configure do |config|
12
14
  config.fail_fast = false
13
- config.order = "random"
14
- config.treat_symbols_as_metadata_keys_with_true_values = true
15
- config.include FactoryGirl::Syntax::Methods
15
+ config.order = 'random'
16
16
  config.filter_run focus: true
17
17
  config.run_all_when_everything_filtered = true
18
+ config.expect_with :rspec do |c|
19
+ c.syntax = [:should, :expect]
20
+ end
18
21
 
19
22
  # wrap test in transactions
20
23
  config.around(:each) do |example|
21
- ActiveRecord::Base.transaction do
24
+ ActiveRecord::Base.transaction do
22
25
  example.run
23
- raise ActiveRecord::Rollback
24
- end
26
+ fail ActiveRecord::Rollback
27
+ end
25
28
  end
26
29
 
27
- config.include(SqlHelper)
30
+ config.include(Dumbo::Test::Helper)
31
+ config.include(Dumbo::Matchers)
28
32
  end
33
+
34
+ require 'dumbo/test/regression_helper' if ENV['DUMBO_REGRESSION']
@@ -0,0 +1,31 @@
1
+ module ExtensionHelper
2
+ def install_testing_extension
3
+ system <<-CMD
4
+ (
5
+ mkdir -p #{spec_root}/dumbo_sample_runtime && \
6
+ cp -R #{spec_root}/dumbo_sample/ #{spec_root}/dumbo_sample_runtime
7
+ cd #{spec_root}/dumbo_sample_runtime && \
8
+ make clean && \
9
+ make && \
10
+ make install
11
+ ) 1> /dev/null
12
+ CMD
13
+ end
14
+
15
+ def uninstall_testing_extension
16
+ system <<-CMD
17
+ (
18
+ cd #{spec_root}/dumbo_sample_runtime && \
19
+ make clean && \
20
+ make uninstall && \
21
+ rm -rf #{spec_root}/dumbo_sample_runtime
22
+ ) 1> /dev/null
23
+ CMD
24
+ end
25
+
26
+ private
27
+
28
+ def spec_root
29
+ File.join(File.dirname(__FILE__), '..')
30
+ end
31
+ end
@@ -0,0 +1,12 @@
1
+ module ActiveRecord
2
+ module ConnectionAdapters
3
+ class PostgreSQLAdapter
4
+ module DatabaseStatements
5
+ def warn(msg)
6
+ return if msg =~ /^unknown OID/
7
+ super
8
+ end
9
+ end
10
+ end
11
+ end
12
+ end
@@ -1,64 +1,76 @@
1
1
  require 'spec_helper'
2
+
2
3
  describe Dumbo::Type do
4
+ around(:each) do |example|
5
+ install_testing_extension
6
+ extension.create
7
+ example.run
8
+ uninstall_testing_extension
9
+ end
10
+
11
+ let(:version) { '0.0.3' }
12
+
13
+ let(:extension) { Dumbo::Extension.new('dumbo_sample', version) }
14
+
15
+ let(:type) do
16
+ oid = query("SELECT oid FROM pg_type WHERE typname = '#{type_name}'").first['oid']
17
+ Dumbo::Type.new(oid).get
18
+ end
19
+
20
+ shared_examples_for 'identifiable' do
21
+ subject { type.identify }
22
+
23
+ it { should eq [type_name] }
24
+ end
25
+
3
26
  describe 'Base Type' do
4
- let(:type) do
5
- extension = Dumbo::Extension.new('hstore','1.1')
6
- extension.install
7
- extension.types.select{|t| t.name =='hstore'}.first
8
- end
9
- it "should have a sql representation" do
10
- type.to_sql.should eq <<-SQL.gsub(/^ {6}/, '')
11
- CREATE TYPE hstore(
12
- INPUT=hstore_in,
13
- OUTPUT=hstore_out,
14
- RECEIVE=hstore_recv,
15
- SEND=hstore_send,
27
+ let(:version) { '0.0.4' }
28
+
29
+ let(:type_name) { 'elephant_base' }
30
+
31
+ let(:type) { extension.types.select { |t| t.name == type_name }.first }
32
+
33
+ it 'should have a sql representation' do
34
+ expect(type.to_sql).to eq <<-SQL.gsub(/^ {6}/, '')
35
+ CREATE TYPE elephant_base(
36
+ INPUT=elephant_in,
37
+ OUTPUT=elephant_out,
38
+ RECEIVE=-,
39
+ SEND=-,
16
40
  ANALYZE=-,
17
41
  CATEGORY='U',
18
42
  DEFAULT='',
19
43
  INTERNALLENGTH=-1,
20
44
  ALIGNMENT=int,
21
- STORAGE=EXTENDED
45
+ STORAGE=PLAIN
22
46
  );
23
47
  SQL
24
48
  end
25
49
 
26
- it 'should have a uniq identfier' do
27
- type.identify.should eq ['hstore']
28
- end
50
+ it_should_behave_like 'identifiable'
29
51
  end
30
52
 
31
53
  describe 'Composite Type' do
32
- let(:type) do
33
- sql "CREATE TYPE compfoo AS (f1 int, f2 text);"
34
- oid = sql("SELECT oid FROM pg_type where typname = 'compfoo'",'oid').first
35
- Dumbo::Type.new(oid).get
36
- end
54
+ let(:type_name) { 'elephant_composite' }
37
55
 
38
- it "should have a sql representation" do
39
- type.to_sql.should eq <<-SQL.gsub(/^ {6}/, '')
40
- CREATE TYPE compfoo AS (
41
- f1 integer,
42
- f2 text
56
+ it 'should have a sql representation' do
57
+ expect(type.to_sql).to eq <<-SQL.gsub(/^ {6}/, '')
58
+ CREATE TYPE elephant_composite AS (
59
+ weight integer,
60
+ name text
43
61
  );
44
62
  SQL
45
63
  end
46
64
 
47
- it 'should have a uniq identfier' do
48
- type.identify.should eq ['compfoo']
49
- end
65
+ it_should_behave_like 'identifiable'
50
66
  end
51
67
 
52
68
  describe 'Range Type' do
53
- let(:type) do
54
- sql "CREATE TYPE float8_range AS RANGE (subtype = float8, subtype_diff = float8mi);"
55
- oid = sql("SELECT oid FROM pg_type where typname = 'float8_range'",'oid').first
56
- Dumbo::Type.new(oid).get
57
- end
69
+ let(:type_name) { 'elephant_range' }
58
70
 
59
- it "should have a sql representation" do
60
- type.to_sql.should eq <<-SQL.gsub(/^ {6}/, '')
61
- CREATE TYPE float8_range AS RANGE (
71
+ it 'should have a sql representation' do
72
+ expect(type.to_sql).to eq <<-SQL.gsub(/^ {6}/, '')
73
+ CREATE TYPE elephant_range AS RANGE (
62
74
  SUBTYPE=float8,
63
75
  SUBTYPE_OPCLASS=float8_ops,
64
76
  SUBTYPE_DIFF=float8mi
@@ -66,30 +78,22 @@ describe Dumbo::Type do
66
78
  SQL
67
79
  end
68
80
 
69
- it 'should have a uniq identfier' do
70
- type.identify.should eq ['float8_range']
71
- end
81
+ it_should_behave_like 'identifiable'
72
82
  end
73
83
 
74
84
  describe 'Enum Type' do
75
- let(:type) do
76
- sql "CREATE TYPE bug_status AS ENUM ('new', 'open', 'closed');"
77
- oid = sql("SELECT oid FROM pg_type where typname = 'bug_status'",'oid').first
78
- Dumbo::Type.new(oid).get
79
- end
85
+ let(:type_name) { 'elephant_enum' }
80
86
 
81
- it "should have a sql representation" do
82
- type.to_sql.should eq <<-SQL.gsub(/^ {6}/, '')
83
- CREATE TYPE bug_status AS ENUM (
84
- 'new',
85
- 'open',
86
- 'closed'
87
+ it 'should have a sql representation' do
88
+ expect(type.to_sql).to eq <<-SQL.gsub(/^ {6}/, '')
89
+ CREATE TYPE elephant_enum AS ENUM (
90
+ 'infant',
91
+ 'child',
92
+ 'adult'
87
93
  );
88
94
  SQL
89
95
  end
90
96
 
91
- it 'should have a uniq identfier' do
92
- type.identify.should eq ['bug_status']
93
- end
97
+ it_should_behave_like 'identifiable'
94
98
  end
95
- end
99
+ end