Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

clean up

  • Loading branch information...
commit 94b253a479df0294ab10bd47815ecad3de7f24df 1 parent 7d0fe57
@ruseel authored
View
6 app/models/topic.rb
@@ -28,11 +28,7 @@ def depth
def set_boardish
if self.boardish.nil?
t = self.class.last_root_topic
- if t.nil? || t.boardish.nil?
- b = Boardish.new(nil)
- else
- b = t.boardish
- end
+ b = t && t.boardish || Boardish.new
self.boardish = b.inc_at_depth(0)
end
end
View
6 app/utils/boardish.rb
@@ -12,7 +12,7 @@ class Boardish
DEPTH_SPEC = [23, BIT_SIZE, BIT_SIZE]
DEFAULT_VALUES = [0, max(BIT_SIZE), max(BIT_SIZE)]
- def initialize(i)
+ def initialize(i = nil)
self.raw = i
end
@@ -71,6 +71,10 @@ def to_i
a | b | c
end
+ def default?
+ @parts == DEFAULT_VALUES
+ end
+
def ==(other)
if other.respond_to?(:to_i)
self.to_i == other.to_i
View
2  test/unit/boardish_test.rb
@@ -13,7 +13,7 @@ def n(*args)
end
test "create with different initializer" do
- n(1)
+ assert_equal Boardish.new, Boardish.new(nil)
assert_equal n(1,6), n(1).inc_at_depth(1)
assert_equal n(1,6,6), n(1).inc_at_depth(1).inc_at_depth(2)
end
Please sign in to comment.
Something went wrong with that request. Please try again.