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.
Files changed (65) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +1 -1
  3. data/lib/redis_orm.rb +8 -13
  4. data/lib/redis_orm/associations/has_many.rb +7 -3
  5. data/lib/redis_orm/redis_orm.rb +3 -5
  6. metadata +64 -124
  7. data/Gemfile +0 -10
  8. data/Manifest +0 -74
  9. data/Rakefile +0 -25
  10. data/benchmarks/sortable_benchmark.rb +0 -45
  11. data/redis_orm.gemspec +0 -45
  12. data/spec/generators/model_generator_spec.rb +0 -29
  13. data/spec/spec_helper.rb +0 -17
  14. data/test/association_indices_test.rb +0 -168
  15. data/test/associations_test.rb +0 -294
  16. data/test/atomicity_test.rb +0 -36
  17. data/test/basic_functionality_test.rb +0 -204
  18. data/test/callbacks_test.rb +0 -49
  19. data/test/changes_array_test.rb +0 -25
  20. data/test/classes/album.rb +0 -6
  21. data/test/classes/article.rb +0 -7
  22. data/test/classes/article_with_comments.rb +0 -8
  23. data/test/classes/book.rb +0 -6
  24. data/test/classes/catalog_item.rb +0 -5
  25. data/test/classes/category.rb +0 -7
  26. data/test/classes/city.rb +0 -7
  27. data/test/classes/comment.rb +0 -26
  28. data/test/classes/country.rb +0 -5
  29. data/test/classes/custom_user.rb +0 -8
  30. data/test/classes/cutout.rb +0 -20
  31. data/test/classes/cutout_aggregator.rb +0 -5
  32. data/test/classes/default_user.rb +0 -10
  33. data/test/classes/dynamic_finder_user.rb +0 -8
  34. data/test/classes/empty_person.rb +0 -2
  35. data/test/classes/expire_user.rb +0 -8
  36. data/test/classes/expire_user_with_predicate.rb +0 -13
  37. data/test/classes/giftcard.rb +0 -6
  38. data/test/classes/jigsaw.rb +0 -4
  39. data/test/classes/location.rb +0 -5
  40. data/test/classes/message.rb +0 -4
  41. data/test/classes/note.rb +0 -5
  42. data/test/classes/omni_user.rb +0 -8
  43. data/test/classes/person.rb +0 -6
  44. data/test/classes/photo.rb +0 -21
  45. data/test/classes/profile.rb +0 -9
  46. data/test/classes/sortable_user.rb +0 -11
  47. data/test/classes/timestamp.rb +0 -3
  48. data/test/classes/user.rb +0 -39
  49. data/test/classes/uuid_default_user.rb +0 -12
  50. data/test/classes/uuid_timestamp.rb +0 -5
  51. data/test/classes/uuid_user.rb +0 -13
  52. data/test/dynamic_finders_test.rb +0 -51
  53. data/test/exceptions_test.rb +0 -47
  54. data/test/expire_records_test.rb +0 -64
  55. data/test/has_one_has_many_test.rb +0 -42
  56. data/test/indices_test.rb +0 -63
  57. data/test/modules/belongs_to_model_within_module.rb +0 -6
  58. data/test/modules/has_many_model_within_module.rb +0 -11
  59. data/test/options_test.rb +0 -226
  60. data/test/polymorphic_test.rb +0 -65
  61. data/test/redis.conf +0 -417
  62. data/test/sortable_test.rb +0 -116
  63. data/test/test_helper.rb +0 -37
  64. data/test/uuid_as_id_test.rb +0 -178
  65. data/test/validations_test.rb +0 -20
