active_decorator 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. checksums.yaml +5 -5
  2. data/.travis.yml +63 -30
  3. data/CHANGELOG.md +9 -0
  4. data/Gemfile +1 -6
  5. data/README.md +5 -5
  6. data/active_decorator.gemspec +10 -1
  7. data/gemfiles/Gemfile-rails.3.2.x +1 -4
  8. data/gemfiles/Gemfile-rails.4.0.x +1 -5
  9. data/gemfiles/Gemfile-rails.4.1.x +1 -5
  10. data/gemfiles/Gemfile-rails.4.2.x +1 -5
  11. data/gemfiles/Gemfile-rails.5.0.x +1 -5
  12. data/gemfiles/Gemfile-rails.5.1.x +2 -6
  13. data/gemfiles/Gemfile-rails.5.2.x +5 -0
  14. data/gemfiles/Gemfile-rails.edge +12 -0
  15. data/lib/active_decorator.rb +1 -0
  16. data/lib/active_decorator/config.rb +1 -0
  17. data/lib/active_decorator/decorated.rb +1 -0
  18. data/lib/active_decorator/decorator.rb +3 -1
  19. data/lib/active_decorator/helpers.rb +1 -0
  20. data/lib/active_decorator/monkey/abstract_controller/rendering.rb +1 -0
  21. data/lib/active_decorator/monkey/action_controller/base/rescue_from.rb +1 -0
  22. data/lib/active_decorator/monkey/action_view/partial_renderer.rb +3 -2
  23. data/lib/active_decorator/monkey/active_record/associations.rb +1 -0
  24. data/lib/active_decorator/railtie.rb +13 -0
  25. data/lib/active_decorator/version.rb +2 -1
  26. data/lib/active_decorator/view_context.rb +1 -0
  27. data/lib/generators/rails/USAGE +8 -0
  28. data/lib/generators/rails/decorator_generator.rb +4 -13
  29. data/lib/generators/rspec/decorator_generator.rb +7 -4
  30. data/lib/generators/rspec/templates/decorator_spec.rb +1 -1
  31. data/lib/generators/test_unit/decorator_generator.rb +8 -4
  32. data/lib/generators/test_unit/templates/decorator_test.rb +1 -1
  33. data/test/configuration_test.rb +1 -0
  34. data/test/controllers/fake_detection_test.rb +1 -0
  35. data/test/decorator_test.rb +19 -0
  36. data/test/fake_app/app/views/api/bookstores/show.json.jbuilder +2 -0
  37. data/test/fake_app/fake_app.rb +19 -0
  38. data/test/features/action_controller_api_test.rb +19 -0
  39. data/test/features/action_view_helpers_test.rb +1 -0
  40. data/test/features/association_test.rb +1 -0
  41. data/test/features/controller_ivar_test.rb +1 -0
  42. data/test/features/jbuilder_test.rb +1 -0
  43. data/test/features/name_error_handling_test.rb +1 -0
  44. data/test/features/partial_test.rb +1 -0
  45. data/test/test_helper.rb +19 -2
  46. metadata +116 -9
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 8ec56959877091a50db872942aaeb8352cdb9269
4
- data.tar.gz: 5a64a878439cc739235815ad6b9345d243cd191b
2
+ SHA256:
3
+ metadata.gz: 298a6372406ac3480e7baaeee85eeea4b3dcb393ed37e6ccf4ab0fe120b5d7ed
4
+ data.tar.gz: 9576044dd3bf36591e9a56190b37f88062f58bc6f325c4e6a7b0446b5d8d05f5
5
5
  SHA512:
6
- metadata.gz: 7935a3abad55b5a751acfe09fab8cf4dcd7f1b4e5c66b09d2a00fbc0cccbf9562ea84ee76767cc77313160174f427fbcb38ec17f767a2f503c01329e8d377472
7
- data.tar.gz: f84157d3533f18cfd9aafed0e5b23f48f210e3dd8a351e8c0bb2df95afec646c634ca650f833e388fb11c1134527ea58c7b7c5f7f4fe7933b98a8221a6672a25
6
+ metadata.gz: ac2c57c9ace629b66a38fa039d622dd4c6f345334ec7bfee10e8e64dbe6efd43f78adc378fd2aff5e9ba52ecd73e963a21ec9817f776718035db250f13365567
7
+ data.tar.gz: acaf0a2612909a35e9d095ec6ad8e80b9cc5240df40accec3fc8e337e192714c8fda649d02f98b6ed92a41ac9c0a33702f2d8bc64b2e61071a7f71762d9e2988
@@ -1,49 +1,82 @@
1
1
  language: ruby
2
2
 
3
- before_install: gem update bundler --no-document
3
+ sudo: false
4
+
4
5
  script: bundle exec rake test
5
6
 
7
+ addons:
8
+ chrome: stable
9
+
10
+ before_install:
11
+ - sudo apt update -qq
12
+ - sudo apt install -y chromium-chromedriver
13
+ - sudo ln -s /usr/lib/chromium-browser/chromedriver /usr/bin/
14
+ - gem update bundler --no-document
15
+
6
16
  rvm:
7
- - 2.0.0
17
+ - 2.5.3
18
+ - 2.4.5
19
+ - 2.3.7
20
+ - 2.2.10
8
21
  - 2.1.10
9
- - 2.2.7
10
- - 2.3.4
11
- - 2.4.1
12
- - ruby-head
22
+ - 2.0.0
13
23
  gemfile:
14
- - gemfiles/Gemfile-rails.3.2.x
15
- - gemfiles/Gemfile-rails.4.0.x
16
- - gemfiles/Gemfile-rails.4.1.x
17
- - gemfiles/Gemfile-rails.4.2.x
18
- - gemfiles/Gemfile-rails.5.0.x
24
+ - gemfiles/Gemfile-rails.5.2.x
19
25
  - gemfiles/Gemfile-rails.5.1.x
20
-
21
- sudo: false
26
+ - gemfiles/Gemfile-rails.5.0.x
27
+ - gemfiles/Gemfile-rails.4.2.x
28
+ - gemfiles/Gemfile-rails.4.1.x
29
+ - gemfiles/Gemfile-rails.4.0.x
30
+ - gemfiles/Gemfile-rails.3.2.x
22
31
 
23
32
  matrix:
24
33
  exclude:
25
- - rvm: ruby-head
26
- gemfile: gemfiles/Gemfile-rails.3.2.x
27
- - rvm: ruby-head
28
- gemfile: gemfiles/Gemfile-rails.4.0.x
29
- - rvm: ruby-head
30
- gemfile: gemfiles/Gemfile-rails.4.1.x
31
- - rvm: 2.4.1
32
- gemfile: gemfiles/Gemfile-rails.3.2.x
33
- - rvm: 2.4.1
34
- gemfile: gemfiles/Gemfile-rails.4.0.x
35
- - rvm: 2.4.1
36
- gemfile: gemfiles/Gemfile-rails.4.1.x
37
- - rvm: 2.4.1
38
- gemfile: gemfiles/Gemfile-rails.4.2.x
34
+ - rvm: 2.1.10
35
+ gemfile: gemfiles/Gemfile-rails.5.2.x
36
+ - rvm: 2.0.0
37
+ gemfile: gemfiles/Gemfile-rails.5.2.x
38
+ - rvm: 2.4.5
39
+ gemfile: gemfiles/Gemfile-rails.5.1.x
40
+ - rvm: 2.3.7
41
+ gemfile: gemfiles/Gemfile-rails.5.1.x
42
+ - rvm: 2.1.10
43
+ gemfile: gemfiles/Gemfile-rails.5.1.x
39
44
  - rvm: 2.0.0
45
+ gemfile: gemfiles/Gemfile-rails.5.1.x
46
+ - rvm: 2.4.5
47
+ gemfile: gemfiles/Gemfile-rails.5.0.x
48
+ - rvm: 2.3.7
40
49
  gemfile: gemfiles/Gemfile-rails.5.0.x
41
50
  - rvm: 2.1.10
42
51
  gemfile: gemfiles/Gemfile-rails.5.0.x
43
52
  - rvm: 2.0.0
