active_decorator 0.7.1 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (34) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +9 -5
  3. data/Gemfile +4 -2
  4. data/README.md +2 -2
  5. data/Rakefile +1 -0
  6. data/active_decorator.gemspec +1 -0
  7. data/gemfiles/Gemfile-rails.3.2.x +1 -10
  8. data/gemfiles/{Gemfile-rails.5.0.0.rc1 → Gemfile-rails.5.0.x} +1 -1
  9. data/lib/active_decorator.rb +1 -0
  10. data/lib/active_decorator/config.rb +1 -0
  11. data/lib/active_decorator/decorator.rb +5 -4
  12. data/lib/active_decorator/helpers.rb +7 -5
  13. data/lib/active_decorator/monkey/abstract_controller/rendering.rb +2 -1
  14. data/lib/active_decorator/monkey/action_controller/base/rescue_from.rb +1 -0
  15. data/lib/active_decorator/monkey/action_view/partial_renderer.rb +3 -2
  16. data/lib/active_decorator/railtie.rb +1 -0
  17. data/lib/active_decorator/version.rb +2 -1
  18. data/lib/active_decorator/view_context.rb +1 -0
  19. data/lib/generators/rails/decorator_generator.rb +1 -0
  20. data/lib/generators/rspec/decorator_generator.rb +1 -0
  21. data/lib/generators/test_unit/decorator_generator.rb +1 -0
  22. data/test/configuration_test.rb +1 -0
  23. data/test/controllers/fake_detection_test.rb +1 -0
  24. data/test/fake_app/app/views/authors/show.json.jbuilder +1 -0
  25. data/test/fake_app/app/views/books/_book.json.jbuilder +1 -0
  26. data/test/fake_app/app/views/books/errata.html.erb +1 -0
  27. data/test/fake_app/fake_app.rb +11 -1
  28. data/test/features/action_view_helpers_test.rb +1 -0
  29. data/test/features/controller_ivar_test.rb +1 -0
  30. data/test/features/jbuilder_test.rb +1 -0
  31. data/test/features/name_error_handling_test.rb +17 -0
  32. data/test/features/partial_test.rb +1 -0
  33. data/test/test_helper.rb +1 -0
  34. metadata +8 -5
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 32cc540a94d0c4151aa9ccc05f8ecdd075643b1d
4
- data.tar.gz: ae85f4549a24440613e4dca88f9f770e8e6b2f1f
3
+ metadata.gz: 14f002118bfbc2127bf674fc7488990d80a5152c
4
+ data.tar.gz: 6e40b90bb6ffc7ba584147a93041025456216f52
5
5
  SHA512:
6
- metadata.gz: c035b1cb9156d73057f019fdc1a6c1f0ded63563570333f212a7d47719cc40d827f099eda3759fe5656fdcfc19ba1739b8f8f1f329bfe79a51a159ed2d5263c2
7
- data.tar.gz: bffdaf8dd9ffb4fe61944266f735292a6dec5e8d008e7d6825acec4d2c5033bae2eecdf70db51da3e7ec209db7ddbe2a8dc987df6af59092039290dbdb04d526
6
+ metadata.gz: 5bd8f1c1bdc0cfe4734755e9a56fd1d20cbea6205319ac20c308360b95b5c74303d3f16cda0002458c2b33795ad6690e2eb8401ed99d35db4c3068f5630e6936
7
+ data.tar.gz: cf5c094dedd2637ea7f23bdd3b0f131b2a33f0cc98e9ff2148433960e8305c2b1732d7cf6005bd82247d9cc8b8a71897c61e5bcd5f9d044a641d970f53c7fa58
data/.travis.yml CHANGED
@@ -5,15 +5,15 @@ script: bundle exec rake test
5
5
  rvm:
6
6
  - 2.0.0
7
7
  - 2.1.10
