activerecord2-hstore 1.0.3 → 1.0.4
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.
- data/CHANGELOG +5 -1
- data/lib/activerecord2-hstore/hstore.rb +3 -3
- data/lib/activerecord2-hstore/version.rb +1 -1
- data/spec/hstore_spec.rb +36 -9
- metadata +4 -4
data/CHANGELOG
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
1.0.4
|
2
|
+
* Better fix for passing in nil, string, or hash into ActiveRecord setter (@kwstannard)
|
3
|
+
* Additional and improved specs
|
4
|
+
|
1
5
|
1.0.3
|
2
6
|
* Corrected ActiveRecord setter to allow for nil input (again)
|
3
7
|
|
@@ -5,7 +9,7 @@
|
|
5
9
|
* Corrected ActiveRecord setter to allow for nil input
|
6
10
|
|
7
11
|
1.0.1
|
8
|
-
* Corrected Hash.to_hstore to take into account apostrophes (
|
12
|
+
* Corrected Hash.to_hstore to take into account apostrophes (@sisk)
|
9
13
|
|
10
14
|
1.0.0
|
11
15
|
* First release
|
@@ -28,9 +28,9 @@ module Hstore
|
|
28
28
|
end
|
29
29
|
|
30
30
|
define_method "#{column}=".to_sym do |value|
|
31
|
-
|
32
|
-
|
33
|
-
write_attribute(column.to_sym,
|
31
|
+
val = {}.to_hstore if value.nil?
|
32
|
+
val ||= value.is_a?(String) ? value : value.to_hstore
|
33
|
+
write_attribute(column.to_sym, val)
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
data/spec/hstore_spec.rb
CHANGED
@@ -50,8 +50,8 @@ describe Hstore do
|
|
50
50
|
end
|
51
51
|
|
52
52
|
describe "setter method" do
|
53
|
-
it "uses ActiveRecord's write_attribute" do
|
54
|
-
subject.should_receive(:write_attribute)
|
53
|
+
it "uses ActiveRecord's write_attribute and accepts a hash" do
|
54
|
+
subject.should_receive(:write_attribute).with(:some_field, "a=>b")
|
55
55
|
subject.some_field = {:a => :b}
|
56
56
|
end
|
57
57
|
|
@@ -61,20 +61,47 @@ describe Hstore do
|
|
61
61
|
end
|
62
62
|
|
63
63
|
it "can also accept a hstore string instead of a hash" do
|
64
|
-
subject.
|
64
|
+
subject.should_receive(:write_attribute).with(:some_field, "a=>b")
|
65
65
|
subject.some_field = "a=>b"
|
66
66
|
end
|
67
67
|
end
|
68
68
|
end
|
69
69
|
|
70
|
+
describe "reading attributes" do
|
71
|
+
before(:each) do
|
72
|
+
MyHstore.create( :label=> "A", :some_field => {"key" => "1"} )
|
73
|
+
MyHstore.create( :label=> "B", :some_field => "" )
|
74
|
+
MyHstore.create( :label=> "C", :some_field => nil )
|
75
|
+
end
|
76
|
+
|
77
|
+
it "should return a hash for label A" do
|
78
|
+
result = MyHstore.find_by_label("A")
|
79
|
+
result.label.should == "A"
|
80
|
+
result.some_field.should == {"key" => "1"}
|
81
|
+
end
|
82
|
+
|
83
|
+
it "should return an empty hash for label B (empty string passed in)" do
|
84
|
+
result = MyHstore.find_by_label("B")
|
85
|
+
result.label.should == "B"
|
86
|
+
result.some_field.should == {}
|
87
|
+
end
|
88
|
+
|
89
|
+
it "should return an empty hash for label C (nil passed in)" do
|
90
|
+
result = MyHstore.find_by_label("C")
|
91
|
+
result.label.should == "C"
|
92
|
+
result.some_field.should == {}
|
93
|
+
end
|
94
|
+
|
95
|
+
end
|
96
|
+
|
70
97
|
describe "querying data" do
|
71
98
|
before(:each) do
|
72
|
-
MyHstore.create( :label=> "A", :some_field => {"key" => "1"}
|
73
|
-
MyHstore.create( :label=> "B", :some_field => {:key => 1, "a" => "b"}
|
74
|
-
MyHstore.create( :label=> "C", :some_field => {"key" => "2"}
|
75
|
-
MyHstore.create( :label=> "D", :some_field => {"key" => "3"}
|
76
|
-
MyHstore.create( :label=> "E", :some_field => {"key" => "123456789"}
|
77
|
-
MyHstore.create( :label=> "F", :some_field => {"c" => "x"}
|
99
|
+
MyHstore.create( :label=> "A", :some_field => {"key" => "1"} )
|
100
|
+
MyHstore.create( :label=> "B", :some_field => {:key => 1, "a" => "b"} )
|
101
|
+
MyHstore.create( :label=> "C", :some_field => {"key" => "2"} )
|
102
|
+
MyHstore.create( :label=> "D", :some_field => {"key" => "3"} )
|
103
|
+
MyHstore.create( :label=> "E", :some_field => {"key" => "123456789"} )
|
104
|
+
MyHstore.create( :label=> "F", :some_field => {"c" => "x"} )
|
78
105
|
end
|
79
106
|
|
80
107
|
it "queries for the records containing a specific key" do
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activerecord2-hstore
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 31
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 1.0.
|
9
|
+
- 4
|
10
|
+
version: 1.0.4
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Tony Drake
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2012-07-
|
18
|
+
date: 2012-07-31 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: rspec
|