##// END OF EJS Templates
Honnor committers/users mapping in repository statistics (#13487)....
Jean-Baptiste Barth -
r12999:8c945fb7914b
parent child
Show More
@@ -421,9 +421,10 class Repository < ActiveRecord::Base
421 h = changes_by_author.inject({}) {|o, i| o[i.first] = i.last; o}
421 h = changes_by_author.inject({}) {|o, i| o[i.first] = i.last; o}
422
422
423 commits_by_author.inject({}) do |hash, (name, commits_count)|
423 commits_by_author.inject({}) do |hash, (name, commits_count)|
424 hash[name] = {}
424 mapped_name = (find_committer_user(name) || name).to_s
425 hash[name][:commits_count] = commits_count
425 hash[mapped_name] ||= { :commits_count => 0, :changes_count => 0 }
426 hash[name][:changes_count] = h[name] || 0
426 hash[mapped_name][:commits_count] += commits_count
427 hash[mapped_name][:changes_count] += h[name] || 0
427 hash
428 hash
428 end
429 end
429 end
430 end
@@ -399,7 +399,7 class RepositoryTest < ActiveSupport::TestCase
399 def test_stats_by_author_reflect_changesets_and_changes
399 def test_stats_by_author_reflect_changesets_and_changes
400 repository = Repository.find(10)
400 repository = Repository.find(10)
401
401
402 expected = {"dlopper"=>{:commits_count=>10, :changes_count=>3}}
402 expected = {"Dave Lopper"=>{:commits_count=>10, :changes_count=>3}}
403 assert_equal expected, repository.stats_by_author
403 assert_equal expected, repository.stats_by_author
404
404
405 set = Changeset.create!(
405 set = Changeset.create!(
@@ -411,7 +411,53 class RepositoryTest < ActiveSupport::TestCase
411 )
411 )
412 Change.create!(:changeset => set, :action => 'A', :path => '/path/to/file1')
412 Change.create!(:changeset => set, :action => 'A', :path => '/path/to/file1')
413 Change.create!(:changeset => set, :action => 'A', :path => '/path/to/file2')
413 Change.create!(:changeset => set, :action => 'A', :path => '/path/to/file2')
414 expected = {"dlopper"=>{:commits_count=>11, :changes_count=>5}}
414 expected = {"Dave Lopper"=>{:commits_count=>11, :changes_count=>5}}
415 assert_equal expected, repository.stats_by_author
416 end
417
418 def test_stats_by_author_honnor_committers
419 # in fact it is really tested above, but let's have a dedicated test
420 # to ensure things are dynamically linked to Users
421 User.find_by_login("dlopper").update_attribute(:firstname, "Dave's")
422 repository = Repository.find(10)
423 expected = {"Dave's Lopper"=>{:commits_count=>10, :changes_count=>3}}
424 assert_equal expected, repository.stats_by_author
425 end
426
427 def test_stats_by_author_doesnt_drop_unmapped_users
428 repository = Repository.find(10)
429 Changeset.create!(
430 :repository => repository,
431 :committer => 'unnamed <foo@bar.net>',
432 :committed_on => Time.now,
433 :revision => 101,
434 :comments => 'Another commit by foo.'
435 )
436
437 assert repository.stats_by_author.has_key?("unnamed <foo@bar.net>")
438 end
439
440 def test_stats_by_author_merge_correctly
441 # as we honnor users->committer map and it's not injective,
442 # we must be sure merges happen correctly and stats are not
443 # wiped out when two source counts map to the same user.
444 #
445 # Here we have Changeset's with committer="dlopper" and others
446 # with committer="dlopper <dlopper@somefoo.net>"
447 repository = Repository.find(10)
448
449 expected = {"Dave Lopper"=>{:commits_count=>10, :changes_count=>3}}
450 assert_equal expected, repository.stats_by_author
451
452 set = Changeset.create!(
453 :repository => repository,
454 :committer => 'dlopper <dlopper@somefoo.net>',
455 :committed_on => Time.now,
456 :revision => 101,
457 :comments => 'Another commit by foo.'
458 )
459
460 expected = {"Dave Lopper"=>{:commits_count=>11, :changes_count=>3}}
415 assert_equal expected, repository.stats_by_author
461 assert_equal expected, repository.stats_by_author
416 end
462 end
417 end
463 end
General Comments 0
You need to be logged in to leave comments. Login now