Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

fix reply error.

  • Loading branch information...
commit f0410c6ff3ca32775cefdce7200e83b0ef76a5db 1 parent b00263a
@ruseel authored
View
6 app/models/topic.rb
@@ -14,7 +14,11 @@ class Topic < ActiveRecord::Base
default_scope { order("boardish desc") }
def parent=(p)
- self.boardish = p.boardish.reply
+ b = p.boardish.reply
+ while (prev = self.class.where(boardish: b).first).present?
+ b = b.inc_at_depth(b.depth)
+ end
+ self.boardish = b
end
def depth
View
6 test/unit/boardish_test.rb
@@ -86,8 +86,10 @@ def n(*args)
boardish_sort([first, first_reply, first_reply_reply, second, second_reply])
end
- test "some wired" do
- assert_equal Boardish.from_int(Boardish.from_int(n(1,7,7).to_i).reply.to_i), n(1, 6, 7)
+ test "1, 1-1, 1-1-1, 1-2 should be ordered" do
+ first = n(1)
+ first_reply = first.inc_at_depth(1)
+ first_reply_reply = first_reply.inc_at_depth(2)
end
private
View
13 test/unit/topic_test.rb
@@ -47,4 +47,17 @@ def admin
assert_equal ["two", "two_one", "one", "one_one", "fixture_one"], subjects
end
+
+ test "prev" do
+ one=Topic.create(subject: "one", body: "one")
+ one_one=Topic.create(subject: "one_one", body: "one_one", parent: one)
+ one_one_one=Topic.create(subject: "one_one_one", body: "one_one_one", parent: one_one)
+
+ one_two=Topic.create(subject: "one_two", body: "one_two", parent: one)
+ one_three=Topic.create(subject: "one_three", body: "one_three", parent: one)
+ one_two_one=Topic.create(subject: "one_two_one", body: "one_two_one", parent: one_two)
+
+ subjects = Topic.all.map(&:subject)
+ assert_equal ["one", "one_one", "one_one_one", "one_two", "one_two_one", "one_three", "fixture_one"], subjects
+ end
end
Please sign in to comment.
Something went wrong with that request. Please try again.