purzelrakete-restful 0.2.13 → 0.2.14
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/CHANGES.markdown +10 -2
- data/lib/restful/rails/active_record/configuration.rb +11 -3
- data/lib/restful/serializers/hash_serializer.rb +0 -1
- data/restful.gemspec +1 -1
- data/test/converters/basic_types_converter_test.rb +30 -9
- data/test/fixtures/models/paginated_collection.rb +2 -3
- data/test/test_helper.rb +2 -0
- metadata +1 -1
data/CHANGES.markdown
CHANGED
@@ -11,6 +11,14 @@
|
|
11
11
|
|
12
12
|
* added ability to publish :wallet-restful-url (explicitly collapsed)
|
13
13
|
|
14
|
-
20. Aug 2009
|
14
|
+
20. Aug 2009
|
15
|
+
|
16
|
+
- 0.2.13
|
15
17
|
|
16
|
-
* hash serializer no longer dereferences ids
|
18
|
+
* hash serializer no longer dereferences ids
|
19
|
+
|
20
|
+
- 0.2.14
|
21
|
+
|
22
|
+
* arrays names now use base_class of content models
|
23
|
+
* restful_path defaults to using base_class in path
|
24
|
+
* if array responds to name, use this as collection name
|
@@ -61,13 +61,21 @@ module Restful
|
|
61
61
|
|
62
62
|
# array
|
63
63
|
if self.is_a?(Array)
|
64
|
+
element_name = if fst = self.first
|
65
|
+
fst.class.respond_to?(:base_class) ?
|
66
|
+
fst.class.base_class.to_s.tableize :
|
67
|
+
fst.class.to_s.pluralize
|
68
|
+
elsif self.respond_to?(:name)
|
69
|
+
self.name
|
70
|
+
else
|
71
|
+
"nil-classes"
|
72
|
+
end
|
73
|
+
|
64
74
|
elements = self.map do |el|
|
65
75
|
raise TypeError.new("Not all array elements respond to #to_restful. ") unless el.respond_to?(:to_restful)
|
66
76
|
Restful::Converters::ActiveRecord.convert(el, !config_parameter.nil? ? Config.new(config_parameter) : el.class.restful_config)
|
67
77
|
end
|
68
78
|
|
69
|
-
element_name = elements.first ? elements.first.name.pluralize : "nil-classes"
|
70
|
-
|
71
79
|
returning Restful.collection(element_name, elements, :array) do |collection|
|
72
80
|
collection.total_entries = self.total_entries if self.respond_to?(:total_entries)
|
73
81
|
end
|
@@ -106,7 +114,7 @@ module Restful
|
|
106
114
|
end
|
107
115
|
|
108
116
|
def restful_path
|
109
|
-
"/#{ self.class.to_s.tableize }/#{ self.to_param }"
|
117
|
+
"/#{ self.class.base_class.to_s.tableize }/#{ self.to_param }"
|
110
118
|
end
|
111
119
|
end
|
112
120
|
|
data/restful.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = "restful"
|
3
|
-
s.version = "0.2.
|
3
|
+
s.version = "0.2.14"
|
4
4
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
5
5
|
s.authors = ["Daniel Bornkessel", "Rany Keddo"]
|
6
6
|
s.date = "2009-08-11"
|
@@ -1,8 +1,21 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/../test_helper.rb'
|
2
2
|
|
3
3
|
context "basic types converter" do
|
4
|
+
|
4
5
|
teardown { reset_config }
|
5
6
|
|
7
|
+
specify "should be able to convert a hash to a resource map" do
|
8
|
+
Person.restful_publish(:name)
|
9
|
+
resource = { "zeperson" => @person = Person.create(:name => "fuddzle") }.to_restful
|
10
|
+
resource.should.is_a?(Restful::ApiModel::Map)
|
11
|
+
|
12
|
+
attrs = resource.simple_attributes
|
13
|
+
attrs.size.should.== 1
|
14
|
+
attrs.first.name.should.== "zeperson"
|
15
|
+
|
16
|
+
attrs.first.value.values.first.value.== "fuddzle"
|
17
|
+
end
|
18
|
+
|
6
19
|
specify "should raise exception if not all array contents respond to .to_restful" do
|
7
20
|
Person.restful_publish(:name)
|
8
21
|
|
@@ -15,6 +28,16 @@ context "basic types converter" do
|
|
15
28
|
collection = [].to_restful
|
16
29
|
collection.name.should.== "nil-classes"
|
17
30
|
end
|
31
|
+
|
32
|
+
specify "should infer array name from first element class" do
|
33
|
+
collection = [Pet.new].to_restful
|
34
|
+
collection.name.should.== "pets"
|
35
|
+
end
|
36
|
+
|
37
|
+
specify "should infer array name from first element base_class if it is an active_record object" do
|
38
|
+
collection = [Emu.new, Pet.new].to_restful
|
39
|
+
collection.name.should.== "pets"
|
40
|
+
end
|
18
41
|
|
19
42
|
specify "should convert an array to a restful collection" do
|
20
43
|
Person.restful_publish(:name)
|
@@ -34,15 +57,13 @@ context "basic types converter" do
|
|
34
57
|
collection.total_entries.should.== 1001
|
35
58
|
end
|
36
59
|
|
37
|
-
specify "should
|
60
|
+
specify "should set name on collection if array responds to .name and has this set" do
|
38
61
|
Person.restful_publish(:name)
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
attrs.first.value.values.first.value.== "fuddzle"
|
62
|
+
people = PaginatedCollection.new()
|
63
|
+
people.total_entries = 0
|
64
|
+
people.name = "people"
|
65
|
+
|
66
|
+
collection = people.to_restful
|
67
|
+
collection.name.should.== "people"
|
47
68
|
end
|
48
69
|
end
|
data/test/test_helper.rb
CHANGED
@@ -34,6 +34,7 @@ silence_stream(STDOUT) do
|
|
34
34
|
t.string :name
|
35
35
|
t.integer :species
|
36
36
|
t.integer :person_id
|
37
|
+
t.string :type
|
37
38
|
|
38
39
|
t.timestamp :created_at
|
39
40
|
t.timestamp :updated_at
|
@@ -62,6 +63,7 @@ end
|
|
62
63
|
|
63
64
|
require plugin_root.join 'init'
|
64
65
|
require 'fixtures/models/pet'
|
66
|
+
require 'fixtures/models/emu'
|
65
67
|
require 'fixtures/models/wallet'
|
66
68
|
require 'fixtures/models/person'
|
67
69
|
require 'fixtures/models/paginated_collection'
|