acts_as_api 0.4.4 → 1.0.0
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.
- checksums.yaml +4 -4
- data/Gemfile +4 -7
- data/History.txt +5 -0
- data/LICENSE.txt +20 -0
- data/README.md +0 -25
- data/Rakefile +5 -12
- data/acts_as_api.gemspec +14 -13
- data/{examples/introduction → docs}/docco.css +0 -0
- data/{examples/introduction → docs}/index.html +18 -21
- data/{examples/introduction → docs}/index.rb +0 -0
- data/{examples/introduction → docs}/layout.mustache +0 -0
- data/lib/acts_as_api.rb +9 -12
- data/lib/acts_as_api/adapters.rb +1 -1
- data/lib/acts_as_api/api_template.rb +23 -25
- data/lib/acts_as_api/base.rb +11 -20
- data/lib/acts_as_api/collection.rb +1 -2
- data/lib/acts_as_api/config.rb +0 -5
- data/lib/acts_as_api/exceptions.rb +2 -2
- data/lib/acts_as_api/rails_renderer.rb +0 -2
- data/lib/acts_as_api/rendering.rb +5 -12
- data/lib/acts_as_api/responder.rb +8 -13
- data/lib/acts_as_api/version.rb +1 -1
- data/spec/README.md +15 -6
- data/spec/active_record_dummy/Gemfile +2 -10
- data/spec/active_record_dummy/app/models/user.rb +31 -32
- data/spec/active_record_dummy/config.ru +1 -1
- data/spec/active_record_dummy/config/application.rb +2 -2
- data/spec/active_record_dummy/config/boot.rb +1 -1
- data/spec/active_record_dummy/config/environments/test.rb +2 -2
- data/spec/active_record_dummy/config/initializers/session_store.rb +1 -1
- data/spec/active_record_dummy/config/initializers/wrap_parameters.rb +1 -1
- data/spec/active_record_dummy/config/routes.rb +1 -57
- data/spec/active_record_dummy/db/migrate/20110214201640_create_tables.rb +25 -26
- data/spec/active_record_dummy/db/schema.rb +27 -29
- data/spec/active_record_dummy/script/rails +2 -2
- data/spec/controllers/plain_objects_controller_spec.rb +11 -12
- data/spec/controllers/respond_with_users_controller_spec.rb +46 -67
- data/spec/controllers/users_controller_spec.rb +2 -3
- data/spec/models/model_spec.rb +17 -19
- data/spec/mongoid_dummy/Gemfile +3 -12
- data/spec/mongoid_dummy/app/models/profile.rb +6 -6
- data/spec/mongoid_dummy/app/models/task.rb +10 -10
- data/spec/mongoid_dummy/app/models/untouched.rb +4 -4
- data/spec/mongoid_dummy/app/models/user.rb +12 -14
- data/spec/mongoid_dummy/config.ru +1 -1
- data/spec/mongoid_dummy/config/application.rb +7 -7
- data/spec/mongoid_dummy/config/boot.rb +1 -1
- data/spec/mongoid_dummy/config/environments/development.rb +0 -1
- data/spec/mongoid_dummy/config/environments/production.rb +0 -1
- data/spec/mongoid_dummy/config/environments/test.rb +2 -2
- data/spec/mongoid_dummy/config/initializers/include_acts_as_api.rb +1 -1
- data/spec/mongoid_dummy/config/initializers/session_store.rb +1 -1
- data/spec/mongoid_dummy/config/initializers/wrap_parameters.rb +1 -2
- data/spec/mongoid_dummy/config/routes.rb +1 -57
- data/spec/mongoid_dummy/script/rails +2 -2
- data/spec/shared_engine/Gemfile +1 -1
- data/spec/shared_engine/Rakefile +1 -4
- data/spec/shared_engine/app/controllers/shared_engine/plain_objects_controller.rb +2 -2
- data/spec/shared_engine/app/controllers/shared_engine/respond_with_users_controller.rb +13 -15
- data/spec/shared_engine/app/controllers/shared_engine/users_controller.rb +17 -19
- data/spec/shared_engine/app/models/plain_object.rb +3 -1
- data/spec/shared_engine/app/models/user_template.rb +28 -29
- data/spec/shared_engine/lib/shared_engine.rb +1 -1
- data/spec/shared_engine/lib/shared_engine/version.rb +1 -1
- data/spec/shared_engine/shared_engine.gemspec +10 -12
- data/spec/spec_helper.rb +5 -13
- data/spec/support/api_test_helpers.rb +0 -2
- data/spec/support/controller_examples.rb +128 -173
- data/spec/support/it_supports.rb +1 -1
- data/spec/support/model_examples/associations.rb +119 -128
- data/spec/support/model_examples/callbacks.rb +17 -27
- data/spec/support/model_examples/closures.rb +21 -29
- data/spec/support/model_examples/conditional_if.rb +71 -103
- data/spec/support/model_examples/conditional_unless.rb +71 -103
- data/spec/support/model_examples/enabled.rb +5 -6
- data/spec/support/model_examples/extending.rb +49 -56
- data/spec/support/model_examples/methods.rb +11 -15
- data/spec/support/model_examples/options.rb +19 -25
- data/spec/support/model_examples/renaming.rb +21 -30
- data/spec/support/model_examples/simple.rb +10 -14
- data/spec/support/model_examples/sub_nodes.rb +47 -59
- data/spec/support/model_examples/undefined.rb +4 -6
- data/spec/support/model_examples/untouched.rb +6 -8
- data/spec/support/simple_fixtures.rb +11 -38
- metadata +22 -159
- data/spec/active_record_dummy/app/assets/images/rails.png +0 -0
- data/spec/active_record_dummy/app/assets/javascripts/application.js +0 -15
- data/spec/active_record_dummy/app/assets/stylesheets/application.css +0 -13
- data/spec/active_record_dummy/app/controllers/application_controller.rb +0 -3
- data/spec/active_record_dummy/app/helpers/application_helper.rb +0 -2
- data/spec/active_record_dummy/app/mailers/.gitkeep +0 -0
- data/spec/active_record_dummy/app/views/layouts/application.html.erb +0 -14
- data/spec/active_record_dummy/doc/README_FOR_APP +0 -2
- data/spec/active_record_dummy/lib/assets/.gitkeep +0 -0
- data/spec/active_record_dummy/lib/tasks/.gitkeep +0 -0
- data/spec/active_record_dummy/public/404.html +0 -26
- data/spec/active_record_dummy/public/422.html +0 -26
- data/spec/active_record_dummy/public/500.html +0 -25
- data/spec/active_record_dummy/public/favicon.ico +0 -0
- data/spec/active_record_dummy/public/index.html +0 -241
- data/spec/active_record_dummy/public/robots.txt +0 -5
- data/spec/active_record_dummy/vendor/assets/javascripts/.gitkeep +0 -0
- data/spec/active_record_dummy/vendor/assets/stylesheets/.gitkeep +0 -0
- data/spec/active_record_dummy/vendor/plugins/.gitkeep +0 -0
- data/spec/mongoid_dummy/README.rdoc +0 -261
- data/spec/mongoid_dummy/app/assets/images/rails.png +0 -0
- data/spec/mongoid_dummy/app/assets/javascripts/application.js +0 -15
- data/spec/mongoid_dummy/app/assets/stylesheets/application.css +0 -13
- data/spec/mongoid_dummy/app/controllers/application_controller.rb +0 -3
- data/spec/mongoid_dummy/app/helpers/application_helper.rb +0 -2
- data/spec/mongoid_dummy/app/mailers/.gitkeep +0 -0
- data/spec/mongoid_dummy/app/views/layouts/application.html.erb +0 -14
- data/spec/mongoid_dummy/doc/README_FOR_APP +0 -2
- data/spec/mongoid_dummy/lib/assets/.gitkeep +0 -0
- data/spec/mongoid_dummy/lib/tasks/.gitkeep +0 -0
- data/spec/mongoid_dummy/public/404.html +0 -26
- data/spec/mongoid_dummy/public/422.html +0 -26
- data/spec/mongoid_dummy/public/500.html +0 -25
- data/spec/mongoid_dummy/public/favicon.ico +0 -0
- data/spec/mongoid_dummy/public/index.html +0 -241
- data/spec/mongoid_dummy/public/robots.txt +0 -5
- data/spec/mongoid_dummy/vendor/assets/javascripts/.gitkeep +0 -0
- data/spec/mongoid_dummy/vendor/assets/stylesheets/.gitkeep +0 -0
- data/spec/mongoid_dummy/vendor/plugins/.gitkeep +0 -0
- data/spec/shared_engine/app/assets/images/shared_engine/.gitkeep +0 -0
- data/spec/shared_engine/app/assets/javascripts/shared_engine/application.js +0 -15
- data/spec/shared_engine/app/assets/stylesheets/shared_engine/application.css +0 -13
- data/spec/shared_engine/app/helpers/shared_engine/application_helper.rb +0 -4
- data/spec/shared_engine/app/views/layouts/shared_engine/application.html.erb +0 -14
- data/spec/shared_engine/dummy/README.rdoc +0 -261
- data/spec/shared_engine/dummy/Rakefile +0 -7
- data/spec/shared_engine/dummy/app/assets/javascripts/application.js +0 -15
- data/spec/shared_engine/dummy/app/assets/stylesheets/application.css +0 -13
- data/spec/shared_engine/dummy/app/controllers/application_controller.rb +0 -3
- data/spec/shared_engine/dummy/app/helpers/application_helper.rb +0 -2
- data/spec/shared_engine/dummy/app/mailers/.gitkeep +0 -0
- data/spec/shared_engine/dummy/app/models/.gitkeep +0 -0
- data/spec/shared_engine/dummy/app/views/layouts/application.html.erb +0 -14
- data/spec/shared_engine/dummy/config.ru +0 -4
- data/spec/shared_engine/dummy/config/application.rb +0 -56
- data/spec/shared_engine/dummy/config/boot.rb +0 -10
- data/spec/shared_engine/dummy/config/database.yml +0 -25
- data/spec/shared_engine/dummy/config/environment.rb +0 -5
- data/spec/shared_engine/dummy/config/environments/development.rb +0 -34
- data/spec/shared_engine/dummy/config/environments/production.rb +0 -63
- data/spec/shared_engine/dummy/config/environments/test.rb +0 -37
- data/spec/shared_engine/dummy/config/initializers/backtrace_silencers.rb +0 -7
- data/spec/shared_engine/dummy/config/initializers/inflections.rb +0 -15
- data/spec/shared_engine/dummy/config/initializers/mime_types.rb +0 -5
- data/spec/shared_engine/dummy/config/initializers/secret_token.rb +0 -7
- data/spec/shared_engine/dummy/config/initializers/session_store.rb +0 -8
- data/spec/shared_engine/dummy/config/initializers/wrap_parameters.rb +0 -14
- data/spec/shared_engine/dummy/config/locales/en.yml +0 -5
- data/spec/shared_engine/dummy/config/routes.rb +0 -4
- data/spec/shared_engine/dummy/lib/assets/.gitkeep +0 -0
- data/spec/shared_engine/dummy/log/.gitkeep +0 -0
- data/spec/shared_engine/dummy/public/404.html +0 -26
- data/spec/shared_engine/dummy/public/422.html +0 -26
- data/spec/shared_engine/dummy/public/500.html +0 -25
- data/spec/shared_engine/dummy/public/favicon.ico +0 -0
- data/spec/shared_engine/dummy/script/rails +0 -6
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
require 'spec_helper'
|
|
2
2
|
|
|
3
3
|
describe SharedEngine::UsersController, type: :controller do
|
|
4
|
-
|
|
5
4
|
before(:each) do
|
|
6
5
|
setup_models
|
|
7
6
|
end
|
|
8
7
|
|
|
9
8
|
after(:each) do
|
|
10
|
-
|
|
9
|
+
clean_up_models
|
|
11
10
|
end
|
|
12
11
|
|
|
13
12
|
# see spec/support/controller_examples.rb
|
|
14
|
-
it_behaves_like
|
|
13
|
+
it_behaves_like 'a controller with ActsAsApi responses'
|
|
15
14
|
end
|
data/spec/models/model_spec.rb
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
require 'spec_helper'
|
|
2
2
|
|
|
3
|
-
describe
|
|
4
|
-
|
|
3
|
+
describe 'Models', type: :model do
|
|
5
4
|
before(:each) do
|
|
6
5
|
setup_models
|
|
7
6
|
end
|
|
@@ -9,23 +8,22 @@ describe "Models" do
|
|
|
9
8
|
after(:each) do
|
|
10
9
|
clean_up_models
|
|
11
10
|
end
|
|
12
|
-
|
|
11
|
+
|
|
13
12
|
describe :act_as_api do
|
|
14
|
-
it_supports
|
|
15
|
-
it_supports
|
|
16
|
-
it_supports
|
|
17
|
-
it_supports
|
|
18
|
-
it_supports
|
|
19
|
-
it_supports
|
|
20
|
-
it_supports
|
|
21
|
-
it_supports
|
|
22
|
-
it_supports
|
|
23
|
-
it_supports
|
|
24
|
-
it_supports
|
|
13
|
+
it_supports 'including an association in the api template'
|
|
14
|
+
it_supports 'calling a closure in the api template'
|
|
15
|
+
it_supports 'conditional if statements'
|
|
16
|
+
it_supports 'conditional unless statements'
|
|
17
|
+
it_supports 'acts_as_api is enabled'
|
|
18
|
+
it_supports 'extending a given api template'
|
|
19
|
+
it_supports 'calling a method in the api template'
|
|
20
|
+
it_supports 'renaming'
|
|
21
|
+
it_supports 'listing attributes in the api template'
|
|
22
|
+
it_supports 'creating a sub hash in the api template'
|
|
23
|
+
it_supports 'trying to render an api template that is not defined'
|
|
25
24
|
# deactivated for vanilla ruby as acts_as_api won't get mixed into any class
|
|
26
|
-
it_supports
|
|
27
|
-
it_supports
|
|
28
|
-
it_supports
|
|
25
|
+
it_supports 'untouched models'
|
|
26
|
+
it_supports 'defining a model callback'
|
|
27
|
+
it_supports 'options'
|
|
29
28
|
end
|
|
30
|
-
|
|
31
|
-
end
|
|
29
|
+
end
|
data/spec/mongoid_dummy/Gemfile
CHANGED
|
@@ -2,17 +2,8 @@ source 'https://rubygems.org'
|
|
|
2
2
|
|
|
3
3
|
gem 'rails', '5.0.0.1'
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
# gem 'rails', :git => 'git://github.com/rails/rails.git'
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
gem "bson_ext"
|
|
5
|
+
gem 'bson_ext'
|
|
10
6
|
gem 'mongoid', '>= 6.0.2'
|
|
11
7
|
|
|
12
|
-
gem 'shared_engine', :
|
|
13
|
-
gem 'acts_as_api', :
|
|
14
|
-
|
|
15
|
-
group :test do
|
|
16
|
-
gem 'rspec-rails', '>= 2.5.0'
|
|
17
|
-
gem 'webrat'
|
|
18
|
-
end
|
|
8
|
+
gem 'shared_engine', path: '../shared_engine'
|
|
9
|
+
gem 'acts_as_api', path: '../../'
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
class Profile
|
|
2
2
|
include Mongoid::Document
|
|
3
3
|
|
|
4
|
-
field :avatar, :
|
|
5
|
-
field :homepage, :
|
|
6
|
-
field :created_at, :
|
|
7
|
-
field :updated_at, :
|
|
4
|
+
field :avatar, type: String
|
|
5
|
+
field :homepage, type: String
|
|
6
|
+
field :created_at, type: DateTime
|
|
7
|
+
field :updated_at, type: DateTime
|
|
8
8
|
|
|
9
|
-
embedded_in :user, :
|
|
10
|
-
end
|
|
9
|
+
embedded_in :user, class_name: 'User', inverse_of: :profile
|
|
10
|
+
end
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
class Task
|
|
2
2
|
include Mongoid::Document
|
|
3
|
-
|
|
4
|
-
field :heading, :
|
|
5
|
-
field :description, :
|
|
6
|
-
field :time_spent, :
|
|
7
|
-
field :done, :
|
|
8
|
-
field :created_at, :
|
|
9
|
-
field :updated_at, :
|
|
10
|
-
|
|
11
|
-
embedded_in :user, :
|
|
12
|
-
end
|
|
3
|
+
|
|
4
|
+
field :heading, type: String
|
|
5
|
+
field :description, type: String
|
|
6
|
+
field :time_spent, type: Integer
|
|
7
|
+
field :done, type: Boolean
|
|
8
|
+
field :created_at, type: DateTime
|
|
9
|
+
field :updated_at, type: DateTime
|
|
10
|
+
|
|
11
|
+
embedded_in :user, class_name: 'User', inverse_of: :task
|
|
12
|
+
end
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
class Untouched
|
|
2
2
|
include Mongoid::Document
|
|
3
|
-
|
|
4
|
-
field :nothing, :
|
|
5
|
-
field :created_at, :
|
|
6
|
-
field :updated_at, :
|
|
3
|
+
|
|
4
|
+
field :nothing, type: String
|
|
5
|
+
field :created_at, type: DateTime
|
|
6
|
+
field :updated_at, type: DateTime
|
|
7
7
|
end
|
|
@@ -1,18 +1,17 @@
|
|
|
1
1
|
class User
|
|
2
|
-
|
|
3
2
|
include Mongoid::Document
|
|
4
3
|
|
|
5
|
-
field :first_name, :
|
|
6
|
-
field :last_name, :
|
|
7
|
-
field :age, :
|
|
8
|
-
field :active, :
|
|
9
|
-
field :created_at, :
|
|
10
|
-
field :updated_at, :
|
|
4
|
+
field :first_name, type: String
|
|
5
|
+
field :last_name, type: String
|
|
6
|
+
field :age, type: Integer
|
|
7
|
+
field :active, type: Boolean
|
|
8
|
+
field :created_at, type: DateTime
|
|
9
|
+
field :updated_at, type: DateTime
|
|
11
10
|
|
|
12
|
-
embeds_one :profile, :
|
|
13
|
-
embeds_many :tasks, :
|
|
11
|
+
embeds_one :profile, class_name: 'Profile', inverse_of: :user
|
|
12
|
+
embeds_many :tasks, class_name: 'Task', inverse_of: :user
|
|
14
13
|
|
|
15
|
-
validates :first_name, :last_name, :
|
|
14
|
+
validates :first_name, :last_name, presence: true
|
|
16
15
|
|
|
17
16
|
acts_as_api
|
|
18
17
|
|
|
@@ -35,14 +34,13 @@ class User
|
|
|
35
34
|
end
|
|
36
35
|
|
|
37
36
|
def say_something
|
|
38
|
-
|
|
37
|
+
'something'
|
|
39
38
|
end
|
|
40
39
|
|
|
41
40
|
def sub_hash
|
|
42
41
|
{
|
|
43
|
-
:
|
|
44
|
-
:
|
|
42
|
+
foo: 'bar',
|
|
43
|
+
hello: 'world'
|
|
45
44
|
}
|
|
46
45
|
end
|
|
47
|
-
|
|
48
46
|
end
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
require File.expand_path('../boot', __FILE__)
|
|
2
2
|
|
|
3
3
|
# Pick the frameworks you want:
|
|
4
|
-
# require
|
|
5
|
-
require
|
|
6
|
-
require
|
|
7
|
-
require
|
|
8
|
-
require
|
|
4
|
+
# require 'active_record/railtie'
|
|
5
|
+
require 'action_controller/railtie'
|
|
6
|
+
require 'action_mailer/railtie'
|
|
7
|
+
require 'sprockets/railtie'
|
|
8
|
+
require 'rails/test_unit/railtie'
|
|
9
9
|
|
|
10
10
|
if defined?(Bundler)
|
|
11
11
|
# If you precompile assets before deploying to production, use this line
|
|
12
|
-
Bundler.require(*Rails.groups(:
|
|
12
|
+
Bundler.require(*Rails.groups(assets: %w(development test)))
|
|
13
13
|
# If you want your assets lazily compiled in production, use this line
|
|
14
14
|
# Bundler.require(:default, :assets, Rails.env)
|
|
15
15
|
end
|
|
@@ -39,7 +39,7 @@ module MongoidDummy
|
|
|
39
39
|
# config.i18n.default_locale = :de
|
|
40
40
|
|
|
41
41
|
# Configure the default encoding used in templates for Ruby 1.9.
|
|
42
|
-
config.encoding =
|
|
42
|
+
config.encoding = 'utf-8'
|
|
43
43
|
|
|
44
44
|
# Configure sensitive parameters which will be filtered from the log file.
|
|
45
45
|
config.filter_parameters += [:password]
|
|
@@ -14,14 +14,14 @@ MongoidDummy::Application.configure do
|
|
|
14
14
|
config.whiny_nils = true
|
|
15
15
|
|
|
16
16
|
# Show full error reports and disable caching
|
|
17
|
-
config.consider_all_requests_local
|
|
17
|
+
config.consider_all_requests_local = true
|
|
18
18
|
config.action_controller.perform_caching = false
|
|
19
19
|
|
|
20
20
|
# Raise exceptions instead of rendering exception templates
|
|
21
21
|
config.action_dispatch.show_exceptions = false
|
|
22
22
|
|
|
23
23
|
# Disable request forgery protection in test environment
|
|
24
|
-
config.action_controller.allow_forgery_protection
|
|
24
|
+
config.action_controller.allow_forgery_protection = false
|
|
25
25
|
|
|
26
26
|
# Tell Action Mailer not to deliver emails to the real world.
|
|
27
27
|
# The :test delivery method accumulates sent emails in the
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Be sure to restart your server when you modify this file.
|
|
2
2
|
|
|
3
|
-
MongoidDummy::Application.config.session_store :cookie_store, :
|
|
3
|
+
MongoidDummy::Application.config.session_store :cookie_store, key: '_mongoid_dummy_session'
|
|
4
4
|
|
|
5
5
|
# Use the database for sessions instead of the cookie-based default,
|
|
6
6
|
# which shouldn't be used to store highly confidential information
|
|
@@ -1,59 +1,3 @@
|
|
|
1
1
|
MongoidDummy::Application.routes.draw do
|
|
2
|
-
mount SharedEngine::Engine =>
|
|
3
|
-
# The priority is based upon order of creation:
|
|
4
|
-
# first created -> highest priority.
|
|
5
|
-
|
|
6
|
-
# Sample of regular route:
|
|
7
|
-
# match 'products/:id' => 'catalog#view'
|
|
8
|
-
# Keep in mind you can assign values other than :controller and :action
|
|
9
|
-
|
|
10
|
-
# Sample of named route:
|
|
11
|
-
# match 'products/:id/purchase' => 'catalog#purchase', :as => :purchase
|
|
12
|
-
# This route can be invoked with purchase_url(:id => product.id)
|
|
13
|
-
|
|
14
|
-
# Sample resource route (maps HTTP verbs to controller actions automatically):
|
|
15
|
-
# resources :products
|
|
16
|
-
|
|
17
|
-
# Sample resource route with options:
|
|
18
|
-
# resources :products do
|
|
19
|
-
# member do
|
|
20
|
-
# get 'short'
|
|
21
|
-
# post 'toggle'
|
|
22
|
-
# end
|
|
23
|
-
#
|
|
24
|
-
# collection do
|
|
25
|
-
# get 'sold'
|
|
26
|
-
# end
|
|
27
|
-
# end
|
|
28
|
-
|
|
29
|
-
# Sample resource route with sub-resources:
|
|
30
|
-
# resources :products do
|
|
31
|
-
# resources :comments, :sales
|
|
32
|
-
# resource :seller
|
|
33
|
-
# end
|
|
34
|
-
|
|
35
|
-
# Sample resource route with more complex sub-resources
|
|
36
|
-
# resources :products do
|
|
37
|
-
# resources :comments
|
|
38
|
-
# resources :sales do
|
|
39
|
-
# get 'recent', :on => :collection
|
|
40
|
-
# end
|
|
41
|
-
# end
|
|
42
|
-
|
|
43
|
-
# Sample resource route within a namespace:
|
|
44
|
-
# namespace :admin do
|
|
45
|
-
# # Directs /admin/products/* to Admin::ProductsController
|
|
46
|
-
# # (app/controllers/admin/products_controller.rb)
|
|
47
|
-
# resources :products
|
|
48
|
-
# end
|
|
49
|
-
|
|
50
|
-
# You can have the root of your site routed with "root"
|
|
51
|
-
# just remember to delete public/index.html.
|
|
52
|
-
# root :to => 'welcome#index'
|
|
53
|
-
|
|
54
|
-
# See how all your routes lay out with "rake routes"
|
|
55
|
-
|
|
56
|
-
# This is a legacy wild controller route that's not recommended for RESTful applications.
|
|
57
|
-
# Note: This route will make all actions in every controller accessible via GET requests.
|
|
58
|
-
# match ':controller(/:action(/:id))(.:format)'
|
|
2
|
+
mount SharedEngine::Engine => '/shared', :as => 'shared'
|
|
59
3
|
end
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env ruby
|
|
2
2
|
# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
|
|
3
3
|
|
|
4
|
-
APP_PATH = File.expand_path('../../config/application',
|
|
5
|
-
require File.expand_path('../../config/boot',
|
|
4
|
+
APP_PATH = File.expand_path('../../config/application', __FILE__)
|
|
5
|
+
require File.expand_path('../../config/boot', __FILE__)
|
|
6
6
|
require 'rails/commands'
|
data/spec/shared_engine/Gemfile
CHANGED
data/spec/shared_engine/Rakefile
CHANGED
|
@@ -20,10 +20,7 @@ RDoc::Task.new(:rdoc) do |rdoc|
|
|
|
20
20
|
rdoc.rdoc_files.include('lib/**/*.rb')
|
|
21
21
|
end
|
|
22
22
|
|
|
23
|
-
APP_RAKEFILE = File.expand_path(
|
|
23
|
+
APP_RAKEFILE = File.expand_path('../active_record_dummy/Rakefile', __FILE__)
|
|
24
24
|
load 'rails/tasks/engine.rake'
|
|
25
25
|
|
|
26
|
-
|
|
27
|
-
|
|
28
26
|
Bundler::GemHelper.install_tasks
|
|
29
|
-
|
|
@@ -6,8 +6,8 @@ module SharedEngine
|
|
|
6
6
|
@users = [@han, @luke, @leia]
|
|
7
7
|
|
|
8
8
|
respond_to do |format|
|
|
9
|
-
format.xml
|
|
10
|
-
format.json { render_for_api params[:api_template].to_sym, :
|
|
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
11
|
end
|
|
12
12
|
end
|
|
13
13
|
end
|
|
@@ -1,42 +1,41 @@
|
|
|
1
1
|
module SharedEngine
|
|
2
2
|
class RespondWithUsersController < SharedEngine::ApplicationController
|
|
3
|
-
|
|
4
3
|
respond_to :json, :xml
|
|
5
4
|
|
|
6
5
|
self.responder = ActsAsApi::Responder
|
|
7
6
|
|
|
8
7
|
def index
|
|
9
8
|
@users = User.all.sort_by(&:first_name)
|
|
10
|
-
respond_with @users, :
|
|
9
|
+
respond_with @users, api_template: params[:api_template].to_sym, root: :users
|
|
11
10
|
end
|
|
12
11
|
|
|
13
12
|
def index_no_root_no_order
|
|
14
13
|
@users = User.all.to_a
|
|
15
|
-
respond_with @users, :
|
|
14
|
+
respond_with @users, api_template: params[:api_template].to_sym
|
|
16
15
|
end
|
|
17
16
|
|
|
18
17
|
def index_meta
|
|
19
18
|
@users = User.all.to_a
|
|
20
|
-
meta_hash = { :
|
|
21
|
-
respond_with @users, :
|
|
19
|
+
meta_hash = { page: 1, total: 999 }
|
|
20
|
+
respond_with @users, api_template: params[:api_template].to_sym, root: :users, meta: meta_hash
|
|
22
21
|
end
|
|
23
22
|
|
|
24
23
|
def index_relation
|
|
25
24
|
@users = User.limit(100).sort_by(&:first_name)
|
|
26
|
-
respond_with @users, :
|
|
25
|
+
respond_with @users, api_template: params[:api_template].to_sym
|
|
27
26
|
end
|
|
28
27
|
|
|
29
28
|
def show
|
|
30
29
|
@user = User.find(params[:id])
|
|
31
|
-
# :
|
|
32
|
-
respond_with @user, :
|
|
30
|
+
# root: :user is only used here because we need it for the node name of the MongoUser model
|
|
31
|
+
respond_with @user, api_template: params[:api_template].to_sym, root: :user
|
|
33
32
|
end
|
|
34
33
|
|
|
35
34
|
def show_meta
|
|
36
35
|
@user = User.find(params[:id])
|
|
37
|
-
meta_hash = { :
|
|
38
|
-
# :
|
|
39
|
-
respond_with @user, :
|
|
36
|
+
meta_hash = { page: 1, total: 999 }
|
|
37
|
+
# root: :user is only used here because we need it for the node name of the MongoUser model
|
|
38
|
+
respond_with @user, api_template: params[:api_template].to_sym, root: :user, meta: meta_hash
|
|
40
39
|
end
|
|
41
40
|
|
|
42
41
|
def show_default
|
|
@@ -46,19 +45,18 @@ module SharedEngine
|
|
|
46
45
|
|
|
47
46
|
def show_prefix_postfix
|
|
48
47
|
@user = User.find(params[:id])
|
|
49
|
-
# :
|
|
50
|
-
respond_with @user, :
|
|
48
|
+
# root: :user is only used here because we need it for the node name of the MongoUser model
|
|
49
|
+
respond_with @user, api_template: { template: params[:api_template], prefix: params[:api_prefix], postfix: params[:api_postfix] }, root: :user
|
|
51
50
|
end
|
|
52
51
|
|
|
53
52
|
def create
|
|
54
53
|
@user = User.new(params[:user].permit!)
|
|
55
54
|
|
|
56
55
|
if @user.save
|
|
57
|
-
respond_with @user, :
|
|
56
|
+
respond_with @user, api_template: params[:api_template]
|
|
58
57
|
else
|
|
59
58
|
respond_with @user
|
|
60
59
|
end
|
|
61
60
|
end
|
|
62
|
-
|
|
63
61
|
end
|
|
64
62
|
end
|