Sha256: 3ecc127a31d4f6ad3a2f4811a2d35300d3f5d80387df1e99a7d81c114f919923

Contents?: true

Size: 941 Bytes

Versions: 46

Compression:

Stored size: 941 Bytes

Contents

# frozen_string_literal: true

require_relative '../../../lib/declare_schema/field_declaration_dsl'

RSpec.describe DeclareSchema::FieldDeclarationDsl do
  let(:model) { TestModel.new }
  subject { declared_class.new(model) }

  context 'Using declare_schema' do
    before do
      load File.expand_path('prepare_testapp.rb', __dir__)

      class TestModel < ActiveRecord::Base
        declare_schema do
          string :name, limit: 127

          timestamps
        end
      end
    end

    it 'has fields' do
      expect(TestModel.field_specs).to be_kind_of(Hash)
      expect(TestModel.field_specs.keys).to eq(['name', 'created_at', 'updated_at'])
      expect(TestModel.field_specs.values.map(&:type)).to eq([:string, :datetime, :datetime])
    end

    it 'stores limits' do
      expect(TestModel.field_specs['name'].limit).to eq(127), TestModel.field_specs['name'].inspect
    end
  end

  # TODO: fill out remaining tests
end

Version data entries

46 entries across 46 versions & 1 rubygems

Version Path
declare_schema-1.2.0 spec/lib/declare_schema/field_declaration_dsl_spec.rb
declare_schema-1.2.0.pre.1 spec/lib/declare_schema/field_declaration_dsl_spec.rb
declare_schema-1.1.0 spec/lib/declare_schema/field_declaration_dsl_spec.rb
declare_schema-1.0.2 spec/lib/declare_schema/field_declaration_dsl_spec.rb
declare_schema-1.0.1 spec/lib/declare_schema/field_declaration_dsl_spec.rb
declare_schema-1.0.0 spec/lib/declare_schema/field_declaration_dsl_spec.rb