acts_as_api 0.4.3 → 0.4.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +4 -2
  3. data/History.txt +8 -0
  4. data/README.md +2 -2
  5. data/acts_as_api.gemspec +2 -2
  6. data/examples/introduction/index.html +6 -6
  7. data/examples/introduction/index.rb +1 -1
  8. data/examples/introduction/layout.mustache +4 -4
  9. data/lib/acts_as_api.rb +18 -2
  10. data/lib/acts_as_api/collection.rb +17 -0
  11. data/lib/acts_as_api/config.rb +15 -15
  12. data/lib/acts_as_api/rails_renderer.rb +6 -2
  13. data/lib/acts_as_api/rendering.rb +4 -4
  14. data/lib/acts_as_api/version.rb +1 -1
  15. data/spec/active_record_dummy/Gemfile +1 -1
  16. data/spec/active_record_dummy/app/models/profile.rb +2 -3
  17. data/spec/active_record_dummy/app/models/task.rb +2 -3
  18. data/spec/active_record_dummy/app/models/user.rb +6 -7
  19. data/spec/active_record_dummy/config/application.rb +0 -6
  20. data/spec/active_record_dummy/config/environments/development.rb +4 -7
  21. data/spec/active_record_dummy/config/environments/production.rb +0 -4
  22. data/spec/active_record_dummy/config/environments/test.rb +3 -3
  23. data/spec/controllers/plain_objects_controller_spec.rb +2 -1
  24. data/spec/controllers/respond_with_users_controller_spec.rb +8 -8
  25. data/spec/mongoid_dummy/Gemfile +2 -2
  26. data/spec/mongoid_dummy/config/application.rb +0 -7
  27. data/spec/mongoid_dummy/config/environments/development.rb +4 -0
  28. data/spec/mongoid_dummy/config/environments/test.rb +3 -1
  29. data/spec/mongoid_dummy/config/mongoid.yml +4 -112
  30. data/spec/shared_engine/app/controllers/shared_engine/plain_objects_controller.rb +1 -1
  31. data/spec/shared_engine/app/controllers/shared_engine/respond_with_users_controller.rb +6 -6
  32. data/spec/shared_engine/app/controllers/shared_engine/users_controller.rb +8 -4
  33. data/spec/shared_engine/dummy/config/application.rb +0 -6
  34. data/spec/shared_engine/dummy/config/environments/development.rb +4 -7
  35. data/spec/shared_engine/dummy/config/environments/production.rb +0 -4
  36. data/spec/shared_engine/dummy/config/environments/test.rb +3 -3
  37. data/spec/shared_engine/shared_engine.gemspec +1 -1
  38. data/spec/spec_helper.rb +7 -5
  39. data/spec/support/controller_examples.rb +23 -47
  40. data/spec/support/model_examples/associations.rb +59 -59
  41. metadata +4 -8
  42. data/lib/acts_as_api/array.rb +0 -21
  43. data/spec/shared_engine/lib/magic/rails/engine.rb +0 -69
  44. data/spec/support/routing.rb +0 -4
@@ -60,8 +60,4 @@ ActiveRecordDummy::Application.configure do
60
60
 
61
61
  # Send deprecation notices to registered listeners
62
62
  config.active_support.deprecation = :notify
63
-
64
- # Log the query plan for queries taking more than this (works
65
- # with SQLite, MySQL, and PostgreSQL)
66
- # config.active_record.auto_explain_threshold_in_seconds = 0.5
67
63
  end
@@ -9,7 +9,6 @@ ActiveRecordDummy::Application.configure do
9
9
 
10
10
  # Configure static asset server for tests with Cache-Control for performance
11
11
  config.serve_static_assets = true
12
- config.static_cache_control = "public, max-age=3600"
13
12
 
14
13
  # Log error messages when you accidentally call methods on nil
15
14
  config.whiny_nils = true
@@ -29,8 +28,9 @@ ActiveRecordDummy::Application.configure do
29
28
  # ActionMailer::Base.deliveries array.
30
29
  config.action_mailer.delivery_method = :test
31
30
 
32
- # Raise exception on mass assignment protection for Active Record models
33
- config.active_record.mass_assignment_sanitizer = :strict
31
+ config.eager_load = false
32
+
33
+ config.secret_key_base = 'helloworld123'
34
34
 
35
35
  # Print deprecation notices to the stderr
36
36
  config.active_support.deprecation = :stderr
