rails-api 0.4.0 → 0.4.1
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/README.md +2 -2
- data/lib/rails-api/action_controller/api.rb +1 -1
- data/lib/rails-api/application.rb +4 -5
- data/lib/rails-api/application/default_rails_four_middleware_stack.rb +3 -3
- data/lib/rails-api/public_exceptions.rb +1 -1
- data/lib/rails-api/templates/rails/scaffold_controller/controller.rb +3 -5
- data/lib/rails-api/version.rb +1 -1
- data/test/generators/scaffold_generator_test.rb +15 -9
- data/test/test_helper.rb +9 -3
- metadata +13 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5cc9bcfa99369202e15a7879a3be4e3cf6ff6ff9
|
4
|
+
data.tar.gz: 322b8241f6fcddbcd94cc19ebd8a5a4b3268e78d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f69c577fa8149f56ea9392ec6664f1558db53430d8a3402c73462c1177b4bd2fe99f01683c1c78258086fd0fb5d3859f722a5d14b77622c1f756694b722427e9
|
7
|
+
data.tar.gz: d1ea77ffcd0d0851ac87480fb490a3c23bba853734da5325c2d8dcb1e984788f3ab0188fa6b96ce7b15cce00877d0a3fed66a79eb7bece3b84b36ab94eb23882
|
data/README.md
CHANGED
@@ -2,6 +2,8 @@
|
|
2
2
|
|
3
3
|
[](http://travis-ci.org/rails-api/rails-api)
|
4
4
|
|
5
|
+
**IMPORTANT**: [Rails::API has been merged into Rails](https://github.com/rails/rails/pull/19832)
|
6
|
+
|
5
7
|
**Rails::API** is a subset of a normal Rails application, created for applications that don't require all functionality that a complete Rails application provides. It is a bit more lightweight, and consequently a bit faster than a normal Rails application. The main example for its usage is in API applications only, where you usually don't need the entire Rails middleware stack nor template generation.
|
6
8
|
|
7
9
|
## Using Rails for API-only Apps
|
@@ -138,7 +140,6 @@ If you want to use the Rails default middleware stack (avoid the reduction that
|
|
138
140
|
### Serialization
|
139
141
|
|
140
142
|
We suggest using [ActiveModel::Serializers][ams] to serialize your ActiveModel/ActiveRecord objects into the desired response format (e.g. JSON).
|
141
|
-
In `ApplicationController` you need to add `include ActionController::Serialization` to make ActiveModelSerializers work.
|
142
143
|
|
143
144
|
|
144
145
|
|
@@ -159,7 +160,6 @@ An API application comes with the following middlewares by default.
|
|
159
160
|
* *Rack::Lock*: If your application is not marked as threadsafe (`config.threadsafe!`), this middleware will add a mutex around your requests.
|
160
161
|
* *Rack::Runtime*: Adds a header to the response listing the total runtime of the request.
|
161
162
|
* *Rack::Sendfile*: Uses a front-end server's file serving support from your Rails application.
|
162
|
-
* *Rack::Head*: Dispatch *HEAD* requests as *GET* requests, and return only the status code and headers.
|
163
163
|
* *Rails::Rack::Logger*: Log the request started and flush all loggers after it.
|
164
164
|
|
165
165
|
Other plugins, including *ActiveRecord*, may add additional middlewares. In general, these middlewares are agnostic to the type of app you are building, and make sense in an API-only Rails application.
|
@@ -143,7 +143,7 @@ module ActionController
|
|
143
143
|
# Add instrumentations hooks at the bottom, to ensure they instrument
|
144
144
|
# all the methods properly.
|
145
145
|
Instrumentation
|
146
|
-
]
|
146
|
+
].freeze
|
147
147
|
|
148
148
|
if Rails::VERSION::MAJOR == 5 || (Rails::VERSION::MAJOR == 4 && Rails::VERSION::MINOR > 0)
|
149
149
|
include AbstractController::Rendering
|
@@ -14,8 +14,6 @@ module Rails
|
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
|
-
private
|
18
|
-
|
19
17
|
def setup_generators!
|
20
18
|
generators = config.generators
|
21
19
|
|
@@ -37,7 +35,9 @@ module Rails
|
|
37
35
|
config.api_only = true
|
38
36
|
setup_generators!
|
39
37
|
end
|
40
|
-
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
41
|
def check_serve_static_files
|
42
42
|
if Rails::VERSION::MAJOR >= 5 || (Rails::VERSION::MAJOR == 4 && Rails::VERSION::MINOR > 1)
|
43
43
|
config.serve_static_files
|
@@ -61,12 +61,11 @@ module Rails
|
|
61
61
|
if config.action_dispatch.x_sendfile_header.present?
|
62
62
|
middleware.use ::Rack::Sendfile, config.action_dispatch.x_sendfile_header
|
63
63
|
end
|
64
|
-
|
65
64
|
|
66
65
|
if check_serve_static_files
|
67
66
|
middleware.use ::ActionDispatch::Static, paths["public"].first, config.static_cache_control
|
68
67
|
end
|
69
|
-
|
68
|
+
|
70
69
|
middleware.use ::Rack::Lock unless config.allow_concurrency
|
71
70
|
middleware.use ::Rack::Runtime
|
72
71
|
middleware.use ::Rack::MethodOverride unless config.api_only
|
@@ -22,7 +22,7 @@ module Rails
|
|
22
22
|
def render(status, content_type, body)
|
23
23
|
format = content_type && "to_#{content_type.to_sym}"
|
24
24
|
if format && body.respond_to?(format)
|
25
|
-
render_format(status, content_type, body.
|
25
|
+
render_format(status, content_type, body.send(format))
|
26
26
|
else
|
27
27
|
render_html(status)
|
28
28
|
end
|
@@ -31,8 +31,6 @@ class <%= controller_class_name %>Controller < ApplicationController
|
|
31
31
|
# PATCH/PUT <%= route_url %>/1
|
32
32
|
# PATCH/PUT <%= route_url %>/1.json
|
33
33
|
def update
|
34
|
-
@<%= singular_table_name %> = <%= orm_class.find(class_name, "params[:id]") %>
|
35
|
-
|
36
34
|
if @<%= Rails::API.rails3? ? orm_instance.update_attributes("params[:#{singular_table_name}]") : orm_instance.update("#{singular_table_name}_params") %>
|
37
35
|
head :no_content
|
38
36
|
else
|
@@ -55,10 +53,10 @@ class <%= controller_class_name %>Controller < ApplicationController
|
|
55
53
|
end
|
56
54
|
|
57
55
|
def <%= "#{singular_table_name}_params" %>
|
58
|
-
<%- if attributes_names
|
59
|
-
params[:<%= singular_table_name %>]
|
60
|
-
<%- else -%>
|
56
|
+
<%- if defined?(attributes_names) -%>
|
61
57
|
params.require(:<%= singular_table_name %>).permit(<%= attributes_names.map { |name| ":#{name}" }.join(', ') %>)
|
58
|
+
<%- else -%>
|
59
|
+
params[:<%= singular_table_name %>]
|
62
60
|
<%- end -%>
|
63
61
|
end
|
64
62
|
end
|
data/lib/rails-api/version.rb
CHANGED
@@ -56,9 +56,8 @@ class ScaffoldGeneratorTest < Rails::Generators::TestCase
|
|
56
56
|
end
|
57
57
|
|
58
58
|
assert_instance_method :update, content do |m|
|
59
|
-
assert_match(/@product_line = ProductLine\.find\(params\[:id\]\)/, m)
|
60
59
|
if rails3?
|
61
|
-
assert_match(/@product_line\.update_attributes\(
|
60
|
+
assert_match(/@product_line\.update_attributes\(params\[:product_line\]\)/, m)
|
62
61
|
else
|
63
62
|
assert_match(/@product_line\.update\(product_line_params\)/, m)
|
64
63
|
end
|
@@ -69,20 +68,27 @@ class ScaffoldGeneratorTest < Rails::Generators::TestCase
|
|
69
68
|
assert_match(/@product_line\.destroy/, m)
|
70
69
|
end
|
71
70
|
|
72
|
-
|
73
|
-
|
74
|
-
|
71
|
+
unless rails3?
|
72
|
+
assert_instance_method :set_product_line, content do |m|
|
73
|
+
assert_match(/@product_line = ProductLine\.find\(params\[:id\]\)/, m)
|
74
|
+
end
|
75
75
|
|
76
|
-
|
77
|
-
|
76
|
+
assert_instance_method :product_line_params, content do |m|
|
77
|
+
assert_match(/params\.require\(:product_line\)\.permit\(:title, :product_id, :user_id\)/, m)
|
78
|
+
end
|
78
79
|
end
|
79
80
|
end
|
80
81
|
|
81
82
|
assert_file "test/#{generated_test_functional_dir}/product_lines_controller_test.rb" do |test|
|
82
83
|
assert_match(/class ProductLinesControllerTest < ActionController::TestCase/, test)
|
83
84
|
if rails3?
|
84
|
-
|
85
|
-
|
85
|
+
if RUBY_VERSION < "1.9"
|
86
|
+
assert_match(/post :create, product_line: \{ :title => @product_line.title \}/, test)
|
87
|
+
assert_match(/put :update, id: @product_line, product_line: \{ :title => @product_line.title \}/, test)
|
88
|
+
else
|
89
|
+
assert_match(/post :create, product_line: \{ title: @product_line.title \}/, test)
|
90
|
+
assert_match(/put :update, id: @product_line, product_line: \{ title: @product_line.title \}/, test)
|
91
|
+
end
|
86
92
|
else
|
87
93
|
assert_match(/post :create, product_line: \{ product_id: @product_line.product_id, title: @product_line.title, user_id: @product_line.user_id \}/, test)
|
88
94
|
assert_match(/put :update, id: @product_line, product_line: \{ product_id: @product_line.product_id, title: @product_line.title, user_id: @product_line.user_id \}/, test)
|
data/test/test_helper.rb
CHANGED
@@ -13,7 +13,16 @@ end
|
|
13
13
|
class ActiveSupport::TestCase
|
14
14
|
def self.app
|
15
15
|
@@app ||= Class.new(Rails::Application) do
|
16
|
+
def self.name
|
17
|
+
'TestApp'
|
18
|
+
end
|
19
|
+
end.tap do |app|
|
20
|
+
config = app.config
|
21
|
+
|
16
22
|
config.active_support.deprecation = :stderr
|
23
|
+
|
24
|
+
config.active_support.test_order = :random
|
25
|
+
|
17
26
|
config.generators do |c|
|
18
27
|
c.orm :active_record, :migration => true,
|
19
28
|
:timestamps => true
|
@@ -30,9 +39,6 @@ class ActiveSupport::TestCase
|
|
30
39
|
config.secret_key_base = 'abc123'
|
31
40
|
end
|
32
41
|
|
33
|
-
def self.name
|
34
|
-
'TestApp'
|
35
|
-
end
|
36
42
|
end
|
37
43
|
end
|
38
44
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails-api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Santiago Pastorino and Carlos Antonio da Silva
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-03-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: actionpack
|
@@ -116,22 +116,22 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
116
116
|
version: 1.3.6
|
117
117
|
requirements: []
|
118
118
|
rubyforge_project:
|
119
|
-
rubygems_version: 2.
|
119
|
+
rubygems_version: 2.6.8
|
120
120
|
signing_key:
|
121
121
|
specification_version: 4
|
122
122
|
summary: Rails for API only Applications
|
123
123
|
test_files:
|
124
|
-
- test/test_helper.rb
|
125
124
|
- test/api_application/api_application_test.rb
|
126
|
-
- test/
|
127
|
-
- test/
|
128
|
-
- test/generators/scaffold_generator_test.rb
|
129
|
-
- test/generators/fixtures/routes.rb
|
130
|
-
- test/generators/app_generator_test.rb
|
131
|
-
- test/api_controller/url_for_test.rb
|
132
|
-
- test/api_controller/force_ssl_test.rb
|
125
|
+
- test/api_controller/action_methods_test.rb
|
126
|
+
- test/api_controller/conditional_get_test.rb
|
133
127
|
- test/api_controller/data_streaming_test.rb
|
128
|
+
- test/api_controller/force_ssl_test.rb
|
134
129
|
- test/api_controller/redirect_to_test.rb
|
135
|
-
- test/api_controller/conditional_get_test.rb
|
136
130
|
- test/api_controller/renderers_test.rb
|
137
|
-
- test/api_controller/
|
131
|
+
- test/api_controller/url_for_test.rb
|
132
|
+
- test/generators/app_generator_test.rb
|
133
|
+
- test/generators/fixtures/routes.rb
|
134
|
+
- test/generators/generators_test_helper.rb
|
135
|
+
- test/generators/resource_generator_test.rb
|
136
|
+
- test/generators/scaffold_generator_test.rb
|
137
|
+
- test/test_helper.rb
|