active_decorator 1.1.0 → 1.1.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
  SHA256:
3
- metadata.gz: 298a6372406ac3480e7baaeee85eeea4b3dcb393ed37e6ccf4ab0fe120b5d7ed
4
- data.tar.gz: 9576044dd3bf36591e9a56190b37f88062f58bc6f325c4e6a7b0446b5d8d05f5
3
+ metadata.gz: 95d46d933899535231f0e24953747370ac289afed99ac881dd91a1bafca06d00
4
+ data.tar.gz: '08989f206e82987244927a07c17f147f59f25c268bb61b59763dbed7cf11aa06'
5
5
  SHA512:
6
- metadata.gz: ac2c57c9ace629b66a38fa039d622dd4c6f345334ec7bfee10e8e64dbe6efd43f78adc378fd2aff5e9ba52ecd73e963a21ec9817f776718035db250f13365567
7
- data.tar.gz: acaf0a2612909a35e9d095ec6ad8e80b9cc5240df40accec3fc8e337e192714c8fda649d02f98b6ed92a41ac9c0a33702f2d8bc64b2e61071a7f71762d9e2988
6
+ metadata.gz: e89c4cc6d373b308858919ebf119c18bc3547e09d0f0dda9d1c52643a844eb50696aac9f5e0372f7c274acbe5d3f34db5b66ad02db62cd3a0808f7c3b566436b
7
+ data.tar.gz: d62771d0c66da65522e8a3b05ba03a5bce188da0c6bad782bac5d8b7d53827ca5471fbd756e7533b7b4701b4539f0a038098c0be37dac514b688c32821b1cd93
@@ -78,5 +78,17 @@ matrix:
78
78
  include:
79
79
  - rvm: ruby-head
80
80
  gemfile: gemfiles/Gemfile-rails.edge
81
+ - rvm: 2.5.3
82
+ gemfile: gemfiles/Gemfile-rails.5.2.x
83
+ env: API=1
84
+ - rvm: 2.5.3
85
+ gemfile: gemfiles/Gemfile-rails.5.1.x
86
+ env: API=1
87
+ - rvm: 2.5.3
88
+ gemfile: gemfiles/Gemfile-rails.5.0.x
89
+ env: API=1
90
+ - rvm: ruby-head
91
+ gemfile: gemfiles/Gemfile-rails.edge
92
+ env: API=1
81
93
  allow_failures:
82
94
  - rvm: ruby-head
@@ -1,3 +1,10 @@
1
+ ## 1.1.1
2
+
3
+ * Improved ActionController::API support for Rails 5.0.x [@frodsan]
4
+
5
+ * Fixed "NameError: undefined local variable or method `view_context'" with ActionController::API or when rendering in controllers
6
+
7
+
1
8
  ## 1.1.0
2
9
 
3
10
  * ActionController::API support [@frodsan]
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # ActiveDecorator [![Build Status](https://travis-ci.org/amatsuda/active_decorator.svg?branch=master)](https://travis-ci.org/amatsuda/active_decorator) [![Code Climate](https://codeclimate.com/github/amatsuda/active_decorator/badges/gpa.svg)](https://codeclimate.com/github/amatsuda/active_decorator)
2
2
 
3
- A simple and Rubyish view helper for Rails 3, Rails 4 and Rails 5. Keep your helpers and views Object-Oriented!
3
+ A simple and Rubyish view helper for Rails 3, Rails 4, Rails 5, and Rails 6. Keep your helpers and views Object-Oriented!
4
4
 
5
5
 
6
6
  ## Features ##
@@ -15,9 +15,9 @@ A simple and Rubyish view helper for Rails 3, Rails 4 and Rails 5. Keep your hel
15
15
 
16
16
  ## Supported versions ##
17
17
 
18
- * Ruby 2.0.0, 2.1.x, 2.2.x, 2.3.x, 2.4.x, and 2.5 (trunk)
18
+ * Ruby 2.0.0, 2.1.x, 2.2.x, 2.3.x, 2.4.x, and 2.5, and 2.6 (trunk)
19
19
 
20
- * Rails 3.2.x, 4.0.x, 4.1.x, 4.2.x, 5.0, 5.1, and 5.2 (edge)
20
+ * Rails 3.2.x, 4.0.x, 4.1.x, 4.2.x, 5.0, 5.1, 5.2, and 6.0 (edge)
21
21
 
22
22
 
23
23
  ## Supported ORMs ##
data/Rakefile CHANGED
@@ -8,7 +8,11 @@ require 'rake/testtask'
8
8
 
9
9
  Rake::TestTask.new do |t|
10
10
  t.libs << "test"
