activerecord-postgres-json 0.1.2 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +28 -0
- data/Gemfile +6 -2
- data/README.md +5 -4
- data/VERSION +1 -1
- data/activerecord-postgres-json.gemspec +18 -12
- data/lib/activerecord-postgres-json.rb +1 -1
- data/lib/activerecord-postgres-json/activerecord.rb +34 -5
- data/lib/activerecord-postgres-json/coders.rb +21 -6
- data/spec/activerecord-postgres-json_spec.rb +100 -1
- data/spec/coder_spec.rb +13 -0
- data/spec/database.yml +4 -0
- data/spec/spec_helper.rb +15 -18
- data/spec/support/database_setup.rb +22 -0
- metadata +24 -7
- data/Gemfile.lock +0 -81
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b385f869eb3d9e0de150fc2762c1dd04f1d66c0e
|
4
|
+
data.tar.gz: 86fe3304395044c2c36ba0218851bddbec25c34f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d4c5751709d4ff8b2b10bb9e962d9b0dee214db3cf7e08e488ae52a94dd1bac1fcce72d65352ea6435ecf4282db7cfb7ebd5470525d45c2ec59d5d57b465f596
|
7
|
+
data.tar.gz: d3a15934cbc4039345e3a295bea2dfe806373648d1aab150af13d246ca85d1cf7e9a986831cbfc0a72b5303d907de4037d4667d1a577939860e2d078954267df
|
data/.rubocop.yml
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
LineLength:
|
2
|
+
Max: 200
|
3
|
+
|
4
|
+
HashSyntax:
|
5
|
+
EnforcedStyle: ruby19
|
6
|
+
|
7
|
+
SingleSpaceBeforeFirstArg:
|
8
|
+
Enabled: false
|
9
|
+
|
10
|
+
Metrics/AbcSize:
|
11
|
+
Max: 26
|
12
|
+
|
13
|
+
Style/Documentation:
|
14
|
+
Enabled: false
|
15
|
+
|
16
|
+
Metrics/ClassLength:
|
17
|
+
Max: 150
|
18
|
+
|
19
|
+
Metrics/MethodLength:
|
20
|
+
Max: 20
|
21
|
+
|
22
|
+
TrailingComma:
|
23
|
+
Enabled: false
|
24
|
+
AllCops:
|
25
|
+
Exclude:
|
26
|
+
- '**/*.gemspec'
|
27
|
+
- 'spec/**/*'
|
28
|
+
- '**/Rakefile'
|
data/Gemfile
CHANGED
@@ -2,10 +2,14 @@ source 'http://rubygems.org'
|
|
2
2
|
|
3
3
|
gem 'activerecord', '>= 3.2', '< 4'
|
4
4
|
gem 'multi_json'
|
5
|
-
|
5
|
+
|
6
|
+
group :development, :test do
|
7
|
+
gem 'rspec', '~> 2.0'
|
8
|
+
gem 'pg'
|
9
|
+
end
|
6
10
|
|
7
11
|
group :development do
|
8
|
-
gem '
|
12
|
+
gem 'rubocop'
|
9
13
|
gem 'rdoc'
|
10
14
|
gem 'bundler'
|
11
15
|
gem 'jeweler'
|
data/README.md
CHANGED
@@ -1,19 +1,20 @@
|
|
1
1
|
# activerecord-postgres-json
|
2
2
|
|
3
|
-
A minimal JSON column type support for ActiveRecord 3.2.x
|
3
|
+
A minimal JSON/JSONB column type support for ActiveRecord 3.2.x
|
4
4
|
This gem adds the following support:
|
5
5
|
|
6
|
-
1. Using json column type in migrations, e.g. `add_column :foo, :bar, :json`
|
6
|
+
1. Using json/jsonb column type in migrations, e.g. `add_column :foo, :bar, :json` or `add_column :foo, :bar, :jsonb`
|
7
7
|
2. json field support in the schema definitions
|
8
8
|
3. JSON coder for using with the `serialize` class method:
|
9
9
|
|
10
10
|
```ruby
|
11
11
|
class User < ActiveRecord::Base
|
12
12
|
serialize :settings, ActiveRecord::Coders::JSON
|
13
|
+
serialize :settings, ActiveRecord::Coders::JSON.new(symbolize_keys: true) # for symbolize keys
|
13
14
|
end
|
14
15
|
|
15
|
-
User.first.settings.class # =>
|
16
|
-
User.first.settings
|
16
|
+
User.first.settings.class # => Hash
|
17
|
+
User.first.settings[:show_popups] # => true
|
17
18
|
...
|
18
19
|
```
|
19
20
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.2.0
|
@@ -2,16 +2,16 @@
|
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
3
|
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
|
-
# stub: activerecord-postgres-json 0.
|
5
|
+
# stub: activerecord-postgres-json 0.2.0 ruby lib
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = "activerecord-postgres-json"
|
9
|
-
s.version = "0.
|
9
|
+
s.version = "0.2.0"
|
10
10
|
|
11
11
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
12
12
|
s.require_paths = ["lib"]
|
13
13
|
s.authors = ["Roman Shterenzon"]
|
14
|
-
s.date = "
|
14
|
+
s.date = "2015-01-16"
|
15
15
|
s.description = "Active Record support for PostgreSQL JSON type"
|
16
16
|
s.email = "romanbsd@yahoo.com"
|
17
17
|
s.extra_rdoc_files = [
|
@@ -21,8 +21,8 @@ Gem::Specification.new do |s|
|
|
21
21
|
s.files = [
|
22
22
|
".document",
|
23
23
|
".rspec",
|
24
|
+
".rubocop.yml",
|
24
25
|
"Gemfile",
|
25
|
-
"Gemfile.lock",
|
26
26
|
"LICENSE.txt",
|
27
27
|
"README.md",
|
28
28
|
"Rakefile",
|
@@ -32,11 +32,14 @@ Gem::Specification.new do |s|
|
|
32
32
|
"lib/activerecord-postgres-json/activerecord.rb",
|
33
33
|
"lib/activerecord-postgres-json/coders.rb",
|
34
34
|
"spec/activerecord-postgres-json_spec.rb",
|
35
|
-
"spec/
|
35
|
+
"spec/coder_spec.rb",
|
36
|
+
"spec/database.yml",
|
37
|
+
"spec/spec_helper.rb",
|
38
|
+
"spec/support/database_setup.rb"
|
36
39
|
]
|
37
40
|
s.homepage = "http://github.com/romanbsd/activerecord-postgres-json"
|
38
41
|
s.licenses = ["MIT"]
|
39
|
-
s.rubygems_version = "2.
|
42
|
+
s.rubygems_version = "2.4.3"
|
40
43
|
s.summary = "Active Record support for PostgreSQL JSON type"
|
41
44
|
|
42
45
|
if s.respond_to? :specification_version then
|
@@ -45,16 +48,18 @@ Gem::Specification.new do |s|
|
|
45
48
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
46
49
|
s.add_runtime_dependency(%q<activerecord>, ["< 4", ">= 3.2"])
|
47
50
|
s.add_runtime_dependency(%q<multi_json>, [">= 0"])
|
48
|
-
s.
|
49
|
-
s.add_development_dependency(%q<
|
51
|
+
s.add_development_dependency(%q<rspec>, ["~> 2.0"])
|
52
|
+
s.add_development_dependency(%q<pg>, [">= 0"])
|
53
|
+
s.add_development_dependency(%q<rubocop>, [">= 0"])
|
50
54
|
s.add_development_dependency(%q<rdoc>, [">= 0"])
|
51
55
|
s.add_development_dependency(%q<bundler>, [">= 0"])
|
52
56
|
s.add_development_dependency(%q<jeweler>, [">= 0"])
|
53
57
|
else
|
54
58
|
s.add_dependency(%q<activerecord>, ["< 4", ">= 3.2"])
|
55
59
|
s.add_dependency(%q<multi_json>, [">= 0"])
|
56
|
-
s.add_dependency(%q<
|
57
|
-
s.add_dependency(%q<
|
60
|
+
s.add_dependency(%q<rspec>, ["~> 2.0"])
|
61
|
+
s.add_dependency(%q<pg>, [">= 0"])
|
62
|
+
s.add_dependency(%q<rubocop>, [">= 0"])
|
58
63
|
s.add_dependency(%q<rdoc>, [">= 0"])
|
59
64
|
s.add_dependency(%q<bundler>, [">= 0"])
|
60
65
|
s.add_dependency(%q<jeweler>, [">= 0"])
|
@@ -62,8 +67,9 @@ Gem::Specification.new do |s|
|
|
62
67
|
else
|
63
68
|
s.add_dependency(%q<activerecord>, ["< 4", ">= 3.2"])
|
64
69
|
s.add_dependency(%q<multi_json>, [">= 0"])
|
65
|
-
s.add_dependency(%q<
|
66
|
-
s.add_dependency(%q<
|
70
|
+
s.add_dependency(%q<rspec>, ["~> 2.0"])
|
71
|
+
s.add_dependency(%q<pg>, [">= 0"])
|
72
|
+
s.add_dependency(%q<rubocop>, [">= 0"])
|
67
73
|
s.add_dependency(%q<rdoc>, [">= 0"])
|
68
74
|
s.add_dependency(%q<bundler>, [">= 0"])
|
69
75
|
s.add_dependency(%q<jeweler>, [">= 0"])
|
@@ -2,17 +2,25 @@ require 'active_record'
|
|
2
2
|
require 'active_record/connection_adapters/postgresql_adapter'
|
3
3
|
|
4
4
|
module ActiveRecord
|
5
|
-
|
6
5
|
module ConnectionAdapters
|
7
|
-
PostgreSQLAdapter::NATIVE_DATABASE_TYPES[:json]
|
6
|
+
PostgreSQLAdapter::NATIVE_DATABASE_TYPES[:json] = { name: 'json' }
|
7
|
+
PostgreSQLAdapter::NATIVE_DATABASE_TYPES[:jsonb] = { name: 'jsonb' }
|
8
8
|
|
9
9
|
class PostgreSQLColumn < Column
|
10
10
|
# Adds the json type for the column.
|
11
11
|
def simplified_type_with_json(field_type)
|
12
|
-
field_type == 'json'
|
12
|
+
return :json if field_type == 'json'
|
13
|
+
simplified_type_without_json(field_type)
|
14
|
+
end
|
15
|
+
|
16
|
+
# Adds the json type for the column.
|
17
|
+
def simplified_type_with_jsonb(field_type)
|
18
|
+
return :jsonb if field_type == 'jsonb'
|
19
|
+
simplified_type_without_jsonb(field_type)
|
13
20
|
end
|
14
21
|
|
15
22
|
alias_method_chain :simplified_type, :json
|
23
|
+
alias_method_chain :simplified_type, :jsonb
|
16
24
|
|
17
25
|
class << self
|
18
26
|
def extract_value_from_default_with_json(default)
|
@@ -25,12 +33,23 @@ module ActiveRecord
|
|
25
33
|
extract_value_from_default_without_json(default)
|
26
34
|
end
|
27
35
|
end
|
36
|
+
|
37
|
+
def extract_value_from_default_with_jsonb(default)
|
38
|
+
case default
|
39
|
+
when "'{}'::jsonb"
|
40
|
+
'{}'
|
41
|
+
when "'[]'::jsonb"
|
42
|
+
'[]'
|
43
|
+
else
|
44
|
+
extract_value_from_default_without_jsonb(default)
|
45
|
+
end
|
46
|
+
end
|
28
47
|
alias_method_chain :extract_value_from_default, :json
|
48
|
+
alias_method_chain :extract_value_from_default, :jsonb
|
29
49
|
end
|
30
50
|
end
|
31
51
|
|
32
52
|
class TableDefinition
|
33
|
-
|
34
53
|
# Adds json type for migrations. So you can add columns to a table like:
|
35
54
|
# create_table :people do |t|
|
36
55
|
# ...
|
@@ -43,10 +62,14 @@ module ActiveRecord
|
|
43
62
|
column_names.each { |name| column(name, 'json', options) }
|
44
63
|
end
|
45
64
|
|
65
|
+
def jsonb(*args)
|
66
|
+
options = args.extract_options!
|
67
|
+
column_names = args
|
68
|
+
column_names.each { |name| column(name, 'jsonb', options) }
|
69
|
+
end
|
46
70
|
end
|
47
71
|
|
48
72
|
class Table
|
49
|
-
|
50
73
|
# Adds json type for migrations. So you can add columns to a table like:
|
51
74
|
# change_table :people do |t|
|
52
75
|
# ...
|
@@ -58,6 +81,12 @@ module ActiveRecord
|
|
58
81
|
column_names = args
|
59
82
|
column_names.each { |name| column(name, 'json', options) }
|
60
83
|
end
|
84
|
+
|
85
|
+
def jsonb(*args)
|
86
|
+
options = args.extract_options!
|
87
|
+
column_names = args
|
88
|
+
column_names.each { |name| column(name, 'jsonb', options) }
|
89
|
+
end
|
61
90
|
end
|
62
91
|
end
|
63
92
|
end
|
@@ -1,5 +1,4 @@
|
|
1
1
|
require 'multi_json'
|
2
|
-
require 'hashie'
|
3
2
|
|
4
3
|
module ActiveRecord
|
5
4
|
module Coders
|
@@ -12,12 +11,19 @@ module ActiveRecord
|
|
12
11
|
new.dump(json)
|
13
12
|
end
|
14
13
|
|
15
|
-
def initialize(
|
16
|
-
@default =
|
14
|
+
def initialize(params = {})
|
15
|
+
@default = {}
|
16
|
+
return unless params.class.name == 'Hash'
|
17
|
+
@default = params[:default] if params[:default]
|
18
|
+
@symbolize_keys = params[:symbolize_keys] if params[:symbolize_keys]
|
17
19
|
end
|
18
20
|
|
19
21
|
def dump(obj)
|
20
|
-
obj.nil?
|
22
|
+
if obj.nil?
|
23
|
+
@default.nil? ? nil : to_json(@default)
|
24
|
+
else
|
25
|
+
to_json(obj)
|
26
|
+
end
|
21
27
|
end
|
22
28
|
|
23
29
|
def load(json)
|
@@ -25,13 +31,22 @@ module ActiveRecord
|
|
25
31
|
end
|
26
32
|
|
27
33
|
private
|
34
|
+
|
28
35
|
def to_json(obj)
|
29
36
|
MultiJson.dump(obj)
|
30
37
|
end
|
31
38
|
|
32
|
-
# FIXME: support arrays
|
33
39
|
def from_json(json)
|
34
|
-
|
40
|
+
convert_object MultiJson.load(json, symbolize_keys: @symbolize_keys)
|
41
|
+
end
|
42
|
+
|
43
|
+
def convert_object(obj)
|
44
|
+
case obj
|
45
|
+
when Array
|
46
|
+
obj.map { |member| convert_object(member) }
|
47
|
+
else
|
48
|
+
obj
|
49
|
+
end
|
35
50
|
end
|
36
51
|
end
|
37
52
|
end
|
@@ -1,4 +1,103 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
require File.expand_path(File.dirname(__FILE__) + '/support/database_setup')
|
2
3
|
|
3
|
-
|
4
|
+
class Post < ActiveRecord::Base
|
5
|
+
serialize :data, ActiveRecord::Coders::JSON.new(symbolize_keys: true)
|
6
|
+
end
|
7
|
+
|
8
|
+
class PostQuestions < ActiveRecord::Base
|
9
|
+
serialize :tags, ActiveRecord::Coders::JSON
|
10
|
+
end
|
11
|
+
|
12
|
+
describe 'ActiverecordPostgresJson', db: true do
|
13
|
+
before(:all) do
|
14
|
+
ActiveRecord::Schema.define do
|
15
|
+
create_table :posts, force: true do |t|
|
16
|
+
t.column :data, :jsonb
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
Post.reset_column_information
|
21
|
+
|
22
|
+
ActiveRecord::Base.connection.execute <<-SQL
|
23
|
+
CREATE INDEX index_posts_data_gin ON posts
|
24
|
+
USING gin (data);
|
25
|
+
SQL
|
26
|
+
|
27
|
+
ActiveRecord::Base.connection.execute <<-SQL
|
28
|
+
CREATE OR REPLACE VIEW post_questions as
|
29
|
+
SELECT
|
30
|
+
id,
|
31
|
+
data ->> 'title' AS title,
|
32
|
+
data #>> '{author,name}' AS author_name,
|
33
|
+
data #>> '{author,email}' AS author_email,
|
34
|
+
(data ->> 'tags')::json AS tags,
|
35
|
+
(data ->> 'draft')::boolean AS draft
|
36
|
+
FROM posts
|
37
|
+
SQL
|
38
|
+
end
|
39
|
+
|
40
|
+
after(:all) do
|
41
|
+
ActiveRecord::Base.connection.execute 'DROP INDEX IF EXISTS index_posts_data_gin'
|
42
|
+
ActiveRecord::Base.connection.execute 'DROP VIEW IF EXISTS post_questions'
|
43
|
+
end
|
44
|
+
|
45
|
+
before { Post.delete_all }
|
46
|
+
|
47
|
+
let!(:hdd) do
|
48
|
+
Post.create!(data: [
|
49
|
+
{f1: 6, f2: 5, value: true, intencity: 2.0},
|
50
|
+
{f1: 9, f2: 3, value: false, intencity: 1.0}
|
51
|
+
]).reload
|
52
|
+
end
|
53
|
+
|
54
|
+
let!(:tdd) do
|
55
|
+
Post.create!(data: [
|
56
|
+
{f1: 1, f2: 2, value: false, intencity: 2.0},
|
57
|
+
{f1: 1, f2: 4, value: true, intencity: 1.0}
|
58
|
+
]).reload
|
59
|
+
end
|
60
|
+
|
61
|
+
let!(:bdd) do
|
62
|
+
Post.create!(data: {
|
63
|
+
title: 'BDD is woot',
|
64
|
+
author: { name: 'Philippe', email: 'philippe@example.com'},
|
65
|
+
tags: ['bdd', 'testing', 'woot', true],
|
66
|
+
word_count: 42
|
67
|
+
}).reload
|
68
|
+
end
|
69
|
+
|
70
|
+
let!(:foo) do
|
71
|
+
Post.create!(data: {
|
72
|
+
title: 'FOO is bar',
|
73
|
+
author: { name: 'Philippe', email: 'philippe@example.com'},
|
74
|
+
tags: ['foo', 'bar', 42],
|
75
|
+
draft: true
|
76
|
+
}).reload
|
77
|
+
end
|
78
|
+
|
79
|
+
it 'maps fields' do
|
80
|
+
post = PostQuestions.find_by_title! 'FOO is bar'
|
81
|
+
expect(post.author_name).to eq('Philippe')
|
82
|
+
expect(post.author_email).to eq('philippe@example.com')
|
83
|
+
expect(post.tags).to eq ['foo', 'bar', 42]
|
84
|
+
expect(post).to be_draft
|
85
|
+
end
|
86
|
+
|
87
|
+
it 'provides search as if it was a good old table' do
|
88
|
+
expect(PostQuestions.where(author_name: 'Philippe').pluck(:title)).to eq ['BDD is woot', 'FOO is bar']
|
89
|
+
expect(PostQuestions.where(draft: true).count).to eq(1)
|
90
|
+
end
|
91
|
+
|
92
|
+
it 'when retrieve objects as array' do
|
93
|
+
expect(Post.where('data @> \'[{"f1":1}]\'').first.data)
|
94
|
+
.to eq [
|
95
|
+
{f1: 1, f2: 2, value: false, intencity: 2.0},
|
96
|
+
{f1: 1, f2: 4, value: true, intencity: 1.0}
|
97
|
+
]
|
98
|
+
end
|
99
|
+
|
100
|
+
it 'when search in objects array' do
|
101
|
+
expect(Post.where('data @> \'[{"f1":6}]\'').count).to eq(1)
|
102
|
+
end
|
4
103
|
end
|
data/spec/coder_spec.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe ActiveRecord::Coders::JSON do
|
4
|
+
it 'converts hashes' do
|
5
|
+
res = described_class.load('{"foo":"bar", "bar":[1,2]}')
|
6
|
+
expect(res).to eq('foo' => 'bar', 'bar' => [1,2])
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'converts arrays' do
|
10
|
+
res = described_class.load('[{"foo":"bar"}, [{"bar":"baz"}], [[1,2],{"baz":"foo"}]]')
|
11
|
+
expect(res).to eq([{'foo' => 'bar'}, [{'bar' => 'baz'}], [[1,2], {'baz' => 'foo'}]])
|
12
|
+
end
|
13
|
+
end
|
data/spec/database.yml
ADDED
data/spec/spec_helper.rb
CHANGED
@@ -1,29 +1,26 @@
|
|
1
|
-
require 'simplecov'
|
2
|
-
|
3
|
-
module SimpleCov::Configuration
|
4
|
-
def clean_filters
|
5
|
-
@filters = []
|
6
|
-
end
|
7
|
-
end
|
8
|
-
|
9
|
-
SimpleCov.configure do
|
10
|
-
clean_filters
|
11
|
-
load_adapter 'test_frameworks'
|
12
|
-
end
|
13
|
-
|
14
|
-
ENV["COVERAGE"] && SimpleCov.start do
|
15
|
-
add_filter "/.rvm/"
|
16
|
-
end
|
17
1
|
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
18
2
|
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
19
3
|
|
20
4
|
require 'rspec'
|
5
|
+
require 'active_record'
|
21
6
|
require 'activerecord-postgres-json'
|
22
7
|
|
23
8
|
# Requires supporting files with custom matchers and macros, etc,
|
24
9
|
# in ./support/ and its subdirectories.
|
25
|
-
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
10
|
+
# Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
26
11
|
|
27
12
|
RSpec.configure do |config|
|
28
|
-
|
13
|
+
config.around db: true do |example|
|
14
|
+
if example.metadata[:disable_transactions]
|
15
|
+
example.call
|
16
|
+
else
|
17
|
+
ActiveRecord::Base.transaction do
|
18
|
+
begin
|
19
|
+
example.call
|
20
|
+
ensure
|
21
|
+
raise ActiveRecord::Rollback
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
29
26
|
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'logger'
|
2
|
+
require 'pg'
|
3
|
+
|
4
|
+
db_config = YAML.load_file(File.expand_path('../../database.yml', __FILE__))
|
5
|
+
|
6
|
+
begin
|
7
|
+
ActiveRecord::Base.establish_connection db_config['test']
|
8
|
+
ActiveRecord::Base.connection.active?
|
9
|
+
rescue Exception => e
|
10
|
+
encoding = db_config['test']['encoding'] || ENV['CHARSET'] || 'utf8'
|
11
|
+
begin
|
12
|
+
ActiveRecord::Base.establish_connection(db_config['test'].merge('database' => 'postgres', 'schema_search_path' => 'public'))
|
13
|
+
ActiveRecord::Base.connection.create_database(db_config['test']['database'], db_config['test'].merge('encoding' => encoding))
|
14
|
+
ActiveRecord::Base.establish_connection(db_config['test'])
|
15
|
+
rescue Exception => ec
|
16
|
+
$stderr.puts ec, *(ec.backtrace)
|
17
|
+
$stderr.puts "Couldn't create database for #{db_config['test'].inspect}"
|
18
|
+
end
|
19
|
+
ensure
|
20
|
+
ActiveRecord::Base.logger = Logger.new(STDOUT)
|
21
|
+
ActiveRecord::Base.logger.formatter = ->(_, _, _, msg) { "#{msg}\n" }
|
22
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activerecord-postgres-json
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Roman Shterenzon
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-01-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -45,13 +45,27 @@ dependencies:
|
|
45
45
|
- !ruby/object:Gem::Version
|
46
46
|
version: '0'
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
|
-
name:
|
48
|
+
name: rspec
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - "~>"
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '2.0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - "~>"
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '2.0'
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: pg
|
49
63
|
requirement: !ruby/object:Gem::Requirement
|
50
64
|
requirements:
|
51
65
|
- - ">="
|
52
66
|
- !ruby/object:Gem::Version
|
53
67
|
version: '0'
|
54
|
-
type: :
|
68
|
+
type: :development
|
55
69
|
prerelease: false
|
56
70
|
version_requirements: !ruby/object:Gem::Requirement
|
57
71
|
requirements:
|
@@ -59,7 +73,7 @@ dependencies:
|
|
59
73
|
- !ruby/object:Gem::Version
|
60
74
|
version: '0'
|
61
75
|
- !ruby/object:Gem::Dependency
|
62
|
-
name:
|
76
|
+
name: rubocop
|
63
77
|
requirement: !ruby/object:Gem::Requirement
|
64
78
|
requirements:
|
65
79
|
- - ">="
|
@@ -124,8 +138,8 @@ extra_rdoc_files:
|
|
124
138
|
files:
|
125
139
|
- ".document"
|
126
140
|
- ".rspec"
|
141
|
+
- ".rubocop.yml"
|
127
142
|
- Gemfile
|
128
|
-
- Gemfile.lock
|
129
143
|
- LICENSE.txt
|
130
144
|
- README.md
|
131
145
|
- Rakefile
|
@@ -135,7 +149,10 @@ files:
|
|
135
149
|
- lib/activerecord-postgres-json/activerecord.rb
|
136
150
|
- lib/activerecord-postgres-json/coders.rb
|
137
151
|
- spec/activerecord-postgres-json_spec.rb
|
152
|
+
- spec/coder_spec.rb
|
153
|
+
- spec/database.yml
|
138
154
|
- spec/spec_helper.rb
|
155
|
+
- spec/support/database_setup.rb
|
139
156
|
homepage: http://github.com/romanbsd/activerecord-postgres-json
|
140
157
|
licenses:
|
141
158
|
- MIT
|
@@ -156,7 +173,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
156
173
|
version: '0'
|
157
174
|
requirements: []
|
158
175
|
rubyforge_project:
|
159
|
-
rubygems_version: 2.
|
176
|
+
rubygems_version: 2.4.3
|
160
177
|
signing_key:
|
161
178
|
specification_version: 4
|
162
179
|
summary: Active Record support for PostgreSQL JSON type
|
data/Gemfile.lock
DELETED
@@ -1,81 +0,0 @@
|
|
1
|
-
GEM
|
2
|
-
remote: http://rubygems.org/
|
3
|
-
specs:
|
4
|
-
activemodel (3.2.18)
|
5
|
-
activesupport (= 3.2.18)
|
6
|
-
builder (~> 3.0.0)
|
7
|
-
activerecord (3.2.18)
|
8
|
-
activemodel (= 3.2.18)
|
9
|
-
activesupport (= 3.2.18)
|
10
|
-
arel (~> 3.0.2)
|
11
|
-
tzinfo (~> 0.3.29)
|
12
|
-
activesupport (3.2.18)
|
13
|
-
i18n (~> 0.6, >= 0.6.4)
|
14
|
-
multi_json (~> 1.0)
|
15
|
-
addressable (2.3.6)
|
16
|
-
arel (3.0.3)
|
17
|
-
builder (3.0.4)
|
18
|
-
descendants_tracker (0.0.4)
|
19
|
-
thread_safe (~> 0.3, >= 0.3.1)
|
20
|
-
diff-lcs (1.2.5)
|
21
|
-
faraday (0.9.0)
|
22
|
-
multipart-post (>= 1.2, < 3)
|
23
|
-
git (1.2.6)
|
24
|
-
github_api (0.11.3)
|
25
|
-
addressable (~> 2.3)
|
26
|
-
descendants_tracker (~> 0.0.1)
|
27
|
-
faraday (~> 0.8, < 0.10)
|
28
|
-
hashie (>= 1.2)
|
29
|
-
multi_json (>= 1.7.5, < 2.0)
|
30
|
-
nokogiri (~> 1.6.0)
|
31
|
-
oauth2
|
32
|
-
hashie (2.1.1)
|
33
|
-
highline (1.6.21)
|
34
|
-
i18n (0.6.9)
|
35
|
-
jeweler (2.0.1)
|
36
|
-
builder
|
37
|
-
bundler (>= 1.0)
|
38
|
-
git (>= 1.2.5)
|
39
|
-
github_api
|
40
|
-
highline (>= 1.6.15)
|
41
|
-
nokogiri (>= 1.5.10)
|
42
|
-
rake
|
43
|
-
rdoc
|
44
|
-
jwt (1.0.0)
|
45
|
-
mini_portile (0.6.0)
|
46
|
-
multi_json (1.10.1)
|
47
|
-
multi_xml (0.5.5)
|
48
|
-
multipart-post (2.0.0)
|
49
|
-
nokogiri (1.6.2.1)
|
50
|
-
mini_portile (= 0.6.0)
|
51
|
-
oauth2 (0.9.4)
|
52
|
-
faraday (>= 0.8, < 0.10)
|
53
|
-
jwt (~> 1.0)
|
54
|
-
multi_json (~> 1.3)
|
55
|
-
multi_xml (~> 0.5)
|
56
|
-
rack (~> 1.2)
|
57
|
-
rack (1.5.2)
|
58
|
-
rake (10.3.2)
|
59
|
-
rdoc (4.1.0)
|
60
|
-
rspec (2.14.1)
|
61
|
-
rspec-core (~> 2.14.0)
|
62
|
-
rspec-expectations (~> 2.14.0)
|
63
|
-
rspec-mocks (~> 2.14.0)
|
64
|
-
rspec-core (2.14.8)
|
65
|
-
rspec-expectations (2.14.5)
|
66
|
-
diff-lcs (>= 1.1.3, < 2.0)
|
67
|
-
rspec-mocks (2.14.6)
|
68
|
-
thread_safe (0.3.4)
|
69
|
-
tzinfo (0.3.39)
|
70
|
-
|
71
|
-
PLATFORMS
|
72
|
-
ruby
|
73
|
-
|
74
|
-
DEPENDENCIES
|
75
|
-
activerecord (>= 3.2, < 4)
|
76
|
-
bundler
|
77
|
-
hashie
|
78
|
-
jeweler
|
79
|
-
multi_json
|
80
|
-
rdoc
|
81
|
-
rspec
|