acts_as_api 0.4 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +2 -2
- data/History.txt +4 -0
- data/acts_as_api.gemspec +3 -3
- data/lib/acts_as_api/rendering.rb +1 -1
- data/lib/acts_as_api/version.rb +1 -1
- data/spec/controllers/respond_with_users_controller_spec.rb +37 -1
- data/spec/mongoid_dummy/Gemfile +2 -2
- data/spec/mongoid_dummy/app/models/user.rb +1 -1
- data/spec/mongoid_dummy/config/mongoid.yml +117 -17
- data/spec/shared_engine/app/controllers/shared_engine/respond_with_users_controller.rb +6 -1
- data/spec/shared_engine/app/controllers/shared_engine/users_controller.rb +1 -1
- data/spec/shared_engine/config/routes.rb +1 -0
- data/spec/shared_engine/lib/magic/rails/engine.rb +69 -0
- data/spec/spec.opts +1 -1
- data/spec/support/routing.rb +4 -0
- data/spec/support/simple_fixtures.rb +1 -1
- metadata +17 -13
data/Gemfile
CHANGED
data/History.txt
CHANGED
data/acts_as_api.gemspec
CHANGED
@@ -17,12 +17,12 @@ Gem::Specification.new do |s|
|
|
17
17
|
s.add_dependency('rack','>= 1.1.0')
|
18
18
|
|
19
19
|
s.add_development_dependency('rails', ['>= 3.2.3'])
|
20
|
-
s.add_development_dependency('mongoid', ['>=
|
20
|
+
s.add_development_dependency('mongoid', ['>= 3.0.1'])
|
21
21
|
|
22
22
|
s.rdoc_options = ['--charset=UTF-8']
|
23
|
-
|
23
|
+
|
24
24
|
s.files = `git ls-files`.split("\n")
|
25
25
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
26
26
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
27
27
|
s.require_paths = ["lib"]
|
28
|
-
end
|
28
|
+
end
|
@@ -53,7 +53,7 @@ module ActsAsApi
|
|
53
53
|
api_root_name = ActsAsApi::Config.default_root.to_s
|
54
54
|
end
|
55
55
|
|
56
|
-
api_root_name = api_root_name.underscore.tr('/', '_')
|
56
|
+
api_root_name = api_root_name.to_s.underscore.tr('/', '_')
|
57
57
|
|
58
58
|
if api_model.is_a?(Array) || (defined?(ActiveRecord) && api_model.is_a?(ActiveRecord::Relation))
|
59
59
|
api_root_name = api_root_name.pluralize
|
data/lib/acts_as_api/version.rb
CHANGED
@@ -58,6 +58,25 @@ describe SharedEngine::RespondWithUsersController do
|
|
58
58
|
end
|
59
59
|
|
60
60
|
end
|
61
|
+
|
62
|
+
context "returning all models without default root and no order" do
|
63
|
+
|
64
|
+
before(:each) do
|
65
|
+
get :index_no_root_no_order, :api_template => :name_only, :format => 'json'
|
66
|
+
end
|
67
|
+
|
68
|
+
it "should return HTTP 200 status" do
|
69
|
+
response.code.should == "200"
|
70
|
+
end
|
71
|
+
|
72
|
+
it "should contain the specified attributes" do
|
73
|
+
response_body_json["users"].each do |user|
|
74
|
+
user.should have_key( "first_name" )
|
75
|
+
user.should have_key( "last_name" )
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
61
80
|
|
62
81
|
end
|
63
82
|
|
@@ -94,11 +113,28 @@ describe SharedEngine::RespondWithUsersController do
|
|
94
113
|
response.code.should == "422"
|
95
114
|
end
|
96
115
|
|
97
|
-
it "should return errors as
|
116
|
+
it "should return errors as xml" do
|
98
117
|
response_body.should have_selector("errors > error")
|
99
118
|
end
|
100
119
|
|
101
120
|
end
|
121
|
+
|
122
|
+
context "returning all models without default root and no order" do
|
123
|
+
|
124
|
+
before(:each) do
|
125
|
+
get :index_no_root_no_order, :api_template => :name_only, :format => 'xml'
|
126
|
+
end
|
127
|
+
|
128
|
+
it "should return HTTP 200 status" do
|
129
|
+
response.code.should == "200"
|
130
|
+
end
|
131
|
+
|
132
|
+
it "should contain the specified attributes" do
|
133
|
+
response_body.should have_selector( "users > user > first-name", :count => 3 )
|
134
|
+
response_body.should have_selector( "users > user > last-name", :count => 3 )
|
135
|
+
end
|
136
|
+
|
137
|
+
end
|
102
138
|
end
|
103
139
|
|
104
140
|
end
|
data/spec/mongoid_dummy/Gemfile
CHANGED
@@ -7,7 +7,7 @@ gem 'rails', '3.2.3'
|
|
7
7
|
|
8
8
|
|
9
9
|
gem "bson_ext"
|
10
|
-
gem "mongoid", ">=
|
10
|
+
gem "mongoid", ">= 3.0.0.rc"
|
11
11
|
|
12
12
|
gem 'shared_engine', :path => '../shared_engine'
|
13
13
|
gem 'acts_as_api', :path => '../../'
|
@@ -15,4 +15,4 @@ gem 'acts_as_api', :path => '../../'
|
|
15
15
|
group :test do
|
16
16
|
gem 'rspec-rails', '>= 2.5.0'
|
17
17
|
gem 'webrat'
|
18
|
-
end
|
18
|
+
end
|
@@ -1,20 +1,120 @@
|
|
1
1
|
development:
|
2
|
-
|
3
|
-
|
2
|
+
# Configure available database sessions. (required)
|
3
|
+
sessions:
|
4
|
+
# Defines the default session. (required)
|
5
|
+
default:
|
6
|
+
# Defines the name of the default database that Mongoid can connect to.
|
7
|
+
# (required).
|
8
|
+
database: mongoid_dummy_development
|
9
|
+
# Provides the hosts the default session can connect to. Must be an array
|
10
|
+
# of host:port pairs. (required)
|
11
|
+
hosts:
|
12
|
+
- localhost:27017
|
13
|
+
options:
|
14
|
+
# Change whether the session persists in safe mode by default.
|
15
|
+
# (default: false)
|
16
|
+
# safe: false
|
4
17
|
|
18
|
+
# Change the default consistency model to :eventual or :strong.
|
19
|
+
# :eventual will send reads to secondaries, :strong sends everything
|
20
|
+
# to master. (default: :eventual)
|
21
|
+
consistency: :strong
|
22
|
+
# Configure Mongoid specific options. (optional)
|
23
|
+
options:
|
24
|
+
# Configuration for whether or not to allow access to fields that do
|
25
|
+
# not have a field definition on the model. (default: true)
|
26
|
+
# allow_dynamic_fields: true
|
27
|
+
|
28
|
+
# Enable the identity map, needed for eager loading. (default: false)
|
29
|
+
# identity_map_enabled: false
|
30
|
+
|
31
|
+
# Includes the root model name in json serialization. (default: false)
|
32
|
+
# include_root_in_json: false
|
33
|
+
|
34
|
+
# Include the _type field in serializaion. (default: false)
|
35
|
+
# include_type_for_serialization: false
|
36
|
+
|
37
|
+
# Preload all models in development, needed when models use
|
38
|
+
# inheritance. (default: false)
|
39
|
+
# preload_models: false
|
40
|
+
|
41
|
+
# Protect id and type from mass assignment. (default: true)
|
42
|
+
# protect_sensitive_fields: true
|
43
|
+
|
44
|
+
# Raise an error when performing a #find and the document is not found.
|
45
|
+
# (default: true)
|
46
|
+
# raise_not_found_error: true
|
47
|
+
|
48
|
+
# Raise an error when defining a scope with the same name as an
|
49
|
+
# existing method. (default: false)
|
50
|
+
# scope_overwrite_exception: false
|
51
|
+
|
52
|
+
# Skip the database version check, used when connecting to a db without
|
53
|
+
# admin access. (default: false)
|
54
|
+
# skip_version_check: false
|
55
|
+
|
56
|
+
# User Active Support's time zone in conversions. (default: true)
|
57
|
+
# use_activesupport_time_zone: true
|
58
|
+
|
59
|
+
# Ensure all times are UTC in the app side. (default: false)
|
60
|
+
# use_utc: false
|
5
61
|
test:
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
62
|
+
# Configure available database sessions. (required)
|
63
|
+
sessions:
|
64
|
+
# Defines the default session. (required)
|
65
|
+
default:
|
66
|
+
# Defines the name of the default database that Mongoid can connect to.
|
67
|
+
# (required).
|
68
|
+
database: mongoid_dummy_test
|
69
|
+
# Provides the hosts the default session can connect to. Must be an array
|
70
|
+
# of host:port pairs. (required)
|
71
|
+
hosts:
|
72
|
+
- localhost:27017
|
73
|
+
options:
|
74
|
+
# Change whether the session persists in safe mode by default.
|
75
|
+
# (default: false)
|
76
|
+
# safe: false
|
77
|
+
|
78
|
+
# Change the default consistency model to :eventual or :strong.
|
79
|
+
# :eventual will send reads to secondaries, :strong sends everything
|
80
|
+
# to master. (default: :eventual)
|
81
|
+
consistency: :strong
|
82
|
+
# Configure Mongoid specific options. (optional)
|
83
|
+
options:
|
84
|
+
# Configuration for whether or not to allow access to fields that do
|
85
|
+
# not have a field definition on the model. (default: true)
|
86
|
+
# allow_dynamic_fields: true
|
87
|
+
|
88
|
+
# Enable the identity map, needed for eager loading. (default: false)
|
89
|
+
# identity_map_enabled: false
|
90
|
+
|
91
|
+
# Includes the root model name in json serialization. (default: false)
|
92
|
+
# include_root_in_json: false
|
93
|
+
|
94
|
+
# Include the _type field in serializaion. (default: false)
|
95
|
+
# include_type_for_serialization: false
|
96
|
+
|
97
|
+
# Preload all models in development, needed when models use
|
98
|
+
# inheritance. (default: false)
|
99
|
+
# preload_models: false
|
100
|
+
|
101
|
+
# Protect id and type from mass assignment. (default: true)
|
102
|
+
# protect_sensitive_fields: true
|
103
|
+
|
104
|
+
# Raise an error when performing a #find and the document is not found.
|
105
|
+
# (default: true)
|
106
|
+
# raise_not_found_error: true
|
107
|
+
|
108
|
+
# Raise an error when defining a scope with the same name as an
|
109
|
+
# existing method. (default: false)
|
110
|
+
# scope_overwrite_exception: false
|
111
|
+
|
112
|
+
# Skip the database version check, used when connecting to a db without
|
113
|
+
# admin access. (default: false)
|
114
|
+
# skip_version_check: false
|
115
|
+
|
116
|
+
# User Active Support's time zone in conversions. (default: true)
|
117
|
+
# use_activesupport_time_zone: true
|
118
|
+
|
119
|
+
# Ensure all times are UTC in the app side. (default: false)
|
120
|
+
# use_utc: false
|
@@ -10,6 +10,11 @@ module SharedEngine
|
|
10
10
|
respond_with @users, :api_template => params[:api_template].to_sym, :root => :users
|
11
11
|
end
|
12
12
|
|
13
|
+
def index_no_root_no_order
|
14
|
+
@users = User.all
|
15
|
+
respond_with @users, :api_template => params[:api_template].to_sym
|
16
|
+
end
|
17
|
+
|
13
18
|
def index_meta
|
14
19
|
@users = User.all
|
15
20
|
meta_hash = { :page => 1, :total => 999 }
|
@@ -56,4 +61,4 @@ module SharedEngine
|
|
56
61
|
end
|
57
62
|
|
58
63
|
end
|
59
|
-
end
|
64
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
module Magic
|
2
|
+
module Rails
|
3
|
+
module Engine
|
4
|
+
##
|
5
|
+
# Automatically append all of the current engine's routes to the main
|
6
|
+
# application's route set. This needs to be done for ALL functional tests that
|
7
|
+
# use engine routes, since the mounted routes don't work during tests.
|
8
|
+
#
|
9
|
+
# @param [Symbol] engine_symbol Optional; if provided, uses this symbol to
|
10
|
+
# locate the engine class by name, otherwise uses the module of the calling
|
11
|
+
# test case as the presumed name of the engine.
|
12
|
+
#
|
13
|
+
# @author Jason Hamilton (jhamilton@greatherorift.com)
|
14
|
+
# @author Matthew Ratzloff (matt@urbaninfluence.com)
|
15
|
+
# @author Xavier Dutreilh (xavier@dutreilh.fr)
|
16
|
+
def load_engine_routes(engine_symbol = nil)
|
17
|
+
if engine_symbol
|
18
|
+
engine_name = engine_symbol.to_s.camelize
|
19
|
+
else
|
20
|
+
# No engine provided, so presume the current engine is the one to load
|
21
|
+
engine_name = self.class.name.split("::").first.split("(").last
|
22
|
+
end
|
23
|
+
engine = ("#{engine_name}::Engine").constantize
|
24
|
+
|
25
|
+
# Append the routes for this module to the existing routes
|
26
|
+
::Rails.application.routes.disable_clear_and_finalize = true
|
27
|
+
::Rails.application.routes.clear!
|
28
|
+
::Rails.application.routes_reloader.paths.each { |path| load(path) }
|
29
|
+
::Rails.application.routes.draw do
|
30
|
+
resourced_routes = []
|
31
|
+
|
32
|
+
named_routes = engine.routes.named_routes.routes
|
33
|
+
|
34
|
+
engine.routes.routes.each do |route|
|
35
|
+
# Call the method by hand based on the symbol
|
36
|
+
path = "/#{engine_name.underscore}#{route.path.spec}"
|
37
|
+
verb = route.verb.to_s.downcase.gsub(/^.+\^(.+)\$.+$/, '\1').to_sym
|
38
|
+
requirements = route.requirements
|
39
|
+
if path_helper = named_routes.key(route)
|
40
|
+
requirements[:as] = path_helper
|
41
|
+
elsif route.requirements[:controller].present?
|
42
|
+
# Presume that all controllers referenced in routes should also be
|
43
|
+
# resources and append that routing on the end so that *_path helpers
|
44
|
+
# will still work
|
45
|
+
resourced_routes << route.requirements[:controller].gsub("#{engine_name.underscore}/", "").to_sym
|
46
|
+
end
|
47
|
+
send(verb, path, requirements) if respond_to?(verb)
|
48
|
+
end
|
49
|
+
|
50
|
+
# Add each route, once, to the end under a scope to trick path helpers.
|
51
|
+
# This will probably break as soon as there is route name overlap, but
|
52
|
+
# we'll cross that bridge when we get to it.
|
53
|
+
resourced_routes.uniq!
|
54
|
+
scope engine_name.underscore do
|
55
|
+
resourced_routes.each do |resource|
|
56
|
+
resources resource
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
# Finalize the routes
|
62
|
+
::Rails.application.routes.finalize!
|
63
|
+
::Rails.application.routes.disable_clear_and_finalize = false
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
Rails::Engine.send(:include, Magic::Rails::Engine)
|
data/spec/spec.opts
CHANGED
@@ -1 +1 @@
|
|
1
|
-
--colour
|
1
|
+
--colour
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: acts_as_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 0.4.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-07-18 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activemodel
|
16
|
-
requirement: &
|
16
|
+
requirement: &70279657916060 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: 3.0.0
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70279657916060
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: activesupport
|
27
|
-
requirement: &
|
27
|
+
requirement: &70279657914840 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: 3.0.0
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70279657914840
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: rack
|
38
|
-
requirement: &
|
38
|
+
requirement: &70279657914060 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: 1.1.0
|
44
44
|
type: :runtime
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70279657914060
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: rails
|
49
|
-
requirement: &
|
49
|
+
requirement: &70279657913480 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,18 +54,18 @@ dependencies:
|
|
54
54
|
version: 3.2.3
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *70279657913480
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: mongoid
|
60
|
-
requirement: &
|
60
|
+
requirement: &70279657912660 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ! '>='
|
64
64
|
- !ruby/object:Gem::Version
|
65
|
-
version:
|
65
|
+
version: 3.0.1
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *70279657912660
|
69
69
|
description: acts_as_api enriches the models and controllers of your app in a rails-like
|
70
70
|
way so you can easily determine how your XML/JSON API responses should look like.
|
71
71
|
email:
|
@@ -247,6 +247,7 @@ files:
|
|
247
247
|
- spec/shared_engine/dummy/public/500.html
|
248
248
|
- spec/shared_engine/dummy/public/favicon.ico
|
249
249
|
- spec/shared_engine/dummy/script/rails
|
250
|
+
- spec/shared_engine/lib/magic/rails/engine.rb
|
250
251
|
- spec/shared_engine/lib/shared_engine.rb
|
251
252
|
- spec/shared_engine/lib/shared_engine/engine.rb
|
252
253
|
- spec/shared_engine/lib/shared_engine/version.rb
|
@@ -272,6 +273,7 @@ files:
|
|
272
273
|
- spec/support/model_examples/sub_nodes.rb
|
273
274
|
- spec/support/model_examples/undefined.rb
|
274
275
|
- spec/support/model_examples/untouched.rb
|
276
|
+
- spec/support/routing.rb
|
275
277
|
- spec/support/simple_fixtures.rb
|
276
278
|
homepage: https://github.com/fabrik42/acts_as_api
|
277
279
|
licenses: []
|
@@ -449,6 +451,7 @@ test_files:
|
|
449
451
|
- spec/shared_engine/dummy/public/500.html
|
450
452
|
- spec/shared_engine/dummy/public/favicon.ico
|
451
453
|
- spec/shared_engine/dummy/script/rails
|
454
|
+
- spec/shared_engine/lib/magic/rails/engine.rb
|
452
455
|
- spec/shared_engine/lib/shared_engine.rb
|
453
456
|
- spec/shared_engine/lib/shared_engine/engine.rb
|
454
457
|
- spec/shared_engine/lib/shared_engine/version.rb
|
@@ -474,4 +477,5 @@ test_files:
|
|
474
477
|
- spec/support/model_examples/sub_nodes.rb
|
475
478
|
- spec/support/model_examples/undefined.rb
|
476
479
|
- spec/support/model_examples/untouched.rb
|
480
|
+
- spec/support/routing.rb
|
477
481
|
- spec/support/simple_fixtures.rb
|