8
- - 2.2.4
9
- - 2.3.1
8
+ - 2.2.6
9
+ - 2.3.3
10
10
  - ruby-head
11
11
  gemfile:
12
12
  - gemfiles/Gemfile-rails.3.2.x
13
13
  - gemfiles/Gemfile-rails.4.0.x
14
14
  - gemfiles/Gemfile-rails.4.1.x
15
15
  - gemfiles/Gemfile-rails.4.2.x
16
- - gemfiles/Gemfile-rails.5.0.0.rc1
16
+ - gemfiles/Gemfile-rails.5.0.x
17
17
 
18
18
  sudo: false
19
19
 
@@ -21,9 +21,13 @@ matrix:
21
21
  exclude:
22
22
  - rvm: ruby-head
23
23
  gemfile: gemfiles/Gemfile-rails.3.2.x
24
+ - rvm: ruby-head
25
+ gemfile: gemfiles/Gemfile-rails.4.0.x
26
+ - rvm: ruby-head
27
+ gemfile: gemfiles/Gemfile-rails.4.1.x
24
28
  - rvm: 2.0.0
25
- gemfile: gemfiles/Gemfile-rails.5.0.0.rc1
29
+ gemfile: gemfiles/Gemfile-rails.5.0.x
26
30
  - rvm: 2.1.10
27
- gemfile: gemfiles/Gemfile-rails.5.0.0.rc1
31
+ gemfile: gemfiles/Gemfile-rails.5.0.x
28
32
  allow_failures:
29
33
  - rvm: ruby-head
data/Gemfile CHANGED
@@ -1,8 +1,10 @@
1
+ # frozen_string_literal: true
1
2
  source 'https://rubygems.org'
2
3
 
3
4
  gemspec
4
5
 
5
- gem 'rails', '~> 4.0.0'
6
- gem 'capybara', '>= 2'
6
+ gem 'rails'
7
+ gem 'test-unit-rails'
8
+ gem 'capybara'
7
9
  gem 'sqlite3'
8
10
  gem 'jbuilder'
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 and Rails 4. Keep your helpers and views Object-Oriented!
3
+ A simple and Rubyish view helper for Rails 3, Rails 4 and Rails 5. Keep your helpers and views Object-Oriented!
4
4
 
5
5
 
6
6
  ## Features ##
@@ -16,7 +16,7 @@ A simple and Rubyish view helper for Rails 3 and Rails 4. Keep your helpers and
16
16
 
17
17
  * Ruby 2.0.0, 2.1.x, 2.2.x, 2.3.x, and 2.4 (trunk)
18
18
 
19
- * Rails 3.2.x, 4.0.x, 4.1.x, 4.2.x, and 5.0 (edge)
19
+ * Rails 3.2.x, 4.0.x, 4.1.x, 4.2.x, 5.0, and 5.1 (edge)
20
20
 
21
21
 
22
22
  ## Supported ORMs ##
data/Rakefile CHANGED
@@ -1,4 +1,5 @@
1
1
  # encoding: utf-8
2
+ # frozen_string_literal: true
2
3
 
3
4
  require 'bundler'
4
5
  Bundler::GemHelper.install_tasks
@@ -1,4 +1,5 @@
1
1
  # -*- encoding: utf-8 -*-
2
+ # frozen_string_literal: true
2
3
  $:.push File.expand_path("../lib", __FILE__)
3
4
  require "active_decorator/version"
4
5
 
@@ -4,17 +4,8 @@ gem 'active_decorator', path: '..'
4
4
 
5
5
  gem 'rails', '~> 3.2.0'
6
6
  gem 'test-unit-rails', '1.0.2'
7
- if RUBY_VERSION <= '1.8.7'
8
- gem 'i18n', '~> 0.6.11'
9
- end
10
7
  gem 'capybara', '~> 2.0.0'
11
- # rubyzip >=1 doesn't support ruby 1.8
12
- gem 'rubyzip', '< 1.0.0'
13
8
  gem 'sqlite3'
