staq-activerecord-postgresql-citext 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/.rspec +2 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +43 -0
- data/Rakefile +32 -0
- data/activerecord-postgresql-citext.gemspec +26 -0
- data/lib/activerecord/postgresql/citext.rb +46 -0
- data/spec/citext_spec.rb +29 -0
- data/spec/spec_helper.rb +34 -0
- metadata +135 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 5a03209945f665c035e26e27f27165652c6143d9
|
4
|
+
data.tar.gz: cdfc658ff435668c32fa0376dabd55e7795f2a3d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: bc919dce0fd2434ae119bfa68041279010ca985fffea422d23e461b333ba1d57bee9c550304a954f61e9df53a3e52fd8b84ffd341b22d27ac627adc5b1c8513c
|
7
|
+
data.tar.gz: 8fc34305a91529e8fd0c08c3f57c98af3813632fa80d6fff969a9578128a0c0a5d6071a6b9bdc917b403770358ef7b7d6d8f12ee9d5b9b2f5abda019621438f8
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
activerecord-postgres-citext
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ruby-1.9.3-p194
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Braintree
|
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,43 @@
|
|
1
|
+
*This fork enables you to use the gem with later versions of ActiveRecord that do include citext support. We needed this to facilitate upgrading different apps in our code
|
2
|
+
base, one at a time*
|
3
|
+
|
4
|
+
# ActiveRecord support for citext
|
5
|
+
|
6
|
+
Adds support for citext to active_record
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
Add this line to your application's Gemfile:
|
11
|
+
|
12
|
+
gem 'activerecord-postgresql-citext'
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
|
16
|
+
$ bundle
|
17
|
+
|
18
|
+
Or install it yourself as:
|
19
|
+
|
20
|
+
$ gem install activerecord-postgresql-citext
|
21
|
+
|
22
|
+
## Usage
|
23
|
+
|
24
|
+
In a database migration you need to first enable `citext` as an extension, then you can create columns of type citext.
|
25
|
+
|
26
|
+
```ruby
|
27
|
+
def up
|
28
|
+
enable_extension("citext")
|
29
|
+
|
30
|
+
create_table :models, :force => true do |t|
|
31
|
+
t.citext :name
|
32
|
+
t.timestamps
|
33
|
+
end
|
34
|
+
end
|
35
|
+
```
|
36
|
+
|
37
|
+
## Contributing
|
38
|
+
|
39
|
+
1. Fork it
|
40
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
41
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
42
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
43
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
require "rspec/core/rake_task"
|
2
|
+
require "active_record"
|
3
|
+
|
4
|
+
RSpec::Core::RakeTask.new(:spec)
|
5
|
+
|
6
|
+
task :default => %w(db:do_over spec)
|
7
|
+
|
8
|
+
namespace :db do
|
9
|
+
task :create do
|
10
|
+
connection.execute "CREATE DATABASE activerecord_postgresql_citext"
|
11
|
+
end
|
12
|
+
|
13
|
+
task :drop do
|
14
|
+
connection.execute "DROP DATABASE IF EXISTS activerecord_postgresql_citext"
|
15
|
+
end
|
16
|
+
|
17
|
+
def connection
|
18
|
+
config = {
|
19
|
+
:adapter => 'postgresql',
|
20
|
+
:template => 'template0',
|
21
|
+
:schema_search_path => 'public',
|
22
|
+
:username => ENV["DB_USERNAME"] || ENV["USER"],
|
23
|
+
:password => ENV["DB_PASSWORD"],
|
24
|
+
:host => 'localhost',
|
25
|
+
:port => ENV["DB_PORT"] || 5433
|
26
|
+
}
|
27
|
+
ActiveRecord::Base.establish_connection(config.merge('database' => 'postgres', 'schema_search_path' => 'public'))
|
28
|
+
ActiveRecord::Base.connection
|
29
|
+
end
|
30
|
+
|
31
|
+
task :do_over => %w(drop create)
|
32
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "staq-activerecord-postgresql-citext"
|
7
|
+
spec.version = "0.2.0"
|
8
|
+
spec.authors = ["Braintree"]
|
9
|
+
spec.email = ["code@getbraintree.com"]
|
10
|
+
spec.description = "citext support for rails (STAQ version)"
|
11
|
+
spec.summary = "citext support for rails"
|
12
|
+
spec.homepage = "https://github.com/braintree/activerecord-postgresql-citext"
|
13
|
+
spec.license = "MIT"
|
14
|
+
|
15
|
+
spec.files = `git ls-files`.split($/)
|
16
|
+
spec.executables = []
|
17
|
+
spec.test_files = spec.files.grep(%r{^spec/})
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
|
20
|
+
spec.add_dependency "activerecord", "~> 4"
|
21
|
+
spec.add_dependency "pg"
|
22
|
+
|
23
|
+
spec.add_development_dependency "rake"
|
24
|
+
spec.add_development_dependency "rspec", "= 2.14.1"
|
25
|
+
spec.add_development_dependency "activerecord", ">= 4.0.0", "< 4.2.0"
|
26
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# Rails 4.2+ doesn't need this monkeypatch. So we only modify ActiveRecord for < 4.2
|
2
|
+
if ActiveRecord::VERSION::MAJOR < 5 && ActiveRecord::VERSION::MINOR < 2
|
3
|
+
require 'active_record/connection_adapters/postgresql_adapter'
|
4
|
+
|
5
|
+
ActiveRecord::ConnectionAdapters::TableDefinition.class_eval do
|
6
|
+
def citext(*args)
|
7
|
+
options = args.extract_options!
|
8
|
+
column(args[0], 'citext', options)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
ActiveRecord::ConnectionAdapters::Column.class_eval do
|
13
|
+
def simplified_type_with_citext_support(field_type)
|
14
|
+
if field_type == "citext"
|
15
|
+
:citext
|
16
|
+
else
|
17
|
+
simplified_type_without_citext_support(field_type)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
alias_method_chain :simplified_type, :citext_support
|
21
|
+
end
|
22
|
+
|
23
|
+
ActiveRecord::ConnectionAdapters::PostgreSQLColumn.class_eval do
|
24
|
+
def self.extract_value_from_default_with_citext_support(default)
|
25
|
+
if default =~ /\A'(.*)'::(?:citext)\z/m
|
26
|
+
$1
|
27
|
+
else
|
28
|
+
extract_value_from_default_without_citext_support(default)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
class << self
|
32
|
+
alias_method_chain :extract_value_from_default, :citext_support
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.class_eval do
|
37
|
+
def native_database_types_with_citext
|
38
|
+
native_database_types_without_citext.merge(
|
39
|
+
:citext => { :name => "citext" }
|
40
|
+
)
|
41
|
+
end
|
42
|
+
alias_method_chain :native_database_types, :citext
|
43
|
+
end
|
44
|
+
|
45
|
+
ActiveRecord::ConnectionAdapters::PostgreSQLAdapter::OID.alias_type "citext", "text"
|
46
|
+
end
|
data/spec/citext_spec.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
class Model < ActiveRecord::Base; end
|
4
|
+
|
5
|
+
describe "citext" do
|
6
|
+
before(:each) do
|
7
|
+
ActiveRecord::Schema.define do
|
8
|
+
self.verbose = false
|
9
|
+
|
10
|
+
enable_extension("citext")
|
11
|
+
|
12
|
+
create_table :models, :force => true do |t|
|
13
|
+
t.citext :name
|
14
|
+
t.timestamps
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
it "can create citext columns" do
|
20
|
+
name_column = Model.columns.detect {|c| c.name == "name"}
|
21
|
+
name_column.sql_type.should == "citext"
|
22
|
+
name_column.type.should == :citext
|
23
|
+
end
|
24
|
+
|
25
|
+
it "save citext contents as a string" do
|
26
|
+
Model.create! name: "123"
|
27
|
+
Model.first.name.should == "123"
|
28
|
+
end
|
29
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
$LOAD_PATH.unshift File.expand_path('../lib/', __FILE__)
|
2
|
+
require 'active_record'
|
3
|
+
require 'activerecord/postgresql/citext'
|
4
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
5
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
6
|
+
# Require this file using `require "spec_helper"` to ensure that it is only
|
7
|
+
# loaded once.
|
8
|
+
#
|
9
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
10
|
+
|
11
|
+
config = {
|
12
|
+
:adapter => 'postgresql',
|
13
|
+
:template => 'template0',
|
14
|
+
:schema_search_path => 'public',
|
15
|
+
:database => 'activerecord_postgresql_citext',
|
16
|
+
:username => ENV["DB_USERNAME"] || ENV["USER"],
|
17
|
+
:password => ENV["DB_PASSWORD"],
|
18
|
+
:host => 'localhost',
|
19
|
+
:port => ENV["DB_PORT"] || 5433
|
20
|
+
}
|
21
|
+
ActiveRecord::Base.establish_connection(config)
|
22
|
+
|
23
|
+
RSpec.configure do |config|
|
24
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
25
|
+
config.run_all_when_everything_filtered = true
|
26
|
+
config.filter_run :focus
|
27
|
+
config.order = 'random'
|
28
|
+
config.around(:each) do |spec|
|
29
|
+
ActiveRecord::Base.transaction do
|
30
|
+
spec.run
|
31
|
+
raise ActiveRecord::Rollback
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
metadata
ADDED
@@ -0,0 +1,135 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: staq-activerecord-postgresql-citext
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Braintree
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-02-03 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'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '4'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: pg
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 2.14.1
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 2.14.1
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: activerecord
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 4.0.0
|
76
|
+
- - "<"
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: 4.2.0
|
79
|
+
type: :development
|
80
|
+
prerelease: false
|
81
|
+
version_requirements: !ruby/object:Gem::Requirement
|
82
|
+
requirements:
|
83
|
+
- - ">="
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: 4.0.0
|
86
|
+
- - "<"
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: 4.2.0
|
89
|
+
description: citext support for rails (STAQ version)
|
90
|
+
email:
|
91
|
+
- code@getbraintree.com
|
92
|
+
executables: []
|
93
|
+
extensions: []
|
94
|
+
extra_rdoc_files: []
|
95
|
+
files:
|
96
|
+
- ".gitignore"
|
97
|
+
- ".rspec"
|
98
|
+
- ".ruby-gemset"
|
99
|
+
- ".ruby-version"
|
100
|
+
- Gemfile
|
101
|
+
- LICENSE.txt
|
102
|
+
- README.md
|
103
|
+
- Rakefile
|
104
|
+
- activerecord-postgresql-citext.gemspec
|
105
|
+
- lib/activerecord/postgresql/citext.rb
|
106
|
+
- spec/citext_spec.rb
|
107
|
+
- spec/spec_helper.rb
|
108
|
+
homepage: https://github.com/braintree/activerecord-postgresql-citext
|
109
|
+
licenses:
|
110
|
+
- MIT
|
111
|
+
metadata: {}
|
112
|
+
post_install_message:
|
113
|
+
rdoc_options: []
|
114
|
+
require_paths:
|
115
|
+
- lib
|
116
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
117
|
+
requirements:
|
118
|
+
- - ">="
|
119
|
+
- !ruby/object:Gem::Version
|
120
|
+
version: '0'
|
121
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
122
|
+
requirements:
|
123
|
+
- - ">="
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
126
|
+
requirements: []
|
127
|
+
rubyforge_project:
|
128
|
+
rubygems_version: 2.5.0
|
129
|
+
signing_key:
|
130
|
+
specification_version: 4
|
131
|
+
summary: citext support for rails
|
132
|
+
test_files:
|
133
|
+
- spec/citext_spec.rb
|
134
|
+
- spec/spec_helper.rb
|
135
|
+
has_rdoc:
|