Commit b81c513aaa03d9dcde5253104870c622c826def8
- Date: Sun Mar 30 15:36:51 +0000 2008
- Committer: Johan Sørensen (johan@johansorensen.com)
- Author: Johan Sørensen (johan@johansorensen.com)
- Commit SHA1: b81c513aaa03d9dcde5253104870c622c826def8
- Tree SHA1: 1446d0241ee739da31532940c3c7db2fb0b8f88f
move #users_by_commits into Repository model where it belongs
Commit diff
| |   |
| 1 | | module RepositoriesHelper |
| 2 | | # Returns a Hash {email => user} |
| 3 | | def self.users_by_commits(commits) |
| 4 | | emails = commits.map { |commit| commit.committer.email } |
| 5 | | users = User.find(:all, :conditions => ["email in (?)", emails]) |
| 6 | | email_user = {} |
| 7 | | users.each { |user| |
| 8 | | email_user[user.email] = user |
| 9 | | } |
| 10 | | |
| 11 | | email_user |
| 12 | | end |
| 13 | | |
| 1 | module RepositoriesHelper |
| 14 | 2 | def log_path(objectish = "master", options = {}) |
| 15 | 3 | if options.blank? # just to avoid the ? being tacked onto the url |
| 16 | 4 | project_repository_log_path(@project, @repository, objectish) |
| toggle raw diff |
--- a/app/helpers/repositories_helper.rb
+++ b/app/helpers/repositories_helper.rb
@@ -1,16 +1,4 @@
-module RepositoriesHelper
- # Returns a Hash {email => user}
- def self.users_by_commits(commits)
- emails = commits.map { |commit| commit.committer.email }
- users = User.find(:all, :conditions => ["email in (?)", emails])
- email_user = {}
- users.each { |user|
- email_user[user.email] = user
- }
-
- email_user
- end
-
+module RepositoriesHelper
def log_path(objectish = "master", options = {})
if options.blank? # just to avoid the ? being tacked onto the url
project_repository_log_path(@project, @repository, objectish) |
| |   |
| 212 | 212 | hash |
| 213 | 213 | end |
| 214 | 214 | end |
| 215 | |
| 216 | # Returns a Hash {email => user}, where email is selected from the +commits+ |
| 217 | def users_by_commits(commits) |
| 218 | emails = commits.map { |commit| commit.committer.email }.uniq |
| 219 | users = User.find(:all, :conditions => ["email in (?)", emails]) |
| 220 | |
| 221 | users_by_email = users.inject({}){|hash, user| hash[user.email] = user; hash } |
| 222 | users_by_email |
| 223 | end |
| 215 | 224 | |
| 216 | 225 | protected |
| 217 | 226 | def set_as_mainline_if_first |
| toggle raw diff |
--- a/app/models/repository.rb
+++ b/app/models/repository.rb
@@ -212,6 +212,15 @@ class Repository < ActiveRecord::Base
hash
end
end
+
+ # Returns a Hash {email => user}, where email is selected from the +commits+
+ def users_by_commits(commits)
+ emails = commits.map { |commit| commit.committer.email }.uniq
+ users = User.find(:all, :conditions => ["email in (?)", emails])
+
+ users_by_email = users.inject({}){|hash, user| hash[user.email] = user; hash }
+ users_by_email
+ end
protected
def set_as_mainline_if_first |
| |   |
| 1 | | <% email_user = RepositoriesHelper.users_by_commits(@commits) %> |
| 1 | <% users_by_email = @repository.users_by_commits(@commits) %> |
| 2 | 2 | <ul class="commit_list"> |
| 3 | 3 | <% @commits.each do |commit| -%> |
| 4 | | <% user = email_user[commit.committer.email] %> |
| 4 | <% user = users_by_email[commit.committer.email] %> |
| 5 | 5 | <li class="commit_item"> |
| 6 | 6 | <div> |
| 7 | 7 | <a href=""><%= link_to h(commit.id_abbrev), |
| toggle raw diff |
--- a/app/views/logs/_log.html.erb
+++ b/app/views/logs/_log.html.erb
@@ -1,7 +1,7 @@
-<% email_user = RepositoriesHelper.users_by_commits(@commits) %>
+<% users_by_email = @repository.users_by_commits(@commits) %>
<ul class="commit_list">
<% @commits.each do |commit| -%>
-<% user = email_user[commit.committer.email] %>
+<% user = users_by_email[commit.committer.email] %>
<li class="commit_item">
<div>
<a href=""><%= link_to h(commit.id_abbrev), |
| |   |
| 36 | 36 | <th></th> |
| 37 | 37 | <th></th> |
| 38 | 38 | </thead> |
| 39 | | <% commits = [] %> |
| 40 | 39 | <% repositories = @repositories.sort_by { |e| if e.last_commit then commits << e.last_commit; e.mainline? ? Time.now : e.last_commit.committed_date; else Time.at(0); end } %> |
| 41 | | <% email_user = RepositoriesHelper.users_by_commits(commits) %> |
| 42 | 40 | <% repositories.reverse_each do |repos| # FIXME: need to graph the parent relation proper -%> |
| 43 | | <% user = email_user[repos.last_commit.committer.email] if repos.has_commits? %> |
| 44 | 41 | <tr class="<%= cycle("even", "odd") -%> <%= repos.mainline? ? "mainline" : "clone" -%>"> |
| 45 | 42 | <td class="name"> |
| 46 | 43 | <%= link_to h(repos.name), project_repository_path(@project, repos) -%> |
| toggle raw diff |
--- a/app/views/projects/show.html.erb
+++ b/app/views/projects/show.html.erb
@@ -36,11 +36,8 @@
<th></th>
<th></th>
</thead>
- <% commits = [] %>
<% repositories = @repositories.sort_by { |e| if e.last_commit then commits << e.last_commit; e.mainline? ? Time.now : e.last_commit.committed_date; else Time.at(0); end } %>
- <% email_user = RepositoriesHelper.users_by_commits(commits) %>
<% repositories.reverse_each do |repos| # FIXME: need to graph the parent relation proper -%>
- <% user = email_user[repos.last_commit.committer.email] if repos.has_commits? %>
<tr class="<%= cycle("even", "odd") -%> <%= repos.mainline? ? "mainline" : "clone" -%>">
<td class="name">
<%= link_to h(repos.name), project_repository_path(@project, repos) -%> |
| |   |
| 257 | 257 | @repository.count_commits_from_last_week_by_user(users(:johan)).should == 0 |
| 258 | 258 | end |
| 259 | 259 | |
| 260 | it "returns a set of users from a list of commits" do |
| 261 | commits = [] |
| 262 | users(:johan, :moe).map(&:email).each do |email| |
| 263 | committer = OpenStruct.new(:email => email) |
| 264 | commits << OpenStruct.new(:committer => committer) |
| 265 | end |
| 266 | users = @repository.users_by_commits(commits) |
| 267 | users.keys.sort.should == users(:johan, :moe).map(&:email).sort |
| 268 | users.values.map(&:login).sort.should == users(:johan, :moe).map(&:login).sort |
| 269 | end |
| 270 | |
| 260 | 271 | describe "observers" do |
| 261 | 272 | it "sends an email to the admin if there's a parent" do |
| 262 | 273 | Mailer.should_receive(:deliver_new_repository_clone).with(@repository).and_return(true) |
| toggle raw diff |
--- a/spec/models/repository_spec.rb
+++ b/spec/models/repository_spec.rb
@@ -257,6 +257,17 @@ describe Repository do
@repository.count_commits_from_last_week_by_user(users(:johan)).should == 0
end
+ it "returns a set of users from a list of commits" do
+ commits = []
+ users(:johan, :moe).map(&:email).each do |email|
+ committer = OpenStruct.new(:email => email)
+ commits << OpenStruct.new(:committer => committer)
+ end
+ users = @repository.users_by_commits(commits)
+ users.keys.sort.should == users(:johan, :moe).map(&:email).sort
+ users.values.map(&:login).sort.should == users(:johan, :moe).map(&:login).sort
+ end
+
describe "observers" do
it "sends an email to the admin if there's a parent" do
Mailer.should_receive(:deliver_new_repository_clone).with(@repository).and_return(true) |