schema_plus_enums 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.travis.yml +16 -0
- data/Gemfile +5 -0
- data/LICENSE.txt +22 -0
- data/README.md +96 -0
- data/Rakefile +9 -0
- data/gemfiles/Gemfile.base +4 -0
- data/gemfiles/activerecord-4.2/Gemfile.base +3 -0
- data/gemfiles/activerecord-4.2/Gemfile.postgresql +10 -0
- data/lib/schema_plus/enums.rb +7 -0
- data/lib/schema_plus/enums/active_record.rb +69 -0
- data/lib/schema_plus/enums/middleware.rb +22 -0
- data/lib/schema_plus/enums/version.rb +5 -0
- data/lib/schema_plus_enums.rb +1 -0
- data/schema_dev.yml +6 -0
- data/schema_plus_enums.gemspec +30 -0
- data/spec/enum_spec.rb +141 -0
- data/spec/schema_dumper_spec.rb +37 -0
- data/spec/spec_helper.rb +22 -0
- metadata +184 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ad8cf6ebb0d21c741326bdb6f5715fd4d3907724
|
4
|
+
data.tar.gz: 56da3f47d07ed577455bb955a64e4b8db2c740bd
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1447dacc6fd9173d1ea79b2ae04d0e89ca45547c63a8373e15a6f892411a0fef141bbf3d53778822d6e196651a173d63f80bee4580d16bc2f36eaeae274e2dba
|
7
|
+
data.tar.gz: bb1a5487853a8e3f92b7df41310106c27f83c06bcfd914fc5c565c44ff3517832364b62f9b9edbfc2b345bd2e5ba7fcc5fa6ed66be096308e04d66849ac26d70
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
# This file was auto-generated by the schema_dev tool, based on the data in
|
2
|
+
# ./schema_dev.yml
|
3
|
+
# Please do not edit this file; any changes will be overwritten next time
|
4
|
+
# schema_dev gets run.
|
5
|
+
---
|
6
|
+
sudo: false
|
7
|
+
rvm:
|
8
|
+
- 2.1.5
|
9
|
+
gemfile:
|
10
|
+
- gemfiles/activerecord-4.2/Gemfile.postgresql
|
11
|
+
env: POSTGRESQL_DB_USER=postgres
|
12
|
+
addons:
|
13
|
+
postgresql: '9.3'
|
14
|
+
before_script: bundle exec rake create_databases
|
15
|
+
after_script: bundle exec rake drop_databases
|
16
|
+
script: bundle exec rake travis
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 ronen barzel
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,96 @@
|
|
1
|
+
[![Gem Version](https://badge.fury.io/rb/schema_plus_enums.svg)](http://badge.fury.io/rb/schema_plus_enums)
|
2
|
+
[![Build Status](https://secure.travis-ci.org/SchemaPlus/schema_plus_enums.svg)](http://travis-ci.org/SchemaPlus/schema_plus_enums)
|
3
|
+
[![Coverage Status](https://img.shields.io/coveralls/SchemaPlus/schema_plus_enums.svg)](https://coveralls.io/r/SchemaPlus/schema_plus_enums)
|
4
|
+
[![Dependency Status](https://gemnasium.com/lomba/schema_plus_enums.svg)](https://gemnasium.com/SchemaPlus/schema_plus_enums)
|
5
|
+
|
6
|
+
# SchemaPlus::Enums
|
7
|
+
|
8
|
+
SchemaPlus::Enums provides support for enum data types in ActiveRecord. Currently the support is limited to defining enum data types, for PostgreSQL only.
|
9
|
+
|
10
|
+
|
11
|
+
SchemaPlus::Enums is part of the [SchemaPlus](https://github.com/SchemaPlus/) family of Ruby on Rails ActiveRecord extension gems.
|
12
|
+
|
13
|
+
## Installation
|
14
|
+
|
15
|
+
<!-- SCHEMA_DEV: TEMPLATE INSTALLATION - begin -->
|
16
|
+
<!-- These lines are auto-inserted from a schema_dev template -->
|
17
|
+
As usual:
|
18
|
+
|
19
|
+
```ruby
|
20
|
+
gem "schema_plus_enums" # in a Gemfile
|
21
|
+
gem.add_dependency "schema_plus_enums" # in a .gemspec
|
22
|
+
```
|
23
|
+
|
24
|
+
<!-- SCHEMA_DEV: TEMPLATE INSTALLATION - end -->
|
25
|
+
|
26
|
+
## Compatibility
|
27
|
+
|
28
|
+
SchemaPlus::Enums is tested on:
|
29
|
+
|
30
|
+
<!-- SCHEMA_DEV: MATRIX - begin -->
|
31
|
+
<!-- These lines are auto-generated by schema_dev based on schema_dev.yml -->
|
32
|
+
* ruby **2.1.5** with activerecord **4.2**, using **postgresql**
|
33
|
+
|
34
|
+
<!-- SCHEMA_DEV: MATRIX - end -->
|
35
|
+
|
36
|
+
## Usage
|
37
|
+
|
38
|
+
In a migration:
|
39
|
+
|
40
|
+
```ruby
|
41
|
+
create_enum :color, 'red', 'green', 'blue'
|
42
|
+
create_enum :color, 'cyan', 'magenta', 'yellow', 'black', schema: 'cmyk'
|
43
|
+
```
|
44
|
+
|
45
|
+
|
46
|
+
## History
|
47
|
+
|
48
|
+
* 0.1.0 - Initial release, pulled from schema_plus 1.x
|
49
|
+
|
50
|
+
## Development & Testing
|
51
|
+
|
52
|
+
Are you interested in contributing to SchemaPlus::Enums? Thanks! Please follow
|
53
|
+
the standard protocol: fork, feature branch, develop, push, and issue pull
|
54
|
+
request.
|
55
|
+
|
56
|
+
Some things to know about to help you develop and test:
|
57
|
+
|
58
|
+
<!-- SCHEMA_DEV: TEMPLATE USES SCHEMA_DEV - begin -->
|
59
|
+
<!-- These lines are auto-inserted from a schema_dev template -->
|
60
|
+
* **schema_dev**: SchemaPlus::Enums uses [schema_dev](https://github.com/SchemaPlus/schema_dev) to
|
61
|
+
facilitate running rspec tests on the matrix of ruby, activerecord, and database
|
62
|
+
versions that the gem supports, both locally and on
|
63
|
+
[travis-ci](http://travis-ci.org/SchemaPlus/schema_plus_enums)
|
64
|
+
|
65
|
+
To to run rspec locally on the full matrix, do:
|
66
|
+
|
67
|
+
$ schema_dev bundle install
|
68
|
+
$ schema_dev rspec
|
69
|
+
|
70
|
+
You can also run on just one configuration at a time; For info, see `schema_dev --help` or the [schema_dev](https://github.com/SchemaPlus/schema_dev) README.
|
71
|
+
|
72
|
+
The matrix of configurations is specified in `schema_dev.yml` in
|
73
|
+
the project root.
|
74
|
+
|
75
|
+
|
76
|
+
<!-- SCHEMA_DEV: TEMPLATE USES SCHEMA_DEV - end -->
|
77
|
+
|
78
|
+
<!-- SCHEMA_DEV: TEMPLATE USES SCHEMA_PLUS_CORE - begin -->
|
79
|
+
<!-- These lines are auto-inserted from a schema_dev template -->
|
80
|
+
* **schema_plus_core**: SchemaPlus::Enums uses the SchemaPlus::Core API that
|
81
|
+
provides middleware callback stacks to make it easy to extend
|
82
|
+
ActiveRecord's behavior. If that API is missing something you need for
|
83
|
+
your contribution, please head over to
|
84
|
+
[schema_plus_core](https://github.com/SchemaPlus/schema_plus_core) and open
|
85
|
+
an issue or pull request.
|
86
|
+
|
87
|
+
<!-- SCHEMA_DEV: TEMPLATE USES SCHEMA_PLUS_CORE - end -->
|
88
|
+
|
89
|
+
<!-- SCHEMA_DEV: TEMPLATE USES SCHEMA_MONKEY - begin -->
|
90
|
+
<!-- These lines are auto-inserted from a schema_dev template -->
|
91
|
+
* **schema_monkey**: SchemaPlus::Enums is implemented as a
|
92
|
+
[schema_monkey](https://github.com/SchemaPlus/schema_monkey) client,
|
93
|
+
using [schema_monkey](https://github.com/SchemaPlus/schema_monkey)'s
|
94
|
+
convention-based protocols for extending ActiveRecord and using middleware stacks.
|
95
|
+
|
96
|
+
<!-- SCHEMA_DEV: TEMPLATE USES SCHEMA_MONKEY - end -->
|
data/Rakefile
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
module SchemaPlus::Enums
|
2
|
+
module ActiveRecord
|
3
|
+
module ConnectionAdapters
|
4
|
+
module PostgresqlAdapter
|
5
|
+
|
6
|
+
def enums
|
7
|
+
result = query(<<-SQL)
|
8
|
+
SELECT
|
9
|
+
N.nspname AS schema_name,
|
10
|
+
T.typname AS enum_name,
|
11
|
+
E.enumlabel AS enum_label,
|
12
|
+
E.enumsortorder AS enum_sort_order
|
13
|
+
--array_agg(E.enumlabel ORDER BY enumsortorder) AS labels
|
14
|
+
FROM pg_type T
|
15
|
+
JOIN pg_enum E ON E.enumtypid = T.oid
|
16
|
+
JOIN pg_namespace N ON N.oid = T.typnamespace
|
17
|
+
ORDER BY 1, 2, 4
|
18
|
+
SQL
|
19
|
+
|
20
|
+
result.reduce([]) do |res, row|
|
21
|
+
last = res.last
|
22
|
+
if last && last[0] == row[0] && last[1] == row[1]
|
23
|
+
last[2] << row[2]
|
24
|
+
else
|
25
|
+
res << (row[0..1] << [row[2]])
|
26
|
+
end
|
27
|
+
res
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def create_enum(name, *values)
|
32
|
+
options = values.extract_options!
|
33
|
+
list = values.map { |value| escape_enum_value(value) }
|
34
|
+
execute "CREATE TYPE #{enum_name(name, options[:schema])} AS ENUM (#{list.join(',')})"
|
35
|
+
end
|
36
|
+
|
37
|
+
def alter_enum(name, value, options = {})
|
38
|
+
opts = case
|
39
|
+
when options[:before] then "BEFORE #{escape_enum_value(options[:before])}"
|
40
|
+
when options[:after] then "AFTER #{escape_enum_value(options[:after])}"
|
41
|
+
else
|
42
|
+
''
|
43
|
+
end
|
44
|
+
execute "ALTER TYPE #{enum_name(name, options[:schema])} ADD VALUE #{escape_enum_value(value)} #{opts}"
|
45
|
+
end
|
46
|
+
|
47
|
+
def drop_enum(name, options = {})
|
48
|
+
execute "DROP TYPE #{enum_name(name, options[:schema])}"
|
49
|
+
end
|
50
|
+
|
51
|
+
private
|
52
|
+
|
53
|
+
def enum_name(name, schema)
|
54
|
+
[schema || 'public', name].map { |s|
|
55
|
+
%Q{"#{s}"}
|
56
|
+
}.join('.')
|
57
|
+
end
|
58
|
+
|
59
|
+
def escape_enum_value(value)
|
60
|
+
escaped_value = value.to_s.sub("'", "''")
|
61
|
+
"'#{escaped_value}'"
|
62
|
+
end
|
63
|
+
|
64
|
+
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module SchemaPlus::Enums
|
2
|
+
module Middleware
|
3
|
+
|
4
|
+
module Dumper
|
5
|
+
module Initial
|
6
|
+
|
7
|
+
module Postgresql
|
8
|
+
|
9
|
+
def after(env)
|
10
|
+
env.connection.enums.each do |schema, name, values|
|
11
|
+
params = [name.inspect]
|
12
|
+
params << values.map(&:inspect).join(', ')
|
13
|
+
params << ":schema => #{schema.inspect}" if schema != 'public'
|
14
|
+
|
15
|
+
env.initial << "create_enum #{params.join(', ')}"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require_relative 'schema_plus/enums'
|
data/schema_dev.yml
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'schema_plus/enums/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "schema_plus_enums"
|
8
|
+
gem.version = SchemaPlus::Enums::VERSION
|
9
|
+
gem.authors = ["ronen barzel"]
|
10
|
+
gem.email = ["ronen@barzel.org"]
|
11
|
+
gem.summary = %q{Adds support for enum data types in ActiveRecord}
|
12
|
+
gem.description = %q{Adds support for enum data types in ActiveRecord}
|
13
|
+
gem.homepage = "https://github.com/SchemaPlus/schema_plus_enums"
|
14
|
+
gem.license = "MIT"
|
15
|
+
|
16
|
+
gem.files = `git ls-files -z`.split("\x0")
|
17
|
+
gem.executables = gem.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
19
|
+
gem.require_paths = ["lib"]
|
20
|
+
|
21
|
+
gem.add_dependency "activerecord", "~> 4.2"
|
22
|
+
gem.add_dependency "schema_plus_core", "~> 0.2", ">= 0.2.1"
|
23
|
+
|
24
|
+
gem.add_development_dependency "bundler", "~> 1.7"
|
25
|
+
gem.add_development_dependency "rake", "~> 10.0"
|
26
|
+
gem.add_development_dependency "rspec", "~> 3.0"
|
27
|
+
gem.add_development_dependency "schema_dev", "~> 3.3"
|
28
|
+
gem.add_development_dependency "simplecov"
|
29
|
+
gem.add_development_dependency "simplecov-gem-profile"
|
30
|
+
end
|
data/spec/enum_spec.rb
ADDED
@@ -0,0 +1,141 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
def enum_fields(name, schema = 'public')
|
4
|
+
sql = <<-SQL
|
5
|
+
SELECT array_to_string(array_agg(E.enumlabel ORDER BY enumsortorder), ' ') AS "values"
|
6
|
+
FROM pg_enum E
|
7
|
+
JOIN pg_type T ON E.enumtypid = T.oid
|
8
|
+
JOIN pg_namespace N ON N.oid = T.typnamespace
|
9
|
+
WHERE N.nspname = '#{schema}' AND T.typname = '#{name}'
|
10
|
+
GROUP BY T.oid;
|
11
|
+
SQL
|
12
|
+
|
13
|
+
data = ActiveRecord::Base.connection.select_all(sql)
|
14
|
+
return nil if data.empty?
|
15
|
+
data[0]['values'].split(' ')
|
16
|
+
end
|
17
|
+
|
18
|
+
describe 'enum', :postgresql => :only do
|
19
|
+
before(:all) do ActiveRecord::Migration.verbose = false end
|
20
|
+
|
21
|
+
let(:migration) { ActiveRecord::Migration }
|
22
|
+
|
23
|
+
describe 'enums' do
|
24
|
+
it 'should return all enums' do
|
25
|
+
begin
|
26
|
+
migration.execute 'create schema cmyk'
|
27
|
+
migration.create_enum 'color', 'red', 'green', 'blue'
|
28
|
+
migration.create_enum 'color', 'cyan', 'magenta', 'yellow', 'black', schema: 'cmyk'
|
29
|
+
|
30
|
+
expect(migration.enums).to match_array [['cmyk', 'color', %w|cyan magenta yellow black|], ['public', 'color', %w|red green blue|]]
|
31
|
+
ensure
|
32
|
+
migration.drop_enum 'color'
|
33
|
+
migration.execute 'drop schema cmyk cascade'
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
describe 'create_enum' do
|
39
|
+
it 'should create enum with given values' do
|
40
|
+
begin
|
41
|
+
migration.create_enum 'color', *%w|red green blue|
|
42
|
+
expect(enum_fields('color')).to eq(%w|red green blue|)
|
43
|
+
ensure
|
44
|
+
migration.execute 'DROP TYPE IF EXISTS color'
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'should create enum using symbols' do
|
49
|
+
begin
|
50
|
+
migration.create_enum :color, :red, :green, :blue
|
51
|
+
expect(enum_fields('color')).to eq(%w|red green blue|)
|
52
|
+
ensure
|
53
|
+
migration.execute 'DROP TYPE IF EXISTS color'
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'should create enum with schema' do
|
58
|
+
begin
|
59
|
+
migration.execute 'CREATE SCHEMA colors'
|
60
|
+
migration.create_enum 'color', *%|red green blue|, schema: 'colors'
|
61
|
+
expect(enum_fields('color', 'colors')).to eq(%w|red green blue|)
|
62
|
+
ensure
|
63
|
+
migration.execute 'DROP SCHEMA IF EXISTS colors CASCADE'
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
it 'should escape enum value' do
|
68
|
+
begin
|
69
|
+
migration.create_enum('names', "O'Neal")
|
70
|
+
expect(enum_fields('names')).to eq(["O'Neal"])
|
71
|
+
ensure
|
72
|
+
migration.execute "DROP TYPE IF EXISTS names"
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
it 'should escape schame name and enum name' do
|
77
|
+
begin
|
78
|
+
migration.execute 'CREATE SCHEMA "select"'
|
79
|
+
migration.create_enum 'where', *%|red green blue|, schema: 'select'
|
80
|
+
expect(enum_fields('where', 'select')).to eq(%w|red green blue|)
|
81
|
+
ensure
|
82
|
+
migration.execute 'DROP SCHEMA IF EXISTS "select" CASCADE'
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
end
|
87
|
+
|
88
|
+
describe 'alter_enum' do
|
89
|
+
before(:each) do migration.create_enum('color', 'red', 'green', 'blue') end
|
90
|
+
after(:each) do migration.execute 'DROP TYPE IF EXISTS color' end
|
91
|
+
|
92
|
+
it 'should add new value after all values' do
|
93
|
+
migration.alter_enum('color', 'magenta')
|
94
|
+
expect(enum_fields('color')).to eq(%w|red green blue magenta|)
|
95
|
+
end
|
96
|
+
|
97
|
+
it 'should add new value after existed' do
|
98
|
+
migration.alter_enum('color', 'magenta', after: 'red')
|
99
|
+
expect(enum_fields('color')).to eq(%w|red magenta green blue|)
|
100
|
+
end
|
101
|
+
|
102
|
+
it 'should add new value before existed' do
|
103
|
+
migration.alter_enum('color', 'magenta', before: 'green')
|
104
|
+
expect(enum_fields('color')).to eq(%w|red magenta green blue|)
|
105
|
+
end
|
106
|
+
|
107
|
+
it 'should add new value within given schema' do
|
108
|
+
begin
|
109
|
+
migration.execute 'CREATE SCHEMA colors'
|
110
|
+
migration.create_enum('color', 'red', schema: 'colors')
|
111
|
+
migration.alter_enum('color', 'green', schema: 'colors')
|
112
|
+
|
113
|
+
expect(enum_fields('color', 'colors')).to eq(%w|red green|)
|
114
|
+
ensure
|
115
|
+
migration.execute 'DROP SCHEMA colors CASCADE'
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
describe 'drop_enum' do
|
121
|
+
it 'should drop enum with given name' do
|
122
|
+
migration.execute "CREATE TYPE color AS ENUM ('red', 'blue')"
|
123
|
+
expect(enum_fields('color')).to eq(%w|red blue|)
|
124
|
+
migration.drop_enum('color')
|
125
|
+
|
126
|
+
expect(enum_fields('color')).to be_nil
|
127
|
+
end
|
128
|
+
|
129
|
+
it 'should drop enum within given name and schema' do
|
130
|
+
begin
|
131
|
+
migration.execute "CREATE SCHEMA colors; CREATE TYPE colors.color AS ENUM ('red', 'blue')"
|
132
|
+
expect(enum_fields('color', 'colors')).to eq(%w|red blue|)
|
133
|
+
migration.drop_enum('color', schema: 'colors')
|
134
|
+
|
135
|
+
expect(enum_fields('color', 'colors')).to be_nil
|
136
|
+
ensure
|
137
|
+
migration.execute "DROP SCHEMA colors CASCADE"
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'stringio'
|
3
|
+
|
4
|
+
describe "Schema dump" do
|
5
|
+
|
6
|
+
context 'with enum', :postgresql => :only do
|
7
|
+
let(:connection) { ActiveRecord::Base.connection }
|
8
|
+
|
9
|
+
it 'should include enum' do
|
10
|
+
begin
|
11
|
+
connection.execute "CREATE TYPE color AS ENUM ('red', 'green', 'blue')"
|
12
|
+
expect(dump_schema).to match(%r{create_enum "color", "red", "green", "blue"})
|
13
|
+
ensure
|
14
|
+
connection.execute "DROP TYPE color"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'should include enum with schema' do
|
19
|
+
begin
|
20
|
+
connection.execute "CREATE SCHEMA cmyk; CREATE TYPE cmyk.color AS ENUM ('cyan', 'magenta', 'yellow', 'black')"
|
21
|
+
expect(dump_schema).to match(%r{create_enum "color", "cyan", "magenta", "yellow", "black", :schema => "cmyk"})
|
22
|
+
ensure
|
23
|
+
connection.execute "DROP SCHEMA cmyk CASCADE"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
protected
|
29
|
+
|
30
|
+
def dump_schema(opts={})
|
31
|
+
stream = StringIO.new
|
32
|
+
ActiveRecord::SchemaDumper.ignore_tables = Array.wrap(opts[:ignore]) || []
|
33
|
+
ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection, stream)
|
34
|
+
stream.string
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'simplecov'
|
2
|
+
require 'simplecov-gem-profile'
|
3
|
+
SimpleCov.start "gem"
|
4
|
+
|
5
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
6
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
7
|
+
|
8
|
+
require 'rspec'
|
9
|
+
require 'active_record'
|
10
|
+
require 'schema_plus_enums'
|
11
|
+
require 'schema_dev/rspec'
|
12
|
+
|
13
|
+
SchemaDev::Rspec.setup
|
14
|
+
|
15
|
+
Dir[File.dirname(__FILE__) + "/support/**/*.rb"].each {|f| require f}
|
16
|
+
|
17
|
+
RSpec.configure do |config|
|
18
|
+
config.warnings = true
|
19
|
+
end
|
20
|
+
|
21
|
+
SimpleCov.command_name "[ruby #{RUBY_VERSION} - ActiveRecord #{::ActiveRecord::VERSION::STRING} - #{ActiveRecord::Base.connection.adapter_name}]"
|
22
|
+
|
metadata
ADDED
@@ -0,0 +1,184 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: schema_plus_enums
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- ronen barzel
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-03-13 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activerecord
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '4.2'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '4.2'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: schema_plus_core
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0.2'
|
34
|
+
- - ">="
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: 0.2.1
|
37
|
+
type: :runtime
|
38
|
+
prerelease: false
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - "~>"
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0.2'
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: 0.2.1
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: bundler
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - "~>"
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '1.7'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - "~>"
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '1.7'
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: rake
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - "~>"
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '10.0'
|
68
|
+
type: :development
|
69
|
+
prerelease: false
|
70
|
+
version_requirements: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - "~>"
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '10.0'
|
75
|
+
- !ruby/object:Gem::Dependency
|
76
|
+
name: rspec
|
77
|
+
requirement: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - "~>"
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '3.0'
|
82
|
+
type: :development
|
83
|
+
prerelease: false
|
84
|
+
version_requirements: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - "~>"
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '3.0'
|
89
|
+
- !ruby/object:Gem::Dependency
|
90
|
+
name: schema_dev
|
91
|
+
requirement: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - "~>"
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '3.3'
|
96
|
+
type: :development
|
97
|
+
prerelease: false
|
98
|
+
version_requirements: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - "~>"
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '3.3'
|
103
|
+
- !ruby/object:Gem::Dependency
|
104
|
+
name: simplecov
|
105
|
+
requirement: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - ">="
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
type: :development
|
111
|
+
prerelease: false
|
112
|
+
version_requirements: !ruby/object:Gem::Requirement
|
113
|
+
requirements:
|
114
|
+
- - ">="
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: '0'
|
117
|
+
- !ruby/object:Gem::Dependency
|
118
|
+
name: simplecov-gem-profile
|
119
|
+
requirement: !ruby/object:Gem::Requirement
|
120
|
+
requirements:
|
121
|
+
- - ">="
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
version: '0'
|
124
|
+
type: :development
|
125
|
+
prerelease: false
|
126
|
+
version_requirements: !ruby/object:Gem::Requirement
|
127
|
+
requirements:
|
128
|
+
- - ">="
|
129
|
+
- !ruby/object:Gem::Version
|
130
|
+
version: '0'
|
131
|
+
description: Adds support for enum data types in ActiveRecord
|
132
|
+
email:
|
133
|
+
- ronen@barzel.org
|
134
|
+
executables: []
|
135
|
+
extensions: []
|
136
|
+
extra_rdoc_files: []
|
137
|
+
files:
|
138
|
+
- ".gitignore"
|
139
|
+
- ".travis.yml"
|
140
|
+
- Gemfile
|
141
|
+
- LICENSE.txt
|
142
|
+
- README.md
|
143
|
+
- Rakefile
|
144
|
+
- gemfiles/Gemfile.base
|
145
|
+
- gemfiles/activerecord-4.2/Gemfile.base
|
146
|
+
- gemfiles/activerecord-4.2/Gemfile.postgresql
|
147
|
+
- lib/schema_plus/enums.rb
|
148
|
+
- lib/schema_plus/enums/active_record.rb
|
149
|
+
- lib/schema_plus/enums/middleware.rb
|
150
|
+
- lib/schema_plus/enums/version.rb
|
151
|
+
- lib/schema_plus_enums.rb
|
152
|
+
- schema_dev.yml
|
153
|
+
- schema_plus_enums.gemspec
|
154
|
+
- spec/enum_spec.rb
|
155
|
+
- spec/schema_dumper_spec.rb
|
156
|
+
- spec/spec_helper.rb
|
157
|
+
homepage: https://github.com/SchemaPlus/schema_plus_enums
|
158
|
+
licenses:
|
159
|
+
- MIT
|
160
|
+
metadata: {}
|
161
|
+
post_install_message:
|
162
|
+
rdoc_options: []
|
163
|
+
require_paths:
|
164
|
+
- lib
|
165
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
166
|
+
requirements:
|
167
|
+
- - ">="
|
168
|
+
- !ruby/object:Gem::Version
|
169
|
+
version: '0'
|
170
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
171
|
+
requirements:
|
172
|
+
- - ">="
|
173
|
+
- !ruby/object:Gem::Version
|
174
|
+
version: '0'
|
175
|
+
requirements: []
|
176
|
+
rubyforge_project:
|
177
|
+
rubygems_version: 2.2.2
|
178
|
+
signing_key:
|
179
|
+
specification_version: 4
|
180
|
+
summary: Adds support for enum data types in ActiveRecord
|
181
|
+
test_files:
|
182
|
+
- spec/enum_spec.rb
|
183
|
+
- spec/schema_dumper_spec.rb
|
184
|
+
- spec/spec_helper.rb
|