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
|
@@ -4,7 +4,7 @@ require 'rails/all'
|
|
|
4
4
|
|
|
5
5
|
if defined?(Bundler)
|
|
6
6
|
# If you precompile assets before deploying to production, use this line
|
|
7
|
-
Bundler.require(*Rails.groups(:
|
|
7
|
+
Bundler.require(*Rails.groups(assets: %w(development test)))
|
|
8
8
|
# If you want your assets lazily compiled in production, use this line
|
|
9
9
|
# Bundler.require(:default, :assets, Rails.env)
|
|
10
10
|
end
|
|
@@ -34,7 +34,7 @@ module ActiveRecordDummy
|
|
|
34
34
|
# config.i18n.default_locale = :de
|
|
35
35
|
|
|
36
36
|
# Configure the default encoding used in templates for Ruby 1.9.
|
|
37
|
-
config.encoding =
|
|
37
|
+
config.encoding = 'utf-8'
|
|
38
38
|
|
|
39
39
|
# Configure sensitive parameters which will be filtered from the log file.
|
|
40
40
|
config.filter_parameters += [:password]
|
|
@@ -14,14 +14,14 @@ ActiveRecordDummy::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
|
-
ActiveRecordDummy::Application.config.session_store :cookie_store, :
|
|
3
|
+
ActiveRecordDummy::Application.config.session_store :cookie_store, key: '_active_record_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
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
|
|
6
6
|
# Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array.
|
|
7
7
|
ActiveSupport.on_load(:action_controller) do
|
|
8
|
-
wrap_parameters :
|
|
8
|
+
wrap_parameters format: [:json]
|
|
9
9
|
end
|
|
10
10
|
|
|
11
11
|
# Disable root element in JSON by default.
|
|
@@ -1,59 +1,3 @@
|
|
|
1
1
|
ActiveRecordDummy::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,35 +1,34 @@
|
|
|
1
1
|
class CreateTables < ActiveRecord::Migration
|
|
2
2
|
def self.up
|
|
3
|
+
create_table 'users', force: true do |t|
|
|
4
|
+
t.string 'first_name'
|
|
5
|
+
t.string 'last_name'
|
|
6
|
+
t.integer 'age'
|
|
7
|
+
t.boolean 'active'
|
|
8
|
+
t.datetime 'created_at'
|
|
9
|
+
t.datetime 'updated_at'
|
|
10
|
+
end
|
|
3
11
|
|
|
4
|
-
create_table
|
|
5
|
-
t.
|
|
6
|
-
t.string
|
|
7
|
-
t.
|
|
8
|
-
t.
|
|
9
|
-
t.
|
|
10
|
-
t.datetime
|
|
12
|
+
create_table 'tasks', force: true do |t|
|
|
13
|
+
t.integer 'user_id'
|
|
14
|
+
t.string 'heading'
|
|
15
|
+
t.string 'description'
|
|
16
|
+
t.integer 'time_spent'
|
|
17
|
+
t.boolean 'done'
|
|
18
|
+
t.datetime 'created_at'
|
|
19
|
+
t.datetime 'updated_at'
|
|
11
20
|
end
|
|
12
21
|
|
|
13
|
-
create_table
|
|
14
|
-
t.integer
|
|
15
|
-
t.string
|
|
16
|
-
t.string
|
|
17
|
-
t.
|
|
18
|
-
t.
|
|
19
|
-
t.datetime "created_at"
|
|
20
|
-
t.datetime "updated_at"
|
|
22
|
+
create_table 'profiles', force: true do |t|
|
|
23
|
+
t.integer 'user_id'
|
|
24
|
+
t.string 'avatar'
|
|
25
|
+
t.string 'homepage'
|
|
26
|
+
t.datetime 'created_at'
|
|
27
|
+
t.datetime 'updated_at'
|
|
21
28
|
end
|
|
22
|
-
|
|
23
|
-
create_table "profiles", :force => true do |t|
|
|
24
|
-
t.integer "user_id"
|
|
25
|
-
t.string "avatar"
|
|
26
|
-
t.string "homepage"
|
|
27
|
-
t.datetime "created_at"
|
|
28
|
-
t.datetime "updated_at"
|
|
29
|
-
end
|
|
30
|
-
|
|
29
|
+
|
|
31
30
|
create_table :untoucheds do |t|
|
|
32
|
-
t.string
|
|
31
|
+
t.string 'nothing'
|
|
33
32
|
t.timestamps
|
|
34
33
|
end
|
|
35
34
|
|
|
@@ -39,6 +38,6 @@ class CreateTables < ActiveRecord::Migration
|
|
|
39
38
|
drop_table :untoucheds
|
|
40
39
|
drop_table :profiles
|
|
41
40
|
drop_table :tasks
|
|
42
|
-
drop_table :users
|
|
41
|
+
drop_table :users
|
|
43
42
|
end
|
|
44
43
|
end
|
|
@@ -10,38 +10,36 @@
|
|
|
10
10
|
#
|
|
11
11
|
# It's strongly recommended to check this file into your version control system.
|
|
12
12
|
|
|
13
|
-
ActiveRecord::Schema.define(:
|
|
13
|
+
ActiveRecord::Schema.define(version: 20110214201640) do
|
|
14
|
+
create_table 'tasks', force: true do |t|
|
|
15
|
+
t.integer 'user_id'
|
|
16
|
+
t.string 'heading'
|
|
17
|
+
t.string 'description'
|
|
18
|
+
t.integer 'time_spent'
|
|
19
|
+
t.boolean 'done'
|
|
20
|
+
t.datetime 'created_at'
|
|
21
|
+
t.datetime 'updated_at'
|
|
22
|
+
end
|
|
14
23
|
|
|
15
|
-
create_table
|
|
16
|
-
t.integer
|
|
17
|
-
t.string
|
|
18
|
-
t.string
|
|
19
|
-
t.
|
|
20
|
-
t.
|
|
21
|
-
t.datetime "created_at"
|
|
22
|
-
t.datetime "updated_at"
|
|
24
|
+
create_table 'profiles', force: true do |t|
|
|
25
|
+
t.integer 'user_id'
|
|
26
|
+
t.string 'avatar'
|
|
27
|
+
t.string 'homepage'
|
|
28
|
+
t.datetime 'created_at'
|
|
29
|
+
t.datetime 'updated_at'
|
|
23
30
|
end
|
|
24
|
-
|
|
25
|
-
create_table "profiles", :force => true do |t|
|
|
26
|
-
t.integer "user_id"
|
|
27
|
-
t.string "avatar"
|
|
28
|
-
t.string "homepage"
|
|
29
|
-
t.datetime "created_at"
|
|
30
|
-
t.datetime "updated_at"
|
|
31
|
-
end
|
|
32
31
|
|
|
33
|
-
create_table
|
|
34
|
-
t.string
|
|
35
|
-
t.string
|
|
36
|
-
t.integer
|
|
37
|
-
t.boolean
|
|
38
|
-
t.datetime
|
|
39
|
-
t.datetime
|
|
32
|
+
create_table 'users', force: true do |t|
|
|
33
|
+
t.string 'first_name'
|
|
34
|
+
t.string 'last_name'
|
|
35
|
+
t.integer 'age'
|
|
36
|
+
t.boolean 'active'
|
|
37
|
+
t.datetime 'created_at'
|
|
38
|
+
t.datetime 'updated_at'
|
|
40
39
|
end
|
|
41
|
-
|
|
42
|
-
create_table "untoucheds", :force => true do |t|
|
|
43
|
-
t.string "nothing"
|
|
44
|
-
t.timestamps
|
|
45
|
-
end
|
|
46
40
|
|
|
41
|
+
create_table 'untoucheds', force: true do |t|
|
|
42
|
+
t.string 'nothing'
|
|
43
|
+
t.timestamps
|
|
44
|
+
end
|
|
47
45
|
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'
|
|
@@ -11,27 +11,26 @@ describe SharedEngine::PlainObjectsController, type: :controller do
|
|
|
11
11
|
end
|
|
12
12
|
|
|
13
13
|
describe 'get all users as a an array of plain objects, autodetecting the root node name' do
|
|
14
|
-
|
|
15
14
|
before(:each) do
|
|
16
|
-
get :index, :
|
|
15
|
+
get :index, format: 'json', params: { api_template: :name_only }
|
|
17
16
|
end
|
|
18
17
|
|
|
19
|
-
it
|
|
20
|
-
response_body_json.
|
|
18
|
+
it 'should have a root node named users' do
|
|
19
|
+
expect(response_body_json).to have_key('plain_objects')
|
|
21
20
|
end
|
|
22
21
|
|
|
23
|
-
it
|
|
24
|
-
response_body_json[
|
|
22
|
+
it 'should contain all users' do
|
|
23
|
+
expect(response_body_json['plain_objects']).to be_a(Array)
|
|
25
24
|
end
|
|
26
25
|
|
|
27
|
-
it
|
|
28
|
-
response_body_json[
|
|
29
|
-
response_body_json[
|
|
26
|
+
it 'should contain the specified attributes' do
|
|
27
|
+
expect(response_body_json['plain_objects'].first).to have_key('first_name')
|
|
28
|
+
expect(response_body_json['plain_objects'].first).to have_key('last_name')
|
|
30
29
|
end
|
|
31
30
|
|
|
32
|
-
it
|
|
33
|
-
response_body_json[
|
|
34
|
-
response_body_json[
|
|
31
|
+
it 'should contain the specified values' do
|
|
32
|
+
expect(response_body_json['plain_objects'].first['first_name']).to eql('Han')
|
|
33
|
+
expect(response_body_json['plain_objects'].first['last_name']).to eql('Solo')
|
|
35
34
|
end
|
|
36
35
|
end
|
|
37
36
|
end
|
|
@@ -1,8 +1,4 @@
|
|
|
1
1
|
require 'spec_helper'
|
|
2
|
-
#
|
|
3
|
-
# RSpec.configure do |config|
|
|
4
|
-
# config.include SharedEngine::Engine.routes.url_helpers
|
|
5
|
-
# end
|
|
6
2
|
|
|
7
3
|
describe SharedEngine::RespondWithUsersController, type: :controller do
|
|
8
4
|
routes { SharedEngine::Engine.routes }
|
|
@@ -12,131 +8,114 @@ describe SharedEngine::RespondWithUsersController, type: :controller do
|
|
|
12
8
|
end
|
|
13
9
|
|
|
14
10
|
after(:each) do
|
|
15
|
-
|
|
11
|
+
clean_up_models
|
|
16
12
|
end
|
|
17
13
|
|
|
18
14
|
# see spec/support/controller_examples.rb
|
|
19
|
-
it_behaves_like
|
|
20
|
-
|
|
21
|
-
describe "default ActionController::Responder behavior" do
|
|
15
|
+
it_behaves_like 'a controller with ActsAsApi responses'
|
|
22
16
|
|
|
17
|
+
describe 'default ActionController::Responder behavior' do
|
|
23
18
|
context 'json responses' do
|
|
24
|
-
|
|
25
|
-
context "creating valid models" do
|
|
26
|
-
|
|
19
|
+
context 'creating valid models' do
|
|
27
20
|
before(:each) do
|
|
28
|
-
post :create, format: 'json', params: { user: { first_name:
|
|
21
|
+
post :create, format: 'json', params: { user: { first_name: 'Luke', last_name: 'Skywalker' }, api_template: :name_only }
|
|
29
22
|
end
|
|
30
23
|
|
|
31
|
-
it
|
|
32
|
-
response.code.
|
|
24
|
+
it 'should return HTTP 201 status' do
|
|
25
|
+
expect(response.code).to eq('201')
|
|
33
26
|
end
|
|
34
27
|
|
|
35
|
-
it
|
|
36
|
-
response_body_json[
|
|
37
|
-
response_body_json[
|
|
28
|
+
it 'should contain the specified attributes' do
|
|
29
|
+
expect(response_body_json['user']).to have_key('first_name')
|
|
30
|
+
expect(response_body_json['user']).to have_key('last_name')
|
|
38
31
|
end
|
|
39
32
|
|
|
40
|
-
it
|
|
41
|
-
response_body_json[
|
|
42
|
-
response_body_json[
|
|
33
|
+
it 'should contain the specified values' do
|
|
34
|
+
expect(response_body_json['user']['first_name']).to eql('Luke')
|
|
35
|
+
expect(response_body_json['user']['last_name']).to eql('Skywalker')
|
|
43
36
|
end
|
|
44
37
|
end
|
|
45
38
|
|
|
46
|
-
context
|
|
47
|
-
|
|
39
|
+
context 'creating invalid models' do
|
|
48
40
|
before(:each) do
|
|
49
41
|
post :create, format: 'json', params: { user: { first_name: 'Luke' }, api_template: :name_only }
|
|
50
42
|
end
|
|
51
43
|
|
|
52
|
-
it
|
|
53
|
-
response.code.
|
|
44
|
+
it 'should return HTTP 422 status' do
|
|
45
|
+
expect(response.code).to eq('422')
|
|
54
46
|
end
|
|
55
47
|
|
|
56
|
-
it
|
|
57
|
-
response_body_json['errors']['last_name'].
|
|
48
|
+
it 'should return errors as json' do
|
|
49
|
+
expect(response_body_json['errors']['last_name']).to include('can\'t be blank')
|
|
58
50
|
end
|
|
59
|
-
|
|
60
51
|
end
|
|
61
52
|
|
|
62
|
-
context
|
|
63
|
-
|
|
53
|
+
context 'returning all models without default root and no order' do
|
|
64
54
|
before(:each) do
|
|
65
55
|
get :index_no_root_no_order, format: 'json', params: { api_template: :name_only }
|
|
66
56
|
end
|
|
67
57
|
|
|
68
|
-
it
|
|
69
|
-
response.code.
|
|
58
|
+
it 'should return HTTP 200 status' do
|
|
59
|
+
expect(response.code).to eq('200')
|
|
70
60
|
end
|
|
71
61
|
|
|
72
|
-
it
|
|
73
|
-
response_body_json[
|
|
74
|
-
user.
|
|
75
|
-
user.
|
|
62
|
+
it 'should contain the specified attributes' do
|
|
63
|
+
response_body_json['users'].each do |user|
|
|
64
|
+
expect(user).to have_key('first_name')
|
|
65
|
+
expect(user).to have_key('last_name')
|
|
76
66
|
end
|
|
77
67
|
end
|
|
78
|
-
|
|
79
68
|
end
|
|
80
|
-
|
|
81
69
|
end
|
|
82
70
|
|
|
83
71
|
context 'xml responses' do
|
|
84
|
-
|
|
85
|
-
context "creating valid models" do
|
|
86
|
-
|
|
72
|
+
context 'creating valid models' do
|
|
87
73
|
before(:each) do
|
|
88
|
-
post :create, format: 'xml', params: { user: { first_name:
|
|
74
|
+
post :create, format: 'xml', params: { user: { first_name: 'Luke', last_name: 'Skywalker' }, api_template: :name_only }
|
|
89
75
|
end
|
|
90
76
|
|
|
91
|
-
it
|
|
92
|
-
response.code.
|
|
77
|
+
it 'should return HTTP 201 status' do
|
|
78
|
+
expect(response.code).to eq('201')
|
|
93
79
|
end
|
|
94
80
|
|
|
95
|
-
it
|
|
96
|
-
response.headers[
|
|
81
|
+
it 'should include HTTP Location header' do
|
|
82
|
+
expect(response.headers['Location']).to match "/shared/users/#{User.last.id}"
|
|
97
83
|
end
|
|
98
84
|
|
|
99
|
-
it
|
|
100
|
-
response_body.
|
|
101
|
-
response_body.
|
|
85
|
+
it 'should contain the specified attributes' do
|
|
86
|
+
expect(response_body).to have_selector('user > first-name')
|
|
87
|
+
expect(response_body).to have_selector('user > last-name')
|
|
102
88
|
end
|
|
103
|
-
|
|
104
89
|
end
|
|
105
90
|
|
|
106
|
-
context
|
|
107
|
-
|
|
91
|
+
context 'creating invalid models' do
|
|
108
92
|
before(:each) do
|
|
109
|
-
post :create, :
|
|
93
|
+
post :create, format: 'xml', params: { user: { first_name: 'Luke' }, api_template: :name_only }
|
|
110
94
|
end
|
|
111
95
|
|
|
112
|
-
it
|
|
113
|
-
response.code.
|
|
96
|
+
it 'should return HTTP 422 status' do
|
|
97
|
+
expect(response.code).to eq('422')
|
|
114
98
|
end
|
|
115
99
|
|
|
116
|
-
it
|
|
117
|
-
response_body.
|
|
100
|
+
it 'should return errors as xml' do
|
|
101
|
+
expect(response_body).to have_selector('errors > error')
|
|
118
102
|
end
|
|
119
|
-
|
|
120
103
|
end
|
|
121
104
|
|
|
122
|
-
context
|
|
123
|
-
|
|
105
|
+
context 'returning all models without default root and no order' do
|
|
124
106
|
before(:each) do
|
|
125
107
|
get :index_no_root_no_order, format: 'xml', params: { api_template: :name_only }
|
|
126
108
|
end
|
|
127
109
|
|
|
128
|
-
it
|
|
129
|
-
response.code.
|
|
110
|
+
it 'should return HTTP 200 status' do
|
|
111
|
+
expect(response.code).to eq('200')
|
|
130
112
|
end
|
|
131
113
|
|
|
132
|
-
it
|
|
133
|
-
response_body.
|
|
134
|
-
response_body.
|
|
114
|
+
it 'should contain the specified attributes' do
|
|
115
|
+
expect(response_body).to have_selector('users > user > first-name', count: 3)
|
|
116
|
+
expect(response_body).to have_selector('users > user > last-name', count: 3)
|
|
135
117
|
end
|
|
136
|
-
|
|
137
118
|
end
|
|
138
119
|
end
|
|
139
|
-
|
|
140
120
|
end
|
|
141
|
-
|
|
142
121
|
end
|