Rails - Test validation of enum fields

Your migration could be the issue, it should look something like:

t.integer :type, default: 1

You may also consider testing this another way.

Maybe more like:

it "validates the category" do
  expect(invoice with category fee).to be_valid
end

Try this:

it { should validate_inclusion_of(:category).in_array(%w[sale sale_with_tax fees lease tax_free other payroll].map(&:to_sym)) }

Additionally, for code-cleanup, try putting the valid categories/types in a corresponding constant. Example:

class Invoice < ActiveRecord::Base
  INVOICE_CATEGORIES = [:sale, :sale_with_tax, :fees, :lease, :tax_free, :other, :payroll]
  enum category: INVOICE_CATEGORIES
end

Using Shoulda matchers we can use the following to test the enum

it { should define_enum_for(:type).with([:receivable, :payable]) }

it { should define_enum_for(:category).
            with(:sale, :sale_with_tax, :fees, :lease, :tax_free, :other, :payroll) }