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.
Files changed (161) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +4 -7
  3. data/History.txt +5 -0
  4. data/LICENSE.txt +20 -0
  5. data/README.md +0 -25
  6. data/Rakefile +5 -12
  7. data/acts_as_api.gemspec +14 -13
  8. data/{examples/introduction → docs}/docco.css +0 -0
  9. data/{examples/introduction → docs}/index.html +18 -21
  10. data/{examples/introduction → docs}/index.rb +0 -0
  11. data/{examples/introduction → docs}/layout.mustache +0 -0
  12. data/lib/acts_as_api.rb +9 -12
  13. data/lib/acts_as_api/adapters.rb +1 -1
  14. data/lib/acts_as_api/api_template.rb +23 -25
  15. data/lib/acts_as_api/base.rb +11 -20
  16. data/lib/acts_as_api/collection.rb +1 -2
  17. data/lib/acts_as_api/config.rb +0 -5
  18. data/lib/acts_as_api/exceptions.rb +2 -2
  19. data/lib/acts_as_api/rails_renderer.rb +0 -2
  20. data/lib/acts_as_api/rendering.rb +5 -12
  21. data/lib/acts_as_api/responder.rb +8 -13
  22. data/lib/acts_as_api/version.rb +1 -1
  23. data/spec/README.md +15 -6
  24. data/spec/active_record_dummy/Gemfile +2 -10
  25. data/spec/active_record_dummy/app/models/user.rb +31 -32
  26. data/spec/active_record_dummy/config.ru +1 -1
  27. data/spec/active_record_dummy/config/application.rb +2 -2
  28. data/spec/active_record_dummy/config/boot.rb +1 -1
  29. data/spec/active_record_dummy/config/environments/test.rb +2 -2
  30. data/spec/active_record_dummy/config/initializers/session_store.rb +1 -1
  31. data/spec/active_record_dummy/config/initializers/wrap_parameters.rb +1 -1
  32. data/spec/active_record_dummy/config/routes.rb +1 -57
  33. data/spec/active_record_dummy/db/migrate/20110214201640_create_tables.rb +25 -26
  34. data/spec/active_record_dummy/db/schema.rb +27 -29
  35. data/spec/active_record_dummy/script/rails +2 -2
  36. data/spec/controllers/plain_objects_controller_spec.rb +11 -12
  37. data/spec/controllers/respond_with_users_controller_spec.rb +46 -67
  38. data/spec/controllers/users_controller_spec.rb +2 -3
  39. data/spec/models/model_spec.rb +17 -19
  40. data/spec/mongoid_dummy/Gemfile +3 -12
  41. data/spec/mongoid_dummy/app/models/profile.rb +6 -6
  42. data/spec/mongoid_dummy/app/models/task.rb +10 -10
  43. data/spec/mongoid_dummy/app/models/untouched.rb +4 -4
  44. data/spec/mongoid_dummy/app/models/user.rb +12 -14
  45. data/spec/mongoid_dummy/config.ru +1 -1
  46. data/spec/mongoid_dummy/config/application.rb +7 -7
  47. data/spec/mongoid_dummy/config/boot.rb +1 -1
  48. data/spec/mongoid_dummy/config/environments/development.rb +0 -1
  49. data/spec/mongoid_dummy/config/environments/production.rb +0 -1
  50. data/spec/mongoid_dummy/config/environments/test.rb +2 -2
  51. data/spec/mongoid_dummy/config/initializers/include_acts_as_api.rb +1 -1
  52. data/spec/mongoid_dummy/config/initializers/session_store.rb +1 -1
  53. data/spec/mongoid_dummy/config/initializers/wrap_parameters.rb +1 -2
  54. data/spec/mongoid_dummy/config/routes.rb +1 -57
  55. data/spec/mongoid_dummy/script/rails +2 -2
  56. data/spec/shared_engine/Gemfile +1 -1
  57. data/spec/shared_engine/Rakefile +1 -4
  58. data/spec/shared_engine/app/controllers/shared_engine/plain_objects_controller.rb +2 -2
  59. data/spec/shared_engine/app/controllers/shared_engine/respond_with_users_controller.rb +13 -15
  60. data/spec/shared_engine/app/controllers/shared_engine/users_controller.rb +17 -19
  61. data/spec/shared_engine/app/models/plain_object.rb +3 -1
  62. data/spec/shared_engine/app/models/user_template.rb +28 -29
  63. data/spec/shared_engine/lib/shared_engine.rb +1 -1
  64. data/spec/shared_engine/lib/shared_engine/version.rb +1 -1
  65. data/spec/shared_engine/shared_engine.gemspec +10 -12
  66. data/spec/spec_helper.rb +5 -13
  67. data/spec/support/api_test_helpers.rb +0 -2
  68. data/spec/support/controller_examples.rb +128 -173
  69. data/spec/support/it_supports.rb +1 -1
  70. data/spec/support/model_examples/associations.rb +119 -128
  71. data/spec/support/model_examples/callbacks.rb +17 -27
  72. data/spec/support/model_examples/closures.rb +21 -29
  73. data/spec/support/model_examples/conditional_if.rb +71 -103
  74. data/spec/support/model_examples/conditional_unless.rb +71 -103
  75. data/spec/support/model_examples/enabled.rb +5 -6
  76. data/spec/support/model_examples/extending.rb +49 -56
  77. data/spec/support/model_examples/methods.rb +11 -15
  78. data/spec/support/model_examples/options.rb +19 -25
  79. data/spec/support/model_examples/renaming.rb +21 -30
  80. data/spec/support/model_examples/simple.rb +10 -14
  81. data/spec/support/model_examples/sub_nodes.rb +47 -59
  82. data/spec/support/model_examples/undefined.rb +4 -6
  83. data/spec/support/model_examples/untouched.rb +6 -8
  84. data/spec/support/simple_fixtures.rb +11 -38
  85. metadata +22 -159
  86. data/spec/active_record_dummy/app/assets/images/rails.png +0 -0
  87. data/spec/active_record_dummy/app/assets/javascripts/application.js +0 -15
  88. data/spec/active_record_dummy/app/assets/stylesheets/application.css +0 -13
  89. data/spec/active_record_dummy/app/controllers/application_controller.rb +0 -3
  90. data/spec/active_record_dummy/app/helpers/application_helper.rb +0 -2
  91. data/spec/active_record_dummy/app/mailers/.gitkeep +0 -0
  92. data/spec/active_record_dummy/app/views/layouts/application.html.erb +0 -14
  93. data/spec/active_record_dummy/doc/README_FOR_APP +0 -2
  94. data/spec/active_record_dummy/lib/assets/.gitkeep +0 -0
  95. data/spec/active_record_dummy/lib/tasks/.gitkeep +0 -0
  96. data/spec/active_record_dummy/public/404.html +0 -26
  97. data/spec/active_record_dummy/public/422.html +0 -26
  98. data/spec/active_record_dummy/public/500.html +0 -25
  99. data/spec/active_record_dummy/public/favicon.ico +0 -0
  100. data/spec/active_record_dummy/public/index.html +0 -241
  101. data/spec/active_record_dummy/public/robots.txt +0 -5
  102. data/spec/active_record_dummy/vendor/assets/javascripts/.gitkeep +0 -0
  103. data/spec/active_record_dummy/vendor/assets/stylesheets/.gitkeep +0 -0
  104. data/spec/active_record_dummy/vendor/plugins/.gitkeep +0 -0
  105. data/spec/mongoid_dummy/README.rdoc +0 -261
  106. data/spec/mongoid_dummy/app/assets/images/rails.png +0 -0
  107. data/spec/mongoid_dummy/app/assets/javascripts/application.js +0 -15
  108. data/spec/mongoid_dummy/app/assets/stylesheets/application.css +0 -13
  109. data/spec/mongoid_dummy/app/controllers/application_controller.rb +0 -3
  110. data/spec/mongoid_dummy/app/helpers/application_helper.rb +0 -2
  111. data/spec/mongoid_dummy/app/mailers/.gitkeep +0 -0
  112. data/spec/mongoid_dummy/app/views/layouts/application.html.erb +0 -14
  113. data/spec/mongoid_dummy/doc/README_FOR_APP +0 -2
  114. data/spec/mongoid_dummy/lib/assets/.gitkeep +0 -0
  115. data/spec/mongoid_dummy/lib/tasks/.gitkeep +0 -0
  116. data/spec/mongoid_dummy/public/404.html +0 -26
  117. data/spec/mongoid_dummy/public/422.html +0 -26
  118. data/spec/mongoid_dummy/public/500.html +0 -25
  119. data/spec/mongoid_dummy/public/favicon.ico +0 -0
  120. data/spec/mongoid_dummy/public/index.html +0 -241
  121. data/spec/mongoid_dummy/public/robots.txt +0 -5
  122. data/spec/mongoid_dummy/vendor/assets/javascripts/.gitkeep +0 -0
  123. data/spec/mongoid_dummy/vendor/assets/stylesheets/.gitkeep +0 -0
  124. data/spec/mongoid_dummy/vendor/plugins/.gitkeep +0 -0
  125. data/spec/shared_engine/app/assets/images/shared_engine/.gitkeep +0 -0
  126. data/spec/shared_engine/app/assets/javascripts/shared_engine/application.js +0 -15
  127. data/spec/shared_engine/app/assets/stylesheets/shared_engine/application.css +0 -13
  128. data/spec/shared_engine/app/helpers/shared_engine/application_helper.rb +0 -4
  129. data/spec/shared_engine/app/views/layouts/shared_engine/application.html.erb +0 -14
  130. data/spec/shared_engine/dummy/README.rdoc +0 -261
  131. data/spec/shared_engine/dummy/Rakefile +0 -7
  132. data/spec/shared_engine/dummy/app/assets/javascripts/application.js +0 -15
  133. data/spec/shared_engine/dummy/app/assets/stylesheets/application.css +0 -13
  134. data/spec/shared_engine/dummy/app/controllers/application_controller.rb +0 -3
  135. data/spec/shared_engine/dummy/app/helpers/application_helper.rb +0 -2
  136. data/spec/shared_engine/dummy/app/mailers/.gitkeep +0 -0
  137. data/spec/shared_engine/dummy/app/models/.gitkeep +0 -0
  138. data/spec/shared_engine/dummy/app/views/layouts/application.html.erb +0 -14
  139. data/spec/shared_engine/dummy/config.ru +0 -4
  140. data/spec/shared_engine/dummy/config/application.rb +0 -56
  141. data/spec/shared_engine/dummy/config/boot.rb +0 -10
  142. data/spec/shared_engine/dummy/config/database.yml +0 -25
  143. data/spec/shared_engine/dummy/config/environment.rb +0 -5
  144. data/spec/shared_engine/dummy/config/environments/development.rb +0 -34
  145. data/spec/shared_engine/dummy/config/environments/production.rb +0 -63
  146. data/spec/shared_engine/dummy/config/environments/test.rb +0 -37
  147. data/spec/shared_engine/dummy/config/initializers/backtrace_silencers.rb +0 -7
  148. data/spec/shared_engine/dummy/config/initializers/inflections.rb +0 -15
  149. data/spec/shared_engine/dummy/config/initializers/mime_types.rb +0 -5
  150. data/spec/shared_engine/dummy/config/initializers/secret_token.rb +0 -7
  151. data/spec/shared_engine/dummy/config/initializers/session_store.rb +0 -8
  152. data/spec/shared_engine/dummy/config/initializers/wrap_parameters.rb +0 -14
  153. data/spec/shared_engine/dummy/config/locales/en.yml +0 -5
  154. data/spec/shared_engine/dummy/config/routes.rb +0 -4
  155. data/spec/shared_engine/dummy/lib/assets/.gitkeep +0 -0
  156. data/spec/shared_engine/dummy/log/.gitkeep +0 -0
  157. data/spec/shared_engine/dummy/public/404.html +0 -26
  158. data/spec/shared_engine/dummy/public/422.html +0 -26
  159. data/spec/shared_engine/dummy/public/500.html +0 -25
  160. data/spec/shared_engine/dummy/public/favicon.ico +0 -0
  161. data/spec/shared_engine/dummy/script/rails +0 -6
