draper 1.2.1 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0f6bd44145856c0f804f44cd0bc8fc38490dd37d
4
- data.tar.gz: fc320b6749db7c272ba791f118774f2bc01640dd
3
+ metadata.gz: 0e75f0dd1ba7ae0030d13480aff3ff107d0d4b4c
4
+ data.tar.gz: 65a8625646622e1028e5a39cc7211cae6149fd5e
5
5
  SHA512:
6
- metadata.gz: 6d6fa20641f68112dba5e37c4e9b355b4f1f11f39cc3f7812e4e2631cf303bcc935f3c5d81265adaf0e96ae907bb60934b1eb047bdd2d2b9236eac9eb767a566
7
- data.tar.gz: c92ef62f75eef8d105887c5be659171981ca59287da7b060d49755c608f3d1e50b0ef79da898c0586c2aaaccf50d7037059fe457cae2a3b3e294f18661f31535
6
+ metadata.gz: e59d96cc6a143e504f2382de22aeeb2d577f062353464cd31d25f161305fdf92609438f77c5b4fb3490cbd23f970286d4de4566729c39db04da47397b80a21a1
7
+ data.tar.gz: e8c846f71bdbcee910f1307d915780da808098303dcba43e7a2dfc3944b791640b866bc20d01d55366585be6a015a82d07fdb23c8b092e83ec5d622461212a12
data/.travis.yml CHANGED
@@ -8,15 +8,14 @@ rvm:
8
8
  - 2.0.0
9
9
  - rbx-19mode
10
10
  - jruby-19mode
11
- - ruby-head
12
11
 
13
12
  env:
13
+ - "RAILS_VERSION=4.0"
14
14
  - "RAILS_VERSION=3.2"
15
15
  - "RAILS_VERSION=3.1"
16
16
  - "RAILS_VERSION=3.0"
17
- - "RAILS_VERSION=master"
17
+ - "RAILS_VERSION=4.1"
18
18
 
19
19
  matrix:
20
20
  allow_failures:
21
- - rvm: ruby-head
22
- - env: "RAILS_VERSION=master"
21
+ - env: "RAILS_VERSION=4.1"
data/CHANGELOG.md CHANGED
@@ -6,7 +6,7 @@
6
6
 
7
7
  * [Document stubbing route helpers](https://github.com/drapergem/draper/commit/dbe8a81ca7d4d9ae87b4b62926a0ba6379397fbc)
8
8
 
9
- * [Rename `source` to `object`. `source` still works, but will be depreciated in a future release.](https://github.com/drapergem/draper/commit/4b933ef39d252ecfe93c573a072633be545c49fb)
9
+ * [Rename `source` to `object`. `source` still works, but will be deprecated in a future release.](https://github.com/drapergem/draper/commit/4b933ef39d252ecfe93c573a072633be545c49fb)
10
10
 
11
11
  Various bugfixes, as always.
12
12
 
data/CONTRIBUTING.md CHANGED
@@ -1,10 +1,13 @@
1
- ## Filing issues
1
+ Contributing to Draper
2
+ ===================
2
3
 
3
- To help us fix the problem you've found, please let us know your versions of Draper and Rails (and any other gems that are relevant to your issue, e.g. RSpec if you're having trouble in your tests).
4
+ First of all, **thank you** for wanting to help and reading this!
5
+
6
+ If you have found a problem with Draper, please [check to see](https://github.com/drapergem/draper/issues) if there's already an issue and if there's not, [create a new report](https://github.com/drapergem/draper/issues/new). Please include your versions of Draper and Rails (and any other gems that are relevant to your issue, e.g. RSpec if you're having trouble in your tests).
4
7
 
5
8
  ## Sending a pull request
6
9
 
7
- So you want to help us out... thanks! Here's a quick how-to:
10
+ Thanks again! Here's a quick how-to:
8
11
 
9
12
  1. [Fork the project](https://help.github.com/articles/fork-a-repo).
10
13
  2. Create a branch - `git checkout -b adding_magic`
@@ -13,3 +16,5 @@ So you want to help us out... thanks! Here's a quick how-to:
13
16
  5. Commit your changes - `git commit -am "Added some magic"`
14
17
  6. Push the branch to Github - `git push origin adding_magic`
15
18
  7. Send us a [pull request](https://help.github.com/articles/using-pull-requests)!
19
+
20
+ :heart: :sparkling_heart: :heart:
data/Gemfile CHANGED
@@ -8,32 +8,9 @@ end
8
8
 
9
9
  platforms :jruby do
10
10
  gem "minitest", ">= 3.0"
11
- gem "activerecord-jdbcsqlite3-adapter"
11
+ gem "activerecord-jdbcsqlite3-adapter", ">= 1.3.0.beta2"
12
12
  end
13
13
 
14
- version = ENV["RAILS_VERSION"] || "3.2"
14
+ version = ENV["RAILS_VERSION"] || "4.0"
15
15
 
16
- rails = case version
17
- when "master"
18
- {github: "rails/rails"}
19
- else
20
- "~> #{version}.0"
21
- end
22
-
23
- mongoid = case version
24
- when "master"
25
- {github: "mongoid/mongoid"}
26
- when "3.2"
27
- "~> 3.1.0"
28
- when "3.1"
29
- "~> 3.0.0"
30
- end
31
-
32
- devise = case version
33
- when "3.1", "3.2"
34
- "~> 2.2"
35
- end
36
-
37
- gem "rails", rails
38
- gem "mongoid", mongoid if mongoid
39
- gem "devise", devise if devise
16
+ eval_gemfile File.expand_path("../gemfiles/#{version}.gemfile", __FILE__)
data/README.md CHANGED
@@ -52,7 +52,7 @@ design calls for a slighly different formatting to the date for a `Book`.
52
52
  Now your helper method can either switch based on the input class type (poor
53
53
  Ruby style), or you break it out into two methods, `book_publication_status` and
54
54
  `article_publication_status`. And keep adding methods for each publication
55
- type...to the global helper namespace. And remember all the names. Ick.
55
+ type...to the global helper namespace. And you'll have to remember all the names. Ick.
56
56
 
57
57
  Ruby thrives when we use Object-Oriented style. If you didn't know Rails'
58
58
  helpers existed, you'd probably imagine that your view template could feature
@@ -109,7 +109,7 @@ Decorators are the ideal place to:
109
109
  Add Draper to your Gemfile:
110
110
 
111
111
  ```ruby
112
- gem 'draper', '~> 1.0'
112
+ gem 'draper', '~> 1.3'
113
113
  ```
114
114
 
115
115
  And run `bundle install` within your app's directory.
@@ -131,11 +131,12 @@ end
131
131
 
132
132
  ### Generators
133
133
 
134
- When you have Draper installed and generate a resource with...
134
+ When you have Draper installed and generate a controller...
135
135
 
136
136
  ```
137
137
  rails generate resource Article
138
138
  ```
139
+
139
140
  ...you'll get a decorator for free!
140
141
 
141
142
  But if the `Article` model already exists, you can run...
@@ -149,7 +150,7 @@ rails generate decorator Article
149
150
  ### Accessing Helpers
150
151
 
151
152
  Normal Rails helpers are still useful for lots of tasks. Both Rails' provided
152
- helper and those defined in your app can be accessed via the `h` method:
153
+ helpers and those defined in your app can be accessed within a decorator via the `h` method:
153
154
 
154
155
  ```ruby
155
156
  class ArticleDecorator < Draper::Decorator
@@ -167,7 +168,8 @@ include Draper::LazyHelpers
167
168
 
168
169
  ...at the top of your decorator class - you'll mix in a bazillion methods and
169
170
  never have to type `h.` again.
170
- (Note: the `capture` method is only available through `h` or `helpers`)
171
+
172
+ (*Note*: the `capture` method is only available through `h` or `helpers`)
171
173
 
172
174
  ### Accessing the model
173
175
 
@@ -187,7 +189,7 @@ end
187
189
 
188
190
  ### Single Objects
189
191
 
190
- Ok, so you've written a sweet decorator, now you're going to want to put it in
192
+ Ok, so you've written a sweet decorator, now you're going to want to put it into
191
193
  action! A simple option is to call the `decorate` method on your model:
192
194
 
193
195
  ```ruby
@@ -206,7 +208,9 @@ control - say you want to decorate a `Widget` with a more general
206
208
 
207
209
  ### Collections
208
210
 
209
- If you have a whole bunch of objects, you can decorate them all in one fell
211
+ #### Decorating Individual Elements
212
+
213
+ If you have a collection of objects, you can decorate them all in one fell
210
214
  swoop:
211
215
 
212
216
  ```ruby
@@ -223,6 +227,8 @@ If your collection is an ActiveRecord query, you can use this:
223
227
  _cannot_ use the technique of `Article.all.decorate` in Rails 3. In Rails 4,
224
228
  `.all` returns a query so this techique would work fine.
225
229
 
230
+ #### Decorating the Collection Itself
231
+
226
232
  If you want to add methods to your decorated collection (for example, for
227
233
  pagination), you can subclass `Draper::CollectionDecorator`:
228
234
 
@@ -240,7 +246,7 @@ end
240
246
  @articles = ArticlesDecorator.decorate(Article.all)
241
247
  ```
242
248
 
243
- Draper decorates each item using its `decorate` method. Alternatively, you can
249
+ Draper decorates each item by calling the `decorate` method. Alternatively, you can
244
250
  specify a decorator by overriding the collection decorator's `decorator_class`
245
251
  method, or by passing the `:with` option to the constructor.
246
252
 
@@ -263,8 +269,11 @@ Support](http://api.rubyonrails.org/classes/Module.html#method-i-delegate),
263
269
  except that the `:to` option is not required; it defaults to `:object` when
264
270
  omitted.
265
271
 
266
- [will_paginate](https://github.com/mislav/will_paginate) needs you to
267
- `delegate :current_page, :per_page, :offset, :total_entries, :total_pages`.
272
+ [will_paginate](https://github.com/mislav/will_paginate) needs the following delegations:
273
+
274
+ ```ruby
275
+ delegate :current_page, :per_page, :offset, :total_entries, :total_pages
276
+ ```
268
277
 
269
278
  ### Decorating Associated Objects
270
279
 
@@ -297,7 +306,7 @@ your `ArticleDecorator` and they'll return decorated objects:
297
306
  @article = ArticleDecorator.find(params[:id])
298
307
  ```
299
308
 
300
- ### When to decorate objects
309
+ ### When to Decorate Objects
301
310
 
302
311
  Decorators are supposed to behave very much like the models they decorate, and
303
312
  for that reason it is very tempting to just decorate your objects at the start
@@ -369,7 +378,7 @@ In your `Spork.prefork` block of `spec_helper.rb`, add this:
369
378
  require 'draper/test/rspec_integration'
370
379
  ```
371
380
 
372
- ### Isolated tests
381
+ ### Isolated Tests
373
382
 
374
383
  In tests, Draper needs to build a view context to access helper methods. By
375
384
  default, it will create an `ApplicationController` and then use its view
@@ -390,7 +399,7 @@ Draper::ViewContext.test_strategy :fast do
390
399
  end
391
400
  ```
392
401
 
393
- #### Stubbing route helper functions
402
+ #### Stubbing Route Helper Functions
394
403
 
395
404
  If you are writing isolated tests for Draper methods that call route helper
396
405
  methods, you can stub them instead of needing to require Rails.
@@ -476,7 +485,7 @@ the following:
476
485
  @article.author_title # Returns the article's `author.title`
477
486
  ```
478
487
 
479
- ### Adding context
488
+ ### Adding Context
480
489
 
481
490
  If you need to pass extra data to your decorators, you can use a `context` hash.
482
491
  Methods that create decorators take it as an option, for example:
@@ -554,7 +563,7 @@ end
554
563
 
555
564
  This is only necessary when proxying class methods.
556
565
 
557
- ### Making models decoratable
566
+ ### Making Models Decoratable
558
567
 
559
568
  Models get their `decorate` method from the `Draper::Decoratable` module, which
560
569
  is included in `ActiveRecord::Base` and `Mongoid::Document` by default. If
data/draper.gemspec CHANGED
@@ -20,6 +20,7 @@ Gem::Specification.new do |s|
20
20
  s.add_dependency 'activesupport', '>= 3.0'
21
21
  s.add_dependency 'actionpack', '>= 3.0'
22
22
  s.add_dependency 'request_store', '~> 1.0.3'
23
+ s.add_dependency 'activemodel', '>= 3.0'
23
24
 
24
25
  s.add_development_dependency 'ammeter'
25
26
  s.add_development_dependency 'rake', '>= 0.9.2'
@@ -0,0 +1,2 @@
1
+ gem "rails", "~> 3.0.0"
2
+ gem "active_model_serializers", "~> 0.7.0"
@@ -0,0 +1,3 @@
1
+ gem "rails", "~> 3.1.0"
2
+ gem "mongoid", "~> 3.0.0"
3
+ gem "devise", "~> 2.2"
@@ -0,0 +1,3 @@
1
+ gem "rails", "~> 3.2.0"
2
+ gem "mongoid", "~> 3.1.0"
3
+ gem "devise", "~> 2.2"
@@ -0,0 +1,3 @@
1
+ gem "rails", "~> 4.0.0"
2
+ gem "mongoid", github: "mongoid/mongoid"
3
+ gem "devise", "~> 3.0.0"
@@ -0,0 +1,2 @@
1
+ gem "rails", github: "rails/rails"
2
+ gem "devise", github: "plataformatec/devise"
data/lib/draper.rb CHANGED
@@ -6,6 +6,7 @@ require 'active_model/serializers/xml'
6
6
  require 'active_support/inflector'
7
7
  require 'active_support/core_ext/hash/keys'
8
8
  require 'active_support/core_ext/hash/reverse_merge'
9
+ require 'active_support/core_ext/name_error'
9
10
 
10
11
  require 'draper/version'
11
12
  require 'draper/view_helpers'
@@ -23,6 +23,10 @@ module Draper
23
23
  self.class.decorator_class
24
24
  end
25
25
 
26
+ def decorator_class?
27
+ self.class.decorator_class?
28
+ end
29
+
26
30
  # The list of decorators that have been applied to the object.
27
31
  #
28
32
  # @return [Array<Class>] `[]`
@@ -56,6 +60,12 @@ module Draper
56
60
  decorator_class.decorate_collection(collection, options.reverse_merge(with: nil))
57
61
  end
58
62
 
63
+ def decorator_class?
64
+ decorator_class
65
+ rescue Draper::UninferrableDecoratorError
66
+ false
67
+ end
68
+
59
69
  # Infers the decorator class to be used by {Decoratable#decorate} (e.g.
60
70
  # `Product` maps to `ProductDecorator`).
61
71
  #
@@ -57,6 +57,7 @@ module Draper
57
57
  # @return [void]
58
58
  def self.decorates(object_class)
59
59
  @object_class = object_class.to_s.camelize.constantize
60
+ alias_object_to_object_class_name
60
61
  end
61
62
 
62
63
  # Returns the source class corresponding to the decorator class, as set by
@@ -187,6 +188,20 @@ module Draper
187
188
  super || object.instance_of?(klass)
188
189
  end
189
190
 
191
+ if RUBY_VERSION < "2.0"
192
+ # nasty hack to stop 1.9.x using the delegated `to_s` in `inspect`
193
+ alias_method :_to_s, :to_s
194
+
195
+ def inspect
196
+ ivars = instance_variables.map do |name|
197
+ "#{name}=#{instance_variable_get(name).inspect}"
198
+ end
199
+ _to_s.insert(-2, " #{ivars.join(", ")}")
200
+ end
201
+ end
202
+
203
+ delegate :to_s
204
+
190
205
  # In case object is nil
191
206
  delegate :present?, :blank?
192
207
 
@@ -219,6 +234,15 @@ module Draper
219
234
 
220
235
  private
221
236
 
237
+ def self.inherited(subclass)
238
+ subclass.alias_object_to_object_class_name
239
+ super
240
+ end
241
+
242
+ def self.alias_object_to_object_class_name
243
+ alias_method object_class.name.underscore, :object if object_class?
244
+ end
245
+
222
246
  def self.object_class_name
223
247
  raise NameError if name.nil? || name.demodulize !~ /.+Decorator$/
224
248
  name.chomp("Decorator")
@@ -6,7 +6,7 @@ module ActiveModel
6
6
  app ||= Rails.application # Rails 3.0.x does not yield `app`
7
7
 
8
8
  Rails::Generators.configure! app.config.generators
9
- require_relative '../generators/resource_override'
9
+ require_relative '../generators/controller_override'
10
10
  end
11
11
  end
12
12
  end
@@ -10,7 +10,7 @@ module Draper
10
10
  config.include DecoratorExampleGroup, example_group: {file_path: %r{spec/decorators}}, type: :decorator
11
11
 
12
12
  [:decorator, :controller, :mailer].each do |type|
13
- config.after(:each, type: type) { Draper::ViewContext.clear! }
13
+ config.before(:each, type: type) { Draper::ViewContext.clear! }
14
14
  end
15
15
  end
16
16
  end
@@ -1,3 +1,3 @@
1
1
  module Draper
2
- VERSION = "1.2.1"
2
+ VERSION = "1.3.0"
3
3
  end
@@ -0,0 +1,15 @@
1
+ require "rails/generators"
2
+ require "rails/generators/rails/controller/controller_generator"
3
+ require "rails/generators/rails/scaffold_controller/scaffold_controller_generator"
4
+
5
+ module Rails
6
+ module Generators
7
+ class ControllerGenerator
8
+ hook_for :decorator, default: true
9
+ end
10
+
11
+ class ScaffoldControllerGenerator
12
+ hook_for :decorator, default: true
13
+ end
14
+ end
15
+ end
@@ -133,7 +133,7 @@ module Draper
133
133
  context "without a block" do
134
134
  it "decorates object.find" do
135
135
  object = []
136
- found = stub(decorate: :decorated)
136
+ found = double(decorate: :decorated)
137
137
  decorator = CollectionDecorator.new(object)
138
138
 
139
139
  object.should_receive(:find).and_return(found)
@@ -46,6 +46,26 @@ module Draper
46
46
  end
47
47
  end
48
48
 
49
+ describe "#decorator_class?" do
50
+ it "returns true for decoratable model" do
51
+ expect(Product.new.decorator_class?).to be_true
52
+ end
53
+
54
+ it "returns false for non-decoratable model" do
55
+ expect(Model.new.decorator_class?).to be_false
56
+ end
57
+ end
58
+
59
+ describe ".decorator_class?" do
60
+ it "returns true for decoratable model" do
61
+ expect(Product.decorator_class?).to be_true
62
+ end
63
+
64
+ it "returns false for non-decoratable model" do
65
+ expect(Model.decorator_class?).to be_false
66
+ end
67
+ end
68
+
49
69
  describe "#decorator_class" do
50
70
  it "delegates to .decorator_class" do
51
71
  product = Product.new
@@ -361,6 +361,46 @@ module Draper
361
361
  end
362
362
  end
363
363
 
364
+ describe "aliasing object to object class name" do
365
+ context "when object_class is inferrable from the decorator name" do
366
+ it "aliases object to the object class name" do
367
+ object = double
368
+ decorator = ProductDecorator.new(object)
369
+
370
+ expect(decorator.product).to be object
371
+ end
372
+ end
373
+
374
+ context "when object_class is set by decorates" do
375
+ it "aliases object to the object class name" do
376
+ decorator_class = Class.new(Decorator) { decorates Product }
377
+ object = double
378
+ decorator = decorator_class.new(object)
379
+
380
+ expect(decorator.product).to be object
381
+ end
382
+ end
383
+
384
+ context "when object_class's name is several words long" do
385
+ it "underscores the method name" do
386
+ stub_const "LongWindedModel", Class.new
387
+ decorator_class = Class.new(Decorator) { decorates LongWindedModel }
388
+ object = double
389
+ decorator = decorator_class.new(object)
390
+
391
+ expect(decorator.long_winded_model).to be object
392
+ end
393
+ end
394
+
395
+ context "when object_class is not set" do
396
+ it "does not alias object" do
397
+ decorator_class = Class.new(Decorator)
398
+
399
+ expect(decorator_class.instance_methods).to eq Decorator.instance_methods
400
+ end
401
+ end
402
+ end
403
+
364
404
  describe "#to_model" do
365
405
  it "returns the decorator" do
366
406
  decorator = Decorator.new(Model.new)
@@ -401,6 +441,41 @@ module Draper
401
441
  end
402
442
  end
403
443
 
444
+ describe "#to_s" do
445
+ it "delegates to the object" do
446
+ decorator = Decorator.new(double(to_s: :delegated))
447
+
448
+ expect(decorator.to_s).to be :delegated
449
+ end
450
+ end
451
+
452
+ describe "#inspect" do
453
+ it "returns a detailed description of the decorator" do
454
+ decorator = ProductDecorator.new(double)
455
+
456
+ expect(decorator.inspect).to match /#<ProductDecorator:0x\h+ .+>/
457
+ end
458
+
459
+ it "includes the object" do
460
+ decorator = Decorator.new(double(inspect: "#<the object>"))
461
+
462
+ expect(decorator.inspect).to include "@object=#<the object>"
463
+ end
464
+
465
+ it "includes the context" do
466
+ decorator = Decorator.new(double, context: {foo: "bar"})
467
+
468
+ expect(decorator.inspect).to include '@context={:foo=>"bar"}'
469
+ end
470
+
471
+ it "includes other instance variables" do
472
+ decorator = Decorator.new(double)
473
+ decorator.instance_variable_set :@foo, "bar"
474
+
475
+ expect(decorator.inspect).to include '@foo="bar"'
476
+ end
477
+ end
478
+
404
479
  describe "#attributes" do
405
480
  it "returns only the object's attributes that are implemented by the decorator" do
406
481
  decorator = Decorator.new(double(attributes: {foo: "bar", baz: "qux"}))
@@ -630,7 +705,6 @@ module Draper
630
705
  object = Class.new{def hello_world; end}.new
631
706
  decorator = Decorator.new(object)
632
707
 
633
- expect { decorator.method(:hello_world) }.not_to raise_error NameError
634
708
  expect(decorator.method(:hello_world)).not_to be_nil
635
709
  end
636
710
  end
@@ -639,7 +713,6 @@ module Draper
639
713
  it "allows .method to be called on delegated class methods" do
640
714
  Decorator.stub object_class: double(hello_world: :delegated)
641
715
 
642
- expect { Decorator.method(:hello_world) }.not_to raise_error NameError
643
716
  expect(Decorator.method(:hello_world)).not_to be_nil
644
717
  end
645
718
  end
@@ -1,2 +1,4 @@
1
- class MongoidPostDecorator < Draper::Decorator
1
+ if defined?(Mongoid)
2
+ class MongoidPostDecorator < Draper::Decorator
3
+ end
2
4
  end
@@ -20,12 +20,18 @@
20
20
  <dt>Helpers from the controller:</dt>
21
21
  <dd id="goodnight_moon"><%= post.goodnight_moon %></dd>
22
22
 
23
+ <dt>Path with decorator:</dt>
24
+ <dd id="path_with_decorator"><%= post_path(post) %></dd>
25
+
23
26
  <dt>Path with model:</dt>
24
27
  <dd id="path_with_model"><%= post.path_with_model %></dd>
25
28
 
26
29
  <dt>Path with id:</dt>
27
30
  <dd id="path_with_id"><%= post.path_with_id %></dd>
28
31
 
32
+ <dt>URL with decorator:</dt>
33
+ <dd id="url_with_decorator"><%= post_url(post) %></dd>
34
+
29
35
  <dt>URL with model:</dt>
30
36
  <dd id="url_with_model"><%= post.url_with_model %></dd>
31
37
 
@@ -16,6 +16,10 @@ describe PostDecorator do
16
16
  expect(decorator.hello_world).to eq "Hello, world!"
17
17
  end
18
18
 
19
+ it "can be passed to path helpers" do
20
+ expect(helpers.post_path(decorator)).to eq "/en/posts/#{object.id}"
21
+ end
22
+
19
23
  it "can use path helpers with its model" do
20
24
  expect(decorator.path_with_model).to eq "/en/posts/#{object.id}"
21
25
  end
@@ -24,6 +28,10 @@ describe PostDecorator do
24
28
  expect(decorator.path_with_id).to eq "/en/posts/#{object.id}"
25
29
  end
26
30
 
31
+ it "can be passed to url helpers" do
32
+ expect(helpers.post_url(decorator)).to eq "http://www.example.com:12345/en/posts/#{object.id}"
33
+ end
34
+
27
35
  it "can use url helpers with its model" do
28
36
  expect(decorator.url_with_model).to eq "http://www.example.com:12345/en/posts/#{object.id}"
29
37
  end
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
  require 'rails'
3
3
  require 'ammeter/init'
4
- require 'generators/decorator/decorator_generator'
4
+ require 'generators/rails/decorator_generator'
5
5
 
6
6
  describe Rails::Generators::DecoratorGenerator do
7
7
  destination File.expand_path("../tmp", __FILE__)
@@ -38,6 +38,10 @@ app.start_server do
38
38
  expect(page).to have_text("Goodnight, moon!").in("#goodnight_moon")
39
39
  end
40
40
 
41
+ it "can be passed to path helpers" do
42
+ expect(page).to have_text("/en/posts/1").in("#path_with_decorator")
43
+ end
44
+
41
45
  it "can use path helpers with a model" do
42
46
  expect(page).to have_text("/en/posts/1").in("#path_with_model")
43
47
  end
@@ -46,6 +50,10 @@ app.start_server do
46
50
  expect(page).to have_text("/en/posts/1").in("#path_with_id")
47
51
  end
48
52
 
53
+ it "can be passed to url helpers" do
54
+ expect(page).to have_text("http://www.example.com:12345/en/posts/1").in("#url_with_decorator")
55
+ end
56
+
49
57
  it "can use url helpers with a model" do
50
58
  expect(page).to have_text("http://www.example.com:12345/en/posts/1").in("#url_with_model")
51
59
  end
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: 1.2.1
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeff Casimir
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-05-05 00:00:00.000000000 Z
12
+ date: 2013-10-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
@@ -53,6 +53,20 @@ dependencies:
53
53
  - - ~>
54
54
  - !ruby/object:Gem::Version
55
55
  version: 1.0.3
56
+ - !ruby/object:Gem::Dependency
57
+ name: activemodel
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - '>='
61
+ - !ruby/object:Gem::Version
62
+ version: '3.0'
63
+ type: :runtime
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '3.0'
56
70
  - !ruby/object:Gem::Dependency
57
71
  name: ammeter
58
72
  requirement: !ruby/object:Gem::Requirement
@@ -186,6 +200,11 @@ files:
186
200
  - README.md
187
201
  - Rakefile
188
202
  - draper.gemspec
203
+ - gemfiles/3.0.gemfile
204
+ - gemfiles/3.1.gemfile
205
+ - gemfiles/3.2.gemfile
206
+ - gemfiles/4.0.gemfile
207
+ - gemfiles/4.1.gemfile
189
208
  - lib/draper.rb
190
209
  - lib/draper/automatic_delegation.rb
191
210
  - lib/draper/collection_decorator.rb
@@ -210,12 +229,12 @@ files:
210
229
  - lib/draper/view_context.rb
211
230
  - lib/draper/view_context/build_strategy.rb
212
231
  - lib/draper/view_helpers.rb
213
- - lib/generators/decorator/decorator_generator.rb
214
- - lib/generators/decorator/templates/decorator.rb
232
+ - lib/generators/controller_override.rb
215
233
  - lib/generators/mini_test/decorator_generator.rb
216
234
  - lib/generators/mini_test/templates/decorator_spec.rb
217
235
  - lib/generators/mini_test/templates/decorator_test.rb
218
- - lib/generators/resource_override.rb
236
+ - lib/generators/rails/decorator_generator.rb
237
+ - lib/generators/rails/templates/decorator.rb
219
238
  - lib/generators/rspec/decorator_generator.rb
220
239
  - lib/generators/rspec/templates/decorator_spec.rb
221
240
  - lib/generators/test_unit/decorator_generator.rb
@@ -330,7 +349,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
330
349
  version: '0'
331
350
  requirements: []
332
351
  rubyforge_project:
333
- rubygems_version: 2.0.0
352
+ rubygems_version: 2.0.3
334
353
  signing_key:
335
354
  specification_version: 4
336
355
  summary: View Models for Rails
@@ -425,4 +444,3 @@ test_files:
425
444
  - spec/support/matchers/have_text.rb
426
445
  - spec/support/shared_examples/decoratable_equality.rb
427
446
  - spec/support/shared_examples/view_helpers.rb
428
- has_rdoc:
@@ -1,12 +0,0 @@
1
- require "rails/generators"
2
- require "rails/generators/rails/resource/resource_generator"
3
-
4
- module Rails
5
- module Generators
6
- ResourceGenerator.class_eval do
7
- def add_decorator
8
- invoke "decorator"
9
- end
10
- end
11
- end
12
- end