Find variant overrides for some hubs

This commit is contained in:
Rohan Mitchell
2014-11-26 13:07:18 +11:00
parent 91b386003a
commit ff28da345d
2 changed files with 16 additions and 0 deletions

View File

@@ -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

View File

@@ -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) }