##// END OF EJS Templates
Cleanup of finders with :conditions option....
Jean-Philippe Lang -
r11733:f9ddb562d58a
parent child
Show More
@@ -71,8 +71,7 class ContextMenusController < ApplicationController
71 71 end
72 72
73 73 def time_entries
74 @time_entries = TimeEntry.all(
75 :conditions => {:id => params[:ids]}, :include => :project)
74 @time_entries = TimeEntry.where(:id => params[:ids]).preload(:project).to_a
76 75 (render_404; return) unless @time_entries.present?
77 76
78 77 @projects = @time_entries.collect(&:project).compact.uniq
@@ -301,7 +301,7 class IssuesController < ApplicationController
301 301 end
302 302
303 303 def destroy
304 @hours = TimeEntry.sum(:hours, :conditions => ['issue_id IN (?)', @issues]).to_f
304 @hours = TimeEntry.where(:issue_id => @issues.map(&:id)).sum(:hours).to_f
305 305 if @hours > 0
306 306 case params[:todo]
307 307 when 'destroy'
@@ -35,7 +35,7 class MessagesController < ApplicationController
35 35 page = params[:page]
36 36 # Find the page of the requested reply
37 37 if params[:r] && page.nil?
38 offset = @topic.children.count(:conditions => ["#{Message.table_name}.id < ?", params[:r].to_i])
38 offset = @topic.children.where("#{Message.table_name}.id < ?", params[:r].to_i).count
39 39 page = 1 + offset / REPLIES_PER_PAGE
40 40 end
41 41
@@ -155,7 +155,7 class ProjectsController < ApplicationController
155 155 @total_issues_by_tracker = Issue.visible.where(cond).count(:group => :tracker)
156 156
157 157 if User.current.allowed_to?(:view_time_entries, @project)
158 @total_hours = TimeEntry.visible.sum(:hours, :include => :project, :conditions => cond).to_f
158 @total_hours = TimeEntry.visible.where(cond).sum(:hours).to_f
159 159 end
160 160
161 161 @key = User.current.rss_key
@@ -352,15 +352,18 class RepositoriesController < ApplicationController
352 352 @date_to = Date.today
353 353 @date_from = @date_to << 11
354 354 @date_from = Date.civil(@date_from.year, @date_from.month, 1)
355 commits_by_day = Changeset.count(
356 :all, :group => :commit_date,
357 :conditions => ["repository_id = ? AND commit_date BETWEEN ? AND ?", repository.id, @date_from, @date_to])
355 commits_by_day = Changeset.
356 where("repository_id = ? AND commit_date BETWEEN ? AND ?", repository.id, @date_from, @date_to).
357 group(:commit_date).
358 count
358 359 commits_by_month = [0] * 12
359 360 commits_by_day.each {|c| commits_by_month[(@date_to.month - c.first.to_date.month) % 12] += c.last }
360 361
361 changes_by_day = Change.count(
362 :all, :group => :commit_date, :include => :changeset,
363 :conditions => ["#{Changeset.table_name}.repository_id = ? AND #{Changeset.table_name}.commit_date BETWEEN ? AND ?", repository.id, @date_from, @date_to])
362 changes_by_day = Change.
363 joins(:changeset).
364 where("#{Changeset.table_name}.repository_id = ? AND #{Changeset.table_name}.commit_date BETWEEN ? AND ?", repository.id, @date_from, @date_to).
365 group(:commit_date).
366 count
364 367 changes_by_month = [0] * 12
365 368 changes_by_day.each {|c| changes_by_month[(@date_to.month - c.first.to_date.month) % 12] += c.last }
366 369
@@ -393,10 +396,10 class RepositoriesController < ApplicationController
393 396 end
394 397
395 398 def graph_commits_per_author(repository)
396 commits_by_author = Changeset.count(:all, :group => :committer, :conditions => ["repository_id = ?", repository.id])
399 commits_by_author = Changeset.where("repository_id = ?", repository.id).group(:committer).count
397 400 commits_by_author.to_a.sort! {|x, y| x.last <=> y.last}
398 401
399 changes_by_author = Change.count(:all, :group => :committer, :include => :changeset, :conditions => ["#{Changeset.table_name}.repository_id = ?", repository.id])
402 changes_by_author = Change.joins(:changeset).where("#{Changeset.table_name}.repository_id = ?", repository.id).group(:committer).count
400 403 h = changes_by_author.inject({}) {|o, i| o[i.first] = i.last; o}
401 404
402 405 fields = commits_by_author.collect {|r| r.first}
@@ -19,11 +19,7 class SysController < ActionController::Base
19 19 before_filter :check_enabled
20 20
21 21 def projects
22 p = Project.active.has_module(:repository).find(
23 :all,
24 :include => :repository,
25 :order => "#{Project.table_name}.identifier"
26 )
22 p = Project.active.has_module(:repository).order("#{Project.table_name}.identifier").preload(:repository).all
27 23 # extra_info attribute from repository breaks activeresource client
28 24 render :xml => p.to_xml(
29 25 :only => [:id, :identifier, :name, :is_public, :status],
@@ -60,7 +60,7 class UsersController < ApplicationController
60 60
61 61 def show
62 62 # show projects based on current user visibility
63 @memberships = @user.memberships.all(:conditions => Project.visible_condition(User.current))
63 @memberships = @user.memberships.where(Project.visible_condition(User.current)).all
64 64
65 65 events = Redmine::Activity::Fetcher.new(User.current, :author => @user).events(nil, nil, :limit => 10)
66 66 @events_by_day = events.group_by(&:event_date)
@@ -46,11 +46,11 class VersionsController < ApplicationController
46 46
47 47 @issues_by_version = {}
48 48 if @selected_tracker_ids.any? && @versions.any?
49 issues = Issue.visible.all(
50 :include => [:project, :status, :tracker, :priority, :fixed_version],
51 :conditions => {:tracker_id => @selected_tracker_ids, :project_id => project_ids, :fixed_version_id => @versions.map(&:id)},
52 :order => "#{Project.table_name}.lft, #{Tracker.table_name}.position, #{Issue.table_name}.id"
53 )
49 issues = Issue.visible.
50 includes(:project, :tracker).
51 preload(:status, :priority, :fixed_version).
52 where(:tracker_id => @selected_tracker_ids, :project_id => project_ids, :fixed_version_id => @versions.map(&:id)).
53 order("#{Project.table_name}.lft, #{Tracker.table_name}.position, #{Issue.table_name}.id")
54 54 @issues_by_version = issues.group_by(&:fixed_version)
55 55 end
56 56 @versions.reject! {|version| !project_ids.include?(version.project_id) && @issues_by_version[version].blank?}
@@ -185,7 +185,7 module QueriesHelper
185 185 if !params[:query_id].blank?
186 186 cond = "project_id IS NULL"
187 187 cond << " OR project_id = #{@project.id}" if @project
188 @query = IssueQuery.find(params[:query_id], :conditions => cond)
188 @query = IssueQuery.where(cond).find(params[:query_id])
189 189 raise ::Unauthorized unless @query.visible?
190 190 @query.project = @project
191 191 session[:query] = {:id => @query.id, :project_id => @query.project_id}
@@ -35,12 +35,9 module VersionsHelper
35 35 h = Hash.new {|k,v| k[v] = [0, 0]}
36 36 begin
37 37 # Total issue count
38 Issue.count(:group => criteria,
39 :conditions => ["#{Issue.table_name}.fixed_version_id = ?", version.id]).each {|c,s| h[c][0] = s}
38 Issue.where(:fixed_version_id => version.id).group(criteria).count.each {|c,s| h[c][0] = s}
40 39 # Open issues count
41 Issue.count(:group => criteria,
42 :include => :status,
43 :conditions => ["#{Issue.table_name}.fixed_version_id = ? AND #{IssueStatus.table_name}.is_closed = ?", version.id, false]).each {|c,s| h[c][1] = s}
40 Issue.open.where(:fixed_version_id => version.id).group(criteria).count.each {|c,s| h[c][1] = s}
44 41 rescue ActiveRecord::RecordNotFound
45 42 # When grouping by an association, Rails throws this exception if there's no result (bug)
46 43 end
@@ -812,7 +812,7 class Issue < ActiveRecord::Base
812 812 # Preloads relations for a collection of issues
813 813 def self.load_relations(issues)
814 814 if issues.any?
815 relations = IssueRelation.all(:conditions => ["issue_from_id IN (:ids) OR issue_to_id IN (:ids)", {:ids => issues.map(&:id)}])
815 relations = IssueRelation.where("issue_from_id IN (:ids) OR issue_to_id IN (:ids)", :ids => issues.map(&:id)).all
816 816 issues.each do |issue|
817 817 issue.instance_variable_set "@relations", relations.select {|r| r.issue_from_id == issue.id || r.issue_to_id == issue.id}
818 818 end
@@ -822,7 +822,7 class Issue < ActiveRecord::Base
822 822 # Preloads visible spent time for a collection of issues
823 823 def self.load_visible_spent_hours(issues, user=User.current)
824 824 if issues.any?
825 hours_by_issue_id = TimeEntry.visible(user).sum(:hours, :group => :issue_id)
825 hours_by_issue_id = TimeEntry.visible(user).group(:issue_id).sum(:hours)
826 826 issues.each do |issue|
827 827 issue.instance_variable_set "@spent_hours", (hours_by_issue_id[issue.id] || 0)
828 828 end
@@ -850,7 +850,7 class Issue < ActiveRecord::Base
850 850
851 851 # Finds an issue relation given its id.
852 852 def find_relation(relation_id)
853 IssueRelation.find(relation_id, :conditions => ["issue_to_id = ? OR issue_from_id = ?", id, id])
853 IssueRelation.where("issue_to_id = ? OR issue_from_id = ?", id, id).find(relation_id)
854 854 end
855 855
856 856 # Returns all the other issues that depend on the issue
@@ -1350,12 +1350,11 class Issue < ActiveRecord::Base
1350 1350 def self.update_versions(conditions=nil)
1351 1351 # Only need to update issues with a fixed_version from
1352 1352 # a different project and that is not systemwide shared
1353 Issue.scoped(:conditions => conditions).all(
1354 :conditions => "#{Issue.table_name}.fixed_version_id IS NOT NULL" +
1353 Issue.includes(:project, :fixed_version).
1354 where("#{Issue.table_name}.fixed_version_id IS NOT NULL" +
1355 1355 " AND #{Issue.table_name}.project_id <> #{Version.table_name}.project_id" +
1356 " AND #{Version.table_name}.sharing <> 'system'",
1357 :include => [:project, :fixed_version]
1358 ).each do |issue|
1356 " AND #{Version.table_name}.sharing <> 'system'").
1357 where(conditions).each do |issue|
1359 1358 next if issue.project.nil? || issue.fixed_version.nil?
1360 1359 unless issue.project.shared_versions.include?(issue.fixed_version)
1361 1360 issue.init_journal(User.current)
@@ -226,7 +226,7 class IssueQuery < Query
226 226
227 227 # Returns the issue count
228 228 def issue_count
229 Issue.visible.count(:include => [:status, :project], :conditions => statement)
229 Issue.visible.joins(:status, :project).where(statement).count
230 230 rescue ::ActiveRecord::StatementInvalid => e
231 231 raise StatementInvalid.new(e.message)
232 232 end
@@ -237,7 +237,12 class IssueQuery < Query
237 237 if grouped?
238 238 begin
239 239 # Rails3 will raise an (unexpected) RecordNotFound if there's only a nil group value
240 r = Issue.visible.count(:joins => joins_for_order_statement(group_by_statement), :group => group_by_statement, :include => [:status, :project], :conditions => statement)
240 r = Issue.visible.
241 joins(:status, :project).
242 where(statement).
243 joins(joins_for_order_statement(group_by_statement)).
244 group(group_by_statement).
245 count
241 246 rescue ActiveRecord::RecordNotFound
242 247 r = {nil => issue_count}
243 248 end
@@ -256,14 +261,16 class IssueQuery < Query
256 261 def issues(options={})
257 262 order_option = [group_by_sort_order, options[:order]].flatten.reject(&:blank?)
258 263
259 issues = Issue.visible.where(options[:conditions]).all(
260 :include => ([:status, :project] + (options[:include] || [])).uniq,
261 :conditions => statement,
262 :order => order_option,
263 :joins => joins_for_order_statement(order_option.join(',')),
264 :limit => options[:limit],
265 :offset => options[:offset]
266 )
264 issues = Issue.visible.
265 joins(:status, :project).
266 where(statement).
267 includes(([:status, :project] + (options[:include] || [])).uniq).
268 where(options[:conditions]).
269 order(order_option).
270 joins(joins_for_order_statement(order_option.join(','))).
271 limit(options[:limit]).
272 offset(options[:offset]).
273 all
267 274
268 275 if has_column?(:spent_hours)
269 276 Issue.load_visible_spent_hours(issues)
@@ -280,12 +287,16 class IssueQuery < Query
280 287 def issue_ids(options={})
281 288 order_option = [group_by_sort_order, options[:order]].flatten.reject(&:blank?)
282 289
283 Issue.visible.scoped(:conditions => options[:conditions]).scoped(:include => ([:status, :project] + (options[:include] || [])).uniq,
284 :conditions => statement,
285 :order => order_option,
286 :joins => joins_for_order_statement(order_option.join(',')),
287 :limit => options[:limit],
288 :offset => options[:offset]).find_ids
290 Issue.visible.
291 joins(:status, :project).
292 where(statement).
293 includes(([:status, :project] + (options[:include] || [])).uniq).
294 where(options[:conditions]).
295 order(order_option).
296 joins(joins_for_order_statement(order_option.join(','))).
297 limit(options[:limit]).
298 offset(options[:offset]).
299 find_ids
289 300 rescue ::ActiveRecord::StatementInvalid => e
290 301 raise StatementInvalid.new(e.message)
291 302 end
@@ -293,13 +304,14 class IssueQuery < Query
293 304 # Returns the journals
294 305 # Valid options are :order, :offset, :limit
295 306 def journals(options={})
296 Journal.visible.all(
297 :include => [:details, :user, {:issue => [:project, :author, :tracker, :status]}],
298 :conditions => statement,
299 :order => options[:order],
300 :limit => options[:limit],
301 :offset => options[:offset]
302 )
307 Journal.visible.
308 joins(:issue => [:project, :status]).
309 where(statement).
310 order(options[:order]).
311 limit(options[:limit]).
312 offset(options[:offset]).
313 preload(:details, :user, {:issue => [:project, :author, :tracker, :status]}).
314 all
303 315 rescue ::ActiveRecord::StatementInvalid => e
304 316 raise StatementInvalid.new(e.message)
305 317 end
@@ -307,10 +319,11 class IssueQuery < Query
307 319 # Returns the versions
308 320 # Valid options are :conditions
309 321 def versions(options={})
310 Version.visible.where(options[:conditions]).all(
311 :include => :project,
312 :conditions => project_statement
313 )
322 Version.visible.
323 where(project_statement).
324 where(options[:conditions]).
325 includes(:project).
326 all
314 327 rescue ::ActiveRecord::StatementInvalid => e
315 328 raise StatementInvalid.new(e.message)
316 329 end
@@ -249,19 +249,18 class Repository < ActiveRecord::Base
249 249 # Default behaviour is to search in cached changesets
250 250 def latest_changesets(path, rev, limit=10)
251 251 if path.blank?
252 changesets.find(
253 :all,
254 :include => :user,
255 :order => "#{Changeset.table_name}.committed_on DESC, #{Changeset.table_name}.id DESC",
256 :limit => limit)
252 changesets.
253 reorder("#{Changeset.table_name}.committed_on DESC, #{Changeset.table_name}.id DESC").
254 limit(limit).
255 preload(:user).
256 all
257 257 else
258 filechanges.find(
259 :all,
260 :include => {:changeset => :user},
261 :conditions => ["path = ?", path.with_leading_slash],
262 :order => "#{Changeset.table_name}.committed_on DESC, #{Changeset.table_name}.id DESC",
263 :limit => limit
264 ).collect(&:changeset)
258 filechanges.
259 where("path = ?", path.with_leading_slash).
260 reorder("#{Changeset.table_name}.committed_on DESC, #{Changeset.table_name}.id DESC").
261 limit(limit).
262 preload(:changeset => :user).
263 collect(&:changeset)
265 264 end
266 265 end
267 266
@@ -393,7 +392,7 class Repository < ActiveRecord::Base
393 392 end
394 393
395 394 def set_as_default?
396 new_record? && project && !Repository.first(:conditions => {:project_id => project.id})
395 new_record? && project && Repository.where(:project_id => project.id).empty?
397 396 end
398 397
399 398 protected
@@ -68,15 +68,11 class Repository::Bazaar < Repository
68 68 full_path = File.join(root_url, e.path)
69 69 e.size = File.stat(full_path).size if File.file?(full_path)
70 70 end
71 c = Change.find(
72 :first,
73 :include => :changeset,
74 :conditions => [
75 "#{Change.table_name}.revision = ? and #{Changeset.table_name}.repository_id = ?",
76 e.lastrev.revision,
77 id
78 ],
79 :order => "#{Changeset.table_name}.revision DESC")
71 c = Change.
72 includes(:changeset).
73 where("#{Change.table_name}.revision = ? and #{Changeset.table_name}.repository_id = ?", e.lastrev.revision, id).
74 order("#{Changeset.table_name}.revision DESC").
75 first
80 76 if c
81 77 e.lastrev.identifier = c.changeset.revision
82 78 e.lastrev.name = c.changeset.revision
@@ -143,14 +143,11 class Repository::Cvs < Repository
143 143 )
144 144 cmt = Changeset.normalize_comments(revision.message, repo_log_encoding)
145 145 author_utf8 = Changeset.to_utf8(revision.author, repo_log_encoding)
146 cs = changesets.find(
147 :first,
148 :conditions => {
149 :committed_on => tmp_time - time_delta .. tmp_time + time_delta,
150 :committer => author_utf8,
151 :comments => cmt
152 }
153 )
146 cs = changesets.where(
147 :committed_on => tmp_time - time_delta .. tmp_time + time_delta,
148 :committer => author_utf8,
149 :comments => cmt
150 ).first
154 151 # create a new changeset....
155 152 unless cs
156 153 # we use a temporaray revision number here (just for inserting)
@@ -185,10 +182,10 class Repository::Cvs < Repository
185 182 end
186 183
187 184 # Renumber new changesets in chronological order
188 Changeset.all(
189 :order => 'committed_on ASC, id ASC',
190 :conditions => ["repository_id = ? AND revision LIKE 'tmp%'", id]
191 ).each do |changeset|
185 Changeset.
186 order('committed_on ASC, id ASC').
187 where("repository_id = ? AND revision LIKE 'tmp%'", id).
188 each do |changeset|
192 189 changeset.update_attribute :revision, next_revision_number
193 190 end
194 191 end # transaction
@@ -191,13 +191,8 class Repository::Git < Repository
191 191 offset = 0
192 192 revisions_copy = revisions.clone # revisions will change
193 193 while offset < revisions_copy.size
194 recent_changesets_slice = changesets.find(
195 :all,
196 :conditions => [
197 'scmid IN (?)',
198 revisions_copy.slice(offset, limit).map{|x| x.scmid}
199 ]
200 )
194 scmids = revisions_copy.slice(offset, limit).map{|x| x.scmid}
195 recent_changesets_slice = changesets.where(:scmid => scmids).all
201 196 # Subtract revisions that redmine already knows about
202 197 recent_revisions = recent_changesets_slice.map{|c| c.scmid}
203 198 revisions.reject!{|r| recent_revisions.include?(r.scmid)}
@@ -246,13 +241,7 class Repository::Git < Repository
246 241 revisions = scm.revisions(path, nil, rev, :limit => limit, :all => false)
247 242 return [] if revisions.nil? || revisions.empty?
248 243
249 changesets.find(
250 :all,
251 :conditions => [
252 "scmid IN (?)",
253 revisions.map!{|c| c.scmid}
254 ]
255 )
244 changesets.where(:scmid => revisions.map {|c| c.scmid}).all
256 245 end
257 246
258 247 def clear_extra_info_of_changesets
@@ -50,10 +50,10 class Wiki < ActiveRecord::Base
50 50 @page_found_with_redirect = false
51 51 title = start_page if title.blank?
52 52 title = Wiki.titleize(title)
53 page = pages.first(:conditions => ["LOWER(title) = LOWER(?)", title])
53 page = pages.where("LOWER(title) = LOWER(?)", title).first
54 54 if !page && !(options[:with_redirect] == false)
55 55 # search for a redirect
56 redirect = redirects.first(:conditions => ["LOWER(title) = LOWER(?)", title])
56 redirect = redirects.where("LOWER(title) = LOWER(?)", title).first
57 57 if redirect
58 58 page = find_page(redirect.redirects_to, :with_redirect => false)
59 59 @page_found_with_redirect = true
@@ -40,7 +40,7
40 40 :from => @events_by_day.keys.first %></h3>
41 41
42 42 <p>
43 <%=l(:label_reported_issues)%>: <%= Issue.count(:conditions => ["author_id=?", @user.id]) %>
43 <%=l(:label_reported_issues)%>: <%= Issue.where(:author_id => @user.id).count %>
44 44 </p>
45 45
46 46 <div id="activity">
@@ -162,11 +162,12 module Redmine
162 162 ids = issues.collect(&:project).uniq.collect(&:id)
163 163 if ids.any?
164 164 # All issues projects and their visible ancestors
165 @projects = Project.visible.all(
166 :joins => "LEFT JOIN #{Project.table_name} child ON #{Project.table_name}.lft <= child.lft AND #{Project.table_name}.rgt >= child.rgt",
167 :conditions => ["child.id IN (?)", ids],
168 :order => "#{Project.table_name}.lft ASC"
169 ).uniq
165 @projects = Project.visible.
166 joins("LEFT JOIN #{Project.table_name} child ON #{Project.table_name}.lft <= child.lft AND #{Project.table_name}.rgt >= child.rgt").
167 where("child.id IN (?)", ids).
168 order("#{Project.table_name}.lft ASC").
169 uniq.
170 all
170 171 else
171 172 @projects = []
172 173 end
@@ -153,7 +153,7 class CustomFieldsControllerTest < ActionController::TestCase
153 153 end
154 154
155 155 def test_destroy
156 custom_values_count = CustomValue.count(:conditions => {:custom_field_id => 1})
156 custom_values_count = CustomValue.where(:custom_field_id => 1).count
157 157 assert custom_values_count > 0
158 158
159 159 assert_difference 'CustomField.count', -1 do
@@ -3701,7 +3701,7 class IssuesControllerTest < ActionController::TestCase
3701 3701
3702 3702 def test_bulk_copy_should_allow_changing_the_issue_attributes
3703 3703 # Fixes random test failure with Mysql
3704 # where Issue.all(:limit => 2, :order => 'id desc', :conditions => {:project_id => 2})
3704 # where Issue.where(:project_id => 2).limit(2).order('id desc')
3705 3705 # doesn't return the expected results
3706 3706 Issue.delete_all("project_id=2")
3707 3707
@@ -3716,7 +3716,7 class IssuesControllerTest < ActionController::TestCase
3716 3716 end
3717 3717 end
3718 3718
3719 copied_issues = Issue.all(:limit => 2, :order => 'id desc', :conditions => {:project_id => 2})
3719 copied_issues = Issue.where(:project_id => 2).limit(2).order('id desc').to_a
3720 3720 assert_equal 2, copied_issues.size
3721 3721 copied_issues.each do |issue|
3722 3722 assert_equal 2, issue.project_id, "Project is incorrect"
@@ -51,7 +51,7 class ProjectsControllerTest < ActionController::TestCase
51 51 assert_response :success
52 52 assert_template 'common/feed'
53 53 assert_select 'feed>title', :text => 'Redmine: Latest projects'
54 assert_select 'feed>entry', :count => Project.count(:conditions => Project.visible_condition(User.current))
54 assert_select 'feed>entry', :count => Project.visible(User.current).count
55 55 end
56 56
57 57 test "#index by non-admin user with view_time_entries permission should show overall spent time link" do
@@ -280,7 +280,7 class RepositoriesControllerTest < ActionController::TestCase
280 280 :revision => 100,
281 281 :comments => 'Committed by foo.'
282 282 )
283 assert_no_difference "Changeset.count(:conditions => 'user_id = 3')" do
283 assert_no_difference "Changeset.where(:user_id => 3).count" do
284 284 post :committers, :id => 10, :committers => { '0' => ['foo', '2'], '1' => ['dlopper', '3']}
285 285 assert_response 302
286 286 assert_equal User.find(2), c.reload.user
@@ -30,7 +30,7 class WorkflowsControllerTest < ActionController::TestCase
30 30 assert_response :success
31 31 assert_template 'index'
32 32
33 count = WorkflowTransition.count(:all, :conditions => 'role_id = 1 AND tracker_id = 2')
33 count = WorkflowTransition.where(:role_id => 1, :tracker_id => 2).count
34 34 assert_tag :tag => 'a', :content => count.to_s,
35 35 :attributes => { :href => '/workflows/edit?role_id=1&amp;tracker_id=2' }
36 36 end
@@ -125,10 +125,10 class WorkflowsControllerTest < ActionController::TestCase
125 125 end
126 126
127 127 def test_clear_workflow
128 assert WorkflowTransition.count(:conditions => {:tracker_id => 1, :role_id => 2}) > 0
128 assert WorkflowTransition.where(:role_id => 1, :tracker_id => 2).count > 0
129 129
130 post :edit, :role_id => 2, :tracker_id => 1
131 assert_equal 0, WorkflowTransition.count(:conditions => {:tracker_id => 1, :role_id => 2})
130 post :edit, :role_id => 1, :tracker_id => 2
131 assert_equal 0, WorkflowTransition.where(:role_id => 1, :tracker_id => 2).count
132 132 end
133 133
134 134 def test_get_permissions
@@ -95,11 +95,11 class Redmine::ApiTest::IssueCategoriesTest < Redmine::ApiTest::Base
95 95 end
96 96
97 97 test "DELETE /issue_categories/:id.xml should reassign issues with :reassign_to_id param" do
98 issue_count = Issue.count(:conditions => {:category_id => 1})
98 issue_count = Issue.where(:category_id => 1).count
99 99 assert issue_count > 0
100 100
101 101 assert_difference 'IssueCategory.count', -1 do
102 assert_difference 'Issue.count(:conditions => {:category_id => 2})', 3 do
102 assert_difference 'Issue.where(:category_id => 2).count', 3 do
103 103 delete '/issue_categories/1.xml', {:reassign_to_id => 2}, credentials('jsmith')
104 104 end
105 105 end
@@ -138,9 +138,9 class Redmine::ApiTest::IssuesTest < Redmine::ApiTest::Base
138 138 get '/issues.xml',
139 139 {:set_filter => 1, :f => ['cf_1'], :op => {:cf_1 => '='},
140 140 :v => {:cf_1 => ['MySQL']}}
141 expected_ids = Issue.visible.all(
142 :include => :custom_values,
143 :conditions => {:custom_values => {:custom_field_id => 1, :value => 'MySQL'}}).map(&:id)
141 expected_ids = Issue.visible.
142 joins(:custom_values).
143 where(:custom_values => {:custom_field_id => 1, :value => 'MySQL'}).map(&:id)
144 144 assert_select 'issues > issue > id', :count => expected_ids.count do |ids|
145 145 ids.each { |id| assert expected_ids.delete(id.children.first.content.to_i) }
146 146 end
@@ -151,9 +151,9 class Redmine::ApiTest::IssuesTest < Redmine::ApiTest::Base
151 151 should "show only issues with the custom field value" do
152 152 get '/issues.xml', { :cf_1 => 'MySQL' }
153 153
154 expected_ids = Issue.visible.all(
155 :include => :custom_values,
156 :conditions => {:custom_values => {:custom_field_id => 1, :value => 'MySQL'}}).map(&:id)
154 expected_ids = Issue.visible.
155 joins(:custom_values).
156 where(:custom_values => {:custom_field_id => 1, :value => 'MySQL'}).map(&:id)
157 157
158 158 assert_select 'issues > issue > id', :count => expected_ids.count do |ids|
159 159 ids.each { |id| assert expected_ids.delete(id.children.first.content.to_i) }
@@ -170,7 +170,7 class Redmine::ApiTest::IssuesTest < Redmine::ApiTest::Base
170 170 should "show only issues with the status_id" do
171 171 get '/issues.xml?status_id=5'
172 172
173 expected_ids = Issue.visible.all(:conditions => {:status_id => 5}).map(&:id)
173 expected_ids = Issue.visible.where(:status_id => 5).map(&:id)
174 174
175 175 assert_select 'issues > issue > id', :count => expected_ids.count do |ids|
176 176 ids.each { |id| assert expected_ids.delete(id.children.first.content.to_i) }
@@ -112,7 +112,7 class ActiveSupport::TestCase
112 112 end
113 113
114 114 def change_user_password(login, new_password)
115 user = User.first(:conditions => {:login => login})
115 user = User.where(:login => login).first
116 116 user.password, user.password_confirmation = new_password, new_password
117 117 user.save!
118 118 end
@@ -100,7 +100,7 class BoardTest < ActiveSupport::TestCase
100 100 end
101 101 end
102 102 end
103 assert_equal 0, Message.count(:conditions => {:board_id => 1})
103 assert_equal 0, Message.where(:board_id => 1).count
104 104 end
105 105
106 106 def test_destroy_should_nullify_children
@@ -30,8 +30,7 class ChangesetTest < ActiveSupport::TestCase
30 30
31 31 def test_ref_keywords_any
32 32 ActionMailer::Base.deliveries.clear
33 Setting.commit_fix_status_id = IssueStatus.find(
34 :first, :conditions => ["is_closed = ?", true]).id
33 Setting.commit_fix_status_id = IssueStatus.where(:is_closed => true).first.id
35 34 Setting.commit_fix_done_ratio = '90'
36 35 Setting.commit_ref_keywords = '*'
37 36 Setting.commit_fix_keywords = 'fixes , closes'
@@ -113,8 +112,7 class ChangesetTest < ActiveSupport::TestCase
113 112 end
114 113
115 114 def test_ref_keywords_closing_with_timelog
116 Setting.commit_fix_status_id = IssueStatus.find(
117 :first, :conditions => ["is_closed = ?", true]).id
115 Setting.commit_fix_status_id = IssueStatus.where(:is_closed => true).first.id
118 116 Setting.commit_ref_keywords = '*'
119 117 Setting.commit_fix_keywords = 'fixes , closes'
120 118 Setting.commit_logtime_enabled = '1'
@@ -36,8 +36,8 class IssueStatusTest < ActiveSupport::TestCase
36 36 assert_difference 'IssueStatus.count', -1 do
37 37 assert status.destroy
38 38 end
39 assert_nil WorkflowTransition.first(:conditions => {:old_status_id => status.id})
40 assert_nil WorkflowTransition.first(:conditions => {:new_status_id => status.id})
39 assert_nil WorkflowTransition.where(:old_status_id => status.id).first
40 assert_nil WorkflowTransition.where(:new_status_id => status.id).first
41 41 end
42 42
43 43 def test_destroy_status_in_use
@@ -98,7 +98,7 class IssueStatusTest < ActiveSupport::TestCase
98 98
99 99 with_settings :issue_done_ratio => 'issue_field' do
100 100 IssueStatus.update_issue_done_ratios
101 assert_equal 0, Issue.count(:conditions => {:done_ratio => 50})
101 assert_equal 0, Issue.where(:done_ratio => 50).count
102 102 end
103 103 end
104 104
@@ -107,7 +107,7 class IssueStatusTest < ActiveSupport::TestCase
107 107
108 108 with_settings :issue_done_ratio => 'issue_status' do
109 109 IssueStatus.update_issue_done_ratios
110 issues = Issue.all(:conditions => {:status_id => 1})
110 issues = Issue.where(:status_id => 1).all
111 111 assert_equal [50], issues.map {|issue| issue.read_attribute(:done_ratio)}.uniq
112 112 end
113 113 end
@@ -63,7 +63,7 class ProjectCopyTest < ActiveSupport::TestCase
63 63 assert_equal @project, issue.project
64 64 end
65 65
66 copied_issue = @project.issues.first(:conditions => {:subject => "copy issue status"})
66 copied_issue = @project.issues.where(:subject => "copy issue status").first
67 67 assert copied_issue
68 68 assert copied_issue.status
69 69 assert_equal "Closed", copied_issue.status.name
@@ -93,7 +93,7 class ProjectCopyTest < ActiveSupport::TestCase
93 93
94 94 assert @project.copy(@source_project)
95 95 @project.reload
96 copied_issue = @project.issues.first(:conditions => {:subject => "copy issues assigned to a locked version"})
96 copied_issue = @project.issues.where(:subject => "copy issues assigned to a locked version").first
97 97
98 98 assert copied_issue
99 99 assert copied_issue.fixed_version
@@ -112,7 +112,7 class ProjectCopyTest < ActiveSupport::TestCase
112 112
113 113 assert @project.copy(@source_project)
114 114 @project.reload
115 copied_issue = @project.issues.first(:conditions => {:subject => "change the new issues to use the copied version"})
115 copied_issue = @project.issues.where(:subject => "change the new issues to use the copied version").first
116 116
117 117 assert copied_issue
118 118 assert copied_issue.fixed_version
@@ -128,7 +128,7 class ProjectCopyTest < ActiveSupport::TestCase
128 128
129 129 assert @project.copy(@source_project)
130 130 @project.reload
131 copied_issue = @project.issues.first(:conditions => {:subject => "keep target shared versions"})
131 copied_issue = @project.issues.where(:subject => "keep target shared versions").first
132 132
133 133 assert copied_issue
134 134 assert_equal assigned_version, copied_issue.fixed_version
@@ -175,7 +175,7 class ProjectCopyTest < ActiveSupport::TestCase
175 175 @source_project.issues << issue
176 176 assert @project.copy(@source_project)
177 177
178 copied_issue = @project.issues.first(:conditions => {:subject => "copy with attachment"})
178 copied_issue = @project.issues.where(:subject => "copy with attachment").first
179 179 assert_not_nil copied_issue
180 180 assert_equal 1, copied_issue.attachments.count, "Attachment not copied"
181 181 assert_equal "testfile.txt", copied_issue.attachments.first.filename
@@ -175,7 +175,7 class ProjectTest < ActiveSupport::TestCase
175 175 # Assign an issue of a project to a version of a child project
176 176 Issue.find(4).update_attribute :fixed_version_id, 4
177 177
178 assert_no_difference "Project.count(:all, :conditions => 'status = #{Project::STATUS_ARCHIVED}')" do
178 assert_no_difference "Project.where(:status => Project::STATUS_ARCHIVED).count" do
179 179 assert_equal false, @ecookbook.archive
180 180 end
181 181 @ecookbook.reload
@@ -211,9 +211,9 class ProjectTest < ActiveSupport::TestCase
211 211 # make sure that the project non longer exists
212 212 assert_raise(ActiveRecord::RecordNotFound) { Project.find(@ecookbook.id) }
213 213 # make sure related data was removed
214 assert_nil Member.first(:conditions => {:project_id => @ecookbook.id})
215 assert_nil Board.first(:conditions => {:project_id => @ecookbook.id})
216 assert_nil Issue.first(:conditions => {:project_id => @ecookbook.id})
214 assert_nil Member.where(:project_id => @ecookbook.id).first
215 assert_nil Board.where(:project_id => @ecookbook.id).first
216 assert_nil Issue.where(:project_id => @ecookbook.id).first
217 217 end
218 218
219 219 def test_destroy_should_destroy_subtasks
@@ -246,7 +246,7 class ProjectTest < ActiveSupport::TestCase
246 246 assert_equal 0, Board.count
247 247 assert_equal 0, Message.count
248 248 assert_equal 0, News.count
249 assert_equal 0, Query.count(:conditions => "project_id IS NOT NULL")
249 assert_equal 0, Query.where("project_id IS NOT NULL").count
250 250 assert_equal 0, Repository.count
251 251 assert_equal 0, Changeset.count
252 252 assert_equal 0, Change.count
@@ -260,7 +260,7 class ProjectTest < ActiveSupport::TestCase
260 260 assert_equal 0, WikiContent::Version.count
261 261 assert_equal 0, Project.connection.select_all("SELECT * FROM projects_trackers").size
262 262 assert_equal 0, Project.connection.select_all("SELECT * FROM custom_fields_projects").size
263 assert_equal 0, CustomValue.count(:conditions => {:customized_type => ['Project', 'Issue', 'TimeEntry', 'Version']})
263 assert_equal 0, CustomValue.where(:customized_type => ['Project', 'Issue', 'TimeEntry', 'Version']).count
264 264 end
265 265
266 266 def test_move_an_orphan_project_to_a_root_project
@@ -586,7 +586,7 class QueryTest < ActiveSupport::TestCase
586 586
587 587 query = IssueQuery.new(:name => '_', :filters => { 'assigned_to_id' => {:operator => '=', :values => ['me']}})
588 588 result = query.issues
589 assert_equal Issue.visible.all(:conditions => {:assigned_to_id => ([2] + user.reload.group_ids)}).sort_by(&:id), result.sort_by(&:id)
589 assert_equal Issue.visible.where(:assigned_to_id => ([2] + user.reload.group_ids)).sort_by(&:id), result.sort_by(&:id)
590 590
591 591 assert result.include?(i1)
592 592 assert result.include?(i2)
@@ -183,9 +183,7 class RepositoryTest < ActiveSupport::TestCase
183 183 Setting.default_language = 'en'
184 184
185 185 # choosing a status to apply to fix issues
186 Setting.commit_fix_status_id = IssueStatus.find(
187 :first,
188 :conditions => ["is_closed = ?", true]).id
186 Setting.commit_fix_status_id = IssueStatus.where(:is_closed => true).first.id
189 187 Setting.commit_fix_done_ratio = "90"
190 188 Setting.commit_ref_keywords = 'refs , references, IssueID'
191 189 Setting.commit_fix_keywords = 'fixes , closes'
@@ -278,7 +276,7 class RepositoryTest < ActiveSupport::TestCase
278 276 end
279 277
280 278 def test_manual_user_mapping
281 assert_no_difference "Changeset.count(:conditions => 'user_id <> 2')" do
279 assert_no_difference "Changeset.where('user_id <> 2').count" do
282 280 c = Changeset.create!(
283 281 :repository => @repository,
284 282 :committer => 'foo',
@@ -128,7 +128,7 class SearchTest < ActiveSupport::TestCase
128 128
129 129 def test_search_issue_with_multiple_hits_in_journals
130 130 i = Issue.find(1)
131 assert_equal 2, i.journals.count(:all, :conditions => "notes LIKE '%notes%'")
131 assert_equal 2, i.journals.where("notes LIKE '%notes%'").count
132 132
133 133 r = Issue.search('%notes%').first
134 134 assert_equal 1, r.size
@@ -40,7 +40,7 class UserTest < ActiveSupport::TestCase
40 40 def test_generate
41 41 User.generate!(:firstname => 'Testing connection')
42 42 User.generate!(:firstname => 'Testing connection')
43 assert_equal 2, User.count(:all, :conditions => {:firstname => 'Testing connection'})
43 assert_equal 2, User.where(:firstname => 'Testing connection').count
44 44 end
45 45
46 46 def test_truth
@@ -30,9 +30,9 class WorkflowTest < ActiveSupport::TestCase
30 30 WorkflowTransition.copy(Tracker.find(2), Role.find(1), Tracker.find(3), Role.find(2))
31 31 end
32 32
33 assert WorkflowTransition.first(:conditions => {:role_id => 2, :tracker_id => 3, :old_status_id => 1, :new_status_id => 2, :author => false, :assignee => false})
34 assert WorkflowTransition.first(:conditions => {:role_id => 2, :tracker_id => 3, :old_status_id => 1, :new_status_id => 3, :author => false, :assignee => true})
35 assert WorkflowTransition.first(:conditions => {:role_id => 2, :tracker_id => 3, :old_status_id => 1, :new_status_id => 4, :author => true, :assignee => false})
33 assert WorkflowTransition.where(:role_id => 2, :tracker_id => 3, :old_status_id => 1, :new_status_id => 2, :author => false, :assignee => false).first
34 assert WorkflowTransition.where(:role_id => 2, :tracker_id => 3, :old_status_id => 1, :new_status_id => 3, :author => false, :assignee => true).first
35 assert WorkflowTransition.where(:role_id => 2, :tracker_id => 3, :old_status_id => 1, :new_status_id => 4, :author => true, :assignee => false).first
36 36 end
37 37
38 38 def test_workflow_permission_should_validate_rule
General Comments 0
You need to be logged in to leave comments. Login now