mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-26 20:56:48 +00:00
Index variants by id
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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 }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user