]> source.dussan.org Git - redmine.git/commitdiff
Fixed error on commits per month graph (#10806).
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Tue, 1 May 2012 21:12:47 +0000 (21:12 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Tue, 1 May 2012 21:12:47 +0000 (21:12 +0000)
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@9610 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/controllers/repositories_controller.rb
test/functional/repositories_controller_test.rb

index fb12ce373c99cd00bb3df594f144e779fa94d1be..f02bd8b70c4bf83a3490039df7bdfad0d89d40ec 100644 (file)
@@ -347,13 +347,13 @@ class RepositoriesController < ApplicationController
                           :all, :group => :commit_date,
                           :conditions => ["repository_id = ? AND commit_date BETWEEN ? AND ?", repository.id, @date_from, @date_to])
     commits_by_month = [0] * 12
-    commits_by_day.each {|c| commits_by_month[c.first.to_date.months_ago] += c.last }
+    commits_by_day.each {|c| commits_by_month[(@date_to.month - c.first.to_date.month) % 12] += c.last }
 
     changes_by_day = Change.count(
                           :all, :group => :commit_date, :include => :changeset,
                           :conditions => ["#{Changeset.table_name}.repository_id = ? AND #{Changeset.table_name}.commit_date BETWEEN ? AND ?", repository.id, @date_from, @date_to])
     changes_by_month = [0] * 12
-    changes_by_day.each {|c| changes_by_month[c.first.to_date.months_ago] += c.last }
+    changes_by_day.each {|c| changes_by_month[(@date_to.month - c.first.to_date.month) % 12] += c.last }
 
     fields = []
     12.times {|m| fields << month_name(((Date.today.month - 1 - m) % 12) + 1)}
index 48ea1ac082d658d63d1cb8122d3d548ec595bd99..0ef4d5462993a36a45bd22bb33a4db3f12029be1 100644 (file)
@@ -201,6 +201,11 @@ class RepositoriesControllerTest < ActionController::TestCase
   end
 
   def test_graph_commits_per_month
+    # Make sure there's some data to display
+    latest = Project.find(1).repository.changesets.maximum(:commit_date)
+    assert_not_nil latest
+    Date.stubs(:today).returns(latest.to_date + 10)
+
     get :graph, :id => 1, :graph => 'commits_per_month'
     assert_response :success
     assert_equal 'image/svg+xml', @response.content_type