lib/helpers/spree_helper.rb in datashift_spree-0.2.1 vs lib/helpers/spree_helper.rb in datashift_spree-0.3.0
- old
+ new
@@ -13,11 +13,11 @@
# The Spree version you want to test should be picked up from spec/Gemfile
#
# Since datashift gem is not a Rails app or a Spree App, provides utilities to internally
# create a Spree Database, and to load Spree components, enabling standalone testing.
#
-# => Has been tested with 0.11.2, 0.7, 1.0.0
+# => Has been tested with 0.11.2, 0.7, 1.0.0, 1.1.2, 1.1.3
#
# => TODO - See if we can improve DB creation/migration ....
# N.B Some or all of Spree Tests may fail very first time run,
# as the database is auto generated
# =>
@@ -48,11 +48,29 @@
else
Object.const_get('Product')
end
end
- def self.get_image_owner(product)
- (SpreeHelper::version.to_f > 1) ? product.master : product
+ # Return the right CLASS to attach Product images to
+ # for the callers version of Spree
+
+ def self.product_attachment_klazz
+ @product_attachment_klazz ||= if(DataShift::SpreeHelper::version.to_f > 1.0 )
+ DataShift::SpreeHelper::get_spree_class('Variant' )
+ else
+ DataShift::SpreeHelper::get_spree_class('Product' )
+ end
+ end
+
+ # Return the right OBJECT to attach Product images to
+ # for the callers version of Spree
+
+ def self.get_image_owner(record)
+ if(SpreeHelper::version.to_f > 1)
+ record.is_a?(get_product_class) ? record.master : record # owner is VARIANT
+ else
+ record.is_a?(get_product_class) ? record : record.product # owner is PRODUCT
+ end
end
def self.version
Gem.loaded_specs['spree'] ? Gem.loaded_specs['spree'].version.version : "0.0.0"
end
\ No newline at end of file