Skip to content

Commit

Permalink
[api] fix and verify binary release item compare
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianschroeter committed Sep 2, 2014
1 parent 0814862 commit 71c4fda
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
6 changes: 3 additions & 3 deletions src/api/app/models/binary_release.rb
Expand Up @@ -136,9 +136,9 @@ def self.update_binary_releases_via_json(repository, json, time = Time.now)
# compare with existing entry
if existing.count == 1
entry = existing.first
if entry.binary_disturl == binary["disturl"] and
entry.binary_supportstatus == binary["supportstatus"] and
entry.binary_buildtime.utc == ::Time.at(binary["buildtime"].to_i).to_datetime.utc
if entry.binary_disturl == binary["disturl"] and
entry.binary_supportstatus == binary["supportstatus"] and
entry.binary_buildtime.to_datetime.utc == ::Time.at(binary["buildtime"].to_i).to_datetime.utc
# same binary, don't touch
processed_item[entry.id] = true
next
Expand Down
12 changes: 11 additions & 1 deletion src/api/test/unit/binary_release.rb
Expand Up @@ -60,11 +60,21 @@ def test_create_and_find_entries
end

def test_update_from_json_hash
json = [{"arch"=>"i586", "binaryarch"=>"i586", "repository"=>"BaseDistro3_repo", "release"=>"1", "name"=>"delete_me", "project"=>"BaseDistro3", "version"=>"1.0", "package"=>"pack2"}, {"arch"=>"i586", "binaryarch"=>"i586", "name"=>"package", "repository"=>"BaseDistro3_repo", "release"=>"1", "project"=>"BaseDistro3", "version"=>"1.0", "package"=>"pack2"}, {"arch"=>"i586", "binaryarch"=>"src", "name"=>"package", "repository"=>"BaseDistro3_repo", "release"=>"1", "project"=>"BaseDistro3", "version"=>"1.0", "package"=>"pack2"}, {"binaryarch"=>"x86_64", "arch"=>"i586", "package"=>"pack2", "project"=>"BaseDistro3", "version"=>"1.0", "release"=>"1", "repository"=>"BaseDistro3_repo", "name"=>"package_newweaktags"}]
json = [{"arch"=>"i586", "binaryarch"=>"i586", "repository"=>"BaseDistro3_repo", "release"=>"1", "name"=>"delete_me", "project"=>"BaseDistro3", "version"=>"1.0", "package"=>"pack2", "buildtime"=>"1409642056"}, {"arch"=>"i586", "binaryarch"=>"i586", "name"=>"package", "repository"=>"BaseDistro3_repo", "release"=>"1", "project"=>"BaseDistro3", "version"=>"1.0", "package"=>"pack2", "buildtime"=>"1409642056"}, {"arch"=>"i586", "binaryarch"=>"src", "name"=>"package", "repository"=>"BaseDistro3_repo", "release"=>"1", "project"=>"BaseDistro3", "version"=>"1.0", "package"=>"pack2", "buildtime"=>"1409642056"}, {"binaryarch"=>"x86_64", "arch"=>"i586", "package"=>"pack2", "project"=>"BaseDistro3", "version"=>"1.0", "release"=>"1", "repository"=>"BaseDistro3_repo", "name"=>"package_newweaktags", "buildtime"=>"1409642056"}]

r = Repository.find_by_project_and_repo_name("BaseDistro3", "BaseDistro3_repo")

BinaryRelease.update_binary_releases_via_json(r, json)
count = BinaryRelease.all.length
# no new entries
BinaryRelease.update_binary_releases_via_json(r, json)
assert_equal count, BinaryRelease.all.length

# modify just one timestampe
json = [{"arch"=>"i586", "binaryarch"=>"i586", "repository"=>"BaseDistro3_repo", "release"=>"1", "name"=>"delete_me", "project"=>"BaseDistro3", "version"=>"1.0", "package"=>"pack2", "buildtime"=>"1409642056"}, {"arch"=>"i586", "binaryarch"=>"i586", "name"=>"package", "repository"=>"BaseDistro3_repo", "release"=>"1", "project"=>"BaseDistro3", "version"=>"1.0", "package"=>"pack2", "buildtime"=>"1409642056"}, {"arch"=>"i586", "binaryarch"=>"src", "name"=>"package", "repository"=>"BaseDistro3_repo", "release"=>"1", "project"=>"BaseDistro3", "version"=>"1.0", "package"=>"pack2", "buildtime"=>"1409642056"}, {"binaryarch"=>"x86_64", "arch"=>"i586", "package"=>"pack2", "project"=>"BaseDistro3", "version"=>"1.0", "release"=>"1", "repository"=>"BaseDistro3_repo", "name"=>"package_newweaktags", "buildtime"=>"1409642057"}]
BinaryRelease.update_binary_releases_via_json(r, json)
assert_equal count, BinaryRelease.all.length-1 # one entry added

end

end

0 comments on commit 71c4fda

Please sign in to comment.