> bit outta the loop on patching these days, but this makes the tests
> run again and supports multiple (array of names) based scoping for
> acts_as_list

Do you have this in a git repository somewhere?  Looks good to me but
a git repostiory or git-format-patch file would make it way easier to
apply.

> cfp:~/src/git/acts_as_list > ruby test/list_test.rb |tail
> .-- create_table(:mixins)
>    -> 0.0006s
> -- initialize_schema_migrations_table()
>    -> 0.0005s
> -- assume_migrated_upto_version(1)
>    -> 0.0002s
> .
> Finished in 0.429682 seconds.
>
> 19 tests, 103 assertions, 0 failures, 0 errors
>
>
>
>
>
>
>
>
>
> diff --git a/lib/active_record/acts/list.rb b/lib/active_record/acts/
> list.rb
> index 00d8692..a04a62b 100644
> --- a/lib/active_record/acts/list.rb
> +++ b/lib/active_record/acts/list.rb
> @@ -35,20 +35,39 @@ module ActiveRecord
>            configuration.update(options) if options.is_a?(Hash)
>
>            configuration[:scope] =
> "#{configuration[:scope]}_id".intern if configuration[:scope].is_a?
> (Symbol) && configuration[:scope].to_s !~ /_id$/
> +          configuration[:scope].map!{|scope| (scope.to_s.sub(/_id
> $/,'') + '_id').intern} if configuration[:scope].is_a?(Array)
> +
> +          scope_condition_method =
> +            case configuration[:scope]
> +              when Symbol
> +                <<-def
> +                  def scope_condition
> +                    if #{configuration[:scope].to_s}.nil?
> +                      "#{configuration[:scope].to_s} IS NULL"
> +                    else
> +                      "#{configuration[:scope].to_s} =
> \#{#{configuration[:scope].to_s}}"
> +                    end
> +                  end
> +                def
> +
> +              when Array
> +                <<-def
> +                  def scope_condition
> +                    #{configuration[:scope].inspect}.map do |scope|
> +                      value = send(scope)
> +                      if value.nil?
> +                        "\#{scope} IS NULL"
> +                      else
> +                        "\#{scope} = \#{value.inspect}"
> +                      end
> +                    end.join(' AND ')
> +                  end
> +                def
> +
> +              else
> +                "def scope_condition() \"#{configuration[:scope]}\"
> end"
> +            end
>
> -          if configuration[:scope].is_a?(Symbol)
> -            scope_condition_method = %(
> -              def scope_condition
> -                if #{configuration[:scope].to_s}.nil?
> -                  "#{configuration[:scope].to_s} IS NULL"
> -                else
> -                  "#{configuration[:scope].to_s} =
> \#{#{configuration[:scope].to_s}}"
> -                end
> -              end
> -            )
> -          else
> -            scope_condition_method = "def scope_condition()
> \"#{configuration[:scope]}\" end"
> -          end
>
>            class_eval <<-EOV
>              include ActiveRecord::Acts::List::InstanceMethods
> diff --git a/test/list_test.rb b/test/list_test.rb
> index e89cb8e..7571b0c 100644
> --- a/test/list_test.rb
> +++ b/test/list_test.rb
> @@ -4,7 +4,13 @@ require 'rubygems'
>  gem 'activerecord', '>= 1.15.4.7794'
>  require 'active_record'
>
> -require "#{File.dirname(__FILE__)}/../init"
> +$:.unshift "#{File.dirname(__FILE__)}/../lib"
> +
> +begin
> +  require "#{File.dirname(__FILE__)}/../init"
> +rescue LoadError
> +  require "#{File.dirname(__FILE__)}/../rails/init"
> +end
>
>  ActiveRecord::Base.establish_connection(:adapter =>
> "sqlite3", :dbfile => ":memory:")
>
> @@ -13,6 +19,7 @@ def setup_db
>      create_table :mixins do |t|
>        t.column :pos, :integer
>        t.column :parent_id, :integer
> +      t.column :parent2_id, :integer
>        t.column :created_at, :datetime
>        t.column :updated_at, :datetime
>      end
> @@ -46,6 +53,13 @@ class ListWithStringScopeMixin < ActiveRecord::Base
>    def self.table_name() "mixins" end
>  end
>
> +class ListWithArrayScopeMixin < ActiveRecord::Base
> +  acts_as_list :column => "pos", :scope => [:parent_id, :parent2_id]
> +
> +  def self.table_name() "mixins" end
> +end
> +
> +
>
>  class ListTest < Test::Unit::TestCase
>
> @@ -182,6 +196,18 @@ class ListTest < Test::Unit::TestCase
>      assert new.last?
>    end
>
> +  def test_with_array_based_scope
> +    first = ListWithArrayScopeMixin.create(:parent_id =>
> 500, :parent2_id => 600)
> +    assert_equal 1, first.pos
> +    assert first.first?
> +    assert first.last?
> +
> +    last = ListWithArrayScopeMixin.create(:parent_id =>
> 500, :parent2_id => 600)
> +    assert_equal 2, last.pos
> +    assert first.first?
> +    assert last.last?
> +  end
> +
>    def test_nil_scope
>      new1, new2, new3 = ListMixin.create, ListMixin.create,
> ListMixin.create
>      new2.move_higher
>
>
>
>
>
>
> a @ http://codeforpeople.com/
> --
> we can deny everything, except that we have the possibility of being
> better. simply reflect on that.
> h.h. the 14th dalai lama
>
>
>
>
> >
>



-- 
Cheers

Koz

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Core" group.
To post to this group, send email to rubyonrails-core@googlegroups.com
To unsubscribe from this group, send email to 
rubyonrails-core+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-core?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to