active_decorator 1.3.1 → 1.3.2
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/.travis.yml +6 -0
- data/CHANGELOG.md +4 -0
- data/README.md +1 -1
- data/active_decorator.gemspec +0 -1
- data/gemfiles/Gemfile-rails.4.2.x +1 -0
- data/gemfiles/Gemfile-rails.5.0.x +1 -0
- data/gemfiles/Gemfile-rails.5.1.x +1 -0
- data/gemfiles/Gemfile-rails.5.2.x +3 -1
- data/gemfiles/Gemfile-rails.6.0.x +3 -1
- data/lib/active_decorator/monkey/action_controller/base/rescue_from.rb +2 -2
- data/lib/active_decorator/version.rb +1 -1
- data/test/fake_app/fake_app.rb +30 -2
- data/test/features/action_controller_api_test.rb +7 -2
- metadata +2 -18
- data/test/fake_app/app/views/api/bookstores/show.json.jbuilder +0 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3d00316b3198613b67dc2acc5cce77d11a47cf9910efd0a5e3d1eae040a466ed
|
4
|
+
data.tar.gz: 56034e7c1ad34d076d8829fb69d6b41db1e8ecf0be5c1d2de59d445d9f2200ad
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0c1e4341ac408a03d24a5ff0479d5127f175b4ffd42e3439441a3ce207e07ce8f54429b468c7b120bd2487562f8d76f70e0bab1928eadf311c082858c61e8c29
|
7
|
+
data.tar.gz: 2c480cf0308dd867d108a152629bcd29b03cd28c43b632a664847149e527e459c3fd13830151064acce473ce2e4ebe2dcb96897c8bd0672ca470416b4fdabcb8
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
## 1.3.2
|
2
|
+
|
3
|
+
* Fixed NameError on ActionController::API controllers without jbuilder enhancement [@kamillle]
|
4
|
+
|
1
5
|
## 1.3.1
|
2
6
|
|
3
7
|
* Switched back from Ruby's `const_get` to Active Support `constantize` for fetching decorator modules, due to inability to properly detect namespaced decorator [@sinsoku]
|
data/README.md
CHANGED
@@ -17,7 +17,7 @@ A simple and Rubyish view helper for Rails 4, Rails 5, and Rails 6. Keep your he
|
|
17
17
|
|
18
18
|
* Ruby 2.0.0, 2.1.x, 2.2.x, 2.3.x, 2.4.x, 2.5.x, 2.6.x, and 2.7 (trunk)
|
19
19
|
|
20
|
-
* Rails 4.2.x, 5.0, 5.1, 5.2, and 6.
|
20
|
+
* Rails 4.2.x, 5.0, 5.1, 5.2, 6.0, and 6.1 (edge)
|
21
21
|
|
22
22
|
|
23
23
|
## Supported ORMs ##
|
data/active_decorator.gemspec
CHANGED
@@ -7,10 +7,10 @@ module ActiveDecorator
|
|
7
7
|
module ActionController
|
8
8
|
module Base
|
9
9
|
def rescue_with_handler(*)
|
10
|
-
ActiveDecorator::ViewContext.push(view_context)
|
10
|
+
ActiveDecorator::ViewContext.push(view_context) if defined?(view_context)
|
11
11
|
super
|
12
12
|
ensure
|
13
|
-
ActiveDecorator::ViewContext.pop
|
13
|
+
ActiveDecorator::ViewContext.pop if defined?(view_context)
|
14
14
|
end
|
15
15
|
end
|
16
16
|
end
|
data/test/fake_app/fake_app.rb
CHANGED
@@ -7,7 +7,7 @@ require 'action_controller/railtie'
|
|
7
7
|
require 'action_mailer/railtie'
|
8
8
|
require 'action_view/railtie'
|
9
9
|
require 'ostruct'
|
10
|
-
require 'jbuilder'
|
10
|
+
require 'jbuilder' unless ENV['API']
|
11
11
|
|
12
12
|
# config
|
13
13
|
ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: ':memory:')
|
@@ -48,7 +48,11 @@ ActiveDecoratorTestApp::Application.routes.draw do
|
|
48
48
|
|
49
49
|
if Rails::VERSION::MAJOR >= 5
|
50
50
|
namespace :api do
|
51
|
-
resources :bookstores, only: :show
|
51
|
+
resources :bookstores, only: :show do
|
52
|
+
collection do
|
53
|
+
get :error
|
54
|
+
end
|
55
|
+
end
|
52
56
|
end
|
53
57
|
end
|
54
58
|
end
|
@@ -164,6 +168,15 @@ module CompanyDecorator
|
|
164
168
|
name.reverse
|
165
169
|
end
|
166
170
|
end
|
171
|
+
module BookstoreDecorator
|
172
|
+
def initial
|
173
|
+
name.first
|
174
|
+
end
|
175
|
+
|
176
|
+
def to_json
|
177
|
+
{name: name, initial: initial}
|
178
|
+
end
|
179
|
+
end
|
167
180
|
|
168
181
|
# decorator fake
|
169
182
|
class MovieDecorator; end
|
@@ -234,8 +247,23 @@ unless ENV['API']
|
|
234
247
|
else
|
235
248
|
module Api
|
236
249
|
class BookstoresController < ActionController::API
|
250
|
+
class CustomError < StandardError; end
|
251
|
+
|
252
|
+
rescue_from CustomError do
|
253
|
+
head :internal_server_error
|
254
|
+
end
|
255
|
+
|
237
256
|
def show
|
238
257
|
@bookstore = Bookstore.find params[:id]
|
258
|
+
render json: serialize('bookstore')
|
259
|
+
end
|
260
|
+
|
261
|
+
private def serialize(name)
|
262
|
+
view_assigns[name].to_json
|
263
|
+
end
|
264
|
+
|
265
|
+
def error
|
266
|
+
raise CustomError, 'boom!'
|
239
267
|
end
|
240
268
|
end
|
241
269
|
end
|
@@ -1,5 +1,4 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
|
3
2
|
require 'test_helper'
|
4
3
|
|
5
4
|
if Rails::VERSION::MAJOR >= 5
|
@@ -12,7 +11,13 @@ class ActionControllerAPITest < ActionDispatch::IntegrationTest
|
|
12
11
|
test 'decorating objects in api only controllers' do
|
13
12
|
get "/api/bookstores/#{Bookstore.last.id}.json"
|
14
13
|
|
15
|
-
assert_equal({"name" => "junkudo"}, response.parsed_body)
|
14
|
+
assert_equal({"initial" => "j", "name" => "junkudo"}, response.parsed_body)
|
15
|
+
end
|
16
|
+
|
17
|
+
test 'error handling in api only controllers' do
|
18
|
+
get "/api/bookstores/error.json"
|
19
|
+
|
20
|
+
assert_response :error
|
16
21
|
end
|
17
22
|
end
|
18
23
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_decorator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.3.
|
4
|
+
version: 1.3.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Akira Matsuda
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-01-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -108,20 +108,6 @@ dependencies:
|
|
108
108
|
- - ">="
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '0'
|
111
|
-
- !ruby/object:Gem::Dependency
|
112
|
-
name: jbuilder
|
113
|
-
requirement: !ruby/object:Gem::Requirement
|
114
|
-
requirements:
|
115
|
-
- - ">="
|
116
|
-
- !ruby/object:Gem::Version
|
117
|
-
version: '0'
|
118
|
-
type: :development
|
119
|
-
prerelease: false
|
120
|
-
version_requirements: !ruby/object:Gem::Requirement
|
121
|
-
requirements:
|
122
|
-
- - ">="
|
123
|
-
- !ruby/object:Gem::Version
|
124
|
-
version: '0'
|
125
111
|
- !ruby/object:Gem::Dependency
|
126
112
|
name: byebug
|
127
113
|
requirement: !ruby/object:Gem::Requirement
|
@@ -180,7 +166,6 @@ files:
|
|
180
166
|
- test/controllers/fake_detection_test.rb
|
181
167
|
- test/decorator_test.rb
|
182
168
|
- test/fake_app/app/decorators/comic_decorator.rb
|
183
|
-
- test/fake_app/app/views/api/bookstores/show.json.jbuilder
|
184
169
|
- test/fake_app/app/views/authors/index.html.erb
|
185
170
|
- test/fake_app/app/views/authors/show.html.erb
|
186
171
|
- test/fake_app/app/views/authors/show.json.jbuilder
|
@@ -234,7 +219,6 @@ test_files:
|
|
234
219
|
- test/controllers/fake_detection_test.rb
|
235
220
|
- test/decorator_test.rb
|
236
221
|
- test/fake_app/app/decorators/comic_decorator.rb
|
237
|
-
- test/fake_app/app/views/api/bookstores/show.json.jbuilder
|
238
222
|
- test/fake_app/app/views/authors/index.html.erb
|
239
223
|
- test/fake_app/app/views/authors/show.html.erb
|
240
224
|
- test/fake_app/app/views/authors/show.json.jbuilder
|
@@ -1 +0,0 @@
|
|
1
|
-
json.name @bookstore.name
|