Hi,
[reposting to list, posting via google groups apparently didn’t work]
I’m trying to use acts_as_list for the first time.
Can anyone confirm the odd behaviour reported here?
Nominet - The Official Registry for UK Domain Names…
i.e. element access and move_higher require an odd indexing scheme to
work.
I’m personally finding that I can’t seem to change the list element
positioning in a rails unit test using move_higher/move_lower, although
move_to_top works. (See code following below)
Cheers,
N
model defs
class AccountTransaction < ActiveRecord::Base
has_many :credits, :foreign_key => ‘transaction_id’, :order =>
‘position ASC’
end
class Credit < ActiveRecord::Base
belongs_to :account_transaction, :foreign_key => ‘transaction_id’
belongs_to :account
acts_as_list :scope => :transaction_id
belongs_to :credit_type
end
#unit test
class AccountTransactionTest < Test::Unit::TestCase
fixtures :account_transactions, :credits
def display_credits(transaction)
transaction.credits.each_index do |x|
credit = transaction.credits[x]
puts " index #{x} id #{credit.id} position #{credit.position}"
end
end
def test_credits
assert_equal @account_transaction.credits[0].id, @first_credit.id
assert_equal @account_transaction.credits[1].id, @second_credit.id
display_credits @account_transaction
@account_transaction.credits[1].move_higher # doesn't work
@account_transaction.reload
display_credits @account_transaction
@account_transaction.credits[1].move_to_top # does work
@account_transaction.reload
display_credits @account_transaction
assert_equal @account_transaction.credits[1].id, @first_credit.id
assert_equal @account_transaction.credits[0].id, @second_credit.id
end
end
outputs:
Loaded suite test/unit/account_transaction_test
Started
index 0 id 1 position 1
index 1 id 2 position 8
index 0 id 1 position 1
index 1 id 2 position 8
index 0 id 2 position 1
index 1 id 1 position 2
…
Finished in 0.188056 seconds.
credits.yml
first_credit:
id: 1
transaction_id: 1
position: 1
account_id: 1
amount: 11
credit_type_id: 1
second_credit:
id: 2
transaction_id: 1
position: 8
account_id: 1
amount: 18
credit_type_id: 1
account_transactions.yml
first_account_transaction:
id: 1
date: 23/01/2005
description: blah
comments: blah
another_account_transaction:
id: 2
date: 23/07/2005
description: blah
comments: blah