activerecord-postgres-composite-types 0.2.7 → 0.2.8

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7a85470536d96dca0ff437cd209b5fa9628e7e71
4
- data.tar.gz: 3e491337ed3e83cff38da77e50abf2c23883068d
3
+ metadata.gz: 4d16fab97f447570a87c19162c8f9d4f706c46ab
4
+ data.tar.gz: 84a4370a599af1d99f6666c6b1b5425382413b97
5
5
  SHA512:
6
- metadata.gz: 9bb2d3459d1fe690ce2f8e5c17c45d203af9f2cd6df725617a6695b98e4e7edf40c9d496ac9dda9b99eaa0dd5dbabe73a22612dc7f4ee63d59487d45965d09cf
7
- data.tar.gz: 5b50e3fa248351d097650a1067168c64f37c48b71781a3e35aacd91f5727c171479fb6987dfede6f43ba340c6b3c51e91a375550e89f51076a8cbd9f986a7986
6
+ metadata.gz: c1786a5fc1abdcc38aa8427de7089daaaa691edc5f65493ad3a940f9716bddb750e57b7c007d16d1fda0f910b6fd68f028e8a237d9d1a0b75f6bf46984c42ff2
7
+ data.tar.gz: d8e39544995e95380b6f09a21d08da0128f039082bf3983ef876cf671db45ac29a46e853b571766acae8aa749721428a226014b71f79109e229975bd2709aeb6
@@ -1,10 +1,11 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.1.0
3
+ - 2.1.6
4
+ - 2.2.2
4
5
  env:
5
- - AR_VERSION=3.2.0
6
- - AR_VERSION=4.1.9
7
- - AR_VERSION=4.2.0
6
+ - AR_VERSION=3.2.22
7
+ - AR_VERSION=4.1.12
8
+ - AR_VERSION=4.2.3
8
9
  addons:
9
10
  postgresql: "9.3"
10
11
  before_script:
data/Gemfile CHANGED
@@ -7,12 +7,11 @@ gem 'pg', '>= 0.17.0'
7
7
 
8
8
  group :development do
9
9
  gem 'test-unit', '~> 2.1'
10
- gem 'shoulda', '>= 0'
11
10
  gem 'rdoc', '~> 3.12'
12
11
  gem 'rake', '~> 10.3'
13
12
  gem 'bundler', '~> 1.0'
14
13
  gem 'jeweler', '~> 2.0.1' unless RUBY_PLATFORM =~ /mswin/
15
14
  gem 'simplecov', '>= 0'
16
15
  gem 'combustion', '~> 0.5.2'
17
- gem 'tzinfo-data' if AR_VERSION > '3.2.0'
16
+ gem 'tzinfo-data' if AR_VERSION >= '4'
18
17
  end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.7
1
+ 0.2.8
@@ -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-composite-types 0.2.7 ruby lib
5
+ # stub: activerecord-postgres-composite-types 0.2.8 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "activerecord-postgres-composite-types"
9
- s.version = "0.2.7"
9
+ s.version = "0.2.8"
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 = ["Rafal Bigaj"]
14
- s.date = "2015-03-20"
14
+ s.date = "2015-07-17"
15
15
  s.description = "This gem adds support to the ActiveRecord (3.x and 4.x) for composite types."
16
16
  s.email = "rafal.bigaj@puzzleflow.com"
17
17
  s.extra_rdoc_files = [
@@ -48,7 +48,7 @@ Gem::Specification.new do |s|
48
48
  ]
49
49
  s.homepage = "http://github.com/puzzleflow/activerecord-postgres-composite-types"
50
50
  s.licenses = ["MIT"]
51
- s.rubygems_version = "2.4.5"
51
+ s.rubygems_version = "2.4.8"
52
52
  s.summary = "ActiveRecord composite types support"
53
53
 
54
54
  if s.respond_to? :specification_version then
@@ -58,7 +58,6 @@ Gem::Specification.new do |s|
58
58
  s.add_runtime_dependency(%q<activerecord>, [">= 3.2"])
59
59
  s.add_runtime_dependency(%q<pg>, [">= 0.17.0"])
60
60
  s.add_development_dependency(%q<test-unit>, ["~> 2.1"])
61
- s.add_development_dependency(%q<shoulda>, [">= 0"])
62
61
  s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
63
62
  s.add_development_dependency(%q<rake>, ["~> 10.3"])
64
63
  s.add_development_dependency(%q<bundler>, ["~> 1.0"])
@@ -69,7 +68,6 @@ Gem::Specification.new do |s|
69
68
  s.add_dependency(%q<activerecord>, [">= 3.2"])
70
69
  s.add_dependency(%q<pg>, [">= 0.17.0"])
71
70
  s.add_dependency(%q<test-unit>, ["~> 2.1"])
