Commit Graph

4 Commits

Author SHA1 Message Date
oieioi 9cb42f6e71
Fix kwargs for Ruby 2.7 (#885)
* Fix kwargs for Ruby 2.7

* Test with Ruby 3.0

Co-authored-by: Nicolas Rodriguez <nicoladmin@free.fr>
2021-01-27 10:44:29 -06:00
Douglas Lutz 661c1a9f0f Add preservation of decorator options on QueryMethods (#868) 2020-01-03 15:17:34 -06:00
Bruno Castro 5e4f529bb8 fix: Make CollectionDecorator respond_to? to ORM methods (#850)
## Testing
1. Create a decorator for the model and its association
```ruby
class OrderHistoryDecorator < Draper::Decorator
  delegate_all
end

class OrderDecorator < Draper::Decorator
  delegate_all

  decorates_association :order_histories, with: OrderHistoryDecorator
end
```

2. Call `respond_to?` with some ORM method allowed by the strategy
```ruby
[1] pry(main)> order.order_histories.decorate.respond_to?(:includes)
=> true
```

## References
* method_missing [usage](https://thoughtbot.com/blog/always-define-respond-to-missing-when-overriding)
2019-03-16 14:15:16 -05:00
Bruno Castro 6b3e9bc5c9 feat: Include ORM associations in CollectionDecorator (#845)
## Description
Include all QueryMethods from the ORM in CollectionDecorator. The default adapter is :active_record

* Why was this change required?
It was necessary to delegate or define a method of the ORM which you are using in your decorator to make an instance of CollectionDecorator able to call it.
* Is there something you aren't happy with or that needs extra attention?
In order to support other ORM associations, we'll need to write a method `allowed?` for each strategy at `lib/draper/query_methods/load_strategy.rb`

## Testing
1. Create a decorator for the model and its association
```ruby
class OrderHistoryDecorator < Draper::Decorator
  delegate_all
end

class OrderDecorator < Draper::Decorator
  delegate_all

  decorates_association :order_histories, with: OrderHistoryDecorator
end
```

2. Call any query method in the decorated instance
```ruby
pry(main)> Order.last.decorate.order_histories.includes(:user)
```

## References
* Issue #702 
* Issue #812
2019-02-25 10:44:19 -06:00