@@ -2,6 +2,7 @@ require 'spec_helper'
2
2
 
3
3
  describe SharedEngine::PlainObjectsController, type: :controller do
4
4
  include ApiTestHelpers
5
+ routes { SharedEngine::Engine.routes }
5
6
 
6
7
  before(:each) do
7
8
  class SharedEngine::PlainObjectsController
@@ -12,7 +13,7 @@ describe SharedEngine::PlainObjectsController, type: :controller do
12
13
  describe 'get all users as a an array of plain objects, autodetecting the root node name' do
13
14
 
14
15
  before(:each) do
15
- get :index, :format => 'json', :api_template => :name_only
16
+ get :index, :format => 'json', params: { :api_template => :name_only }
16
17
  end
17
18
 
18
19
  it "should have a root node named users" do
@@ -5,6 +5,7 @@ require 'spec_helper'
5
5
  # end
6
6
 
7
7
  describe SharedEngine::RespondWithUsersController, type: :controller do
8
+ routes { SharedEngine::Engine.routes }
8
9
 
9
10
  before(:each) do
10
11
  setup_models
@@ -24,7 +25,7 @@ describe SharedEngine::RespondWithUsersController, type: :controller do
24
25
  context "creating valid models" do
25
26
 
26
27
  before(:each) do
27
- post :create, :user => { :first_name => "Luke", :last_name => "Skywalker" }, :api_template => :name_only, :format => 'json'
28
+ post :create, format: 'json', params: { user: { first_name: "Luke", last_name: "Skywalker" }, api_template: :name_only }
28
29
  end
29
30
 
30
31
  it "should return HTTP 201 status" do
@@ -45,7 +46,7 @@ describe SharedEngine::RespondWithUsersController, type: :controller do
45
46
  context "creating invalid models" do
46
47
 
47
48
  before(:each) do
48
- post :create, :user => {}, :api_template => :name_only, :format => 'json'
49
+ post :create, format: 'json', params: { user: { first_name: 'Luke' }, api_template: :name_only }
49
50
  end
50
51
 
51
52
  it "should return HTTP 422 status" do
@@ -53,16 +54,15 @@ describe SharedEngine::RespondWithUsersController, type: :controller do
53
54
  end
54
55
 
55
56
  it "should return errors as json" do
56
- response_body_json['errors']['first_name'].should include("can't be blank")
57
57
  response_body_json['errors']['last_name'].should include("can't be blank")
58
58
  end
59
59
 
60
60
  end
61
-
61
+
62
62
  context "returning all models without default root and no order" do
63
63
 
64
64
  before(:each) do
65
- get :index_no_root_no_order, :api_template => :name_only, :format => 'json'
65
+ get :index_no_root_no_order, format: 'json', params: { api_template: :name_only }
66
66
  end
67
67
 
68
68
  it "should return HTTP 200 status" do
@@ -85,7 +85,7 @@ describe SharedEngine::RespondWithUsersController, type: :controller do
85
85
  context "creating valid models" do
86
86
 
87
87
  before(:each) do
88
- post :create, :user => { :first_name => "Luke", :last_name => "Skywalker" }, :api_template => :name_only, :format => 'xml'
88
+ post :create, format: 'xml', params: { user: { first_name: "Luke", last_name: "Skywalker" }, api_template: :name_only }
89
89
  end
90
90
 
91
91
  it "should return HTTP 201 status" do
@@ -106,7 +106,7 @@ describe SharedEngine::RespondWithUsersController, type: :controller do
106
106
  context "creating invalid models" do
107
107
 
108
108
  before(:each) do
109
- post :create, :user => {}, :api_template => :name_only, :format => 'xml'
109
+ post :create, :format => 'xml', params: { user: { first_name: 'Luke' }, api_template: :name_only }
110
110
  end
111
111
 
112
112
  it "should return HTTP 422 status" do
@@ -122,7 +122,7 @@ describe SharedEngine::RespondWithUsersController, type: :controller do
122
122
  context "returning all models without default root and no order" do
123
123
 
124
124
  before(:each) do
125
- get :index_no_root_no_order, :api_template => :name_only, :format => 'xml'
125
+ get :index_no_root_no_order, format: 'xml', params: { api_template: :name_only }
126
126
  end
127
127
 
128
128
  it "should return HTTP 200 status" do
@@ -1,13 +1,13 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- gem 'rails', '3.2.22.2'
3
+ gem 'rails', '5.0.0.1'
4
4
 
