Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add specs for Refinery::Menu and fix stack level too deep error comin…

…g from Refinery::Menu#inspect.
  • Loading branch information...
commit c7b176e6a69cdee22c54fffda1beef3119bd3558 1 parent 40fcf21
@ugisozols ugisozols authored
Showing with 39 additions and 4 deletions.
  1. +1 −4 core/lib/refinery/menu.rb
  2. +38 −0 core/spec/lib/refinery/menu_spec.rb
View
5 core/lib/refinery/menu.rb
@@ -21,10 +21,7 @@ def roots
def to_s
items.map(&:title).join(' ')
end
-
- def inspect
- items.map(&:inspect)
- end
+ alias :inspect :to_s
@parndt Owner
parndt added a note

Does this actually give you full object inspection?

@ugisozols Owner

No. inspect output differs in 1.8.7 and 1.9.3 so I choose to stick to what's 1.9.3 is returning. Probably not the best decision so I'm open to suggestions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
# The delegation is specified so crazily so that it works on 1.8.x and 1.9.x
delegate *((Array.instance_methods - Object.instance_methods) << {:to => :items})
View
38 core/spec/lib/refinery/menu_spec.rb
@@ -0,0 +1,38 @@
+require 'spec_helper'
+
+module Refinery
+ describe Menu do
+
+ let(:menu) do
+ page1 = FactoryGirl.create(:page, :title => 'test1')
+ page2 = FactoryGirl.create(:page, :title => 'test2', :parent_id => page1.id)
+ Refinery::Menu.new([page1, page2])
+ end
+
+ describe '.initialize' do
+ it "returns a collection of menu item objects" do
+ menu.each { |item| item.should be_an_instance_of(MenuItem) }
+ end
+ end
+
+ describe '#items' do
+ it 'returns a collection' do
+ menu.items.count.should eq(2)
+ end
+ end
+
+ describe '#roots' do
+ it 'returns a collection of items with parent_id == nil' do
+ menu.roots.collect(&:parent_id).should eq([nil])
+ end
+ end
+
+ describe '#to_s & #inspect' do
+ it 'returns string of joined page titles' do
+ menu.to_s.should eq('test1 test2')
+ menu.inspect.should eq('test1 test2')
+ end
+ end
+
+ end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.