require 'spec_helper' describe 'ErrorHelper' do include RSpec::Rails::HelperExampleGroup include Webrat::HaveTagMatcher before(:each) do @object = mock({ :errors => {:name => "Invalid name"} }) end it "should not find existing errors" do helper.has_errors?(:login).should be_false end it "should find existing errors" do helper.has_errors?(:name).should be_true end it "should get errors for attribute" do helper.error_message_on(:name).should == "Invalid name" end it "should get errors for base" do helper.error_messages_on_base.should be_blank end it "should return inline error for attribute" do helper.jquery_form_for(:new_post, :url => '/hello') do |builder| builder.object = @object builder.inline_error(:name).should have_tag("div.ui-input-error-message") end end it "should not display model errors" do helper.model_errors.should be_blank end it "should display default error" do helper.jquery_form_for(:new_post, :url => '/hello') do |builder| builder.object = @object builder.model_errors("One error").should have_tag("div.ui-base-error-messages>p>strong") do |text| text.should contain("One error") end end end it "should display default errors" do helper.jquery_form_for(:new_post, :url => '/hello') do |builder| builder.object = @object builder.model_errors(["One", "Two"]).should have_tag("div.ui-base-error-messages>p>strong",:count => 2) do |text| text.should contain("OneTwo") end end end it "should display model errors" do @object = mock({ :errors => {:base => "One"} }) helper.jquery_form_for(:new_post, :url => '/hello') do |builder| builder.object = @object builder.model_errors.should have_tag("div.ui-base-error-messages>p>strong") do |text| text.should contain("One") end end end it "should display model errors with default" do @object = mock({ :errors => {:base => "One"} }) helper.jquery_form_for(:new_post, :url => '/hello') do |builder| builder.object = @object builder.model_errors(["Two", "Three"]).should have_tag("div.ui-base-error-messages>p>strong",:count => 3) do |text| text.should contain("OneTwoThree") end end end end