Sha256: 891b04d0786b4b5b3e608266db330790e784712d4997d4dcfbed517a5b067a14

Contents?: true

Size: 1.44 KB

Versions: 6

Compression:

Stored size: 1.44 KB

Contents

require 'spec_helper'

describe ValidatePostClearErrors do 

  it "#clean_Errors! will force the #valid? method to clear the target's errors at the start" do

    post = RubyPost.new(body: 'body')
    context = ValidatePostClearErrors.perform(post: post)
    context.success?.should == false
    post.errors.added?(:title, :blank).should == true
    post.errors.size.should == 1

    post.title = 'title'
    post.body = ''
    context = ValidatePostClearErrors.perform(post: post)
    context.success?.should == false
    post.errors.added?(:body, :blank).should == true
    post.errors.size.should == 1

    post.title = ''
    context = ValidatePostClearErrors.perform(post: post)
    context.success?.should == false
    post.errors.added?(:title, :blank).should == true
    post.errors.added?(:body, :blank).should == true
    post.errors.size.should == 2

  end

  it "By default a Validator Class should not clean the target's errors" do

    post = RubyPost.new(body: 'body')
    context = ValidatePost.perform(post: post)
    context.success?.should == false
    post.errors.added?(:title, "can't be blank!").should == true
    post.errors.size.should == 1

    post.title = 'title'
    post.body = ''
    context = ValidatePost.perform(post: post)
    context.success?.should == false
    post.errors.added?(:title, "can't be blank!").should == true
    post.errors.added?(:body, "can't be blank!").should == true
    post.errors.size.should == 2

  end

end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
usecasing_validations-0.6.0 spec/usecasing/validate_post_clear_errors_spec.rb
usecasing_validations-0.5.5 spec/usecasing/validate_post_clear_errors_spec.rb
usecasing_validations-0.5.4 spec/usecasing/validate_post_clear_errors_spec.rb
usecasing_validations-0.5.3 spec/usecasing/validate_post_clear_errors_spec.rb
usecasing_validations-0.5.1 spec/usecasing/validate_post_clear_errors_spec.rb
usecasing_validations-0.5.0 spec/usecasing/validate_post_clear_errors_spec.rb