redis_orm 0.7 → 0.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 +7 -0
- data/README.md +1 -1
- data/lib/redis_orm.rb +8 -13
- data/lib/redis_orm/associations/has_many.rb +7 -3
- data/lib/redis_orm/redis_orm.rb +3 -5
- metadata +64 -124
- data/Gemfile +0 -10
- data/Manifest +0 -74
- data/Rakefile +0 -25
- data/benchmarks/sortable_benchmark.rb +0 -45
- data/redis_orm.gemspec +0 -45
- data/spec/generators/model_generator_spec.rb +0 -29
- data/spec/spec_helper.rb +0 -17
- data/test/association_indices_test.rb +0 -168
- data/test/associations_test.rb +0 -294
- data/test/atomicity_test.rb +0 -36
- data/test/basic_functionality_test.rb +0 -204
- data/test/callbacks_test.rb +0 -49
- data/test/changes_array_test.rb +0 -25
- data/test/classes/album.rb +0 -6
- data/test/classes/article.rb +0 -7
- data/test/classes/article_with_comments.rb +0 -8
- data/test/classes/book.rb +0 -6
- data/test/classes/catalog_item.rb +0 -5
- data/test/classes/category.rb +0 -7
- data/test/classes/city.rb +0 -7
- data/test/classes/comment.rb +0 -26
- data/test/classes/country.rb +0 -5
- data/test/classes/custom_user.rb +0 -8
- data/test/classes/cutout.rb +0 -20
- data/test/classes/cutout_aggregator.rb +0 -5
- data/test/classes/default_user.rb +0 -10
- data/test/classes/dynamic_finder_user.rb +0 -8
- data/test/classes/empty_person.rb +0 -2
- data/test/classes/expire_user.rb +0 -8
- data/test/classes/expire_user_with_predicate.rb +0 -13
- data/test/classes/giftcard.rb +0 -6
- data/test/classes/jigsaw.rb +0 -4
- data/test/classes/location.rb +0 -5
- data/test/classes/message.rb +0 -4
- data/test/classes/note.rb +0 -5
- data/test/classes/omni_user.rb +0 -8
- data/test/classes/person.rb +0 -6
- data/test/classes/photo.rb +0 -21
- data/test/classes/profile.rb +0 -9
- data/test/classes/sortable_user.rb +0 -11
- data/test/classes/timestamp.rb +0 -3
- data/test/classes/user.rb +0 -39
- data/test/classes/uuid_default_user.rb +0 -12
- data/test/classes/uuid_timestamp.rb +0 -5
- data/test/classes/uuid_user.rb +0 -13
- data/test/dynamic_finders_test.rb +0 -51
- data/test/exceptions_test.rb +0 -47
- data/test/expire_records_test.rb +0 -64
- data/test/has_one_has_many_test.rb +0 -42
- data/test/indices_test.rb +0 -63
- data/test/modules/belongs_to_model_within_module.rb +0 -6
- data/test/modules/has_many_model_within_module.rb +0 -11
- data/test/options_test.rb +0 -226
- data/test/polymorphic_test.rb +0 -65
- data/test/redis.conf +0 -417
- data/test/sortable_test.rb +0 -116
- data/test/test_helper.rb +0 -37
- data/test/uuid_as_id_test.rb +0 -178
- data/test/validations_test.rb +0 -20
data/test/sortable_test.rb
DELETED
@@ -1,116 +0,0 @@
|
|
1
|
-
require File.dirname(File.expand_path(__FILE__)) + '/test_helper.rb'
|
2
|
-
|
3
|
-
describe "test options" do
|
4
|
-
before(:each) do
|
5
|
-
@dan = SortableUser.create :name => "Daniel", :age => 26, :wage => 40000.0, :address => "Bellevue"
|
6
|
-
@abe = SortableUser.create :name => "Abe", :age => 30, :wage => 100000.0, :address => "Bellevue"
|
7
|
-
@michael = SortableUser.create :name => "Michael", :age => 25, :wage => 60000.0, :address => "Bellevue"
|
8
|
-
@todd = SortableUser.create :name => "Todd", :age => 22, :wage => 30000.0, :address => "Bellevue"
|
9
|
-
end
|
10
|
-
|
11
|
-
it "should return records in specified order" do
|
12
|
-
$redis.llen("sortable_user:name_ids").to_i.should == SortableUser.count
|
13
|
-
$redis.zcard("sortable_user:age_ids").to_i.should == SortableUser.count
|
14
|
-
$redis.zcard("sortable_user:wage_ids").to_i.should == SortableUser.count
|
15
|
-
|
16
|
-
SortableUser.find(:all, :order => [:name, :asc]).should == [@abe, @dan, @michael, @todd]
|
17
|
-
SortableUser.find(:all, :order => [:name, :desc]).should == [@todd, @michael, @dan, @abe]
|
18
|
-
|
19
|
-
SortableUser.find(:all, :order => [:age, :asc]).should == [@todd, @michael, @dan, @abe]
|
20
|
-
SortableUser.find(:all, :order => [:age, :desc]).should == [@abe, @dan, @michael, @todd]
|
21
|
-
|
22
|
-
SortableUser.find(:all, :order => [:wage, :asc]).should == [@todd, @dan, @michael, @abe]
|
23
|
-
SortableUser.find(:all, :order => [:wage, :desc]).should == [@abe, @michael, @dan, @todd]
|
24
|
-
end
|
25
|
-
|
26
|
-
it "should return records which met specified conditions in specified order" do
|
27
|
-
@abe2 = SortableUser.create :name => "Abe", :age => 12, :wage => 10.0, :address => "Santa Fe"
|
28
|
-
|
29
|
-
# :asc should be default value for property in :order clause
|
30
|
-
SortableUser.find(:all, :conditions => {:name => "Abe"}, :order => [:wage]).should == [@abe2, @abe]
|
31
|
-
|
32
|
-
SortableUser.find(:all, :conditions => {:name => "Abe"}, :order => [:wage, :desc]).should == [@abe, @abe2]
|
33
|
-
SortableUser.find(:all, :conditions => {:name => "Abe"}, :order => [:wage, :asc]).should == [@abe2, @abe]
|
34
|
-
|
35
|
-
SortableUser.find(:all, :conditions => {:name => "Abe"}, :order => [:age, :desc]).should == [@abe, @abe2]
|
36
|
-
SortableUser.find(:all, :conditions => {:name => "Abe"}, :order => [:age, :asc]).should == [@abe2, @abe]
|
37
|
-
|
38
|
-
SortableUser.find(:all, :conditions => {:name => "Abe"}, :order => [:wage, :desc]).should == [@abe, @abe2]
|
39
|
-
SortableUser.find(:all, :conditions => {:name => "Abe"}, :order => [:wage, :asc]).should == [@abe2, @abe]
|
40
|
-
end
|
41
|
-
|
42
|
-
it "should update keys after the persisted object was edited and sort properly" do
|
43
|
-
@abe.update_attributes :name => "Zed", :age => 12, :wage => 10.0, :address => "Santa Fe"
|
44
|
-
|
45
|
-
$redis.llen("sortable_user:name_ids").to_i.should == SortableUser.count
|
46
|
-
$redis.zcard("sortable_user:age_ids").to_i.should == SortableUser.count
|
47
|
-
$redis.zcard("sortable_user:wage_ids").to_i.should == SortableUser.count
|
48
|
-
|
49
|
-
SortableUser.find(:all, :order => [:name, :asc]).should == [@dan, @michael, @todd, @abe]
|
50
|
-
SortableUser.find(:all, :order => [:name, :desc]).should == [@abe, @todd, @michael, @dan]
|
51
|
-
|
52
|
-
SortableUser.find(:all, :order => [:age, :asc]).should == [@abe, @todd, @michael, @dan]
|
53
|
-
SortableUser.find(:all, :order => [:age, :desc]).should == [@dan, @michael, @todd, @abe]
|
54
|
-
|
55
|
-
SortableUser.find(:all, :order => [:wage, :asc]).should == [@abe, @todd, @dan, @michael]
|
56
|
-
SortableUser.find(:all, :order => [:wage, :desc]).should == [@michael, @dan, @todd, @abe]
|
57
|
-
end
|
58
|
-
|
59
|
-
it "should update keys after the persisted object was deleted and sort properly" do
|
60
|
-
user_count = SortableUser.count
|
61
|
-
@abe.destroy
|
62
|
-
|
63
|
-
$redis.llen("sortable_user:name_ids").to_i.should == user_count - 1
|
64
|
-
$redis.zcard("sortable_user:age_ids").to_i.should == user_count - 1
|
65
|
-
$redis.zcard("sortable_user:wage_ids").to_i.should == user_count - 1
|
66
|
-
|
67
|
-
SortableUser.find(:all, :order => [:name, :asc]).should == [@dan, @michael, @todd]
|
68
|
-
SortableUser.find(:all, :order => [:name, :desc]).should == [@todd, @michael, @dan]
|
69
|
-
|
70
|
-
SortableUser.find(:all, :order => [:age, :asc]).should == [@todd, @michael, @dan]
|
71
|
-
SortableUser.find(:all, :order => [:age, :desc]).should == [@dan, @michael, @todd]
|
72
|
-
|
73
|
-
SortableUser.find(:all, :order => [:wage, :asc]).should == [@todd, @dan, @michael]
|
74
|
-
SortableUser.find(:all, :order => [:wage, :desc]).should == [@michael, @dan, @todd]
|
75
|
-
end
|
76
|
-
|
77
|
-
it "should sort objects with more than 3-4 symbols" do
|
78
|
-
vladislav = SortableUser.create :name => "Vladislav", :age => 19, :wage => 120.0
|
79
|
-
vladimir = SortableUser.create :name => "Vladimir", :age => 22, :wage => 220.5
|
80
|
-
vlad = SortableUser.create :name => "Vlad", :age => 29, :wage => 1200.0
|
81
|
-
|
82
|
-
SortableUser.find(:all, :order => [:name, :desc], :limit => 3).should == [vladislav, vladimir, vlad]
|
83
|
-
SortableUser.find(:all, :order => [:name, :desc], :limit => 2, :offset => 4).should == [@michael, @dan]
|
84
|
-
SortableUser.find(:all, :order => [:name, :desc], :offset => 3).should == [@todd, @michael, @dan, @abe]
|
85
|
-
SortableUser.find(:all, :order => [:name, :desc]).should == [vladislav, vladimir, vlad, @todd, @michael, @dan, @abe]
|
86
|
-
|
87
|
-
SortableUser.find(:all, :order => [:name, :asc], :limit => 3, :offset => 4).should == [vlad, vladimir, vladislav]
|
88
|
-
SortableUser.find(:all, :order => [:name, :asc], :offset => 3).should == [@todd, vlad, vladimir, vladislav]
|
89
|
-
SortableUser.find(:all, :order => [:name, :asc], :limit => 3).should == [@abe, @dan, @michael]
|
90
|
-
SortableUser.find(:all, :order => [:name, :asc]).should == [@abe, @dan, @michael, @todd, vlad, vladimir, vladislav]
|
91
|
-
end
|
92
|
-
|
93
|
-
it "should properly handle multiple users with almost the same names" do
|
94
|
-
users = [@abe, @todd, @michael, @dan]
|
95
|
-
20.times{|i| users << SortableUser.create(:name => "user#{i}") }
|
96
|
-
users.sort{|n,m| n.name <=> m.name}.should == SortableUser.all(:order => [:name, :asc])
|
97
|
-
end
|
98
|
-
|
99
|
-
it "should properly handle multiple users with almost the same names (descending order)" do
|
100
|
-
rev_users = [@abe, @todd, @michael, @dan]
|
101
|
-
20.times{|i| rev_users << SortableUser.create(:name => "user#{i}") }
|
102
|
-
SortableUser.all(:order => [:name, :desc]).should == rev_users.sort{|n,m| n.name <=> m.name}.reverse
|
103
|
-
end
|
104
|
-
|
105
|
-
it "should properly store records with the same names" do
|
106
|
-
users = [@abe, @todd, @michael, @dan]
|
107
|
-
users << SortableUser.create(:name => "user#1")
|
108
|
-
users << SortableUser.create(:name => "user#2")
|
109
|
-
users << SortableUser.create(:name => "user#1")
|
110
|
-
users << SortableUser.create(:name => "user#2")
|
111
|
-
|
112
|
-
# we pluck only *name* here since it didn't sort by id (and it could be messed up)
|
113
|
-
SortableUser.all(:order => [:name, :desc]).map{|u| u.name}.should == users.sort{|n,m| n.name <=> m.name}.map{|u| u.name}.reverse
|
114
|
-
SortableUser.all(:order => [:name, :asc]).map{|u| u.name}.should == users.sort{|n,m| n.name <=> m.name}.map{|u| u.name}
|
115
|
-
end
|
116
|
-
end
|
data/test/test_helper.rb
DELETED
@@ -1,37 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require 'rspec'
|
4
|
-
require 'rspec/autorun'
|
5
|
-
require File.dirname(File.expand_path(__FILE__)) + '/../lib/redis_orm.rb'
|
6
|
-
|
7
|
-
Dir.glob(['test/classes/*.rb', 'test/modules/*.rb']).each do |klassfile|
|
8
|
-
require File.dirname(File.expand_path(__FILE__)) + '/../' + klassfile
|
9
|
-
end
|
10
|
-
|
11
|
-
|
12
|
-
RSpec.configure do |config|
|
13
|
-
config.before(:all) do
|
14
|
-
path_to_conf = File.dirname(File.expand_path(__FILE__)) + "/redis.conf"
|
15
|
-
$redis_pid = spawn 'redis-server ' + path_to_conf, :out => "/dev/null"
|
16
|
-
sleep(0.3) # must be some delay otherwise "Connection refused - Unable to connect to Redis"
|
17
|
-
path_to_socket = File.dirname(File.expand_path(__FILE__)) + "/../redis.sock"
|
18
|
-
begin
|
19
|
-
$redis = Redis.new(:host => 'localhost', :path => path_to_socket)
|
20
|
-
rescue => e
|
21
|
-
puts 'Unable to create connection to the redis server: ' + e.message.inspect
|
22
|
-
Process.kill 9, $redis_pid.to_i if $redis_pid
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
config.after(:all) do
|
27
|
-
Process.kill 9, $redis_pid.to_i if $redis_pid
|
28
|
-
end
|
29
|
-
|
30
|
-
config.after(:each) do
|
31
|
-
$redis.flushall if $redis
|
32
|
-
end
|
33
|
-
|
34
|
-
config.before(:each) do
|
35
|
-
$redis.flushall if $redis
|
36
|
-
end
|
37
|
-
end
|
data/test/uuid_as_id_test.rb
DELETED
@@ -1,178 +0,0 @@
|
|
1
|
-
require File.dirname(File.expand_path(__FILE__)) + '/test_helper.rb'
|
2
|
-
|
3
|
-
describe "check basic functionality" do
|
4
|
-
it "test_simple_creation" do
|
5
|
-
UuidUser.count.should == 0
|
6
|
-
|
7
|
-
user = UuidUser.new :name => "german"
|
8
|
-
user.save
|
9
|
-
|
10
|
-
user.should be
|
11
|
-
user.id.should be
|
12
|
-
|
13
|
-
user.id.should_not == 1
|
14
|
-
user.id.length.should == 32 # b57525b09a69012e8fbe001d61192f09 for example
|
15
|
-
|
16
|
-
user.name.should == "german"
|
17
|
-
|
18
|
-
UuidUser.count.should == 1
|
19
|
-
UuidUser.first.name.should == "german"
|
20
|
-
end
|
21
|
-
|
22
|
-
it "should test different ways to update a record" do
|
23
|
-
UuidUser.count.should == 0
|
24
|
-
|
25
|
-
user = UuidUser.new :name => "german"
|
26
|
-
user.should be
|
27
|
-
user.save
|
28
|
-
|
29
|
-
user.name.should == "german"
|
30
|
-
|
31
|
-
user.name = "nobody"
|
32
|
-
user.save
|
33
|
-
|
34
|
-
UuidUser.count.should == 1
|
35
|
-
UuidUser.first.name.should == "nobody"
|
36
|
-
|
37
|
-
u = UuidUser.first
|
38
|
-
u.should be
|
39
|
-
u.id.should_not == 1
|
40
|
-
u.id.length.should == 32
|
41
|
-
u.update_attribute :name, "root"
|
42
|
-
UuidUser.first.name.should == "root"
|
43
|
-
|
44
|
-
u = UuidUser.first
|
45
|
-
u.should be
|
46
|
-
u.update_attributes :name => "german"
|
47
|
-
UuidUser.first.name.should == "german"
|
48
|
-
end
|
49
|
-
|
50
|
-
it "test_deletion" do
|
51
|
-
UuidUser.count.should == 0
|
52
|
-
|
53
|
-
user = UuidUser.new :name => "german"
|
54
|
-
user.save
|
55
|
-
user.should be
|
56
|
-
|
57
|
-
user.name.should == "german"
|
58
|
-
|
59
|
-
UuidUser.count.should == 1
|
60
|
-
id = user.id
|
61
|
-
|
62
|
-
user.destroy
|
63
|
-
UuidUser.count.should == 0
|
64
|
-
$redis.zrank("user:ids", id).should == nil
|
65
|
-
$redis.hgetall("user:#{id}").should == {}
|
66
|
-
end
|
67
|
-
|
68
|
-
it "should return first and last objects" do
|
69
|
-
UuidUser.count.should == 0
|
70
|
-
UuidUser.first.should == nil
|
71
|
-
UuidUser.last.should == nil
|
72
|
-
|
73
|
-
user1 = UuidUser.new :name => "german"
|
74
|
-
user1.save
|
75
|
-
user1.should be
|
76
|
-
user1.name.should == "german"
|
77
|
-
user1.id.should_not == 1
|
78
|
-
user1.id.length.should == 32 # b57525b09a69012e8fbe001d61192f09 for example
|
79
|
-
|
80
|
-
user2 = UuidUser.new :name => "nobody"
|
81
|
-
user2.save
|
82
|
-
user2.should be
|
83
|
-
user2.name.should == "nobody"
|
84
|
-
user2.id.should_not == 2
|
85
|
-
user2.id.length.should == 32
|
86
|
-
|
87
|
-
UuidUser.count.should == 2
|
88
|
-
|
89
|
-
UuidUser.first.should be
|
90
|
-
UuidUser.last.should be
|
91
|
-
|
92
|
-
UuidUser.first.id.should == user1.id
|
93
|
-
UuidUser.last.id.should == user2.id
|
94
|
-
end
|
95
|
-
|
96
|
-
it "should return values with correct classes" do
|
97
|
-
user = UuidUser.new
|
98
|
-
user.name = "german"
|
99
|
-
user.age = 26
|
100
|
-
user.wage = 124.34
|
101
|
-
user.male = true
|
102
|
-
user.save
|
103
|
-
|
104
|
-
user.should be
|
105
|
-
|
106
|
-
u = UuidUser.first
|
107
|
-
|
108
|
-
u.created_at.class.should == DateTime
|
109
|
-
u.modified_at.class.should == DateTime
|
110
|
-
u.wage.class.should == Float
|
111
|
-
u.male.class.to_s.should match(/TrueClass|FalseClass/)
|
112
|
-
u.age.class.to_s.should match(/Integer|Fixnum/)
|
113
|
-
u.id.should_not == 1
|
114
|
-
u.id.length.should == 32
|
115
|
-
|
116
|
-
u.name.should == "german"
|
117
|
-
u.wage.should == 124.34
|
118
|
-
u.age.should == 26
|
119
|
-
u.male.should == true
|
120
|
-
end
|
121
|
-
|
122
|
-
it "should return correct saved defaults" do
|
123
|
-
UuidDefaultUser.count.should == 0
|
124
|
-
UuidDefaultUser.create
|
125
|
-
UuidDefaultUser.count.should == 1
|
126
|
-
|
127
|
-
u = UuidDefaultUser.first
|
128
|
-
|
129
|
-
u.created_at.class.should == DateTime
|
130
|
-
u.modified_at.class.should == DateTime
|
131
|
-
u.wage.class.should == Float
|
132
|
-
u.male.class.to_s.should match(/TrueClass|FalseClass/)
|
133
|
-
u.admin.class.to_s.should match(/TrueClass|FalseClass/)
|
134
|
-
u.age.class.to_s.should match(/Integer|Fixnum/)
|
135
|
-
|
136
|
-
u.name.should == "german"
|
137
|
-
u.male.should == true
|
138
|
-
u.age.should == 26
|
139
|
-
u.wage.should == 256.25
|
140
|
-
u.admin.should == false
|
141
|
-
u.id.should_not == 1
|
142
|
-
u.id.length.should == 32
|
143
|
-
|
144
|
-
du = UuidDefaultUser.new
|
145
|
-
du.name = "germaninthetown"
|
146
|
-
du.save
|
147
|
-
|
148
|
-
du_saved = UuidDefaultUser.last
|
149
|
-
du_saved.name.should == "germaninthetown"
|
150
|
-
du_saved.admin.should == false
|
151
|
-
du.id.should_not == 2
|
152
|
-
du.id.should_not == u.id
|
153
|
-
du.id.length.should == 32
|
154
|
-
end
|
155
|
-
|
156
|
-
it "should expand timestamps declaration properly" do
|
157
|
-
t = UuidTimeStamp.new
|
158
|
-
t.save
|
159
|
-
|
160
|
-
t.created_at.should be
|
161
|
-
t.modified_at.should be
|
162
|
-
t.created_at.day.should == Time.now.day
|
163
|
-
t.modified_at.day.should == Time.now.day
|
164
|
-
end
|
165
|
-
|
166
|
-
# from associations_test.rb
|
167
|
-
it "should maintain correct self referencing link" do
|
168
|
-
me = UuidUser.create :name => "german", :age => 26, :wage => 10.0, :male => true
|
169
|
-
friend1 = UuidUser.create :name => "friend1", :age => 26, :wage => 7.0, :male => true
|
170
|
-
friend2 = UuidUser.create :name => "friend2", :age => 25, :wage => 5.0, :male => true
|
171
|
-
|
172
|
-
me.friends << [friend1, friend2]
|
173
|
-
|
174
|
-
me.friends.count.should == 2
|
175
|
-
friend1.friends.count.should == 0
|
176
|
-
friend2.friends.count.should == 0
|
177
|
-
end
|
178
|
-
end
|
data/test/validations_test.rb
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
require File.dirname(File.expand_path(__FILE__)) + '/test_helper.rb'
|
2
|
-
|
3
|
-
describe "check associations" do
|
4
|
-
it "should validate presence if image in photo" do
|
5
|
-
p = Photo.new
|
6
|
-
p.save.should == false
|
7
|
-
p.errors.should be
|
8
|
-
p.errors[:image].should include("can't be blank")
|
9
|
-
|
10
|
-
p.image = "test"
|
11
|
-
p.save.should == false
|
12
|
-
p.errors.should be
|
13
|
-
p.errors[:image].should include("is too short (minimum is 7 characters)")
|
14
|
-
p.errors[:image].should include("is invalid")
|
15
|
-
|
16
|
-
p.image = "facepalm.jpg"
|
17
|
-
p.save
|
18
|
-
p.errors.empty?.should == true
|
19
|
-
end
|
20
|
-
end
|