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: 6552b0d6e8e9db0f064f1aa53fa3b3eca373704d
4
- data.tar.gz: 41e4f1fb4dc2ae5394b28cfbdc816913990c146c
3
+ metadata.gz: c9319abecd74d853d55d236bda20394144d4344c
4
+ data.tar.gz: 6111be1dfa521795b482cac451ae1e8a4ffe6b96
5
5
  SHA512:
6
- metadata.gz: 1af0c8581b5910fc399c548d371fcc2589956ed6e475332c44a435371aef8bfa756dbba283b9510f9d31eb178a489ab831d8f614e5ff8adbd1410fa9a3f75a28
7
- data.tar.gz: 62269c9fc9200cd5b5255f0cec075c5d9a96def54174e09d8e1e2013a6179c70f67c00c62cc42077148f36ed167dbf4c891db83af274ca51b0ba08c3ba9e27c8
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
- hash = serializer.as_json(root: false)
47
- output = if hash.is_a?(Hash) && hash[single].present?
48
- hash[single].is_a?(Array) ? hash[single] : [hash[single]]
49
- else
50
- hash.is_a?(Array) ? hash : [hash]
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
@@ -1,3 +1,3 @@
1
1
  module GrapeApeRails
2
- VERSION = "0.9.2"
2
+ VERSION = "0.9.3"
3
3
  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])
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.2
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-01-15 00:00:00.000000000 Z
11
+ date: 2015-02-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport