draper-extensions 0.1.0
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 +7 -0
- data/.coveralls.yml +2 -0
- data/.gitignore +23 -0
- data/.rspec +1 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/.travis.yml +15 -0
- data/Gemfile +19 -0
- data/Guardfile +24 -0
- data/LICENSE.txt +22 -0
- data/README.md +106 -0
- data/Rakefile +10 -0
- data/draper-extensions.gemspec +22 -0
- data/lib/draper-extensions.rb +1 -0
- data/lib/draper/extensions.rb +10 -0
- data/lib/draper/extensions/active_relation.rb +15 -0
- data/lib/draper/extensions/collection_decorator.rb +40 -0
- data/lib/draper/extensions/paginatable_array.rb +14 -0
- data/lib/draper/extensions/version.rb +5 -0
- data/spec/app/decorators/ar_event_decorator.rb +3 -0
- data/spec/app/decorators/ar_listing_decorator.rb +3 -0
- data/spec/app/decorators/mongo_event_decorator.rb +3 -0
- data/spec/app/decorators/mongo_events_decorator.rb +4 -0
- data/spec/app/decorators/mongo_listing_decorator.rb +5 -0
- data/spec/app/models/ar_event.rb +2 -0
- data/spec/app/models/ar_listing.rb +3 -0
- data/spec/app/models/mongo_event.rb +8 -0
- data/spec/app/models/mongo_listing.rb +7 -0
- data/spec/config/active_record/connection.rb +19 -0
- data/spec/config/mongoid/connection.rb +3 -0
- data/spec/config/mongoid/mongoid.yml +6 -0
- data/spec/lib/draper/extensions/active_relation_spec.rb +17 -0
- data/spec/lib/draper/extensions/collection_decorator_spec.rb +54 -0
- data/spec/lib/draper/extensions/paginatable_array_spec.rb +14 -0
- data/spec/spec_helper.rb +65 -0
- metadata +108 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 8d804b9e6e617c86427048a4f9b4ab3ca90ea6dd
|
4
|
+
data.tar.gz: 6ebc901c79746ad462157b8a3fe5f050505cb817
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c977b68fe791434c8c45438e944eda085c08b5a33bc9918f3e38f704ce7073889baa688e98fa339a4b6b2f2b268077544c95219a59fc4de89b42379966f660df
|
7
|
+
data.tar.gz: 60850e0a2931c05f95d323cd239e9a52937901c9333e3bc83aa0e866abc8d4f5400a7cd27e12238c8d5ccd4d4f877532aec0182a8ec0b2fb5256cfd89e71a960
|
data/.coveralls.yml
ADDED
data/.gitignore
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
*.bundle
|
19
|
+
*.so
|
20
|
+
*.o
|
21
|
+
*.a
|
22
|
+
mkmf.log
|
23
|
+
spec/test.sqlite3
|
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
draper-extensions
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ruby-2.1.1
|
data/.travis.yml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
services: mongodb
|
2
|
+
language: ruby
|
3
|
+
script: "bundle exec rake spec"
|
4
|
+
rvm:
|
5
|
+
- 1.9.3
|
6
|
+
- 2.0.0
|
7
|
+
- 2.1.0
|
8
|
+
- 2.1.1
|
9
|
+
env:
|
10
|
+
- CODECLIMATE_REPO_TOKEN=5cd40e471a2be2282170f06be821052b9c9f6a44961176068feb460dbb8d517d
|
11
|
+
notifications:
|
12
|
+
email: false
|
13
|
+
addons:
|
14
|
+
code_climate:
|
15
|
+
repo_token: 5cd40e471a2be2282170f06be821052b9c9f6a44961176068feb460dbb8d517d
|
data/Gemfile
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
source "https://rubygems.org"
|
2
|
+
|
3
|
+
gem "bundler", "~> 1.6.1"
|
4
|
+
gem "rake", "~> 10.3.1"
|
5
|
+
gem "rspec", "~> 2.14.1"
|
6
|
+
gem "guard-rspec", "~> 4.2.9"
|
7
|
+
gem "simplecov", "~> 0.8.2"
|
8
|
+
gem "coveralls", "~> 0.7.0"
|
9
|
+
gem "codeclimate-test-reporter", "~> 0.3.0"
|
10
|
+
gem "pry", "~> 0.9.12.6"
|
11
|
+
|
12
|
+
gem "sqlite3", "~> 1.3.9"
|
13
|
+
gem "activerecord", ">= 4.0.4"
|
14
|
+
gem "mongoid", ">= 4.0.0.beta1"
|
15
|
+
gem "kaminari", ">= 0.15.1"
|
16
|
+
gem "railties", ">= 4.0.4"
|
17
|
+
|
18
|
+
# Specify your gem's dependencies in draper-extensions.gemspec
|
19
|
+
gemspec
|
data/Guardfile
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# A sample Guardfile
|
2
|
+
# More info at https://github.com/guard/guard#readme
|
3
|
+
|
4
|
+
guard :rspec do
|
5
|
+
watch(%r{^spec/.+_spec\.rb$})
|
6
|
+
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
|
7
|
+
watch('spec/spec_helper.rb') { "spec" }
|
8
|
+
|
9
|
+
# Rails example
|
10
|
+
watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
|
11
|
+
watch(%r{^app/(.*)(\.erb|\.haml|\.slim)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
|
12
|
+
watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
|
13
|
+
watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
|
14
|
+
watch('config/routes.rb') { "spec/routing" }
|
15
|
+
watch('app/controllers/application_controller.rb') { "spec/controllers" }
|
16
|
+
|
17
|
+
# Capybara features specs
|
18
|
+
watch(%r{^app/views/(.+)/.*\.(erb|haml|slim)$}) { |m| "spec/features/#{m[1]}_spec.rb" }
|
19
|
+
|
20
|
+
# Turnip features and steps
|
21
|
+
watch(%r{^spec/acceptance/(.+)\.feature$})
|
22
|
+
watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance' }
|
23
|
+
end
|
24
|
+
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Chamnap Chhorn
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,106 @@
|
|
1
|
+
# Draper::Extensions [](https://travis-ci.org/chamnap/draper-extensions) [](https://codeclimate.com/github/chamnap/draper-extensions) [](https://coveralls.io/r/chamnap/draper-extensions?branch=master) [](https://gemnasium.com/chamnap/draper-extensions)
|
2
|
+
|
3
|
+
Extends Draper by adding pagination and scoping methods
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'draper-extensions'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install draper-extensions
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
This extension extends these things on the `draper` gem:
|
22
|
+
|
23
|
+
+ Add `#decorate` to `ActiveRecord::Relation`.
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
> listing = Listing.first
|
27
|
+
> listing.events.decorate
|
28
|
+
=> #<Draper::CollectionDecorator:0x000001059500f0
|
29
|
+
@context={},
|
30
|
+
@decorator_class=EventDecorator,
|
31
|
+
@object=
|
32
|
+
[#<Event id: 1, name: "BugSmash", ar_listing_id: 1, created_at: "2014-05-10 12:43:16", updated_at: "2014-05-10 12:43:16">]>
|
33
|
+
```
|
34
|
+
|
35
|
+
+ Add `#decorate` to `Kaminari::PaginatableArray`.
|
36
|
+
|
37
|
+
```ruby
|
38
|
+
class Listing
|
39
|
+
include Mongoid::Document
|
40
|
+
|
41
|
+
embeds_many :product_categories
|
42
|
+
|
43
|
+
def products
|
44
|
+
@products ||= Kaminari.paginate_array(product_categories.map(&:products))
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
> listing = Listing.first
|
49
|
+
> listing.products.page(1).decorate
|
50
|
+
=> #<Draper::CollectionDecorator:0x000001059500f0
|
51
|
+
@context={},
|
52
|
+
@decorator_class=ProductDecorator,
|
53
|
+
@object=
|
54
|
+
[#<Product id: 1, name: "Laptop", created_at: "2014-05-10 12:43:16", updated_at: "2014-05-10 12:43:16">]>
|
55
|
+
```
|
56
|
+
|
57
|
+
+ Add `#decorates_scope` to `Draper::CollectionDecorator`.
|
58
|
+
|
59
|
+
```ruby
|
60
|
+
# app/models/listing.rb
|
61
|
+
class Listing
|
62
|
+
include Mongoid::Document
|
63
|
+
|
64
|
+
field :name, type: String
|
65
|
+
|
66
|
+
embeds_many :events
|
67
|
+
end
|
68
|
+
|
69
|
+
# app/models/event.rb
|
70
|
+
class Event
|
71
|
+
include Mongoid::Document
|
72
|
+
|
73
|
+
field :name, type: String
|
74
|
+
field :starts_at, type: Time
|
75
|
+
|
76
|
+
scope :upcomings, -> { where(:starts_at.gt => Time.now) }
|
77
|
+
|
78
|
+
embedded_in :listing
|
79
|
+
end
|
80
|
+
|
81
|
+
# app/decorators/listing_decorator.rb
|
82
|
+
class ListingDecorator < Draper::Decorator
|
83
|
+
decorates_association :events, with: EventsDecorator
|
84
|
+
end
|
85
|
+
|
86
|
+
# app/decorators/events_decorator.rb
|
87
|
+
class EventsDecorator < Draper::CollectionDecorator
|
88
|
+
decorates_scope :upcomings
|
89
|
+
end
|
90
|
+
|
91
|
+
> listing = Listing.first
|
92
|
+
> listing.decorate.events.upcomings
|
93
|
+
=> #<EventsDecorator:0x000001016e1ed0
|
94
|
+
@context={},
|
95
|
+
@decorator_class=EventDecorator,
|
96
|
+
@object=
|
97
|
+
#<Mongoid::Criteria
|
98
|
+
selector: {"starts_at"=>{"$gt"=>2014-05-10 13:03:29 UTC}}
|
99
|
+
options: {}
|
100
|
+
class: Event
|
101
|
+
embedded: true>
|
102
|
+
>
|
103
|
+
```
|
104
|
+
## Authors
|
105
|
+
|
106
|
+
* [Chamnap Chhorn](https://github.com/chamnap)
|
data/Rakefile
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'draper/extensions/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "draper-extensions"
|
8
|
+
spec.version = Draper::Extensions::VERSION
|
9
|
+
spec.authors = ["Chamnap Chhorn"]
|
10
|
+
spec.email = ["chamnapchhorn@gmail.com"]
|
11
|
+
spec.summary = %q{Extends Draper by adding pagination and scoping methods}
|
12
|
+
spec.description = %q{Extends Draper by adding pagination and scoping methods}
|
13
|
+
spec.homepage = "https://github.com/chamnap/draper-extensions"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency "draper", "~> 1.3.0"
|
22
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require "draper/extensions"
|
@@ -0,0 +1,15 @@
|
|
1
|
+
## This extension allow us to invoke `#decorate` on active_relation objects
|
2
|
+
##
|
3
|
+
## @products = listing.products.page(1).decorate
|
4
|
+
## @products => Draper::CollectionDecorator
|
5
|
+
|
6
|
+
if defined?(ActiveRecord) &&
|
7
|
+
ActiveRecord::VERSION::STRING.start_with?("4.") ||
|
8
|
+
ActiveRecord::VERSION::STRING.start_with?("3.2")
|
9
|
+
|
10
|
+
class ActiveRecord::Relation
|
11
|
+
def decorate
|
12
|
+
klass.decorator_class.decorate_collection(self)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
## This extension allow us to invoke `pagination methods`
|
2
|
+
## on collection decorator
|
3
|
+
##
|
4
|
+
## @products = ProductDecorator.decorate_collection(mongo_listing.products.page(1))
|
5
|
+
## @products.current_page => 1
|
6
|
+
## @products.per_page => 20
|
7
|
+
|
8
|
+
class Draper::CollectionDecorator
|
9
|
+
|
10
|
+
if defined?(Kaminari)
|
11
|
+
delegate :current_page, :total_pages, :limit_value,
|
12
|
+
:next_page, :prev_page, :total_count,
|
13
|
+
to: :object
|
14
|
+
|
15
|
+
def per_page
|
16
|
+
object.limit_value
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
## Allow your collection_decorator to invoke `scope` methods
|
21
|
+
##
|
22
|
+
## > listing_decorator.product_categories.with_products
|
23
|
+
# => #<ProductCategoriesDecorator:0x0000010a4125c0
|
24
|
+
# @context={},
|
25
|
+
# @decorator_class=ProductCategoryDecorator,
|
26
|
+
# @object=
|
27
|
+
# #<Mongoid::Criteria
|
28
|
+
# selector: {"products"=>{"$exists"=>true}}
|
29
|
+
# options: {}
|
30
|
+
# class: ProductCategory
|
31
|
+
# embedded: true>
|
32
|
+
# >
|
33
|
+
def self.decorates_scope(name)
|
34
|
+
define_method(name) do
|
35
|
+
raise ArgumentError, "#{object.klass.name} doesn't define scope: #{name}" unless object.respond_to?(name)
|
36
|
+
|
37
|
+
object.klass.decorator_class.decorate_collection(object.send(name))
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
## This extension allow us to invoke `pagination methods`
|
2
|
+
## on kaminari/paginatable_array
|
3
|
+
|
4
|
+
if defined?(Kaminari)
|
5
|
+
|
6
|
+
require "kaminari/models/array_extension"
|
7
|
+
|
8
|
+
class Kaminari::PaginatableArray
|
9
|
+
def decorate
|
10
|
+
Draper::CollectionDecorator.new(self)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require "active_record"
|
2
|
+
|
3
|
+
ActiveRecord::Base.establish_connection(adapter: "sqlite3", database: "spec/test.sqlite3")
|
4
|
+
ActiveRecord::Migration.verbose = false
|
5
|
+
|
6
|
+
ActiveRecord::Schema.define do
|
7
|
+
self.verbose = false
|
8
|
+
|
9
|
+
create_table :ar_listings, :force => true do |t|
|
10
|
+
t.string :name
|
11
|
+
t.timestamps
|
12
|
+
end
|
13
|
+
|
14
|
+
create_table :ar_events, :force => true do |t|
|
15
|
+
t.string :name
|
16
|
+
t.references :ar_listing
|
17
|
+
t.timestamps
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe "#decorate on active_relation" do
|
4
|
+
let(:listing) { ArListing.create!(name: "Listing 1") }
|
5
|
+
let!(:event) { listing.events.create!(name: "BugSmash") }
|
6
|
+
subject { listing.events.decorate }
|
7
|
+
|
8
|
+
it "returns Draper::CollectionDecorator" do
|
9
|
+
expect(subject).to be_kind_of(Draper::CollectionDecorator)
|
10
|
+
expect(subject.decorator_class).to be(ArEventDecorator)
|
11
|
+
end
|
12
|
+
|
13
|
+
it "#decorated_collection" do
|
14
|
+
expect(subject.decorated_collection.count).to eq(1)
|
15
|
+
expect(subject.decorated_collection[0]).to be_instance_of(ArEventDecorator)
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Draper::CollectionDecorator, "pagination" do
|
4
|
+
let(:listing) { ArListing.create!(name: "Listing 1") }
|
5
|
+
let!(:events) { listing.events.create!([{name: "BugSmash"}, {name: "KataCamp"}]) }
|
6
|
+
|
7
|
+
subject { listing.events.page(1).decorate }
|
8
|
+
|
9
|
+
it "#current_page" do
|
10
|
+
expect(subject.current_page).to eq(subject.send(:object).current_page)
|
11
|
+
end
|
12
|
+
|
13
|
+
it "#total_pages" do
|
14
|
+
expect(subject.total_pages).to eq(subject.send(:object).total_pages)
|
15
|
+
end
|
16
|
+
|
17
|
+
it "#per_page" do
|
18
|
+
expect(subject.per_page).to eq(subject.send(:object).limit_value)
|
19
|
+
end
|
20
|
+
|
21
|
+
it "#limit_value" do
|
22
|
+
expect(subject.limit_value).to eq(subject.send(:object).limit_value)
|
23
|
+
end
|
24
|
+
|
25
|
+
it "#next_page" do
|
26
|
+
expect(subject.next_page).to eq(subject.send(:object).next_page)
|
27
|
+
end
|
28
|
+
|
29
|
+
it "#prev_page" do
|
30
|
+
expect(subject.prev_page).to eq(subject.send(:object).prev_page)
|
31
|
+
end
|
32
|
+
|
33
|
+
it "#total_count" do
|
34
|
+
expect(subject.total_count).to eq(subject.send(:object).total_count)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
describe Draper::CollectionDecorator, "#decorates_scope" do
|
39
|
+
let(:listing) { MongoListing.create!(name: "Listing 1") }
|
40
|
+
let!(:events) { listing.events.create!([{name: "BugSmash"}, {name: "KataCamp"}]) }
|
41
|
+
|
42
|
+
it "invokes on valid scope :upcomings" do
|
43
|
+
decorates = listing.decorate.events.upcomings
|
44
|
+
|
45
|
+
expect(decorates).to be_instance_of(MongoEventsDecorator)
|
46
|
+
expect(decorates.send(:object).selector).not_to be_blank
|
47
|
+
end
|
48
|
+
|
49
|
+
it "invokes on invalid scope :invalids" do
|
50
|
+
expect {
|
51
|
+
listing.decorate.events.invalids
|
52
|
+
}.to raise_error(ArgumentError, "MongoEvent doesn't define scope: invalids")
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Kaminari::PaginatableArray do
|
4
|
+
let(:listing1) { ArListing.create!(name: "listing1") }
|
5
|
+
let(:listing2) { ArListing.create!(name: "listing2") }
|
6
|
+
|
7
|
+
it "#decorate on non-empty array" do
|
8
|
+
expect(Kaminari::PaginatableArray.new([listing1, listing2]).decorate).to be_instance_of(Draper::CollectionDecorator)
|
9
|
+
end
|
10
|
+
|
11
|
+
it "#decorate on non-empty array" do
|
12
|
+
expect(Kaminari::PaginatableArray.new.decorate).to be_instance_of(Draper::CollectionDecorator)
|
13
|
+
end
|
14
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
require "simplecov"
|
2
|
+
require "coveralls"
|
3
|
+
require "codeclimate-test-reporter"
|
4
|
+
|
5
|
+
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
|
6
|
+
Coveralls::SimpleCov::Formatter,
|
7
|
+
SimpleCov::Formatter::HTMLFormatter,
|
8
|
+
CodeClimate::TestReporter::Formatter
|
9
|
+
]
|
10
|
+
|
11
|
+
SimpleCov.start do
|
12
|
+
add_filter "/spec/"
|
13
|
+
end
|
14
|
+
|
15
|
+
require "pry"
|
16
|
+
require "active_record"
|
17
|
+
require "mongoid"
|
18
|
+
require "kaminari"
|
19
|
+
require "draper-extensions"
|
20
|
+
|
21
|
+
[:active_record, :mongoid].each do |orm|
|
22
|
+
ActiveSupport.on_load orm do
|
23
|
+
Draper.setup_orm self
|
24
|
+
end
|
25
|
+
end
|
26
|
+
Kaminari::Hooks.init
|
27
|
+
|
28
|
+
# active_record
|
29
|
+
if Gem.loaded_specs["activerecord"]
|
30
|
+
load File.dirname(__FILE__) + "/config/active_record/connection.rb"
|
31
|
+
end
|
32
|
+
|
33
|
+
# mongoid
|
34
|
+
if Gem.loaded_specs["mongoid"]
|
35
|
+
load File.dirname(__FILE__) + "/config/mongoid/connection.rb"
|
36
|
+
end
|
37
|
+
|
38
|
+
MODELS = File.join(File.dirname(__FILE__), "app/models")
|
39
|
+
$LOAD_PATH.unshift(MODELS)
|
40
|
+
|
41
|
+
# Autoload every model for the test suite that sits in spec/app/models.
|
42
|
+
Dir[ File.join(MODELS, "*.rb") ].sort.each do |file|
|
43
|
+
name = File.basename(file, ".rb")
|
44
|
+
autoload name.camelize.to_sym, name
|
45
|
+
end
|
46
|
+
|
47
|
+
DECORATORS = File.join(File.dirname(__FILE__), "app/decorators")
|
48
|
+
$LOAD_PATH.unshift(DECORATORS)
|
49
|
+
|
50
|
+
# Autoload every decorator for the test suite that sits in spec/app/decorators.
|
51
|
+
Dir[ File.join(DECORATORS, "*.rb") ].sort.each do |file|
|
52
|
+
name = File.basename(file, ".rb")
|
53
|
+
autoload name.camelize.to_sym, name
|
54
|
+
end
|
55
|
+
|
56
|
+
RSpec.configure do |config|
|
57
|
+
config.filter_run focus: true
|
58
|
+
config.run_all_when_everything_filtered = true
|
59
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
60
|
+
|
61
|
+
config.before(:each) do
|
62
|
+
ActiveRecord::Base.descendants.each(&:delete_all)
|
63
|
+
Mongoid.purge!
|
64
|
+
end
|
65
|
+
end
|
metadata
ADDED
@@ -0,0 +1,108 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: draper-extensions
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Chamnap Chhorn
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-05-12 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: draper
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.3.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 1.3.0
|
27
|
+
description: Extends Draper by adding pagination and scoping methods
|
28
|
+
email:
|
29
|
+
- chamnapchhorn@gmail.com
|
30
|
+
executables: []
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- ".coveralls.yml"
|
35
|
+
- ".gitignore"
|
36
|
+
- ".rspec"
|
37
|
+
- ".ruby-gemset"
|
38
|
+
- ".ruby-version"
|
39
|
+
- ".travis.yml"
|
40
|
+
- Gemfile
|
41
|
+
- Guardfile
|
42
|
+
- LICENSE.txt
|
43
|
+
- README.md
|
44
|
+
- Rakefile
|
45
|
+
- draper-extensions.gemspec
|
46
|
+
- lib/draper-extensions.rb
|
47
|
+
- lib/draper/extensions.rb
|
48
|
+
- lib/draper/extensions/active_relation.rb
|
49
|
+
- lib/draper/extensions/collection_decorator.rb
|
50
|
+
- lib/draper/extensions/paginatable_array.rb
|
51
|
+
- lib/draper/extensions/version.rb
|
52
|
+
- spec/app/decorators/ar_event_decorator.rb
|
53
|
+
- spec/app/decorators/ar_listing_decorator.rb
|
54
|
+
- spec/app/decorators/mongo_event_decorator.rb
|
55
|
+
- spec/app/decorators/mongo_events_decorator.rb
|
56
|
+
- spec/app/decorators/mongo_listing_decorator.rb
|
57
|
+
- spec/app/models/ar_event.rb
|
58
|
+
- spec/app/models/ar_listing.rb
|
59
|
+
- spec/app/models/mongo_event.rb
|
60
|
+
- spec/app/models/mongo_listing.rb
|
61
|
+
- spec/config/active_record/connection.rb
|
62
|
+
- spec/config/mongoid/connection.rb
|
63
|
+
- spec/config/mongoid/mongoid.yml
|
64
|
+
- spec/lib/draper/extensions/active_relation_spec.rb
|
65
|
+
- spec/lib/draper/extensions/collection_decorator_spec.rb
|
66
|
+
- spec/lib/draper/extensions/paginatable_array_spec.rb
|
67
|
+
- spec/spec_helper.rb
|
68
|
+
homepage: https://github.com/chamnap/draper-extensions
|
69
|
+
licenses:
|
70
|
+
- MIT
|
71
|
+
metadata: {}
|
72
|
+
post_install_message:
|
73
|
+
rdoc_options: []
|
74
|
+
require_paths:
|
75
|
+
- lib
|
76
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
77
|
+
requirements:
|
78
|
+
- - ">="
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: '0'
|
81
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
82
|
+
requirements:
|
83
|
+
- - ">="
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
requirements: []
|
87
|
+
rubyforge_project:
|
88
|
+
rubygems_version: 2.2.2
|
89
|
+
signing_key:
|
90
|
+
specification_version: 4
|
91
|
+
summary: Extends Draper by adding pagination and scoping methods
|
92
|
+
test_files:
|
93
|
+
- spec/app/decorators/ar_event_decorator.rb
|
94
|
+
- spec/app/decorators/ar_listing_decorator.rb
|
95
|
+
- spec/app/decorators/mongo_event_decorator.rb
|
96
|
+
- spec/app/decorators/mongo_events_decorator.rb
|
97
|
+
- spec/app/decorators/mongo_listing_decorator.rb
|
98
|
+
- spec/app/models/ar_event.rb
|
99
|
+
- spec/app/models/ar_listing.rb
|
100
|
+
- spec/app/models/mongo_event.rb
|
101
|
+
- spec/app/models/mongo_listing.rb
|
102
|
+
- spec/config/active_record/connection.rb
|
103
|
+
- spec/config/mongoid/connection.rb
|
104
|
+
- spec/config/mongoid/mongoid.yml
|
105
|
+
- spec/lib/draper/extensions/active_relation_spec.rb
|
106
|
+
- spec/lib/draper/extensions/collection_decorator_spec.rb
|
107
|
+
- spec/lib/draper/extensions/paginatable_array_spec.rb
|
108
|
+
- spec/spec_helper.rb
|