rocking_chair 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/rocking_chair/view.rb +18 -15
- data/test/simply_stored_test.rb +21 -0
- metadata +20 -9
data/lib/rocking_chair/view.rb
CHANGED
@@ -192,24 +192,27 @@ module RockingChair
|
|
192
192
|
def sort_by_attribute(attribute)
|
193
193
|
attribute ||= '_id'
|
194
194
|
@keys = (options['descending'].to_s == 'true') ?
|
195
|
-
keys.sort{|x,y|
|
196
|
-
|
195
|
+
keys.sort{|x,y|
|
196
|
+
if RockingChair::Helper.access(attribute, ruby_store[y]).nil?
|
197
|
+
-1
|
198
|
+
else
|
199
|
+
RockingChair::Helper.access(attribute, ruby_store[y]) <=> RockingChair::Helper.access(attribute, ruby_store[x])
|
200
|
+
end } :
|
201
|
+
keys.sort{|x,y|
|
202
|
+
if RockingChair::Helper.access(attribute, ruby_store[x]).nil?
|
203
|
+
-1
|
204
|
+
else
|
205
|
+
RockingChair::Helper.access(attribute, ruby_store[x]) <=> RockingChair::Helper.access(attribute, ruby_store[y])
|
206
|
+
end }
|
197
207
|
end
|
198
208
|
|
199
209
|
def filter_items_without_attribute_value(attribute, attr_value)
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
RockingChair::Helper.access(attribute, document) == attr_value
|
207
|
-
end
|
208
|
-
end
|
209
|
-
else
|
210
|
-
@keys = keys.select do |key|
|
211
|
-
document = ruby_store[key]
|
212
|
-
RockingChair::Helper.access(attribute, document).present?
|
210
|
+
@keys = keys.select do |key|
|
211
|
+
document = ruby_store[key]
|
212
|
+
if RockingChair::Helper.access(attribute, document).is_a?(Array)
|
213
|
+
RockingChair::Helper.access(attribute, document).include?(attr_value)
|
214
|
+
else
|
215
|
+
RockingChair::Helper.access(attribute, document) == attr_value
|
213
216
|
end
|
214
217
|
end
|
215
218
|
end
|
data/test/simply_stored_test.rb
CHANGED
@@ -172,6 +172,27 @@ class SimplyStoredTest < Test::Unit::TestCase
|
|
172
172
|
assert_equal 3, User.count
|
173
173
|
end
|
174
174
|
|
175
|
+
should "count_by" do
|
176
|
+
User.create(:firstname => 'michael')
|
177
|
+
|
178
|
+
assert_equal 1, User.count
|
179
|
+
assert_equal 1, User.count_by_firstname('michael')
|
180
|
+
end
|
181
|
+
|
182
|
+
should "count_by with nil attributes" do
|
183
|
+
Project.create(:title => nil)
|
184
|
+
|
185
|
+
assert_equal 1, Project.count
|
186
|
+
assert_equal 1, Project.count_by_title(nil)
|
187
|
+
|
188
|
+
Project.create(:title => nil, :manager_id => 12)
|
189
|
+
|
190
|
+
assert_equal 2, Project.count
|
191
|
+
assert_equal 2, Project.count_by_title(nil)
|
192
|
+
assert_equal 1, Project.count_by_manager_id(12)
|
193
|
+
assert_equal 1, Project.count_by_manager_id_and_title(12, nil)
|
194
|
+
end
|
195
|
+
|
175
196
|
context "with deleted" do
|
176
197
|
setup do
|
177
198
|
RockingChair::Server.reset
|
metadata
CHANGED
@@ -1,7 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rocking_chair
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 0
|
8
|
+
- 6
|
9
|
+
version: 0.0.6
|
5
10
|
platform: ruby
|
6
11
|
authors:
|
7
12
|
- Jonathan Weiss
|
@@ -9,19 +14,23 @@ autorequire:
|
|
9
14
|
bindir: bin
|
10
15
|
cert_chain: []
|
11
16
|
|
12
|
-
date: 2010-
|
17
|
+
date: 2010-04-21 00:00:00 +02:00
|
13
18
|
default_executable:
|
14
19
|
dependencies:
|
15
20
|
- !ruby/object:Gem::Dependency
|
16
21
|
name: simply_stored
|
17
|
-
|
18
|
-
|
19
|
-
version_requirements: !ruby/object:Gem::Requirement
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
20
24
|
requirements:
|
21
25
|
- - ">="
|
22
26
|
- !ruby/object:Gem::Version
|
27
|
+
segments:
|
28
|
+
- 0
|
29
|
+
- 1
|
30
|
+
- 12
|
23
31
|
version: 0.1.12
|
24
|
-
|
32
|
+
type: :runtime
|
33
|
+
version_requirements: *id001
|
25
34
|
description: In-memory CouchDB for Couchrest and SimplyStored. Works for database and document API, by_attribute views, and for SimplyStored generated views
|
26
35
|
email: jw@innerewut.de
|
27
36
|
executables: []
|
@@ -54,18 +63,20 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
54
63
|
requirements:
|
55
64
|
- - ">="
|
56
65
|
- !ruby/object:Gem::Version
|
66
|
+
segments:
|
67
|
+
- 0
|
57
68
|
version: "0"
|
58
|
-
version:
|
59
69
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
60
70
|
requirements:
|
61
71
|
- - ">="
|
62
72
|
- !ruby/object:Gem::Version
|
73
|
+
segments:
|
74
|
+
- 0
|
63
75
|
version: "0"
|
64
|
-
version:
|
65
76
|
requirements: []
|
66
77
|
|
67
78
|
rubyforge_project:
|
68
|
-
rubygems_version: 1.3.
|
79
|
+
rubygems_version: 1.3.6
|
69
80
|
signing_key:
|
70
81
|
specification_version: 3
|
71
82
|
summary: In-memory CouchDB for Couchrest and SimplyStored
|