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.
- checksums.yaml +7 -0
- data/CHANGELOG +29 -0
- data/README.md +66 -2
- data/TODO +5 -0
- data/lib/rails/generators/redis_orm/model/model_generator.rb +21 -0
- data/lib/rails/generators/redis_orm/model/templates/model.rb.erb +5 -0
- data/lib/redis_orm.rb +8 -11
- data/lib/redis_orm/active_model_behavior.rb +0 -2
- data/lib/redis_orm/associations/belongs_to.rb +49 -11
- data/lib/redis_orm/associations/has_many.rb +29 -21
- data/lib/redis_orm/associations/has_many_helper.rb +1 -1
- data/lib/redis_orm/associations/has_many_proxy.rb +19 -8
- data/lib/redis_orm/associations/has_one.rb +36 -2
- data/lib/redis_orm/redis_orm.rb +486 -173
- data/lib/redis_orm/utils.rb +12 -0
- metadata +93 -80
- data/Manifest +0 -30
- data/Rakefile +0 -33
- data/redis_orm.gemspec +0 -45
- data/test/association_indices_test.rb +0 -145
- data/test/associations_test.rb +0 -306
- data/test/atomicity_test.rb +0 -64
- data/test/basic_functionality_test.rb +0 -173
- data/test/callbacks_test.rb +0 -119
- data/test/changes_array_test.rb +0 -31
- data/test/dynamic_finders_test.rb +0 -68
- data/test/exceptions_test.rb +0 -45
- data/test/has_one_has_many_test.rb +0 -54
- data/test/indices_test.rb +0 -81
- data/test/options_test.rb +0 -243
- data/test/polymorphic_test.rb +0 -104
- data/test/redis.conf +0 -417
- data/test/test_helper.rb +0 -25
- data/test/uuid_as_id_test.rb +0 -210
- data/test/validations_test.rb +0 -28
@@ -0,0 +1,12 @@
|
|
1
|
+
module RedisOrm
|
2
|
+
module Utils
|
3
|
+
def calculate_key_for_zset(string)
|
4
|
+
return 0.0 if string.nil?
|
5
|
+
sum = ""
|
6
|
+
string.codepoints.each do |codepoint|
|
7
|
+
sum += ("%05i" % codepoint.to_s) # 5 because 65536 => 2 bytes UTF-8
|
8
|
+
end
|
9
|
+
"0.#{sum}".to_f
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
metadata
CHANGED
@@ -1,72 +1,113 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: redis_orm
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
5
|
-
prerelease:
|
4
|
+
version: '0.8'
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Dmitrii Samoilov
|
9
|
-
autorequire:
|
8
|
+
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
13
|
-
default_executable:
|
11
|
+
date: 2021-02-07 00:00:00.000000000 Z
|
14
12
|
dependencies:
|
15
13
|
- !ruby/object:Gem::Dependency
|
16
14
|
name: activesupport
|
17
|
-
requirement:
|
18
|
-
none: false
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
19
16
|
requirements:
|
20
|
-
- -
|
17
|
+
- - "~>"
|
21
18
|
- !ruby/object:Gem::Version
|
22
|
-
version:
|
19
|
+
version: '5.1'
|
23
20
|
type: :runtime
|
24
21
|
prerelease: false
|
25
|
-
version_requirements:
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '5.1'
|
26
27
|
- !ruby/object:Gem::Dependency
|
27
28
|
name: activemodel
|
28
|
-
requirement:
|
29
|
-
none: false
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: '5.1'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
|
-
version_requirements:
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '5.1'
|
37
41
|
- !ruby/object:Gem::Dependency
|
38
42
|
name: redis
|
39
|
-
requirement:
|
40
|
-
none: false
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
41
44
|
requirements:
|
42
|
-
- -
|
45
|
+
- - "~>"
|
43
46
|
- !ruby/object:Gem::Version
|
44
|
-
version:
|
47
|
+
version: 4.2.5
|
45
48
|
type: :runtime
|
46
49
|
prerelease: false
|
47
|
-
version_requirements:
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 4.2.5
|
48
55
|
- !ruby/object:Gem::Dependency
|
49
56
|
name: uuid
|
50
|
-
requirement:
|
51
|
-
none: false
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
52
58
|
requirements:
|
53
|
-
- -
|
59
|
+
- - "~>"
|
54
60
|
- !ruby/object:Gem::Version
|
55
61
|
version: 2.3.2
|
56
62
|
type: :runtime
|
57
63
|
prerelease: false
|
58
|
-
version_requirements:
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 2.3.2
|
59
69
|
- !ruby/object:Gem::Dependency
|
60
70
|
name: rspec
|
61
|
-
requirement:
|
62
|
-
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '3.10'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
63
79
|
requirements:
|
64
|
-
- -
|
80
|
+
- - "~>"
|
65
81
|
- !ruby/object:Gem::Version
|
66
|
-
version:
|
82
|
+
version: '3.10'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rspec-rails
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '3'
|
67
90
|
type: :development
|
68
91
|
prerelease: false
|
69
|
-
version_requirements:
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '3'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: ammeter
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '1.1'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '1.1'
|
70
111
|
description: ORM for Redis (advanced key-value storage) with ActiveRecord API
|
71
112
|
email: germaninthetown@gmail.com
|
72
113
|
executables: []
|
@@ -75,6 +116,9 @@ extra_rdoc_files:
|
|
75
116
|
- CHANGELOG
|
76
117
|
- LICENSE
|
77
118
|
- README.md
|
119
|
+
- TODO
|
120
|
+
- lib/rails/generators/redis_orm/model/model_generator.rb
|
121
|
+
- lib/rails/generators/redis_orm/model/templates/model.rb.erb
|
78
122
|
- lib/redis_orm.rb
|
79
123
|
- lib/redis_orm/active_model_behavior.rb
|
80
124
|
- lib/redis_orm/associations/belongs_to.rb
|
@@ -83,12 +127,14 @@ extra_rdoc_files:
|
|
83
127
|
- lib/redis_orm/associations/has_many_proxy.rb
|
84
128
|
- lib/redis_orm/associations/has_one.rb
|
85
129
|
- lib/redis_orm/redis_orm.rb
|
130
|
+
- lib/redis_orm/utils.rb
|
86
131
|
files:
|
87
132
|
- CHANGELOG
|
88
133
|
- LICENSE
|
89
|
-
- Manifest
|
90
134
|
- README.md
|
91
|
-
-
|
135
|
+
- TODO
|
136
|
+
- lib/rails/generators/redis_orm/model/model_generator.rb
|
137
|
+
- lib/rails/generators/redis_orm/model/templates/model.rb.erb
|
92
138
|
- lib/redis_orm.rb
|
93
139
|
- lib/redis_orm/active_model_behavior.rb
|
94
140
|
- lib/redis_orm/associations/belongs_to.rb
|
@@ -97,67 +143,34 @@ files:
|
|
97
143
|
- lib/redis_orm/associations/has_many_proxy.rb
|
98
144
|
- lib/redis_orm/associations/has_one.rb
|
99
145
|
- lib/redis_orm/redis_orm.rb
|
100
|
-
- redis_orm.
|
101
|
-
- test/association_indices_test.rb
|
102
|
-
- test/associations_test.rb
|
103
|
-
- test/atomicity_test.rb
|
104
|
-
- test/basic_functionality_test.rb
|
105
|
-
- test/callbacks_test.rb
|
106
|
-
- test/changes_array_test.rb
|
107
|
-
- test/dynamic_finders_test.rb
|
108
|
-
- test/exceptions_test.rb
|
109
|
-
- test/has_one_has_many_test.rb
|
110
|
-
- test/indices_test.rb
|
111
|
-
- test/options_test.rb
|
112
|
-
- test/polymorphic_test.rb
|
113
|
-
- test/redis.conf
|
114
|
-
- test/test_helper.rb
|
115
|
-
- test/uuid_as_id_test.rb
|
116
|
-
- test/validations_test.rb
|
117
|
-
has_rdoc: true
|
146
|
+
- lib/redis_orm/utils.rb
|
118
147
|
homepage: https://github.com/german/redis_orm
|
119
|
-
licenses:
|
120
|
-
|
148
|
+
licenses:
|
149
|
+
- MIT
|
150
|
+
metadata: {}
|
151
|
+
post_install_message:
|
121
152
|
rdoc_options:
|
122
|
-
- --line-numbers
|
123
|
-
- --inline-source
|
124
|
-
- --title
|
153
|
+
- "--line-numbers"
|
154
|
+
- "--inline-source"
|
155
|
+
- "--title"
|
125
156
|
- Redis_orm
|
126
|
-
- --main
|
157
|
+
- "--main"
|
127
158
|
- README.md
|
128
159
|
require_paths:
|
129
160
|
- lib
|
130
161
|
required_ruby_version: !ruby/object:Gem::Requirement
|
131
|
-
none: false
|
132
162
|
requirements:
|
133
|
-
- -
|
163
|
+
- - ">="
|
134
164
|
- !ruby/object:Gem::Version
|
135
165
|
version: '0'
|
136
166
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
137
|
-
none: false
|
138
167
|
requirements:
|
139
|
-
- -
|
168
|
+
- - ">="
|
140
169
|
- !ruby/object:Gem::Version
|
141
|
-
version: '
|
170
|
+
version: '0'
|
142
171
|
requirements: []
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
specification_version: 3
|
172
|
+
rubygems_version: 3.0.3
|
173
|
+
signing_key:
|
174
|
+
specification_version: 4
|
147
175
|
summary: ORM for Redis (advanced key-value storage) with ActiveRecord API
|
148
|
-
test_files:
|
149
|
-
- test/options_test.rb
|
150
|
-
- test/dynamic_finders_test.rb
|
151
|
-
- test/associations_test.rb
|
152
|
-
- test/validations_test.rb
|
153
|
-
- test/test_helper.rb
|
154
|
-
- test/polymorphic_test.rb
|
155
|
-
- test/uuid_as_id_test.rb
|
156
|
-
- test/atomicity_test.rb
|
157
|
-
- test/exceptions_test.rb
|
158
|
-
- test/association_indices_test.rb
|
159
|
-
- test/has_one_has_many_test.rb
|
160
|
-
- test/indices_test.rb
|
161
|
-
- test/changes_array_test.rb
|
162
|
-
- test/callbacks_test.rb
|
163
|
-
- test/basic_functionality_test.rb
|
176
|
+
test_files: []
|
data/Manifest
DELETED
@@ -1,30 +0,0 @@
|
|
1
|
-
CHANGELOG
|
2
|
-
LICENSE
|
3
|
-
Manifest
|
4
|
-
README.md
|
5
|
-
Rakefile
|
6
|
-
lib/redis_orm.rb
|
7
|
-
lib/redis_orm/active_model_behavior.rb
|
8
|
-
lib/redis_orm/associations/belongs_to.rb
|
9
|
-
lib/redis_orm/associations/has_many.rb
|
10
|
-
lib/redis_orm/associations/has_many_helper.rb
|
11
|
-
lib/redis_orm/associations/has_many_proxy.rb
|
12
|
-
lib/redis_orm/associations/has_one.rb
|
13
|
-
lib/redis_orm/redis_orm.rb
|
14
|
-
redis_orm.gemspec
|
15
|
-
test/association_indices_test.rb
|
16
|
-
test/associations_test.rb
|
17
|
-
test/atomicity_test.rb
|
18
|
-
test/basic_functionality_test.rb
|
19
|
-
test/callbacks_test.rb
|
20
|
-
test/changes_array_test.rb
|
21
|
-
test/dynamic_finders_test.rb
|
22
|
-
test/exceptions_test.rb
|
23
|
-
test/has_one_has_many_test.rb
|
24
|
-
test/indices_test.rb
|
25
|
-
test/options_test.rb
|
26
|
-
test/polymorphic_test.rb
|
27
|
-
test/redis.conf
|
28
|
-
test/test_helper.rb
|
29
|
-
test/uuid_as_id_test.rb
|
30
|
-
test/validations_test.rb
|
data/Rakefile
DELETED
@@ -1,33 +0,0 @@
|
|
1
|
-
require 'psych'
|
2
|
-
require 'rubygems'
|
3
|
-
require 'rake'
|
4
|
-
#=begin
|
5
|
-
require 'echoe'
|
6
|
-
|
7
|
-
Echoe.new('redis_orm', '0.5.1') do |p|
|
8
|
-
p.description = "ORM for Redis (advanced key-value storage) with ActiveRecord API"
|
9
|
-
p.url = "https://github.com/german/redis_orm"
|
10
|
-
p.author = "Dmitrii Samoilov"
|
11
|
-
p.email = "germaninthetown@gmail.com"
|
12
|
-
p.dependencies = ["activesupport >=3.0.0", "activemodel >=3.0.0", "redis >=2.2.0", "uuid >=2.3.2"]
|
13
|
-
p.development_dependencies = ["rspec >=2.5.0"]
|
14
|
-
end
|
15
|
-
#=end
|
16
|
-
|
17
|
-
#require 'rake/testtask'
|
18
|
-
#$LOAD_PATH << File.join(File.dirname(__FILE__), 'lib')
|
19
|
-
|
20
|
-
=begin
|
21
|
-
desc 'Test the redis_orm gem.'
|
22
|
-
Rake::TestTask.new(:test) do |t|
|
23
|
-
#t.libs << 'lib'
|
24
|
-
t.pattern = 'test/**/*_test.rb'
|
25
|
-
t.verbose = true
|
26
|
-
end
|
27
|
-
=end
|
28
|
-
|
29
|
-
task :test do |t|
|
30
|
-
Dir['test/**/*_test.rb'].each do |file|
|
31
|
-
puts `ruby -I./lib #{file}`
|
32
|
-
end
|
33
|
-
end
|
data/redis_orm.gemspec
DELETED
@@ -1,45 +0,0 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
2
|
-
|
3
|
-
Gem::Specification.new do |s|
|
4
|
-
s.name = %q{redis_orm}
|
5
|
-
s.version = "0.5.1"
|
6
|
-
|
7
|
-
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
|
-
s.authors = ["Dmitrii Samoilov"]
|
9
|
-
s.date = %q{2011-07-27}
|
10
|
-
s.description = %q{ORM for Redis (advanced key-value storage) with ActiveRecord API}
|
11
|
-
s.email = %q{germaninthetown@gmail.com}
|
12
|
-
s.extra_rdoc_files = ["CHANGELOG", "LICENSE", "README.md", "lib/redis_orm.rb", "lib/redis_orm/active_model_behavior.rb", "lib/redis_orm/associations/belongs_to.rb", "lib/redis_orm/associations/has_many.rb", "lib/redis_orm/associations/has_many_helper.rb", "lib/redis_orm/associations/has_many_proxy.rb", "lib/redis_orm/associations/has_one.rb", "lib/redis_orm/redis_orm.rb"]
|
13
|
-
s.files = ["CHANGELOG", "LICENSE", "Manifest", "README.md", "Rakefile", "lib/redis_orm.rb", "lib/redis_orm/active_model_behavior.rb", "lib/redis_orm/associations/belongs_to.rb", "lib/redis_orm/associations/has_many.rb", "lib/redis_orm/associations/has_many_helper.rb", "lib/redis_orm/associations/has_many_proxy.rb", "lib/redis_orm/associations/has_one.rb", "lib/redis_orm/redis_orm.rb", "redis_orm.gemspec", "test/association_indices_test.rb", "test/associations_test.rb", "test/atomicity_test.rb", "test/basic_functionality_test.rb", "test/callbacks_test.rb", "test/changes_array_test.rb", "test/dynamic_finders_test.rb", "test/exceptions_test.rb", "test/has_one_has_many_test.rb", "test/indices_test.rb", "test/options_test.rb", "test/polymorphic_test.rb", "test/redis.conf", "test/test_helper.rb", "test/uuid_as_id_test.rb", "test/validations_test.rb"]
|
14
|
-
s.homepage = %q{https://github.com/german/redis_orm}
|
15
|
-
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Redis_orm", "--main", "README.md"]
|
16
|
-
s.require_paths = ["lib"]
|
17
|
-
s.rubyforge_project = %q{redis_orm}
|
18
|
-
s.rubygems_version = %q{1.6.2}
|
19
|
-
s.summary = %q{ORM for Redis (advanced key-value storage) with ActiveRecord API}
|
20
|
-
s.test_files = ["test/options_test.rb", "test/dynamic_finders_test.rb", "test/associations_test.rb", "test/validations_test.rb", "test/test_helper.rb", "test/polymorphic_test.rb", "test/uuid_as_id_test.rb", "test/atomicity_test.rb", "test/exceptions_test.rb", "test/association_indices_test.rb", "test/has_one_has_many_test.rb", "test/indices_test.rb", "test/changes_array_test.rb", "test/callbacks_test.rb", "test/basic_functionality_test.rb"]
|
21
|
-
|
22
|
-
if s.respond_to? :specification_version then
|
23
|
-
s.specification_version = 3
|
24
|
-
|
25
|
-
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
26
|
-
s.add_runtime_dependency(%q<activesupport>, [">= 3.0.0"])
|
27
|
-
s.add_runtime_dependency(%q<activemodel>, [">= 3.0.0"])
|
28
|
-
s.add_runtime_dependency(%q<redis>, [">= 2.2.0"])
|
29
|
-
s.add_runtime_dependency(%q<uuid>, [">= 2.3.2"])
|
30
|
-
s.add_development_dependency(%q<rspec>, [">= 2.5.0"])
|
31
|
-
else
|
32
|
-
s.add_dependency(%q<activesupport>, [">= 3.0.0"])
|
33
|
-
s.add_dependency(%q<activemodel>, [">= 3.0.0"])
|
34
|
-
s.add_dependency(%q<redis>, [">= 2.2.0"])
|
35
|
-
s.add_dependency(%q<uuid>, [">= 2.3.2"])
|
36
|
-
s.add_dependency(%q<rspec>, [">= 2.5.0"])
|
37
|
-
end
|
38
|
-
else
|
39
|
-
s.add_dependency(%q<activesupport>, [">= 3.0.0"])
|
40
|
-
s.add_dependency(%q<activemodel>, [">= 3.0.0"])
|
41
|
-
s.add_dependency(%q<redis>, [">= 2.2.0"])
|
42
|
-
s.add_dependency(%q<uuid>, [">= 2.3.2"])
|
43
|
-
s.add_dependency(%q<rspec>, [">= 2.5.0"])
|
44
|
-
end
|
45
|
-
end
|
@@ -1,145 +0,0 @@
|
|
1
|
-
require File.dirname(File.expand_path(__FILE__)) + '/test_helper.rb'
|
2
|
-
|
3
|
-
class Article < RedisOrm::Base
|
4
|
-
property :title, String
|
5
|
-
has_many :comments
|
6
|
-
end
|
7
|
-
|
8
|
-
class Comment < RedisOrm::Base
|
9
|
-
property :body, String
|
10
|
-
|
11
|
-
property :moderated, RedisOrm::Boolean, :default => false
|
12
|
-
index :moderated
|
13
|
-
|
14
|
-
belongs_to :article
|
15
|
-
end
|
16
|
-
|
17
|
-
class User < RedisOrm::Base
|
18
|
-
property :name, String
|
19
|
-
index :name
|
20
|
-
|
21
|
-
property :moderator, RedisOrm::Boolean, :default => false
|
22
|
-
property :moderated_area, String, :default => "messages"
|
23
|
-
|
24
|
-
index :moderator
|
25
|
-
index [:moderator, :moderated_area]
|
26
|
-
|
27
|
-
has_many :users, :as => :friends
|
28
|
-
end
|
29
|
-
|
30
|
-
describe "check indices for associations" do
|
31
|
-
before(:each) do
|
32
|
-
@article = Article.new :title => "DHH drops OpenID on 37signals"
|
33
|
-
@article.save
|
34
|
-
|
35
|
-
@article.should be
|
36
|
-
@article.title.should == "DHH drops OpenID on 37signals"
|
37
|
-
|
38
|
-
@comment1 = Comment.new :body => "test"
|
39
|
-
@comment1.save
|
40
|
-
@comment1.should be
|
41
|
-
@comment1.body.should == "test"
|
42
|
-
@comment1.moderated.should == false
|
43
|
-
|
44
|
-
@comment2 = Comment.new :body => "test #2", :moderated => true
|
45
|
-
@comment2.save
|
46
|
-
@comment2.should be
|
47
|
-
@comment2.body.should == "test #2"
|
48
|
-
@comment2.moderated.should == true
|
49
|
-
end
|
50
|
-
|
51
|
-
it "should properly find associated records (e.g. with :conditions, :order, etc options) '<<' used for association" do
|
52
|
-
@article.comments << [@comment1, @comment2]
|
53
|
-
@article.comments.count.should == 2
|
54
|
-
|
55
|
-
@article.comments.all(:limit => 1).size.should == 1
|
56
|
-
@article.comments.find(:first).should be
|
57
|
-
@article.comments.find(:first).id.should == @comment1.id
|
58
|
-
@article.comments.find(:last).should be
|
59
|
-
@article.comments.find(:last).id.should == @comment2.id
|
60
|
-
|
61
|
-
@article.comments.find(:all, :conditions => {:moderated => true}).size.should == 1
|
62
|
-
@article.comments.find(:all, :conditions => {:moderated => false}).size.should == 1
|
63
|
-
@article.comments.find(:all, :conditions => {:moderated => true})[0].id.should == @comment2.id
|
64
|
-
@article.comments.find(:all, :conditions => {:moderated => false})[0].id.should == @comment1.id
|
65
|
-
|
66
|
-
@article.comments.find(:all, :conditions => {:moderated => true}, :limit => 1).size.should == 1
|
67
|
-
@article.comments.find(:all, :conditions => {:moderated => false}, :limit => 1).size.should == 1
|
68
|
-
@article.comments.find(:all, :conditions => {:moderated => true}, :limit => 1)[0].id.should == @comment2.id
|
69
|
-
@article.comments.find(:all, :conditions => {:moderated => false}, :limit => 1)[0].id.should == @comment1.id
|
70
|
-
|
71
|
-
@article.comments.find(:all, :conditions => {:moderated => true}, :limit => 1, :order => :desc).size.should == 1
|
72
|
-
@article.comments.find(:all, :conditions => {:moderated => false}, :limit => 1, :order => :asc).size.should == 1
|
73
|
-
@article.comments.find(:all, :conditions => {:moderated => true}, :limit => 1, :order => :desc)[0].id.should == @comment2.id
|
74
|
-
@article.comments.find(:all, :conditions => {:moderated => false}, :limit => 1, :order => :asc)[0].id.should == @comment1.id
|
75
|
-
|
76
|
-
@comment1.update_attribute :moderated, true
|
77
|
-
@article.comments.find(:all, :conditions => {:moderated => true}).size.should == 2
|
78
|
-
@article.comments.find(:all, :conditions => {:moderated => false}).size.should == 0
|
79
|
-
|
80
|
-
@comment1.destroy
|
81
|
-
$redis.zrange("article:#{@article.id}:comments:moderated:true", 0, -1).size.should == 1
|
82
|
-
$redis.zrange("article:#{@article.id}:comments:moderated:true", 0, -1)[0].should == @comment2.id.to_s
|
83
|
-
$redis.zrange("article:#{@article.id}:comments:moderated:false", 0, -1).size.should == 0
|
84
|
-
@article.comments.find(:all, :conditions => {:moderated => true}).size.should == 1
|
85
|
-
@article.comments.find(:all, :conditions => {:moderated => false}).size.should == 0
|
86
|
-
end
|
87
|
-
|
88
|
-
it "should properly find associated records (e.g. with :conditions, :order, etc options) '=' used for association" do
|
89
|
-
@article.comments = [@comment1, @comment2]
|
90
|
-
@article.comments.count.should == 2
|
91
|
-
|
92
|
-
@article.comments.all(:limit => 1).size.should == 1
|
93
|
-
@article.comments.find(:first).should be
|
94
|
-
@article.comments.find(:first).id.should == @comment1.id
|
95
|
-
@article.comments.find(:last).should be
|
96
|
-
@article.comments.find(:last).id.should == @comment2.id
|
97
|
-
|
98
|
-
@article.comments.find(:all, :conditions => {:moderated => true}).size.should == 1
|
99
|
-
@article.comments.find(:all, :conditions => {:moderated => false}).size.should == 1
|
100
|
-
@article.comments.find(:all, :conditions => {:moderated => true})[0].id.should == @comment2.id
|
101
|
-
@article.comments.find(:all, :conditions => {:moderated => false})[0].id.should == @comment1.id
|
102
|
-
|
103
|
-
@article.comments.find(:all, :conditions => {:moderated => true}, :limit => 1).size.should == 1
|
104
|
-
@article.comments.find(:all, :conditions => {:moderated => false}, :limit => 1).size.should == 1
|
105
|
-
@article.comments.find(:all, :conditions => {:moderated => true}, :limit => 1)[0].id.should == @comment2.id
|
106
|
-
@article.comments.find(:all, :conditions => {:moderated => false}, :limit => 1)[0].id.should == @comment1.id
|
107
|
-
|
108
|
-
@article.comments.find(:all, :conditions => {:moderated => true}, :limit => 1, :order => :desc).size.should == 1
|
109
|
-
@article.comments.find(:all, :conditions => {:moderated => false}, :limit => 1, :order => :asc).size.should == 1
|
110
|
-
@article.comments.find(:all, :conditions => {:moderated => true}, :limit => 1, :order => :desc)[0].id.should == @comment2.id
|
111
|
-
@article.comments.find(:all, :conditions => {:moderated => false}, :limit => 1, :order => :asc)[0].id.should == @comment1.id
|
112
|
-
|
113
|
-
@comment1.update_attribute :moderated, true
|
114
|
-
@article.comments.find(:all, :conditions => {:moderated => true}).size.should == 2
|
115
|
-
@article.comments.find(:all, :conditions => {:moderated => false}).size.should == 0
|
116
|
-
|
117
|
-
@comment1.destroy
|
118
|
-
@article.comments.find(:all, :conditions => {:moderated => true}).size.should == 1
|
119
|
-
@article.comments.find(:all, :conditions => {:moderated => false}).size.should == 0
|
120
|
-
$redis.zrange("article:#{@article.id}:comments:moderated:true", 0, -1).size.should == 1
|
121
|
-
$redis.zrange("article:#{@article.id}:comments:moderated:true", 0, -1)[0].should == @comment2.id.to_s
|
122
|
-
$redis.zrange("article:#{@article.id}:comments:moderated:false", 0, -1).size.should == 0
|
123
|
-
end
|
124
|
-
|
125
|
-
it "should check compound indices for associations" do
|
126
|
-
friend1 = User.create :name => "Director", :moderator => true, :moderated_area => "films"
|
127
|
-
friend2 = User.create :name => "Admin", :moderator => true, :moderated_area => "all"
|
128
|
-
friend3 = User.create :name => "Gena", :moderator => false
|
129
|
-
|
130
|
-
me = User.create :name => "german"
|
131
|
-
|
132
|
-
me.friends << [friend1, friend2, friend3]
|
133
|
-
|
134
|
-
me.friends.count.should == 3
|
135
|
-
me.friends.find(:all, :conditions => {:moderator => true}).size.should == 2
|
136
|
-
me.friends.find(:all, :conditions => {:moderator => false}).size.should == 1
|
137
|
-
|
138
|
-
me.friends.find(:all, :conditions => {:moderator => true, :moderated_area => "films"}).size.should == 1
|
139
|
-
me.friends.find(:all, :conditions => {:moderator => true, :moderated_area => "films"})[0].id.should == friend1.id
|
140
|
-
|
141
|
-
# reverse key's order in :conditions hash
|
142
|
-
me.friends.find(:all, :conditions => {:moderated_area => "all", :moderator => true}).size.should == 1
|
143
|
-
me.friends.find(:all, :conditions => {:moderated_area => "all", :moderator => true})[0].id.should == friend2.id
|
144
|
-
end
|
145
|
-
end
|