Last active
August 29, 2015 13:58
-
-
Save kyanny/10103515 to your computer and use it in GitHub Desktop.
Inconsistent results of Draper::Decorator#decorate_collection and Draper:: Decoratable#decorate
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rails' | |
require 'mongo_mapper' | |
require 'draper' | |
require 'rspec' | |
MongoMapper.database = 'testing' | |
MongoMapper::Document.send(:include, Draper::Decoratable) | |
class Bookmark | |
include MongoMapper::Document | |
key :url, String | |
key :public, Boolean, default: true | |
scope :valid, where(url: { :$ne => nil }) | |
scope :private, where(public: false) | |
end | |
class BookmarkDecorator < Draper::Decorator | |
delegate_all | |
end | |
Bookmark.destroy_all | |
describe "draper & mongo_mapper & decorate collection" do | |
before do | |
Bookmark.destroy_all | |
Bookmark.create url: "http://google.com/" | |
Bookmark.create url: "http://apple.com/" | |
Bookmark.create url: "http://amazon.com", public: false | |
Bookmark.create url: nil | |
end | |
context "no decorate" do | |
it { expect(Bookmark.valid.count).to eq 3 } | |
it { expect(Bookmark.valid.private.count).to eq 1 } | |
end | |
context "call #decorate method for MongoMapper::Plugins::Querying::DecoratedPluckyQuery object" do | |
it { expect(Bookmark.valid.decorate.count).to eq 3 } | |
it { expect(Bookmark.valid.private.decorate.count).to eq 1 } | |
end | |
context "decorate by decorate_collection method" do | |
it { expect(BookmarkDecorator.decorate_collection(Bookmark.valid).count).to eq 3 } | |
it { expect(BookmarkDecorator.decorate_collection(Bookmark.valid.private).count).to eq 1 } | |
end | |
after do | |
Bookmark.destroy_all | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
draper & mongo_mapper & decorate collection | |
no decorate | |
should eq 3 | |
should eq 1 | |
call #decorate method for MongoMapper::Plugins::Querying::DecoratedPluckyQuery object | |
should eq 3 (FAILED - 1) | |
should eq 1 (FAILED - 2) | |
decorate by decorate_collection method | |
should eq 3 | |
should eq 1 | |
Failures: | |
1) draper & mongo_mapper & decorate collection call #decorate method for MongoMapper::Plugins::Querying::DecoratedPluckyQuery object should eq 3 | |
Failure/Error: it { expect(Bookmark.valid.decorate.count).to eq 3 } | |
expected: 3 | |
got: 4 | |
(compared using ==) | |
# ./test.rb:40:in `block (3 levels) in <top (required)>' | |
2) draper & mongo_mapper & decorate collection call #decorate method for MongoMapper::Plugins::Querying::DecoratedPluckyQuery object should eq 1 | |
Failure/Error: it { expect(Bookmark.valid.private.decorate.count).to eq 1 } | |
expected: 1 | |
got: 4 | |
(compared using ==) | |
# ./test.rb:41:in `block (3 levels) in <top (required)>' | |
Finished in 0.03968 seconds | |
6 examples, 2 failures | |
Failed examples: | |
rspec ./test.rb:40 # draper & mongo_mapper & decorate collection call #decorate method for MongoMapper::Plugins::Querying::DecoratedPluckyQuery object should eq 3 | |
rspec ./test.rb:41 # draper & mongo_mapper & decorate collection call #decorate method for MongoMapper::Plugins::Querying::DecoratedPluckyQuery object should eq 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment