redis_orm 0.5.1 → 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.
data/test/test_helper.rb DELETED
@@ -1,25 +0,0 @@
1
- require 'rspec'
2
- require 'rspec/autorun'
3
- require File.dirname(File.expand_path(__FILE__)) + '/../lib/redis_orm.rb'
4
-
5
- RSpec.configure do |config|
6
- config.before(:all) do
7
- path_to_conf = File.dirname(File.expand_path(__FILE__)) + "/redis.conf"
8
- $redis_pid = spawn 'redis-server ' + path_to_conf, :out => "/dev/null"
9
- sleep(0.3) # must be some delay otherwise "Connection refused - Unable to connect to Redis"
10
- path_to_socket = File.dirname(File.expand_path(__FILE__)) + "/../redis.sock"
11
- $redis = Redis.new(:host => 'localhost', :path => path_to_socket)
12
- end
13
-
14
- config.after(:all) do
15
- Process.kill 9, $redis_pid.to_i if $redis_pid
16
- end
17
-
18
- config.after(:each) do
19
- $redis.flushall if $redis
20
- end
21
-
22
- config.before(:each) do
23
- $redis.flushall if $redis
24
- end
25
- end
@@ -1,210 +0,0 @@
1
- require File.dirname(File.expand_path(__FILE__)) + '/test_helper.rb'
2
-
3
- class User < RedisOrm::Base
4
- use_uuid_as_id
5
-
6
- property :name, String
7
- property :age, Integer
8
- property :wage, Float
9
- property :male, RedisOrm::Boolean
10
-
11
- property :created_at, Time
12
- property :modified_at, Time
13
-
14
- has_many :users, :as => :friends
15
- end
16
-
17
- class DefaultUser < RedisOrm::Base
18
- use_uuid_as_id
19
-
20
- property :name, String, :default => "german"
21
- property :age, Integer, :default => 26
22
- property :wage, Float, :default => 256.25
23
- property :male, RedisOrm::Boolean, :default => true
24
- property :admin, RedisOrm::Boolean, :default => false
25
-
26
- property :created_at, Time
27
- property :modified_at, Time
28
- end
29
-
30
- class TimeStamp < RedisOrm::Base
31
- use_uuid_as_id
32
- timestamps
33
- end
34
-
35
- describe "check basic functionality" do
36
- it "test_simple_creation" do
37
- User.count.should == 0
38
-
39
- user = User.new :name => "german"
40
- user.save
41
-
42
- user.should be
43
- user.id.should be
44
-
45
- user.id.should_not == 1
46
- user.id.length.should == 32 # b57525b09a69012e8fbe001d61192f09 for example
47
-
48
- user.name.should == "german"
49
-
50
- User.count.should == 1
51
- User.first.name.should == "german"
52
- end
53
-
54
- it "should test different ways to update a record" do
55
- User.count.should == 0
56
-
57
- user = User.new :name => "german"
58
- user.should be
59
- user.save
60
-
61
- user.name.should == "german"
62
-
63
- user.name = "nobody"
64
- user.save
65
-
66
- User.count.should == 1
67
- User.first.name.should == "nobody"
68
-
69
- u = User.first
70
- u.should be
71
- u.id.should_not == 1
72
- u.id.length.should == 32
73
- u.update_attribute :name, "root"
74
- User.first.name.should == "root"
75
-
76
- u = User.first
77
- u.should be
78
- u.update_attributes :name => "german"
79
- User.first.name.should == "german"
80
- end
81
-
82
- it "test_deletion" do
83
- User.count.should == 0
84
-
85
- user = User.new :name => "german"
86
- user.save
87
- user.should be
88
-
89
- user.name.should == "german"
90
-
91
- User.count.should == 1
92
- id = user.id
93
-
94
- user.destroy
95
- User.count.should == 0
96
- $redis.zrank("user:ids", id).should == nil
97
- $redis.hgetall("user:#{id}").should == {}
98
- end
99
-
100
- it "should return first and last objects" do
101
- User.count.should == 0
102
- User.first.should == nil
103
- User.last.should == nil
104
-
105
- user1 = User.new :name => "german"
106
- user1.save
107
- user1.should be
108
- user1.name.should == "german"
109
- user1.id.should_not == 1
110
- user1.id.length.should == 32 # b57525b09a69012e8fbe001d61192f09 for example
111
-
112
- user2 = User.new :name => "nobody"
113
- user2.save
114
- user2.should be
115
- user2.name.should == "nobody"
116
- user2.id.should_not == 2
117
- user2.id.length.should == 32
118
-
119
- User.count.should == 2
120
-
121
- User.first.should be
122
- User.last.should be
123
-
124
- User.first.id.should == user1.id
125
- User.last.id.should == user2.id
126
- end
127
-
128
- it "should return values with correct classes" do
129
- user = User.new
130
- user.name = "german"
131
- user.age = 26
132
- user.wage = 124.34
133
- user.male = true
134
- user.save
135
-
136
- user.should be
137
-
138
- u = User.first
139
-
140
- u.created_at.class.should == Time
141
- u.modified_at.class.should == Time
142
- u.wage.class.should == Float
143
- u.male.class.to_s.should match(/TrueClass|FalseClass/)
144
- u.age.class.to_s.should match(/Integer|Fixnum/)
145
- u.id.should_not == 1
146
- u.id.length.should == 32
147
-
148
- u.name.should == "german"
149
- u.wage.should == 124.34
150
- u.age.should == 26
151
- u.male.should == true
152
- end
153
-
154
- it "should return correct saved defaults" do
155
- DefaultUser.count.should == 0
156
- DefaultUser.create
157
- DefaultUser.count.should == 1
158
-
159
- u = DefaultUser.first
160
-
161
- u.created_at.class.should == Time
162
- u.modified_at.class.should == Time
163
- u.wage.class.should == Float
164
- u.male.class.to_s.should match(/TrueClass|FalseClass/)
165
- u.admin.class.to_s.should match(/TrueClass|FalseClass/)
166
- u.age.class.to_s.should match(/Integer|Fixnum/)
167
-
168
- u.name.should == "german"
169
- u.male.should == true
170
- u.age.should == 26
171
- u.wage.should == 256.25
172
- u.admin.should == false
173
- u.id.should_not == 1
174
- u.id.length.should == 32
175
-
176
- du = DefaultUser.new
177
- du.name = "germaninthetown"
178
- du.save
179
-
180
- du_saved = DefaultUser.last
181
- du_saved.name.should == "germaninthetown"
182
- du_saved.admin.should == false
183
- du.id.should_not == 2
184
- du.id.should_not == u.id
185
- du.id.length.should == 32
186
- end
187
-
188
- it "should expand timestamps declaration properly" do
189
- t = TimeStamp.new
190
- t.save
191
-
192
- t.created_at.should be
193
- t.modified_at.should be
194
- t.created_at.day.should == Time.now.day
195
- t.modified_at.day.should == Time.now.day
196
- end
197
-
198
- # from associations_test.rb
199
- it "should maintain correct self referencing link" do
200
- me = User.create :name => "german", :age => 26, :wage => 10.0, :male => true
201
- friend1 = User.create :name => "friend1", :age => 26, :wage => 7.0, :male => true
202
- friend2 = User.create :name => "friend2", :age => 25, :wage => 5.0, :male => true
203
-
204
- me.friends << [friend1, friend2]
205
-
206
- me.friends.count.should == 2
207
- friend1.friends.count.should == 0
208
- friend2.friends.count.should == 0
209
- end
210
- end
@@ -1,28 +0,0 @@
1
- require File.dirname(File.expand_path(__FILE__)) + '/test_helper.rb'
2
-
3
- class Photo < RedisOrm::Base
4
- property :image, String
5
-
6
- validates_presence_of :image
7
- validates_length_of :image, :in => 7..32
8
- validates_format_of :image, :with => /\w*\.(gif|jpe?g|png)/
9
- end
10
-
11
- describe "check associations" do
12
- it "should validate presence if image in photo" do
13
- p = Photo.new
14
- p.save.should == false
15
- p.errors.should be
16
- p.errors[:image].should include("can't be blank")
17
-
18
- p.image = "test"
19
- p.save.should == false
20
- p.errors.should be
21
- p.errors[:image].should include("is too short (minimum is 7 characters)")
22
- p.errors[:image].should include("is invalid")
23
-
24
- p.image = "facepalm.jpg"
25
- p.save
26
- p.errors.empty?.should == true
27
- end
28
- end