draper 4.0.2 → 4.0.4
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 +4 -4
- data/.github/workflows/ci.yml +41 -25
- data/.rspec +1 -2
- data/CHANGELOG.md +18 -0
- data/Gemfile +27 -5
- data/README.md +23 -1
- data/draper.gemspec +3 -3
- data/lib/draper/automatic_delegation.rb +14 -4
- data/lib/draper/decoratable/collection_proxy.rb +15 -0
- data/lib/draper/decoratable.rb +2 -2
- data/lib/draper/query_methods.rb +1 -1
- data/lib/draper/railtie.rb +8 -4
- data/lib/draper/version.rb +1 -1
- data/lib/draper/view_context/build_strategy.rb +1 -9
- data/lib/draper.rb +0 -6
- data/spec/draper/decoratable_spec.rb +1 -1
- data/spec/draper/decorator_spec.rb +2 -2
- data/spec/draper/factory_spec.rb +8 -8
- data/spec/draper/query_methods_spec.rb +10 -0
- data/spec/draper/view_context/build_strategy_spec.rb +1 -18
- data/spec/dummy/.rspec +0 -1
- data/spec/dummy/app/decorators/comment_decorator.rb +13 -0
- data/spec/dummy/app/decorators/mongoid_post_decorator.rb +1 -3
- data/spec/dummy/app/models/admin.rb +2 -4
- data/spec/dummy/app/models/comment.rb +3 -0
- data/spec/dummy/app/models/mongoid_post.rb +2 -4
- data/spec/dummy/app/models/post.rb +4 -0
- data/spec/dummy/app/models/user.rb +2 -4
- data/spec/dummy/config/application.rb +22 -51
- data/spec/dummy/config/environments/development.rb +65 -22
- data/spec/dummy/config/environments/production.rb +76 -33
- data/spec/dummy/config/environments/test.rb +55 -21
- data/spec/dummy/config/initializers/draper.rb +4 -2
- data/spec/dummy/db/migrate/20240907041839_create_comments.rb +9 -0
- data/spec/dummy/db/schema.rb +16 -9
- data/spec/dummy/spec/decorators/active_model_serializers_spec.rb +1 -1
- data/spec/dummy/spec/decorators/post_decorator_spec.rb +1 -1
- data/spec/dummy/spec/jobs/publish_post_job_spec.rb +2 -0
- data/spec/dummy/spec/models/post_spec.rb +41 -5
- data/spec/dummy/spec/rails_helper.rb +69 -0
- data/spec/dummy/spec/spec_helper.rb +90 -5
- data/spec/performance/benchmark.rb +1 -1
- data/spec/support/dummy_app.rb +1 -1
- metadata +22 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 78c5e444690de191d46a5be87ed46a3f9be6ec0ffd59fed6dcd1d63e5d527b85
|
4
|
+
data.tar.gz: f92be8ee42d8ce2e48c1743077f758eef779296593fcbcdef9a82fd5937a03ae
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2b2d10594f175019d7cbee9b7af7f811c8978349abae3cdce746abd94f24501d81b519c9da9ae350658265dd5aa0b33cdd9b3f18e26df922363227df8f57c4a4
|
7
|
+
data.tar.gz: 81565fd7b8034294a41c49b557f48619e6cee814056d2d4bff4c0e6f17c024877b250b421d4a185310f6b6fa3dee14b51d954b6ee3cef39100d3cfb4c9582af7
|
data/.github/workflows/ci.yml
CHANGED
@@ -2,21 +2,42 @@
|
|
2
2
|
name: CI
|
3
3
|
|
4
4
|
on:
|
5
|
-
|
6
|
-
|
5
|
+
push:
|
6
|
+
branches:
|
7
|
+
- master
|
8
|
+
pull_request:
|
9
|
+
|
10
|
+
permissions:
|
11
|
+
contents: read
|
7
12
|
|
8
13
|
jobs:
|
9
14
|
rspec:
|
10
|
-
|
15
|
+
name: >-
|
16
|
+
rspec (${{ matrix.ruby }})
|
17
|
+
|
18
|
+
runs-on: ubuntu-latest
|
19
|
+
|
11
20
|
strategy:
|
12
21
|
fail-fast: false
|
13
22
|
matrix:
|
14
23
|
ruby:
|
15
|
-
-
|
16
|
-
-
|
17
|
-
-
|
18
|
-
|
19
|
-
-
|
24
|
+
- 3.3
|
25
|
+
- 3.2
|
26
|
+
- 3.1
|
27
|
+
rails:
|
28
|
+
- 7.2
|
29
|
+
include:
|
30
|
+
# Edge
|
31
|
+
- { ruby: 'head', rails: 'edge', allow-fail: true }
|
32
|
+
# Outdated
|
33
|
+
- { ruby: '3.0', rails: '7.1' }
|
34
|
+
- { ruby: '2.7', rails: '6' } # RSpec AR Expectations support Rails 7.1 since Ruby 3.0
|
35
|
+
- { ruby: '2.6', rails: '6' }
|
36
|
+
- { ruby: '2.5', rails: '6' }
|
37
|
+
- { ruby: '2.4', rails: '5' }
|
38
|
+
|
39
|
+
env:
|
40
|
+
RAILS_VERSION: "${{ matrix.rails }}"
|
20
41
|
|
21
42
|
services:
|
22
43
|
mongodb:
|
@@ -25,31 +46,26 @@ jobs:
|
|
25
46
|
- 27017:27017
|
26
47
|
|
27
48
|
steps:
|
28
|
-
-
|
29
|
-
uses: actions/checkout@v2
|
49
|
+
- uses: actions/checkout@v4
|
30
50
|
|
31
51
|
- name: Setup Ruby
|
32
52
|
uses: ruby/setup-ruby@v1
|
33
53
|
with:
|
34
54
|
ruby-version: ${{ matrix.ruby }}
|
35
|
-
|
36
|
-
|
37
|
-
uses: actions/cache@v2
|
38
|
-
with:
|
39
|
-
path: vendor/bundle
|
40
|
-
key: ${{ runner.os }}-gems-${{ matrix.ruby }}-${{ hashFiles('**/Gemfile.lock') }}
|
41
|
-
restore-keys: |
|
42
|
-
${{ runner.os }}-gems-${{ matrix.ruby }}-
|
43
|
-
|
44
|
-
- name: Bundle
|
45
|
-
run: |
|
46
|
-
gem install bundler
|
47
|
-
bundle config path vendor/bundle
|
48
|
-
bundle install --jobs 4 --retry 3
|
55
|
+
rubygems: latest
|
56
|
+
bundler-cache: true
|
49
57
|
|
50
58
|
- name: RSpec & publish code coverage
|
51
|
-
uses: paambaati/codeclimate-action@
|
59
|
+
uses: paambaati/codeclimate-action@v8
|
52
60
|
env:
|
53
61
|
CC_TEST_REPORTER_ID: b7ba588af2a540fa96c267b3655a2afe31ea29976dc25905a668dd28d5e88915
|
54
62
|
with:
|
55
63
|
coverageCommand: bin/rake
|
64
|
+
continue-on-error: ${{ matrix.allow-fail }}
|
65
|
+
id: test
|
66
|
+
|
67
|
+
- name: >-
|
68
|
+
Test ${{ steps.test.outcome }}
|
69
|
+
run: |
|
70
|
+
echo Ruby ${{ matrix.ruby }}
|
71
|
+
echo Rails ${{ matrix.rails }}
|
data/.rspec
CHANGED
@@ -1,2 +1 @@
|
|
1
|
-
--
|
2
|
-
--order rand
|
1
|
+
--format progress
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,23 @@
|
|
1
1
|
# Draper Changelog
|
2
2
|
|
3
|
+
## 4.0.4 - 2025-01-28
|
4
|
+
|
5
|
+
### Fixes
|
6
|
+
* Fix a `LoadError` caused by a cherry-pick issue in version 4.0.3
|
7
|
+
|
8
|
+
## 4.0.3 - 2025-01-27
|
9
|
+
|
10
|
+
Added support for latest Ruby (upto 3.4) and Rails (upto 8) versions.
|
11
|
+
|
12
|
+
### Fixes
|
13
|
+
* Fix `CollectionDecorator#respond_to?` for non-ORM collections [#920](https://github.com/drapergem/draper/pull/920)
|
14
|
+
* Fix issues with using Draper outside of controller scope [#927](https://github.com/drapergem/draper/pull/927)
|
15
|
+
* Fix decoration of AR associations [#932](https://github.com/drapergem/draper/pull/932)
|
16
|
+
|
17
|
+
### Other Changes
|
18
|
+
* Improve performance of delegation via `delegate_all` [#911](https://github.com/drapergem/draper/pull/911)
|
19
|
+
* Improve README [#878](https://github.com/drapergem/draper/pull/878), [#922](https://github.com/drapergem/draper/pull/922), [#934](https://github.com/drapergem/draper/pull/934)
|
20
|
+
|
3
21
|
## 4.0.2 - 2021-05-27
|
4
22
|
|
5
23
|
### Fixes
|
data/Gemfile
CHANGED
@@ -2,6 +2,8 @@ source "https://rubygems.org"
|
|
2
2
|
|
3
3
|
gemspec
|
4
4
|
|
5
|
+
gem 'puma'
|
6
|
+
|
5
7
|
platforms :ruby do
|
6
8
|
if RUBY_VERSION >= "2.5.0"
|
7
9
|
gem 'sqlite3'
|
@@ -15,10 +17,30 @@ platforms :jruby do
|
|
15
17
|
gem "activerecord-jdbcsqlite3-adapter"
|
16
18
|
end
|
17
19
|
|
18
|
-
|
19
|
-
|
20
|
-
gem '
|
20
|
+
case rails_version = ENV['RAILS_VERSION']
|
21
|
+
when nil
|
22
|
+
gem 'rails'
|
23
|
+
when 'edge'
|
24
|
+
gem 'rails', github: 'rails/rails'
|
21
25
|
else
|
22
|
-
gem
|
26
|
+
gem 'rails', "~> #{rails_version}.0"
|
27
|
+
end
|
28
|
+
|
29
|
+
gem 'mongoid' unless
|
30
|
+
rails_version == 'edge'
|
31
|
+
gem 'active_model_serializers'
|
32
|
+
|
33
|
+
case RUBY_VERSION
|
34
|
+
when '2.6'...'3.0'
|
35
|
+
gem "turbo-rails", "<= 2.0.7"
|
36
|
+
gem "redis", "~> 4.0"
|
37
|
+
when '3.0'...'4'
|
38
|
+
gem 'turbo-rails'
|
39
|
+
gem 'redis', '~> 4.0'
|
40
|
+
end
|
41
|
+
|
42
|
+
if RUBY_VERSION < "2.5.0"
|
43
|
+
gem 'rspec-activerecord-expectations', '~> 1.2.0'
|
44
|
+
gem 'simplecov', '0.17.1'
|
45
|
+
gem "loofah", "< 2.21.0" # Workaround for `uninitialized constant Nokogiri::HTML4`
|
23
46
|
end
|
24
|
-
gem "mongoid", github: "mongodb/mongoid"
|
data/README.md
CHANGED
@@ -131,6 +131,17 @@ class ArticleDecorator < Draper::Decorator
|
|
131
131
|
end
|
132
132
|
```
|
133
133
|
|
134
|
+
|
135
|
+
To decorate a model in a namespace e.g. `Admin::Catalogue` place the decorator under the
|
136
|
+
directory `app/decorators/admin` in the same way you would with views and models.
|
137
|
+
|
138
|
+
```ruby
|
139
|
+
# app/decorators/admin/catalogue_decorator.rb
|
140
|
+
class Admin::CatalogueDecorator < Draper::Decorator
|
141
|
+
# ...
|
142
|
+
end
|
143
|
+
```
|
144
|
+
|
134
145
|
### Generators
|
135
146
|
|
136
147
|
To create an `ApplicationDecorator` that all generated decorators inherit from, run...
|
@@ -155,6 +166,15 @@ rails generate decorator Article
|
|
155
166
|
|
156
167
|
...to create the `ArticleDecorator`.
|
157
168
|
|
169
|
+
If you don't want Rails to generate decorator files when generating a new controller,
|
170
|
+
you can add the following configuration to your `config/application.rb` file:
|
171
|
+
|
172
|
+
```ruby
|
173
|
+
config.generators do |g|
|
174
|
+
g.decorator false
|
175
|
+
end
|
176
|
+
```
|
177
|
+
|
158
178
|
### Accessing Helpers
|
159
179
|
|
160
180
|
Normal Rails helpers are still useful for lots of tasks. Both Rails' provided
|
@@ -664,7 +684,8 @@ great community of open source
|
|
664
684
|
|
665
685
|
### Current maintainers
|
666
686
|
|
667
|
-
*
|
687
|
+
* Alexander Senko (Alexander.Senko@gmail.com)
|
688
|
+
* Yuji Yaginuma (yuuji.yaginuma@gmail.com)
|
668
689
|
|
669
690
|
### Historical maintainers
|
670
691
|
|
@@ -673,3 +694,4 @@ great community of open source
|
|
673
694
|
* Vasiliy Ermolovich
|
674
695
|
* Andrew Haines
|
675
696
|
* Sean Linsley
|
697
|
+
* Cliff Braton (cliff.braton@gmail.com)
|
data/draper.gemspec
CHANGED
@@ -5,7 +5,7 @@ Gem::Specification.new do |s|
|
|
5
5
|
s.version = Draper::VERSION
|
6
6
|
s.authors = ["Jeff Casimir", "Steve Klabnik"]
|
7
7
|
s.email = ["jeff@casimircreative.com", "steve@steveklabnik.com"]
|
8
|
-
s.homepage = "
|
8
|
+
s.homepage = "https://github.com/drapergem/draper"
|
9
9
|
s.summary = "View Models for Rails"
|
10
10
|
s.description = "Draper adds an object-oriented layer of presentation logic to your Rails apps."
|
11
11
|
s.license = "MIT"
|
@@ -26,9 +26,9 @@ Gem::Specification.new do |s|
|
|
26
26
|
s.add_development_dependency 'ammeter'
|
27
27
|
s.add_development_dependency 'rake'
|
28
28
|
s.add_development_dependency 'rspec-rails'
|
29
|
+
s.add_development_dependency 'rspec-activerecord-expectations'
|
29
30
|
s.add_development_dependency 'minitest-rails'
|
30
31
|
s.add_development_dependency 'capybara'
|
31
|
-
s.add_development_dependency 'active_model_serializers', '>= 0.10'
|
32
32
|
s.add_development_dependency 'rubocop'
|
33
|
-
s.add_development_dependency 'simplecov'
|
33
|
+
s.add_development_dependency 'simplecov'
|
34
34
|
end
|
@@ -18,11 +18,21 @@ module Draper
|
|
18
18
|
super || delegatable?(method)
|
19
19
|
end
|
20
20
|
|
21
|
-
#
|
22
|
-
|
23
|
-
|
21
|
+
# The inherit argument for `private_method_defined?` is supported since Ruby 2.6.
|
22
|
+
if RUBY_VERSION >= "2.6"
|
23
|
+
# @private
|
24
|
+
def delegatable?(method)
|
25
|
+
return if self.class.private_method_defined?(method, false)
|
24
26
|
|
25
|
-
|
27
|
+
object.respond_to?(method)
|
28
|
+
end
|
29
|
+
else
|
30
|
+
# @private
|
31
|
+
def delegatable?(method)
|
32
|
+
return if private_methods(false).include?(method)
|
33
|
+
|
34
|
+
object.respond_to?(method)
|
35
|
+
end
|
26
36
|
end
|
27
37
|
|
28
38
|
module ClassMethods
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Draper
|
2
|
+
module Decoratable
|
3
|
+
module CollectionProxy
|
4
|
+
# Decorates a collection of objects. Used at the end of a scope chain.
|
5
|
+
#
|
6
|
+
# @example
|
7
|
+
# company.products.popular.decorate
|
8
|
+
# @param [Hash] options
|
9
|
+
# see {Decorator.decorate_collection}.
|
10
|
+
def decorate(options = {})
|
11
|
+
decorator_class.decorate_collection(load_target, options.reverse_merge(with: nil))
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
data/lib/draper/decoratable.rb
CHANGED
@@ -11,6 +11,8 @@ module Draper
|
|
11
11
|
extend ActiveSupport::Concern
|
12
12
|
include Draper::Decoratable::Equality
|
13
13
|
|
14
|
+
autoload :CollectionProxy, 'draper/decoratable/collection_proxy'
|
15
|
+
|
14
16
|
# Decorates the object using the inferred {#decorator_class}.
|
15
17
|
# @param [Hash] options
|
16
18
|
# see {Decorator#initialize}
|
@@ -87,8 +89,6 @@ module Draper
|
|
87
89
|
def ===(other)
|
88
90
|
super || (other.is_a?(Draper::Decorator) && super(other.object))
|
89
91
|
end
|
90
|
-
|
91
92
|
end
|
92
|
-
|
93
93
|
end
|
94
94
|
end
|
data/lib/draper/query_methods.rb
CHANGED
data/lib/draper/railtie.rb
CHANGED
@@ -33,10 +33,14 @@ module Draper
|
|
33
33
|
end
|
34
34
|
|
35
35
|
initializer 'draper.setup_orm' do
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
36
|
+
ActiveSupport.on_load :active_record do
|
37
|
+
include Draper::Decoratable
|
38
|
+
|
39
|
+
ActiveRecord::Associations::CollectionProxy.include Draper::Decoratable::CollectionProxy
|
40
|
+
end
|
41
|
+
|
42
|
+
ActiveSupport.on_load :mongoid do
|
43
|
+
include Draper::Decoratable
|
40
44
|
end
|
41
45
|
end
|
42
46
|
|
data/lib/draper/version.rb
CHANGED
@@ -38,17 +38,9 @@ module Draper
|
|
38
38
|
def controller
|
39
39
|
Draper::ViewContext.controller ||= Draper.default_controller.new
|
40
40
|
Draper::ViewContext.controller.tap do |controller|
|
41
|
-
controller.request ||=
|
41
|
+
controller.request ||= ActionDispatch::TestRequest.create
|
42
42
|
end
|
43
43
|
end
|
44
|
-
|
45
|
-
def new_test_request(controller)
|
46
|
-
is_above_rails_5_1 ? ActionController::TestRequest.create(controller) : ActionController::TestRequest.create
|
47
|
-
end
|
48
|
-
|
49
|
-
def is_above_rails_5_1
|
50
|
-
ActionController::TestRequest.method(:create).parameters.first == [:req, :controller_class]
|
51
|
-
end
|
52
44
|
end
|
53
45
|
end
|
54
46
|
end
|
data/lib/draper.rb
CHANGED
@@ -51,12 +51,6 @@ module Draper
|
|
51
51
|
end
|
52
52
|
end
|
53
53
|
|
54
|
-
def self.setup_orm(base)
|
55
|
-
base.class_eval do
|
56
|
-
include Draper::Decoratable
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
54
|
class UninferrableDecoratorError < NameError
|
61
55
|
def initialize(klass)
|
62
56
|
super("Could not infer a decorator for #{klass}.")
|
@@ -147,7 +147,7 @@ module Draper
|
|
147
147
|
scoped = [Product.new]
|
148
148
|
allow(Product).to receive(:all).and_return(scoped)
|
149
149
|
|
150
|
-
expect(Product.decorator_class).to receive(:decorate_collection).with(scoped, with: nil).and_return(:decorated_collection)
|
150
|
+
expect(Product.decorator_class).to receive(:decorate_collection).with(scoped, {with: nil}).and_return(:decorated_collection)
|
151
151
|
expect(Product.decorate).to be :decorated_collection
|
152
152
|
end
|
153
153
|
|
@@ -118,7 +118,7 @@ module Draper
|
|
118
118
|
it "creates a CollectionDecorator using itself for each item" do
|
119
119
|
object = [Model.new]
|
120
120
|
|
121
|
-
expect(CollectionDecorator).to receive(:new).with(object, with: Decorator)
|
121
|
+
expect(CollectionDecorator).to receive(:new).with(object, {with: Decorator})
|
122
122
|
Decorator.decorate_collection(object)
|
123
123
|
end
|
124
124
|
|
@@ -134,7 +134,7 @@ module Draper
|
|
134
134
|
it "creates a custom collection decorator using itself for each item" do
|
135
135
|
object = [Model.new]
|
136
136
|
|
137
|
-
expect(ProductsDecorator).to receive(:new).with(object, with: ProductDecorator)
|
137
|
+
expect(ProductsDecorator).to receive(:new).with(object, {with: ProductDecorator})
|
138
138
|
ProductDecorator.decorate_collection(object)
|
139
139
|
end
|
140
140
|
|
data/spec/draper/factory_spec.rb
CHANGED
@@ -73,17 +73,17 @@ module Draper
|
|
73
73
|
worker = ->(*){}
|
74
74
|
allow(Factory::Worker).to receive_messages new: worker
|
75
75
|
|
76
|
-
expect(worker).to receive(:call).with(baz: "qux", context: {foo: "bar"})
|
76
|
+
expect(worker).to receive(:call).with({baz: "qux", context: {foo: "bar"}})
|
77
77
|
factory.decorate(double, {baz: "qux"})
|
78
78
|
end
|
79
79
|
|
80
80
|
it "is overridden by explicitly-specified context" do
|
81
|
-
factory = Factory.new(context: {foo: "bar"})
|
81
|
+
factory = Factory.new({context: {foo: "bar"}})
|
82
82
|
worker = ->(*){}
|
83
83
|
allow(Factory::Worker).to receive_messages new: worker
|
84
84
|
|
85
|
-
expect(worker).to receive(:call).with(context: {baz: "qux"})
|
86
|
-
factory.decorate(double, context: {baz: "qux"})
|
85
|
+
expect(worker).to receive(:call).with({context: {baz: "qux"}})
|
86
|
+
factory.decorate(double, {context: {baz: "qux"}})
|
87
87
|
end
|
88
88
|
end
|
89
89
|
end
|
@@ -109,7 +109,7 @@ module Draper
|
|
109
109
|
allow(worker).to receive_messages decorator: decorator
|
110
110
|
context = {foo: "bar"}
|
111
111
|
|
112
|
-
expect(decorator).to receive(:call).with(anything(), context: context)
|
112
|
+
expect(decorator).to receive(:call).with(anything(), {context: context})
|
113
113
|
worker.call(context: ->{ context })
|
114
114
|
end
|
115
115
|
|
@@ -140,7 +140,7 @@ module Draper
|
|
140
140
|
allow(worker).to receive_messages decorator: decorator
|
141
141
|
context = {foo: "bar"}
|
142
142
|
|
143
|
-
expect(decorator).to receive(:call).with(anything(), context: context)
|
143
|
+
expect(decorator).to receive(:call).with(anything(), {context: context})
|
144
144
|
worker.call(context: context)
|
145
145
|
end
|
146
146
|
end
|
@@ -150,7 +150,7 @@ module Draper
|
|
150
150
|
decorator = ->(*){}
|
151
151
|
allow(worker).to receive_messages decorator: decorator
|
152
152
|
|
153
|
-
expect(decorator).to receive(:call).with(anything(), foo: "bar")
|
153
|
+
expect(decorator).to receive(:call).with(anything(), {foo: "bar"})
|
154
154
|
worker.call(foo: "bar", context_args: [])
|
155
155
|
end
|
156
156
|
end
|
@@ -228,7 +228,7 @@ module Draper
|
|
228
228
|
allow(object).to receive(:decorate){ nil }
|
229
229
|
worker = Factory::Worker.new(nil, object)
|
230
230
|
|
231
|
-
expect(decorator_class).to receive(:decorate_collection).with(object, foo: "bar", with: nil).and_return(:decorated)
|
231
|
+
expect(decorator_class).to receive(:decorate_collection).with(object, {foo: "bar", with: nil}).and_return(:decorated)
|
232
232
|
expect(worker.decorator.call(object, foo: "bar")).to be :decorated
|
233
233
|
end
|
234
234
|
end
|
@@ -53,14 +53,24 @@ module Draper
|
|
53
53
|
context 'when strategy allows collection to call the method' do
|
54
54
|
before do
|
55
55
|
allow(fake_strategy).to receive(:allowed?).with(:some_query_method).and_return(true)
|
56
|
+
allow(collection).to receive(:respond_to?).with(:some_query_method).and_return(true)
|
56
57
|
end
|
57
58
|
|
58
59
|
it { is_expected.to eq(true) }
|
60
|
+
|
61
|
+
context 'and collection does not implement the method' do
|
62
|
+
before do
|
63
|
+
allow(collection).to receive(:respond_to?).with(:some_query_method).and_return(false)
|
64
|
+
end
|
65
|
+
|
66
|
+
it { is_expected.to eq(false) }
|
67
|
+
end
|
59
68
|
end
|
60
69
|
|
61
70
|
context 'when strategy does not allow collection to call the method' do
|
62
71
|
before do
|
63
72
|
allow(fake_strategy).to receive(:allowed?).with(:some_query_method).and_return(false)
|
73
|
+
allow(collection).to receive(:respond_to?).with(:some_query_method).and_return(true)
|
64
74
|
end
|
65
75
|
|
66
76
|
it { is_expected.to eq(false) }
|
@@ -37,7 +37,7 @@ module Draper
|
|
37
37
|
|
38
38
|
expect(controller.request).to be_nil
|
39
39
|
strategy.call
|
40
|
-
expect(controller.request).to be_an
|
40
|
+
expect(controller.request).to be_an ActionDispatch::TestRequest
|
41
41
|
expect(controller.params).to be_empty
|
42
42
|
|
43
43
|
# sanity checks
|
@@ -45,23 +45,6 @@ module Draper
|
|
45
45
|
expect(controller.view_context.params).to be controller.params
|
46
46
|
end
|
47
47
|
|
48
|
-
it "compatible with rails 5.1 change on ActionController::TestRequest.create method" do
|
49
|
-
ActionController::TestRequest.class_eval do
|
50
|
-
if ActionController::TestRequest.method(:create).parameters.first == []
|
51
|
-
def create controller_class
|
52
|
-
create
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
56
|
-
controller = Class.new(ActionController::Base).new
|
57
|
-
allow(ViewContext).to receive_messages controller: controller
|
58
|
-
strategy = ViewContext::BuildStrategy::Full.new
|
59
|
-
|
60
|
-
expect(controller.request).to be_nil
|
61
|
-
strategy.call
|
62
|
-
expect(controller.request).to be_an ActionController::TestRequest
|
63
|
-
end
|
64
|
-
|
65
48
|
it "adds methods to the view context from the constructor block" do
|
66
49
|
allow(ViewContext).to receive(:controller).and_return(fake_controller)
|
67
50
|
strategy = ViewContext::BuildStrategy::Full.new do
|
data/spec/dummy/.rspec
CHANGED
@@ -0,0 +1,13 @@
|
|
1
|
+
class CommentDecorator < Draper::Decorator
|
2
|
+
delegate_all
|
3
|
+
|
4
|
+
# Define presentation-specific methods here. Helpers are accessed through
|
5
|
+
# `helpers` (aka `h`). You can override attributes, for example:
|
6
|
+
#
|
7
|
+
# def created_at
|
8
|
+
# helpers.content_tag :span, class: 'time' do
|
9
|
+
# object.created_at.strftime("%a %m/%d/%y")
|
10
|
+
# end
|
11
|
+
# end
|
12
|
+
|
13
|
+
end
|