14
9
  gem 'nokogiri', '~> 1.5.0'
15
- if RUBY_VERSION <= '1.8.7'
16
- gem 'jbuilder', '< 2'
17
- else
18
- gem 'jbuilder'
19
- end
10
+ gem 'jbuilder'
20
11
  gem 'test-unit'
@@ -2,7 +2,7 @@ source 'https://rubygems.org'
2
2
 
3
3
  gem 'active_decorator', path: '..'
4
4
 
5
- gem 'rails', '~> 5.0.0.beta4'
5
+ gem 'rails', '~> 5.0.0'
6
6
  gem 'test-unit-rails'
7
7
  gem 'capybara'
8
8
  gem 'sqlite3'
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'active_decorator/version'
2
3
  require 'active_decorator/decorator'
3
4
  require 'active_decorator/railtie'
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module ActiveDecorator
2
3
  include ActiveSupport::Configurable
3
4
 
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'singleton'
2
3
  require 'active_decorator/helpers'
3
4
 
@@ -17,14 +18,14 @@ module ActiveDecorator
17
18
  obj.each do |r|
18
19
  decorate r
19
20
  end
20
- elsif defined?(ActiveRecord) && obj.is_a?(ActiveRecord::Relation) && !obj.is_a?(ActiveDecorator::RelationDecorator)
21
+ elsif defined?(ActiveRecord) && obj.is_a?(ActiveRecord::Relation)
21
22
  # don't call each nor to_a immediately
22
23
  if obj.respond_to?(:records)
23
24
  # Rails 5.0
24
- obj.extend ActiveDecorator::RelationDecorator
25
+ obj.extend ActiveDecorator::RelationDecorator unless obj.is_a? ActiveDecorator::RelationDecorator
25
26
  else
26
27
  # Rails 3.x and 4.x
27
- obj.extend ActiveDecorator::RelationDecoratorLegacy
28
+ obj.extend ActiveDecorator::RelationDecoratorLegacy unless obj.is_a? ActiveDecorator::RelationDecoratorLegacy
28
29
  end
29
30
  else
30
31
  d = decorator_for obj.class
@@ -35,7 +36,7 @@ module ActiveDecorator
35
36
 
36
37
  private
37
38
  def decorator_for(model_class)
38
- return @@decorators[model_class] if @@decorators.has_key? model_class
39
+ return @@decorators[model_class] if @@decorators.key? model_class
39
40
 
40
41
  decorator_name = "#{model_class.name}#{ActiveDecorator.config.decorator_suffix}"
41
42
  d = decorator_name.constantize
@@ -1,13 +1,15 @@
1
+ # frozen_string_literal: true
1
2
  module ActiveDecorator
2
3
  module Helpers
3
4
  def method_missing(method, *args, &block)
4
5
  super
5
- #TODO need to make sure who raised the error?
6
- rescue NoMethodError, NameError => original_error
6
+ rescue NoMethodError, NameError
7
7
  begin
8
- ActiveDecorator::ViewContext.current.send method, *args, &block
9
- rescue NoMethodError, NameError
10
- raise original_error
8
+ (view_context = ActiveDecorator::ViewContext.current).send method, *args, &block
9
+ rescue NoMethodError
10
+ raise NoMethodError, "undefined method `#{method}` for either #{self} or #{view_context}"
11
+ rescue NameError
12
+ raise NameError, "undefined local variable `#{method}` for either #{self} or #{view_context}"
11
13
  end
12
14
  end
13
15
  end
@@ -1,10 +1,11 @@
1
+ # frozen_string_literal: true
1
2
  module ActiveDecorator
2
3
  module Monkey
3
4
  module AbstractController
4
5
  module Rendering
5
6
  def view_assigns
6
7
  hash = super
7
- hash.values.each do |v|
8
+ hash.each_value do |v|
8
9
  ActiveDecorator::Decorator.instance.decorate v
