]> source.dussan.org Git - redmine.git/commitdiff
Fixed that open scope on Project#issues raises an error (#11545).
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Mon, 13 Aug 2012 14:23:33 +0000 (14:23 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Mon, 13 Aug 2012 14:23:33 +0000 (14:23 +0000)
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
app/models/version.rb
config/initializers/10-patches.rb
test/unit/project_test.rb

index 97c97e910ea971b22f209e673ca56291c42005c7..7807d2859a569fd287607f0fff9cde10916cbdd7 100644 (file)
@@ -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}
index 49b91b87fcfa4873af977c46088cf4221b9eb998..cd32da91e62a90828e1fefc3b90868a14b2e2232 100644 (file)
@@ -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) } }
index 672f1c0a08545b50ed6c319a9e9eb0db813296c5..e4a110cfa644e177c7b7b0a082c18f394f55d965 100644 (file)
@@ -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
index 64a2631eaca1a8065c3a2e9404496a55220696e2..3abfbe3276c1c10aa40ff439e2ef3e82deaa2885 100644 (file)
@@ -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