From 8fb1a7e3ccc7b501704a7873b328c1b976554cab Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Mon, 13 Aug 2012 14:23:33 +0000 Subject: [PATCH] Fixed that open scope on Project#issues raises an error (#11545). Patch by Petr Pospisil. git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@10199 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/models/issue.rb | 1 - app/models/version.rb | 1 - config/initializers/10-patches.rb | 5 +++++ test/unit/project_test.rb | 4 ++++ 4 files changed, 9 insertions(+), 2 deletions(-) diff --git a/app/models/issue.rb b/app/models/issue.rb index 97c97e910..7807d2859 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -64,7 +64,6 @@ class Issue < ActiveRecord::Base lambda {|*args| { :include => :project, :conditions => Issue.visible_condition(args.shift || User.current, *args) } } - class << self; undef :open; end scope :open, lambda {|*args| is_closed = args.size > 0 ? !args.first : false {:conditions => ["#{IssueStatus.table_name}.is_closed = ?", is_closed], :include => :status} diff --git a/app/models/version.rb b/app/models/version.rb index 49b91b87f..cd32da91e 100644 --- a/app/models/version.rb +++ b/app/models/version.rb @@ -35,7 +35,6 @@ class Version < ActiveRecord::Base validates_inclusion_of :sharing, :in => VERSION_SHARINGS scope :named, lambda {|arg| { :conditions => ["LOWER(#{table_name}.name) = LOWER(?)", arg.to_s.strip]}} - class << self; undef :open; end scope :open, :conditions => {:status => 'open'} scope :visible, lambda {|*args| { :include => :project, :conditions => Project.allowed_to_condition(args.first || User.current, :view_issues) } } diff --git a/config/initializers/10-patches.rb b/config/initializers/10-patches.rb index 672f1c0a0..e4a110cfa 100644 --- a/config/initializers/10-patches.rb +++ b/config/initializers/10-patches.rb @@ -10,6 +10,11 @@ module ActiveRecord l("field_#{name.underscore.gsub('/', '_')}_#{attr}", :default => ["field_#{attr}".to_sym, attr]) end end + + # Undefines private Kernel#open method to allow using `open` scopes in models. + # See Defect #11545 (http://www.redmine.org/issues/11545) for details. + class Base ; undef open ; end + class Relation ; undef open ; end end module ActionView diff --git a/test/unit/project_test.rb b/test/unit/project_test.rb index 64a2631ea..3abfbe327 100644 --- a/test/unit/project_test.rb +++ b/test/unit/project_test.rb @@ -132,6 +132,10 @@ class ProjectTest < ActiveSupport::TestCase end end + def test_open_scope_on_issues_association + assert_kind_of Issue, Project.find(1).issues.open.first + end + def test_archive user = @ecookbook.members.first.user @ecookbook.archive