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

foodcoops / foodsoft / 21544448614

31 Jan 2026 12:25PM UTC coverage: 47.144% (-20.0%) from 67.127%
21544448614

Pull #1268

github

lentschi
Closes #1267

Remove the convert units feature
Pull Request #1268: Closes #1267 - Remove the `convert_units` feature

1 of 2 new or added lines in 2 files covered. (50.0%)

1539 existing lines in 99 files now uncovered.

3376 of 7161 relevant lines covered (47.14%)

13.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✔
UNCOV
18
            date = instance_variable_get("@#{attribute}_date_value")
×
UNCOV
19
            time = instance_variable_get("@#{attribute}_time_value")
×
UNCOV
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✔
UNCOV
26
          instance_variable_set("@#{attribute}_is_set", true)
×
UNCOV
27
          instance_variable_set("@#{attribute}_date_value", val)
×
28
          begin
UNCOV
29
            send("#{attribute}_date=", val)
×
30
          rescue StandardError
31
            nil
×
32
          end
33
        end
34
        define_method("#{attribute}_time_value=") do |val|
5✔
UNCOV
35
          instance_variable_set("@#{attribute}_is_set", true)
×
UNCOV
36
          instance_variable_set("@#{attribute}_time_value", val)
×
37
          begin
UNCOV
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✔
UNCOV
46
          instance_variable_get("@#{attribute}_date_value") || send("#{attribute}_date").try do |e|
×
UNCOV
47
            e.strftime('%Y-%m-%d')
×
48
          end
49
        end
50
        define_method("#{attribute}_time_value") do
5✔
UNCOV
51
          instance_variable_get("@#{attribute}_time_value") || send("#{attribute}_time").try do |e|
×
UNCOV
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✔
UNCOV
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✔
UNCOV
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