draper 4.0.4 → 4.0.5
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/CHANGELOG.md +6 -0
- data/README.md +3 -6
- data/lib/draper/collection_decorator.rb +0 -6
- data/lib/draper/compatibility/broadcastable.rb +24 -0
- data/lib/draper/compatibility/global_id.rb +9 -5
- data/lib/draper/decoratable.rb +5 -0
- data/lib/draper/decorator.rb +2 -18
- data/lib/draper/railtie.rb +6 -1
- data/lib/draper/version.rb +1 -1
- metadata +4 -232
- data/.github/PULL_REQUEST_TEMPLATE.md +0 -24
- data/.github/workflows/ci.yml +0 -71
- data/.gitignore +0 -18
- data/Gemfile +0 -46
- data/bin/bundle +0 -114
- data/bin/rake +0 -29
- data/draper.gemspec +0 -34
- data/spec/draper/collection_decorator_spec.rb +0 -291
- data/spec/draper/configuration_spec.rb +0 -49
- data/spec/draper/decoratable/equality_spec.rb +0 -10
- data/spec/draper/decoratable_spec.rb +0 -235
- data/spec/draper/decorated_association_spec.rb +0 -82
- data/spec/draper/decorates_assigned_spec.rb +0 -71
- data/spec/draper/decorator_spec.rb +0 -872
- data/spec/draper/draper_spec.rb +0 -25
- data/spec/draper/factory_spec.rb +0 -247
- data/spec/draper/finders_spec.rb +0 -166
- data/spec/draper/helper_proxy_spec.rb +0 -61
- data/spec/draper/lazy_helpers_spec.rb +0 -21
- data/spec/draper/query_methods/load_strategy_spec.rb +0 -26
- data/spec/draper/query_methods_spec.rb +0 -80
- data/spec/draper/undecorate_chain_spec.rb +0 -20
- data/spec/draper/undecorate_spec.rb +0 -19
- data/spec/draper/view_context/build_strategy_spec.rb +0 -115
- data/spec/draper/view_context_spec.rb +0 -182
- data/spec/draper/view_helpers_spec.rb +0 -8
- data/spec/dummy/.rspec +0 -1
- data/spec/dummy/Rakefile +0 -7
- data/spec/dummy/app/assets/config/manifest.js +0 -3
- data/spec/dummy/app/controllers/application_controller.rb +0 -2
- data/spec/dummy/app/controllers/base_controller.rb +0 -4
- data/spec/dummy/app/controllers/localized_urls.rb +0 -5
- data/spec/dummy/app/controllers/posts_controller.rb +0 -20
- data/spec/dummy/app/decorators/comment_decorator.rb +0 -13
- data/spec/dummy/app/decorators/mongoid_post_decorator.rb +0 -2
- data/spec/dummy/app/decorators/post_decorator.rb +0 -60
- data/spec/dummy/app/helpers/application_helper.rb +0 -5
- data/spec/dummy/app/jobs/publish_post_job.rb +0 -7
- data/spec/dummy/app/mailers/application_mailer.rb +0 -3
- data/spec/dummy/app/mailers/post_mailer.rb +0 -19
- data/spec/dummy/app/models/admin.rb +0 -3
- data/spec/dummy/app/models/application_record.rb +0 -3
- data/spec/dummy/app/models/comment.rb +0 -3
- data/spec/dummy/app/models/mongoid_post.rb +0 -3
- data/spec/dummy/app/models/post.rb +0 -7
- data/spec/dummy/app/models/user.rb +0 -3
- data/spec/dummy/app/views/layouts/application.html.erb +0 -11
- data/spec/dummy/app/views/post_mailer/decorated_email.html.erb +0 -1
- data/spec/dummy/app/views/posts/_post.html.erb +0 -42
- data/spec/dummy/app/views/posts/show.html.erb +0 -1
- data/spec/dummy/bin/rails +0 -4
- data/spec/dummy/config/application.rb +0 -39
- data/spec/dummy/config/boot.rb +0 -5
- data/spec/dummy/config/database.yml +0 -25
- data/spec/dummy/config/environment.rb +0 -5
- data/spec/dummy/config/environments/development.rb +0 -78
- data/spec/dummy/config/environments/production.rb +0 -102
- data/spec/dummy/config/environments/test.rb +0 -69
- data/spec/dummy/config/initializers/backtrace_silencers.rb +0 -7
- data/spec/dummy/config/initializers/draper.rb +0 -5
- data/spec/dummy/config/initializers/filter_parameter_logging.rb +0 -4
- data/spec/dummy/config/initializers/inflections.rb +0 -15
- data/spec/dummy/config/initializers/mime_types.rb +0 -5
- data/spec/dummy/config/initializers/secret_token.rb +0 -8
- data/spec/dummy/config/initializers/session_store.rb +0 -8
- data/spec/dummy/config/locales/en.yml +0 -5
- data/spec/dummy/config/mongoid.yml +0 -142
- data/spec/dummy/config/routes.rb +0 -9
- data/spec/dummy/config/storage.yml +0 -7
- data/spec/dummy/config.ru +0 -4
- data/spec/dummy/db/migrate/20121019115657_create_posts.rb +0 -8
- data/spec/dummy/db/migrate/20240907041839_create_comments.rb +0 -9
- data/spec/dummy/db/schema.rb +0 -28
- data/spec/dummy/db/seeds.rb +0 -2
- data/spec/dummy/fast_spec/post_decorator_spec.rb +0 -37
- data/spec/dummy/lib/tasks/test.rake +0 -16
- data/spec/dummy/log/.gitkeep +0 -0
- data/spec/dummy/public/404.html +0 -26
- data/spec/dummy/public/422.html +0 -26
- data/spec/dummy/public/500.html +0 -25
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/script/rails +0 -6
- data/spec/dummy/spec/decorators/active_model_serializers_spec.rb +0 -12
- data/spec/dummy/spec/decorators/devise_spec.rb +0 -55
- data/spec/dummy/spec/decorators/helpers_spec.rb +0 -21
- data/spec/dummy/spec/decorators/post_decorator_spec.rb +0 -64
- data/spec/dummy/spec/decorators/spec_type_spec.rb +0 -7
- data/spec/dummy/spec/decorators/view_context_spec.rb +0 -22
- data/spec/dummy/spec/jobs/publish_post_job_spec.rb +0 -11
- data/spec/dummy/spec/mailers/post_mailer_spec.rb +0 -25
- data/spec/dummy/spec/models/application_spec.rb +0 -7
- data/spec/dummy/spec/models/mongoid_post_spec.rb +0 -8
- data/spec/dummy/spec/models/post_spec.rb +0 -51
- data/spec/dummy/spec/rails_helper.rb +0 -69
- data/spec/dummy/spec/shared_examples/decoratable.rb +0 -22
- data/spec/dummy/spec/spec_helper.rb +0 -93
- data/spec/dummy/test/decorators/minitest/devise_test.rb +0 -55
- data/spec/dummy/test/decorators/minitest/helpers_test.rb +0 -21
- data/spec/dummy/test/decorators/minitest/spec_type_test.rb +0 -52
- data/spec/dummy/test/decorators/minitest/view_context_test.rb +0 -24
- data/spec/dummy/test/decorators/test_unit/devise_test.rb +0 -55
- data/spec/dummy/test/decorators/test_unit/helpers_test.rb +0 -21
- data/spec/dummy/test/decorators/test_unit/view_context_test.rb +0 -24
- data/spec/dummy/test/minitest_helper.rb +0 -2
- data/spec/dummy/test/test_helper.rb +0 -3
- data/spec/generators/controller/controller_generator_spec.rb +0 -23
- data/spec/generators/decorator/decorator_generator_spec.rb +0 -93
- data/spec/generators/install/install_generator_spec.rb +0 -19
- data/spec/integration/integration_spec.rb +0 -70
- data/spec/performance/active_record.rb +0 -4
- data/spec/performance/benchmark.rb +0 -55
- data/spec/performance/decorators.rb +0 -45
- data/spec/performance/models.rb +0 -20
- data/spec/spec_helper.rb +0 -50
- data/spec/support/dummy_app.rb +0 -85
- data/spec/support/matchers/have_text.rb +0 -50
- data/spec/support/shared_examples/decoratable_equality.rb +0 -40
- data/spec/support/shared_examples/view_helpers.rb +0 -39
data/bin/bundle
DELETED
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env ruby
|
|
2
|
-
# frozen_string_literal: true
|
|
3
|
-
|
|
4
|
-
#
|
|
5
|
-
# This file was generated by Bundler.
|
|
6
|
-
#
|
|
7
|
-
# The application 'bundle' is installed as part of a gem, and
|
|
8
|
-
# this file is here to facilitate running it.
|
|
9
|
-
#
|
|
10
|
-
|
|
11
|
-
require "rubygems"
|
|
12
|
-
|
|
13
|
-
m = Module.new do
|
|
14
|
-
module_function
|
|
15
|
-
|
|
16
|
-
def invoked_as_script?
|
|
17
|
-
File.expand_path($0) == File.expand_path(__FILE__)
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
def env_var_version
|
|
21
|
-
ENV["BUNDLER_VERSION"]
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
def cli_arg_version
|
|
25
|
-
return unless invoked_as_script? # don't want to hijack other binstubs
|
|
26
|
-
return unless "update".start_with?(ARGV.first || " ") # must be running `bundle update`
|
|
27
|
-
bundler_version = nil
|
|
28
|
-
update_index = nil
|
|
29
|
-
ARGV.each_with_index do |a, i|
|
|
30
|
-
if update_index && update_index.succ == i && a =~ Gem::Version::ANCHORED_VERSION_PATTERN
|
|
31
|
-
bundler_version = a
|
|
32
|
-
end
|
|
33
|
-
next unless a =~ /\A--bundler(?:[= ](#{Gem::Version::VERSION_PATTERN}))?\z/
|
|
34
|
-
bundler_version = $1
|
|
35
|
-
update_index = i
|
|
36
|
-
end
|
|
37
|
-
bundler_version
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
def gemfile
|
|
41
|
-
gemfile = ENV["BUNDLE_GEMFILE"]
|
|
42
|
-
return gemfile if gemfile && !gemfile.empty?
|
|
43
|
-
|
|
44
|
-
File.expand_path("../../Gemfile", __FILE__)
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
def lockfile
|
|
48
|
-
lockfile =
|
|
49
|
-
case File.basename(gemfile)
|
|
50
|
-
when "gems.rb" then gemfile.sub(/\.rb$/, gemfile)
|
|
51
|
-
else "#{gemfile}.lock"
|
|
52
|
-
end
|
|
53
|
-
File.expand_path(lockfile)
|
|
54
|
-
end
|
|
55
|
-
|
|
56
|
-
def lockfile_version
|
|
57
|
-
return unless File.file?(lockfile)
|
|
58
|
-
lockfile_contents = File.read(lockfile)
|
|
59
|
-
return unless lockfile_contents =~ /\n\nBUNDLED WITH\n\s{2,}(#{Gem::Version::VERSION_PATTERN})\n/
|
|
60
|
-
Regexp.last_match(1)
|
|
61
|
-
end
|
|
62
|
-
|
|
63
|
-
def bundler_version
|
|
64
|
-
@bundler_version ||=
|
|
65
|
-
env_var_version || cli_arg_version ||
|
|
66
|
-
lockfile_version
|
|
67
|
-
end
|
|
68
|
-
|
|
69
|
-
def bundler_requirement
|
|
70
|
-
return "#{Gem::Requirement.default}.a" unless bundler_version
|
|
71
|
-
|
|
72
|
-
bundler_gem_version = Gem::Version.new(bundler_version)
|
|
73
|
-
|
|
74
|
-
requirement = bundler_gem_version.approximate_recommendation
|
|
75
|
-
|
|
76
|
-
return requirement unless Gem::Version.new(Gem::VERSION) < Gem::Version.new("2.7.0")
|
|
77
|
-
|
|
78
|
-
requirement += ".a" if bundler_gem_version.prerelease?
|
|
79
|
-
|
|
80
|
-
requirement
|
|
81
|
-
end
|
|
82
|
-
|
|
83
|
-
def load_bundler!
|
|
84
|
-
ENV["BUNDLE_GEMFILE"] ||= gemfile
|
|
85
|
-
|
|
86
|
-
activate_bundler
|
|
87
|
-
end
|
|
88
|
-
|
|
89
|
-
def activate_bundler
|
|
90
|
-
gem_error = activation_error_handling do
|
|
91
|
-
gem "bundler", bundler_requirement
|
|
92
|
-
end
|
|
93
|
-
return if gem_error.nil?
|
|
94
|
-
require_error = activation_error_handling do
|
|
95
|
-
require "bundler/version"
|
|
96
|
-
end
|
|
97
|
-
return if require_error.nil? && Gem::Requirement.new(bundler_requirement).satisfied_by?(Gem::Version.new(Bundler::VERSION))
|
|
98
|
-
warn "Activating bundler (#{bundler_requirement}) failed:\n#{gem_error.message}\n\nTo install the version of bundler this project requires, run `gem install bundler -v '#{bundler_requirement}'`"
|
|
99
|
-
exit 42
|
|
100
|
-
end
|
|
101
|
-
|
|
102
|
-
def activation_error_handling
|
|
103
|
-
yield
|
|
104
|
-
nil
|
|
105
|
-
rescue StandardError, LoadError => e
|
|
106
|
-
e
|
|
107
|
-
end
|
|
108
|
-
end
|
|
109
|
-
|
|
110
|
-
m.load_bundler!
|
|
111
|
-
|
|
112
|
-
if m.invoked_as_script?
|
|
113
|
-
load Gem.bin_path("bundler", "bundle")
|
|
114
|
-
end
|
data/bin/rake
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env ruby
|
|
2
|
-
# frozen_string_literal: true
|
|
3
|
-
|
|
4
|
-
#
|
|
5
|
-
# This file was generated by Bundler.
|
|
6
|
-
#
|
|
7
|
-
# The application 'rake' is installed as part of a gem, and
|
|
8
|
-
# this file is here to facilitate running it.
|
|
9
|
-
#
|
|
10
|
-
|
|
11
|
-
require "pathname"
|
|
12
|
-
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
|
|
13
|
-
Pathname.new(__FILE__).realpath)
|
|
14
|
-
|
|
15
|
-
bundle_binstub = File.expand_path("../bundle", __FILE__)
|
|
16
|
-
|
|
17
|
-
if File.file?(bundle_binstub)
|
|
18
|
-
if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
|
|
19
|
-
load(bundle_binstub)
|
|
20
|
-
else
|
|
21
|
-
abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
|
|
22
|
-
Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
|
|
23
|
-
end
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
require "rubygems"
|
|
27
|
-
require "bundler/setup"
|
|
28
|
-
|
|
29
|
-
load Gem.bin_path("rake", "rake")
|
data/draper.gemspec
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
require_relative 'lib/draper/version'
|
|
2
|
-
|
|
3
|
-
Gem::Specification.new do |s|
|
|
4
|
-
s.name = "draper"
|
|
5
|
-
s.version = Draper::VERSION
|
|
6
|
-
s.authors = ["Jeff Casimir", "Steve Klabnik"]
|
|
7
|
-
s.email = ["jeff@casimircreative.com", "steve@steveklabnik.com"]
|
|
8
|
-
s.homepage = "https://github.com/drapergem/draper"
|
|
9
|
-
s.summary = "View Models for Rails"
|
|
10
|
-
s.description = "Draper adds an object-oriented layer of presentation logic to your Rails apps."
|
|
11
|
-
s.license = "MIT"
|
|
12
|
-
|
|
13
|
-
s.files = `git ls-files`.split("\n")
|
|
14
|
-
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
|
15
|
-
s.require_paths = ["lib"]
|
|
16
|
-
|
|
17
|
-
s.required_ruby_version = '>= 2.2.2'
|
|
18
|
-
|
|
19
|
-
s.add_dependency 'activesupport', '>= 5.0'
|
|
20
|
-
s.add_dependency 'actionpack', '>= 5.0'
|
|
21
|
-
s.add_dependency 'request_store', '>= 1.0'
|
|
22
|
-
s.add_dependency 'activemodel', '>= 5.0'
|
|
23
|
-
s.add_dependency 'activemodel-serializers-xml', '>= 1.0'
|
|
24
|
-
s.add_dependency 'ruby2_keywords'
|
|
25
|
-
|
|
26
|
-
s.add_development_dependency 'ammeter'
|
|
27
|
-
s.add_development_dependency 'rake'
|
|
28
|
-
s.add_development_dependency 'rspec-rails'
|
|
29
|
-
s.add_development_dependency 'rspec-activerecord-expectations'
|
|
30
|
-
s.add_development_dependency 'minitest-rails'
|
|
31
|
-
s.add_development_dependency 'capybara'
|
|
32
|
-
s.add_development_dependency 'rubocop'
|
|
33
|
-
s.add_development_dependency 'simplecov'
|
|
34
|
-
end
|
|
@@ -1,291 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
require 'support/shared_examples/view_helpers'
|
|
3
|
-
|
|
4
|
-
module Draper
|
|
5
|
-
describe CollectionDecorator do
|
|
6
|
-
it_behaves_like "view helpers", CollectionDecorator.new([])
|
|
7
|
-
|
|
8
|
-
describe "#initialize" do
|
|
9
|
-
describe "options validation" do
|
|
10
|
-
it "does not raise error on valid options" do
|
|
11
|
-
valid_options = {with: Decorator, context: {}}
|
|
12
|
-
expect{CollectionDecorator.new([], valid_options)}.not_to raise_error
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
it "raises error on invalid options" do
|
|
16
|
-
expect{CollectionDecorator.new([], foo: "bar")}.to raise_error ArgumentError, /Unknown key/
|
|
17
|
-
end
|
|
18
|
-
end
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
context "with context" do
|
|
22
|
-
it "stores the context itself" do
|
|
23
|
-
context = {some: "context"}
|
|
24
|
-
decorator = CollectionDecorator.new([], context: context)
|
|
25
|
-
|
|
26
|
-
expect(decorator.context).to be context
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
it "passes context to the individual decorators" do
|
|
30
|
-
context = {some: "context"}
|
|
31
|
-
decorator = CollectionDecorator.new([Product.new, Product.new], context: context)
|
|
32
|
-
|
|
33
|
-
decorator.each do |item|
|
|
34
|
-
expect(item.context).to be context
|
|
35
|
-
end
|
|
36
|
-
end
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
describe "#context=" do
|
|
40
|
-
it "updates the stored context" do
|
|
41
|
-
decorator = CollectionDecorator.new([], context: {some: "context"})
|
|
42
|
-
new_context = {other: "context"}
|
|
43
|
-
|
|
44
|
-
decorator.context = new_context
|
|
45
|
-
expect(decorator.context).to be new_context
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
context "when the collection is already decorated" do
|
|
49
|
-
it "updates the items' context" do
|
|
50
|
-
decorator = CollectionDecorator.new([Product.new, Product.new], context: {some: "context"})
|
|
51
|
-
decorator.decorated_collection # trigger decoration
|
|
52
|
-
new_context = {other: "context"}
|
|
53
|
-
|
|
54
|
-
decorator.context = new_context
|
|
55
|
-
decorator.each do |item|
|
|
56
|
-
expect(item.context).to be new_context
|
|
57
|
-
end
|
|
58
|
-
end
|
|
59
|
-
end
|
|
60
|
-
|
|
61
|
-
context "when the collection has not yet been decorated" do
|
|
62
|
-
it "does not trigger decoration" do
|
|
63
|
-
decorated = CollectionDecorator.new([]).tap(&:to_a)
|
|
64
|
-
undecorated = CollectionDecorator.new([])
|
|
65
|
-
|
|
66
|
-
expect(decorated.instance_variable_defined?(:@decorated_collection)).to be_truthy
|
|
67
|
-
expect(undecorated.instance_variable_defined?(:@decorated_collection)).to be_falsy
|
|
68
|
-
end
|
|
69
|
-
|
|
70
|
-
it "sets context after decoration is triggered" do
|
|
71
|
-
decorator = CollectionDecorator.new([Product.new, Product.new], context: {some: "context"})
|
|
72
|
-
new_context = {other: "context"}
|
|
73
|
-
|
|
74
|
-
decorator.context = new_context
|
|
75
|
-
decorator.each do |item|
|
|
76
|
-
expect(item.context).to be new_context
|
|
77
|
-
end
|
|
78
|
-
end
|
|
79
|
-
end
|
|
80
|
-
end
|
|
81
|
-
|
|
82
|
-
describe "item decoration" do
|
|
83
|
-
it "sets decorated items' source models" do
|
|
84
|
-
collection = [Product.new, Product.new]
|
|
85
|
-
decorator = CollectionDecorator.new(collection)
|
|
86
|
-
|
|
87
|
-
decorator.zip collection do |item, object|
|
|
88
|
-
expect(item.object).to be object
|
|
89
|
-
end
|
|
90
|
-
end
|
|
91
|
-
|
|
92
|
-
context "when the :with option was given" do
|
|
93
|
-
it "uses the :with option" do
|
|
94
|
-
decorator = CollectionDecorator.new([Product.new], with: OtherDecorator).first
|
|
95
|
-
|
|
96
|
-
expect(decorator).to be_decorated_with OtherDecorator
|
|
97
|
-
end
|
|
98
|
-
end
|
|
99
|
-
|
|
100
|
-
context "when the :with option was not given" do
|
|
101
|
-
it "infers the item decorator from each item" do
|
|
102
|
-
decorator = CollectionDecorator.new([double(decorate: :inferred_decorator)]).first
|
|
103
|
-
|
|
104
|
-
expect(decorator).to be :inferred_decorator
|
|
105
|
-
end
|
|
106
|
-
end
|
|
107
|
-
end
|
|
108
|
-
|
|
109
|
-
describe ".delegate" do
|
|
110
|
-
protect_class ProductsDecorator
|
|
111
|
-
|
|
112
|
-
it "defaults the :to option to :object" do
|
|
113
|
-
expect(Object).to receive(:delegate).with(:foo, :bar, to: :object)
|
|
114
|
-
ProductsDecorator.delegate :foo, :bar
|
|
115
|
-
end
|
|
116
|
-
|
|
117
|
-
it "does not overwrite the :to option if supplied" do
|
|
118
|
-
expect(Object).to receive(:delegate).with(:foo, :bar, to: :baz)
|
|
119
|
-
ProductsDecorator.delegate :foo, :bar, to: :baz
|
|
120
|
-
end
|
|
121
|
-
end
|
|
122
|
-
|
|
123
|
-
describe "#find" do
|
|
124
|
-
it "decorates Enumerable#find" do
|
|
125
|
-
decorator = CollectionDecorator.new([])
|
|
126
|
-
|
|
127
|
-
expect(decorator.decorated_collection).to receive(:find).and_return(:delegated)
|
|
128
|
-
expect(decorator.find{|p| p.title == "title"}).to be :delegated
|
|
129
|
-
end
|
|
130
|
-
end
|
|
131
|
-
|
|
132
|
-
describe "#to_ary" do
|
|
133
|
-
# required for `render @collection` in Rails
|
|
134
|
-
it "delegates to the decorated collection" do
|
|
135
|
-
decorator = CollectionDecorator.new([])
|
|
136
|
-
|
|
137
|
-
expect(decorator.decorated_collection).to receive(:to_ary).and_return(:delegated)
|
|
138
|
-
expect(decorator.to_ary).to be :delegated
|
|
139
|
-
end
|
|
140
|
-
end
|
|
141
|
-
|
|
142
|
-
it "delegates array methods to the decorated collection" do
|
|
143
|
-
decorator = CollectionDecorator.new([])
|
|
144
|
-
|
|
145
|
-
allow(decorator).to receive_message_chain(:decorated_collection, :[]).with(42).and_return(:delegated)
|
|
146
|
-
expect(decorator[42]).to be :delegated
|
|
147
|
-
end
|
|
148
|
-
|
|
149
|
-
describe "#==" do
|
|
150
|
-
context "when comparing to a collection decorator with the same object" do
|
|
151
|
-
it "returns true" do
|
|
152
|
-
object = [Product.new, Product.new]
|
|
153
|
-
decorator = CollectionDecorator.new(object)
|
|
154
|
-
other = ProductsDecorator.new(object)
|
|
155
|
-
|
|
156
|
-
expect(decorator == other).to be_truthy
|
|
157
|
-
end
|
|
158
|
-
end
|
|
159
|
-
|
|
160
|
-
context "when comparing to a collection decorator with a different object" do
|
|
161
|
-
it "returns false" do
|
|
162
|
-
decorator = CollectionDecorator.new([Product.new, Product.new])
|
|
163
|
-
other = ProductsDecorator.new([Product.new, Product.new])
|
|
164
|
-
|
|
165
|
-
expect(decorator == other).to be_falsey
|
|
166
|
-
end
|
|
167
|
-
end
|
|
168
|
-
|
|
169
|
-
context "when comparing to a collection of the same items" do
|
|
170
|
-
it "returns true" do
|
|
171
|
-
object = [Product.new, Product.new]
|
|
172
|
-
decorator = CollectionDecorator.new(object)
|
|
173
|
-
other = object.dup
|
|
174
|
-
|
|
175
|
-
expect(decorator == other).to be_truthy
|
|
176
|
-
end
|
|
177
|
-
end
|
|
178
|
-
|
|
179
|
-
context "when comparing to a collection of different items" do
|
|
180
|
-
it "returns false" do
|
|
181
|
-
decorator = CollectionDecorator.new([Product.new, Product.new])
|
|
182
|
-
other = [Product.new, Product.new]
|
|
183
|
-
|
|
184
|
-
expect(decorator == other).to be_falsey
|
|
185
|
-
end
|
|
186
|
-
end
|
|
187
|
-
|
|
188
|
-
context "when the decorated collection has been modified" do
|
|
189
|
-
it "is no longer equal to the object" do
|
|
190
|
-
object = [Product.new, Product.new]
|
|
191
|
-
decorator = CollectionDecorator.new(object)
|
|
192
|
-
other = object.dup
|
|
193
|
-
|
|
194
|
-
decorator << Product.new.decorate
|
|
195
|
-
expect(decorator == other).to be_falsey
|
|
196
|
-
end
|
|
197
|
-
end
|
|
198
|
-
end
|
|
199
|
-
|
|
200
|
-
describe "#to_s" do
|
|
201
|
-
context "when :with option was given" do
|
|
202
|
-
it "returns a string representation of the collection decorator" do
|
|
203
|
-
decorator = CollectionDecorator.new(["a", "b", "c"], with: ProductDecorator)
|
|
204
|
-
|
|
205
|
-
expect(decorator.to_s).to eq '#<Draper::CollectionDecorator of ProductDecorator for ["a", "b", "c"]>'
|
|
206
|
-
end
|
|
207
|
-
end
|
|
208
|
-
|
|
209
|
-
context "when :with option was not given" do
|
|
210
|
-
it "returns a string representation of the collection decorator" do
|
|
211
|
-
decorator = CollectionDecorator.new(["a", "b", "c"])
|
|
212
|
-
|
|
213
|
-
expect(decorator.to_s).to eq '#<Draper::CollectionDecorator of inferred decorators for ["a", "b", "c"]>'
|
|
214
|
-
end
|
|
215
|
-
end
|
|
216
|
-
|
|
217
|
-
context "for a custom subclass" do
|
|
218
|
-
it "uses the custom class name" do
|
|
219
|
-
decorator = ProductsDecorator.new([])
|
|
220
|
-
|
|
221
|
-
expect(decorator.to_s).to match(/ProductsDecorator/)
|
|
222
|
-
end
|
|
223
|
-
end
|
|
224
|
-
end
|
|
225
|
-
|
|
226
|
-
describe '#object' do
|
|
227
|
-
it 'returns the underlying collection' do
|
|
228
|
-
collection = [Product.new]
|
|
229
|
-
decorator = ProductsDecorator.new(collection)
|
|
230
|
-
|
|
231
|
-
expect(decorator.object).to eq collection
|
|
232
|
-
end
|
|
233
|
-
end
|
|
234
|
-
|
|
235
|
-
describe '#decorated?' do
|
|
236
|
-
it 'returns true' do
|
|
237
|
-
decorator = ProductsDecorator.new([Product.new])
|
|
238
|
-
|
|
239
|
-
expect(decorator).to be_decorated
|
|
240
|
-
end
|
|
241
|
-
end
|
|
242
|
-
|
|
243
|
-
describe '#decorated_with?' do
|
|
244
|
-
it "checks if a decorator has been applied to a collection" do
|
|
245
|
-
decorator = ProductsDecorator.new([Product.new])
|
|
246
|
-
|
|
247
|
-
expect(decorator).to be_decorated_with ProductsDecorator
|
|
248
|
-
expect(decorator).not_to be_decorated_with OtherDecorator
|
|
249
|
-
end
|
|
250
|
-
end
|
|
251
|
-
|
|
252
|
-
describe '#kind_of?' do
|
|
253
|
-
it 'asks the kind of its decorated collection' do
|
|
254
|
-
decorator = ProductsDecorator.new([])
|
|
255
|
-
expect(decorator.decorated_collection).to receive(:kind_of?).with(Array).and_return("true")
|
|
256
|
-
expect(decorator.kind_of?(Array)).to eq "true"
|
|
257
|
-
end
|
|
258
|
-
|
|
259
|
-
context 'when asking the underlying collection returns false' do
|
|
260
|
-
it 'asks the CollectionDecorator instance itself' do
|
|
261
|
-
decorator = ProductsDecorator.new([])
|
|
262
|
-
allow(decorator.decorated_collection).to receive(:kind_of?).with(::Draper::CollectionDecorator).and_return(false)
|
|
263
|
-
expect(decorator.kind_of?(::Draper::CollectionDecorator)).to be true
|
|
264
|
-
end
|
|
265
|
-
end
|
|
266
|
-
end
|
|
267
|
-
|
|
268
|
-
describe '#is_a?' do
|
|
269
|
-
it 'aliases to #kind_of?' do
|
|
270
|
-
decorator = ProductsDecorator.new([])
|
|
271
|
-
expect(decorator.method(:kind_of?)).to eq decorator.method(:is_a?)
|
|
272
|
-
end
|
|
273
|
-
end
|
|
274
|
-
|
|
275
|
-
describe "#replace" do
|
|
276
|
-
it "replaces the decorated collection" do
|
|
277
|
-
decorator = CollectionDecorator.new([Product.new])
|
|
278
|
-
replacement = [:foo, :bar]
|
|
279
|
-
|
|
280
|
-
decorator.replace replacement
|
|
281
|
-
expect(decorator).to match_array replacement
|
|
282
|
-
end
|
|
283
|
-
|
|
284
|
-
it "returns itself" do
|
|
285
|
-
decorator = CollectionDecorator.new([Product.new])
|
|
286
|
-
|
|
287
|
-
expect(decorator.replace([:foo, :bar])).to be decorator
|
|
288
|
-
end
|
|
289
|
-
end
|
|
290
|
-
end
|
|
291
|
-
end
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
|
|
3
|
-
module Draper
|
|
4
|
-
RSpec.describe Configuration do
|
|
5
|
-
it 'yields Draper on configure' do
|
|
6
|
-
Draper.configure { |config| expect(config).to be Draper }
|
|
7
|
-
end
|
|
8
|
-
|
|
9
|
-
describe '#default_controller' do
|
|
10
|
-
it 'defaults default_controller to ApplicationController' do
|
|
11
|
-
expect(Draper.default_controller).to be ApplicationController
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
it 'allows customizing default_controller through configure' do
|
|
15
|
-
default = Draper.default_controller
|
|
16
|
-
|
|
17
|
-
Draper.configure do |config|
|
|
18
|
-
config.default_controller = CustomController
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
expect(Draper.default_controller).to be CustomController
|
|
22
|
-
|
|
23
|
-
Draper.default_controller = default
|
|
24
|
-
end
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
describe '#default_query_methods_strategy' do
|
|
28
|
-
let!(:default) { Draper.default_query_methods_strategy }
|
|
29
|
-
|
|
30
|
-
subject { Draper.default_query_methods_strategy }
|
|
31
|
-
|
|
32
|
-
context 'when there is no custom strategy' do
|
|
33
|
-
it { is_expected.to eq(:active_record) }
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
context 'when using a custom strategy' do
|
|
37
|
-
before do
|
|
38
|
-
Draper.configure do |config|
|
|
39
|
-
config.default_query_methods_strategy = :mongoid
|
|
40
|
-
end
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
after { Draper.default_query_methods_strategy = default }
|
|
44
|
-
|
|
45
|
-
it { is_expected.to eq(:mongoid) }
|
|
46
|
-
end
|
|
47
|
-
end
|
|
48
|
-
end
|
|
49
|
-
end
|