mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Use Spree Taxon Controller instead of API Taxon Controller
Add tests for reordering taxons
This commit is contained in:
committed by
Maikel Linke
parent
5dd2737811
commit
d95c5ff8a8
@@ -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",
|
||||
|
||||
32
spec/controllers/spree/admin/taxons_controller_spec.rb
Normal file
32
spec/controllers/spree/admin/taxons_controller_spec.rb
Normal 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
|
||||
Reference in New Issue
Block a user