require "spec_helper" describe MessageBlock::Helpers do include ActionView::Helpers::TagHelper include MessageBlock::Helpers before do setup_post setup_user end it "should not accept invalid options" do lambda { message_block :invalid => "option" }.should raise_error(ArgumentError) end it "should accept valid options" do lambda { message_block :on => :post, :model_error_type => "fail", :flash_types => %w(error warn), :html => {:style => 'height: 10em'}, :id => "block", :class => "messages" }.should_not raise_error end it "should show nothing with no errors" do message_block.should == %(
) end it "should automatically find post errorts with posts controller" do @controller = posts_controller output = message_block output.should == %( ) end it "should give no error for post" do output = message_block(:on => :post) output.should == %( ) end it "should give error for user" do output = message_block(:on => :user) output.should == %( ) end it "should give errors for both post and user" do output = message_block(:on => [:post, :user]) output.should == %( ) end it "should give errors for both post and user in the correct order" do output = message_block(:on => [:user, :post]) output.should == %( ) end it "should give error for user given direct instance variable" do output = message_block(:on => @user) output.should == %( ) end it "should respect model error type" do output = message_block(:on => :user, :model_error_type => "fail") output.should == %( ) end it "should be able to specify id for containing div" do output = message_block(:id => "messages") output.should == %() end it "should be able to specify class for containing div" do output = message_block(:class => "messages") output.should == %() end it "should be able to specify html options for containing div" do output = message_block(:html => {:id => "block", :class => "messages"}) output.should == %() end it "should be able to specify container option as false" do output = message_block(:on => :post, :container => false) output.should == %(