Add missing api taxonomies controller only for the required jstree action

This commit is contained in:
luisramos0
2019-08-14 21:55:14 +01:00
parent 9f5c9916ba
commit 92a270165e
2 changed files with 44 additions and 0 deletions

View File

@@ -0,0 +1,12 @@
module Api
class TaxonomiesController < Api::BaseController
respond_to :json
skip_authorization_check only: :jstree
def jstree
@taxonomy = Spree::Taxonomy.find(params[:id])
render json: @taxonomy.root, serializer: Api::TaxonJstreeSerializer
end
end
end

View File

@@ -0,0 +1,32 @@
require 'spec_helper'
module Api
describe TaxonomiesController do
render_views
let(:taxonomy) { create(:taxonomy) }
let(:taxon) { create(:taxon, name: "Ruby", taxonomy: taxonomy) }
let(:taxon2) { create(:taxon, name: "Rails", taxonomy: taxonomy) }
let(:attributes) { [:id, :name] }
before do
allow(controller).to receive(:spree_current_user) { current_api_user }
taxon2.children << create(:taxon, name: "3.2.2", taxonomy: taxonomy)
taxon.children << taxon2
taxonomy.root.children << taxon
end
context "as a normal user" do
let(:current_api_user) { build(:user) }
it "gets the jstree-friendly version of a taxonomy" do
api_get :jstree, id: taxonomy.id
json_response["data"].should eq(taxonomy.root.name)
json_response["attr"].should eq("id" => taxonomy.root.id, "name" => taxonomy.root.name)
json_response["state"].should eq("closed")
end
end
end
end