Add specs for Refinery::Menu and fix stack level too deep error coming from #inspect #1551

Merged
merged 3 commits into from Apr 4, 2012
View
@@ -2,6 +2,9 @@
* [See full list](https://github.com/resolve/refinerycms/compare/2-0-stable...master)
+## 2.0.4 [unreleased]
+* Fixed stack level too deep error in Refinery::Menu#inspect. [Uģis Ozols](https://github.com/ugisozols)
+
## 2.0.3 [2 April 2012]
* Fixed missing authentication initializer. [Uģis Ozols](https://github.com/ugisozols)
* Fixed Heroku and sqlite3 related errors. [Philip Arndt](https://github.com/parndt)
@@ -22,10 +22,6 @@ def to_s
items.map(&:title).join(' ')
end
- def inspect
- items.map(&:inspect)
- end
-
# 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})
end
@@ -0,0 +1,37 @@
+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' do
+ it 'returns string of joined page titles' do
+ menu.to_s.should eq('test1 test2')
+ end
+ end
+
+ end
+end