9
10
  end
10
11
  hash
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module ActiveDecorator
2
3
  module Monkey
3
4
  module ActionController
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module ActiveDecorator
2
3
  module Monkey
3
4
  module ActionView
@@ -9,8 +10,8 @@ module ActiveDecorator
9
10
 
10
11
  @locals.values.each do |v|
11
12
  ActiveDecorator::Decorator.instance.decorate v
12
- end unless @locals.blank?
13
- ActiveDecorator::Decorator.instance.decorate @object unless @object.blank?
13
+ end if @locals
14
+ ActiveDecorator::Decorator.instance.decorate @object if @object && (@object != nil)
14
15
  ActiveDecorator::Decorator.instance.decorate @collection unless @collection.blank?
15
16
 
16
17
  self
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'active_decorator/view_context'
2
3
  require 'rails'
3
4
 
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module ActiveDecorator
2
- VERSION = '0.7.1'
3
+ VERSION = '0.8.0'
3
4
  end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module ActiveDecorator
2
3
  module ViewContext
3
4
  class << self
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Rails
2
3
  module Generators
3
4
  class DecoratorGenerator < Rails::Generators::NamedBase
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Rspec
2
3
  class DecoratorGenerator < ::Rails::Generators::NamedBase
3
4
  source_root File.expand_path('../templates', __FILE__)
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module TestUnit
2
3
  class DecoratorGenerator < ::Rails::Generators::NamedBase
3
4
  source_root File.expand_path('../templates', __FILE__)
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'test_helper'
2
3
 
3
4
  Comic = Struct.new(:title, :price)
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'test_helper'
2
3
 
3
4
  class MoviesControllerTest < ActionController::TestCase
@@ -1,2 +1,3 @@
1
+ # frozen_string_literal: true
1
2
  json.name @author.name
2
3
  json.books @author.books, partial: 'books/book', as: :book
@@ -1,2 +1,3 @@
1
+ # frozen_string_literal: true
1
2
  json.title book.title
2
3
  json.reverse_title book.reverse_title
@@ -0,0 +1 @@
1
+ <%= @book.errata %>
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'active_record'
2
3
  require 'action_controller/railtie'
3
4
  require 'action_mailer/railtie'
@@ -27,6 +28,7 @@ ActiveDecoratorTestApp::Application.routes.draw do
27
28
  resources :authors, only: [:index, :show] do
28
29
  resources :books, only: [:index, :show] do
29
30
  member do
31
+ get :errata
30
32
  get :error
31
33
  post :purchase
32
34
  end
@@ -83,6 +85,10 @@ module BookDecorator
83
85
  image_tag 'cover.png'
84
86
  end
85
87
 
88
+ def errata
89
+ poof!
90
+ end
91
+
86
92
  def error
87
93
  "ERROR"
88
94
  end
@@ -126,7 +132,7 @@ class BooksController < ApplicationController
126
132
  class CustomError < StandardError; end
127
133
 
128
134
  rescue_from CustomError do
129
- render "error"
135
+ render :error
130
136
  end
131
137
 
132
138
  def index
@@ -138,6 +144,10 @@ class BooksController < ApplicationController
138
144
  @book = Author.find(params[:author_id]).books.find(params[:id])
139
145
  end
140
146
 
147
+ def errata
148
+ @book = Author.find(params[:author_id]).books.find(params[:id])
149
+ end
150
+
141
151
  def error
142
152
  @book = Author.find(params[:author_id]).books.find(params[:id])
143
153
  raise CustomError, "error"
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'test_helper'
2
3
 
3
4
  class ActionViewHelpersTest < ActionDispatch::IntegrationTest
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'test_helper'
2
3
 
3
4
  class ControllerIvarTest < ActionDispatch::IntegrationTest
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'test_helper'
2
3
 
