require File.dirname(__FILE__) + "/../../../spec_helper.rb"
describe RightRails::Helpers::Misc do
include ActionView::Helpers::UrlHelper
include ActionView::Helpers::TagHelper
include ActionView::Helpers::TextHelper
include RightRails::Helpers::Basic
include RightRails::Helpers::Misc
it "should provide the basic #flashes builder" do
should_receive(:flash).any_number_of_times.and_return({
:warning => "Warning!",
:notice => "Notice!",
:error => "Error!"
})
flashes.should == '
'+
'
Error!
'+
'
Notice!
'+
'
Warning!
'+
'
'
end
describe "#autocomplete_result" do
it "should generate a simple result" do
autocomplete_result(%w{one two three}).should == ''
end
it "should generate result with highlightning" do
autocomplete_result(%w{one two three}, :highlight => 'o').should ==
''
end
it "should escape strings by default" do
autocomplete_result(['b', 'i']).should ==
%Q{}
end
it "should not escape strings if asked" do
autocomplete_result(['b', 'i'], :escape => false).should ==
%Q{}
end
it "should generate result out of list of records" do
records = [
mock(:boo, :boo => 'one'),
mock(:boo, :boo => 'two')
]
autocomplete_result(records, :boo).should == ''
end
it "should highlight result when generated out of an objects list" do
records = [
mock(:boo, :boo => 'one'),
mock(:boo, :boo => 'two')
]
autocomplete_result(records, :boo, :highlight => 'o').should ==
%Q{}
end
end
describe "#link_to_lightbox" do
it "should generate the link" do
link_to_lightbox('boo', 'boo').should == 'boo'
@_right_scripts.should == ['lightbox']
end
it "should generate lightbox with roadtrip" do
link_to_lightbox('boo', 'boo', :roadtrip => true).should ==
%Q{boo}
end
it "should generate lightbox with options" do
link_to_lightbox('boo', 'boo', :hide_on_out_click => false).should ==
%Q{boo}
end
end
describe "#tabs generator" do
def capture(&block)
return yield()
end
def concat(content)
content
end
it "should generate simple tabs" do
tabs(:id => 'my-tabs') {
tab("Tab 1", :id => 'tab-1'){ 'content 1' }
tab("Tab 2", :id => 'tab-2'){ 'content 2' }
}.should == %Q{\n}
end
it "should generate tabs with id prefix" do
tabs(:id => 'my-tabs', :id_prefix => 'foo-') {
tab("Tab 1", :id => 'tab-1'){ 'content 1' }
tab("Tab 2", :id => 'tab-2'){ 'content 2' }
}.should == %Q{\n}
end
it "should generate remote tabs" do
tabs(:id => 'my-tabs') {
tab("Tab 1", :url => '/tab/1')
tab("Tab 2", :url => '/tab/2')
}.should == %Q{\n}
end
it "should generate carousel tabs" do
tabs(:id => 'my-tabs', :type => :carousel) {
tab("Tab 1", :id => 'tab-1'){ 'content 1' }
tab("Tab 2", :id => 'tab-2'){ 'content 2' }
}.should == %Q{\n}
end
it "should generate harmonica tabs" do
tabs(:id => 'my-tabs', :type => :harmonica) {
tab("Tab 1", :id => 'tab-1'){ 'content 1' }
tab("Tab 2", :id => 'tab-2'){ 'content 2' }
}.should == %Q{- Tab 1
\n- content 1
\n- Tab 2
\n- content 2
\n}
end
end
end