redis_orm 0.4.1 → 0.4.2
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +6 -0
- data/Rakefile +1 -1
- data/lib/redis_orm/redis_orm.rb +22 -13
- data/redis_orm.gemspec +2 -2
- data/test/options_test.rb +44 -2
- data/test/polymorphic_test.rb +16 -0
- metadata +10 -10
data/CHANGELOG
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
v0.4.2 [25-06-2011]
|
2
|
+
* fixed bug with wrong saving of :default value/index for boolean type, fixed bug with #find(:all), #find(:first), #find(:last) function calls, added test for it
|
3
|
+
* added simple test to ensure correct search on boolean properties
|
4
|
+
* properly destroy dependent records
|
5
|
+
* delete polymorphic records properly along with their backlinks
|
6
|
+
|
1
7
|
v0.4.1 [23-06-2011]
|
2
8
|
* fixed clitical bug: records after #destroy still available (added test for it)
|
3
9
|
* added simple atomicity test
|
data/Rakefile
CHANGED
@@ -4,7 +4,7 @@ require 'rake'
|
|
4
4
|
#=begin
|
5
5
|
require 'echoe'
|
6
6
|
|
7
|
-
Echoe.new('redis_orm', '0.4.
|
7
|
+
Echoe.new('redis_orm', '0.4.2') do |p|
|
8
8
|
p.description = "ORM for Redis advanced key-value storage"
|
9
9
|
p.url = "https://github.com/german/redis_orm"
|
10
10
|
p.author = "Dmitrii Samoilov"
|
data/lib/redis_orm/redis_orm.rb
CHANGED
@@ -75,7 +75,7 @@ module RedisOrm
|
|
75
75
|
elsif Float == class_name
|
76
76
|
value = value.to_f
|
77
77
|
elsif RedisOrm::Boolean == class_name
|
78
|
-
value = (value == "false" ? false : true)
|
78
|
+
value = ((value == "false" || value == false) ? false : true)
|
79
79
|
end
|
80
80
|
value
|
81
81
|
end
|
@@ -166,7 +166,7 @@ module RedisOrm
|
|
166
166
|
raise NotIndexFound if !index
|
167
167
|
|
168
168
|
prepared_index = construct_prepared_index(index, options[:conditions])
|
169
|
-
|
169
|
+
|
170
170
|
records = []
|
171
171
|
|
172
172
|
if index[:options][:unique]
|
@@ -177,7 +177,7 @@ module RedisOrm
|
|
177
177
|
records += model_name.to_s.camelize.constantize.find(ids)
|
178
178
|
end
|
179
179
|
records
|
180
|
-
else
|
180
|
+
else
|
181
181
|
if options[:order].to_s == 'desc'
|
182
182
|
$redis.zrevrangebyscore("#{model_name}:ids", Time.now.to_f, 0, :limit => limit).compact.collect{|id| find(id)}
|
183
183
|
else
|
@@ -200,16 +200,16 @@ module RedisOrm
|
|
200
200
|
case first = args.shift
|
201
201
|
when :all
|
202
202
|
options = args.last
|
203
|
-
|
203
|
+
options = {} if !options.is_a?(Hash)
|
204
204
|
all(options)
|
205
205
|
when :first
|
206
206
|
options = args.last
|
207
|
-
|
207
|
+
options = {} if !options.is_a?(Hash)
|
208
208
|
all(options.merge({:limit => 1}))[0]
|
209
209
|
when :last
|
210
210
|
options = args.last
|
211
|
-
|
212
|
-
reversed = options[:order] == '
|
211
|
+
options = {} if !options.is_a?(Hash)
|
212
|
+
reversed = options[:order] == 'desc' ? 'asc' : 'desc'
|
213
213
|
all(options.merge({:limit => 1, :order => reversed}))[0]
|
214
214
|
else
|
215
215
|
id = first
|
@@ -402,7 +402,7 @@ module RedisOrm
|
|
402
402
|
|
403
403
|
@@properties[model_name].each do |prop|
|
404
404
|
prop_value = self.send(prop[:name].to_sym)
|
405
|
-
|
405
|
+
|
406
406
|
if prop_value.nil? && !prop[:options][:default].nil?
|
407
407
|
prop_value = prop[:options][:default]
|
408
408
|
# set instance variable in order to properly save indexes here
|
@@ -479,9 +479,16 @@ module RedisOrm
|
|
479
479
|
when :belongs_to
|
480
480
|
foreign_model = assoc[:foreign_model].to_s
|
481
481
|
foreign_model_name = assoc[:options][:as] ? assoc[:options][:as] : assoc[:foreign_model]
|
482
|
-
|
483
|
-
|
484
|
-
|
482
|
+
if assoc[:options][:polymorphic]
|
483
|
+
records << self.send(foreign_model_name)
|
484
|
+
# get real foreign_model's name in order to delete backlinks properly
|
485
|
+
foreign_model = $redis.get("#{model_name}:#{id}:#{foreign_model_name}_type")
|
486
|
+
$redis.del("#{model_name}:#{id}:#{foreign_model_name}_type")
|
487
|
+
$redis.del("#{model_name}:#{id}:#{foreign_model_name}_id")
|
488
|
+
else
|
489
|
+
records << self.send(foreign_model_name)
|
490
|
+
$redis.del "#{model_name}:#{@id}:#{assoc[:foreign_model]}"
|
491
|
+
end
|
485
492
|
when :has_one
|
486
493
|
foreign_model = assoc[:foreign_model].to_s
|
487
494
|
foreign_model_name = assoc[:options][:as] ? assoc[:options][:as] : assoc[:foreign_model]
|
@@ -520,8 +527,10 @@ module RedisOrm
|
|
520
527
|
end
|
521
528
|
|
522
529
|
if assoc[:options][:dependent] == :destroy
|
523
|
-
records.
|
524
|
-
r
|
530
|
+
if !records.compact.empty?
|
531
|
+
records.compact.each do |r|
|
532
|
+
r.destroy
|
533
|
+
end
|
525
534
|
end
|
526
535
|
end
|
527
536
|
end
|
data/redis_orm.gemspec
CHANGED
@@ -2,11 +2,11 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{redis_orm}
|
5
|
-
s.version = "0.4.
|
5
|
+
s.version = "0.4.2"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = [%q{Dmitrii Samoilov}]
|
9
|
-
s.date = %q{2011-06-
|
9
|
+
s.date = %q{2011-06-25}
|
10
10
|
s.description = %q{ORM for Redis advanced key-value storage}
|
11
11
|
s.email = %q{germaninthetown@gmail.com}
|
12
12
|
s.extra_rdoc_files = [%q{CHANGELOG}, %q{LICENSE}, %q{README.md}, %q{lib/redis_orm.rb}, %q{lib/redis_orm/active_model_behavior.rb}, %q{lib/redis_orm/associations/belongs_to.rb}, %q{lib/redis_orm/associations/has_many.rb}, %q{lib/redis_orm/associations/has_many_proxy.rb}, %q{lib/redis_orm/associations/has_one.rb}, %q{lib/redis_orm/redis_orm.rb}]
|
data/test/options_test.rb
CHANGED
@@ -17,6 +17,12 @@ class Photo < RedisOrm::Base
|
|
17
17
|
property :image, String
|
18
18
|
property :image_type, String
|
19
19
|
|
20
|
+
property :checked, RedisOrm::Boolean, :default => false
|
21
|
+
index :checked
|
22
|
+
|
23
|
+
property :inverted, RedisOrm::Boolean, :default => true
|
24
|
+
index :inverted
|
25
|
+
|
20
26
|
index :image
|
21
27
|
index [:image, :image_type]
|
22
28
|
|
@@ -40,13 +46,13 @@ describe "test options" do
|
|
40
46
|
@album.should be
|
41
47
|
@album.title.should == "my 1st album"
|
42
48
|
|
43
|
-
@photo1 = Photo.new :image => "facepalm.jpg", :image_type => "jpg"
|
49
|
+
@photo1 = Photo.new :image => "facepalm.jpg", :image_type => "jpg", :checked => true
|
44
50
|
@photo1.save
|
45
51
|
@photo1.should be
|
46
52
|
@photo1.image.should == "facepalm.jpg"
|
47
53
|
@photo1.image_type.should == "jpg"
|
48
54
|
|
49
|
-
@photo2 = Photo.new :image => "boobs.png", :image_type => "png"
|
55
|
+
@photo2 = Photo.new :image => "boobs.png", :image_type => "png", :inverted => false
|
50
56
|
@photo2.save
|
51
57
|
@photo2.should be
|
52
58
|
@photo2.image.should == "boobs.png"
|
@@ -70,6 +76,10 @@ describe "test options" do
|
|
70
76
|
|
71
77
|
@album.photos.find(:all, :limit => 1, :offset => 1).size.should == 1
|
72
78
|
|
79
|
+
Photo.find(:all).size.should == 2
|
80
|
+
Photo.find(:first).id.should == @photo1.id
|
81
|
+
Photo.find(:last).id.should == @photo2.id
|
82
|
+
|
73
83
|
Photo.find(:all, :conditions => {:image => "facepalm.jpg"}).size.should == 1
|
74
84
|
Photo.find(:all, :conditions => {:image => "boobs.png"}).size.should == 1
|
75
85
|
|
@@ -89,6 +99,38 @@ describe "test options" do
|
|
89
99
|
Photo.find(:last, :conditions => {:image => "boobs.png", :image_type => "png"}).id.should == @photo2.id
|
90
100
|
end
|
91
101
|
|
102
|
+
it "should correctly save boolean values" do
|
103
|
+
$redis.hgetall("photo:#{@photo1.id}")["inverted"].should == "true"
|
104
|
+
$redis.hgetall("photo:#{@photo2.id}")["inverted"].should == "false"
|
105
|
+
|
106
|
+
@photo1.inverted.should == true
|
107
|
+
@photo2.inverted.should == false
|
108
|
+
|
109
|
+
$redis.zrange("photo:inverted:true", 0, -1).should include(@photo1.id.to_s)
|
110
|
+
$redis.zrange("photo:inverted:false", 0, -1).should include(@photo2.id.to_s)
|
111
|
+
|
112
|
+
$redis.hgetall("photo:#{@photo1.id}")["checked"].should == "true"
|
113
|
+
$redis.hgetall("photo:#{@photo2.id}")["checked"].should == "false"
|
114
|
+
|
115
|
+
@photo1.checked.should == true
|
116
|
+
@photo2.checked.should == false
|
117
|
+
|
118
|
+
$redis.zrange("photo:checked:true", 0, -1).should include(@photo1.id.to_s)
|
119
|
+
$redis.zrange("photo:checked:false", 0, -1).should include(@photo2.id.to_s)
|
120
|
+
end
|
121
|
+
|
122
|
+
it "should search on bool values properly" do
|
123
|
+
Photo.find(:all, :conditions => {:checked => true}).size.should == 1
|
124
|
+
Photo.find(:all, :conditions => {:checked => true}).first.id.should == @photo1.id
|
125
|
+
Photo.find(:all, :conditions => {:checked => false}).size.should == 1
|
126
|
+
Photo.find(:all, :conditions => {:checked => false}).first.id.should == @photo2.id
|
127
|
+
|
128
|
+
Photo.find(:all, :conditions => {:inverted => true}).size.should == 1
|
129
|
+
Photo.find(:all, :conditions => {:inverted => true}).first.id.should == @photo1.id
|
130
|
+
Photo.find(:all, :conditions => {:inverted => false}).size.should == 1
|
131
|
+
Photo.find(:all, :conditions => {:inverted => false}).first.id.should == @photo2.id
|
132
|
+
end
|
133
|
+
|
92
134
|
it "should return correct array when :order option is provided" do
|
93
135
|
Photo.all(:order => "asc").map{|p| p.id}.should == [@photo1.id, @photo2.id]
|
94
136
|
Photo.all(:order => "desc").map{|p| p.id}.should == [@photo2.id, @photo1.id]
|
data/test/polymorphic_test.rb
CHANGED
@@ -85,4 +85,20 @@ describe "check polymorphic property" do
|
|
85
85
|
City.first.people[0].id.should == person.id
|
86
86
|
Country.first.people.count.should == 0
|
87
87
|
end
|
88
|
+
|
89
|
+
it "should delete records properly" do
|
90
|
+
country = Country.create :name => "Ukraine"
|
91
|
+
person = Person.create :name => "german"
|
92
|
+
person.location = country
|
93
|
+
|
94
|
+
Person.first.location.id.should == country.id
|
95
|
+
Country.first.people.count.should == 1
|
96
|
+
Country.first.people[0].id.should == person.id
|
97
|
+
|
98
|
+
person.destroy
|
99
|
+
Person.count.should == 0
|
100
|
+
$redis.hgetall("user:#{person.id}").should == {}
|
101
|
+
$redis.zrank("user:ids", person.id).should == nil
|
102
|
+
Country.first.people.count.should == 0
|
103
|
+
end
|
88
104
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: redis_orm
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-06-
|
12
|
+
date: 2011-06-25 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|
16
|
-
requirement: &
|
16
|
+
requirement: &82547900 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: 3.0.0
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *82547900
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: activemodel
|
27
|
-
requirement: &
|
27
|
+
requirement: &82547630 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: 3.0.0
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *82547630
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: redis
|
38
|
-
requirement: &
|
38
|
+
requirement: &82547320 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: 2.2.0
|
44
44
|
type: :runtime
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *82547320
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: rspec
|
49
|
-
requirement: &
|
49
|
+
requirement: &82547020 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,7 +54,7 @@ dependencies:
|
|
54
54
|
version: 2.5.0
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *82547020
|
58
58
|
description: ORM for Redis advanced key-value storage
|
59
59
|
email: germaninthetown@gmail.com
|
60
60
|
executables: []
|