72
- s.add_dependency(%q<shoulda>, [">= 0"])
73
71
  s.add_dependency(%q<rdoc>, ["~> 3.12"])
74
72
  s.add_dependency(%q<rake>, ["~> 10.3"])
75
73
  s.add_dependency(%q<bundler>, ["~> 1.0"])
@@ -81,7 +79,6 @@ Gem::Specification.new do |s|
81
79
  s.add_dependency(%q<activerecord>, [">= 3.2"])
82
80
  s.add_dependency(%q<pg>, [">= 0.17.0"])
83
81
  s.add_dependency(%q<test-unit>, ["~> 2.1"])
84
- s.add_dependency(%q<shoulda>, [">= 0"])
85
82
  s.add_dependency(%q<rdoc>, ["~> 3.12"])
86
83
  s.add_dependency(%q<rake>, ["~> 10.3"])
87
84
  s.add_dependency(%q<bundler>, ["~> 1.0"])
@@ -28,7 +28,7 @@ module ActiveRecord
28
28
 
29
29
  def type_cast_for_database(object)
30
30
  return object if object.is_a?(String) # already quoted by AREL visitor
31
- return "NULL" if object == nil
31
+ return nil if object == nil
32
32
  quoted_values = object.class.columns.collect do |column|
33
33
  value = object.send(column.name)
34
34
  if String === value
@@ -24,8 +24,6 @@ rescue Bundler::BundlerError => e
24
24
  exit e.status_code
25
25
  end
26
26
 
27
- require 'shoulda'
28
-
29
27
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
30
28
  $LOAD_PATH.unshift(File.dirname(__FILE__))
31
29
 
@@ -40,7 +38,7 @@ Combustion.initialize! :active_record
40
38
 
41
39
  ActiveRecord::Base.default_timezone = :utc
42
40
 
43
- class Test::Unit::TestCase
41
+ class ActiveSupport::TestCase
44
42
  def connection
45
43
  ActiveRecord::Base.connection
46
44
  end
@@ -1,6 +1,6 @@
1
1
  require_relative 'helper'
2
2
 
3
- class TestCompositeTypeClass < Test::Unit::TestCase
3
+ class TestCompositeTypeClass < ActiveSupport::TestCase
4
4
 
5
5
  PostgreSQLColumn = ActiveRecord::ConnectionAdapters::PostgreSQLColumn
6
6
 
@@ -8,7 +8,7 @@ class TestCompositeTypeClass < Test::Unit::TestCase
8
8
  @my_type_column = connection.columns(:my_table).first
9
9
  end
10
10
 
11
- should "define accessors" do
11
+ test "define accessors" do
12
12
  assert MyType.method_defined?(:name)
13
13
  assert MyType.method_defined?(:name=)
14
14
  assert MyType.method_defined?(:number)
@@ -17,44 +17,44 @@ class TestCompositeTypeClass < Test::Unit::TestCase
17
17
  assert MyType.method_defined?(:date=)
18
18
  end
19
19
 
20
- should "be created by adapter from string" do
20
+ test "be created by adapter from string" do
21
21
  value = PostgreSQLColumn.string_to_composite_type(MyType, "(text,5,2014-08-27 00:00:00)")
22
22
  assert_equal 'text', value.name
23
23
  assert_equal 5, value.number
24
24
  assert_equal Time.parse('2014-08-27 00:00:00 UTC'), value.date
25
25
  end
26
26
 
27
- should "accept escaped string" do
27
+ test "accept escaped string" do
28
28
  value = PostgreSQLColumn.string_to_composite_type(MyType, '("text\'s",125,"2014-08-27 10:00:00")')
29
29
  assert_equal "text's", value.name
30
30
  assert_equal 125, value.number
31
31
  assert_equal Time.parse('2014-08-27 10:00:00 UTC'), value.date
32
32
  end
33
33
 
34
- should "initialize with hash" do
34
+ test "initialize with hash" do
35
35
  value = MyType.new(number: 1, name: 'abc', date: Time.parse('2014-08-27 12:00:00 UTC'))
36
36
  assert_equal 'abc', value.name
37
37
  assert_equal 1, value.number
38
38
  assert_equal Time.parse('2014-08-27 12:00:00 UTC'), value.date
39
39
  end
40
40
 
41
- should "cast to qouted string" do
41
+ test "cast to qouted string" do
42
42
  value = MyType.new(number: 1, name: '"\'a\'bc[]*/\"', date: Time.parse('2014-08-27 12:00:00 UTC'))
43
43
  quoted = connection.quote(value, @my_type_column).sub(':00.000000', ':00 UTC') # On AR ver < 4.2 time is quoted to format with milliseconds
44
44
  assert_equal %Q{'("\\\"''a''bc[]*/\\\\\\\"",1,2014-08-27 12:00:00 UTC)'}, quoted
