djsun-mongomapper 0.3.1 → 0.3.1.1
Sign up to get free protection for your applications and to get access to all the features.
@@ -50,7 +50,17 @@ module MongoMapper #:nodoc:
|
|
50
50
|
# "created_at": "2006/08/01", "awesome": true,
|
51
51
|
# "permalink": "1-konata-izumi"}
|
52
52
|
def to_json(options = {})
|
53
|
-
|
53
|
+
unless options[:only]
|
54
|
+
o = options[:methods]
|
55
|
+
if o && o.is_a?(Array)
|
56
|
+
o << :id
|
57
|
+
elsif o
|
58
|
+
o = [o, :id]
|
59
|
+
else
|
60
|
+
o = :id
|
61
|
+
end
|
62
|
+
options[:methods] = o
|
63
|
+
end
|
54
64
|
options.reverse_merge!(:except => :_id)
|
55
65
|
if include_root_in_json
|
56
66
|
"{#{self.class.json_class_name}: #{JsonSerializer.new(self, options).to_s}}"
|
data/mongomapper.gemspec
CHANGED
@@ -2,11 +2,11 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{mongomapper}
|
5
|
-
s.version = "0.3.1"
|
5
|
+
s.version = "0.3.1.1"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["John Nunemaker"]
|
9
|
-
s.date = %q{2009-08-
|
9
|
+
s.date = %q{2009-08-06}
|
10
10
|
s.default_executable = %q{mmconsole}
|
11
11
|
s.email = %q{nunemaker@gmail.com}
|
12
12
|
s.executables = ["mmconsole"]
|
@@ -80,7 +80,7 @@ Gem::Specification.new do |s|
|
|
80
80
|
s.rdoc_options = ["--charset=UTF-8"]
|
81
81
|
s.require_paths = ["lib"]
|
82
82
|
s.rubyforge_project = %q{mongomapper}
|
83
|
-
s.rubygems_version = %q{1.3.
|
83
|
+
s.rubygems_version = %q{1.3.5}
|
84
84
|
s.summary = %q{Awesome gem for modeling your domain and storing it in mongo}
|
85
85
|
s.test_files = [
|
86
86
|
"test/functional/associations/test_belongs_to_polymorphic_proxy.rb",
|
@@ -29,6 +29,7 @@ class JsonSerializationTest < Test::Unit::TestCase
|
|
29
29
|
should "encode all encodable attributes" do
|
30
30
|
json = @contact.to_json
|
31
31
|
|
32
|
+
assert_no_match %r{"_id"}, json
|
32
33
|
assert_match %r{"name":"Konata Izumi"}, json
|
33
34
|
assert_match %r{"age":16}, json
|
34
35
|
assert json.include?(%("created_at":#{ActiveSupport::JSON.encode(Time.utc(2006, 8, 1))}))
|
@@ -39,6 +40,7 @@ class JsonSerializationTest < Test::Unit::TestCase
|
|
39
40
|
should "allow attribute filtering with only" do
|
40
41
|
json = @contact.to_json(:only => [:name, :age])
|
41
42
|
|
43
|
+
assert_no_match %r{"_id"}, json
|
42
44
|
assert_match %r{"name":"Konata Izumi"}, json
|
43
45
|
assert_match %r{"age":16}, json
|
44
46
|
assert_no_match %r{"awesome"}, json
|
@@ -49,6 +51,7 @@ class JsonSerializationTest < Test::Unit::TestCase
|
|
49
51
|
should "allow attribute filtering with except" do
|
50
52
|
json = @contact.to_json(:except => [:name, :age])
|
51
53
|
|
54
|
+
assert_match %r{"_id"}, json
|
52
55
|
assert_no_match %r{"name"}, json
|
53
56
|
assert_no_match %r{"age"}, json
|
54
57
|
assert_match %r{"awesome"}, json
|
@@ -62,14 +65,31 @@ class JsonSerializationTest < Test::Unit::TestCase
|
|
62
65
|
def @contact.favorite_quote; "Constraints are liberating"; end
|
63
66
|
end
|
64
67
|
|
65
|
-
should "include
|
66
|
-
|
68
|
+
should "include label method" do
|
69
|
+
json = @contact.to_json(:methods => :label)
|
70
|
+
assert_match %r{"label":"Has cheezburger"}, json
|
71
|
+
end
|
72
|
+
|
73
|
+
should "include name and label method" do
|
74
|
+
json = @contact.to_json(:only => :name, :methods => :label)
|
75
|
+
|
76
|
+
assert_match %r{"label":"Has cheezburger"}, json
|
77
|
+
assert_match %r{"name":"Konata Izumi"}, json
|
78
|
+
assert_no_match %r{"age":16}, json
|
79
|
+
assert_no_match %r{"awesome"}, json
|
80
|
+
assert_no_match %r{"created_at"}, json
|
81
|
+
assert_no_match %r{"preferences"}, json
|
67
82
|
end
|
68
83
|
|
69
84
|
should "include multiple methods" do
|
70
85
|
json = @contact.to_json(:only => :name, :methods => [:label, :favorite_quote])
|
71
86
|
assert_match %r{"label":"Has cheezburger"}, json
|
72
87
|
assert_match %r{"favorite_quote":"Constraints are liberating"}, json
|
88
|
+
assert_match %r{"name":"Konata Izumi"}, json
|
89
|
+
assert_no_match %r{"age":16}, json
|
90
|
+
assert_no_match %r{"awesome"}, json
|
91
|
+
assert_no_match %r{"created_at"}, json
|
92
|
+
assert_no_match %r{"preferences"}, json
|
73
93
|
end
|
74
94
|
end
|
75
95
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: djsun-mongomapper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.1
|
4
|
+
version: 0.3.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Nunemaker
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-08-
|
12
|
+
date: 2009-08-06 00:00:00 -07:00
|
13
13
|
default_executable: mmconsole
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|