@@ -1,36 +0,0 @@
1
- require File.dirname(File.expand_path(__FILE__)) + '/test_helper.rb'
2
-
3
- describe "check atomicity" do
4
- it "should properly increment property's value" do
5
- article = Article.new :title => "Simple test atomicity with multiple threads", :karma => 1
6
- article.save
7
-
8
- threads = []
9
-
10
- 50.times do |i|
11
- threads << Thread.new(i) do
12
- article.update_attribute :karma, (article.karma + 1)
13
- end
14
- end
15
-
16
- threads.each{|thread| thread.join}
17
-
18
- Article.first.karma.should == 51
19
- end
20
-
21
- it "should properly increment/decrement property's value" do
22
- article = Article.create :title => "article #1", :karma => 10
23
- threads = []
24
-
25
- 10.times do
26
- threads << Thread.new{ article.update_attribute(:karma, (article.karma + 2)) }
27
- end
28
-
29
- 15.times do
30
- threads << Thread.new{ article.update_attribute(:karma, (article.karma - 1)) }
31
- end
32
-
33
- threads.each{|thread| thread.join}
34
- article.karma.should == 15
35
- end
36
- end
@@ -1,204 +0,0 @@
1
- require File.dirname(File.expand_path(__FILE__)) + '/test_helper.rb'
2
-
3
- describe "check basic functionality" do
4
- it "should have 3 models in descendants" do
5
- RedisOrm::Base.descendants.should include(User, DefaultUser, TimeStamp)
6
- RedisOrm::Base.descendants.should_not include(EmptyPerson)
7
- end
8
-
9
- it "should return the same user" do
10
- user = User.new :name => "german"
11
- user.save
12
- User.first.should == user
13
-
14
- user.name = "Anderson"
15
- User.first.should_not == user
16
- end
17
-
18
- it "test_simple_creation" do
19
- User.count.should == 0
20
-
21
- user = User.new :name => "german"
22
-
23
- user.save
24
-
25
- user.should be
26
-
27
- user.name.should == "german"
28
- user.__redis_record_key.should == "user:1"
29
-
30
- User.count.should == 1
31
- User.first.name.should == "german"
32
- end
33
-
34
- it "should test different ways to update a record" do
35
- User.count.should == 0
36
-
37
- user = User.new :name => "german"
38
- user.should be
39
- user.save
40
-
41
- user.name.should == "german"
42
-
43
- user.name = "nobody"
44
- user.save
45
-
46
- User.count.should == 1
47
- User.first.name.should == "nobody"
48
-
49
- u = User.first
50
- u.should be
51
- u.update_attribute :name, "root"
52
- User.first.name.should == "root"
53
-
54
- u = User.first
55
- u.should be
56
- u.update_attributes :name => "german"
57
- User.first.name.should == "german"
58
- end
59
-
60
- it "test_deletion" do
61
- User.count.should == 0
62
-
63
- user = User.new :name => "german"
64
- user.save
65
- user.should be
66
-
67
- user.name.should == "german"
68
-
69
- User.count.should == 1
70
- id = user.id
71
-
72
- user.destroy
73
- User.count.should == 0
74
- $redis.zrank("user:ids", id).should == nil
75
- $redis.hgetall("user:#{id}").should == {}
76
- end
77
-
78
- it "should return first and last objects" do
79
- User.count.should == 0
80
- User.first.should == nil
81
- User.last.should == nil
82
-
83
- user1 = User.new :name => "german"
84
- user1.save
85
- user1.should be
86
- user1.name.should == "german"
87
-
88
- user2 = User.new :name => "nobody"
89
- user2.save
90
- user2.should be
91
- user2.name.should == "nobody"
92
-
93
- User.count.should == 2
94
-
95
- User.first.should be
96
- User.last.should be
97
-
98
- User.first.id.should == user1.id
99
- User.last.id.should == user2.id
100
- end
101
-
102
- it "should return values with correct classes" do
103
- user = User.new
104
- user.name = "german"
105
- user.age = 26
106
- user.wage = 124.34
107
- user.male = true
108
- user.save
109
-
110
- user.should be
111
-
112
- u = User.first
113
-
114
- u.created_at.class.should == DateTime
115
- u.modified_at.class.should == DateTime
116
- u.wage.class.should == Float
117
- u.male.class.to_s.should match(/TrueClass|FalseClass/)
118
- u.age.class.to_s.should match(/Integer|Fixnum/)
119
-
120
- u.name.should == "german"
121
- u.wage.should == 124.34
122
- u.age.should == 26
123
- u.male.should == true
124
- end
125
-
126
- it "should return correct saved defaults" do
127
- DefaultUser.count.should == 0
128
- DefaultUser.create
129
- DefaultUser.count.should == 1
130
-
131
- u = DefaultUser.first
132
-
133
- u.created_at.class.should == DateTime
134
- u.modified_at.class.should == DateTime
135
- u.wage.class.should == Float
136
- u.male.class.to_s.should match(/TrueClass|FalseClass/)
137
- u.admin.class.to_s.should match(/TrueClass|FalseClass/)
138
- u.age.class.to_s.should match(/Integer|Fixnum/)
139
-
140
- u.name.should == "german"
141
- u.male.should == true
142
- u.age.should == 26
143
- u.wage.should == 256.25
144
- u.admin.should == false
145
-
146
- du = DefaultUser.new
147
- du.name = "germaninthetown"
148
- du.save
149
-
150
- du_saved = DefaultUser.last
151
- du_saved.name.should == "germaninthetown"
152
- du_saved.admin.should == false
153
- end
154
-
155
- it "should expand timestamps declaration properly" do
156
- t = TimeStamp.new
157
- t.save
158
- t.created_at.should be
159
- t.modified_at.should be
160
- t.created_at.day.should == Time.now.day
161
- t.modified_at.day.should == Time.now.day
162
- end
163
-
164
- it "should store arrays in the property correctly" do
165
- a = ArticleWithComments.new :title => "Article #1", :comments => ["Hello", "there are comments"]
166
- expect {
167
- a.save
168
- }.to change(ArticleWithComments, :count).by(1)
169
-
170
- saved_article = ArticleWithComments.last
171
- saved_article.comments.should == ["Hello", "there are comments"]
172
- end
173
-
174
- it "should store default hash in the property if it's not provided" do
175
- a = ArticleWithComments.new :title => "Article #1"
176
- expect {
177
- a.save
178
- }.to change(ArticleWithComments, :count).by(1)
179
-
180
- saved_article = ArticleWithComments.last
181
- saved_article.rates.should == {1 => 0, 2 => 0, 3 => 0, 4 => 0, 5 => 0}
182
- end
183
-
184
- it "should store hash in the property correctly" do
185
- a = ArticleWithComments.new :title => "Article #1", :rates => {4 => 134}
186
- expect {
187
- a.save
188
- }.to change(ArticleWithComments, :count).by(1)
189
-
190
- saved_article = ArticleWithComments.last
191
- saved_article.rates.should == {4 => 134}
192
- end
193
-
194
- it "should properly transform :default values to right classes (if :default values are wrong) so when comparing them to other/stored instances they'll be the same" do
195
- # SortableUser class has 3 properties with wrong classes of :default value
196
- u = SortableUser.new :name => "Alan"
197
- u.save
198
-
199
- su = SortableUser.first
200
- su.test_type_cast.should == false
201
- su.wage.should == 20_000.0
202
- su.age.should == 26
203
- end
204
- end
@@ -1,49 +0,0 @@
1
- require File.dirname(File.expand_path(__FILE__)) + '/test_helper.rb'
2
-
3
- describe "check callbacks" do
4
- it "should fire after_create/after_destroy callbacks" do
5
- user = User.new :first_name => "Robert", :last_name => "Pirsig"
6
- user.save
7
-
8
- $redis.zrank("users:sorted_by_rating", user.id).should == 0
9
-
10
- comment = Comment.create :text => "First!"
11
- user.comments << comment
12
-
13
- u = User.first
14
- u.id.should == user.id
15
- u.comments.count.should == 1
16
- u.destroy
17
- u.comments.count.should == 0
18
- end
19
-
20
- it "should fire before_create/before_destroy callbacks" do
21
- CutoutAggregator.create
22
-
23
- CutoutAggregator.count.should == 1
24
- Cutout.create :filename => "1.jpg"
25
- Cutout.create :filename => "2.jpg"
26
- CutoutAggregator.last.revision.should == 2
27
- Cutout.last.destroy
28
- Cutout.last.destroy
29
- CutoutAggregator.count.should == 0
30
- end
31
-
32
- it "should fire after_save/before_save callbacks" do
33
- comment = Comment.new :text => " Trim meeee ! "
34
- comment.save
35
- Comment.first.text.should == "Trim meeee !"
36
-
37
- user = User.new :first_name => "Robert", :last_name => "Pirsig"
38
- user.save
39
- user.karma.should == 1000
40
-
41
- user.comments << comment
42
- user.comments.count == 1
43
-
44
- c = Comment.first
45
- c.update_attributes :text => "Another brick in the wall"
46
-
47
- User.first.karma.should == 975
48
- end
49
- end
@@ -1,25 +0,0 @@
1
- require File.dirname(File.expand_path(__FILE__)) + '/test_helper.rb'
2
-
3
- describe "check associations" do
4
- it "should return correct _changes array" do
5
- user = User.new :name => "german"
6
- user.name_changed?.should == false
7
-
8
- user.name_changes.should == ["german"]
9
- user.save
10
-
11
- user.name_changes.should == ["german"]
12
- user.name = "germaninthetown"
13
- user.name_changes.should == ["german", "germaninthetown"]
14
- user.name_changed?.should == true
15
- user.save
16
-
17
- user = User.first
18
- user.name.should == "germaninthetown"
19
- user.name_changed?.should == false
20
- user.name_changes.should == ["germaninthetown"]
21
- user.name = "german"
22
- user.name_changed?.should == true
23
- user.name_changes.should == ["germaninthetown", "german"]
24
- end
25
- end
@@ -1,6 +0,0 @@
1
- class Album < RedisOrm::Base
2
- property :title, String
3
-
4
- has_one :photo, :as => :front_photo
5
- has_many :photos, :dependent => :destroy
6
- end
@@ -1,7 +0,0 @@
1
- class Article < RedisOrm::Base
2
- property :title, String
3
- property :karma, Integer
4
-
5
- has_many :comments
6
- has_many :categories
7
- end
@@ -1,8 +0,0 @@
1
- class ArticleWithComments < RedisOrm::Base
2
- property :title, String
3
- property :comments, Array
4
-
5
- property :rates, Hash, :default => {1 => 0, 2 => 0, 3 => 0, 4 => 0, 5 => 0}
6
-
7
- has_many :categories
8
- end
data/test/classes/book.rb DELETED
@@ -1,6 +0,0 @@
1
- class Book < RedisOrm::Base
2
- property :price, Integer, :default => 0 # in cents
3
- property :title, String
4
-
5
- has_one :catalog_item
6
- end
@@ -1,5 +0,0 @@
1
- class CatalogItem < RedisOrm::Base
2
- property :title, String
3
-
4
- belongs_to :resource, :polymorphic => true
5
- end
@@ -1,7 +0,0 @@
1
- class Category < RedisOrm::Base
2
- property :name, String
3
- property :title, String
4
-
5
- has_many :articles
6
- has_many :photos, :dependent => :nullify
7
- end
data/test/classes/city.rb DELETED
@@ -1,7 +0,0 @@
1
- class City < RedisOrm::Base
2
- property :name, String
3
- property :name, String
4
-
5
- has_many :people
6
- has_many :profiles
7
- end
@@ -1,26 +0,0 @@
1
- class Comment < RedisOrm::Base
2
- property :body, String
3
- property :text, String
4
- property :moderated, RedisOrm::Boolean, :default => false
5
-
6
- index :moderated
7
-
8
- belongs_to :user
9
- belongs_to :article
10
-
11
- has_many :comments, :as => :replies
12
- belongs_to :comment, :as => :reply_to
13
-
14
- before_save :trim_whitespaces
15
- after_save :regenerate_karma
16
-
17
- def trim_whitespaces
18
- self.text = self.text.to_s.strip
19
- end
20
-
21
- def regenerate_karma
22
- if self.user
23
- self.user.update_attribute :karma, (self.user.karma - self.text.length)
24
- end
25
- end
26
- end
@@ -1,5 +0,0 @@
1
- class Country < RedisOrm::Base
2
- property :name, String
3
-
4
- has_many :people
5
- end
@@ -1,8 +0,0 @@
1
- class CustomUser < RedisOrm::Base
2
- property :first_name, String
3
- property :last_name, String
4
-
5
- index :first_name, :unique => false
6
- index :last_name, :unique => false
7
- index [:first_name, :last_name], :unique => true
8
- end
@@ -1,20 +0,0 @@
1
- class Cutout < RedisOrm::Base
2
- property :filename, String
3
-
4
- before_create :increase_revisions
5
- before_destroy :decrease_revisions
6
-
7
- def increase_revisions
8
- ca = CutoutAggregator.last
9
- ca.update_attribute(:revision, ca.revision + 1) if ca
10
- end
11
-
12
- def decrease_revisions
13
- ca = CutoutAggregator.first
14
- if ca.revision > 0
15
- ca.update_attribute :revision, ca.revision - 1
16
- end
17
-
18
- ca.destroy if ca.revision == 0
19
- end
20
- end