5
5
  # Bundle edge Rails instead:
6
6
  # gem 'rails', :git => 'git://github.com/rails/rails.git'
7
7
 
8
8
 
9
9
  gem "bson_ext"
10
- gem "mongoid", ">= 3.0.0.rc"
10
+ gem 'mongoid', '>= 6.0.2'
11
11
 
12
12
  gem 'shared_engine', :path => '../shared_engine'
13
13
  gem 'acts_as_api', :path => '../../'
@@ -4,7 +4,6 @@ require File.expand_path('../boot', __FILE__)
4
4
  # require "active_record/railtie"
5
5
  require "action_controller/railtie"
6
6
  require "action_mailer/railtie"
7
- require "active_resource/railtie"
8
7
  require "sprockets/railtie"
9
8
  require "rails/test_unit/railtie"
10
9
 
@@ -50,12 +49,6 @@ module MongoidDummy
50
49
  # like if you have constraints or database-specific column types
51
50
  # config.active_record.schema_format = :sql
52
51
 
53
- # Enforce whitelist mode for mass assignment.
54
- # This will create an empty whitelist of attributes available for mass-assignment for all models
55
- # in your app. As such, your models will need to explicitly whitelist or blacklist accessible
56
- # parameters by using an attr_accessible or attr_protected declaration.
57
- # config.active_record.whitelist_attributes = true
58
-
59
52
  # Enable the asset pipeline
60
53
  config.assets.enabled = true
61
54
 
@@ -26,6 +26,10 @@ MongoidDummy::Application.configure do
26
26
  # Do not compress assets
27
27
  config.assets.compress = false
28
28
 
29
+ config.eager_load = false
30
+
31
+ config.secret_key_base = 'helloworld123'
32
+
29
33
  # Expands the lines which load the assets
30
34
  config.assets.debug = true
31
35
  end
@@ -9,7 +9,6 @@ MongoidDummy::Application.configure do
9
9
 
10
10
  # Configure static asset server for tests with Cache-Control for performance
11
11
  config.serve_static_assets = true
12
- config.static_cache_control = "public, max-age=3600"
13
12
 
14
13
  # Log error messages when you accidentally call methods on nil
15
14
  config.whiny_nils = true
@@ -29,6 +28,9 @@ MongoidDummy::Application.configure do
29
28
  # ActionMailer::Base.deliveries array.
30
29
  config.action_mailer.delivery_method = :test
31
30
 
31
+ config.eager_load = false
32
+
33
+ config.secret_key_base = 'helloworld123'
32
34
 
33
35
  # Print deprecation notices to the stderr
34
36
  config.active_support.deprecation = :stderr
@@ -1,120 +1,12 @@
1
1
  development:
2
- # Configure available database sessions. (required)
3
- sessions:
4
- # Defines the default session. (required)
2
+ clients:
5
3
  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)
4
+ database: mongoid
11
5
  hosts:
12
6
  - localhost:27017
13
- options:
14
- # Change whether the session persists in safe mode by default.
15
- # (default: false)
16
- # safe: false
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
61
7
  test:
62
- # Configure available database sessions. (required)
63
- sessions:
64
- # Defines the default session. (required)
8
+ clients:
65
9
  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)
10
+ database: mongoid
71
11
  hosts:
72
12
  - 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
@@ -1,6 +1,6 @@
1
1
  module SharedEngine
2
2
  class PlainObjectsController < SharedEngine::ApplicationController
3
- before_filter :setup_objects
3
+ before_action :setup_objects
4
4
 
5
5
  def index
6
6
  @users = [@han, @luke, @leia]
@@ -11,20 +11,20 @@ module SharedEngine
11
11
  end
12
12
 
13
13
  def index_no_root_no_order
14
- @users = User.all
14
+ @users = User.all.to_a
15
15
  respond_with @users, :api_template => params[:api_template].to_sym
16
16
  end
17
-
17
+
18
18
  def index_meta
19
- @users = User.all
19
+ @users = User.all.to_a
20
20
  meta_hash = { :page => 1, :total => 999 }
21
21
  respond_with @users, :api_template => params[:api_template].to_sym, :root => :users, :meta => meta_hash
22
22
  end
23
-
23
+
24
24
  def index_relation
25
25
  @users = User.limit(100).sort_by(&:first_name)
26
26
  respond_with @users, :api_template => params[:api_template].to_sym
