# Issues with move\_higher and move\_lower

**URL:** <https://www.ruby-forum.com/t/issues-with-move-higher-and-move-lower/125278>\
**Category:** Rails\
**Created:** [January 7, 2008, 7:45pm UTC](https://www.ruby-forum.com/t/issues-with-move-higher-and-move-lower/125278 "2008-01-07T19:45:19Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![taro](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/df705f/32.png) [@taro](https://www.ruby-forum.com/u/taro)\
**Post date:** [January 7, 2008, 7:45pm UTC](https://www.ruby-forum.com/t/issues-with-move-higher-and-move-lower/125278/1 "2008-01-07T19:45:19Z")

</div>

I made sure that my MessageBoards would acts\_as\_list for Forum:

* * *

## class Forum \< ActiveRecord::Base #This is a superset of message boards has\_many :message\_boards, :order =\> ‘position’, :dependent =\> :destroy … end

class MessageBoard \< ActiveRecord::Base  
#This is a subset of forums  
belongs\_to :forum

## #This causes MessageBoard to act as a list #it uses order as its index acts\_as\_list :scope =\> :forum\_id … end

But for some reason, the unit tests file indicates several failures:

* * *

#in 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 = []  
board[0] = forum.message\_boards.build(:title =\> ‘#1’, :description  
=\> ‘one’  
)  
board[2] = forum.message\_boards.build(:title =\> ‘#3’, :description  
=\> ‘thre  
e’)  
board[1] = forum.message\_boards.build(:title =\> ‘#2’, :description  
=\> ‘two’  
)  
forum.message\_boards[2].move\_lower  
forum.save  
board\_temp = forum.message\_boards  
board\_temp.each{|b| puts 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 = [] board[0] = forum.message\_boards.build(:title =\> ‘#1’, :description =\> ‘one’ ) board[2] = forum.message\_boards.build(:title =\> ‘#3’, :description =\> ‘thre e’) board[1] = forum.message\_boards.build(:title =\> ‘#2’, :description =\> ‘two’ ) board[2].move\_higher forum.save board\_temp = forum.message\_boards board\_temp.each{|b| puts 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  
.#1  
#3  
#2  
F.#1  
#3  
#2  
F…  
Finished in 0.597854 seconds.

1. Failure:  
test\_board\_down(ForumTest)  
[forum\_test.rb:133:in `test_board_down' forum_test.rb:132:in`each’  
forum\_test.rb:132:in `test\_board\_down’]:  
\<"#3"\> expected but was  
\<"#2"\>.

2. Failure:  
test\_board\_up(ForumTest)  
[forum\_test.rb:114:in `test_board_up' forum_test.rb:113:in`each’  
forum\_test.rb:113:in `test\_board\_up’]:  
\<"#3"\> expected but was  
\<"#2"\>.

## 10 tests, 43 assertions, 2 failures, 0 errors

Why doesn’t move\_higher and move\_lower affect forum.message\_boards in  
any way?

---

<div class="post-metadata">

**Author:** ![taro](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/df705f/32.png) [@taro](https://www.ruby-forum.com/u/taro)\
**Post date:** [January 7, 2008, 9:23pm UTC](https://www.ruby-forum.com/t/issues-with-move-higher-and-move-lower/125278/2 "2008-01-07T21:23:59Z")

</div>

I attempted to save forum, move up/down the board, and save the forum  
again, but that doesn’t seem to work, either…

---

<div class="post-metadata">

**Author:** ![taro](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/df705f/32.png) [@taro](https://www.ruby-forum.com/u/taro)\
**Post date:** [January 8, 2008, 10:27pm UTC](https://www.ruby-forum.com/t/issues-with-move-higher-and-move-lower/125278/3 "2008-01-08T22:27:58Z")

</div>

Sorry, I’m really desperate on this. Can someone help me out?

---

<div class="post-metadata">

**Author:** ![taro](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/df705f/32.png) [@taro](https://www.ruby-forum.com/u/taro)\
**Post date:** [January 8, 2008, 11:51pm UTC](https://www.ruby-forum.com/t/issues-with-move-higher-and-move-lower/125278/4 "2008-01-08T23:51:48Z")

</div>

Does move\_higher save it when it does it? Perhaps try calling save after  
doing the move\_higher.

On Jan 9, 2008 7:57 AM, Taro [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Sorry, I’m really desperate on this. Can someone help me out?
> 
> >

–  
Ryan B.

> **[frozenplague.net](http://www.frozenplague.net)**
>
> This domain may be for sale!

Feel free to add me to MSN and/or GTalk as this email.

---

<div class="post-metadata">

**Author:** ![taro](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/df705f/32.png) [@taro](https://www.ruby-forum.com/u/taro)\
**Post date:** [January 9, 2008, 3:08am UTC](https://www.ruby-forum.com/t/issues-with-move-higher-and-move-lower/125278/5 "2008-01-09T03:08:54Z")

</div>

I’ve heard move\_higher and move\_lower doesn’t save. Which isn’t  
exactly the problem with this test as I’ll explain later.

## I’ve noticed a slight flaw in my test, so revised it to get a similar results as before. As one might notice in the test code, forum.save doesn’t seem to have any effect on saving changes of move\_higher/ move\_lower (or, move\_higher/lower does nothing…):

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:in`each’  
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:in`each’  
forum\_test.rb:124:in `test\_board\_up’]:  
\<"#3"\> expected but was  
\<"#2"\>.

## 10 tests, 43 assertions, 2 failures, 0 errors
