Skip to content

Commit

Permalink
Merge pull request #1 from site-prism/feature/add_dsl_validations
Browse files Browse the repository at this point in the history
Add input spec and input dsl validator
  • Loading branch information
luke-hill committed Dec 20, 2023
2 parents 96422c7 + 0229ff4 commit d6e3992
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/testing_record.rb
@@ -1,7 +1,8 @@
# frozen_string_literal: true

require_relative 'testing_record/version'
require_relative 'testing_record/dsl'
require_relative 'testing_record/model'
require_relative 'testing_record/version'

module TestingRecord
class Error < StandardError; end
Expand Down
1 change: 1 addition & 0 deletions lib/testing_record/dsl.rb
@@ -0,0 +1 @@
require_relative 'dsl/validation'
1 change: 1 addition & 0 deletions lib/testing_record/dsl/validation.rb
@@ -0,0 +1 @@
require_relative 'validation/input'
19 changes: 19 additions & 0 deletions lib/testing_record/dsl/validation/input.rb
@@ -0,0 +1,19 @@
# frozen_string_literal: true

module TestingRecord
module DSL
module Validation
# [TestingRecord::DSL::Validation::Input]
# Validations for direct inputs into creating models
module Input
def type_valid?(input)
type_validations.include?(input)
end

private

def type_validations = %i[singular plural]
end
end
end
end
23 changes: 23 additions & 0 deletions spec/testing_record/dsl/validation/input_spec.rb
@@ -0,0 +1,23 @@
# frozen_string_literal: true

RSpec.describe TestingRecord::DSL::Validation::Input do
subject(:klazz) do
Class.new do
extend TestingRecord::DSL::Validation::Input
end
end

describe '#type_valid?' do
it 'is `true` when the type is singular' do
expect(klazz.type_valid?(:singular)).to be true
end

it 'is `true` when the type is plural' do
expect(klazz.type_valid?(:plural)).to be true
end

it 'is `false` for all other types' do
expect(klazz.type_valid?(:foo)).to be false
end
end
end

0 comments on commit d6e3992

Please sign in to comment.