module WpTerm
  extend ActiveSupport::Concern

  def update_term(json)
    self.class.mappable_wordpress_attributes.each do |wp_attribute|
      send("#{wp_attribute}=", json[wp_attribute])
    end

    self.wp_id        = json['ID']
    if json['parent']
      self.class.where(wp_id: json['parent']['ID']).first_or_create.update_wp_cache(json['parent'])
      self.parent_id = self.class.where(wp_id: json['parent']['ID']).first.id
    end

    save!
  end

  module ClassMethods

    def mappable_wordpress_attributes
      %w( name slug description count )
    end

    def wp_type
      self.to_s.underscore.pluralize
    end

  end
end

module WpTerm
  extend ActiveSupport::Concern

  def update_term(json)
    return unless json.is_a?(Hash)

    self.class.mappable_wordpress_attributes.each do |wp_attribute|
      send("#{wp_attribute}=", json[wp_attribute])
    end

    self.wp_id        = json['ID']
    if json['parent']
      self.class.where(wp_id: json['parent']['ID']).first_or_create.update_wp_cache(json['parent'])
      self.parent_id = self.class.where(wp_id: json['parent']['ID']).first.id
    end

    save!
  end

  module ClassMethods

    def mappable_wordpress_attributes
      %w( name slug description count )
    end

    def wp_type
      self.to_s.underscore.pluralize
    end

  end
end

Fix not found json for terms
Fix not found json for terms

When a term no longer exists on the WP side the json will return an array containing an error message. This breaks the assignment of values because the look up is done with a string.
