Sha256: fba9a9610df0fd973b4d7697dd3bd333e902ad24ab45d174dad33d9f9ef72ed3

Contents?: true

Size: 1.45 KB

Versions: 4

Compression:

Stored size: 1.45 KB

Contents

require 'spec_helper'

describe ForeignKeyValidation::ModelExtension do

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

  context "with calling private methods from model" do
    before { Issue.send :validate_foreign_keys }

    let(:issue) { Issue.create }

    it "does not allow to call private validate_foreign_keys_on_* methods" do
      expect{issue.validate_foreign_keys_on_user}.to raise_exception(/private method `validate_foreign_keys_on_user' called/)
    end
  end

  context "with calling validation and wrong attributes hash" do

    it "raises error due to wrong :on key" do
      expect{Idea.class_eval { validate_foreign_keys on: :not_existing }}.to raise_error("No foreign key for relation not_existing on ideas table!")
    end

    it "raises error due to not related :on key" do
      expect{Project.class_eval { validate_foreign_keys on: :comment }}.to raise_error("No foreign key for relation comment on projects table!")
    end

    it "raises error due to wrong :with key" do
      expect{Idea.class_eval { validate_foreign_keys with: :not_existing }}.to raise_error('Unknown relation in ["not_existing"]!')
    end

  end

  context "with calling validation and missing relations" do

    it "raises error due to no existing relations" do
      expect{Dummy.class_eval { validate_foreign_keys }}.to raise_error("Can't find any belongs_to relations for Dummy class. Put validation call below association definitions!")
    end

  end

end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
foreign_key_validation-1.1.2 spec/model_extension/validation_with_exceptions_spec.rb
foreign_key_validation-1.1.1 spec/model_extension/validation_with_exceptions_spec.rb
foreign_key_validation-1.1.0 spec/model_extension/validation_with_exceptions_spec.rb
foreign_key_validation-1.0.1 spec/models/validation_with_exceptions_spec.rb