11
- t.pattern = 'test/**/*_test.rb'
11
+ if ENV['API']
12
+ t.pattern = 'test/**/*_api_test.rb'
13
+ else
14
+ t.test_files = Dir['test/**/*_test.rb'] - Dir['test/**/*_api_test.rb']
15
+ end
12
16
  t.warning = true
13
17
  t.verbose = true
14
18
  end
@@ -5,20 +5,24 @@ module ActiveDecorator
5
5
  module Helpers
6
6
  def method_missing(method, *args, &block)
7
7
  super
8
- rescue NoMethodError, NameError => e
8
+ rescue NoMethodError, NameError => e1
9
9
  # the error is not mine, so just releases it as is.
10
- raise e if e.name != method
10
+ raise e1 if e1.name != method
11
11
 
12
- begin
13
- (view_context = ActiveDecorator::ViewContext.current).send method, *args, &block
14
- rescue NoMethodError => e
15
- raise e if e.name != method
12
+ if (view_context = ActiveDecorator::ViewContext.current)
13
+ begin
14
+ view_context.send method, *args, &block
15
+ rescue NoMethodError => e2
16
+ raise e2 if e2.name != method
16
17
 
17
- raise NoMethodError.new("undefined method `#{method}' for either #{self} or #{view_context}", method)
18
- rescue NameError => e
19
- raise e if e.name != method
18
+ raise NoMethodError.new("undefined method `#{method}' for either #{self} or #{view_context}", method)
19
+ rescue NameError => e2
20
+ raise e2 if e2.name != method
20
21
 
21
- raise NameError.new("undefined local variable `#{method}' for either #{self} or #{view_context}", method)
22
+ raise NameError.new("undefined local variable `#{method}' for either #{self} or #{view_context}", method)
23
+ end
24
+ else # AC::API would have not view_context
25
+ raise e1
22
26
  end
23
27
  end
24
28
  end
@@ -22,14 +22,14 @@ module ActiveDecorator
22
22
  end
23
23
 
24
24
  if Rails::VERSION::MAJOR >= 5
25
- ActiveSupport.on_load :action_controller_api do
26
- require 'active_decorator/monkey/abstract_controller/rendering'
27
- ::ActionController::API.send :prepend, ActiveDecorator::Monkey::AbstractController::Rendering
28
-
29
- require 'active_decorator/monkey/action_controller/base/rescue_from'
30
- ::ActionController::API.send :prepend, ActiveDecorator::Monkey::ActionController::Base
31
-
32
- ::ActionController::API.send :include, ActiveDecorator::ViewContext::Filter
25
+ ActiveSupport.on_load :action_controller do
26
+ if self == ActionController::API
27
+ require 'active_decorator/monkey/abstract_controller/rendering'
28
+ ::ActionController::API.send :prepend, ActiveDecorator::Monkey::AbstractController::Rendering
29
+
30
+ require 'active_decorator/monkey/action_controller/base/rescue_from'
31
+ ::ActionController::API.send :prepend, ActiveDecorator::Monkey::ActionController::Base
32
+ end
33
33
  end
34
34
  end
35
35
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ActiveDecorator
4
- VERSION = '1.1.0'
4
+ VERSION = '1.1.1'
5
5
  end
@@ -1,2 +1 @@
1
- # frozen_string_literal: true
2
1
  json.name @bookstore.name
@@ -1,3 +1,2 @@
1
- # frozen_string_literal: true
2
1
  json.name @author.name
3
2
  json.books @author.books, partial: 'books/book', as: :book
@@ -1,3 +1,2 @@
1
- # frozen_string_literal: true
2
1
  json.title book.title
3
2
  json.reverse_title book.reverse_title
@@ -167,79 +167,80 @@ end
167
167
  class MovieDecorator; end
168
168
 
169
169
  # controllers
170
- class ApplicationController < ActionController::Base
171
- self.append_view_path File.dirname(__FILE__)
172
- end
173
- class AuthorsController < ApplicationController
174
- def index
175
- if Author.respond_to?(:scoped)
176
- # ActiveRecord 3.x
177
- if params[:variable_type] == 'array'
178
- @authors = Author.all
179
- elsif params[:variable_type] == 'proxy'
180
- @authors = RelationProxy.new(Author.scoped)
181
- else
182
- @authors = Author.scoped
183
- end
184
- else
185
- # ActiveRecord 4.x
186
- if params[:variable_type] == 'array'
187
- @authors = Author.all.to_a
188
- elsif params[:variable_type] == 'proxy'
189
- @authors = RelationProxy.new(Author.all)
170
+ unless ENV['API']
171
+ class ApplicationController < ActionController::Base
172
+ self.append_view_path File.dirname(__FILE__)
173
+ end
174
+ class AuthorsController < ApplicationController
175
+ def index
176
+ if Author.respond_to?(:scoped)
177
+ # ActiveRecord 3.x
178
+ if params[:variable_type] == 'array'
179
+ @authors = Author.all
180
+ elsif params[:variable_type] == 'proxy'
181
+ @authors = RelationProxy.new(Author.scoped)
182
+ else
183
+ @authors = Author.scoped
184
+ end
190
185
  else
