Skip to content

Commit

Permalink
rebasing on master and fixing all specs
Browse files Browse the repository at this point in the history
  • Loading branch information
Mohammed Gharbi committed May 6, 2016
1 parent 5575de0 commit b0a7b74
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 18 deletions.
2 changes: 1 addition & 1 deletion api/app/controllers/spree/api/taxons_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def index
elsif params[:ids]
@taxons = Spree::Taxon.accessible_by(current_ability, :read).where(id: params[:ids].split(','))
else
@taxons = Spree::Taxon.accessible_by(current_ability, :read).order(:taxonomy_id, :lft).ransack(params[:q]).result
@taxons = Spree::Taxon.accessible_by(current_ability, :read).order(:taxonomy_id, :permalink).ransack(params[:q]).result
end

@taxons = @taxons.page(params[:page]).per(params[:per_page])
Expand Down
2 changes: 1 addition & 1 deletion api/spec/controllers/spree/api/taxons_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ module Spree

it "can update the position in the list" do
taxonomy.root.children << taxon2
api_put :update, taxonomy_id: taxonomy.id, id: taxon.id, taxon: { parent_id: taxon.parent_id, child_index: 2 }
api_put :update, taxonomy_id: taxonomy.id, id: taxon.id, taxon: { parent_id: taxon.parent_id, child_index: 1 }
expect(response.status).to eq(200)
expect(taxonomy.reload.root.children[0]).to eql taxon2
expect(taxonomy.reload.root.children[1]).to eql taxon
Expand Down
26 changes: 13 additions & 13 deletions core/app/models/spree/taxon.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module Spree
class Taxon < Spree::Base
has_closure_tree hierarchy_class_name: 'Spree::TaxonHierarchy',
hierarchy_table_name: 'spree_taxon_hierarchies',
order: 'position',
order: :position,
dependent: :destroy

belongs_to :taxonomy, class_name: 'Spree::Taxonomy', inverse_of: :taxons
Expand Down Expand Up @@ -110,18 +110,6 @@ def child_index=(idx)
move_to_child_with_index(parent, idx.to_i) unless new_record?
end

def permalink_part
permalink.split('/').last
end

def permalink_part=(value)
if parent.present?
self.permalink = "#{parent.permalink}/#{value}"
else
self.permalink = value
end
end

def move_to_child_with_index(node, index)
# closure_tree does not provide any method that move nodes regarding position
# this method overrides move_to_child_with_index offered by awesome_nested_set
Expand All @@ -139,6 +127,18 @@ def move_to_child_with_index(node, index)
end
end

def permalink_part
permalink.split('/').last
end

def permalink_part=(value)
if parent.present?
self.permalink = "#{parent.permalink}/#{value}"
else
self.permalink = value
end
end

private

def touch_ancestors_and_taxonomy
Expand Down
11 changes: 8 additions & 3 deletions core/spec/models/spree/taxon_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,14 @@
context "updating permalink" do
let(:taxonomy) { create(:taxonomy, name: 't') }
let(:root) { taxonomy.root }
let(:taxon1) { create(:taxon, name: 't1', taxonomy: taxonomy, parent: root) }
let(:taxon2) { create(:taxon, name: 't2', taxonomy: taxonomy, parent: root) }
let(:taxon2_child) { create(:taxon, name: 't2_child', taxonomy: taxonomy, parent: taxon2) }
let(:taxon1) { create(:taxon, name: 't1', taxonomy: taxonomy) }
let(:taxon2) { create(:taxon, name: 't2', taxonomy: taxonomy) }
let(:taxon2_child) { create(:taxon, name: 't2_child', taxonomy: taxonomy) }

before :each do
root.children << [taxon1, taxon2]
taxon2.children << taxon2_child
end

context "changing parent" do
subject do
Expand Down

0 comments on commit b0a7b74

Please sign in to comment.