45
45
  end
46
46
 
47
- should "parse string and return array" do
47
+ test "parse string and return array" do
48
48
  result = PostgreSQLColumn::CompositeTypeParser.parse_data("(text,5,2014-08-27 00:00:00)")
49
49
  assert_equal ["text", "5", "2014-08-27 00:00:00"], result
50
50
  end
51
51
 
52
- should "parse string and return array 2" do
52
+ test "parse string and return array 2" do
53
53
  result = PostgreSQLColumn::CompositeTypeParser.parse_data('(text,5,"(titi,tata)",2014-08-27 00:00:00)')
54
54
  assert_equal ["text", "5", '(titi,tata)', "2014-08-27 00:00:00"], result
55
55
  end
56
56
 
57
- should "parse string and return array 3" do
57
+ test "parse string and return array 3" do
58
58
  result = PostgreSQLColumn::CompositeTypeParser.parse_data('(text,5,"(titi,tata,""(tutu""""tata,tete)"")",2014-08-27 00:00:00)')
59
59
  assert_equal ["text", "5", '(titi,tata,"(tutu""tata,tete)")', "2014-08-27 00:00:00"], result
60
60
  end
@@ -1,13 +1,13 @@
1
1
  require_relative 'helper'
2
2
 
3
- class TestNestedTypes < Test::Unit::TestCase
3
+ class TestNestedTypes < ActiveSupport::TestCase
4
4
  class Bar < ActiveRecord::Base
5
5
  end
6
6
 
7
7
  class Bar2 < ActiveRecord::Base
8
8
  end
9
9
 
10
- should "cast value properly" do
10
+ test "cast value properly" do
11
11
  bars = Bar.order('(nested).comp.f1').all
12
12
  assert_equal 2, bars.size
13
13
  assert_kind_of NestedType, bars[0].nested
@@ -18,46 +18,46 @@ class TestNestedTypes < Test::Unit::TestCase
18
18
  assert_equal 'blue', bars[1].nested.color
19
19
  end
20
20
 
21
- should "insert with nested type" do
21
+ test "insert with nested type" do
22
22
  bar = Bar.new(nested: {comp: Compfoo.new([2, 'bac']), color: 'red'})
23
23
  bar.save
24
24
  assert !bar.new_record?
25
25
  end
26
26
 
27
- should "build nested types from Hash" do
27
+ test "build nested types from Hash" do
28
28
  bar = Bar.new(nested: {comp: {f1: 2, f2: 'bac'}, color: 'red'})
29
29
  assert_kind_of NestedType, bar.nested
30
30
  end
31
31
 
32
- should "build nested types from Array" do
32
+ test "build nested types from Array" do
33
33
  bar = Bar.new(nested: [[2, 'bac'], 'red'])
34
34
  assert_kind_of NestedType, bar.nested
35
35
  end
36
36
 
37
- should "insert with double nested type" do
37
+ test "insert with double nested type" do
38
38
  bar = Bar2.new(nested: {nested: {comp: [1, 'dca'], color: 'blue'}, color: 'red'})
39
39
  assert_kind_of NestedNestedType, bar.nested
40
40
  end
41
41
 
42
- should "select nested type" do
42
+ test "select nested type" do
43
43
  Bar2.create!(nested: {nested: {comp: [1, 'dca'], color: 'blue'}, color: 'red'})
44
44
  assert !Bar2.where(nested: NestedNestedType.new(nested: {comp: [1, 'dca'], color: 'red'}, color: 'red')).exists?
45
45
  assert Bar2.where(nested: NestedNestedType.new(nested: {comp: [1, 'dca'], color: 'blue'}, color: 'red')).exists?
46
46
  end
47
47
 
48
- should "parser should work when nested attribute contains parenthesis" do
48
+ test "parser test work when nested attribute contains parenthesis" do
49
49
  Bar2.create!(nested: {nested: {comp: [1, 'dc)))a'], color: 'blue'}, color: 'red'})
50
50
  assert_equal 'dc)))a', Bar2.all.to_a.last.nested.nested.comp.f2
51
51
  assert Bar2.where(nested: NestedNestedType.new(nested: {comp: [1, 'dc)))a'], color: 'blue'}, color: 'red')).exists?
52
52
  end
53
53
 
54
- should "parser should work when nested attribute contains double quote" do
54
+ test "parser test work when nested attribute contains double quote" do
55
55
  Bar2.create!(nested: {nested: {comp: [1, "dc\"a"], color: 'blue'}, color: 'blue'})
56
56
  assert_equal 'blue', Bar2.all.to_a.last.nested.color
57
57
  assert_equal 'dc"a', Bar2.all.to_a.last.nested.nested.comp.f2
58
58
  end
59
59
 