191
- @authors = Author.all
186
+ # ActiveRecord 4.x
187
+ if params[:variable_type] == 'array'
188
+ @authors = Author.all.to_a
189
+ elsif params[:variable_type] == 'proxy'
190
+ @authors = RelationProxy.new(Author.all)
191
+ else
192
+ @authors = Author.all
193
+ end
192
194
  end
193
195
  end
194
- end
195
196
 
196
- def show
197
- @author = Author.find params[:id]
197
+ def show
198
+ @author = Author.find params[:id]
199
+ end
198
200
  end
199
- end
200
- class BooksController < ApplicationController
201
- class CustomError < StandardError; end
201
+ class BooksController < ApplicationController
202
+ class CustomError < StandardError; end
202
203
 
203
- rescue_from CustomError do
204
- render :error
205
- end
204
+ rescue_from CustomError do
205
+ render :error
206
+ end
206
207
 
207
- def index
208
- @author = Author.find params[:author_id]
209
- @books = @author.books
210
- end
208
+ def index
209
+ @author = Author.find params[:author_id]
210
+ @books = @author.books
211
+ end
211
212
 
212
- def show
213
- @book = Author.find(params[:author_id]).books.find(params[:id])
214
- end
213
+ def show
214
+ @book = Author.find(params[:author_id]).books.find(params[:id])
215
+ end
215
216
 
216
- def errata
217
- @book = Author.find(params[:author_id]).books.find(params[:id])
218
- end
217
+ def errata
218
+ @book = Author.find(params[:author_id]).books.find(params[:id])
219
+ end
219
220
 
220
- def errata2
221
- @book = Author.find(params[:author_id]).books.find(params[:id])
222
- end
221
+ def errata2
222
+ @book = Author.find(params[:author_id]).books.find(params[:id])
223
+ end
223
224
 
224
- def error
225
- @book = Author.find(params[:author_id]).books.find(params[:id])
226
- raise CustomError, "error"
227
- end
225
+ def error
226
+ @book = Author.find(params[:author_id]).books.find(params[:id])
227
+ raise CustomError, "error"
228
+ end
228
229
 
229
- def purchase
230
- @book = Author.find(params[:author_id]).books.find(params[:id])
230
+ def purchase
231
+ @book = Author.find(params[:author_id]).books.find(params[:id])
231
232
 
232
- @view_context_before_sending_mail = ActiveDecorator::ViewContext.current
233
- BookMailer.thanks(@book).deliver
234
- raise 'Wrong ViewContext!' if ActiveDecorator::ViewContext.current != @view_context_before_sending_mail
233
+ @view_context_before_sending_mail = ActiveDecorator::ViewContext.current
234
+ BookMailer.thanks(@book).deliver
235
+ raise 'Wrong ViewContext!' if ActiveDecorator::ViewContext.current != @view_context_before_sending_mail
236
+ end
235
237
  end
236
- end
237
- class MoviesController < ApplicationController
238
- def show
239
- @movie = Movie.find params[:id]
238
+ class MoviesController < ApplicationController
239
+ def show
240
+ @movie = Movie.find params[:id]
241
+ end
240
242
  end
241
- end
242
- if Rails::VERSION::MAJOR >= 5
243
+ else
243
244
  module Api
244
245
  class BookstoresController < ActionController::API
245
246
  def show
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.1.0
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Akira Matsuda
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-11-07 00:00:00.000000000 Z
11
+ date: 2018-11-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: test-unit-rails
@@ -169,6 +169,7 @@ files:
169
169
  - test/fake_app/app/views/books/show.html.erb
170
170
  - test/fake_app/app/views/movies/show.html.erb
171
171
  - test/fake_app/fake_app.rb
172
+ - test/fake_app/public/images/cover.png
172
173
  - test/features/action_controller_api_test.rb
173
174
  - test/features/action_view_helpers_test.rb
174
175
  - test/features/association_test.rb
@@ -221,6 +222,7 @@ test_files:
221
222
  - test/fake_app/app/views/books/show.html.erb
222
223
  - test/fake_app/app/views/movies/show.html.erb
223
224
  - test/fake_app/fake_app.rb
225
+ - test/fake_app/public/images/cover.png
224
226
  - test/features/action_controller_api_test.rb
225
227
  - test/features/action_view_helpers_test.rb
226
228
  - test/features/association_test.rb