@@ -256,6 +256,64 @@ class Extension < Spree::Base
256256 end
257257 end
258258
259+ describe "#tax_category" do
260+ context "when the product has a tax category" do
261+ let ( :tax_category ) { create ( :tax_category ) }
262+ let ( :product ) { create ( :product , tax_category :) }
263+
264+ it "returns the product's tax category" do
265+ expect ( product . tax_category ) . to eq ( tax_category )
266+ end
267+ end
268+
269+ context "when the product has no tax category" do
270+ let ( :product ) { create ( :product , tax_category : nil ) }
271+
272+ context "and a default tax category exists" do
273+ let! ( :default_tax_category ) { create ( :tax_category , is_default : true ) }
274+
275+ it "returns the default tax category" do
276+ expect ( product . tax_category ) . to eq ( default_tax_category )
277+ end
278+ end
279+
280+ context "and no default tax category exists" do
281+ it "returns nil" do
282+ expect ( product . tax_category ) . to be_nil
283+ end
284+ end
285+ end
286+ end
287+
288+ describe "#tax_category_id" do
289+ context "when the product has a tax category" do
290+ let ( :tax_category ) { create ( :tax_category ) }
291+ let ( :product ) { create ( :product , tax_category :) }
292+
293+ it "returns the product's tax category id" do
294+ expect ( product . tax_category_id ) . to eq ( tax_category . id )
295+ end
296+ end
297+
298+ context "when the product has no tax category" do
299+ let ( :product ) { create ( :product , tax_category : nil ) }
300+
301+ context "and a default tax category exists" do
302+ let! ( :default_tax_category ) { create ( :tax_category , is_default : true ) }
303+
304+ it "returns the default tax category's id" do
305+ expect ( product . tax_category_id ) . to eq ( default_tax_category . id )
306+ end
307+ end
308+
309+ context "and no default tax category exists" do
310+ it "returns nil" do
311+ expect ( product . tax_category_id ) . to be_nil
312+ end
313+ end
314+ end
315+ end
316+
259317 context "variants_and_option_values_for" do
260318 let! ( :high ) { create ( :variant , product :) }
261319 let! ( :low ) { create ( :variant , product :) }
0 commit comments