active_decorator 0.8.0 → 1.4.0
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 +5 -5
- data/.gitignore +2 -0
- data/.travis.yml +92 -25
- data/CHANGELOG.md +52 -0
- data/Gemfile +1 -6
- data/README.md +68 -49
- data/Rakefile +5 -1
- data/active_decorator.gemspec +15 -4
- data/gemfiles/Gemfile-rails.4.2.x +4 -5
- data/gemfiles/Gemfile-rails.5.0.x +3 -5
- data/gemfiles/Gemfile-rails.5.1.x +6 -0
- data/gemfiles/Gemfile-rails.5.2.x +7 -0
- data/gemfiles/Gemfile-rails.6.0.x +7 -0
- data/gemfiles/Gemfile-rails.6.1.x +8 -0
- data/gemfiles/Gemfile-rails.edge +18 -0
- data/lib/active_decorator/config.rb +8 -1
- data/lib/active_decorator/decorated.rb +5 -0
- data/lib/active_decorator/decorator.rb +52 -20
- data/lib/active_decorator/helpers.rb +21 -7
- data/lib/active_decorator/monkey/abstract_controller/rendering.rb +3 -0
- data/lib/active_decorator/monkey/action_controller/base/rescue_from.rb +5 -2
- data/lib/active_decorator/monkey/action_view/collection_renderer.rb +12 -0
- data/lib/active_decorator/monkey/action_view/object_renderer.rb +12 -0
- data/lib/active_decorator/monkey/action_view/partial_renderer.rb +22 -8
- data/lib/active_decorator/monkey/active_record/associations.rb +61 -0
- data/lib/active_decorator/railtie.rb +36 -2
- data/lib/active_decorator/version.rb +2 -1
- data/lib/active_decorator/view_context.rb +19 -21
- data/lib/active_decorator.rb +6 -1
- data/lib/generators/rails/USAGE +8 -0
- data/lib/generators/rails/decorator_generator.rb +4 -13
- data/lib/generators/rails/templates/decorator.rb +2 -0
- data/lib/generators/rspec/decorator_generator.rb +7 -4
- data/lib/generators/rspec/templates/decorator_spec.rb +4 -2
- data/lib/generators/test_unit/decorator_generator.rb +8 -4
- data/lib/generators/test_unit/templates/decorator_test.rb +4 -2
- metadata +133 -57
- data/gemfiles/Gemfile-rails.3.2.x +0 -11
- data/gemfiles/Gemfile-rails.4.0.x +0 -9
- data/gemfiles/Gemfile-rails.4.1.x +0 -9
- data/test/configuration_test.rb +0 -27
- data/test/controllers/fake_detection_test.rb +0 -9
- data/test/fake_app/app/views/authors/index.html.erb +0 -16
- data/test/fake_app/app/views/authors/show.html.erb +0 -2
- data/test/fake_app/app/views/authors/show.json.jbuilder +0 -3
- data/test/fake_app/app/views/book_mailer/thanks.text.erb +0 -1
- data/test/fake_app/app/views/books/_book.html.erb +0 -2
- data/test/fake_app/app/views/books/_book.json.jbuilder +0 -3
- data/test/fake_app/app/views/books/_book_locals.html.erb +0 -2
- data/test/fake_app/app/views/books/errata.html.erb +0 -1
- data/test/fake_app/app/views/books/error.html.erb +0 -1
- data/test/fake_app/app/views/books/index.html.erb +0 -4
- data/test/fake_app/app/views/books/purchase.html.erb +0 -1
- data/test/fake_app/app/views/books/show.html.erb +0 -4
- data/test/fake_app/app/views/movies/show.html.erb +0 -1
- data/test/fake_app/fake_app.rb +0 -198
- data/test/features/action_view_helpers_test.rb +0 -37
- data/test/features/controller_ivar_test.rb +0 -40
- data/test/features/jbuilder_test.rb +0 -15
- data/test/features/name_error_handling_test.rb +0 -17
- data/test/features/partial_test.rb +0 -28
- data/test/test_helper.rb +0 -30
metadata
CHANGED
|
@@ -1,15 +1,127 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: active_decorator
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version:
|
|
4
|
+
version: 1.4.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Akira Matsuda
|
|
8
|
-
autorequire:
|
|
8
|
+
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
12
|
-
dependencies:
|
|
11
|
+
date: 2021-05-09 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: activesupport
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - ">="
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '0'
|
|
20
|
+
type: :runtime
|
|
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: test-unit-rails
|
|
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: selenium-webdriver
|
|
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: puma
|
|
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: capybara
|
|
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: sqlite3
|
|
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: rake
|
|
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'
|
|
111
|
+
- !ruby/object:Gem::Dependency
|
|
112
|
+
name: byebug
|
|
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'
|
|
13
125
|
description: A simple and Rubyish view helper for Rails
|
|
14
126
|
email:
|
|
15
127
|
- ronnie@dio.jp
|
|
@@ -19,58 +131,45 @@ extra_rdoc_files: []
|
|
|
19
131
|
files:
|
|
20
132
|
- ".gitignore"
|
|
21
133
|
- ".travis.yml"
|
|
134
|
+
- CHANGELOG.md
|
|
22
135
|
- Gemfile
|
|
23
136
|
- MIT-LICENSE
|
|
24
137
|
- README.md
|
|
25
138
|
- Rakefile
|
|
26
139
|
- active_decorator.gemspec
|
|
27
|
-
- gemfiles/Gemfile-rails.3.2.x
|
|
28
|
-
- gemfiles/Gemfile-rails.4.0.x
|
|
29
|
-
- gemfiles/Gemfile-rails.4.1.x
|
|
30
140
|
- gemfiles/Gemfile-rails.4.2.x
|
|
31
141
|
- gemfiles/Gemfile-rails.5.0.x
|
|
142
|
+
- gemfiles/Gemfile-rails.5.1.x
|
|
143
|
+
- gemfiles/Gemfile-rails.5.2.x
|
|
144
|
+
- gemfiles/Gemfile-rails.6.0.x
|
|
145
|
+
- gemfiles/Gemfile-rails.6.1.x
|
|
146
|
+
- gemfiles/Gemfile-rails.edge
|
|
32
147
|
- lib/active_decorator.rb
|
|
33
148
|
- lib/active_decorator/config.rb
|
|
149
|
+
- lib/active_decorator/decorated.rb
|
|
34
150
|
- lib/active_decorator/decorator.rb
|
|
35
151
|
- lib/active_decorator/helpers.rb
|
|
36
152
|
- lib/active_decorator/monkey/abstract_controller/rendering.rb
|
|
37
153
|
- lib/active_decorator/monkey/action_controller/base/rescue_from.rb
|
|
154
|
+
- lib/active_decorator/monkey/action_view/collection_renderer.rb
|
|
155
|
+
- lib/active_decorator/monkey/action_view/object_renderer.rb
|
|
38
156
|
- lib/active_decorator/monkey/action_view/partial_renderer.rb
|
|
157
|
+
- lib/active_decorator/monkey/active_record/associations.rb
|
|
39
158
|
- lib/active_decorator/railtie.rb
|
|
40
159
|
- lib/active_decorator/version.rb
|
|
41
160
|
- lib/active_decorator/view_context.rb
|
|
161
|
+
- lib/generators/rails/USAGE
|
|
42
162
|
- lib/generators/rails/decorator_generator.rb
|
|
43
163
|
- lib/generators/rails/templates/decorator.rb
|
|
44
164
|
- lib/generators/rspec/decorator_generator.rb
|
|
45
165
|
- lib/generators/rspec/templates/decorator_spec.rb
|
|
46
166
|
- lib/generators/test_unit/decorator_generator.rb
|
|
47
167
|
- lib/generators/test_unit/templates/decorator_test.rb
|
|
48
|
-
- test/configuration_test.rb
|
|
49
|
-
- test/controllers/fake_detection_test.rb
|
|
50
|
-
- test/fake_app/app/views/authors/index.html.erb
|
|
51
|
-
- test/fake_app/app/views/authors/show.html.erb
|
|
52
|
-
- test/fake_app/app/views/authors/show.json.jbuilder
|
|
53
|
-
- test/fake_app/app/views/book_mailer/thanks.text.erb
|
|
54
|
-
- test/fake_app/app/views/books/_book.html.erb
|
|
55
|
-
- test/fake_app/app/views/books/_book.json.jbuilder
|
|
56
|
-
- test/fake_app/app/views/books/_book_locals.html.erb
|
|
57
|
-
- test/fake_app/app/views/books/errata.html.erb
|
|
58
|
-
- test/fake_app/app/views/books/error.html.erb
|
|
59
|
-
- test/fake_app/app/views/books/index.html.erb
|
|
60
|
-
- test/fake_app/app/views/books/purchase.html.erb
|
|
61
|
-
- test/fake_app/app/views/books/show.html.erb
|
|
62
|
-
- test/fake_app/app/views/movies/show.html.erb
|
|
63
|
-
- test/fake_app/fake_app.rb
|
|
64
|
-
- test/features/action_view_helpers_test.rb
|
|
65
|
-
- test/features/controller_ivar_test.rb
|
|
66
|
-
- test/features/jbuilder_test.rb
|
|
67
|
-
- test/features/name_error_handling_test.rb
|
|
68
|
-
- test/features/partial_test.rb
|
|
69
|
-
- test/test_helper.rb
|
|
70
168
|
homepage: https://github.com/amatsuda/active_decorator
|
|
71
|
-
licenses:
|
|
169
|
+
licenses:
|
|
170
|
+
- MIT
|
|
72
171
|
metadata: {}
|
|
73
|
-
post_install_message:
|
|
172
|
+
post_install_message:
|
|
74
173
|
rdoc_options: []
|
|
75
174
|
require_paths:
|
|
76
175
|
- lib
|
|
@@ -85,31 +184,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
85
184
|
- !ruby/object:Gem::Version
|
|
86
185
|
version: '0'
|
|
87
186
|
requirements: []
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
signing_key:
|
|
187
|
+
rubygems_version: 3.3.0.dev
|
|
188
|
+
signing_key:
|
|
91
189
|
specification_version: 4
|
|
92
190
|
summary: A simple and Rubyish view helper for Rails
|
|
93
|
-
test_files:
|
|
94
|
-
- test/configuration_test.rb
|
|
95
|
-
- test/controllers/fake_detection_test.rb
|
|
96
|
-
- test/fake_app/app/views/authors/index.html.erb
|
|
97
|
-
- test/fake_app/app/views/authors/show.html.erb
|
|
98
|
-
- test/fake_app/app/views/authors/show.json.jbuilder
|
|
99
|
-
- test/fake_app/app/views/book_mailer/thanks.text.erb
|
|
100
|
-
- test/fake_app/app/views/books/_book.html.erb
|
|
101
|
-
- test/fake_app/app/views/books/_book.json.jbuilder
|
|
102
|
-
- test/fake_app/app/views/books/_book_locals.html.erb
|
|
103
|
-
- test/fake_app/app/views/books/errata.html.erb
|
|
104
|
-
- test/fake_app/app/views/books/error.html.erb
|
|
105
|
-
- test/fake_app/app/views/books/index.html.erb
|
|
106
|
-
- test/fake_app/app/views/books/purchase.html.erb
|
|
107
|
-
- test/fake_app/app/views/books/show.html.erb
|
|
108
|
-
- test/fake_app/app/views/movies/show.html.erb
|
|
109
|
-
- test/fake_app/fake_app.rb
|
|
110
|
-
- test/features/action_view_helpers_test.rb
|
|
111
|
-
- test/features/controller_ivar_test.rb
|
|
112
|
-
- test/features/jbuilder_test.rb
|
|
113
|
-
- test/features/name_error_handling_test.rb
|
|
114
|
-
- test/features/partial_test.rb
|
|
115
|
-
- test/test_helper.rb
|
|
191
|
+
test_files: []
|
data/test/configuration_test.rb
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
require 'test_helper'
|
|
3
|
-
|
|
4
|
-
Comic = Struct.new(:title, :price)
|
|
5
|
-
|
|
6
|
-
module ComicPresenter
|
|
7
|
-
def price
|
|
8
|
-
"$#{super}"
|
|
9
|
-
end
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
class ConfigurationTest < Test::Unit::TestCase
|
|
13
|
-
test 'with a custom decorator_suffix' do
|
|
14
|
-
begin
|
|
15
|
-
ActiveDecorator.configure do |config|
|
|
16
|
-
config.decorator_suffix = 'Presenter'
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
comic = ActiveDecorator::Decorator.instance.decorate Comic.new("amatsuda's (Poignant) Guide to ActiveDecorator", 3)
|
|
20
|
-
assert_equal '$3', comic.price
|
|
21
|
-
ensure
|
|
22
|
-
ActiveDecorator.configure do |config|
|
|
23
|
-
config.decorator_suffix = 'Decorator'
|
|
24
|
-
end
|
|
25
|
-
end
|
|
26
|
-
end
|
|
27
|
-
end
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
<% @authors.each do |author| %>
|
|
2
|
-
<%= author.name %>
|
|
3
|
-
<%= author.reverse_name %>
|
|
4
|
-
|
|
5
|
-
<% if params[:partial] == 'collection' %>
|
|
6
|
-
<%= render author.books %>
|
|
7
|
-
<% elsif params[:partial] == 'locals' %>
|
|
8
|
-
<% author.books.each do |book| %>
|
|
9
|
-
<%= render partial: 'books/book_locals', locals: {b: book} %>
|
|
10
|
-
<% end %>
|
|
11
|
-
<% else %>
|
|
12
|
-
<% author.books.each do |book| %>
|
|
13
|
-
<%= render book %>
|
|
14
|
-
<% end %>
|
|
15
|
-
<% end %>
|
|
16
|
-
<% end %>
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
Thank you for purchasing <%= @book.upcased_title %>.
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
<%= @book.errata %>
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
<%= @book.error %>
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
done
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
<%= @movie.name %>
|
data/test/fake_app/fake_app.rb
DELETED
|
@@ -1,198 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
require 'active_record'
|
|
3
|
-
require 'action_controller/railtie'
|
|
4
|
-
require 'action_mailer/railtie'
|
|
5
|
-
require 'action_view/railtie'
|
|
6
|
-
require 'ostruct'
|
|
7
|
-
require 'jbuilder'
|
|
8
|
-
|
|
9
|
-
# config
|
|
10
|
-
ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: ':memory:')
|
|
11
|
-
|
|
12
|
-
module ActiveDecoratorTestApp
|
|
13
|
-
class Application < Rails::Application
|
|
14
|
-
config.secret_token = '"confusion" will be my epitaph.'
|
|
15
|
-
config.session_store :cookie_store, key: '_myapp_session'
|
|
16
|
-
config.active_support.deprecation = :log
|
|
17
|
-
config.eager_load = false
|
|
18
|
-
config.action_dispatch.show_exceptions = false
|
|
19
|
-
config.root = File.dirname(__FILE__)
|
|
20
|
-
|
|
21
|
-
config.action_mailer.delivery_method = :test
|
|
22
|
-
end
|
|
23
|
-
end
|
|
24
|
-
ActiveDecoratorTestApp::Application.initialize!
|
|
25
|
-
|
|
26
|
-
# routes
|
|
27
|
-
ActiveDecoratorTestApp::Application.routes.draw do
|
|
28
|
-
resources :authors, only: [:index, :show] do
|
|
29
|
-
resources :books, only: [:index, :show] do
|
|
30
|
-
member do
|
|
31
|
-
get :errata
|
|
32
|
-
get :error
|
|
33
|
-
post :purchase
|
|
34
|
-
end
|
|
35
|
-
end
|
|
36
|
-
resources :novels, only: [:index, :show] do
|
|
37
|
-
member do
|
|
38
|
-
get :error
|
|
39
|
-
post :purchase
|
|
40
|
-
end
|
|
41
|
-
end
|
|
42
|
-
end
|
|
43
|
-
resources :movies, only: :show
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
# models
|
|
47
|
-
class Author < ActiveRecord::Base
|
|
48
|
-
has_many :books
|
|
49
|
-
end
|
|
50
|
-
class Book < ActiveRecord::Base
|
|
51
|
-
belongs_to :author
|
|
52
|
-
end
|
|
53
|
-
class Novel < Book
|
|
54
|
-
end
|
|
55
|
-
class Movie < ActiveRecord::Base
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
# helpers
|
|
59
|
-
module ApplicationHelper; end
|
|
60
|
-
|
|
61
|
-
# decorators
|
|
62
|
-
module AuthorDecorator
|
|
63
|
-
def reverse_name
|
|
64
|
-
name.reverse
|
|
65
|
-
end
|
|
66
|
-
|
|
67
|
-
def capitalized_name
|
|
68
|
-
name.capitalize
|
|
69
|
-
end
|
|
70
|
-
end
|
|
71
|
-
module BookDecorator
|
|
72
|
-
def reverse_title
|
|
73
|
-
title.reverse
|
|
74
|
-
end
|
|
75
|
-
|
|
76
|
-
def upcased_title
|
|
77
|
-
title.upcase
|
|
78
|
-
end
|
|
79
|
-
|
|
80
|
-
def link
|
|
81
|
-
link_to title, "#{request.protocol}#{request.host_with_port}/assets/sample.png", class: 'title'
|
|
82
|
-
end
|
|
83
|
-
|
|
84
|
-
def cover_image
|
|
85
|
-
image_tag 'cover.png'
|
|
86
|
-
end
|
|
87
|
-
|
|
88
|
-
def errata
|
|
89
|
-
poof!
|
|
90
|
-
end
|
|
91
|
-
|
|
92
|
-
def error
|
|
93
|
-
"ERROR"
|
|
94
|
-
end
|
|
95
|
-
end
|
|
96
|
-
|
|
97
|
-
# decorator fake
|
|
98
|
-
class MovieDecorator; end
|
|
99
|
-
|
|
100
|
-
# controllers
|
|
101
|
-
class ApplicationController < ActionController::Base
|
|
102
|
-
self.append_view_path File.dirname(__FILE__)
|
|
103
|
-
end
|
|
104
|
-
class AuthorsController < ApplicationController
|
|
105
|
-
def index
|
|
106
|
-
if Author.respond_to?(:scoped)
|
|
107
|
-
# ActiveRecord 3.x
|
|
108
|
-
if params[:variable_type] == 'array'
|
|
109
|
-
@authors = Author.all
|
|
110
|
-
elsif params[:variable_type] == 'proxy'
|
|
111
|
-
@authors = RelationProxy.new(Author.scoped)
|
|
112
|
-
else
|
|
113
|
-
@authors = Author.scoped
|
|
114
|
-
end
|
|
115
|
-
else
|
|
116
|
-
# ActiveRecord 4.x
|
|
117
|
-
if params[:variable_type] == 'array'
|
|
118
|
-
@authors = Author.all.to_a
|
|
119
|
-
elsif params[:variable_type] == 'proxy'
|
|
120
|
-
@authors = RelationProxy.new(Author.all)
|
|
121
|
-
else
|
|
122
|
-
@authors = Author.all
|
|
123
|
-
end
|
|
124
|
-
end
|
|
125
|
-
end
|
|
126
|
-
|
|
127
|
-
def show
|
|
128
|
-
@author = Author.find params[:id]
|
|
129
|
-
end
|
|
130
|
-
end
|
|
131
|
-
class BooksController < ApplicationController
|
|
132
|
-
class CustomError < StandardError; end
|
|
133
|
-
|
|
134
|
-
rescue_from CustomError do
|
|
135
|
-
render :error
|
|
136
|
-
end
|
|
137
|
-
|
|
138
|
-
def index
|
|
139
|
-
@author = Author.find params[:author_id]
|
|
140
|
-
@books = @author.books
|
|
141
|
-
end
|
|
142
|
-
|
|
143
|
-
def show
|
|
144
|
-
@book = Author.find(params[:author_id]).books.find(params[:id])
|
|
145
|
-
end
|
|
146
|
-
|
|
147
|
-
def errata
|
|
148
|
-
@book = Author.find(params[:author_id]).books.find(params[:id])
|
|
149
|
-
end
|
|
150
|
-
|
|
151
|
-
def error
|
|
152
|
-
@book = Author.find(params[:author_id]).books.find(params[:id])
|
|
153
|
-
raise CustomError, "error"
|
|
154
|
-
end
|
|
155
|
-
|
|
156
|
-
def purchase
|
|
157
|
-
@book = Author.find(params[:author_id]).books.find(params[:id])
|
|
158
|
-
|
|
159
|
-
@view_context_before_sending_mail = ActiveDecorator::ViewContext.current
|
|
160
|
-
BookMailer.thanks(@book).deliver
|
|
161
|
-
raise 'Wrong ViewContext!' if ActiveDecorator::ViewContext.current != @view_context_before_sending_mail
|
|
162
|
-
end
|
|
163
|
-
end
|
|
164
|
-
class MoviesController < ApplicationController
|
|
165
|
-
def show
|
|
166
|
-
@movie = Movie.find params[:id]
|
|
167
|
-
end
|
|
168
|
-
end
|
|
169
|
-
|
|
170
|
-
# mailers
|
|
171
|
-
class BookMailer < ActionMailer::Base
|
|
172
|
-
def thanks(book)
|
|
173
|
-
@book = book
|
|
174
|
-
mail from: 'nobody@example.com', to: 'test@example.com', subject: 'Thanks'
|
|
175
|
-
end
|
|
176
|
-
end
|
|
177
|
-
|
|
178
|
-
# migrations
|
|
179
|
-
class CreateAllTables < ActiveRecord::Migration
|
|
180
|
-
def self.up
|
|
181
|
-
create_table(:authors) {|t| t.string :name}
|
|
182
|
-
create_table(:books) {|t| t.string :title; t.references :author; t.string :type }
|
|
183
|
-
create_table(:movies) {|t| t.string :name}
|
|
184
|
-
end
|
|
185
|
-
end
|
|
186
|
-
|
|
187
|
-
# Proxy for ActiveRecord::Relation
|
|
188
|
-
class RelationProxy < BasicObject
|
|
189
|
-
attr_accessor :ar_relation
|
|
190
|
-
|
|
191
|
-
def initialize(ar_relation)
|
|
192
|
-
@ar_relation = ar_relation
|
|
193
|
-
end
|
|
194
|
-
|
|
195
|
-
def method_missing(method, *args, &block)
|
|
196
|
-
@ar_relation.public_send(method, *args, &block)
|
|
197
|
-
end
|
|
198
|
-
end
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
require 'test_helper'
|
|
3
|
-
|
|
4
|
-
class ActionViewHelpersTest < ActionDispatch::IntegrationTest
|
|
5
|
-
setup do
|
|
6
|
-
aamine = Author.create! name: 'aamine'
|
|
7
|
-
@rhg = aamine.books.create! title: 'RHG'
|
|
8
|
-
@rhg_novel = aamine.books.create! title: 'RHG Novel', type: 'Novel'
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
test 'invoking action_view helper methods' do
|
|
12
|
-
visit "/authors/#{@rhg.author.id}/books/#{@rhg.id}"
|
|
13
|
-
within 'a.title' do
|
|
14
|
-
assert page.has_content? 'RHG'
|
|
15
|
-
end
|
|
16
|
-
assert page.has_css?('img')
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
test 'invoking action_view helper methods on model subclass' do
|
|
20
|
-
visit "/authors/#{@rhg_novel.author.id}/books/#{@rhg_novel.id}"
|
|
21
|
-
within 'a.title' do
|
|
22
|
-
assert page.has_content? 'RHG Novel'
|
|
23
|
-
end
|
|
24
|
-
assert page.has_css?('img')
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
test 'invoking action_view helper methods in rescue_from view' do
|
|
28
|
-
visit "/authors/#{@rhg.author.id}/books/#{@rhg.id}/error"
|
|
29
|
-
assert page.has_content?('ERROR')
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
test 'make sure that action_view + action_mailer works' do
|
|
33
|
-
visit "/authors/#{@rhg.author.id}/books/#{@rhg.id}"
|
|
34
|
-
click_link 'purchase'
|
|
35
|
-
assert page.has_content? 'done'
|
|
36
|
-
end
|
|
37
|
-
end
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
require 'test_helper'
|
|
3
|
-
|
|
4
|
-
class ControllerIvarTest < ActionDispatch::IntegrationTest
|
|
5
|
-
setup do
|
|
6
|
-
@matz = Author.create! name: 'matz'
|
|
7
|
-
@matz.books.create! title: 'the world of code'
|
|
8
|
-
Author.create! name: 'takahashim'
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
test 'decorating a model object in ivar' do
|
|
12
|
-
visit "/authors/#{@matz.id}"
|
|
13
|
-
assert page.has_content? 'matz'
|
|
14
|
-
assert page.has_content? 'matz'.capitalize
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
test 'decorating model scope in ivar' do
|
|
18
|
-
visit '/authors'
|
|
19
|
-
assert page.has_content? 'takahashim'
|
|
20
|
-
assert page.has_content? 'takahashim'.reverse
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
test "decorating models' array in ivar" do
|
|
24
|
-
visit '/authors?variable_type=array'
|
|
25
|
-
assert page.has_content? 'takahashim'
|
|
26
|
-
assert page.has_content? 'takahashim'.reverse
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
test "decorating models' proxy object in ivar" do
|
|
30
|
-
visit '/authors?variable_type=proxy'
|
|
31
|
-
assert page.has_content? 'takahashim'
|
|
32
|
-
assert page.has_content? 'takahashim'.reverse
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
test 'decorating model association proxy in ivar' do
|
|
36
|
-
visit "/authors/#{@matz.id}/books"
|
|
37
|
-
assert page.has_content? 'the world of code'
|
|
38
|
-
assert page.has_content? 'the world of code'.reverse
|
|
39
|
-
end
|
|
40
|
-
end
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
require 'test_helper'
|
|
3
|
-
|
|
4
|
-
class JbuilderTest < ActionDispatch::IntegrationTest
|
|
5
|
-
setup do
|
|
6
|
-
Author.create! name: 'aamine'
|
|
7
|
-
nari = Author.create! name: 'nari'
|
|
8
|
-
nari.books.create! title: 'the gc book'
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
test 'decorating objects in Jbuilder partials' do
|
|
12
|
-
visit "/authors/#{Author.last.id}.json"
|
|
13
|
-
assert_equal '{"name":"nari","books":[{"title":"the gc book","reverse_title":"koob cg eht"}]}', page.source
|
|
14
|
-
end
|
|
15
|
-
end
|