@@ -1,4 +1,4 @@
1
1
  # This file is used by Rack-based servers to start the application.
2
2
 
3
- require ::File.expand_path('../config/environment', __FILE__)
3
+ require ::File.expand_path('../config/environment', __FILE__)
4
4
  run ActiveRecordDummy::Application
@@ -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(:assets => %w(development test)))
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 = "utf-8"
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]
@@ -3,4 +3,4 @@ require 'rubygems'
3
3
  # Set up gems listed in the Gemfile.
4
4
  ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
5
5
 
6
- require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])
6
+ require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])
@@ -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 = true
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 = false
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, :key => '_active_record_dummy_session'
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 :format => [:json]
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 => "/shared", :as => "shared"
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 "users", :force => true do |t|
5
- t.string "first_name"
6
- t.string "last_name"
7
- t.integer "age"
8
- t.boolean "active"
9
- t.datetime "created_at"
10
- t.datetime "updated_at"
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 "tasks", :force => true do |t|
14
- t.integer "user_id"
15
- t.string "heading"
16
- t.string "description"
17
- t.integer "time_spent"
18
- t.boolean "done"
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 "nothing"
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(:version => 20110214201640) do
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 "tasks", :force => true do |t|
16
- t.integer "user_id"
17
- t.string "heading"
18
- t.string "description"
19
- t.integer "time_spent"
20
- t.boolean "done"
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 "users", :force => true do |t|
34
- t.string "first_name"
35
- t.string "last_name"
36
- t.integer "age"
37
- t.boolean "active"
38
- t.datetime "created_at"
39
- t.datetime "updated_at"
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', __FILE__)
5
- require File.expand_path('../../config/boot', __FILE__)
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, :format => 'json', params: { :api_template => :name_only }
15
+ get :index, format: 'json', params: { api_template: :name_only }
17
16
  end
