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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9312dab89b8f57877eac8447beff11151b7399640c9a457aa51d9251a0779792
4
- data.tar.gz: d09cceaf7f064a6536d983fdb577bdbca11aba51046faaee021887ca112b1bed
3
+ metadata.gz: 3d00316b3198613b67dc2acc5cce77d11a47cf9910efd0a5e3d1eae040a466ed
4
+ data.tar.gz: 56034e7c1ad34d076d8829fb69d6b41db1e8ecf0be5c1d2de59d445d9f2200ad
5
5
  SHA512:
6
- metadata.gz: f1d98fea1b67c618239dc865b913a8f1ccf32097ca19b7e2adc2679bb3668ce57a981ddcc5940aa3b5388d85ac7fe01eb4cd51bd8005944253016112d53e5c1c
7
- data.tar.gz: 9314835959902259af91f0909abd3b299dc7b7a30730323b235e51a231d8d9ce644145c457cfeae526b18a600dbf3561dcbf9072219ad17a9d980a1ec3c0595a
6
+ metadata.gz: 0c1e4341ac408a03d24a5ff0479d5127f175b4ffd42e3439441a3ce207e07ce8f54429b468c7b120bd2487562f8d76f70e0bab1928eadf311c082858c61e8c29
7
+ data.tar.gz: 2c480cf0308dd867d108a152629bcd29b03cd28c43b632a664847149e527e459c3fd13830151064acce473ce2e4ebe2dcb96897c8bd0672ca470416b4fdabcb8
@@ -26,6 +26,12 @@ cache: bundler
26
26
 
27
27
  matrix:
28
28
  include:
29
+ - rvm: 2.7.0
30
+ gemfile: gemfiles/Gemfile-rails.6.0.x
31
+ - rvm: 2.7.0
32
+ gemfile: gemfiles/Gemfile-rails.6.0.x
33
+ env: API=1
34
+
29
35
  - rvm: 2.6.3
30
36
  gemfile: gemfiles/Gemfile-rails.6.0.x
31
37
  - rvm: 2.6.3
@@ -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.0 (edge)
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 ##
@@ -26,6 +26,5 @@ Gem::Specification.new do |s|
26
26
  s.add_development_dependency 'capybara'
27
27
  s.add_development_dependency 'sqlite3'
28
28
  s.add_development_dependency 'rake'
29
- s.add_development_dependency 'jbuilder'
30
29
  s.add_development_dependency 'byebug'
31
30
  end
@@ -5,3 +5,4 @@ gemspec path: '..'
5
5
  gem 'rails', '~> 4.2.0'
6
6
  gem 'sqlite3', '< 1.4'
7
7
  gem 'nokogiri', '~> 1.6.0'
8
+ gem 'jbuilder' unless ENV['API']
@@ -4,3 +4,4 @@ gemspec path: '..'
4
4
 
5
5
  gem 'rails', '~> 5.0.0'
6
6
  gem 'sqlite3', '< 1.4'
7
+ gem 'jbuilder' unless ENV['API']
@@ -3,3 +3,4 @@ source 'https://rubygems.org'
3
3
  gemspec path: '..'
4
4
 
5
5
  gem 'rails', '~> 5.1.0'
6
+ gem 'jbuilder' unless ENV['API']
@@ -2,4 +2,6 @@ source 'https://rubygems.org'
2
2
 
3
3
  gemspec path: '..'
4
4
 
5
- gem 'rails', '~> 5.2.0'
5
+ gem 'rails', git: 'https://github.com/rails/rails', branch: '5-2-stable'
6
+ gem 'webdrivers', '< 4'
7
+ gem 'jbuilder' unless ENV['API']
@@ -2,4 +2,6 @@ source 'https://rubygems.org'
2
2
 
3
3
  gemspec path: '..'
4
4
 
5
- gem 'rails', '~> 6.0.0.rc2'
5
+ gem 'rails', '~> 6.0.0'
6
+ gem 'webdrivers'
7
+ gem 'jbuilder' unless ENV['API']
@@ -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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ActiveDecorator
4
- VERSION = '1.3.1'
4
+ VERSION = '1.3.2'
5
5
  end
@@ -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.1
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: 2019-08-16 00:00:00.000000000 Z
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