mm_no_empties 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/mm_no_empties/version.rb +1 -1
- data/lib/mm_no_empties.rb +1 -1
- data/spec/mm_no_empties_spec.rb +13 -1
- metadata +2 -2
data/lib/mm_no_empties.rb
CHANGED
@@ -16,7 +16,7 @@ module MmNoEmpties
|
|
16
16
|
else
|
17
17
|
keys.select do |name, key|
|
18
18
|
val = self[key.name]
|
19
|
-
key.type == ObjectId or
|
19
|
+
#key.type == ObjectId or # this is in the original :attributes implementation, but is seems safe to remove it as 'belongs_to: nil' if it's missing
|
20
20
|
not (val.nil? or (val.respond_to?(:empty?) and val.empty?))
|
21
21
|
end
|
22
22
|
end
|
data/spec/mm_no_empties_spec.rb
CHANGED
@@ -3,11 +3,19 @@ require File.expand_path('../../lib/mm_no_empties', __FILE__)
|
|
3
3
|
describe MmNoEmpties do
|
4
4
|
|
5
5
|
before(:all) do
|
6
|
+
class Company
|
7
|
+
include MongoMapper::Document
|
8
|
+
many :groups
|
9
|
+
end
|
10
|
+
|
6
11
|
class Group
|
7
12
|
include MongoMapper::Document
|
8
13
|
plugin MmNoEmpties
|
9
14
|
|
10
15
|
many :people, :class_name => 'Person'
|
16
|
+
belongs_to :company
|
17
|
+
|
18
|
+
key :motto, String
|
11
19
|
|
12
20
|
key :names, Array
|
13
21
|
key :counts, Hash
|
@@ -35,8 +43,12 @@ describe MmNoEmpties do
|
|
35
43
|
@group.attributes.keys.should_not include('names', 'counts', 'tags')
|
36
44
|
end
|
37
45
|
|
46
|
+
it "should not include nil values in 'attributes'" do
|
47
|
+
@group.attributes.keys.should_not include('motto')
|
48
|
+
end
|
49
|
+
|
38
50
|
it "should not include unused many associations in attributes" do
|
39
|
-
@group.attributes.keys.should_not include('people')
|
51
|
+
@group.attributes.keys.should_not include('people', 'company_id')
|
40
52
|
end
|
41
53
|
|
42
54
|
it "should restore empty fields when loading from the database" do
|