Sha256: 825938241df1ca34538ba234e741b0a713a8ae91f327bf472d93798a9ad40daa

Contents?: true

Size: 1.04 KB

Versions: 3

Compression:

Stored size: 1.04 KB

Contents

require 'spec_helper'

describe ForeignKeyValidation::Validator do

  let(:user) { User.create }
  let(:other_user) { User.create }

  describe ".new" do

    subject { ForeignKeyValidation::Validator }

    it "initializes new validator" do
      expect(subject.new).to be_instance_of ForeignKeyValidation::Validator
    end

  end

  describe "#validate" do

    subject { ForeignKeyValidation::Validator }

    it "creates no validations if params blank" do
      expect(subject.new.validate).to be false
    end

    it "creates no validations if object is valid" do
      object = Issue.create(user: user, project: Project.create(user: user))
      expect(subject.new(validate_against_key: :user_id, reflection_names: [:project], object: object).validate).to be false
    end

    it "creates validations if object is invalid" do
      object = Issue.create(user: user, project: Project.create(user: other_user))
      expect(subject.new(validate_against_key: :user_id, reflection_names: [:project], object: object).validate).to be true
    end

  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
foreign_key_validation-1.1.2 spec/validator/base_spec.rb
foreign_key_validation-1.1.1 spec/validator/base_spec.rb
foreign_key_validation-1.1.0 spec/validator/base_spec.rb