belongs_to_hstore 0.0.2 → 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.
- checksums.yaml +4 -4
- data/Gemfile +10 -0
- data/README.md +2 -1
- data/belongs_to_hstore.gemspec +0 -4
- data/lib/belongs_to_hstore/association.rb +8 -4
- data/lib/belongs_to_hstore/version.rb +1 -1
- data/spec/belongs_to_hstore_spec.rb +16 -6
- data/spec/spec_helper.rb +3 -0
- metadata +3 -45
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 232f79dff9040e7feaebb58925a85decacfcc4d8
|
4
|
+
data.tar.gz: 5fa6bfadf9dddc1c55796465d27cac518419be9d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4a47729427dbcd63db020d7c1cbcf7c3178c12807a81a3fb905f0e5586769ccecdb6d8954bc1a4477ff3837ff621e51ab6de3344fe2911fa88be19736e3b019d
|
7
|
+
data.tar.gz: 04f21bb7cc8e98c7459902be0734009c5786864b12f27f95fb61292e853b44559d6dbedc6e65fd42aa29c866bb1593cc32470a396671515091d63f0e346ef0a1
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,4 +1,5 @@
|
|
1
|
-
# BelongsToHstore
|
1
|
+
# BelongsToHstore
|
2
|
+
[](https://travis-ci.org/evanlok/belongs_to_hstore) [](http://badge.fury.io/rb/belongs_to_hstore) [](https://codeclimate.com/github/evanlok/belongs_to_hstore) [](https://coveralls.io/r/evanlok/belongs_to_hstore)
|
2
3
|
|
3
4
|
Create ActiveRecord belongs_to associations using postgresql hstore columns. Compatible with polymorphic associations
|
4
5
|
and supports eager loading.
|
data/belongs_to_hstore.gemspec
CHANGED
@@ -19,9 +19,5 @@ Gem::Specification.new do |spec|
|
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
21
|
spec.add_dependency "activerecord", ">= 3.1"
|
22
|
-
|
23
22
|
spec.add_development_dependency "bundler", "~> 1.3"
|
24
|
-
spec.add_development_dependency "rake"
|
25
|
-
spec.add_development_dependency "rspec"
|
26
|
-
spec.add_development_dependency "sqlite3"
|
27
23
|
end
|
@@ -17,11 +17,11 @@ module BelongsToHstore
|
|
17
17
|
key_type = key.gsub(/_id$/, '_type')
|
18
18
|
|
19
19
|
store_accessor store_attribute, key.to_s
|
20
|
-
self.belongs_to_hstore_attributes[key.to_s]=
|
20
|
+
self.belongs_to_hstore_attributes[key.to_s]= Integer
|
21
21
|
|
22
22
|
if options[:polymorphic]
|
23
23
|
store_accessor store_attribute, key_type
|
24
|
-
self.belongs_to_hstore_attributes[key_type]=
|
24
|
+
self.belongs_to_hstore_attributes[key_type]= String
|
25
25
|
end
|
26
26
|
|
27
27
|
belongs_to name, options
|
@@ -34,8 +34,12 @@ module BelongsToHstore
|
|
34
34
|
end
|
35
35
|
|
36
36
|
def read_attribute(attr_name)
|
37
|
-
if self.class.belongs_to_hstore_attributes[attr_name]
|
38
|
-
send(attr_name)
|
37
|
+
if attr_type = self.class.belongs_to_hstore_attributes[attr_name]
|
38
|
+
attr_value = send(attr_name)
|
39
|
+
if attr_type == Integer
|
40
|
+
attr_value = (attr_value.is_a?(String) && attr_value.empty?) ? nil : attr_value.to_i
|
41
|
+
end
|
42
|
+
attr_value
|
39
43
|
else
|
40
44
|
super
|
41
45
|
end
|
@@ -10,7 +10,7 @@ class Widget < ActiveRecord::Base
|
|
10
10
|
end
|
11
11
|
|
12
12
|
class ExtendedWidget < Widget
|
13
|
-
belongs_to_hstore :properties, :
|
13
|
+
belongs_to_hstore :properties, :additional_item, :class_name => 'Item'
|
14
14
|
end
|
15
15
|
|
16
16
|
class Item < ActiveRecord::Base
|
@@ -18,6 +18,7 @@ end
|
|
18
18
|
|
19
19
|
describe BelongsToHstore do
|
20
20
|
let(:item) { Item.create }
|
21
|
+
let(:extra_item) { Item.create(:name=>'extra') }
|
21
22
|
let(:widget) { Widget.new }
|
22
23
|
let(:extended_widget) { ExtendedWidget.new }
|
23
24
|
|
@@ -61,17 +62,26 @@ describe BelongsToHstore do
|
|
61
62
|
end
|
62
63
|
|
63
64
|
it 'sets/gets properties from subclass' do
|
64
|
-
extended_widget.
|
65
|
-
extended_widget.properties['
|
66
|
-
extended_widget.
|
65
|
+
extended_widget.additional_item = item
|
66
|
+
extended_widget.properties['additional_item_id'].should == item.id.to_s
|
67
|
+
extended_widget.additional_item.should == item
|
67
68
|
end
|
68
69
|
|
69
70
|
it 'does not add subclass properties to base class' do
|
70
|
-
expect{widget.
|
71
|
-
expect{widget.
|
71
|
+
expect{widget.additional_item = item}.to raise_error(NameError)
|
72
|
+
expect{widget.additional_item}.to raise_error(NameError)
|
72
73
|
Widget.belongs_to_hstore_attributes.should include('item_id')
|
73
74
|
Widget.belongs_to_hstore_attributes.should_not include('additional_item_id')
|
74
75
|
end
|
75
76
|
end
|
76
77
|
|
78
|
+
context 'preload associations' do
|
79
|
+
it 'works with includes' do
|
80
|
+
5.times { ExtendedWidget.create(:name => 'preload', :item => item, :additional_item => extra_item) }
|
81
|
+
widgets = ExtendedWidget.where(:name => 'preload').includes(:item, :additional_item).to_a
|
82
|
+
expect(widgets.size).to eq(5)
|
83
|
+
expect(widgets[0].item).to eq(widgets[1].item)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
77
87
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -6,6 +6,9 @@
|
|
6
6
|
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
7
7
|
Dir[File.expand_path("spec/support/**/*.rb")].each { |f| require f }
|
8
8
|
require 'belongs_to_hstore'
|
9
|
+
require 'coveralls'
|
10
|
+
|
11
|
+
Coveralls.wear!
|
9
12
|
|
10
13
|
RSpec.configure do |config|
|
11
14
|
config.treat_symbols_as_metadata_keys_with_true_values = true
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: belongs_to_hstore
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Evan Lok
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-06-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -38,48 +38,6 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '1.3'
|
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: '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
|
-
- !ruby/object:Gem::Dependency
|
70
|
-
name: sqlite3
|
71
|
-
requirement: !ruby/object:Gem::Requirement
|
72
|
-
requirements:
|
73
|
-
- - ">="
|
74
|
-
- !ruby/object:Gem::Version
|
75
|
-
version: '0'
|
76
|
-
type: :development
|
77
|
-
prerelease: false
|
78
|
-
version_requirements: !ruby/object:Gem::Requirement
|
79
|
-
requirements:
|
80
|
-
- - ">="
|
81
|
-
- !ruby/object:Gem::Version
|
82
|
-
version: '0'
|
83
41
|
description: Allows hstore columns to store belongs_to association foreign keys with
|
84
42
|
the same functionality as the default belongs_to
|
85
43
|
email:
|
@@ -126,7 +84,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
126
84
|
version: '0'
|
127
85
|
requirements: []
|
128
86
|
rubyforge_project:
|
129
|
-
rubygems_version: 2.2.
|
87
|
+
rubygems_version: 2.2.2
|
130
88
|
signing_key:
|
131
89
|
specification_version: 4
|
132
90
|
summary: Allows hstore columns to store belongs_to associations
|