Sha256: eefab0f68f54e0bd00a48b80273b3c5b2816cf19979b4c9834488c4dc7c5dd5c

Contents?: true

Size: 1.22 KB

Versions: 9

Compression:

Stored size: 1.22 KB

Contents

require "spec_helper"
require "shamu/attributes"

describe Shamu::Attributes::Validation do
  let( :klass ) do
    Class.new do
      include Shamu::Attributes
      include Shamu::Attributes::Assignment
      include Shamu::Attributes::Validation

      attribute :name, presence: true

      def self.name
        "Example"
      end
    end
  end

  it "forwards unused options to .validates method" do
    TestClass = Class.new do
      include Shamu::Attributes
      include Shamu::Attributes::Validation
    end

    expect( TestClass ).to receive( :validates ).with( :name, presence: true )
    class TestClass
      attribute :name, on: :user, presence: true
    end
  end

  it "doesn't clear errors on call to valid?" do
    instance = klass.new( {} )
    instance.validate
    expect( instance ).not_to be_valid

    instance.name = "Something"
    expect( instance ).not_to be_valid
  end

  it "validates methods on validate" do
    instance = klass.new( {} )
    instance.validate

    expect( instance.errors ).to have_key :name
  end

  it "validates on first call to valid?" do
    instance = klass.new( {} )
    expect( instance ).to receive( :validate ).once.and_call_original
    instance.valid?
    instance.valid?
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
shamu-0.0.13 spec/lib/shamu/attributes/validation_spec.rb
shamu-0.0.11 spec/lib/shamu/attributes/validation_spec.rb
shamu-0.0.9 spec/lib/shamu/attributes/validation_spec.rb
shamu-0.0.8 spec/lib/shamu/attributes/validation_spec.rb
shamu-0.0.7 spec/lib/shamu/attributes/validation_spec.rb
shamu-0.0.5 spec/lib/shamu/attributes/validation_spec.rb
shamu-0.0.4 spec/lib/shamu/attributes/validation_spec.rb
shamu-0.0.3 spec/lib/shamu/attributes/validation_spec.rb
shamu-0.0.2 spec/lib/shamu/attributes/validation_spec.rb