mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Find variant overrides for some hubs
This commit is contained in:
@@ -2,6 +2,10 @@ class VariantOverride < ActiveRecord::Base
|
||||
belongs_to :variant, class_name: 'Spree::Variant'
|
||||
belongs_to :hub, class_name: 'Enterprise'
|
||||
|
||||
scope :for_hubs, lambda { |hubs|
|
||||
where(hub_id: hubs)
|
||||
}
|
||||
|
||||
def self.price_for(variant, hub)
|
||||
VariantOverride.where(variant_id: variant, hub_id: hub).first.andand.price
|
||||
end
|
||||
|
||||
@@ -1,6 +1,18 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe VariantOverride do
|
||||
describe "scopes" do
|
||||
let(:hub1) { create(:distributor_enterprise) }
|
||||
let(:hub2) { create(:distributor_enterprise) }
|
||||
let(:v) { create(:variant) }
|
||||
let!(:vo1) { create(:variant_override, hub: hub1, variant: v) }
|
||||
let!(:vo2) { create(:variant_override, hub: hub2, variant: v) }
|
||||
|
||||
it "finds variant overrides for a set of hubs" do
|
||||
VariantOverride.for_hubs([hub1, hub2]).sort.should == [vo1, vo2].sort
|
||||
end
|
||||
end
|
||||
|
||||
describe "looking up prices" do
|
||||
let(:variant) { create(:variant) }
|
||||
let(:hub) { create(:distributor_enterprise) }
|
||||
|
||||
Reference in New Issue
Block a user