Skip to content

Commit

Permalink
Merge pull request SUSE#551 from Salzig/fix_removeale_of_wrong_tags
Browse files Browse the repository at this point in the history
fix: only remove associated tags
  • Loading branch information
flavio committed Nov 11, 2015
2 parents 412aa02 + bf5c667 commit 99fa347
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/models/repository.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def self.create_or_update!(repo)
end

# Finally remove the tags that are left and return the repo.
Tag.where(name: to_be_deleted_tags).find_each(&:delete_and_update!)
repository.tags.where(name: to_be_deleted_tags).find_each(&:delete_and_update!)
repository.reload
end
end
15 changes: 15 additions & 0 deletions spec/models/repository_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -334,5 +334,20 @@ def get_url(repo, tag)
repo = { "name" => "unknown/repo1", "tags" => ["latest", "0.1"] }
expect(Repository.create_or_update!(repo)).to be_nil
end

it "dosnt remove tags of same name for different repo" do
# create "latest" for repo1 and repo2
event_one = { "name" => "#{namespace.name}/repo1", "tags" => ["latest"] }
Repository.create_or_update!(event_one)
event_two = { "name" => "#{namespace.name}/repo2", "tags" => ["latest"] }
Repository.create_or_update!(event_two)

# remove "latest" for repo2
event_three = { "name" => "#{namespace.name}/repo2", "tags" => ["other"] }
Repository.create_or_update!(event_three)

expect(repo1.tags.pluck(:name)).to include("latest")
expect(repo2.tags.pluck(:name)).not_to include("latest")
end
end
end

0 comments on commit 99fa347

Please sign in to comment.