grape_ape_rails 0.9.2 → 0.9.3
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c9319abecd74d853d55d236bda20394144d4344c
|
4
|
+
data.tar.gz: 6111be1dfa521795b482cac451ae1e8a4ffe6b96
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 947b19eb36e0944719cf6b5e7c9e0a506f3ab38edb234153ffe2d4fa985c66a22d4c76ea97f6d5e0c76e2b5f24c795f895a5ea6c74f5b3bc5b8f6ae5f1dab2ba
|
7
|
+
data.tar.gz: a430845cf35a6f7568a6e49abc251047338029d77f20e93d070564adc4e052882235613da5d3ff62db39069609c181d51ab76192e3bc5636945effb7e04a5141
|
@@ -34,23 +34,13 @@ module Grape
|
|
34
34
|
module GarActiveModelSerializers
|
35
35
|
def self.call(resource, env)
|
36
36
|
if serializer = Grape::Formatter::ActiveModelSerializers.fetch_serializer(resource, env)
|
37
|
-
# single = serializer.try(:resource_singular) || serializer.object.class.name.underscore
|
38
|
-
# default_plural = default_plural = serializer.object.class.name.underscore.pluralize
|
39
|
-
# if serializer.object.is_a?(Array)
|
40
|
-
# single = serializer.object.first.class.name.underscore
|
41
|
-
# default_plural = serializer.object.first.class.name.underscore.pluralize
|
42
|
-
# end
|
43
|
-
# plural = serializer.try(:resource_plural) || default_plural
|
44
37
|
single = serializer.try(:resource_singular) || serializer.instance_variable_get(:@resource_name).try(:singularize) || serializer.instance_variable_get(:@object).class.name.underscore
|
45
38
|
plural = serializer.try(:resource_plural) || serializer.instance_variable_get(:@resource_name) || single.pluralize
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
end
|
52
|
-
template = MultiJson.dump({ result: { plural => "***" } })
|
53
|
-
template.gsub(%Q("***"), MultiJson.dump(output))
|
39
|
+
|
40
|
+
return %Q[{\"result\":#{MultiJson.dump(serializer)}}] if [serializer.object].flatten.size > 1
|
41
|
+
|
42
|
+
serializer.root = false
|
43
|
+
%Q[{\"result\":{\"#{plural}\":[#{MultiJson.dump(serializer)}]}}]
|
54
44
|
else
|
55
45
|
Grape::Formatter::GarJsonSerializer.call serializer.object, env
|
56
46
|
end
|
@@ -6,6 +6,12 @@ module API
|
|
6
6
|
formatter :json, Grape::Formatter::GarActiveModelSerializers
|
7
7
|
|
8
8
|
resource :monkeys do
|
9
|
+
desc "Get many monkeys"
|
10
|
+
get '/' do
|
11
|
+
@monkeys = Monkey.all
|
12
|
+
@monkeys
|
13
|
+
end
|
14
|
+
|
9
15
|
desc "Get a single Monkey"
|
10
16
|
get ':id' do
|
11
17
|
@monkey = Monkey.find(params[:id])
|
data/spec/dummy/db/test.sqlite3
CHANGED
Binary file
|
@@ -12,11 +12,19 @@ describe API::V1::Monkeys do
|
|
12
12
|
expect(response.status).to eql 401
|
13
13
|
end
|
14
14
|
|
15
|
-
it "returns a monkey by id, using the ActiveModelSerializers" do
|
15
|
+
it "returns a single monkey by id, using the ActiveModelSerializers" do
|
16
16
|
req :get, "/monkeys/#{monkey.id}"
|
17
17
|
expect(response.status).to eql 200
|
18
18
|
expect(json_result[:monkeys].size).to eql 1
|
19
19
|
expect(json_result[:monkeys].first[:name]).to eql "Frank the Monkey"
|
20
20
|
end
|
21
21
|
end
|
22
|
+
describe "GET /monkeys" do
|
23
|
+
it "returns multiple monkeys, using the ActiveModelSerializers" do
|
24
|
+
3.times { FactoryGirl.create :monkey }
|
25
|
+
req :get, "/monkeys"
|
26
|
+
expect(response.status).to eql 200
|
27
|
+
expect(json_result[:monkeys].size).to eql 3
|
28
|
+
end
|
29
|
+
end
|
22
30
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: grape_ape_rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matt E. Patterson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-02-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|