purzelrakete-restful 0.2.1
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.
- data/LICENSE.markdown +22 -0
- data/README.markdown +108 -0
- data/Rakefile +22 -0
- data/TODO.markdown +7 -0
- data/init.rb +1 -0
- data/lib/restful/apimodel/attribute.rb +17 -0
- data/lib/restful/apimodel/collection.rb +14 -0
- data/lib/restful/apimodel/link.rb +21 -0
- data/lib/restful/apimodel/resource.rb +47 -0
- data/lib/restful/converters/active_record.rb +128 -0
- data/lib/restful/rails/action_controller.rb +14 -0
- data/lib/restful/rails/active_record/configuration.rb +114 -0
- data/lib/restful/rails/active_record/metadata_tools.rb +106 -0
- data/lib/restful/rails.rb +22 -0
- data/lib/restful/serializers/atom_like_serializer.rb +51 -0
- data/lib/restful/serializers/base.rb +41 -0
- data/lib/restful/serializers/hash_serializer.rb +45 -0
- data/lib/restful/serializers/json_serializer.rb +20 -0
- data/lib/restful/serializers/params_serializer.rb +40 -0
- data/lib/restful/serializers/xml_serializer.rb +146 -0
- data/lib/restful.rb +64 -0
- data/rails/init.rb +1 -0
- data/restful.gemspec +17 -0
- data/test/converters/active_record_converter_test.rb +108 -0
- data/test/fixtures/models/person.rb +17 -0
- data/test/fixtures/models/pet.rb +5 -0
- data/test/fixtures/models/wallet.rb +5 -0
- data/test/fixtures/people.json.yaml +16 -0
- data/test/fixtures/people.xml.yaml +105 -0
- data/test/fixtures/pets.xml.yaml +21 -0
- data/test/rails/active_record_metadata_test.rb +23 -0
- data/test/rails/configuration_test.rb +45 -0
- data/test/rails/restful_publish_test.rb +41 -0
- data/test/serializers/atom_serializer_test.rb +33 -0
- data/test/serializers/json_serializer_test.rb +21 -0
- data/test/serializers/params_serializer_test.rb +44 -0
- data/test/serializers/xml_serializer_test.rb +38 -0
- data/test/test_helper.rb +129 -0
- metadata +93 -0
@@ -0,0 +1,105 @@
|
|
1
|
+
joe_bloggs:
|
2
|
+
|
|
3
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
4
|
+
<person>
|
5
|
+
<restful-url type="link">http://example.com:3000/people/<%= @person.id %></restful-url>
|
6
|
+
<name>Joe Bloggs</name>
|
7
|
+
<wallet-restful-url type="link">http://example.com:3000/wallets/<%= @wallet.id %></wallet-restful-url>
|
8
|
+
</person>
|
9
|
+
|
10
|
+
no_wallet:
|
11
|
+
|
|
12
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
13
|
+
<person>
|
14
|
+
<restful-url type="link">http://example.com:3000/people/<%= @person.id %></restful-url>
|
15
|
+
<location-sentence><%= @person.location_sentence %></location-sentence>
|
16
|
+
</person>
|
17
|
+
|
18
|
+
with_oldest_pet:
|
19
|
+
|
|
20
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
21
|
+
<person>
|
22
|
+
<restful-url type="link">http://example.com:3000/people/<%= @person.id %></restful-url>
|
23
|
+
<oldest-pet>
|
24
|
+
<restful-url type="link">http://example.com:3000/pets/<%= @person.oldest_pet.id %></restful-url>
|
25
|
+
<name><%= @person.oldest_pet.name %></name>
|
26
|
+
<person-restful-url type="link">http://example.com:3000/people/<%= @person.id %></person-restful-url>
|
27
|
+
</oldest-pet>
|
28
|
+
</person>
|
29
|
+
|
30
|
+
with_oldest_pet_species:
|
31
|
+
|
|
32
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
33
|
+
<person>
|
34
|
+
<restful-url type="link">http://example.com:3000/people/<%= @person.id %></restful-url>
|
35
|
+
<oldest-pet>
|
36
|
+
<restful-url type="link">http://example.com:3000/pets/<%= @person.oldest_pet.id %></restful-url>
|
37
|
+
<species type="integer"><%= @person.oldest_pet.species %></species>
|
38
|
+
</oldest-pet>
|
39
|
+
</person>
|
40
|
+
|
41
|
+
joe_with_zwiebelleder:
|
42
|
+
|
|
43
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
44
|
+
<person>
|
45
|
+
<restful-url type="link">http://example.com:3000/people/<%= @person.id %></restful-url>
|
46
|
+
<wallet nil="true"></wallet>
|
47
|
+
</person>
|
48
|
+
|
49
|
+
atom_person:
|
50
|
+
|
|
51
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
52
|
+
<person xml:base="http://example.com:3000">
|
53
|
+
<created-at><%= @person.created_at.xmlschema %></created-at>
|
54
|
+
<link rel="self" href="/people/<%= @person.id %>"/>
|
55
|
+
<name>Joe Bloggs</name>
|
56
|
+
<current-location>Under a tree</current-location>
|
57
|
+
<pets>
|
58
|
+
<pet>
|
59
|
+
<link rel="self" href="/pets/<%= @pet.id %>"/>
|
60
|
+
<name>mietze</name>
|
61
|
+
</pet>
|
62
|
+
</pets>
|
63
|
+
<wallet>
|
64
|
+
<link rel="self" href="/wallets/<%= @wallet.id %>"/>
|
65
|
+
<contents>an old photo, 5 euros in coins</contents>
|
66
|
+
</wallet>
|
67
|
+
</person>
|
68
|
+
|
69
|
+
verbose_with_pets:
|
70
|
+
|
|
71
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
72
|
+
<person>
|
73
|
+
<restful-url type="link">http://example.com:3000/people/<%= @person.id %></restful-url>
|
74
|
+
<name>Joe Bloggs</name>
|
75
|
+
<created-at type="datetime"><%= @person.created_at.xmlschema %></created-at>
|
76
|
+
<current-location>Under a tree</current-location>
|
77
|
+
<pets type="array">
|
78
|
+
<pet>
|
79
|
+
<restful-url type="link">http://example.com:3000/pets/<%= @pet.id %></restful-url>
|
80
|
+
<name>mietze</name>
|
81
|
+
</pet>
|
82
|
+
</pets>
|
83
|
+
<wallet-restful-url type="link" nil="true"></wallet-restful-url>
|
84
|
+
</person>
|
85
|
+
|
86
|
+
with_pets_and_expanded_wallet:
|
87
|
+
|
|
88
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
89
|
+
<person>
|
90
|
+
<restful-url type="link">http://example.com:3000/people/<%= @person.id %></restful-url>
|
91
|
+
<name>Joe Bloggs</name>
|
92
|
+
<created-at type="datetime"><%= @person.created_at.xmlschema %></created-at>
|
93
|
+
<current-location>Under a tree</current-location>
|
94
|
+
<pets type="array">
|
95
|
+
<pet>
|
96
|
+
<restful-url type="link">http://example.com:3000/pets/<%= @pet.id %></restful-url>
|
97
|
+
<name>mietze</name>
|
98
|
+
</pet>
|
99
|
+
</pets>
|
100
|
+
<wallet>
|
101
|
+
<restful-url type="link">http://example.com:3000/wallets/<%= @wallet.id %></restful-url>
|
102
|
+
<contents>an old photo, 5 euros in coins</contents>
|
103
|
+
</wallet>
|
104
|
+
</person>
|
105
|
+
|
@@ -0,0 +1,21 @@
|
|
1
|
+
nameless_pet:
|
2
|
+
|
|
3
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
4
|
+
<pet>
|
5
|
+
<restful-url type="link">http://example.com:3000/pets/<%= @pet.id %></restful-url>
|
6
|
+
<owner>
|
7
|
+
<restful-url type="link">http://example.com:3000/people/<%= @person.id %></restful-url>
|
8
|
+
<name>Joe Bloggs</name>
|
9
|
+
<current-location>Under a tree</current-location>
|
10
|
+
<wallet-restful-url type="link">http://example.com:3000/wallets/<%= @wallet.id %></wallet-restful-url>
|
11
|
+
</owner>
|
12
|
+
</pet>
|
13
|
+
|
14
|
+
gracie:
|
15
|
+
|
|
16
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
17
|
+
<pet>
|
18
|
+
<person-restful-url type="link">http://example.com:3000/people/<%= @person.id %></person-restful-url>
|
19
|
+
<species>123</species>
|
20
|
+
<name>Gracie</name>
|
21
|
+
</pet>
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../test_helper.rb'
|
2
|
+
|
3
|
+
context "active record metadata" do
|
4
|
+
setup do
|
5
|
+
Person.restful_publish(:name, :pets => [:name, :species])
|
6
|
+
Pet.restful_publish(:person_id, :name) # person_id gets converted to a link automagically.
|
7
|
+
|
8
|
+
@person = Person.create(:name => "Jimmy Jones", :current_location => "Under a tree")
|
9
|
+
@pet = @person.pets.create(:name => "Mietze", :species => "cat")
|
10
|
+
end
|
11
|
+
|
12
|
+
teardown do
|
13
|
+
reset_config
|
14
|
+
end
|
15
|
+
|
16
|
+
specify "should be able to convert a collection to an array of resources" do
|
17
|
+
resources = Restful::Rails.tools.convert_collection_to_resources(@person, :pets, Restful.cfg)
|
18
|
+
pet = resources.first
|
19
|
+
|
20
|
+
resources.size.should.equal 1
|
21
|
+
pet.url.should.equal @pet.to_restful.url
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../test_helper.rb'
|
2
|
+
|
3
|
+
context "Configuration" do
|
4
|
+
specify "should have an empty whitelist if only restful options are passed in" do
|
5
|
+
config = Restful.cfg
|
6
|
+
config.restful_options[:expansion] = :expanded
|
7
|
+
config.whitelisted.should.empty
|
8
|
+
end
|
9
|
+
|
10
|
+
specify "should return fields without restful_options via whitelisted" do
|
11
|
+
config = Restful.cfg([:one, :two])
|
12
|
+
config.restful_options[:expansion] = :expanded
|
13
|
+
config.whitelisted.should.not.include :restful_options
|
14
|
+
end
|
15
|
+
|
16
|
+
specify "should have 0 whitelisted fields if none were specified" do
|
17
|
+
end
|
18
|
+
|
19
|
+
specify "should know if it has restful_options" do
|
20
|
+
config = Restful.cfg([:one, :two])
|
21
|
+
config.restful_options[:expansion] = :expanded
|
22
|
+
config.restful_options.should.not.empty
|
23
|
+
end
|
24
|
+
|
25
|
+
specify "should be able to handle nested whitelist attributes" do
|
26
|
+
config = Restful.cfg(:one, :two => [:a, :b])
|
27
|
+
config.nested(:two).whitelisted.should.== [:a,:b]
|
28
|
+
end
|
29
|
+
|
30
|
+
specify "should set restful options when set in to_restful method" do
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
specify "should know which attributes are published" do
|
35
|
+
config = Restful.cfg(:one, :two => [:a, :b])
|
36
|
+
config.published?(:two).should.== true
|
37
|
+
config.published?(:one).should.== true
|
38
|
+
end
|
39
|
+
|
40
|
+
specify "should know if it is nested" do
|
41
|
+
config = Restful.cfg(:one, :restful_options => {:nested => true})
|
42
|
+
config.nested?.should.== true
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../test_helper.rb'
|
2
|
+
|
3
|
+
context "restful publish" do
|
4
|
+
teardown do
|
5
|
+
reset_config
|
6
|
+
end
|
7
|
+
|
8
|
+
specify "should result in a method .published?(:attr_key) return true for published attributes" do
|
9
|
+
Pet.restful_publish(:person_id, :name) # person_id gets converted to a link automagically.
|
10
|
+
|
11
|
+
Pet.restful_config.published?(:name).should.equal true
|
12
|
+
Pet.restful_config.published?(:pets).should.equal false
|
13
|
+
Pet.restful_config.published?(:species).should.equal false
|
14
|
+
end
|
15
|
+
|
16
|
+
specify "should have restful_options as an empty hash after calling restful_publish" do
|
17
|
+
Person.restful_publish(:name, :pets => [:name, :species])
|
18
|
+
Person.restful_config.restful_options.should.==({})
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
context "api publishing with nesting" do
|
23
|
+
teardown do
|
24
|
+
reset_config
|
25
|
+
end
|
26
|
+
|
27
|
+
specify "should result in a method .published?(:attr_key) return true for nested attributes" do
|
28
|
+
Person.restful_publish(:name, :pets => [:name, :species])
|
29
|
+
Person.restful_config.published?(:pets).should.equal true
|
30
|
+
end
|
31
|
+
|
32
|
+
specify "should be invoke to_restful on the nested model with the specified nested attributes" do
|
33
|
+
Person.restful_publish(:name, :pets => [:name, :species])
|
34
|
+
@person = Person.create(:name => "Joe Bloggs", :current_location => "Under a tree")
|
35
|
+
@pet = @person.pets.create(:name => "Mietze", :species => "cat")
|
36
|
+
|
37
|
+
Pet.any_instance.expects(:to_restful).with { |arg| arg.whitelisted == [:name, :species] }
|
38
|
+
@person.to_restful
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../test_helper.rb'
|
2
|
+
|
3
|
+
context "params serializer" do
|
4
|
+
|
5
|
+
setup do
|
6
|
+
Person.restful_publish(:name, :current_location, :pets, :wallet, :created_at)
|
7
|
+
Pet.restful_publish(:name)
|
8
|
+
Wallet.restful_publish(:contents)
|
9
|
+
|
10
|
+
@person = Person.create(:name => "Joe Bloggs", :current_location => "Under a tree")
|
11
|
+
@pet = @person.pets.create(:species => "cat", :age => 200, :name => "mietze")
|
12
|
+
@wallet = @person.wallet = Wallet.new(:contents => "an old photo, 5 euros in coins")
|
13
|
+
@person.save
|
14
|
+
end
|
15
|
+
|
16
|
+
teardown do
|
17
|
+
reset_config
|
18
|
+
end
|
19
|
+
|
20
|
+
specify "serialize to xml, atom style" do
|
21
|
+
xml_should_eql_fixture(@person.to_restful_atom_like, "people", :atom_person)
|
22
|
+
end
|
23
|
+
|
24
|
+
specify "deserialize from atom style xml" do
|
25
|
+
restful = @pet.to_restful
|
26
|
+
expected = restful.serialize(:atom_like)
|
27
|
+
serializer = Restful::Serializers::AtomLikeSerializer.new
|
28
|
+
resource = serializer.deserialize(expected)
|
29
|
+
actual = serializer.serialize(resource)
|
30
|
+
|
31
|
+
xml_should_eql(expected, actual)
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../test_helper.rb'
|
2
|
+
|
3
|
+
context "json serializer" do
|
4
|
+
|
5
|
+
setup do
|
6
|
+
Person.restful_publish(:name, :current_location, :pets, :wallet, :created_at)
|
7
|
+
Pet.restful_publish(:name)
|
8
|
+
Wallet.restful_publish(:contents)
|
9
|
+
|
10
|
+
@person = Person.create(:name => "Joe Bloggs", :current_location => "Under a tree")
|
11
|
+
@pet = @person.pets.create(:species => "cat", :age => 200, :name => "mietze")
|
12
|
+
@wallet = @person.wallet = Wallet.new(:contents => "an old photo, 5 euros in coins")
|
13
|
+
@person.save
|
14
|
+
end
|
15
|
+
|
16
|
+
teardown { reset_config }
|
17
|
+
|
18
|
+
specify "serialize to json" do
|
19
|
+
json_should_eql_fixture(@person.to_restful_json, "people", :bloggs)
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../test_helper.rb'
|
2
|
+
|
3
|
+
context "params serializer" do
|
4
|
+
|
5
|
+
setup do
|
6
|
+
Person.restful_publish(:name, :current_location, :pets, :wallet, :created_at)
|
7
|
+
Pet.restful_publish(:name)
|
8
|
+
Wallet.restful_publish(:contents)
|
9
|
+
|
10
|
+
@person = Person.create(:name => "Joe Bloggs", :current_location => "Under a tree")
|
11
|
+
@pet = @person.pets.create(:species => "cat", :age => 200, :name => "mietze")
|
12
|
+
@wallet = @person.wallet = Wallet.new(:contents => "an old photo, 5 euros in coins")
|
13
|
+
@person.save
|
14
|
+
end
|
15
|
+
|
16
|
+
teardown do
|
17
|
+
reset_config
|
18
|
+
end
|
19
|
+
|
20
|
+
specify "serialize to params" do
|
21
|
+
actual = @person.to_restful.serialize(:params)
|
22
|
+
|
23
|
+
expected =
|
24
|
+
{
|
25
|
+
:name => "Joe Bloggs",
|
26
|
+
:current_location => "Under a tree",
|
27
|
+
:created_at => @person.created_at,
|
28
|
+
:wallet_attributes=>{:contents=>"an old photo, 5 euros in coins"},
|
29
|
+
:pets_attributes => [ {:name => "mietze"} ]
|
30
|
+
}
|
31
|
+
|
32
|
+
actual.should.== expected
|
33
|
+
end
|
34
|
+
|
35
|
+
specify "serialize to an ar params hash" do
|
36
|
+
input = xml_fixture("pets")[:gracie]
|
37
|
+
params = Restful.from_xml(input).serialize(:params)
|
38
|
+
clone = Pet.create!(params)
|
39
|
+
|
40
|
+
clone.name.should.== "Gracie"
|
41
|
+
clone.species.should.== 123
|
42
|
+
clone.person_id.should.== @person.id
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../test_helper.rb'
|
2
|
+
|
3
|
+
context "params serializer" do
|
4
|
+
setup do
|
5
|
+
Person.restful_publish(:name, :current_location, :pets, :wallet, :created_at)
|
6
|
+
Pet.restful_publish(:name)
|
7
|
+
Wallet.restful_publish(:contents)
|
8
|
+
|
9
|
+
@person = Person.create(:name => "Joe Bloggs", :current_location => "Under a tree")
|
10
|
+
@pet = @person.pets.create(:species => "cat", :age => 200, :name => "mietze")
|
11
|
+
@wallet = @person.wallet = Wallet.new(:contents => "an old photo, 5 euros in coins")
|
12
|
+
@person.save
|
13
|
+
end
|
14
|
+
|
15
|
+
teardown do
|
16
|
+
reset_config
|
17
|
+
end
|
18
|
+
|
19
|
+
specify "deserialize from rails style xml" do
|
20
|
+
restful = @person.to_restful
|
21
|
+
expected = restful.serialize(:xml)
|
22
|
+
serializer = Restful::Serializers::XMLSerializer.new
|
23
|
+
resource = serializer.deserialize(expected)
|
24
|
+
actual = serializer.serialize(resource)
|
25
|
+
|
26
|
+
xml_should_eql(expected, actual)
|
27
|
+
end
|
28
|
+
|
29
|
+
specify "should convert a NULL inner association such as person.wallet to a link with a null value" do
|
30
|
+
@person.wallet = nil
|
31
|
+
|
32
|
+
xml_should_eql_fixture(@person.to_restful_xml(:restful_options => { :expansion => :collapsed }), "people", :verbose_with_pets)
|
33
|
+
end
|
34
|
+
|
35
|
+
specify "serialize to xml, rails style" do
|
36
|
+
xml_should_eql_fixture(@person.to_restful_xml, "people", :with_pets_and_expanded_wallet)
|
37
|
+
end
|
38
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,129 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'ruby-debug'
|
3
|
+
require 'active_support'
|
4
|
+
require 'active_record'
|
5
|
+
require 'action_controller'
|
6
|
+
require 'test/spec'
|
7
|
+
require 'mocha'
|
8
|
+
require 'hpricot'
|
9
|
+
require 'xmlsimple'
|
10
|
+
require 'yajl'
|
11
|
+
require 'pathname'
|
12
|
+
require 'stringio'
|
13
|
+
|
14
|
+
plugin_test = Pathname.new(File.dirname(__FILE__))
|
15
|
+
plugin_root = plugin_test.join '..'
|
16
|
+
plugin_lib = plugin_root.join 'lib'
|
17
|
+
|
18
|
+
$:.unshift plugin_lib, plugin_test
|
19
|
+
|
20
|
+
RAILS_ENV = "test"
|
21
|
+
RAILS_ROOT = plugin_root # fake the rails root directory.
|
22
|
+
RESTFUL_ROOT = plugin_root
|
23
|
+
|
24
|
+
ActiveRecord::Base.logger = Logger.new(STDERR)
|
25
|
+
ActiveRecord::Base.logger.level = Logger::ERROR
|
26
|
+
ActiveRecord::Base.colorize_logging = false
|
27
|
+
ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :dbfile => ":memory:")
|
28
|
+
|
29
|
+
silence_stream(STDOUT) do
|
30
|
+
ActiveRecord::Schema.define do
|
31
|
+
|
32
|
+
create_table :pets do |t|
|
33
|
+
t.integer :age, :default => 10
|
34
|
+
t.string :name
|
35
|
+
t.integer :species
|
36
|
+
t.integer :person_id
|
37
|
+
|
38
|
+
t.timestamp :created_at
|
39
|
+
t.timestamp :updated_at
|
40
|
+
end
|
41
|
+
|
42
|
+
create_table :people do |t|
|
43
|
+
t.string :name
|
44
|
+
t.string :current_location
|
45
|
+
t.string :biography
|
46
|
+
|
47
|
+
t.timestamp :created_at
|
48
|
+
t.timestamp :updated_at
|
49
|
+
end
|
50
|
+
|
51
|
+
create_table :wallets do |t|
|
52
|
+
t.string :person_id
|
53
|
+
t.string :contents
|
54
|
+
|
55
|
+
t.timestamp :created_at
|
56
|
+
t.timestamp :updated_at
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
require plugin_root.join 'init'
|
62
|
+
require 'fixtures/models/pet'
|
63
|
+
require 'fixtures/models/wallet'
|
64
|
+
require 'fixtures/models/person'
|
65
|
+
|
66
|
+
Restful::Rails.api_hostname = "http://example.com:3000"
|
67
|
+
|
68
|
+
#
|
69
|
+
# Helper methods
|
70
|
+
#
|
71
|
+
def reset_config
|
72
|
+
Person.restful_config = Restful.cfg
|
73
|
+
Pet.restful_config = Restful.cfg
|
74
|
+
Wallet.restful_config = Restful.cfg
|
75
|
+
end
|
76
|
+
|
77
|
+
def xml_cmp(actual, expected)
|
78
|
+
eq_all_but_zero = Object.new.instance_eval do
|
79
|
+
def ==(other)
|
80
|
+
Integer(other) == 0 ? false : true
|
81
|
+
end
|
82
|
+
self
|
83
|
+
end
|
84
|
+
|
85
|
+
actual = XmlSimple.xml_in(actual.to_s, 'normalisespace' => eq_all_but_zero)
|
86
|
+
expected = XmlSimple.xml_in(expected.to_s, 'normalisespace' => eq_all_but_zero)
|
87
|
+
actual == expected
|
88
|
+
end
|
89
|
+
|
90
|
+
def json_cmp(actual, expected)
|
91
|
+
actual = Yajl::Parser.parse(actual)
|
92
|
+
expected = Yajl::Parser.parse(expected)
|
93
|
+
|
94
|
+
actual == expected
|
95
|
+
end
|
96
|
+
|
97
|
+
def xml_should_eql_fixture(actual, name, key)
|
98
|
+
expected = Hpricot(xml_fixture(name)[key])
|
99
|
+
actual = Hpricot(actual)
|
100
|
+
|
101
|
+
xml_should_eql(actual, expected)
|
102
|
+
end
|
103
|
+
|
104
|
+
# doing this tests that the content is the same regardless of attribute order etc.
|
105
|
+
def xml_should_eql(actual, expected)
|
106
|
+
same = xml_cmp(actual, expected)
|
107
|
+
actual.should.== expected unless same
|
108
|
+
end
|
109
|
+
|
110
|
+
def json_should_eql_fixture(actual, name, key)
|
111
|
+
expected = json_fixture(name)[key]
|
112
|
+
json_should_eql(actual, expected)
|
113
|
+
end
|
114
|
+
|
115
|
+
# doing this tests that the content is the same regardless of attribute order etc.
|
116
|
+
def json_should_eql(actual, expected)
|
117
|
+
same = json_cmp(actual, expected)
|
118
|
+
actual.should.== expected unless same
|
119
|
+
end
|
120
|
+
|
121
|
+
def file_fixture(name)
|
122
|
+
template = File.open(RESTFUL_ROOT.join("test", "fixtures", name)).read
|
123
|
+
fixture = ERB.new(template).result(binding)
|
124
|
+
yaml = YAML.load(fixture)
|
125
|
+
yaml.symbolize_keys
|
126
|
+
end
|
127
|
+
|
128
|
+
def xml_fixture(name); file_fixture("#{ name }.xml.yaml"); end
|
129
|
+
def json_fixture(name); file_fixture("#{ name }.json.yaml"); end
|
metadata
ADDED
@@ -0,0 +1,93 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: purzelrakete-restful
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Daniel Bornkessel
|
8
|
+
- Rany Keddo
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2009-08-11 00:00:00 -07:00
|
14
|
+
default_executable:
|
15
|
+
dependencies: []
|
16
|
+
|
17
|
+
description:
|
18
|
+
email: M4SSIVE@m4ssive.com
|
19
|
+
executables: []
|
20
|
+
|
21
|
+
extensions: []
|
22
|
+
|
23
|
+
extra_rdoc_files:
|
24
|
+
- README.markdown
|
25
|
+
files:
|
26
|
+
- init.rb
|
27
|
+
- lib/restful/apimodel/attribute.rb
|
28
|
+
- lib/restful/apimodel/collection.rb
|
29
|
+
- lib/restful/apimodel/link.rb
|
30
|
+
- lib/restful/apimodel/resource.rb
|
31
|
+
- lib/restful/converters/active_record.rb
|
32
|
+
- lib/restful/rails/action_controller.rb
|
33
|
+
- lib/restful/rails/active_record/configuration.rb
|
34
|
+
- lib/restful/rails/active_record/metadata_tools.rb
|
35
|
+
- lib/restful/rails.rb
|
36
|
+
- lib/restful/serializers/atom_like_serializer.rb
|
37
|
+
- lib/restful/serializers/base.rb
|
38
|
+
- lib/restful/serializers/hash_serializer.rb
|
39
|
+
- lib/restful/serializers/json_serializer.rb
|
40
|
+
- lib/restful/serializers/params_serializer.rb
|
41
|
+
- lib/restful/serializers/xml_serializer.rb
|
42
|
+
- lib/restful.rb
|
43
|
+
- LICENSE.markdown
|
44
|
+
- rails/init.rb
|
45
|
+
- Rakefile
|
46
|
+
- README.markdown
|
47
|
+
- restful.gemspec
|
48
|
+
- test/converters/active_record_converter_test.rb
|
49
|
+
- test/fixtures/models/person.rb
|
50
|
+
- test/fixtures/models/pet.rb
|
51
|
+
- test/fixtures/models/wallet.rb
|
52
|
+
- test/fixtures/people.json.yaml
|
53
|
+
- test/fixtures/people.xml.yaml
|
54
|
+
- test/fixtures/pets.xml.yaml
|
55
|
+
- test/rails/active_record_metadata_test.rb
|
56
|
+
- test/rails/configuration_test.rb
|
57
|
+
- test/rails/restful_publish_test.rb
|
58
|
+
- test/serializers/atom_serializer_test.rb
|
59
|
+
- test/serializers/json_serializer_test.rb
|
60
|
+
- test/serializers/params_serializer_test.rb
|
61
|
+
- test/serializers/xml_serializer_test.rb
|
62
|
+
- test/test_helper.rb
|
63
|
+
- TODO.markdown
|
64
|
+
has_rdoc: true
|
65
|
+
homepage: http://github.com/M4SSIVE/restful
|
66
|
+
licenses:
|
67
|
+
post_install_message:
|
68
|
+
rdoc_options:
|
69
|
+
- --line-numbers
|
70
|
+
- --inline-source
|
71
|
+
require_paths:
|
72
|
+
- lib
|
73
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - ">="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: "0"
|
78
|
+
version:
|
79
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: "0"
|
84
|
+
version:
|
85
|
+
requirements:
|
86
|
+
- brianmario-yajl-ruby
|
87
|
+
rubyforge_project:
|
88
|
+
rubygems_version: 1.3.5
|
89
|
+
signing_key:
|
90
|
+
specification_version: 2
|
91
|
+
summary: api niceness.
|
92
|
+
test_files: []
|
93
|
+
|