Index variants by id

This commit is contained in:
Rohan Mitchell
2015-06-04 12:09:34 +10:00
parent cf0031d9a5
commit 27bc28ffa4
2 changed files with 18 additions and 0 deletions

View File

@@ -46,6 +46,13 @@ Spree::Variant.class_eval do
}
def self.indexed
Hash[
scoped.map { |v| [v.id, v] }
]
end
def price_with_fees(distributor, order_cycle)
price + fees_for(distributor, order_cycle)
end

View File

@@ -104,6 +104,17 @@ module Spree
end
end
describe "indexing variants by id" do
let!(:v1) { create(:variant) }
let!(:v2) { create(:variant) }
let!(:v3) { create(:variant) }
it "indexes variants by id" do
Variant.where(id: [v1, v2, v3]).indexed.should ==
{v1.id => v1, v2.id => v2, v3.id => v3}
end
end
describe "generating the full name" do
let(:v) { Variant.new }