44
- gemfile: gemfiles/Gemfile-rails.5.1.x
53
+ gemfile: gemfiles/Gemfile-rails.5.0.x
54
+ - rvm: 2.5.3
55
+ gemfile: gemfiles/Gemfile-rails.4.2.x
56
+ - rvm: 2.4.5
57
+ gemfile: gemfiles/Gemfile-rails.4.2.x
58
+ - rvm: 2.5.3
59
+ gemfile: gemfiles/Gemfile-rails.4.1.x
60
+ - rvm: 2.4.5
61
+ gemfile: gemfiles/Gemfile-rails.4.1.x
62
+ - rvm: 2.2.10
63
+ gemfile: gemfiles/Gemfile-rails.4.1.x
45
64
  - rvm: 2.1.10
46
- gemfile: gemfiles/Gemfile-rails.5.1.x
65
+ gemfile: gemfiles/Gemfile-rails.4.1.x
66
+ - rvm: 2.5.3
67
+ gemfile: gemfiles/Gemfile-rails.4.0.x
68
+ - rvm: 2.4.5
69
+ gemfile: gemfiles/Gemfile-rails.4.0.x
70
+ - rvm: 2.2.10
71
+ gemfile: gemfiles/Gemfile-rails.4.0.x
72
+ - rvm: 2.1.10
73
+ gemfile: gemfiles/Gemfile-rails.4.0.x
74
+ - rvm: 2.5.3
75
+ gemfile: gemfiles/Gemfile-rails.3.2.x
76
+ - rvm: 2.4.5
77
+ gemfile: gemfiles/Gemfile-rails.3.2.x
78
+ include:
79
+ - rvm: ruby-head
80
+ gemfile: gemfiles/Gemfile-rails.edge
47
81
  allow_failures:
48
82
  - rvm: ruby-head
49
- - gemfile: gemfiles/Gemfile-rails.5.1.x
@@ -0,0 +1,9 @@
1
+ ## 1.1.0
2
+
3
+ * ActionController::API support [@frodsan]
4
+
5
+ * `ActiveDecorator::Decorator.instance.decorate` now returns the decorated object when the receiver was already a decorated object (it used to return `nil`) [@velonica1997]
6
+
7
+ * Update decorator_spec.rb syntax to respect RSpec 3 style [@memoht]
8
+
9
+ * Fixed namespace for TestUnit generator with some refactorings [@yhirano55]
data/Gemfile CHANGED
@@ -1,10 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  source 'https://rubygems.org'
3
4
 
4
5
  gemspec
5
-
6
- gem 'rails'
7
- gem 'test-unit-rails'
8
- gem 'capybara'
9
- gem 'sqlite3'
10
- gem 'jbuilder'
data/README.md CHANGED
@@ -6,9 +6,9 @@ A simple and Rubyish view helper for Rails 3, Rails 4 and Rails 5. Keep your hel
6
6
  ## Features ##
7
7
 
8
8
  1. automatically mixes decorator module into corresponding model only when:
9
- 1. passing a model or collection of models or an instance of ActiveRecord::Relation from controllers to views
10
- 2. rendering partials with models (using `:collection` or `:object` or `:locals` explicitly or implicitly)
11
- 3. fetching already decorated Active Record model object's association
9
+ 1. passing a model or collection of models or an instance of ActiveRecord::Relation from controllers to views
10
+ 2. rendering partials with models (using `:collection` or `:object` or `:locals` explicitly or implicitly)
11
+ 3. fetching already decorated Active Record model object's association
12
12
  2. the decorator module runs in the model's context. So, you can directly call any attributes or methods in the decorator module
13
13
  3. since decorators are considered as sort of helpers, you can also call any ActionView's helper methods such as `content_tag` or `link_to`
14
14
 
@@ -114,9 +114,9 @@ end
114
114
 
115
115
  ### Using ActiveDecorator outside of Action View ###
116
116
 
117
- Sometimes your may want to use decorators outside of Action View, for example,
117
+ Sometimes you may want to use decorators outside of Action View, for example,
118
118
  for background tasks for ActiveJob.
119
- For such use case, ActiveDecorator module provides `with_view_context` method
119
+ For such use case, ActiveDecorator module provides `run_with` method
120
120
  that takes some kind of Action View and a block.
121
121
 
122
122
  ```ruby
@@ -1,5 +1,5 @@
1
- # -*- encoding: utf-8 -*-
2
1
  # frozen_string_literal: true
2
+
3
3
  $:.push File.expand_path("../lib", __FILE__)
4
4
  require "active_decorator/version"
5
5
 
@@ -9,6 +9,7 @@ Gem::Specification.new do |s|
9
9
  s.authors = ["Akira Matsuda"]
10
10
  s.email = ["ronnie@dio.jp"]
11
11
  s.homepage = 'https://github.com/amatsuda/active_decorator'
12
+ s.license = 'MIT'
12
13
  s.summary = %q{A simple and Rubyish view helper for Rails}
13
14
  s.description = %q{A simple and Rubyish view helper for Rails}
14
15
 
@@ -16,4 +17,12 @@ Gem::Specification.new do |s|
16
17
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
17
18
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
18
19
  s.require_paths = ["lib"]
20
+
21
+ s.add_development_dependency 'test-unit-rails'
22
+ s.add_development_dependency 'selenium-webdriver'
23
+ s.add_development_dependency 'puma'
24
+ s.add_development_dependency 'capybara'
25
+ s.add_development_dependency 'sqlite3'
26
+ s.add_development_dependency 'rake'
27
+ s.add_development_dependency 'jbuilder'
19
28
  end
@@ -1,11 +1,8 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- gem 'active_decorator', path: '..'
3
+ gemspec path: '..'
4
4
 
5
5
  gem 'rails', '~> 3.2.0'
6
6
  gem 'test-unit-rails', '1.0.2'
7
7
  gem 'capybara', '~> 2.0.0'
8
- gem 'sqlite3'
9
8
  gem 'nokogiri', '~> 1.5.0'
10
- gem 'jbuilder'
11
- gem 'test-unit'
@@ -1,10 +1,6 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- gem 'active_decorator', path: '..'
3
+ gemspec path: '..'
4
4
 
5
5
  gem 'rails', '~> 4.0.0'
6
- gem 'test-unit-rails'
7
- gem 'capybara'
8
- gem 'sqlite3'
9
6
  gem 'nokogiri', '~> 1.6.0'
10
- gem 'jbuilder'
@@ -1,10 +1,6 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- gem 'active_decorator', path: '..'
3
+ gemspec path: '..'
4
4
 
5
5
  gem 'rails', '~> 4.1.0'
6
- gem 'test-unit-rails'
7
- gem 'capybara'
8
- gem 'sqlite3'
9
6
  gem 'nokogiri', '~> 1.6.0'
10
- gem 'jbuilder'
@@ -1,10 +1,6 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- gem 'active_decorator', path: '..'
3
+ gemspec path: '..'
4
4
 
5
5
  gem 'rails', '~> 4.2.0'
6
- gem 'test-unit-rails'
7
- gem 'capybara'
8
- gem 'sqlite3'
9
6
  gem 'nokogiri', '~> 1.6.0'
10
- gem 'jbuilder'
@@ -1,9 +1,5 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- gem 'active_decorator', path: '..'
3
+ gemspec path: '..'
4
4
 
5
5
  gem 'rails', '~> 5.0.0'
6
- gem 'test-unit-rails'
7
- gem 'capybara'
8
- gem 'sqlite3'
9
- gem 'jbuilder'
@@ -1,9 +1,5 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- gem 'active_decorator', path: '..'
3
+ gemspec path: '..'
4
4
 
5
- gem 'rails', '5.1.0'
6
- gem 'test-unit-rails'
7
- gem 'capybara'
8
- gem 'sqlite3'
9
- gem 'jbuilder'
5
+ gem 'rails', '~> 5.1.0'
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec path: '..'
4
+
5
+ gem 'rails', '~> 5.2.0'
@@ -0,0 +1,12 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec path: '..'
4
+
5
+ git_source(:github) do |repo_name|
6
+ repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?("/")
7
+ "https://github.com/#{repo_name}.git"
8
+ end
9
+
10
+ github 'rails/rails' do
11
+ gem 'rails'
12
+ end
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require 'active_decorator/version'
3
4
  require 'active_decorator/decorator'
4
5
  require 'active_decorator/railtie'
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module ActiveDecorator
3
4
  include ActiveSupport::Configurable
4
5
 
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  # A no-op module to mark an AR model instance as a "decorated" object.
3
4
  module ActiveDecorator::Decorated
4
5
  end
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require 'singleton'
3
4
  require 'active_decorator/helpers'
4
5
  require 'active_decorator/decorated'
@@ -45,8 +46,9 @@ module ActiveDecorator
45
46
  d = decorator_for obj.class
46
47
  return obj unless d
47
48
  obj.extend d unless obj.is_a? d
48
- obj
49
49
  end
50
+
51
+ obj
50
52
  end
51
53
 
52
54
  # Decorates AR model object's association only when the object was decorated.
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  # On the fly delegation from the decorator to the decorated object and the helpers.
3
4
  module ActiveDecorator
4
5
  module Helpers
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  # A monkey-patch for Rails controllers/mailers that auto-decorates ivars
3
4
  # that are passed to views.
4
5
  module ActiveDecorator
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  # A monkey-patch for Action Controller to pass the controller view_context over
3
4
  # to `render` invocation in `rescue_from` block.
4
5
  module ActiveDecorator
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  # A monkey-patch for Action View `render :partial` that auto-decorates `locals` values.
3
4
  module ActiveDecorator
4
5
  module Monkey
@@ -9,10 +10,10 @@ module ActiveDecorator
9
10
  def setup(*)
10
11
  super
11
12
 
12
- @locals.values.each do |v|
13
+ @locals.each_value do |v|
13
14
  ActiveDecorator::Decorator.instance.decorate v
14
15
  end if @locals
15
- ActiveDecorator::Decorator.instance.decorate @object if @object && (@object != nil)
16
+ ActiveDecorator::Decorator.instance.decorate @object if @object
16
17
  ActiveDecorator::Decorator.instance.decorate @collection unless @collection.blank?
17
18
 
18
19
  self
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  # A monkey-patch for Active Record that enables association auto-decoration.
3
4
  module ActiveDecorator
4
5
  module Monkey
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require 'active_decorator/view_context'
3
4
  require 'rails'
4
5
 
@@ -20,6 +21,18 @@ module ActiveDecorator
20
21
  ActionController::Base.send :include, ActiveDecorator::ViewContext::Filter
21
22
  end
22
23
 
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
33
+ end
34
+ end
35
+
23
36
  ActiveSupport.on_load :action_mailer do
24
37
  require 'active_decorator/monkey/abstract_controller/rendering'
25
38
  ActionMailer::Base.send :prepend, ActiveDecorator::Monkey::AbstractController::Rendering
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module ActiveDecorator
3
- VERSION = '1.0.0'
4
+ VERSION = '1.1.0'
4
5
  end
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  # A module that carries the controllers' view_context to decorators.
3
4
  module ActiveDecorator
4
5
  module ViewContext
@@ -0,0 +1,8 @@
1
+ Description:
2
+ Stubs out a decorator module in app/decorators directory.
3
+
4
+ Examples:
5
+ `rails g decorator book`
6
+
7
+ This creates:
8
+ app/decorators/book_decorator.rb
@@ -1,19 +1,10 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module Rails
3
4
  module Generators
4
- class DecoratorGenerator < Rails::Generators::NamedBase
5
- source_root File.expand_path('../templates', __FILE__)
6
-
7
- desc <<DESC
8
- Description:
9
- Stubs out a decorator module in app/decorators directory.
10
-
11
- Examples:
12
- `rails g decorator book`
13
-
14
- This creates:
15
- app/decorators/book_decorator.rb
16
- DESC
5
+ class DecoratorGenerator < NamedBase
6
+ source_root File.expand_path("templates", __dir__)
7
+ check_class_collision suffix: "Decorator"
17
8
 
18
9
  def create_decorator_file
19
10
  template 'decorator.rb', File.join('app/decorators', class_path, "#{file_name}_decorator.rb")
@@ -1,10 +1,13 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module Rspec
3
- class DecoratorGenerator < ::Rails::Generators::NamedBase
4
- source_root File.expand_path('../templates', __FILE__)
4
+ module Generators
5
+ class DecoratorGenerator < ::Rails::Generators::NamedBase
6
+ source_root File.expand_path("templates", __dir__)
5
7
 
6
- def create_spec_file
7
- template 'decorator_spec.rb', File.join('spec/decorators', class_path, "#{file_name}_decorator_spec.rb")
8
+ def create_spec_file
9
+ template 'decorator_spec.rb', File.join('spec/decorators', class_path, "#{file_name}_decorator_spec.rb")
10
+ end
8
11
  end
9
12
  end
10
13
  end
@@ -1,6 +1,6 @@
1
1
  require '<%= File.exists?('spec/rails_helper.rb') ? 'rails_helper' : 'spec_helper' %>'
2
2
 
3
- describe <%= class_name %>Decorator do
3
+ RSpec.describe <%= class_name %>Decorator do
4
4
  let(:<%= singular_name %>) { <%= class_name %>.new.extend <%= class_name %>Decorator }
5
5
  subject { <%= singular_name %> }
6
6
  it { should be_a <%= class_name %> }
@@ -1,10 +1,14 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module TestUnit
3
- class DecoratorGenerator < ::Rails::Generators::NamedBase
4
- source_root File.expand_path('../templates', __FILE__)
4
+ module Generators
5
+ class DecoratorGenerator < ::Rails::Generators::NamedBase
6
+ source_root File.expand_path("templates", __dir__)
7
+ check_class_collision suffix: "DecoratorTest"
5
8
 
6
- def create_test_file
7
- template 'decorator_test.rb', File.join('test/decorators', class_path, "#{file_name}_decorator_test.rb")
9
+ def create_test_file
10
+ template 'decorator_test.rb', File.join('test/decorators', class_path, "#{file_name}_decorator_test.rb")
11
+ end
8
12
  end
9
13
  end
10
14
  end
@@ -1,6 +1,6 @@
1
1
  require 'test_helper'
2
2
 
3
- class <%= singular_name.camelize %>DecoratorTest < ActiveSupport::TestCase
3
+ class <%= class_name %>DecoratorTest < ActiveSupport::TestCase
4
4
  def setup
5
5
  @<%= singular_name %> = <%= class_name %>.new.extend <%= class_name %>Decorator
6
6
  end
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require 'test_helper'
3
4
 
4
5
  Comic = Struct.new(:title, :price)
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require 'test_helper'
3
4
 
4
5
  class MoviesControllerTest < ActionController::TestCase
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require 'test_helper'
3
4
 
4
5
  class DecoratorTest < Test::Unit::TestCase
@@ -12,4 +13,22 @@ class DecoratorTest < Test::Unit::TestCase
12
13
  book = Book.new title: 'Boek'
13
14
  assert_equal book, ActiveDecorator::Decorator.instance.decorate(ActiveDecorator::Decorator.instance.decorate(book))
14
15
  end
16
+
17
+ test 'it returns the object of ActiveRecord::Relation on decorate' do
18
+ 3.times do |index|
19
+ Book.create title: "ve#{index}"
20
+ end
21
+
22
+ books = Book.all
23
+ assert_equal books, ActiveDecorator::Decorator.instance.decorate(books)
24
+ end
25
+
26
+ test 'it returns the object of ActiveRecord::Relation when it already is decorated on decorate' do
27
+ 3.times do |index|
28
+ Book.create title: "ve#{index}"
29
+ end
30
+
31
+ books = Book.all
32
+ assert_equal books, ActiveDecorator::Decorator.instance.decorate(ActiveDecorator::Decorator.instance.decorate(books))
33
+ end
15
34
  end
@@ -0,0 +1,2 @@
1
+ # frozen_string_literal: true
2
+ json.name @bookstore.name
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require 'active_record'
3
4
  require 'action_controller/railtie'
4
5
  require 'action_mailer/railtie'
@@ -42,6 +43,12 @@ ActiveDecoratorTestApp::Application.routes.draw do
42
43
  end
43
44
  end
44
45
  resources :movies, only: :show
46
+
47
+ if Rails::VERSION::MAJOR >= 5
48
+ namespace :api do
49
+ resources :bookstores, only: :show
50
+ end
51
+ end
45
52
  end
46
53
 
47
54
  # models
@@ -81,6 +88,8 @@ end
81
88
  class Company < ActiveRecord::Base
82
89
  has_many :authors
83
90
  end
91
+ class Bookstore < ActiveRecord::Base
92
+ end
84
93
 
85
94
  # helpers
86
95
  module ApplicationHelper; end
@@ -230,6 +239,15 @@ class MoviesController < ApplicationController
230
239
  @movie = Movie.find params[:id]
231
240
  end
232
241
  end
242
+ if Rails::VERSION::MAJOR >= 5
243
+ module Api
244
+ class BookstoresController < ActionController::API
245
+ def show
246
+ @bookstore = Bookstore.find params[:id]
247
+ end
248
+ end
249
+ end
250
+ end
233
251
 
234
252
  # mailers
235
253
  class BookMailer < ActionMailer::Base
@@ -251,6 +269,7 @@ class CreateAllTables < ActiveRecord::VERSION::MAJOR >= 5 ? ActiveRecord::Migrat
251
269
  create_table(:magazines) {|t| t.string :title}
252
270
  create_table(:authors_magazines) {|t| t.references :author; t.references :magazine}
253
271
  create_table(:companies) {|t| t.string :name}
272
+ create_table(:bookstores) {|t| t.string :name}
254
273
  end
255
274
  end
256
275
 
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'test_helper'
4
+
5
+ if Rails::VERSION::MAJOR >= 5
6
+
7
+ class ActionControllerAPITest < ActionDispatch::IntegrationTest
8
+ setup do
9
+ Bookstore.create! name: 'junkudo'
10
+ end
11
+
12
+ test 'decorating objects in api only controllers' do
13
+ get "/api/bookstores/#{Bookstore.last.id}.json"
14
+
15
+ assert_equal({"name" => "junkudo"}, response.parsed_body)
16
+ end
17
+ end
18
+
19
+ end
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require 'test_helper'
3
4
 
4
5
  class ActionViewHelpersTest < ActionDispatch::IntegrationTest
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require 'test_helper'
3
4
 
4
5
  class AssociationTest < ActionDispatch::IntegrationTest
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require 'test_helper'
3
4
 
4
5
  class ControllerIvarTest < ActionDispatch::IntegrationTest
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require 'test_helper'
3
4
 
4
5
  class JbuilderTest < ActionDispatch::IntegrationTest
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require 'test_helper'
3
4
 
4
5
  class NameErrorHandlingTest < ActionDispatch::IntegrationTest
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require 'test_helper'
3
4
 
4
5
  class PartialTest < ActionDispatch::IntegrationTest
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
4
  $LOAD_PATH.unshift(File.dirname(__FILE__))
4
5
  # load Rails first
@@ -7,13 +8,29 @@ require 'rails'
7
8
  # load the plugin
8
9
  require 'active_decorator'
9
10
 
11
+ Bundler.require
12
+ require 'capybara'
13
+ require 'selenium/webdriver'
14
+
10
15
  # needs to load the app next
11
16
  require 'fake_app/fake_app'
12
17
 
13
18
  require 'test/unit/rails/test_help'
14
19
 
15
- class ActionDispatch::IntegrationTest
16
- include Capybara::DSL
20
+ begin
21
+ require 'action_dispatch/system_test_case'
22
+ rescue LoadError
23
+ Capybara.register_driver :chrome do |app|
24
+ options = Selenium::WebDriver::Chrome::Options.new(args: %w[no-sandbox headless disable-gpu])
25
+ Capybara::Selenium::Driver.new(app, browser: :chrome, options: options)
26
+ end
27
+ Capybara.javascript_driver = :chrome
28
+
29
+ class ActionDispatch::IntegrationTest
30
+ include Capybara::DSL
31
+ end
32
+ else
33
+ ActionDispatch::SystemTestCase.driven_by(:selenium, using: :headless_chrome)
17
34
  end
18
35
 
19
36
  module DatabaseDeleter
metadata CHANGED
@@ -1,15 +1,113 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_decorator
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.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: 2017-06-29 00:00:00.000000000 Z
12
- dependencies: []
11
+ date: 2018-11-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: test-unit-rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: selenium-webdriver
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: puma
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: capybara
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: sqlite3
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rake
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: jbuilder
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
13
111
  description: A simple and Rubyish view helper for Rails
14
112
  email:
15
113
  - ronnie@dio.jp
@@ -17,8 +115,9 @@ executables: []
17
115
  extensions: []
18
116
  extra_rdoc_files: []
19
117
  files:
20
- - .gitignore
21
- - .travis.yml
118
+ - ".gitignore"
119
+ - ".travis.yml"
120
+ - CHANGELOG.md
22
121
  - Gemfile
23
122
  - MIT-LICENSE
24
123
  - README.md
@@ -30,6 +129,8 @@ files:
30
129
  - gemfiles/Gemfile-rails.4.2.x
31
130
  - gemfiles/Gemfile-rails.5.0.x
32
131
  - gemfiles/Gemfile-rails.5.1.x
132
+ - gemfiles/Gemfile-rails.5.2.x
133
+ - gemfiles/Gemfile-rails.edge
33
134
  - lib/active_decorator.rb
34
135
  - lib/active_decorator/config.rb
35
136
  - lib/active_decorator/decorated.rb
@@ -42,6 +143,7 @@ files:
42
143
  - lib/active_decorator/railtie.rb
43
144
  - lib/active_decorator/version.rb
44
145
  - lib/active_decorator/view_context.rb
146
+ - lib/generators/rails/USAGE
45
147
  - lib/generators/rails/decorator_generator.rb
46
148
  - lib/generators/rails/templates/decorator.rb
47
149
  - lib/generators/rspec/decorator_generator.rb
@@ -51,6 +153,7 @@ files:
51
153
  - test/configuration_test.rb
52
154
  - test/controllers/fake_detection_test.rb
53
155
  - test/decorator_test.rb
156
+ - test/fake_app/app/views/api/bookstores/show.json.jbuilder
54
157
  - test/fake_app/app/views/authors/index.html.erb
55
158
  - test/fake_app/app/views/authors/show.html.erb
56
159
  - test/fake_app/app/views/authors/show.json.jbuilder
@@ -66,6 +169,7 @@ files:
66
169
  - test/fake_app/app/views/books/show.html.erb
67
170
  - test/fake_app/app/views/movies/show.html.erb
68
171
  - test/fake_app/fake_app.rb
172
+ - test/features/action_controller_api_test.rb
69
173
  - test/features/action_view_helpers_test.rb
70
174
  - test/features/association_test.rb
71
175
  - test/features/controller_ivar_test.rb
@@ -74,7 +178,8 @@ files:
74
178
  - test/features/partial_test.rb
75
179
  - test/test_helper.rb
76
180
  homepage: https://github.com/amatsuda/active_decorator
77
- licenses: []
181
+ licenses:
182
+ - MIT
78
183
  metadata: {}
79
184
  post_install_message:
80
185
  rdoc_options: []
@@ -82,17 +187,17 @@ require_paths:
82
187
  - lib
83
188
  required_ruby_version: !ruby/object:Gem::Requirement
84
189
  requirements:
85
- - - '>='
190
+ - - ">="
86
191
  - !ruby/object:Gem::Version
87
192
  version: '0'
88
193
  required_rubygems_version: !ruby/object:Gem::Requirement
89
194
  requirements:
90
- - - '>='
195
+ - - ">="
91
196
  - !ruby/object:Gem::Version
92
197
  version: '0'
93
198
  requirements: []
94
199
  rubyforge_project:
95
- rubygems_version: 2.6.12
200
+ rubygems_version: 2.7.6
96
201
  signing_key:
97
202
  specification_version: 4
98
203
  summary: A simple and Rubyish view helper for Rails
@@ -100,6 +205,7 @@ test_files:
100
205
  - test/configuration_test.rb
101
206
  - test/controllers/fake_detection_test.rb
102
207
  - test/decorator_test.rb
208
+ - test/fake_app/app/views/api/bookstores/show.json.jbuilder
103
209
  - test/fake_app/app/views/authors/index.html.erb
104
210
  - test/fake_app/app/views/authors/show.html.erb
105
211
  - test/fake_app/app/views/authors/show.json.jbuilder
@@ -115,6 +221,7 @@ test_files:
115
221
  - test/fake_app/app/views/books/show.html.erb
116
222
  - test/fake_app/app/views/movies/show.html.erb
117
223
  - test/fake_app/fake_app.rb
224
+ - test/features/action_controller_api_test.rb
118
225
  - test/features/action_view_helpers_test.rb
119
226
  - test/features/association_test.rb
120
227
  - test/features/controller_ivar_test.rb