18
17
 
19
- it "should have a root node named users" do
20
- response_body_json.should have_key("plain_objects")
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 "should contain all users" do
24
- response_body_json["plain_objects"].should be_a(Array)
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 "should contain the specified attributes" do
28
- response_body_json["plain_objects"].first.should have_key("first_name")
29
- response_body_json["plain_objects"].first.should have_key("last_name")
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 "should contain the specified values" do
33
- response_body_json["plain_objects"].first["first_name"].should eql("Han")
34
- response_body_json["plain_objects"].first["last_name"].should eql("Solo")
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
- clean_up_models
11
+ clean_up_models
16
12
  end
17
13
 
18
14
  # see spec/support/controller_examples.rb
19
- it_behaves_like "a controller with ActsAsApi responses"
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: "Luke", last_name: "Skywalker" }, api_template: :name_only }
21
+ post :create, format: 'json', params: { user: { first_name: 'Luke', last_name: 'Skywalker' }, api_template: :name_only }
29
22
  end
30
23
 
31
- it "should return HTTP 201 status" do
32
- response.code.should == "201"
24
+ it 'should return HTTP 201 status' do
25
+ expect(response.code).to eq('201')
33
26
  end
34
27
 
35
- it "should contain the specified attributes" do
36
- response_body_json["user"].should have_key("first_name")
37
- response_body_json["user"].should have_key("last_name")
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 "should contain the specified values" do
41
- response_body_json["user"]["first_name"].should eql("Luke")
42
- response_body_json["user"]["last_name"].should eql("Skywalker")
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 "creating invalid models" do
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 "should return HTTP 422 status" do
53
- response.code.should == "422"
44
+ it 'should return HTTP 422 status' do
45
+ expect(response.code).to eq('422')
54
46
  end
