activeobject 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGE +10 -0
- data/Interface_desc +21 -0
- data/MIT-LICENSE +20 -0
- data/README +72 -0
- data/Rakefile.rb +9 -0
- data/active-object.gemspec +50 -0
- data/examples/account.rb +69 -0
- data/examples/data.tch +0 -0
- data/examples/light_cloud.yml +18 -0
- data/examples/test.rb +3 -0
- data/examples/user.rb +112 -0
- data/init.rb +4 -0
- data/lib/active-object.rb +23 -0
- data/lib/active_object/adapters/light_cloud.rb +40 -0
- data/lib/active_object/adapters/tokyo_cabinet.rb +48 -0
- data/lib/active_object/adapters/tokyo_tyrant.rb +14 -0
- data/lib/active_object/associations.rb +200 -0
- data/lib/active_object/base.rb +415 -0
- data/lib/active_object/callbacks.rb +180 -0
- data/lib/active_object/observer.rb +180 -0
- data/lib/active_object/serialization.rb +99 -0
- data/lib/active_object/serializers/json_serializer.rb +75 -0
- data/lib/active_object/serializers/xml_serializer.rb +325 -0
- data/lib/active_object/validations.rb +687 -0
- data/lib/active_support/callbacks.rb +303 -0
- data/lib/active_support/core_ext/array/access.rb +53 -0
- data/lib/active_support/core_ext/array/conversions.rb +183 -0
- data/lib/active_support/core_ext/array/extract_options.rb +20 -0
- data/lib/active_support/core_ext/array/grouping.rb +106 -0
- data/lib/active_support/core_ext/array/random_access.rb +12 -0
- data/lib/active_support/core_ext/array.rb +13 -0
- data/lib/active_support/core_ext/blank.rb +58 -0
- data/lib/active_support/core_ext/class/attribute_accessors.rb +54 -0
- data/lib/active_support/core_ext/class/inheritable_attributes.rb +140 -0
- data/lib/active_support/core_ext/class/removal.rb +50 -0
- data/lib/active_support/core_ext/class.rb +3 -0
- data/lib/active_support/core_ext/duplicable.rb +43 -0
- data/lib/active_support/core_ext/enumerable.rb +72 -0
- data/lib/active_support/core_ext/hash/conversions.rb +259 -0
- data/lib/active_support/core_ext/hash/keys.rb +52 -0
- data/lib/active_support/core_ext/hash.rb +8 -0
- data/lib/active_support/core_ext/module/aliasing.rb +74 -0
- data/lib/active_support/core_ext/module/attr_accessor_with_default.rb +31 -0
- data/lib/active_support/core_ext/module/attribute_accessors.rb +58 -0
- data/lib/active_support/core_ext/module.rb +16 -0
- data/lib/active_support/core_ext/object/conversions.rb +14 -0
- data/lib/active_support/core_ext/object/extending.rb +80 -0
- data/lib/active_support/core_ext/object/instance_variables.rb +74 -0
- data/lib/active_support/core_ext/object/metaclass.rb +13 -0
- data/lib/active_support/core_ext/object/misc.rb +43 -0
- data/lib/active_support/core_ext/object.rb +5 -0
- data/lib/active_support/core_ext/string/inflections.rb +167 -0
- data/lib/active_support/core_ext/string.rb +7 -0
- data/lib/active_support/core_ext.rb +4 -0
- data/lib/active_support/inflections.rb +55 -0
- data/lib/active_support/inflector.rb +348 -0
- data/lib/active_support/vendor/builder-2.1.2/blankslate.rb +113 -0
- data/lib/active_support/vendor/builder-2.1.2/builder/blankslate.rb +20 -0
- data/lib/active_support/vendor/builder-2.1.2/builder/css.rb +250 -0
- data/lib/active_support/vendor/builder-2.1.2/builder/xchar.rb +115 -0
- data/lib/active_support/vendor/builder-2.1.2/builder/xmlbase.rb +139 -0
- data/lib/active_support/vendor/builder-2.1.2/builder/xmlevents.rb +63 -0
- data/lib/active_support/vendor/builder-2.1.2/builder/xmlmarkup.rb +328 -0
- data/lib/active_support/vendor/builder-2.1.2/builder.rb +13 -0
- data/lib/active_support/vendor/xml-simple-1.0.11/xmlsimple.rb +1021 -0
- data/lib/active_support/vendor.rb +14 -0
- data/lib/active_support.rb +6 -0
- data/spec/case/association_test.rb +97 -0
- data/spec/case/base_test.rb +74 -0
- data/spec/case/callbacks_observers_test.rb +38 -0
- data/spec/case/callbacks_test.rb +424 -0
- data/spec/case/serialization_test.rb +87 -0
- data/spec/case/validations_test.rb +1482 -0
- data/spec/data.tch +0 -0
- data/spec/helper.rb +15 -0
- data/spec/light_cloud.yml +18 -0
- data/spec/model/account.rb +4 -0
- data/spec/model/topic.rb +26 -0
- data/spec/model/user.rb +8 -0
- metadata +173 -0
@@ -0,0 +1,87 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__),'..','helper')
|
2
|
+
require File.join(File.dirname(__FILE__),'..','model','user')
|
3
|
+
|
4
|
+
require 'rubygems'
|
5
|
+
|
6
|
+
require 'builder'
|
7
|
+
|
8
|
+
user = Array(User.new(@attributes))
|
9
|
+
puts user.to_json
|
10
|
+
|
11
|
+
class SerializationTest < Test::Unit::TestCase
|
12
|
+
def setup
|
13
|
+
@attributes = {:name=>'Aaron',:email=>'aaron@nonobo.com',:password=>'123456'}
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_to_json
|
17
|
+
assert_not_equal User.new(@attributes).to_json,nil
|
18
|
+
end
|
19
|
+
|
20
|
+
# def test_array_to_json
|
21
|
+
# @users = []
|
22
|
+
# @users << User.new(@attributes)
|
23
|
+
# @users << User.new(@attributes.merge(:email=>"kame@nonobo.com"))
|
24
|
+
# @users << User.new(@attributes.merge(:email=>"jim@nonobo.com"))
|
25
|
+
#
|
26
|
+
# assert_nothing_raised do
|
27
|
+
# @users.to_json()
|
28
|
+
# end
|
29
|
+
# end
|
30
|
+
|
31
|
+
def test_to_json_include_has_many
|
32
|
+
@u = User.create(@attributes)
|
33
|
+
|
34
|
+
f = User.create(@attributes.merge(:name=>'kame',:email=>'kame@nonobo.com',:password=>'123456'))
|
35
|
+
@u.friends.append(f)
|
36
|
+
@u.save
|
37
|
+
|
38
|
+
assert_equal @u.to_json(:include=>:friends).grep(/kame/).empty?,false
|
39
|
+
end
|
40
|
+
|
41
|
+
# def test_array_to_json_include_has_many
|
42
|
+
# @users = []
|
43
|
+
# @users << User.new(@attributes)
|
44
|
+
# @users << User.new(@attributes.merge(:email=>"kame@nonobo.com"))
|
45
|
+
# @users << User.new(@attributes.merge(:email=>"jim@nonobo.com"))
|
46
|
+
#
|
47
|
+
# assert_nothing_raised do
|
48
|
+
# @users.to_json(:include=>:friends)
|
49
|
+
# end
|
50
|
+
# end
|
51
|
+
|
52
|
+
def test_to_json_include_has_one
|
53
|
+
@u = User.create(@attributes)
|
54
|
+
|
55
|
+
f = User.create(@attributes.merge(:name=>'rita',:email=>'rita@nonobo.com',:password=>'123456'))
|
56
|
+
@u.wife = f
|
57
|
+
@u.save
|
58
|
+
|
59
|
+
assert_equal @u.to_json(:include=>:wife).grep(/rita/).empty?,false
|
60
|
+
end
|
61
|
+
|
62
|
+
|
63
|
+
def test_to_xml
|
64
|
+
assert_not_equal User.new(@attributes).to_xml,nil
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_to_xml_include_has_many
|
68
|
+
@u = User.create(@attributes)
|
69
|
+
|
70
|
+
f = User.create(@attributes.merge(:name=>'kame',:email=>'kame@nonobo.com',:password=>'123456'))
|
71
|
+
@u.friends.append(f)
|
72
|
+
@u.save
|
73
|
+
|
74
|
+
assert_equal @u.to_xml(:include=>:friends).grep(/kame/).empty?,false
|
75
|
+
end
|
76
|
+
|
77
|
+
def test_to_xml_include_has_one
|
78
|
+
@u = User.create(@attributes)
|
79
|
+
|
80
|
+
f = User.create(@attributes.merge(:name=>'rita',:email=>'rita@nonobo.com',:password=>'123456'))
|
81
|
+
@u.wife = f
|
82
|
+
@u.save
|
83
|
+
|
84
|
+
assert_equal @u.to_xml(:include=>:wife).grep(/rita/).empty?,false
|
85
|
+
end
|
86
|
+
|
87
|
+
end
|