Skip to content

Commit

Permalink
Merge pull request #18378 from yrudman/fixed-saving-tag-name
Browse files Browse the repository at this point in the history
Fixed saving edited tag name
  • Loading branch information
gtanzillo authored Jan 25, 2019
2 parents 91e3dd8 + fccb683 commit 4794a6d
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
6 changes: 5 additions & 1 deletion app/models/classification.rb
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,11 @@ def find_tag

def save_tag
tag_name = Classification.name2tag(name, parent_id, ns)
self.tag = Tag.in_region(region_id).find_or_create_by(:name => tag_name)
if tag.present?
tag.update_attributes(:name => tag_name)
else
self.tag = Tag.in_region(region_id).find_or_create_by(:name => tag_name)
end
end

def delete_all_entries
Expand Down
25 changes: 25 additions & 0 deletions spec/models/classification_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,31 @@
end
end

describe '#save' do
let(:new_name) { "new_tag_name" }

context "editing existing tag" do
it "updates record in Tag table which linked to this classification" do
classification = FactoryBot.create(:classification_tag, :name => "some_tag_name")
tag = classification.tag
classification.name = new_name
classification.save
expect(tag.id).to eq classification.tag.id
expect(classification.tag.name).to eq(Classification.name2tag(new_name))
end
end

context "saving new tag" do
it "creates new record in Tag table and links it to this classification" do
classification = Classification.new
classification.description = "some description"
classification.name = new_name
classification.save
expect(classification.tag).to eq(Tag.last)
end
end
end

def all_tagged_with(target, all, category = nil)
tagged_with(target, :all => all, :cat => category)
end
Expand Down

0 comments on commit 4794a6d

Please sign in to comment.