• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

foodcoops / foodsoft / 18256748003

05 Oct 2025 09:13AM UTC coverage: 42.833% (-24.2%) from 67.053%
18256748003

push

github

web-flow
Fixes #1221 (#1222)

1. Renamed the new `price-unit-wrapper` class to just `unit-wrapper` as it affects non-price units as well.
2. Added the class to the erroneous fields.

3081 of 7193 relevant lines covered (42.83%)

11.89 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

50.0
/lib/date_time_attribute_validate.rb
1
# workaround for https://github.com/einzige/date_time_attribute/issues/14
2
require 'date_time_attribute'
1✔
3

4
module DateTimeAttributeValidate
1✔
5
  extend ActiveSupport::Concern
1✔
6
  include DateTimeAttribute
1✔
7

8
  module ClassMethods
1✔
9
    def date_time_attribute(*attributes)
1✔
10
      super
2✔
11

12
      attributes.each do |attribute|
2✔
13
        validate -> { send("#{attribute}_datetime_value_valid") }
11✔
14

15
        # allow resetting the field to nil
16
        before_validation do
5✔
17
          if instance_variable_get("@#{attribute}_is_set")
6✔
18
            date = instance_variable_get("@#{attribute}_date_value")
×
19
            time = instance_variable_get("@#{attribute}_time_value")
×
20
            send("#{attribute}=", nil) if date.blank? && time.blank?
×
21
          end
22
        end
23

24
        # remember old date and time values
25
        define_method("#{attribute}_date_value=") do |val|
5✔
26
          instance_variable_set("@#{attribute}_is_set", true)
×
27
          instance_variable_set("@#{attribute}_date_value", val)
×
28
          begin
29
            send("#{attribute}_date=", val)
×
30
          rescue StandardError
31
            nil
×
32
          end
33
        end
34
        define_method("#{attribute}_time_value=") do |val|
5✔
35
          instance_variable_set("@#{attribute}_is_set", true)
×
36
          instance_variable_set("@#{attribute}_time_value", val)
×
37
          begin
38
            send("#{attribute}_time=", val)
×
39
          rescue StandardError
40
            nil
×
41
          end
42
        end
43

44
        # fallback to field when values are not set
45
        define_method("#{attribute}_date_value") do
5✔
46
          instance_variable_get("@#{attribute}_date_value") || send("#{attribute}_date").try do |e|
×
47
            e.strftime('%Y-%m-%d')
×
48
          end
49
        end
50
        define_method("#{attribute}_time_value") do
5✔
51
          instance_variable_get("@#{attribute}_time_value") || send("#{attribute}_time").try do |e|
×
52
            e.strftime('%H:%M')
×
53
          end
54
        end
55

56
        private
5✔
57

58
        # validate date and time
59
        define_method("#{attribute}_datetime_value_valid") do
5✔
60
          date = instance_variable_get("@#{attribute}_date_value")
6✔
61
          unless date.blank? || begin
6✔
62
            Date.parse(date)
×
63
          rescue StandardError
64
            nil
×
65
          end
66
            errors.add(attribute, 'is not a valid date') # @todo I18n
×
67
          end
68
          time = instance_variable_get("@#{attribute}_time_value")
6✔
69
          unless time.blank? || begin
6✔
70
            Time.parse(time)
×
71
          rescue StandardError
72
            nil
×
73
          end
74
            errors.add(attribute, 'is not a valid time') # @todo I18n
×
75
          end
76
        end
77
      end
78
    end
79
  end
80
end
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc