acts_as_api 0.4.1 → 0.4.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/.travis.yml +2 -5
- data/History.txt +4 -0
- data/README.md +7 -3
- data/Rakefile +1 -2
- data/acts_as_api.gemspec +1 -1
- data/lib/acts_as_api/base.rb +1 -1
- data/lib/acts_as_api/rendering.rb +2 -1
- data/lib/acts_as_api/version.rb +2 -2
- data/spec/README.md +1 -1
- data/spec/controllers/plain_objects_controller_spec.rb +36 -0
- data/spec/mongoid_dummy/app/models/user.rb +1 -1
- data/spec/shared_engine/app/controllers/shared_engine/plain_objects_controller.rb +14 -0
- data/spec/shared_engine/app/models/plain_object.rb +17 -0
- data/spec/shared_engine/config/routes.rb +2 -0
- data/spec/shared_engine/shared_engine.gemspec +1 -1
- data/spec/support/simple_fixtures.rb +6 -0
- metadata +42 -23
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
NDkxOTQ3MWZmMjk3YWJiZGRhYjk3OGE5NWU2ZWJmMzRhYmRlNzkwMg==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
M2VlNDBlNzUyMzJmNzM2MjdjNTA5ODQzYzBlNTJiM2ZjYzliOGQ4Yw==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
MzYyNGY5MjY2NTk0ZjViNGI5NjMwZTU4YjBkNjYzZGI3ZDcwZmE3ZmU3MDhl
|
10
|
+
NDMwYTUzZmQyZmNmZjY1NzlkYzRiMjc4MjlhZTFhNWJkNjkxNzE2YTM4ZDcy
|
11
|
+
YzIyYzg5ZTYyYTY1N2FmYmVlNzZhZmMwNzBjYmI3ODMxM2ZhYTA=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
NjEwMmZiMjFmMTFlNDIzMmViMzdmMDk1OGEwM2UwMmExZDZhNWJhNmY1Mzhj
|
14
|
+
NTRlYTVlMWQwNzg3MzI3MTBiZjJiOTkzMDBmZWRmOWE1MzUzMzM2NDU2ZWNj
|
15
|
+
NGQzYzBlM2RmZTE2OTM2ODM2MDA5NjFkZjhmNDQwN2U4NTg1MDk=
|
data/.travis.yml
CHANGED
data/History.txt
CHANGED
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# acts_as_api ![acts_as_api on travis ci](
|
1
|
+
# acts_as_api ![acts_as_api on travis ci](https://secure.travis-ci.org/fabrik42/acts_as_api.png?branch=master)
|
2
2
|
|
3
3
|
acts_as_api makes creating XML/JSON responses in Rails 3 easy and fun.
|
4
4
|
|
@@ -80,12 +80,16 @@ There are a lot of how-tos like:
|
|
80
80
|
|
81
81
|
* Want to contribute - the spec suite is explained here: https://github.com/fabrik42/acts_as_api/tree/master/spec
|
82
82
|
|
83
|
-
### Travis CI build status ![acts_as_api on travis ci](
|
83
|
+
### Travis CI build status ![acts_as_api on travis ci](https://secure.travis-ci.org/fabrik42/acts_as_api.png?branch=master)
|
84
84
|
|
85
|
-
Specs run with 1.9.3
|
85
|
+
Specs run with 1.9.3: http://travis-ci.org/#!/fabrik42/acts_as_api
|
86
86
|
|
87
87
|
### Tested with:
|
88
88
|
|
89
|
+
It has been used in production with the following ruby versions.
|
90
|
+
|
91
|
+
They are not integrated in Travis, because optional dependencies (like Mongoid 3) don't support these Ruby versions.
|
92
|
+
|
89
93
|
* MRI 1.9.3-p125
|
90
94
|
* MRI 1.9.2-p290
|
91
95
|
* MRI 1.8.7-p358
|
data/Rakefile
CHANGED
data/acts_as_api.gemspec
CHANGED
@@ -16,7 +16,7 @@ Gem::Specification.new do |s|
|
|
16
16
|
s.add_dependency('activesupport','>= 3.0.0')
|
17
17
|
s.add_dependency('rack','>= 1.1.0')
|
18
18
|
|
19
|
-
s.add_development_dependency('rails', ['>= 3.2.
|
19
|
+
s.add_development_dependency('rails', ['>= 3.2.16'])
|
20
20
|
s.add_development_dependency('mongoid', ['>= 3.0.1'])
|
21
21
|
|
22
22
|
s.rdoc_options = ['--charset=UTF-8']
|
data/lib/acts_as_api/base.rb
CHANGED
@@ -34,7 +34,7 @@ module ActsAsApi
|
|
34
34
|
# be contained in the api responses.
|
35
35
|
def api_accessible(api_template, options = {}, &block)
|
36
36
|
|
37
|
-
attributes = api_accessible_attributes(api_template) || ApiTemplate.new(api_template)
|
37
|
+
attributes = api_accessible_attributes(api_template).try(:dup) || ApiTemplate.new(api_template)
|
38
38
|
|
39
39
|
attributes.merge!(api_accessible_attributes(options[:extend])) if options[:extend]
|
40
40
|
|
@@ -47,12 +47,13 @@ module ActsAsApi
|
|
47
47
|
api_root_name = api_model.collection_name
|
48
48
|
elsif api_model.is_a?(Array) && !api_model.empty? && api_model.first.class.respond_to?(:model_name)
|
49
49
|
api_root_name = api_model.first.class.model_name
|
50
|
+
elsif api_model.is_a?(Array) && !api_model.empty? && api_model.first.respond_to?(:model_name)
|
51
|
+
api_root_name = api_model.first.model_name
|
50
52
|
elsif api_model.respond_to?(:model_name)
|
51
53
|
api_root_name = api_model.model_name
|
52
54
|
else
|
53
55
|
api_root_name = ActsAsApi::Config.default_root.to_s
|
54
56
|
end
|
55
|
-
|
56
57
|
api_root_name = api_root_name.to_s.underscore.tr('/', '_')
|
57
58
|
|
58
59
|
if api_model.is_a?(Array) || (defined?(ActiveRecord) && api_model.is_a?(ActiveRecord::Relation))
|
data/lib/acts_as_api/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
1
|
module ActsAsApi
|
2
|
-
VERSION = "0.4.
|
3
|
-
end
|
2
|
+
VERSION = "0.4.2"
|
3
|
+
end
|
data/spec/README.md
CHANGED
@@ -38,7 +38,7 @@ They contain **no controllers** to be tested, just models that match the tested
|
|
38
38
|
|
39
39
|
* Create to Models used in the spec (`User, Profile, Untouched, Task`).
|
40
40
|
|
41
|
-
* Include `
|
41
|
+
* Include `UserTemplate` in your `User` model.
|
42
42
|
|
43
43
|
* Add `mount SharedEngine::Engine => "/shared", :as => "shared"` to your `routes.rb`
|
44
44
|
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe SharedEngine::PlainObjectsController do
|
4
|
+
include ApiTestHelpers
|
5
|
+
|
6
|
+
before(:each) do
|
7
|
+
class SharedEngine::PlainObjectsController
|
8
|
+
include SimpleFixtures
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
describe 'get all users as a an array of plain objects, autodetecting the root node name' do
|
13
|
+
|
14
|
+
before(:each) do
|
15
|
+
get :index, :format => 'json', :api_template => :name_only
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should have a root node named users" do
|
19
|
+
response_body_json.should have_key("plain_objects")
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should contain all users" do
|
23
|
+
response_body_json["plain_objects"].should be_a(Array)
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should contain the specified attributes" do
|
27
|
+
response_body_json["plain_objects"].first.should have_key("first_name")
|
28
|
+
response_body_json["plain_objects"].first.should have_key("last_name")
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should contain the specified values" do
|
32
|
+
response_body_json["plain_objects"].first["first_name"].should eql("Han")
|
33
|
+
response_body_json["plain_objects"].first["last_name"].should eql("Solo")
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module SharedEngine
|
2
|
+
class PlainObjectsController < SharedEngine::ApplicationController
|
3
|
+
before_filter :setup_objects
|
4
|
+
|
5
|
+
def index
|
6
|
+
@users = [@han, @luke, @leia]
|
7
|
+
|
8
|
+
respond_to do |format|
|
9
|
+
format.xml { render_for_api params[:api_template].to_sym, :xml => @users }
|
10
|
+
format.json { render_for_api params[:api_template].to_sym, :json => @users }
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
class PlainObject < Struct.new(:first_name, :last_name, :age, :active)
|
2
|
+
extend ActsAsApi::Base
|
3
|
+
|
4
|
+
def initialize(opts)
|
5
|
+
opts.each do |k, v|
|
6
|
+
send("#{k}=", v)
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
def model_name
|
11
|
+
'plain_object'
|
12
|
+
end
|
13
|
+
|
14
|
+
acts_as_api
|
15
|
+
|
16
|
+
include SharedEngine::UserTemplate
|
17
|
+
end
|
@@ -15,7 +15,7 @@ Gem::Specification.new do |s|
|
|
15
15
|
|
16
16
|
s.files = Dir["{app,config,db,lib}/**/*"] + ["MIT-LICENSE", "Rakefile", "README.rdoc"]
|
17
17
|
|
18
|
-
s.add_dependency "rails", "~> 3.2.
|
18
|
+
s.add_dependency "rails", "~> 3.2.16"
|
19
19
|
# s.add_dependency "jquery-rails"
|
20
20
|
|
21
21
|
s.add_development_dependency "sqlite3"
|
@@ -21,6 +21,12 @@ module SimpleFixtures
|
|
21
21
|
User.delete_all
|
22
22
|
end
|
23
23
|
|
24
|
+
def setup_objects
|
25
|
+
@luke = PlainObject.new({ :first_name => 'Luke', :last_name => 'Skywalker', :age => 25, :active => true })
|
26
|
+
@han = PlainObject.new({ :first_name => 'Han', :last_name => 'Solo', :age => 35, :active => true })
|
27
|
+
@leia = PlainObject.new({ :first_name => 'Princess', :last_name => 'Leia', :age => 25, :active => false })
|
28
|
+
end
|
29
|
+
|
24
30
|
# def setup_roflscale_models
|
25
31
|
# @orm_for_testing = :vanilla
|
26
32
|
# @user_model = VanillaUser
|
metadata
CHANGED
@@ -1,71 +1,85 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: acts_as_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
5
|
-
prerelease:
|
4
|
+
version: 0.4.2
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Christian Bäuerlein
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2013-12-28 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: activemodel
|
16
|
-
requirement:
|
17
|
-
none: false
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
18
16
|
requirements:
|
19
17
|
- - ! '>='
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: 3.0.0
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
|
-
version_requirements:
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ! '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 3.0.0
|
25
27
|
- !ruby/object:Gem::Dependency
|
26
28
|
name: activesupport
|
27
|
-
requirement:
|
28
|
-
none: false
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
29
30
|
requirements:
|
30
31
|
- - ! '>='
|
31
32
|
- !ruby/object:Gem::Version
|
32
33
|
version: 3.0.0
|
33
34
|
type: :runtime
|
34
35
|
prerelease: false
|
35
|
-
version_requirements:
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ! '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 3.0.0
|
36
41
|
- !ruby/object:Gem::Dependency
|
37
42
|
name: rack
|
38
|
-
requirement:
|
39
|
-
none: false
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
40
44
|
requirements:
|
41
45
|
- - ! '>='
|
42
46
|
- !ruby/object:Gem::Version
|
43
47
|
version: 1.1.0
|
44
48
|
type: :runtime
|
45
49
|
prerelease: false
|
46
|
-
version_requirements:
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 1.1.0
|
47
55
|
- !ruby/object:Gem::Dependency
|
48
56
|
name: rails
|
49
|
-
requirement:
|
50
|
-
none: false
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
51
58
|
requirements:
|
52
59
|
- - ! '>='
|
53
60
|
- !ruby/object:Gem::Version
|
54
|
-
version: 3.2.
|
61
|
+
version: 3.2.16
|
55
62
|
type: :development
|
56
63
|
prerelease: false
|
57
|
-
version_requirements:
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ! '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 3.2.16
|
58
69
|
- !ruby/object:Gem::Dependency
|
59
70
|
name: mongoid
|
60
|
-
requirement:
|
61
|
-
none: false
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
62
72
|
requirements:
|
63
73
|
- - ! '>='
|
64
74
|
- !ruby/object:Gem::Version
|
65
75
|
version: 3.0.1
|
66
76
|
type: :development
|
67
77
|
prerelease: false
|
68
|
-
version_requirements:
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ! '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 3.0.1
|
69
83
|
description: acts_as_api enriches the models and controllers of your app in a rails-like
|
70
84
|
way so you can easily determine how your XML/JSON API responses should look like.
|
71
85
|
email:
|
@@ -148,6 +162,7 @@ files:
|
|
148
162
|
- spec/active_record_dummy/vendor/assets/javascripts/.gitkeep
|
149
163
|
- spec/active_record_dummy/vendor/assets/stylesheets/.gitkeep
|
150
164
|
- spec/active_record_dummy/vendor/plugins/.gitkeep
|
165
|
+
- spec/controllers/plain_objects_controller_spec.rb
|
151
166
|
- spec/controllers/respond_with_users_controller_spec.rb
|
152
167
|
- spec/controllers/users_controller_spec.rb
|
153
168
|
- spec/models/model_spec.rb
|
@@ -209,9 +224,11 @@ files:
|
|
209
224
|
- spec/shared_engine/app/assets/javascripts/shared_engine/application.js
|
210
225
|
- spec/shared_engine/app/assets/stylesheets/shared_engine/application.css
|
211
226
|
- spec/shared_engine/app/controllers/shared_engine/application_controller.rb
|
227
|
+
- spec/shared_engine/app/controllers/shared_engine/plain_objects_controller.rb
|
212
228
|
- spec/shared_engine/app/controllers/shared_engine/respond_with_users_controller.rb
|
213
229
|
- spec/shared_engine/app/controllers/shared_engine/users_controller.rb
|
214
230
|
- spec/shared_engine/app/helpers/shared_engine/application_helper.rb
|
231
|
+
- spec/shared_engine/app/models/plain_object.rb
|
215
232
|
- spec/shared_engine/app/models/user_template.rb
|
216
233
|
- spec/shared_engine/app/views/layouts/shared_engine/application.html.erb
|
217
234
|
- spec/shared_engine/config/routes.rb
|
@@ -277,28 +294,27 @@ files:
|
|
277
294
|
- spec/support/simple_fixtures.rb
|
278
295
|
homepage: https://github.com/fabrik42/acts_as_api
|
279
296
|
licenses: []
|
297
|
+
metadata: {}
|
280
298
|
post_install_message:
|
281
299
|
rdoc_options:
|
282
300
|
- --charset=UTF-8
|
283
301
|
require_paths:
|
284
302
|
- lib
|
285
303
|
required_ruby_version: !ruby/object:Gem::Requirement
|
286
|
-
none: false
|
287
304
|
requirements:
|
288
305
|
- - ! '>='
|
289
306
|
- !ruby/object:Gem::Version
|
290
307
|
version: '0'
|
291
308
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
292
|
-
none: false
|
293
309
|
requirements:
|
294
310
|
- - ! '>='
|
295
311
|
- !ruby/object:Gem::Version
|
296
312
|
version: '0'
|
297
313
|
requirements: []
|
298
314
|
rubyforge_project:
|
299
|
-
rubygems_version: 1.
|
315
|
+
rubygems_version: 2.1.11
|
300
316
|
signing_key:
|
301
|
-
specification_version:
|
317
|
+
specification_version: 4
|
302
318
|
summary: Makes creating XML/JSON responses in Rails 3 easy and fun.
|
303
319
|
test_files:
|
304
320
|
- spec/README.md
|
@@ -352,6 +368,7 @@ test_files:
|
|
352
368
|
- spec/active_record_dummy/vendor/assets/javascripts/.gitkeep
|
353
369
|
- spec/active_record_dummy/vendor/assets/stylesheets/.gitkeep
|
354
370
|
- spec/active_record_dummy/vendor/plugins/.gitkeep
|
371
|
+
- spec/controllers/plain_objects_controller_spec.rb
|
355
372
|
- spec/controllers/respond_with_users_controller_spec.rb
|
356
373
|
- spec/controllers/users_controller_spec.rb
|
357
374
|
- spec/models/model_spec.rb
|
@@ -413,9 +430,11 @@ test_files:
|
|
413
430
|
- spec/shared_engine/app/assets/javascripts/shared_engine/application.js
|
414
431
|
- spec/shared_engine/app/assets/stylesheets/shared_engine/application.css
|
415
432
|
- spec/shared_engine/app/controllers/shared_engine/application_controller.rb
|
433
|
+
- spec/shared_engine/app/controllers/shared_engine/plain_objects_controller.rb
|
416
434
|
- spec/shared_engine/app/controllers/shared_engine/respond_with_users_controller.rb
|
417
435
|
- spec/shared_engine/app/controllers/shared_engine/users_controller.rb
|
418
436
|
- spec/shared_engine/app/helpers/shared_engine/application_helper.rb
|
437
|
+
- spec/shared_engine/app/models/plain_object.rb
|
419
438
|
- spec/shared_engine/app/models/user_template.rb
|
420
439
|
- spec/shared_engine/app/views/layouts/shared_engine/application.html.erb
|
421
440
|
- spec/shared_engine/config/routes.rb
|