55
47
 
56
- it "should return errors as json" do
57
- response_body_json['errors']['last_name'].should include("can't be blank")
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 "returning all models without default root and no order" do
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 "should return HTTP 200 status" do
69
- response.code.should == "200"
58
+ it 'should return HTTP 200 status' do
59
+ expect(response.code).to eq('200')
70
60
  end
71
61
 
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" )
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: "Luke", last_name: "Skywalker" }, api_template: :name_only }
74
+ post :create, format: 'xml', params: { user: { first_name: 'Luke', last_name: 'Skywalker' }, api_template: :name_only }
89
75
  end
90
76
 
91
- it "should return HTTP 201 status" do
92
- response.code.should == "201"
77
+ it 'should return HTTP 201 status' do
78
+ expect(response.code).to eq('201')
93
79
  end
94
80
 
95
- it "should include HTTP Location header" do
96
- response.headers["Location"].should match "/shared/users/#{User.last.id}"
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 "should contain the specified attributes" do
100
- response_body.should have_selector("user > first-name")
101
- response_body.should have_selector("user > last-name")
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 "creating invalid models" do
107
-
91
+ context 'creating invalid models' do
108
92
  before(:each) do
109
- post :create, :format => 'xml', params: { user: { first_name: 'Luke' }, api_template: :name_only }
93
+ post :create, format: 'xml', params: { user: { first_name: 'Luke' }, api_template: :name_only }
110
94
  end
111
95
 
112
- it "should return HTTP 422 status" do
113
- response.code.should == "422"
96
+ it 'should return HTTP 422 status' do
97
+ expect(response.code).to eq('422')
114
98
  end
115
99
 
116
- it "should return errors as xml" do
117
- response_body.should have_selector("errors > error")
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 "returning all models without default root and no order" do
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 "should return HTTP 200 status" do
129
- response.code.should == "200"
110
+ it 'should return HTTP 200 status' do
111
+ expect(response.code).to eq('200')
130
112
  end
131
113
 
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 )
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