Sha256: a089087a7c2a9dc3b9924607862765233e00117912f69e96bbe9fd87e6b61774

Contents?: true

Size: 1.35 KB

Versions: 4

Compression:

Stored size: 1.35 KB

Contents

# frozen_string_literal: true

require 'eac_ruby_utils/core_ext'

module EacRailsUtils
  module Rspec
    module Setup
      module ModelsUtils
        def model_record_attribute_test(record_variable, attribute, valid, value)
          context("when #{record_variable}.#{attribute} == #{value}") do
            before do
              send(record_variable).send("#{attribute}=", value)
            end

            it "#{record_variable} should be {valid ? '' : 'not '}valid" do
              expect(send(record_variable).valid?).to send("be_#{valid ? 'truthy' : 'falsy'}"),
                                                      send(record_variable).errors.messages
            end
          end
        end

        def model_record_values_attribute_test(record_variable, attribute, valid, values)
          values.each do |value|
            model_record_attribute_test(record_variable, attribute, valid, value)
          end
        end

        def model_record_valid_invalid_values_attribute_test(record_variable, attribute,
                                                             valid_values, invalid_values)
          {
            false => invalid_values,
            true => valid_values
          }.each do |valid, values|
            model_record_values_attribute_test(record_variable, attribute, valid, values)
          end
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
eac_rails_utils-0.15.1 lib/eac_rails_utils/rspec/setup/models_utils.rb
eac_rails_utils-0.15.0 lib/eac_rails_utils/rspec/setup/models_utils.rb
eac_rails_utils-0.14.1 lib/eac_rails_utils/rspec/setup/models_utils.rb
eac_rails_utils-0.14.0 lib/eac_rails_utils/rspec/setup/models_utils.rb