27
- end
27
+ end
28
28
 
29
29
  def show
30
30
  @user = User.find(params[:id])
@@ -51,7 +51,7 @@ module SharedEngine
51
51
  end
52
52
 
53
53
  def create
54
- @user = User.new(params[:user])
54
+ @user = User.new(params[:user].permit!)
55
55
 
56
56
  if @user.save
57
57
  respond_with @user, :api_template => params[:api_template]
@@ -11,7 +11,7 @@ module SharedEngine
11
11
  end
12
12
 
13
13
  def index_meta
14
- @users = User.all
14
+ @users = User.all.to_a
15
15
  meta_hash = { :page => 1, :total => 999 }
16
16
 
17
17
  respond_to do |format|
@@ -19,14 +19,18 @@ module SharedEngine
19
19
  format.json { render_for_api params[:api_template].to_sym, :json => @users, :root => :users, :meta => meta_hash }
20
20
  end
21
21
  end
22
-
22
+
23
23
  def index_relation
24
- @users = User.limit(100).sort_by(&:first_name)
24
+ @users = if defined?(ActiveRecord::Base) && User < ActiveRecord::Base
25
+ User.where('id > 0').order('first_name ASC').all
26
+ else
27
+ User.limit(100).sort_by(&:first_name)
28
+ end
25
29
 
26
30
  respond_to do |format|
27
31
  format.xml { render_for_api params[:api_template].to_sym, :xml => @users }
28
32
  format.json { render_for_api params[:api_template].to_sym, :json => @users }
29
- end
33
+ end
30
34
  end
31
35
 
32
36
  def show
@@ -46,12 +46,6 @@ module Dummy
46
46
  # like if you have constraints or database-specific column types
47
47
  # config.active_record.schema_format = :sql
48
48
 
49
- # Enforce whitelist mode for mass assignment.
50
- # This will create an empty whitelist of attributes available for mass-assignment for all models
51
- # in your app. As such, your models will need to explicitly whitelist or blacklist accessible
52
- # parameters by using an attr_accessible or attr_protected declaration.
53
- config.active_record.whitelist_attributes = true
54
-
55
49
  # Enable the asset pipeline
56
50
  config.assets.enabled = true
57
51
 
@@ -22,16 +22,13 @@ Dummy::Application.configure do
22
22
  # Only use best-standards-support built into browsers
23
23
  config.action_dispatch.best_standards_support = :builtin
24
24
 
25
- # Raise exception on mass assignment protection for Active Record models
26
- config.active_record.mass_assignment_sanitizer = :strict
27
-
28
- # Log the query plan for queries taking more than this (works
29
- # with SQLite, MySQL, and PostgreSQL)
30
- config.active_record.auto_explain_threshold_in_seconds = 0.5
31
-
32
25
  # Do not compress assets
33
26
  config.assets.compress = false
34
27
 
28
+ config.eager_load = false
29
+
30
+ config.secret_key_base = 'helloworld123'
31
+
35
32
  # Expands the lines which load the assets
36
33
  config.assets.debug = true
37
34
  end
@@ -60,8 +60,4 @@ Dummy::Application.configure do
60
60
 
61
61
  # Send deprecation notices to registered listeners
62
62
  config.active_support.deprecation = :notify
63
-
64
- # Log the query plan for queries taking more than this (works
65
- # with SQLite, MySQL, and PostgreSQL)
66
- # config.active_record.auto_explain_threshold_in_seconds = 0.5
67
63
  end
@@ -9,7 +9,6 @@ Dummy::Application.configure do
9
9
 
10
10
  # Configure static asset server for tests with Cache-Control for performance
11
11
  config.serve_static_assets = true
12
- config.static_cache_control = "public, max-age=3600"
13
12
 
14
13
  # Log error messages when you accidentally call methods on nil
15
14
  config.whiny_nils = true
@@ -29,8 +28,9 @@ Dummy::Application.configure do
29
28
  # ActionMailer::Base.deliveries array.
30
29
  config.action_mailer.delivery_method = :test
31
30
 
32
- # Raise exception on mass assignment protection for Active Record models
33
- config.active_record.mass_assignment_sanitizer = :strict
31
+ config.eager_load = false
32
+
33
+ config.secret_key_base = 'helloworld123'
34
34
 
35
35
  # Print deprecation notices to the stderr
36
36
  config.active_support.deprecation = :stderr