Trouble with Acts_as_list::move_higher/lower

I have the model MessageBoard acts_as_list for Forum, but for some
reason, the function move_higher/lower doesn’t seem to do its job in
the test file I wrote for forum_test.rb:

def test_board_up
forum = Forum.new(:title => ‘basic’)
assert forum.valid?, “forum is invalid, expect more failures”
assert_equal forum.title, ‘basic’
board = []
#initialize three boards in this order: #1, #3, #2
#board array holds = [#1, #2, #3]
board[0] = forum.message_boards.build(:title => ‘#1’,
:description => ‘one’)
board[2] = forum.message_boards.build(:title => ‘#3’,
:description => ‘three’)
board[1] = forum.message_boards.build(:title => ‘#2’,
:description => ‘two’)
#save, just in case
forum.save

move the index #2 lower (so that it’s less than #3)

forum.message_boards[2].move_lower

and save.

forum.save
board_temp = forum.message_boards
board_temp.each{|b| puts "\ntest_board_up order #{b.title}"}
for num in 0..2
  assert_equal board_temp[num].title, board[num].title
  assert_equal board_temp[num].description, board[num].description
end
forum.destroy

end

def test_board_down
forum = Forum.new(:title => ‘basic’)
assert forum.valid?, “forum is invalid, expect more failures”
assert_equal forum.title, ‘basic’
board = []
#initialize three boards in this order: #1, #3, #2
#board array holds = [#1, #2, #3]
board[0] = forum.message_boards.build(:title => ‘#1’,
:description => ‘one’)
board[2] = forum.message_boards.build(:title => ‘#3’,
:description => ‘three’)
board[1] = forum.message_boards.build(:title => ‘#2’,
:description => ‘two’)
#save, just in case
forum.save

move the index #3 higher (so that it’s greater than #2)

forum.message_boards[1].move_higher

and save.

forum.save
board_temp = forum.message_boards
board_temp.each{|b| puts "\ntest_board_down order #{b.title}"}
for num in 0..2
  assert_equal board_temp[num].title, board[num].title
  assert_equal board_temp[num].description, board[num].description
end
forum.destroy

end

Loaded suite forum_test
Started
.
test_board_down order #1

test_board_down order #3

test_board_down order #2
F.
test_board_up order #1

test_board_up order #3

test_board_up order #2
F…
Finished in 0.615307 seconds.

  1. Failure:
    test_board_down(ForumTest)
    [forum_test.rb:152:in test_board_down' forum_test.rb:151:ineach’
    forum_test.rb:151:in `test_board_down’]:
    <"#3"> expected but was
    <"#2">.

  2. Failure:
    test_board_up(ForumTest)
    [forum_test.rb:125:in test_board_up' forum_test.rb:124:ineach’
    forum_test.rb:124:in `test_board_up’]:
    <"#3"> expected but was
    <"#2">.

10 tests, 43 assertions, 2 failures, 0 errors

While it may be possible I confused myself with the first test, and
thus, see no activity there, the second test SHOULD result in some
change. I saved object forum before calling move_higher in the middle
index, then saved again. However, according to my puts statement,
nothing seemed to have happened at all in the middle index! Why is
that?

On 9 Jan 2008, at 13:26, Taro wrote:

I have the model MessageBoard acts_as_list for Forum, but for some
reason, the function move_higher/lower doesn’t seem to do its job in
the test file I wrote for forum_test.rb:

move_higher/lower are calling update_all : you’ll need to reload
forum.message_boards to see any change.

Fred

Ahhh…I see. Yes it works, thank you!

Out of curiosity, where can I find that method in the rails framework
documentation? Being able to see the source would really help!

On Jan 9, 8:35 am, Frederick C. [email protected]

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs