diff --git a/api/app/controllers/spree/api/images_controller.rb b/api/app/controllers/spree/api/images_controller.rb index 3ec65e1f7fa..c22c91a81d3 100644 --- a/api/app/controllers/spree/api/images_controller.rb +++ b/api/app/controllers/spree/api/images_controller.rb @@ -20,7 +20,7 @@ def create end def update - @image = scope.images.accessible_by(current_ability, :update).find(params[:id]) + @image = scope.gallery.images.accessible_by(current_ability, :update).find(params[:id]) @image.update(image_params) respond_with(@image, default_template: :show) end diff --git a/backend/spec/features/admin/products/edit/images_spec.rb b/backend/spec/features/admin/products/edit/images_spec.rb index 6d482f082aa..7d680f53f1d 100644 --- a/backend/spec/features/admin/products/edit/images_spec.rb +++ b/backend/spec/features/admin/products/edit/images_spec.rb @@ -6,7 +6,9 @@ stub_authorization! let(:file_path) { file_fixture("ror_ringer.jpeg") } - let(:product) { create(:product) } + let!(:product) { create(:product) } + let!(:variant1) { create(:variant, product: product) } + let!(:variant2) { create(:variant, product: product) } before do # Ensure attachment style keys are symbolized before running all tests @@ -18,7 +20,6 @@ context "uploading, editing, and deleting an image", js: true do before do Spree::Image.attachment_definitions[:attachment].delete :storage - create(:product) visit spree.admin_path click_nav "Products" @@ -67,6 +68,38 @@ end expect(page).not_to have_field "image[alt]", with: "ruby on rails t-shirt" end + + context "with several variants" do + it "should allow an admin to re-assign an image to another variant" do + click_link "new_image_link" + within_fieldset 'New Image' do + # Select image + attach_file('image_attachment', file_path) + # Select specific variant + select variant1.sku_and_options_text, from: "Variant" + end + click_button "Update" + expect(page).to have_content("Image has been successfully created!") + + find('tbody > tr').hover + within_row(1) do + # Select another variant + targetted_select2 variant2.sku_and_options_text, from: "#s2id_image_viewable_id" + # Click the checkmark which has appeared + within ".actions" do + click_icon :check + end + end + + # Re-load the tab + click_link "Images" + + # The new variant has been associated with the image + within_row(1) do + expect(page).to have_content(variant2.sku_and_options_text) + end + end + end end it "should not see variant column when product has no variants" do