redis_orm 0.7 → 0.8
Sign up to get free protection for your applications and to get access to all the features.
- 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
@@ -1,10 +0,0 @@
|
|
1
|
-
class DefaultUser < RedisOrm::Base
|
2
|
-
property :name, String, :default => "german"
|
3
|
-
property :age, Integer, :default => 26
|
4
|
-
property :wage, Float, :default => 256.25
|
5
|
-
property :male, RedisOrm::Boolean, :default => true
|
6
|
-
property :admin, RedisOrm::Boolean, :default => false
|
7
|
-
|
8
|
-
property :created_at, Time
|
9
|
-
property :modified_at, Time
|
10
|
-
end
|
data/test/classes/expire_user.rb
DELETED
@@ -1,13 +0,0 @@
|
|
1
|
-
class ExpireUserWithPredicate < RedisOrm::Base
|
2
|
-
property :name, String
|
3
|
-
property :persist, RedisOrm::Boolean, :default => false
|
4
|
-
|
5
|
-
expire 10.minutes.from_now, :if => Proc.new {|r| !r.persist?}
|
6
|
-
|
7
|
-
has_many :articles
|
8
|
-
has_one :profile
|
9
|
-
|
10
|
-
def persist?
|
11
|
-
!!self.persist
|
12
|
-
end
|
13
|
-
end
|
data/test/classes/giftcard.rb
DELETED
data/test/classes/jigsaw.rb
DELETED
data/test/classes/location.rb
DELETED
data/test/classes/message.rb
DELETED
data/test/classes/note.rb
DELETED
data/test/classes/omni_user.rb
DELETED
data/test/classes/person.rb
DELETED
data/test/classes/photo.rb
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
class Photo < RedisOrm::Base
|
2
|
-
property :image, String
|
3
|
-
property :image_type, String
|
4
|
-
|
5
|
-
property :checked, RedisOrm::Boolean, :default => false
|
6
|
-
index :checked
|
7
|
-
|
8
|
-
property :inverted, RedisOrm::Boolean, :default => true
|
9
|
-
index :inverted
|
10
|
-
|
11
|
-
index :image
|
12
|
-
index [:image, :image_type]
|
13
|
-
|
14
|
-
belongs_to :album
|
15
|
-
belongs_to :user
|
16
|
-
belongs_to :category
|
17
|
-
|
18
|
-
validates_presence_of :image
|
19
|
-
validates_length_of :image, :in => 7..32
|
20
|
-
validates_format_of :image, :with => /\w*\.(gif|jpe?g|png)/
|
21
|
-
end
|
data/test/classes/profile.rb
DELETED
@@ -1,11 +0,0 @@
|
|
1
|
-
class SortableUser < RedisOrm::Base
|
2
|
-
property :name, String, :sortable => true
|
3
|
-
property :age, Integer, :sortable => true, :default => 26.0
|
4
|
-
property :wage, Float, :sortable => true, :default => 20_000
|
5
|
-
property :address, String, :default => "Singa_poor"
|
6
|
-
|
7
|
-
property :test_type_cast, RedisOrm::Boolean, :default => "false"
|
8
|
-
|
9
|
-
index :age
|
10
|
-
index :name
|
11
|
-
end
|
data/test/classes/timestamp.rb
DELETED
data/test/classes/user.rb
DELETED
@@ -1,39 +0,0 @@
|
|
1
|
-
class User < RedisOrm::Base
|
2
|
-
property :name, String
|
3
|
-
property :first_name, String
|
4
|
-
property :last_name, String
|
5
|
-
property :karma, Integer, :default => 1000
|
6
|
-
property :age, Integer
|
7
|
-
property :wage, Float
|
8
|
-
property :male, RedisOrm::Boolean
|
9
|
-
property :created_at, Time
|
10
|
-
property :modified_at, Time
|
11
|
-
property :gender, RedisOrm::Boolean, :default => true
|
12
|
-
property :moderator, RedisOrm::Boolean, :default => false
|
13
|
-
property :moderated_area, String, :default => "messages"
|
14
|
-
|
15
|
-
index :moderator
|
16
|
-
index [:moderator, :moderated_area]
|
17
|
-
index :age
|
18
|
-
index :name
|
19
|
-
index :first_name
|
20
|
-
index :last_name
|
21
|
-
index [:first_name, :last_name]
|
22
|
-
|
23
|
-
has_one :profile, :index => true
|
24
|
-
has_many :comments
|
25
|
-
has_many :users, :as => :friends
|
26
|
-
has_one :photo, :dependent => :destroy
|
27
|
-
has_many :notes
|
28
|
-
|
29
|
-
after_create :store_in_rating
|
30
|
-
after_destroy :after_destroy_callback
|
31
|
-
|
32
|
-
def store_in_rating
|
33
|
-
$redis.zadd "users:sorted_by_rating", 0.0, self.id
|
34
|
-
end
|
35
|
-
|
36
|
-
def after_destroy_callback
|
37
|
-
self.comments.map{|c| c.destroy}
|
38
|
-
end
|
39
|
-
end
|
@@ -1,12 +0,0 @@
|
|
1
|
-
class UuidDefaultUser < RedisOrm::Base
|
2
|
-
use_uuid_as_id
|
3
|
-
|
4
|
-
property :name, String, :default => "german"
|
5
|
-
property :age, Integer, :default => 26
|
6
|
-
property :wage, Float, :default => 256.25
|
7
|
-
property :male, RedisOrm::Boolean, :default => true
|
8
|
-
property :admin, RedisOrm::Boolean, :default => false
|
9
|
-
|
10
|
-
property :created_at, Time
|
11
|
-
property :modified_at, Time
|
12
|
-
end
|
data/test/classes/uuid_user.rb
DELETED
@@ -1,13 +0,0 @@
|
|
1
|
-
class UuidUser < RedisOrm::Base
|
2
|
-
use_uuid_as_id
|
3
|
-
|
4
|
-
property :name, String
|
5
|
-
property :age, Integer
|
6
|
-
property :wage, Float
|
7
|
-
property :male, RedisOrm::Boolean
|
8
|
-
|
9
|
-
property :created_at, Time
|
10
|
-
property :modified_at, Time
|
11
|
-
|
12
|
-
has_many :users, :as => :friends
|
13
|
-
end
|
@@ -1,51 +0,0 @@
|
|
1
|
-
require File.dirname(File.expand_path(__FILE__)) + '/test_helper.rb'
|
2
|
-
|
3
|
-
describe "check associations" do
|
4
|
-
it "should create and use indexes to implement dynamic finders" do
|
5
|
-
user1 = DynamicFinderUser.new
|
6
|
-
user1.first_name = "Dmitrii"
|
7
|
-
user1.last_name = "Samoilov"
|
8
|
-
user1.save
|
9
|
-
|
10
|
-
DynamicFinderUser.find_by_first_name("John").should == nil
|
11
|
-
|
12
|
-
user = DynamicFinderUser.find_by_first_name "Dmitrii"
|
13
|
-
user.id.should == user1.id
|
14
|
-
|
15
|
-
DynamicFinderUser.find_all_by_first_name("Dmitrii").size.should == 1
|
16
|
-
|
17
|
-
user = DynamicFinderUser.find_by_first_name_and_last_name('Dmitrii', 'Samoilov')
|
18
|
-
user.should be
|
19
|
-
user.id.should == user1.id
|
20
|
-
|
21
|
-
DynamicFinderUser.find_all_by_first_name_and_last_name('Dmitrii', 'Samoilov').size.should == 1
|
22
|
-
|
23
|
-
DynamicFinderUser.find_all_by_last_name_and_first_name('Samoilov', 'Dmitrii')[0].id.should == user1.id
|
24
|
-
|
25
|
-
lambda{DynamicFinderUser.find_by_first_name_and_cast_name('Dmitrii', 'Samoilov')}.should raise_error
|
26
|
-
end
|
27
|
-
|
28
|
-
it "should create and use indexes to implement dynamic finders" do
|
29
|
-
user1 = CustomUser.new
|
30
|
-
user1.first_name = "Dmitrii"
|
31
|
-
user1.last_name = "Samoilov"
|
32
|
-
user1.save
|
33
|
-
|
34
|
-
user2 = CustomUser.new
|
35
|
-
user2.first_name = "Dmitrii"
|
36
|
-
user2.last_name = "Nabaldyan"
|
37
|
-
user2.save
|
38
|
-
|
39
|
-
user = CustomUser.find_by_first_name "Dmitrii"
|
40
|
-
user.id.should == user1.id
|
41
|
-
|
42
|
-
CustomUser.find_by_last_name("Krassovkin").should == nil
|
43
|
-
|
44
|
-
CustomUser.find_all_by_first_name("Dmitrii").size.should == 2
|
45
|
-
end
|
46
|
-
|
47
|
-
# TODO
|
48
|
-
it "should properly delete indices when record was deleted" do
|
49
|
-
|
50
|
-
end
|
51
|
-
end
|
data/test/exceptions_test.rb
DELETED
@@ -1,47 +0,0 @@
|
|
1
|
-
require File.dirname(File.expand_path(__FILE__)) + '/test_helper.rb'
|
2
|
-
|
3
|
-
describe "exceptions test" do
|
4
|
-
it "should raise an exception if association is provided with improper class" do
|
5
|
-
User.count.should == 0
|
6
|
-
|
7
|
-
user = User.new :name => "german", :age => 26
|
8
|
-
user.save
|
9
|
-
|
10
|
-
user.should be
|
11
|
-
user.name.should == "german"
|
12
|
-
User.count.should == 1
|
13
|
-
|
14
|
-
lambda{ User.find :all, :conditions => {:gender => true} }.should raise_error
|
15
|
-
User.find(:all, :conditions => {:age => 26}).size.should == 1
|
16
|
-
lambda{ User.find :all, :conditions => {:name => "german", :age => 26} }.should raise_error
|
17
|
-
|
18
|
-
jigsaw = Jigsaw.new
|
19
|
-
jigsaw.title = "123"
|
20
|
-
jigsaw.save
|
21
|
-
|
22
|
-
# RedisOrm::TypeMismatchError
|
23
|
-
lambda { user.profile = jigsaw }.should raise_error
|
24
|
-
end
|
25
|
-
|
26
|
-
it "should raise an exception if there is no such record in the storage" do
|
27
|
-
User.find(12).should == nil
|
28
|
-
lambda{ User.find! 12 }.should raise_error(RedisOrm::RecordNotFound)
|
29
|
-
end
|
30
|
-
|
31
|
-
it "should throw an exception if there was an error while creating object with #create! method" do
|
32
|
-
jigsaw = Jigsaw.create :title => "jigsaw"
|
33
|
-
lambda { User.create!(:name => "John", :age => 44, :profile => jigsaw) }.should raise_error(RedisOrm::TypeMismatchError)
|
34
|
-
end
|
35
|
-
|
36
|
-
it "should throw an exception if wrong format of the default value is specified for Array/Hash property" do
|
37
|
-
a = ArticleWithComments.new :title => "Article #1", :rates => [1,2,3,4,5]
|
38
|
-
lambda {
|
39
|
-
a.save
|
40
|
-
}.should raise_error(RedisOrm::TypeMismatchError)
|
41
|
-
|
42
|
-
a = ArticleWithComments.new :title => "Article #1", :comments => 12
|
43
|
-
lambda {
|
44
|
-
a.save
|
45
|
-
}.should raise_error(RedisOrm::TypeMismatchError)
|
46
|
-
end
|
47
|
-
end
|
data/test/expire_records_test.rb
DELETED
@@ -1,64 +0,0 @@
|
|
1
|
-
require File.dirname(File.expand_path(__FILE__)) + '/test_helper.rb'
|
2
|
-
|
3
|
-
describe "expire record after specified time" do
|
4
|
-
it "should create a record and then delete if *expire* method is specified in appropriate class" do
|
5
|
-
euser = ExpireUser.create :name => "Ghost rider"
|
6
|
-
$redis.ttl(euser.__redis_record_key).should be > 9.minutes.from_now.to_i
|
7
|
-
$redis.ttl(euser.__redis_record_key).should be < (10.minutes.from_now.to_i + 1)
|
8
|
-
end
|
9
|
-
|
10
|
-
it "should create a record and then delete if *expire* method is specified in appropriate class" do
|
11
|
-
euser = ExpireUserWithPredicate.create :name => "Ghost rider"
|
12
|
-
$redis.ttl(euser.__redis_record_key).should be > 9.minutes.from_now.to_i
|
13
|
-
$redis.ttl(euser.__redis_record_key).should be < (10.minutes.from_now.to_i + 1)
|
14
|
-
|
15
|
-
euser2 = ExpireUserWithPredicate.create :name => "Ghost rider", :persist => true
|
16
|
-
$redis.ttl(euser2.__redis_record_key).should == -1
|
17
|
-
end
|
18
|
-
|
19
|
-
it "should create a record with an inline *expire* option (which overrides default *expire* value)" do
|
20
|
-
euser = ExpireUser.create :name => "Ghost rider", :expire_in => 50.minutes.from_now
|
21
|
-
$redis.ttl(euser.__redis_record_key).should be < (50.minutes.from_now.to_i + 1)
|
22
|
-
$redis.ttl(euser.__redis_record_key).should be > 49.minutes.from_now.to_i
|
23
|
-
end
|
24
|
-
|
25
|
-
it "should also create expirable key when record has associated records" do
|
26
|
-
euser = ExpireUser.create :name => "Ghost rider"
|
27
|
-
$redis.ttl(euser.__redis_record_key).should be > 9.minutes.from_now.to_i
|
28
|
-
$redis.ttl(euser.__redis_record_key).should be < (10.minutes.from_now.to_i + 1)
|
29
|
-
|
30
|
-
profile = Profile.create :title => "Profile for ghost rider", :name => "Ghost Rider"
|
31
|
-
articles = [Article.create(:title => "article1", :karma => 1), Article.create(:title => "article2", :karma => 2)]
|
32
|
-
|
33
|
-
euser.profile = profile
|
34
|
-
euser.profile.should == profile
|
35
|
-
$redis.get("expire_user:1:profile").to_i.should == profile.id
|
36
|
-
$redis.ttl("expire_user:1:profile").should be > 9.minutes.from_now.to_i
|
37
|
-
$redis.ttl("expire_user:1:profile").should be < (10.minutes.from_now.to_i + 1)
|
38
|
-
|
39
|
-
euser.articles = articles
|
40
|
-
$redis.zrange("expire_user:1:articles", 0, -1).should =~ articles.map{|a| a.id.to_s}
|
41
|
-
$redis.ttl("expire_user:1:articles").should be > 9.minutes.from_now.to_i
|
42
|
-
$redis.ttl("expire_user:1:articles").should be < (10.minutes.from_now.to_i + 1)
|
43
|
-
end
|
44
|
-
|
45
|
-
it "should also create expirable key when record has associated records (class with predicate expiry)" do
|
46
|
-
euser2 = ExpireUserWithPredicate.create :name => "Ghost rider", :persist => false
|
47
|
-
$redis.ttl(euser2.__redis_record_key).should be > 9.minutes.from_now.to_i
|
48
|
-
$redis.ttl(euser2.__redis_record_key).should be < (10.minutes.from_now.to_i + 1)
|
49
|
-
|
50
|
-
profile = Profile.create :title => "Profile for ghost rider", :name => "Ghost Rider"
|
51
|
-
articles = [Article.create(:title => "article1", :karma => 1), Article.create(:title => "article2", :karma => 2)]
|
52
|
-
|
53
|
-
euser2.profile = profile
|
54
|
-
euser2.profile.should == profile
|
55
|
-
$redis.get("expire_user_with_predicate:1:profile").to_i.should == profile.id
|
56
|
-
$redis.ttl("expire_user_with_predicate:1:profile").should be > 9.minutes.from_now.to_i
|
57
|
-
$redis.ttl("expire_user_with_predicate:1:profile").should be < (10.minutes.from_now.to_i + 1)
|
58
|
-
|
59
|
-
euser2.articles << articles
|
60
|
-
$redis.zrange("expire_user_with_predicate:1:articles", 0, -1).should =~ articles.map{|a| a.id.to_s}
|
61
|
-
$redis.ttl("expire_user_with_predicate:1:articles").should be > 9.minutes.from_now.to_i
|
62
|
-
$redis.ttl("expire_user_with_predicate:1:articles").should be < (10.minutes.from_now.to_i + 1)
|
63
|
-
end
|
64
|
-
end
|
@@ -1,42 +0,0 @@
|
|
1
|
-
require File.dirname(File.expand_path(__FILE__)) + '/test_helper.rb'
|
2
|
-
|
3
|
-
describe "check associations" do
|
4
|
-
it "should save associations properly" do
|
5
|
-
@profile = Profile.new
|
6
|
-
@profile.name = "my profile"
|
7
|
-
@profile.save
|
8
|
-
|
9
|
-
@profile.should be
|
10
|
-
@profile.name.should == "my profile"
|
11
|
-
|
12
|
-
@location1 = Location.new
|
13
|
-
@location1.coordinates = "44.343456345 56.23341432"
|
14
|
-
@location1.save
|
15
|
-
@location1.should be
|
16
|
-
@location1.coordinates.should == "44.343456345 56.23341432"
|
17
|
-
|
18
|
-
@profile.location = @location1
|
19
|
-
|
20
|
-
@profile.location.should be
|
21
|
-
@profile.location.id.should == @location1.id
|
22
|
-
|
23
|
-
@location1.profiles.size.should == 1
|
24
|
-
@location1.profiles.first.id.should == @profile.id
|
25
|
-
|
26
|
-
# check second profile
|
27
|
-
@profile2 = Profile.new
|
28
|
-
@profile2.name = "someone else's profile"
|
29
|
-
@profile2.save
|
30
|
-
|
31
|
-
@profile2.should be
|
32
|
-
@profile2.name.should == "someone else's profile"
|
33
|
-
|
34
|
-
@profile2.location = @location1
|
35
|
-
|
36
|
-
@profile2.location.should be
|
37
|
-
@profile2.location.id.should == @location1.id
|
38
|
-
|
39
|
-
@location1.profiles.size.should == 2
|
40
|
-
@location1.profiles.collect{|p| p.id}.sort.should == [@profile.id, @profile2.id].sort
|
41
|
-
end
|
42
|
-
end
|