From 7dc1091bc2aa6f72d0fd64bed639dbe6bb453c8f Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Mon, 22 May 2023 11:39:38 +0100 Subject: [PATCH] Migrate product image from master variant to product --- .../admin/spree/images/index.js.coffee | 15 --------------- .../javascripts/admin/spree/images/new.js.coffee | 7 ------- .../darkswarm/services/products.js.coffee | 4 ++-- app/components/product_component.rb | 4 ++-- app/components/products_table_component.rb | 2 +- app/controllers/admin/enterprises_controller.rb | 2 +- .../api/v0/product_images_controller.rb | 6 +++--- app/controllers/api/v0/products_controller.rb | 2 +- app/controllers/spree/admin/images_controller.rb | 15 ++++++++++++++- .../spree/admin/products_controller.rb | 4 ++-- app/models/spree/product.rb | 12 ++++++------ .../supplied_product_serializer.rb | 2 +- app/serializers/api/admin/product_serializer.rb | 4 ++-- app/serializers/api/admin/variant_serializer.rb | 2 +- app/serializers/api/product_serializer.rb | 2 +- app/serializers/api/variant_serializer.rb | 2 +- app/services/exchange_products_renderer.rb | 2 +- app/services/image_importer.rb | 4 ++-- app/services/permitted_attributes/product.rb | 2 +- app/views/spree/admin/images/_form.html.haml | 6 ++---- app/views/spree/admin/images/index.html.haml | 4 ++-- app/views/spree/admin/images/new.html.haml | 2 -- app/views/spree/admin/products/new.html.haml | 2 +- .../spree/shared/_variant_thumbnail.html.haml | 2 +- lib/spree/core/product_duplicator.rb | 1 + lib/tasks/import_product_images.rake | 2 +- .../api/v0/product_images_controller_spec.rb | 6 +++--- .../api/v0/products_controller_spec.rb | 2 +- .../spree/admin/products_controller_spec.rb | 4 ++-- spec/factories/product_factory.rb | 4 ++-- .../darkswarm/services/products_spec.js.coffee | 4 ++-- spec/models/spree/product_spec.rb | 10 +++++----- spec/serializers/api/product_serializer_spec.rb | 2 +- spec/services/image_importer_spec.rb | 4 ++-- spec/system/admin/products_spec.rb | 8 ++------ spec/system/admin/reports_spec.rb | 2 +- spec/views/spree/orders/show.html.haml_spec.rb | 4 ++-- 37 files changed, 73 insertions(+), 89 deletions(-) delete mode 100644 app/assets/javascripts/admin/spree/images/index.js.coffee delete mode 100644 app/assets/javascripts/admin/spree/images/new.js.coffee diff --git a/app/assets/javascripts/admin/spree/images/index.js.coffee b/app/assets/javascripts/admin/spree/images/index.js.coffee deleted file mode 100644 index a7fab5d735..0000000000 --- a/app/assets/javascripts/admin/spree/images/index.js.coffee +++ /dev/null @@ -1,15 +0,0 @@ -$ -> - ($ '#new_image_link').click (event) -> - event.preventDefault() - - ($ '.no-objects-found').hide() - - ($ this).hide() - $.ajax - type: 'GET' - url: @href - data: ( - authenticity_token: AUTH_TOKEN - ) - success: (r) -> - ($ '#images').html r diff --git a/app/assets/javascripts/admin/spree/images/new.js.coffee b/app/assets/javascripts/admin/spree/images/new.js.coffee deleted file mode 100644 index 8df2f33d2e..0000000000 --- a/app/assets/javascripts/admin/spree/images/new.js.coffee +++ /dev/null @@ -1,7 +0,0 @@ -($ '#cancel_link').click (event) -> - event.preventDefault() - - ($ '.no-objects-found').show() - - ($ '#new_image_link').show() - ($ '#images').html('') diff --git a/app/assets/javascripts/darkswarm/services/products.js.coffee b/app/assets/javascripts/darkswarm/services/products.js.coffee index c791be2600..8482c34d57 100644 --- a/app/assets/javascripts/darkswarm/services/products.js.coffee +++ b/app/assets/javascripts/darkswarm/services/products.js.coffee @@ -33,9 +33,9 @@ angular.module('Darkswarm').factory 'Products', (OrderCycleResource, OrderCycle, prices = (v.price for v in product.variants) product.price = Math.min.apply(null, prices) product.hasVariants = product.variants?.length > 0 - product.primaryImage = product.images[0]?.small_url if product.images + product.primaryImage = product.image?.small_url if product.image product.primaryImageOrMissing = product.primaryImage || "/noimage/small.png" - product.largeImage = product.images[0]?.large_url if product.images + product.largeImage = product.image?.large_url if product.image dereference: -> for product in @fetched_products diff --git a/app/components/product_component.rb b/app/components/product_component.rb index 5d6ce0c9fc..e05bde0802 100644 --- a/app/components/product_component.rb +++ b/app/components/product_component.rb @@ -6,7 +6,7 @@ class ProductComponent < ViewComponentReflex::Component def initialize(product:, columns:) super @product = product - @image = @product.images[0] if product.images.any? + @image = @product.image if product.image.present? @columns = columns.map do |c| { id: c[:value], @@ -28,7 +28,7 @@ class ProductComponent < ViewComponentReflex::Component when 'price' @product.price when 'unit' - "#{@product.unit_value} #{@product.variant_unit}" + "#{@product.variants.first.unit_value} #{@product.variant_unit}" when 'producer' @product.supplier.name when 'category' diff --git a/app/components/products_table_component.rb b/app/components/products_table_component.rb index 1eba6f1391..7d37a0f480 100644 --- a/app/components/products_table_component.rb +++ b/app/components/products_table_component.rb @@ -168,7 +168,7 @@ class ProductsTableComponent < ViewComponentReflex::Component def product_query_includes [ - master: [:images], + :image, variants: [ :default_price, :stock_locations, diff --git a/app/controllers/admin/enterprises_controller.rb b/app/controllers/admin/enterprises_controller.rb index 93e95581cd..28d03a47ee 100644 --- a/app/controllers/admin/enterprises_controller.rb +++ b/app/controllers/admin/enterprises_controller.rb @@ -188,7 +188,7 @@ module Admin if enterprises.present? enterprises.includes( supplied_products: - [:supplier, :variants, { master: [:images] }] + [:supplier, :variants, :image] ) end when :index diff --git a/app/controllers/api/v0/product_images_controller.rb b/app/controllers/api/v0/product_images_controller.rb index 97e4b2d42c..f2263e6ba2 100644 --- a/app/controllers/api/v0/product_images_controller.rb +++ b/app/controllers/api/v0/product_images_controller.rb @@ -9,9 +9,9 @@ module Api product = Spree::Product.find(params[:product_id]) authorize! :update, product - image = product.images.first || Spree::Image.new( - viewable_id: product.master.id, - viewable_type: 'Spree::Variant' + image = product.image || Spree::Image.new( + viewable_id: product.id, + viewable_type: 'Spree::Product' ) success_status = image.persisted? ? :ok : :created diff --git a/app/controllers/api/v0/products_controller.rb b/app/controllers/api/v0/products_controller.rb index 0363c21e56..a6e989cc5d 100644 --- a/app/controllers/api/v0/products_controller.rb +++ b/app/controllers/api/v0/products_controller.rb @@ -116,7 +116,7 @@ module Api def product_query_includes [ - master: { images: { attachment_attachment: :blob } }, + image: { attachment_attachment: :blob }, variants: [:default_price, :stock_locations, :stock_items, :variant_overrides] ] end diff --git a/app/controllers/spree/admin/images_controller.rb b/app/controllers/spree/admin/images_controller.rb index b258ef8e2c..65f278e5bd 100644 --- a/app/controllers/spree/admin/images_controller.rb +++ b/app/controllers/spree/admin/images_controller.rb @@ -25,6 +25,7 @@ module Spree set_viewable @object.attributes = permitted_resource_params + if @object.save flash[:success] = flash_message_for(@object, :successfully_created) redirect_to spree.admin_product_images_url(params[:product_id], @url_filters) @@ -62,6 +63,18 @@ module Spree private + def collection + parent.image + end + + def find_resource + parent.image + end + + def build_resource + Spree::Image.new(viewable: parent) + end + def location_after_save spree.admin_product_images_url(@product) end @@ -75,7 +88,7 @@ module Spree end def set_viewable - @image.viewable_type = 'Spree::Variant' + @image.viewable_type = 'Spree::Product' @image.viewable_id = params[:image][:viewable_id] end diff --git a/app/controllers/spree/admin/products_controller.rb b/app/controllers/spree/admin/products_controller.rb index a92b04bac3..4719746a18 100644 --- a/app/controllers/spree/admin/products_controller.rb +++ b/app/controllers/spree/admin/products_controller.rb @@ -121,8 +121,8 @@ module Spree end def product_includes - [{ variants: [:images] }, - { master: [:images, :default_price] }] + [:image, { variants: [:images] }, + { master: [:default_price] }] end def collection_actions diff --git a/app/models/spree/product.rb b/app/models/spree/product.rb index 5ef8741cc3..1940c243a9 100755 --- a/app/models/spree/product.rb +++ b/app/models/spree/product.rb @@ -43,6 +43,8 @@ module Spree belongs_to :supplier, class_name: 'Enterprise', touch: true belongs_to :primary_taxon, class_name: 'Spree::Taxon', touch: true + has_one :image, class_name: "Spree::Image", as: :viewable, dependent: :destroy + has_one :master, -> { where is_master: true }, class_name: 'Spree::Variant', @@ -75,9 +77,6 @@ module Spree ) } - delegate_belongs_to :master, :images - delegate :images_attributes=, to: :master - # Transient attributes used temporarily when creating a new product, # these values are persisted on the product's variant attr_accessor :price, :display_as, :unit_value, :unit_description @@ -89,6 +88,7 @@ module Spree through: :variants_including_master accepts_nested_attributes_for :variants, allow_destroy: true + accepts_nested_attributes_for :image validates :name, presence: true validates :permalink, presence: true @@ -106,7 +106,7 @@ module Spree presence: { if: ->(p) { %w(weight volume).include? p.variant_unit } } validates :variant_unit_name, presence: { if: ->(p) { p.variant_unit == 'items' } } - validate :validate_image_for_master + validate :validate_image accepts_nested_attributes_for :product_properties, allow_destroy: true, @@ -410,8 +410,8 @@ module Spree self.permalink = create_unique_permalink(requested.parameterize) end - def validate_image_for_master - return if master.images.all?(&:valid?) + def validate_image + return if image.blank? || image.valid? errors.add(:base, I18n.t('spree.admin.products.image_not_processable')) end diff --git a/app/serializers/api/admin/for_order_cycle/supplied_product_serializer.rb b/app/serializers/api/admin/for_order_cycle/supplied_product_serializer.rb index fa0c9e7365..ff895d7003 100644 --- a/app/serializers/api/admin/for_order_cycle/supplied_product_serializer.rb +++ b/app/serializers/api/admin/for_order_cycle/supplied_product_serializer.rb @@ -11,7 +11,7 @@ module Api end def image_url - object.images.first&.url(:mini) + object.image&.url(:mini) end def master_id diff --git a/app/serializers/api/admin/product_serializer.rb b/app/serializers/api/admin/product_serializer.rb index 6dd930f7da..0fafedfa4d 100644 --- a/app/serializers/api/admin/product_serializer.rb +++ b/app/serializers/api/admin/product_serializer.rb @@ -27,11 +27,11 @@ module Api end def image_url - object.images.first&.url(:product) || Spree::Image.default_image_url(:product) + object.image&.url(:product) || Spree::Image.default_image_url(:product) end def thumb_url - object.images.first&.url(:mini) || Spree::Image.default_image_url(:mini) + object.image&.url(:mini) || Spree::Image.default_image_url(:mini) end def on_hand diff --git a/app/serializers/api/admin/variant_serializer.rb b/app/serializers/api/admin/variant_serializer.rb index e4ad155914..4db58190f2 100644 --- a/app/serializers/api/admin/variant_serializer.rb +++ b/app/serializers/api/admin/variant_serializer.rb @@ -33,7 +33,7 @@ module Api end def image - options[:image] || object.product.images.first&.url(:mini) + options[:image] || object.product.image&.url(:mini) end def in_stock diff --git a/app/serializers/api/product_serializer.rb b/app/serializers/api/product_serializer.rb index b37bc78366..ec2dfa4c6f 100644 --- a/app/serializers/api/product_serializer.rb +++ b/app/serializers/api/product_serializer.rb @@ -12,7 +12,7 @@ class Api::ProductSerializer < ActiveModel::Serializer has_one :primary_taxon, serializer: Api::TaxonSerializer has_many :taxons, serializer: Api::IdSerializer - has_many :images, serializer: Api::ImageSerializer + has_one :image, serializer: Api::ImageSerializer has_one :supplier, serializer: Api::IdSerializer # return an unformatted descripton diff --git a/app/serializers/api/variant_serializer.rb b/app/serializers/api/variant_serializer.rb index 79b492b528..b3a4cd9217 100644 --- a/app/serializers/api/variant_serializer.rb +++ b/app/serializers/api/variant_serializer.rb @@ -40,7 +40,7 @@ class Api::VariantSerializer < ActiveModel::Serializer end def thumb_url - object.product.images.first&.url(:mini) || Spree::Image.default_image_url(:mini) + object.product.image&.url(:mini) || Spree::Image.default_image_url(:mini) end def unit_price_price diff --git a/app/services/exchange_products_renderer.rb b/app/services/exchange_products_renderer.rb index a622ad94a1..8f762cda84 100644 --- a/app/services/exchange_products_renderer.rb +++ b/app/services/exchange_products_renderer.rb @@ -96,7 +96,7 @@ class ExchangeProductsRenderer return enterprises if enterprises.empty? enterprises.includes( - supplied_products: [:supplier, :variants, { master: [:images] }] + supplied_products: [:supplier, :variants, :image] ) end end diff --git a/app/services/image_importer.rb b/app/services/image_importer.rb index 706de935a0..bdf32fcf2a 100644 --- a/app/services/image_importer.rb +++ b/app/services/image_importer.rb @@ -8,8 +8,8 @@ class ImageImporter Spree::Image.create( attachment: { io: file, filename: filename }, - viewable_id: product.master.id, - viewable_type: Spree::Variant, + viewable_id: product.id, + viewable_type: Spree::Product, ) end end diff --git a/app/services/permitted_attributes/product.rb b/app/services/permitted_attributes/product.rb index 555a764a40..f50c8cf63a 100644 --- a/app/services/permitted_attributes/product.rb +++ b/app/services/permitted_attributes/product.rb @@ -11,7 +11,7 @@ module PermittedAttributes :meta_keywords, :notes, :inherits_properties, { product_properties_attributes: [:id, :property_name, :value], variants_attributes: [PermittedAttributes::Variant.attributes], - images_attributes: [:attachment] } + image_attributes: [:attachment] } ] end end diff --git a/app/views/spree/admin/images/_form.html.haml b/app/views/spree/admin/images/_form.html.haml index a316040c3c..86cd8b507d 100644 --- a/app/views/spree/admin/images/_form.html.haml +++ b/app/views/spree/admin/images/_form.html.haml @@ -1,13 +1,11 @@ %div + = f.hidden_field :viewable_id, value: @product.id + .four.columns.alpha .field = f.label t('spree.filename') %br/ = f.file_field :attachment - .field - = f.label Spree::Variant.model_name.human - %br/ - = f.select :viewable_id, @variants, {}, {class: 'select2 fullwidth'} .field.omega.five.columns = f.label t('spree.alt_text') %br/ diff --git a/app/views/spree/admin/images/index.html.haml b/app/views/spree/admin/images/index.html.haml index 4757f869de..5839dd10e1 100644 --- a/app/views/spree/admin/images/index.html.haml +++ b/app/views/spree/admin/images/index.html.haml @@ -6,7 +6,7 @@ #images -- unless @product.images.any? || @product.variant_images.any? +- unless @product.image.present? .no-objects-found = t('spree.no_images_found') \. @@ -25,7 +25,7 @@ %th= t('spree.alt_text') %th.actions %tbody - - (@product.variant_images).each do |image| + - ([@product.image]).each do |image| - tr_class = cycle('odd', 'even') - tr_id = spree_dom_id(image) %tr{class: tr_class, id: tr_id } diff --git a/app/views/spree/admin/images/new.html.haml b/app/views/spree/admin/images/new.html.haml index b2f2acf1d3..e579c511d5 100644 --- a/app/views/spree/admin/images/new.html.haml +++ b/app/views/spree/admin/images/new.html.haml @@ -7,5 +7,3 @@ .form-buttons.filter-actions.actions = button t('actions.create'), 'icon-ok' = link_to_with_icon 'icon-remove', t('spree.actions.cancel'), admin_product_images_url(@product, @url_filters), id: 'cancel_link', class: 'button' - -= javascript_include_tag 'admin/spree/images/new.js' diff --git a/app/views/spree/admin/products/new.html.haml b/app/views/spree/admin/products/new.html.haml index b167c07998..f514f33084 100644 --- a/app/views/spree/admin/products/new.html.haml +++ b/app/views/spree/admin/products/new.html.haml @@ -101,7 +101,7 @@ .row = image_tag Spree::Image.default_image_url(:product), class: "four columns alpha" .row - = f.fields_for 'images_attributes[]', f.object.images.build do |image_fields| + = f.fields_for 'image_attributes[]', f.object.build_image do |image_fields| = image_fields.file_field :attachment .sixteen.columns.alpha .form-buttons.filter-actions.actions diff --git a/app/views/spree/shared/_variant_thumbnail.html.haml b/app/views/spree/shared/_variant_thumbnail.html.haml index d97d6175ca..708418c31d 100644 --- a/app/views/spree/shared/_variant_thumbnail.html.haml +++ b/app/views/spree/shared/_variant_thumbnail.html.haml @@ -1 +1 @@ -= image_tag(variant.product.images.first&.url(:mini) || Spree::Image.default_image_url(:mini)) += image_tag(variant.product.image&.url(:mini) || Spree::Image.default_image_url(:mini)) diff --git a/lib/spree/core/product_duplicator.rb b/lib/spree/core/product_duplicator.rb index 83f80376ee..66e86c6b33 100644 --- a/lib/spree/core/product_duplicator.rb +++ b/lib/spree/core/product_duplicator.rb @@ -26,6 +26,7 @@ module Spree new_product.updated_at = nil new_product.product_properties = reset_properties new_product.master = duplicate_master + new_product.image = duplicate_image(product.image) if product.image&.attached? new_product.variants = duplicate_variants end end diff --git a/lib/tasks/import_product_images.rake b/lib/tasks/import_product_images.rake index 7ebfc62c8f..260875ada6 100644 --- a/lib/tasks/import_product_images.rake +++ b/lib/tasks/import_product_images.rake @@ -25,7 +25,7 @@ namespace :ofn do next end - if product.images.first.nil? + if product.image.nil? ImageImporter.new.import(entry[:image_url], product) puts " image added." else diff --git a/spec/controllers/api/v0/product_images_controller_spec.rb b/spec/controllers/api/v0/product_images_controller_spec.rb index 75c4a53f20..1e2ffee08c 100644 --- a/spec/controllers/api/v0/product_images_controller_spec.rb +++ b/spec/controllers/api/v0/product_images_controller_spec.rb @@ -25,7 +25,7 @@ describe Api::V0::ProductImagesController, type: :controller do } expect(response.status).to eq 201 - expect(product_without_image.reload.images.first.id).to eq json_response['id'] + expect(product_without_image.reload.image.id).to eq json_response['id'] end it "updates an existing product image" do @@ -34,7 +34,7 @@ describe Api::V0::ProductImagesController, type: :controller do } expect(response.status).to eq 200 - expect(product_with_image.reload.images.first.id).to eq json_response['id'] + expect(product_with_image.reload.image.id).to eq json_response['id'] end it "reports errors when saving fails" do @@ -43,7 +43,7 @@ describe Api::V0::ProductImagesController, type: :controller do } expect(response.status).to eq 422 - expect(product_without_image.images.count).to eq 0 + expect(product_without_image.image).to be_nil expect(json_response["id"]).to eq nil expect(json_response["errors"]).to include "Attachment has an invalid content type" end diff --git a/spec/controllers/api/v0/products_controller_spec.rb b/spec/controllers/api/v0/products_controller_spec.rb index 170f662211..567ebc45ed 100644 --- a/spec/controllers/api/v0/products_controller_spec.rb +++ b/spec/controllers/api/v0/products_controller_spec.rb @@ -33,7 +33,7 @@ describe Api::V0::ProductsController, type: :controller do end it "gets a single product" do - product.master.images.create!(attachment: image("thinking-cat.jpg")) + product.create_image!(attachment: image("thinking-cat.jpg")) product.variants.create!(unit_value: "1", unit_description: "thing", price: 1) product.variants.first.images.create!(attachment: image("thinking-cat.jpg")) product.set_property("spree", "rocks") diff --git a/spec/controllers/spree/admin/products_controller_spec.rb b/spec/controllers/spree/admin/products_controller_spec.rb index 5474e5edad..bc02ae7217 100644 --- a/spec/controllers/spree/admin/products_controller_spec.rb +++ b/spec/controllers/spree/admin/products_controller_spec.rb @@ -158,8 +158,8 @@ describe Spree::Admin::ProductsController, type: :controller do tempfile: Tempfile.new('unsupported_image_format.exr') ) product_attrs_with_image = product_attrs.merge( - images_attributes: { - '0' => { attachment: product_image } + image_attributes: { + attachment: product_image } ) diff --git a/spec/factories/product_factory.rb b/spec/factories/product_factory.rb index 1d936699ec..622981b3d2 100644 --- a/spec/factories/product_factory.rb +++ b/spec/factories/product_factory.rb @@ -42,8 +42,8 @@ FactoryBot.define do factory :product_with_image, parent: :product do after(:create) do |product| Spree::Image.create(attachment: white_logo_file, - viewable_id: product.master.id, - viewable_type: 'Spree::Variant') + viewable_id: product.id, + viewable_type: 'Spree::Product') end end diff --git a/spec/javascripts/unit/darkswarm/services/products_spec.js.coffee b/spec/javascripts/unit/darkswarm/services/products_spec.js.coffee index 4c35fb80dd..baea195cf2 100644 --- a/spec/javascripts/unit/darkswarm/services/products_spec.js.coffee +++ b/spec/javascripts/unit/darkswarm/services/products_spec.js.coffee @@ -29,9 +29,9 @@ describe 'Products service', -> id: 9 master: {} variants: [] - images: [ + image: { large_url: 'foo.png' - ] + } currentOrder = line_items: [] currentHub = diff --git a/spec/models/spree/product_spec.rb b/spec/models/spree/product_spec.rb index 1bb88f1b09..9adfafbcb8 100644 --- a/spec/models/spree/product_spec.rb +++ b/spec/models/spree/product_spec.rb @@ -17,7 +17,7 @@ module Spree clone = product.duplicate expect(clone.name).to eq 'COPY OF ' + product.name expect(clone.master.sku).to eq '' - expect(clone.images.size).to eq product.images.size + expect(clone.image).to eq product.image end end @@ -421,11 +421,11 @@ module Spree end end - describe "#validate_image_for_master" do - let(:product) { build_stubbed(:simple_product) } + describe "#validate_image" do + let(:product) { create(:product_with_image) } - context "when the image attached to the master variant is invalid" do - before { product.master.images.new.errors.add(:image_not_processable, "invalid") } + context "when the image is invalid" do + before { expect(product.image).to receive(:valid?).and_return(false) } it "adds an error message to the base object" do expect(product).not_to be_valid diff --git a/spec/serializers/api/product_serializer_spec.rb b/spec/serializers/api/product_serializer_spec.rb index 11ee826b12..b343710af7 100644 --- a/spec/serializers/api/product_serializer_spec.rb +++ b/spec/serializers/api/product_serializer_spec.rb @@ -28,7 +28,7 @@ describe Api::ProductSerializer do it "serializes various attributes" do expect(serializer.serializable_hash.keys).to eq [ :id, :name, :permalink, :meta_keywords, :group_buy, :notes, :description, :description_html, - :properties_with_values, :variants, :primary_taxon, :taxons, :images, :supplier + :properties_with_values, :variants, :primary_taxon, :taxons, :image, :supplier ] end diff --git a/spec/services/image_importer_spec.rb b/spec/services/image_importer_spec.rb index 2c0ed2f7ad..8fc8e20395 100644 --- a/spec/services/image_importer_spec.rb +++ b/spec/services/image_importer_spec.rb @@ -14,8 +14,8 @@ describe ImageImporter do Spree::Image.count }.by(1) - expect(product.images.count).to eq 1 - expect(product.reload.images.first.attachment_blob.byte_size).to eq 6274 + expect(product.image).to_not be_nil + expect(product.reload.image.attachment_blob.byte_size).to eq 6274 end end end diff --git a/spec/system/admin/products_spec.rb b/spec/system/admin/products_spec.rb index 738a43c351..f280950105 100644 --- a/spec/system/admin/products_spec.rb +++ b/spec/system/admin/products_spec.rb @@ -527,10 +527,6 @@ describe ' page.find('a#new_image_link').click - uri = URI.parse(current_url) - # we stay on the same url as the new image content is loaded via an ajax call - expect("#{uri.path}?#{uri.query}").to eq spree.admin_product_images_path(product, filter) - expected_cancel_link = Regexp.new(Regexp.escape(spree.admin_product_images_path(product, filter))) expect(page).to have_link('Cancel', href: expected_cancel_link) @@ -628,14 +624,14 @@ describe ' visit spree.admin_product_images_path(product) expect(page).to have_selector "table.index td img" - expect(product.reload.images.count).to eq 1 + expect(product.reload.image).to_not be_nil accept_alert do page.find('a.delete-resource').click end expect(page).to_not have_selector "table.index td img" - expect(product.reload.images.count).to eq 0 + expect(product.reload.image).to be_nil end it "deleting product image including url filter" do diff --git a/spec/system/admin/reports_spec.rb b/spec/system/admin/reports_spec.rb index 93e1eb4273..07c33f1a79 100644 --- a/spec/system/admin/reports_spec.rb +++ b/spec/system/admin/reports_spec.rb @@ -752,7 +752,7 @@ describe ' def xero_invoice_li_row(line_item, opts = {}) tax_type = line_item.has_tax? ? 'GST on Income' : 'GST Free Income' - xero_invoice_row line_item.product.sku, line_item.product_and_full_name, + xero_invoice_row line_item.variant.sku, line_item.product_and_full_name, line_item.price.to_s, line_item.quantity.to_s, tax_type, opts end diff --git a/spec/views/spree/orders/show.html.haml_spec.rb b/spec/views/spree/orders/show.html.haml_spec.rb index 6980b58caf..6ce839a6e8 100644 --- a/spec/views/spree/orders/show.html.haml_spec.rb +++ b/spec/views/spree/orders/show.html.haml_spec.rb @@ -33,7 +33,7 @@ describe "spree/orders/show.html.haml" do end it "shows product images" do - order.line_items.first.variant.product.images << Spree::Image.new( + order.line_items.first.variant.product.image = Spree::Image.new( attachment: fixture_file_upload("logo.png", "image/png") ) @@ -43,7 +43,7 @@ describe "spree/orders/show.html.haml" do end it "handles broken images" do - image, = order.line_items.first.variant.product.images << Spree::Image.new( + image, = order.line_items.first.variant.product.image = Spree::Image.new( attachment: fixture_file_upload("logo.png", "image/png") ) # This image is not "variable" and can't be resized: