Use Spree Taxon Controller instead of API Taxon Controller

Add tests for reordering taxons
This commit is contained in:
Neal Chambers
2023-03-06 15:07:52 +09:00
committed by Maikel Linke
parent 5dd2737811
commit d95c5ff8a8
2 changed files with 33 additions and 1 deletions

View File

@@ -8,7 +8,7 @@ handle_move = (e, data) ->
node = data.rslt.o
new_parent = data.rslt.np
url = new URL(base_url)
url = new URL(Spree.routes.admin_taxonomy_taxons)
url.pathname = url.pathname + '/' + node.attr("id")
data = {
_method: "put",

View File

@@ -0,0 +1,32 @@
# frozen_string_literal: true
require 'spec_helper'
describe Spree::Admin::TaxonsController do
render_views
let(:taxonomy) { create(:taxonomy) }
let(:taxon) { create(:taxon, name: "Ruby", taxonomy: taxonomy) }
let(:taxon2) { create(:taxon, name: "Rails", taxonomy: taxonomy) }
before do
allow(controller).to receive(:spree_current_user) { current_api_user }
taxonomy.root.children << taxon
taxonomy.root.children << taxon2
end
context "as an admin" do
let(:current_api_user) { build(:admin_user) }
it "can reorder taxons" do
spree_post :update,
taxonomy_id: taxonomy.id,
id: taxon2.id,
taxon: { parent_id: taxonomy.root.id, position: 0 }
expect(taxon2.reload.lft).to eq 2
expect(Spree::Taxonomy.find(taxonomy.id).root.children.first).to eq(taxon2)
end
end
end