3
4
  class JbuilderTest < ActionDispatch::IntegrationTest
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+ require 'test_helper'
3
+
4
+ class NameErrorHandlingTest < ActionDispatch::IntegrationTest
5
+ setup do
6
+ aamine = Author.create! name: 'aamine'
7
+ @rhg = aamine.books.create! title: 'RHG'
8
+ end
9
+
10
+ test 'raising NameError in a decorator' do
11
+ err = assert_raises ActionView::Template::Error do
12
+ visit "/authors/#{@rhg.author.id}/books/#{@rhg.id}/errata"
13
+ end
14
+
15
+ assert_match(/undefined method `poof!` for/, err.message)
16
+ end
17
+ end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'test_helper'
2
3
 
3
4
  class PartialTest < ActionDispatch::IntegrationTest
data/test/test_helper.rb CHANGED
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
3
  $LOAD_PATH.unshift(File.dirname(__FILE__))
3
4
  # load Rails first
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: 0.7.1
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Akira Matsuda
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-05-07 00:00:00.000000000 Z
11
+ date: 2016-12-13 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: A simple and Rubyish view helper for Rails
14
14
  email:
@@ -28,7 +28,7 @@ files:
28
28
  - gemfiles/Gemfile-rails.4.0.x
29
29
  - gemfiles/Gemfile-rails.4.1.x
30
30
  - gemfiles/Gemfile-rails.4.2.x
31
- - gemfiles/Gemfile-rails.5.0.0.rc1
31
+ - gemfiles/Gemfile-rails.5.0.x
32
32
  - lib/active_decorator.rb
33
33
  - lib/active_decorator/config.rb
34
34
  - lib/active_decorator/decorator.rb
@@ -54,6 +54,7 @@ files:
54
54
  - test/fake_app/app/views/books/_book.html.erb
55
55
  - test/fake_app/app/views/books/_book.json.jbuilder
56
56
  - test/fake_app/app/views/books/_book_locals.html.erb
57
+ - test/fake_app/app/views/books/errata.html.erb
57
58
  - test/fake_app/app/views/books/error.html.erb
58
59
  - test/fake_app/app/views/books/index.html.erb
59
60
  - test/fake_app/app/views/books/purchase.html.erb
@@ -63,6 +64,7 @@ files:
63
64
  - test/features/action_view_helpers_test.rb
64
65
  - test/features/controller_ivar_test.rb
65
66
  - test/features/jbuilder_test.rb
67
+ - test/features/name_error_handling_test.rb
66
68
  - test/features/partial_test.rb
67
69
  - test/test_helper.rb
68
70
  homepage: https://github.com/amatsuda/active_decorator
@@ -84,7 +86,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
84
86
  version: '0'
85
87
  requirements: []
86
88
  rubyforge_project:
87
- rubygems_version: 2.6.3
89
+ rubygems_version: 2.6.8
88
90
  signing_key:
89
91
  specification_version: 4
90
92
  summary: A simple and Rubyish view helper for Rails
@@ -98,6 +100,7 @@ test_files:
98
100
  - test/fake_app/app/views/books/_book.html.erb
99
101
  - test/fake_app/app/views/books/_book.json.jbuilder
100
102
  - test/fake_app/app/views/books/_book_locals.html.erb
103
+ - test/fake_app/app/views/books/errata.html.erb
101
104
  - test/fake_app/app/views/books/error.html.erb
102
105
  - test/fake_app/app/views/books/index.html.erb
103
106
  - test/fake_app/app/views/books/purchase.html.erb
@@ -107,6 +110,6 @@ test_files:
107
110
  - test/features/action_view_helpers_test.rb
108
111
  - test/features/controller_ivar_test.rb
109
112
  - test/features/jbuilder_test.rb
113
+ - test/features/name_error_handling_test.rb
110
114
  - test/features/partial_test.rb
111
115
  - test/test_helper.rb
112
- has_rdoc: