Skip to content

Commit

Permalink
[fix] Ability to reassign image to another variant
Browse files Browse the repository at this point in the history
  • Loading branch information
felixyz committed Oct 26, 2020
1 parent ee05883 commit ccaef75
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 3 deletions.
2 changes: 1 addition & 1 deletion api/app/controllers/spree/api/images_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
37 changes: 35 additions & 2 deletions backend/spec/features/admin/products/edit/images_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit ccaef75

Please sign in to comment.