60
- should "parser should work when nested attribute contains backslash" do
60
+ test "parser test work when nested attribute contains backslash" do
61
61
  Bar2.create!(nested: {nested: {comp: [1, "dc\\a"], color: 'blue'}, color: 'green'})
62
62
  assert_equal 'green', Bar2.all.to_a.last.nested.color
63
63
  assert_equal 'dc\\a', Bar2.all.to_a.last.nested.nested.comp.f2
@@ -1,11 +1,18 @@
1
1
  require_relative 'helper'
2
2
 
3
- class TestPostgresCompositeTypes < Test::Unit::TestCase
3
+ class TestPostgresCompositeTypes < ActiveSupport::TestCase
4
4
  class Foo < ActiveRecord::Base
5
+ end
6
+
7
+ class MyValue < ActiveRecord::Base
8
+ self.table_name = 'my_table'
9
+ end
5
10
 
11
+ teardown do
12
+ Foo.delete_all '(comp).f1 NOT IN (0,1)'
6
13
  end
7
14
 
8
- should "cast value properly" do
15
+ test "cast value properly" do
9
16
  foos = Foo.all
10
17
  assert_equal 2, foos.size
11
18
  assert_equal 0, foos[0].comp.f1
@@ -14,12 +21,12 @@ class TestPostgresCompositeTypes < Test::Unit::TestCase
14
21
  assert_equal "a/b'c\\d e f", foos[1].comp.f2
15
22
  end
16
23
 
17
- should "accept composite type in where clausure" do
24
+ test "accept composite type in where clausure" do
18
25
  sql = Foo.where(comp: Compfoo.new([123, 'text 1'])).to_sql
19
26
  assert_equal %Q(SELECT "foos".* FROM "foos" WHERE "foos"."comp" = '(123,"text 1")'::compfoo), sql.gsub(/ +/, ' ')
20
27
  end
21
28
 
22
- should "create new record with compound object" do
29
+ test "create new record with compound object" do
23
30
  foo = Foo.create!(comp: Compfoo.new([123, 'text 1']))
24
31
 
25
32
  assert_kind_of Compfoo, foo.comp
@@ -28,7 +35,7 @@ class TestPostgresCompositeTypes < Test::Unit::TestCase
28
35
  assert Foo.where(comp: Compfoo.new([123, 'text 1'])).exists?
29
36
  end
30
37
 
31
- should "create new record with hash" do
38
+ test "create new record with hash" do
32
39
  foo = Foo.create!(comp: {f1: 321, f2: 'text 2'})
33
40
 
34
41
  assert_kind_of Compfoo, foo.comp
@@ -37,7 +44,7 @@ class TestPostgresCompositeTypes < Test::Unit::TestCase
37
44
  assert Foo.where(comp: Compfoo.new({f1: 321, f2: 'text 2'})).exists?
38
45
  end
39
46
 
40
- should "create new record with array" do
47
+ test "create new record with array" do
41
48
  foo = Foo.create!(comp: [111, 'text 3'])
42
49
 
43
50
  assert_kind_of Compfoo, foo.comp
@@ -46,10 +53,19 @@ class TestPostgresCompositeTypes < Test::Unit::TestCase
46
53
  assert Foo.where(comp: Compfoo.new({f1: 111, f2: 'text 3'})).exists?
47
54
  end
48
55
 
49
- should 'make object nil' do
56
+ test 'make object nil' do
50
57
  foo = Foo.create!(comp: [333, 'ala ma kota'])
51
58
  foo.comp = nil
52
59
 
53
60
  assert_nil foo.comp
61
+
62
+ Foo.where(comp: Compfoo.new([333, 'ala ma kota'])).delete_all
54
63
  end
64
+
65
+ test 'accept nil value' do
66
+ mt = MyValue.create!(value: nil)
67
+ assert_nil mt.value
68
+
69
+ MyValue.where(value: nil).delete_all
70
+ end
55
71
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord-postgres-composite-types
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.7
4
+ version: 0.2.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rafal Bigaj
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-20 00:00:00.000000000 Z
11
+ date: 2015-07-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -52,20 +52,6 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '2.1'
55
- - !ruby/object:Gem::Dependency
56
- name: shoulda
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - ">="
60
- - !ruby/object:Gem::Version
61
- version: '0'
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - ">="
67
- - !ruby/object:Gem::Version
68
- version: '0'
69
55
  - !ruby/object:Gem::Dependency
70
56
  name: rdoc
71
57
  requirement: !ruby/object:Gem::Requirement
@@ -205,7 +191,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
205
191
  version: '0'
206
192
  requirements: []
207
193
  rubyforge_project:
208
- rubygems_version: 2.4.5
194
+ rubygems_version: 2.4.8
209
195
  signing_key:
210
196
  specification_version: 4
211
197
  summary: ActiveRecord composite types support