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 # fraking Rails 3 replacement def javascript_tag(script) RightRails::Helpers.html_safe(%Q{}) end # stubbing those two def capture(&block) return yield() end def concat(content) content end def rightjs_required_files RightRails::Helpers.required_js_files(self) end before :each do RightRails::Config.reset! end 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' rightjs_required_files.should include('right/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 describe "in RightJS 1 mode" do before :each do RightRails::Config.rightjs_version = 1 end it "should generate the link" do link_to_lightbox('boo', 'boo').should == 'boo' rightjs_required_files.should include('right/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 end describe "#tabs generator" do 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} rightjs_required_files.should include('right/tabs') 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 describe "#resizable generator" do it "should generate a simple resizable" do resizable { "bla bla bla" }.should == %Q{
}+ %Q{
bla bla bla
}+ %Q{
}+ %Q{
} rightjs_required_files.should include('right/resizable') end it "should generate a resizable with directions" do resizable(:direction => :bottom) { 'boo' }.should == %Q{
}+ %Q{
boo
}+ %Q{
}+ %Q{
} end it "should generate a resizable with constraints" do resizable(:min_width => 100, :maxHeight => '10em'){ 'boo' }.should == %Q{
}+ %Q{
boo
}+ %Q{
}+ %Q{
} end describe "in RightJS 1 mode" do before :each do RightRails::Config.rightjs_version = 1 end it "should generate a simple resizable" do resizable { "bla bla bla" }.should == %Q{
}+ %Q{
bla bla bla
}+ %Q{
}+ %Q{
} rightjs_required_files.should include('right/resizable') end it "should generate a resizable with directions" do resizable(:direction => :bottom) { 'boo' }.should == %Q{
}+ %Q{
boo
}+ %Q{
}+ %Q{
} end it "should generate a resizable with constraints" do resizable(:min_width => 100, :maxHeight => '10em'){ 'boo' }.should == %Q{
}+ %Q{
boo
}+ %Q{
}+ %Q{
} end end end end