rails-api 0.4.0 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 77d3d89e4ce4fa7f0c861dc9cedb98d69a5b43f6
4
- data.tar.gz: ea09b246ac549fce29ba5968fbf2bca3a82b5327
3
+ metadata.gz: 5cc9bcfa99369202e15a7879a3be4e3cf6ff6ff9
4
+ data.tar.gz: 322b8241f6fcddbcd94cc19ebd8a5a4b3268e78d
5
5
  SHA512:
6
- metadata.gz: e1247598f6072111eba2674bdc23df065dca70b3bf1031c7e7ea640bf568c64464df55c1cd57652369d4e8cf73bf28b0103fb7dd11a611889ad63c03af1f7063
7
- data.tar.gz: 3973dee3bcd9b1f1456af5fac6c1eacb328789c9deab2a14b96a45b3e7289db17f1a081f2732a0458066b10d53748d5ca35c21a366ab8c3c810d7be04165fdd2
6
+ metadata.gz: f69c577fa8149f56ea9392ec6664f1558db53430d8a3402c73462c1177b4bd2fe99f01683c1c78258086fd0fb5d3859f722a5d14b77622c1f756694b722427e9
7
+ data.tar.gz: d1ea77ffcd0d0851ac87480fb490a3c23bba853734da5325c2d8dcb1e984788f3ab0188fa6b96ce7b15cce00877d0a3fed66a79eb7bece3b84b36ab94eb23882
data/README.md CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  [![Build Status](https://secure.travis-ci.org/rails-api/rails-api.png?branch=master)](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
@@ -95,9 +95,9 @@ module Rails
95
95
 
96
96
  if rack_cache == true
97
97
  {
98
- metastore: "rails:/",
99
- entitystore: "rails:/",
100
- verbose: false
98
+ :metastore => "rails:/",
99
+ :entitystore => "rails:/",
100
+ :verbose => false
101
101
  }
102
102
  else
103
103
  rack_cache
@@ -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.public_send(format))
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.empty? -%>
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
@@ -1,5 +1,5 @@
1
1
  module Rails
2
2
  module API
3
- VERSION = '0.4.0'
3
+ VERSION = '0.4.1'
4
4
  end
5
5
  end
@@ -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\(product_line_params\)/, m)
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
- assert_instance_method :set_product_line, content do |m|
73
- assert_match(/@product_line = ProductLine\.find\(params\[:id\]\)/, m)
74
- end
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
- assert_instance_method :product_line_params, content do |m|
77
- assert_match(/params\.require\(:product_line\)\.permit\(:title, :product_id, :user_id\)/, m)
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
- assert_match(/post :create, product_line: \{ title: @product_line.title \}/, test)
85
- assert_match(/put :update, id: @product_line, product_line: \{ title: @product_line.title \}/, test)
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)
@@ -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.0
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: 2015-01-22 00:00:00.000000000 Z
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.2.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/generators/resource_generator_test.rb
127
- - test/generators/generators_test_helper.rb
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/action_methods_test.rb
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