draper 2.1.0 → 3.0.0.pre1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +3 -1
- data/.travis.yml +2 -7
- data/CHANGELOG.md +6 -0
- data/Gemfile +4 -5
- data/README.md +36 -8
- data/Rakefile +3 -2
- data/draper.gemspec +11 -10
- data/lib/draper.rb +1 -1
- data/lib/draper/automatic_delegation.rb +1 -1
- data/lib/draper/decoratable.rb +1 -2
- data/lib/draper/decorator.rb +0 -12
- data/lib/draper/railtie.rb +0 -8
- data/lib/draper/tasks/test.rake +2 -15
- data/lib/draper/test/rspec_integration.rb +1 -5
- data/lib/draper/test_case.rb +4 -8
- data/lib/draper/version.rb +1 -1
- data/lib/draper/view_context/build_strategy.rb +1 -1
- data/lib/generators/rspec/templates/decorator_spec.rb +1 -1
- data/spec/draper/decoratable_spec.rb +3 -5
- data/spec/draper/decorator_spec.rb +8 -0
- data/spec/draper/factory_spec.rb +3 -3
- data/spec/draper/helper_proxy_spec.rb +1 -1
- data/spec/dummy/app/views/posts/_post.html.erb +8 -6
- data/spec/dummy/config/mongoid.yml +104 -41
- data/spec/dummy/spec/decorators/active_model_serializers_spec.rb +4 -8
- data/spec/dummy/spec/decorators/post_decorator_spec.rb +0 -2
- data/spec/dummy/spec/mailers/post_mailer_spec.rb +0 -8
- data/spec/dummy/spec/shared_examples/decoratable.rb +0 -2
- data/spec/dummy/test/decorators/minitest/view_context_test.rb +1 -1
- data/spec/dummy/test/decorators/test_unit/view_context_test.rb +1 -1
- data/spec/generators/decorator/decorator_generator_spec.rb +3 -2
- data/spec/integration/integration_spec.rb +11 -8
- data/spec/performance/benchmark.rb +1 -1
- data/spec/spec_helper.rb +0 -1
- data/spec/support/matchers/have_text.rb +2 -2
- metadata +44 -33
- data/gemfiles/4.0.gemfile +0 -3
- data/gemfiles/4.1.gemfile +0 -3
- data/gemfiles/4.2.gemfile +0 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 016c0c7b5f38f0560c5629e83abcc175401cdcb4
|
4
|
+
data.tar.gz: eb23dac2cdc58bf4a2eedccd0f468b25f2df49b8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4fc57f67ed9b7f7779f93c7393c4a91a883ed5a5393dffa6be88da26171bfa6ae463db4d73c5d8831dc4c8f5f4fa3d6e61e3a38c8fec02e9d481c7c3e88ab85d
|
7
|
+
data.tar.gz: 972827d365bf4d02bc8bb9f817c6fab065a9de81bf9f80c3de67b2be8fc12b1216d5e459fa561997afe9debad1456d704da2d2f8d108aef8fdcccbc6139da317
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,11 @@
|
|
1
1
|
# Draper Changelog
|
2
2
|
|
3
|
+
## 3.0.0.pre1 - 2016-07-10
|
4
|
+
|
5
|
+
* Added support for Rails 5, dropped 4.0 - 4.2
|
6
|
+
* Ruby >= 2.2 is required, matching Rails 5
|
7
|
+
* Dropped support for ActiveModelSerializers 0.8
|
8
|
+
|
3
9
|
## 2.1.0 - 2015-03-26
|
4
10
|
|
5
11
|
* Cleared most issues and merged a few PRs
|
data/Gemfile
CHANGED
@@ -7,10 +7,9 @@ platforms :ruby do
|
|
7
7
|
end
|
8
8
|
|
9
9
|
platforms :jruby do
|
10
|
-
gem "minitest"
|
11
|
-
gem "activerecord-jdbcsqlite3-adapter"
|
10
|
+
gem "minitest"
|
11
|
+
gem "activerecord-jdbcsqlite3-adapter"
|
12
12
|
end
|
13
13
|
|
14
|
-
|
15
|
-
|
16
|
-
eval_gemfile File.expand_path("../gemfiles/#{version}.gemfile", __FILE__)
|
14
|
+
gem "rails", "~> 5.0"
|
15
|
+
gem "mongoid", github: "mongodb/mongoid"
|
data/README.md
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
# Draper: View Models for Rails
|
2
2
|
|
3
3
|
[![TravisCI Build Status](https://travis-ci.org/drapergem/draper.svg?branch=master)](http://travis-ci.org/drapergem/draper)
|
4
|
-
[![Code Climate](https://codeclimate.com/github/drapergem/draper.
|
5
|
-
[![Inline docs](http://inch-ci.org/github/drapergem/draper.
|
4
|
+
[![Code Climate](https://codeclimate.com/github/drapergem/draper.svg)](https://codeclimate.com/github/drapergem/draper)
|
5
|
+
[![Inline docs](http://inch-ci.org/github/drapergem/draper.svg?branch=master)](http://inch-ci.org/github/drapergem/draper)
|
6
6
|
|
7
7
|
Draper adds an object-oriented layer of presentation logic to your Rails
|
8
8
|
application.
|
@@ -48,7 +48,7 @@ end
|
|
48
48
|
But it makes you a little uncomfortable. `publication_status` lives in a
|
49
49
|
nebulous namespace spread across all controllers and view. Down the road, you
|
50
50
|
might want to display the publication status of a `Book`. And, of course, your
|
51
|
-
design calls for a
|
51
|
+
design calls for a slightly different formatting to the date for a `Book`.
|
52
52
|
|
53
53
|
Now your helper method can either switch based on the input class type (poor
|
54
54
|
Ruby style), or you break it out into two methods, `book_publication_status` and
|
@@ -110,7 +110,7 @@ Decorators are the ideal place to:
|
|
110
110
|
Add Draper to your Gemfile:
|
111
111
|
|
112
112
|
```ruby
|
113
|
-
gem 'draper'
|
113
|
+
gem 'draper'
|
114
114
|
```
|
115
115
|
|
116
116
|
And run `bundle install` within your app's directory.
|
@@ -276,6 +276,19 @@ omitted.
|
|
276
276
|
delegate :current_page, :per_page, :offset, :total_entries, :total_pages
|
277
277
|
```
|
278
278
|
|
279
|
+
If needed, you can then set the collection_decorator_class of your CustomDecorator as follows:
|
280
|
+
```ruby
|
281
|
+
class ArticleDecorator < Draper::Decorator
|
282
|
+
def self.collection_decorator_class
|
283
|
+
PaginatingDecorator
|
284
|
+
end
|
285
|
+
end
|
286
|
+
|
287
|
+
ArticleDecorator.decorate_collection(@articles.paginate)
|
288
|
+
# => Collection decorated by PaginatingDecorator
|
289
|
+
# => Members decorated by ArticleDecorator
|
290
|
+
```
|
291
|
+
|
279
292
|
### Decorating Associated Objects
|
280
293
|
|
281
294
|
You can automatically decorate associated models when the primary model is
|
@@ -379,6 +392,15 @@ In your `Spork.prefork` block of `spec_helper.rb`, add this:
|
|
379
392
|
require 'draper/test/rspec_integration'
|
380
393
|
```
|
381
394
|
|
395
|
+
#### Custom Draper Controller ViewContext
|
396
|
+
If running tests in an engine setting with a controller other than "ApplicationController," set a custom controller in `spec_helper.rb`
|
397
|
+
|
398
|
+
```ruby
|
399
|
+
config.before(:each, type: :decorator) do |example|
|
400
|
+
Draper::ViewContext.controller = ExampleEngine::CustomRootController.new
|
401
|
+
end
|
402
|
+
```
|
403
|
+
|
382
404
|
### Isolated Tests
|
383
405
|
|
384
406
|
In tests, Draper needs to build a view context to access helper methods. By
|
@@ -564,13 +586,15 @@ end
|
|
564
586
|
|
565
587
|
This is only necessary when proxying class methods.
|
566
588
|
|
589
|
+
Once this association between the decorator and the model is set up, you can call
|
590
|
+
`SomeModel.decorator_class` to access class methods defined in the decorator.
|
591
|
+
If necessary, you can check if your model is decorated with `SomeModel.decorator_class?`.
|
592
|
+
|
567
593
|
### Making Models Decoratable
|
568
594
|
|
569
595
|
Models get their `decorate` method from the `Draper::Decoratable` module, which
|
570
596
|
is included in `ActiveRecord::Base` and `Mongoid::Document` by default. If
|
571
|
-
you're
|
572
|
-
ORM](https://github.com/drapergem/draper/wiki/Using-other-ORMs) (including
|
573
|
-
versions of Mongoid prior to 3.0), or want to decorate plain old Ruby objects,
|
597
|
+
you're using another ORM, or want to decorate plain old Ruby objects,
|
574
598
|
you can include this module manually.
|
575
599
|
|
576
600
|
## Contributors
|
@@ -579,7 +603,11 @@ Draper was conceived by Jeff Casimir and heavily refined by Steve Klabnik and a
|
|
579
603
|
great community of open source
|
580
604
|
[contributors](https://github.com/drapergem/draper/contributors).
|
581
605
|
|
582
|
-
###
|
606
|
+
### Current maintainers
|
607
|
+
|
608
|
+
* Sean Linsley
|
609
|
+
|
610
|
+
### Historical maintainers
|
583
611
|
|
584
612
|
* Jeff Casimir (jeff@jumpstartlab.com)
|
585
613
|
* Steve Klabnik (steve@jumpstartlab.com)
|
data/Rakefile
CHANGED
@@ -16,7 +16,8 @@ desc "Run all specs"
|
|
16
16
|
task "spec" => "spec:all"
|
17
17
|
|
18
18
|
namespace "spec" do
|
19
|
-
|
19
|
+
# TODOD: add back "generators"
|
20
|
+
task "all" => ["draper", "integration"]
|
20
21
|
|
21
22
|
def spec_task(name)
|
22
23
|
desc "Run #{name} specs"
|
@@ -64,6 +65,6 @@ namespace "db" do
|
|
64
65
|
run_in_dummy_app "rm -f db/*.sqlite3"
|
65
66
|
run_in_dummy_app "RAILS_ENV=development rake db:schema:load db:seed"
|
66
67
|
run_in_dummy_app "RAILS_ENV=production rake db:schema:load db:seed"
|
67
|
-
run_in_dummy_app "RAILS_ENV=test rake db:schema:load"
|
68
|
+
run_in_dummy_app "RAILS_ENV=test rake db:environment:set db:schema:load"
|
68
69
|
end
|
69
70
|
end
|
data/draper.gemspec
CHANGED
@@ -1,6 +1,4 @@
|
|
1
|
-
|
2
|
-
$:.push File.expand_path("../lib", __FILE__)
|
3
|
-
require "draper/version"
|
1
|
+
require File.join(__dir__, "lib", "draper", "version")
|
4
2
|
|
5
3
|
Gem::Specification.new do |s|
|
6
4
|
s.name = "draper"
|
@@ -17,15 +15,18 @@ Gem::Specification.new do |s|
|
|
17
15
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
18
16
|
s.require_paths = ["lib"]
|
19
17
|
|
20
|
-
s.
|
21
|
-
|
18
|
+
s.required_ruby_version = '>= 2.2.2'
|
19
|
+
|
20
|
+
s.add_dependency 'activesupport', '~> 5.0'
|
21
|
+
s.add_dependency 'actionpack', '~> 5.0'
|
22
22
|
s.add_dependency 'request_store', '~> 1.0'
|
23
|
-
s.add_dependency 'activemodel', '
|
23
|
+
s.add_dependency 'activemodel', '~> 5.0'
|
24
|
+
s.add_dependency 'activemodel-serializers-xml', '~> 1.0'
|
24
25
|
|
25
26
|
s.add_development_dependency 'ammeter'
|
26
|
-
s.add_development_dependency 'rake'
|
27
|
-
s.add_development_dependency 'rspec-rails'
|
28
|
-
s.add_development_dependency 'minitest-rails'
|
27
|
+
s.add_development_dependency 'rake'
|
28
|
+
s.add_development_dependency 'rspec-rails'
|
29
|
+
s.add_development_dependency 'minitest-rails'
|
29
30
|
s.add_development_dependency 'capybara'
|
30
|
-
s.add_development_dependency 'active_model_serializers'
|
31
|
+
s.add_development_dependency 'active_model_serializers', '~> 0.10'
|
31
32
|
end
|
data/lib/draper.rb
CHANGED
data/lib/draper/decoratable.rb
CHANGED
@@ -56,8 +56,7 @@ module Draper
|
|
56
56
|
# @param [Hash] options
|
57
57
|
# see {Decorator.decorate_collection}.
|
58
58
|
def decorate(options = {})
|
59
|
-
|
60
|
-
decorator_class.decorate_collection(collection, options.reverse_merge(with: nil))
|
59
|
+
decorator_class.decorate_collection(all, options.reverse_merge(with: nil))
|
61
60
|
end
|
62
61
|
|
63
62
|
def decorator_class?
|
data/lib/draper/decorator.rb
CHANGED
@@ -203,18 +203,6 @@ module Draper
|
|
203
203
|
super || object.instance_of?(klass)
|
204
204
|
end
|
205
205
|
|
206
|
-
if RUBY_VERSION < "2.0"
|
207
|
-
# nasty hack to stop 1.9.x using the delegated `to_s` in `inspect`
|
208
|
-
alias_method :_to_s, :to_s
|
209
|
-
|
210
|
-
def inspect
|
211
|
-
ivars = instance_variables.map do |name|
|
212
|
-
"#{name}=#{instance_variable_get(name).inspect}"
|
213
|
-
end
|
214
|
-
_to_s.insert(-2, " #{ivars.join(", ")}")
|
215
|
-
end
|
216
|
-
end
|
217
|
-
|
218
206
|
delegate :to_s
|
219
207
|
|
220
208
|
# In case object is nil
|
data/lib/draper/railtie.rb
CHANGED
@@ -43,14 +43,6 @@ module Draper
|
|
43
43
|
end
|
44
44
|
end
|
45
45
|
|
46
|
-
initializer "draper.setup_active_model_serializers" do |app|
|
47
|
-
ActiveSupport.on_load :active_model_serializers do
|
48
|
-
if defined?(ActiveModel::ArraySerializerSupport)
|
49
|
-
Draper::CollectionDecorator.send :include, ActiveModel::ArraySerializerSupport
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
46
|
initializer "draper.minitest-rails_integration" do |app|
|
55
47
|
ActiveSupport.on_load :minitest do
|
56
48
|
require "draper/test/minitest_integration"
|
data/lib/draper/tasks/test.rake
CHANGED
@@ -1,22 +1,9 @@
|
|
1
1
|
require 'rake/testtask'
|
2
|
-
|
3
|
-
test_task = if Rails.version.to_f < 3.2
|
4
|
-
require 'rails/test_unit/railtie'
|
5
|
-
Rake::TestTask
|
6
|
-
else
|
7
|
-
require 'rails/test_unit/sub_test_task'
|
8
|
-
Rails::SubTestTask
|
9
|
-
end
|
2
|
+
require 'rails/test_unit/railtie'
|
10
3
|
|
11
4
|
namespace :test do
|
12
|
-
|
5
|
+
Rake::TestTask.new(:decorators => "test:prepare") do |t|
|
13
6
|
t.libs << "test"
|
14
7
|
t.pattern = "test/decorators/**/*_test.rb"
|
15
8
|
end
|
16
9
|
end
|
17
|
-
|
18
|
-
if Rails.version.to_f < 4.2 && Rake::Task.task_defined?('test:run')
|
19
|
-
Rake::Task['test:run'].enhance do
|
20
|
-
Rake::Task['test:decorators'].invoke
|
21
|
-
end
|
22
|
-
end
|
@@ -7,11 +7,7 @@ module Draper
|
|
7
7
|
end
|
8
8
|
|
9
9
|
RSpec.configure do |config|
|
10
|
-
|
11
|
-
config.include DecoratorExampleGroup, file_path: %r{spec/decorators}, type: :decorator
|
12
|
-
else
|
13
|
-
config.include DecoratorExampleGroup, example_group: {file_path: %r{spec/decorators}}, type: :decorator
|
14
|
-
end
|
10
|
+
config.include DecoratorExampleGroup, file_path: %r{spec/decorators}, type: :decorator
|
15
11
|
|
16
12
|
[:decorator, :controller, :mailer].each do |type|
|
17
13
|
config.before(:each, type: type) { Draper::ViewContext.clear! }
|
data/lib/draper/test_case.rb
CHANGED
@@ -29,14 +29,10 @@ module Draper
|
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
32
|
-
if defined?
|
33
|
-
|
34
|
-
include Draper::TestCase::ViewContextTeardown
|
35
|
-
end
|
32
|
+
if defined? ActionController::TestCase
|
33
|
+
ActionController::TestCase.include Draper::TestCase::ViewContextTeardown
|
36
34
|
end
|
37
35
|
|
38
|
-
if defined?
|
39
|
-
|
40
|
-
include Draper::TestCase::ViewContextTeardown
|
41
|
-
end
|
36
|
+
if defined? ActionMailer::TestCase
|
37
|
+
ActionMailer::TestCase.include Draper::TestCase::ViewContextTeardown
|
42
38
|
end
|
data/lib/draper/version.rb
CHANGED
@@ -38,7 +38,7 @@ module Draper
|
|
38
38
|
|
39
39
|
def controller
|
40
40
|
(Draper::ViewContext.controller || ApplicationController.new).tap do |controller|
|
41
|
-
controller.request ||= ActionController::TestRequest.
|
41
|
+
controller.request ||= ActionController::TestRequest.create
|
42
42
|
end
|
43
43
|
end
|
44
44
|
end
|
@@ -128,11 +128,9 @@ module Draper
|
|
128
128
|
end
|
129
129
|
|
130
130
|
describe ".decorate" do
|
131
|
-
let(:scoping_method) { Rails::VERSION::MAJOR >= 4 ? :all : :scoped }
|
132
|
-
|
133
131
|
it "calls #decorate_collection on .decorator_class" do
|
134
132
|
scoped = [Product.new]
|
135
|
-
Product.stub
|
133
|
+
Product.stub all: scoped
|
136
134
|
|
137
135
|
Product.decorator_class.should_receive(:decorate_collection).with(scoped, with: nil).and_return(:decorated_collection)
|
138
136
|
expect(Product.decorate).to be :decorated_collection
|
@@ -140,7 +138,7 @@ module Draper
|
|
140
138
|
|
141
139
|
it "accepts options" do
|
142
140
|
options = {with: ProductDecorator, context: {some: "context"}}
|
143
|
-
Product.stub
|
141
|
+
Product.stub all: []
|
144
142
|
|
145
143
|
Product.decorator_class.should_receive(:decorate_collection).with([], options)
|
146
144
|
Product.decorate(options)
|
@@ -162,7 +160,7 @@ module Draper
|
|
162
160
|
|
163
161
|
context "for ActiveModel classes" do
|
164
162
|
it "infers the decorator from the model name" do
|
165
|
-
Product.
|
163
|
+
allow(Product).to receive(:model_name){"Other"}
|
166
164
|
|
167
165
|
expect(Product.decorator_class).to be OtherDecorator
|
168
166
|
end
|
@@ -604,6 +604,14 @@ module Draper
|
|
604
604
|
expect(decorator.methods).to include :hello_world
|
605
605
|
end
|
606
606
|
|
607
|
+
it "allows decorator to decorate different classes of objects" do
|
608
|
+
decorator_1 = Decorator.new(double)
|
609
|
+
decorator_2 = Decorator.new(double(hello_world: :delegated))
|
610
|
+
|
611
|
+
decorator_2.hello_world
|
612
|
+
expect(decorator_1.methods).not_to include :hello_world
|
613
|
+
end
|
614
|
+
|
607
615
|
it "passes blocks to delegated methods" do
|
608
616
|
object = Model.new
|
609
617
|
object.stub(:hello_world) { |*args, &block| block.call }
|
data/spec/draper/factory_spec.rb
CHANGED
@@ -99,7 +99,7 @@ module Draper
|
|
99
99
|
options = {foo: "bar"}
|
100
100
|
worker = Factory::Worker.new(double, object)
|
101
101
|
decorator = ->(*){}
|
102
|
-
worker.
|
102
|
+
allow(worker).to receive(:decorator){ decorator }
|
103
103
|
|
104
104
|
decorator.should_receive(:call).with(object, options).and_return(:decorated)
|
105
105
|
expect(worker.call(options)).to be :decorated
|
@@ -227,8 +227,8 @@ module Draper
|
|
227
227
|
it "returns the .decorate_collection method from the object's decorator" do
|
228
228
|
object = []
|
229
229
|
decorator_class = Class.new(Decorator)
|
230
|
-
object.
|
231
|
-
object.
|
230
|
+
allow(object).to receive(:decorator_class){ decorator_class }
|
231
|
+
allow(object).to receive(:decorate){ nil }
|
232
232
|
worker = Factory::Worker.new(nil, object)
|
233
233
|
|
234
234
|
decorator_class.should_receive(:decorate_collection).with(object, foo: "bar", with: nil).and_return(:decorated)
|
@@ -52,7 +52,7 @@ module Draper
|
|
52
52
|
view_context = double
|
53
53
|
helper_proxy = HelperProxy.new(view_context)
|
54
54
|
|
55
|
-
view_context.
|
55
|
+
allow(view_context).to receive(:capture) { |*args, &block| [*args, block.call] }
|
56
56
|
expect(helper_proxy.capture(:first_arg, :second_arg){:yielded}).to \
|
57
57
|
be_eql [:first_arg, :second_arg, :yielded]
|
58
58
|
end
|
@@ -20,14 +20,16 @@
|
|
20
20
|
<dt>Helpers from the controller:</dt>
|
21
21
|
<dd id="goodnight_moon"><%= post.goodnight_moon %></dd>
|
22
22
|
|
23
|
-
|
24
|
-
|
23
|
+
<% unless defined? mailer %>
|
24
|
+
<dt>Path with decorator:</dt>
|
25
|
+
<dd id="path_with_decorator"><%= post_url(post) %></dd>
|
25
26
|
|
26
|
-
|
27
|
-
|
27
|
+
<dt>Path with model:</dt>
|
28
|
+
<dd id="path_with_model"><%= post.path_with_model %></dd>
|
28
29
|
|
29
|
-
|
30
|
-
|
30
|
+
<dt>Path with id:</dt>
|
31
|
+
<dd id="path_with_id"><%= post.path_with_id %></dd>
|
32
|
+
<% end %>
|
31
33
|
|
32
34
|
<dt>URL with decorator:</dt>
|
33
35
|
<dd id="url_with_decorator"><%= post_url(post) %></dd>
|
@@ -1,54 +1,117 @@
|
|
1
1
|
development:
|
2
|
-
# Configure available database
|
3
|
-
|
4
|
-
# Defines the default
|
2
|
+
# Configure available database clients. (required)
|
3
|
+
clients:
|
4
|
+
# Defines the default client. (required)
|
5
5
|
default:
|
6
6
|
# Defines the name of the default database that Mongoid can connect to.
|
7
7
|
# (required).
|
8
8
|
database: dummy_development
|
9
|
-
# Provides the hosts the default
|
9
|
+
# Provides the hosts the default client can connect to. Must be an array
|
10
10
|
# of host:port pairs. (required)
|
11
11
|
hosts:
|
12
12
|
- localhost:27017
|
13
13
|
options:
|
14
|
-
# Change
|
15
|
-
#
|
16
|
-
#
|
17
|
-
|
18
|
-
# Change the default
|
19
|
-
# :
|
20
|
-
#
|
21
|
-
#
|
22
|
-
|
23
|
-
#
|
24
|
-
#
|
25
|
-
|
26
|
-
|
27
|
-
#
|
28
|
-
|
29
|
-
#
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
14
|
+
# Change the default write concern. (default = { w: 1 })
|
15
|
+
# write:
|
16
|
+
# w: 1
|
17
|
+
|
18
|
+
# Change the default read preference. Valid options for mode are: :secondary,
|
19
|
+
# :secondary_preferred, :primary, :primary_preferred, :nearest
|
20
|
+
# (default: primary)
|
21
|
+
# read:
|
22
|
+
# mode: :secondary_preferred
|
23
|
+
# tag_sets:
|
24
|
+
# - use: web
|
25
|
+
|
26
|
+
# The name of the user for authentication.
|
27
|
+
# user: 'user'
|
28
|
+
|
29
|
+
# The password of the user for authentication.
|
30
|
+
# password: 'password'
|
31
|
+
|
32
|
+
# The user's database roles.
|
33
|
+
# roles:
|
34
|
+
# - 'dbOwner'
|
35
|
+
|
36
|
+
# Change the default authentication mechanism. Valid options are: :scram,
|
37
|
+
# :mongodb_cr, :mongodb_x509, and :plain. (default on 3.0 is :scram, default
|
38
|
+
# on 2.4 and 2.6 is :plain)
|
39
|
+
# auth_mech: :scram
|
40
|
+
|
41
|
+
# The database or source to authenticate the user against. (default: admin)
|
42
|
+
# auth_source: admin
|
43
|
+
|
44
|
+
# Force a the driver cluster to behave in a certain manner instead of auto-
|
45
|
+
# discovering. Can be one of: :direct, :replica_set, :sharded. Set to :direct
|
46
|
+
# when connecting to hidden members of a replica set.
|
47
|
+
# connect: :direct
|
48
|
+
|
49
|
+
# Changes the default time in seconds the server monitors refresh their status
|
50
|
+
# via ismaster commands. (default: 10)
|
51
|
+
# heartbeat_frequency: 10
|
52
|
+
|
53
|
+
# The time in seconds for selecting servers for a near read preference. (default: 5)
|
54
|
+
# local_threshold: 5
|
55
|
+
|
56
|
+
# The timeout in seconds for selecting a server for an operation. (default: 30)
|
57
|
+
# server_selection_timeout: 30
|
58
|
+
|
59
|
+
# The maximum number of connections in the connection pool. (default: 5)
|
60
|
+
# max_pool_size: 5
|
61
|
+
|
62
|
+
# The minimum number of connections in the connection pool. (default: 1)
|
63
|
+
# min_pool_size: 1
|
64
|
+
|
65
|
+
# The time to wait, in seconds, in the connection pool for a connection
|
66
|
+
# to be checked in before timing out. (default: 5)
|
67
|
+
# wait_queue_timeout: 5
|
35
68
|
|
36
|
-
|
37
|
-
|
69
|
+
# The time to wait to establish a connection before timing out, in seconds.
|
70
|
+
# (default: 5)
|
71
|
+
# connect_timeout: 5
|
38
72
|
|
73
|
+
# The timeout to wait to execute operations on a socket before raising an error.
|
74
|
+
# (default: 5)
|
75
|
+
# socket_timeout: 5
|
76
|
+
|
77
|
+
# The name of the replica set to connect to. Servers provided as seeds that do
|
78
|
+
# not belong to this replica set will be ignored.
|
79
|
+
# replica_set: name
|
80
|
+
|
81
|
+
# Whether to connect to the servers via ssl. (default: false)
|
82
|
+
# ssl: true
|
83
|
+
|
84
|
+
# The certificate file used to identify the connection against MongoDB.
|
85
|
+
# ssl_cert: /path/to/my.cert
|
86
|
+
|
87
|
+
# The private keyfile used to identify the connection against MongoDB.
|
88
|
+
# Note that even if the key is stored in the same file as the certificate,
|
89
|
+
# both need to be explicitly specified.
|
90
|
+
# ssl_key: /path/to/my.key
|
91
|
+
|
92
|
+
# A passphrase for the private key.
|
93
|
+
# ssl_key_pass_phrase: password
|
94
|
+
|
95
|
+
# Whether or not to do peer certification validation. (default: true)
|
96
|
+
# ssl_verify: true
|
97
|
+
|
98
|
+
# The file containing a set of concatenated certification authority certifications
|
99
|
+
# used to validate certs passed from the other end of the connection.
|
100
|
+
# ssl_ca_cert: /path/to/ca.cert
|
101
|
+
|
102
|
+
|
103
|
+
# Configure Mongoid specific options. (optional)
|
104
|
+
options:
|
39
105
|
# Includes the root model name in json serialization. (default: false)
|
40
106
|
# include_root_in_json: false
|
41
107
|
|
42
|
-
# Include the _type field in
|
108
|
+
# Include the _type field in serialization. (default: false)
|
43
109
|
# include_type_for_serialization: false
|
44
110
|
|
45
111
|
# Preload all models in development, needed when models use
|
46
112
|
# inheritance. (default: false)
|
47
113
|
# preload_models: false
|
48
114
|
|
49
|
-
# Protect id and type from mass assignment. (default: true)
|
50
|
-
# protect_sensitive_fields: true
|
51
|
-
|
52
115
|
# Raise an error when performing a #find and the document is not found.
|
53
116
|
# (default: true)
|
54
117
|
# raise_not_found_error: true
|
@@ -57,23 +120,23 @@ development:
|
|
57
120
|
# existing method. (default: false)
|
58
121
|
# scope_overwrite_exception: false
|
59
122
|
|
60
|
-
#
|
61
|
-
# admin access. (default: false)
|
62
|
-
# skip_version_check: false
|
63
|
-
|
64
|
-
# User Active Support's time zone in conversions. (default: true)
|
123
|
+
# Use Active Support's time zone in conversions. (default: true)
|
65
124
|
# use_activesupport_time_zone: true
|
66
125
|
|
67
126
|
# Ensure all times are UTC in the app side. (default: false)
|
68
127
|
# use_utc: false
|
128
|
+
|
129
|
+
# Set the Mongoid and Ruby driver log levels when not in a Rails
|
130
|
+
# environment. The Mongoid logger will be set to the Rails logger
|
131
|
+
# otherwise.(default: :info)
|
132
|
+
# log_level: :info
|
69
133
|
test:
|
70
|
-
|
134
|
+
clients:
|
71
135
|
default:
|
72
136
|
database: dummy_test
|
73
137
|
hosts:
|
74
138
|
- localhost:27017
|
75
139
|
options:
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
retry_interval: 0
|
140
|
+
read:
|
141
|
+
mode: :primary
|
142
|
+
max_pool_size: 1
|
@@ -2,15 +2,11 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Draper::CollectionDecorator do
|
4
4
|
describe "#active_model_serializer" do
|
5
|
-
it "returns ActiveModel::
|
6
|
-
collection_decorator
|
7
|
-
|
8
|
-
collection_serializer = collection_decorator.active_model_serializer
|
9
|
-
else
|
10
|
-
collection_serializer = ActiveModel::Serializer.serializer_for(collection_decorator)
|
11
|
-
end
|
5
|
+
it "returns ActiveModel::Serializer::CollectionSerializer" do
|
6
|
+
collection_decorator = Draper::CollectionDecorator.new([])
|
7
|
+
collection_serializer = ActiveModel::Serializer.serializer_for(collection_decorator)
|
12
8
|
|
13
|
-
expect(collection_serializer).to be ActiveModel::
|
9
|
+
expect(collection_serializer).to be ActiveModel::Serializer::CollectionSerializer
|
14
10
|
end
|
15
11
|
end
|
16
12
|
end
|
@@ -54,8 +54,6 @@ describe PostDecorator do
|
|
54
54
|
end
|
55
55
|
|
56
56
|
it "serializes to XML" do
|
57
|
-
pending("Rails < 3.2 does not use `serializable_hash` in `to_xml`") if Rails.version.to_f < 3.2
|
58
|
-
|
59
57
|
xml = Capybara.string(decorator.to_xml)
|
60
58
|
expect(xml).to have_css "post > updated-at", text: "overridden"
|
61
59
|
end
|
@@ -10,14 +10,6 @@ describe PostMailer do
|
|
10
10
|
expect(email_body).to have_content "Today"
|
11
11
|
end
|
12
12
|
|
13
|
-
it "can use path helpers with a model" do
|
14
|
-
expect(email_body).to have_css "#path_with_model", text: "/en/posts/#{post.id}"
|
15
|
-
end
|
16
|
-
|
17
|
-
it "can use path helpers with an id" do
|
18
|
-
expect(email_body).to have_css "#path_with_id", text: "/en/posts/#{post.id}"
|
19
|
-
end
|
20
|
-
|
21
13
|
it "can use url helpers with a model" do
|
22
14
|
expect(email_body).to have_css "#url_with_model", text: "http://www.example.com:12345/en/posts/#{post.id}"
|
23
15
|
end
|
@@ -11,8 +11,6 @@ shared_examples_for "a decoratable model" do
|
|
11
11
|
|
12
12
|
describe "#==" do
|
13
13
|
it "is true for other instances' decorators" do
|
14
|
-
pending "Mongoid < 3.1 overrides `#==`" if defined?(Mongoid) && Mongoid::VERSION.to_f < 3.1 && described_class < Mongoid::Document
|
15
|
-
|
16
14
|
described_class.create
|
17
15
|
one = described_class.first
|
18
16
|
other = described_class.first
|
@@ -40,8 +40,9 @@ describe Rails::Generators::DecoratorGenerator do
|
|
40
40
|
|
41
41
|
context "with an ApplicationDecorator" do
|
42
42
|
before do
|
43
|
-
Object.
|
44
|
-
stub_const "ApplicationDecorator", Class.new
|
43
|
+
allow_any_instance_of(Object).to receive(:require).with("application_decorator").and_return(
|
44
|
+
stub_const "ApplicationDecorator", Class.new
|
45
|
+
)
|
45
46
|
end
|
46
47
|
|
47
48
|
before { run_generator %w(YourModel) }
|
@@ -38,16 +38,19 @@ app.start_server do
|
|
38
38
|
expect(page).to have_text("Goodnight, moon!").in("#goodnight_moon")
|
39
39
|
end
|
40
40
|
|
41
|
-
|
42
|
-
|
43
|
-
|
41
|
+
# _path helpers aren't available in mailers
|
42
|
+
if type == :view
|
43
|
+
it "can be passed to path helpers" do
|
44
|
+
expect(page).to have_text("/en/posts/1").in("#path_with_decorator")
|
45
|
+
end
|
44
46
|
|
45
|
-
|
46
|
-
|
47
|
-
|
47
|
+
it "can use path helpers with a model" do
|
48
|
+
expect(page).to have_text("/en/posts/1").in("#path_with_model")
|
49
|
+
end
|
48
50
|
|
49
|
-
|
50
|
-
|
51
|
+
it "can use path helpers with an id" do
|
52
|
+
expect(page).to have_text("/en/posts/1").in("#path_with_id")
|
53
|
+
end
|
51
54
|
end
|
52
55
|
|
53
56
|
it "can be passed to url helpers" do
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
|
3
3
|
require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])
|
4
|
-
Bundler.require
|
4
|
+
Bundler.require :default
|
5
5
|
|
6
6
|
require "benchmark"
|
7
7
|
require "draper"
|
data/spec/spec_helper.rb
CHANGED
@@ -21,11 +21,11 @@ module HaveTextMatcher
|
|
21
21
|
@subject.has_css?(@css || "*", text: @text)
|
22
22
|
end
|
23
23
|
|
24
|
-
def
|
24
|
+
def failure_message
|
25
25
|
"expected to find #{@text.inspect} #{within}"
|
26
26
|
end
|
27
27
|
|
28
|
-
def
|
28
|
+
def failure_message_when_negated
|
29
29
|
"expected not to find #{@text.inspect} #{within}"
|
30
30
|
end
|
31
31
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: draper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 3.0.0.pre1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeff Casimir
|
@@ -9,36 +9,36 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2016-07-10 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|
16
16
|
requirement: !ruby/object:Gem::Requirement
|
17
17
|
requirements:
|
18
|
-
- - "
|
18
|
+
- - "~>"
|
19
19
|
- !ruby/object:Gem::Version
|
20
|
-
version: '
|
20
|
+
version: '5.0'
|
21
21
|
type: :runtime
|
22
22
|
prerelease: false
|
23
23
|
version_requirements: !ruby/object:Gem::Requirement
|
24
24
|
requirements:
|
25
|
-
- - "
|
25
|
+
- - "~>"
|
26
26
|
- !ruby/object:Gem::Version
|
27
|
-
version: '
|
27
|
+
version: '5.0'
|
28
28
|
- !ruby/object:Gem::Dependency
|
29
29
|
name: actionpack
|
30
30
|
requirement: !ruby/object:Gem::Requirement
|
31
31
|
requirements:
|
32
|
-
- - "
|
32
|
+
- - "~>"
|
33
33
|
- !ruby/object:Gem::Version
|
34
|
-
version: '
|
34
|
+
version: '5.0'
|
35
35
|
type: :runtime
|
36
36
|
prerelease: false
|
37
37
|
version_requirements: !ruby/object:Gem::Requirement
|
38
38
|
requirements:
|
39
|
-
- - "
|
39
|
+
- - "~>"
|
40
40
|
- !ruby/object:Gem::Version
|
41
|
-
version: '
|
41
|
+
version: '5.0'
|
42
42
|
- !ruby/object:Gem::Dependency
|
43
43
|
name: request_store
|
44
44
|
requirement: !ruby/object:Gem::Requirement
|
@@ -57,16 +57,30 @@ dependencies:
|
|
57
57
|
name: activemodel
|
58
58
|
requirement: !ruby/object:Gem::Requirement
|
59
59
|
requirements:
|
60
|
-
- - "
|
60
|
+
- - "~>"
|
61
61
|
- !ruby/object:Gem::Version
|
62
|
-
version: '
|
62
|
+
version: '5.0'
|
63
63
|
type: :runtime
|
64
64
|
prerelease: false
|
65
65
|
version_requirements: !ruby/object:Gem::Requirement
|
66
66
|
requirements:
|
67
|
-
- - "
|
67
|
+
- - "~>"
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '5.0'
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
name: activemodel-serializers-xml
|
72
|
+
requirement: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - "~>"
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '1.0'
|
77
|
+
type: :runtime
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - "~>"
|
68
82
|
- !ruby/object:Gem::Version
|
69
|
-
version: '
|
83
|
+
version: '1.0'
|
70
84
|
- !ruby/object:Gem::Dependency
|
71
85
|
name: ammeter
|
72
86
|
requirement: !ruby/object:Gem::Requirement
|
@@ -87,42 +101,42 @@ dependencies:
|
|
87
101
|
requirements:
|
88
102
|
- - ">="
|
89
103
|
- !ruby/object:Gem::Version
|
90
|
-
version: 0
|
104
|
+
version: '0'
|
91
105
|
type: :development
|
92
106
|
prerelease: false
|
93
107
|
version_requirements: !ruby/object:Gem::Requirement
|
94
108
|
requirements:
|
95
109
|
- - ">="
|
96
110
|
- !ruby/object:Gem::Version
|
97
|
-
version: 0
|
111
|
+
version: '0'
|
98
112
|
- !ruby/object:Gem::Dependency
|
99
113
|
name: rspec-rails
|
100
114
|
requirement: !ruby/object:Gem::Requirement
|
101
115
|
requirements:
|
102
|
-
- - "
|
116
|
+
- - ">="
|
103
117
|
- !ruby/object:Gem::Version
|
104
|
-
version: '
|
118
|
+
version: '0'
|
105
119
|
type: :development
|
106
120
|
prerelease: false
|
107
121
|
version_requirements: !ruby/object:Gem::Requirement
|
108
122
|
requirements:
|
109
|
-
- - "
|
123
|
+
- - ">="
|
110
124
|
- !ruby/object:Gem::Version
|
111
|
-
version: '
|
125
|
+
version: '0'
|
112
126
|
- !ruby/object:Gem::Dependency
|
113
127
|
name: minitest-rails
|
114
128
|
requirement: !ruby/object:Gem::Requirement
|
115
129
|
requirements:
|
116
130
|
- - ">="
|
117
131
|
- !ruby/object:Gem::Version
|
118
|
-
version: '
|
132
|
+
version: '0'
|
119
133
|
type: :development
|
120
134
|
prerelease: false
|
121
135
|
version_requirements: !ruby/object:Gem::Requirement
|
122
136
|
requirements:
|
123
137
|
- - ">="
|
124
138
|
- !ruby/object:Gem::Version
|
125
|
-
version: '
|
139
|
+
version: '0'
|
126
140
|
- !ruby/object:Gem::Dependency
|
127
141
|
name: capybara
|
128
142
|
requirement: !ruby/object:Gem::Requirement
|
@@ -141,16 +155,16 @@ dependencies:
|
|
141
155
|
name: active_model_serializers
|
142
156
|
requirement: !ruby/object:Gem::Requirement
|
143
157
|
requirements:
|
144
|
-
- - "
|
158
|
+
- - "~>"
|
145
159
|
- !ruby/object:Gem::Version
|
146
|
-
version: '0'
|
160
|
+
version: '0.10'
|
147
161
|
type: :development
|
148
162
|
prerelease: false
|
149
163
|
version_requirements: !ruby/object:Gem::Requirement
|
150
164
|
requirements:
|
151
|
-
- - "
|
165
|
+
- - "~>"
|
152
166
|
- !ruby/object:Gem::Version
|
153
|
-
version: '0'
|
167
|
+
version: '0.10'
|
154
168
|
description: Draper adds an object-oriented layer of presentation logic to your Rails
|
155
169
|
apps.
|
156
170
|
email:
|
@@ -172,9 +186,6 @@ files:
|
|
172
186
|
- README.md
|
173
187
|
- Rakefile
|
174
188
|
- draper.gemspec
|
175
|
-
- gemfiles/4.0.gemfile
|
176
|
-
- gemfiles/4.1.gemfile
|
177
|
-
- gemfiles/4.2.gemfile
|
178
189
|
- lib/draper.rb
|
179
190
|
- lib/draper/automatic_delegation.rb
|
180
191
|
- lib/draper/collection_decorator.rb
|
@@ -314,15 +325,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
314
325
|
requirements:
|
315
326
|
- - ">="
|
316
327
|
- !ruby/object:Gem::Version
|
317
|
-
version:
|
328
|
+
version: 2.2.2
|
318
329
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
319
330
|
requirements:
|
320
|
-
- - "
|
331
|
+
- - ">"
|
321
332
|
- !ruby/object:Gem::Version
|
322
|
-
version:
|
333
|
+
version: 1.3.1
|
323
334
|
requirements: []
|
324
335
|
rubyforge_project:
|
325
|
-
rubygems_version: 2.
|
336
|
+
rubygems_version: 2.5.1
|
326
337
|
signing_key:
|
327
338
|
specification_version: 4
|
328
339
|
summary: View Models for Rails
|
data/gemfiles/4.0.gemfile
DELETED
data/gemfiles/4.1.gemfile
DELETED
data/gemfiles/4.2.gemfile
DELETED