require File.dirname(__FILE__) + "/../../../spec_helper.rb" describe RightRails::Helpers::Forms do include ActionView::Helpers::TagHelper include ActionView::Helpers::FormTagHelper include ActionView::Helpers::JavaScriptHelper include RightRails::Helpers::Basic include RightRails::Helpers::Forms def url_for(options) options end def escape_javascript(str) str end def rightjs_required_files RightRails::Helpers.required_js_files(self) end before :each do RightRails::Config.reset! end describe ".calendar_field" do it "should generate a basic calendar_field_tag" do calendar_field_tag('name', 'value').should == %Q{} rightjs_required_files.should include('right/calendar') end it "should generate a calendar_field_tag with options" do calendar_field_tag('name', 'value', :format => '%Y/%m/%d').should == %Q{} end it "should generate a basic calendar_field" do calendar_field('model', 'method').should == %Q{} end it "should generate a calendar_field with options" do calendar_field('model', 'method', :hide_on_pick => true).should == %Q{} end describe "in RightJS 1 mode" do before :each do RightRails::Config.rightjs_version = 1 end it "should generate a basic calendar_field_tag" do calendar_field_tag('name', 'value').should == %Q{} rightjs_required_files.should include('right/calendar') end it "should generate a calendar_field_tag with options" do calendar_field_tag('name', 'value', :format => '%Y/%m/%d').should == %Q{} end it "should generate a basic calendar_field" do calendar_field('model', 'method').should == %Q{} end it "should generate a calendar_field with options" do calendar_field('model', 'method', :hide_on_pick => true).should == %Q{} end end end describe ".autocomplete_field" do it "should generate a basic autocomplete_field_tag" do autocomplete_field_tag('name', 'value', :url => '/foo').should == %Q{} rightjs_required_files.should include('right/autocompleter') end it "should generate an autocomplete_field_tag with options" do autocomplete_field_tag('name', 'value', :url => '/foo', :spinner => 'spinner', :min_length => 2).should == %Q{} end it "should generate a basic autocomplete_field" do autocomplete_field('object', 'method', :url => '/foo').should == %Q{} end it "should generate an autocomplete_field with options" do autocomplete_field('object', 'method', :url => '/foo', :fx_name => 'fade').should == %Q{} end describe "in RightJS 1 mode" do before :each do RightRails::Config.rightjs_version = 1 end it "should generate a basic autocomplete_field_tag" do autocomplete_field_tag('name', 'value', :url => '/foo').should == %Q{} rightjs_required_files.should include('right/autocompleter') end it "should generate an autocomplete_field_tag with options" do autocomplete_field_tag('name', 'value', :url => '/foo', :spinner => 'spinner', :min_length => 2).should == %Q{} end it "should generate a basic autocomplete_field" do autocomplete_field('object', 'method', :url => '/foo').should == %Q{} end it "should generate an autocomplete_field with options" do autocomplete_field('object', 'method', :url => '/foo', :fx_name => 'fade').should == %Q{} end end end describe ".slider" do it "should generate a basic slider_tag" do slider_tag('some_field', 22).should == %Q{\n}+ %Q{} end it "should generate a slider_tag with options" do slider_tag('some_field', 22, :min => 10, :max => 40).should == %Q{\n}+ %Q{} end it "should generate a slider with options" do model = {} model.should_receive('method').twice.and_return(22) should_receive(:instance_variable_get).twice.with('@object').and_return(model) slider('object', 'method', :value => 22, :min => 20, :max => 80).should == %Q{\n}+ %Q{} end end describe ".rater" do it "should generate a simple rater" do model = {} model.should_receive('method').twice.and_return(2) should_receive(:instance_variable_get).twice.with('@object').and_return(model) rater('object', 'method', :value => 2).should == %Q{\n}+ %Q{} end it "should generate a #rater_tag" do rater_tag('some_field', 2).should == %Q{\n}+ %Q{} end it "should generate the #rater_display tag" do rater_display(4).should == %Q{
}+ %Q{
}+ %Q{
}+ %Q{
}+ %Q{
}+ %Q{
}+ %Q{
} end describe "in RightJS 1 mode" do before :each do RightRails::Config.rightjs_version = 1 end it "should generate the #rater_display tag" do rater_display(4).should == %Q{
}+ %Q{
}+ %Q{
}+ %Q{
}+ %Q{
}+ %Q{
}+ %Q{
} end end end describe ".colorpicker" do it "should generate a simple colorpicker_field_tag" do colorpicker_field_tag('name', '#FF0').should == %Q{} end it "should generate a colorpicker_field_tag with options" do colorpicker_field_tag('name', '#FF0', :format => 'rgb').should == %Q{} end it "should generate a colorpicker_field with options" do colorpicker_field('object', 'method', :fx_name => 'slide').should == %Q{} end describe "in RightJS 1 mode" do before :each do RightRails::Config.rightjs_version = 1 end it "should generate a simple colorpicker_field_tag" do colorpicker_field_tag('name', '#FF0').should == %Q{} end it "should generate a colorpicker_field_tag with options" do colorpicker_field_tag('name', '#FF0', :format => 'rgb').should == %Q{} end it "should generate a colorpicker_field with options" do colorpicker_field('object', 'method', :fx_name => 'slide').should == %Q{} end end end describe ".tags_field" do it "should automatically require the 'right/tags.js' file" do tags_field_tag('name', 'one,two,three') rightjs_required_files.should include('right/tags') end it "should generate a simple tags_field_tag" do tags_field_tag('name', 'one,two,three').should == %Q{} end it "should generate a tags_field_tag with options" do tags_field_tag('name', 'one,two,three', { :tags => ['one', 'two', 'three'], :allow_new => false }).should == %Q{} end it "should generate a tags_field with options" do tags_field('object', 'method', {:tags => ['one', 'two', 'three']}).should == %Q{} end end describe ".rte_field" do it "should automatically require the 'right/rte.js' file" do rte_field_tag('name', 'some text') rightjs_required_files.should include('right/rte') end it "should generate a simple rte_field_tag" do rte_field_tag('name', 'some text').should == %Q{} end it "should generate a rte_field_tag with options" do rte_field_tag('name', 'some text', { :toolbar => 'extra' }).should == %Q{} end it "should generate a rte_field with options" do rte_field('object', 'method', {:toolbar => 'basic'}).should == %Q{} end end end