Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix reassign image to another variant in admin #3810

Merged
merged 1 commit into from
Nov 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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