Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add tdd variant of #add_any_helper * Add changelog
- Loading branch information
Showing
6 changed files
with
71 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
# frozen_string_literal: true | ||
|
||
require_relative 'dsl/builder' | ||
require_relative 'dsl/validation' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# frozen_string_literal: true | ||
|
||
require_relative 'builder/helpers' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# frozen_string_literal: true | ||
|
||
module TestingRecord | ||
module DSL | ||
module Builder | ||
# [TestingRecord::DSL::Builder::Helpers] | ||
# Ways in which we can build in extra helper methods from building requests | ||
module Helpers | ||
# Add the boolean helper which will perform the `#any?` check on your instance | ||
# | ||
# @return [TestingRecord::Model] | ||
def add_any_helper(name) | ||
define_method(:"#{name}?") do | ||
instance_variable_get(:"@#{name}").any? | ||
end | ||
end | ||
|
||
# Check whether the type setting is valid | ||
# | ||
# @return [Boolean] | ||
def type_valid?(input) | ||
type_validations.include?(input) | ||
end | ||
|
||
private | ||
|
||
def caching_validations = %i[enabled disabled] | ||
def type_validations = %i[singular plural] | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# frozen_string_literal: true | ||
|
||
RSpec.describe TestingRecord::DSL::Builder::Helpers do | ||
subject(:klazz) do | ||
Class.new do | ||
extend TestingRecord::DSL::Builder::Helpers | ||
end | ||
end | ||
|
||
describe '.add_any_helper' do | ||
subject(:instance) { klazz.new } | ||
|
||
before { klazz.add_any_helper(:foo) } | ||
|
||
it 'creates a boolean helper with the desired name' do | ||
expect(instance).to respond_to(:foo?) | ||
end | ||
|
||
it 'is `true` when the iVar corresponding to the name is not empty' do | ||
instance.instance_variable_set(:@foo, [1]) | ||
|
||
expect(instance.foo?).to be true | ||
end | ||
|
||
it 'is `false` when the iVar corresponding to the name is empty' do | ||
instance.instance_variable_set(:@foo, []) | ||
|
||
expect(instance.foo?).to be false | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters