measured 3.1.0 → 3.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3b304fbf20408beb13b8408d74c17747f00ccb991b586775b91249f2e90e9073
4
- data.tar.gz: d8df7e3a16743234d79b1d8375f2f6d83e69f18824fdd1ff95c530fdd333d3a3
3
+ metadata.gz: 1e8794e944fe077ce5f8fe1271de15dbd7aae08e9faa25870d5a2f1df2fecfe3
4
+ data.tar.gz: d6250b4975dbf4a2972b998cc68971b983f6ee2d45c2a22fe7839d672c951233
5
5
  SHA512:
6
- metadata.gz: 3f7e92b9cdc9165c11dca6857ae9bbc141b938eb071e89f56ca1e13198fc6d281bde0abe4d3436d2f102d869057c5b1f60562bdcb2f9376739a4927b11ccb248
7
- data.tar.gz: 4b3d830a1814b6b64dd9123a40e444918adf3a546b925bb57088bc2c4324da0ccd7040253a838d24f0c53ea1c749cbade548dee29f2995678be903f87af04dcf
6
+ metadata.gz: 30590d0e624813f1cbc0bc8bbe5a397b0197e799cd36070c91eba906890cea07fbf2b1755db57fc73aea8e1ce5bbf220edd608cf27ee809afccc0d18a0abafe7
7
+ data.tar.gz: 4197246ef6225ab834396b9287e705d1e12878f90ed9892a372d552c566ab387cfee24b083f0a6018a4e6515d1245167db548f123521c510af1671a835373599
@@ -11,6 +11,10 @@ registries:
11
11
  username: ${{secrets.DEPENDENCIES_GITHUB_USER}}
12
12
  password: ${{secrets.DEPENDENCIES_GITHUB_TOKEN}}
13
13
  updates:
14
+ - package-ecosystem: github-actions
15
+ directory: "/"
16
+ schedule:
17
+ interval: weekly
14
18
  - package-ecosystem: bundler
15
19
  directory: "/"
16
20
  schedule:
@@ -26,9 +26,9 @@ jobs:
26
26
 
27
27
  name: Ruby ${{ matrix.ruby }} ${{ matrix.gemfile }}
28
28
  steps:
29
- - uses: actions/checkout@v1
29
+ - uses: actions/checkout@50fbc622fc4ef5163becd7fab6573eac35f8462e # v1.2.0
30
30
  - name: Set up Ruby ${{ matrix.ruby }}
31
- uses: ruby/setup-ruby@v1
31
+ uses: ruby/setup-ruby@e34163cd15f4bb403dcd72d98e295997e6a55798 # v1.238.0
32
32
  with:
33
33
  ruby-version: ${{ matrix.ruby }}
34
34
  bundler-cache: true
@@ -8,7 +8,7 @@ jobs:
8
8
  steps:
9
9
  - name: Dependabot metadata
10
10
  id: metadata
11
- uses: dependabot/fetch-metadata@v1.6.0
11
+ uses: dependabot/fetch-metadata@c9c4182bf1b97f5224aee3906fd373f6b61b4526 # v1.6.0
12
12
  with:
13
13
  github-token: "${{ secrets.GITHUB_TOKEN }}"
14
14
 
@@ -16,7 +16,7 @@ jobs:
16
16
  id: check_ci_failure
17
17
  continue-on-error: true
18
18
  if: ${{ steps.metadata.outputs.update-type == 'version-update:semver-patch' || steps.metadata.outputs.update-type == 'version-update:semver-minor' || steps.metadata.outputs.dependency-group == 'auto_merge' }}
19
- uses: actions/github-script@v6
19
+ uses: actions/github-script@d7906e4ad0b1822421a7e6a35d5ca353c962f410 # v6.4.1
20
20
  with:
21
21
  script: |
22
22
  function sleep(ms) {
@@ -62,7 +62,7 @@ jobs:
62
62
  core.setOutput("ci_state", ci_state)
63
63
  - name: Send Slack notification if auto-merge failed
64
64
  if: ${{ steps.check_ci_failure.outputs.ci_state == 'false' }}
65
- uses: ruby/action-slack@v3.0.0
65
+ uses: ruby/action-slack@b6882ea6ef8f556f9f9af9ec1220d3f1ced74acf # v3.0.0
66
66
  with:
67
67
  payload: |
68
68
  {
@@ -77,7 +77,7 @@ jobs:
77
77
 
78
78
  - name: Approve and merge
79
79
  if: ${{ steps.check_ci_failure.outputs.ci_state == 'true' && (steps.metadata.outputs.update-type == 'version-update:semver-patch' || steps.metadata.outputs.update-type == 'version-update:semver-minor' || steps.metadata.outputs.dependency-group == 'auto_merge') }}
80
- uses: actions/github-script@v6
80
+ uses: actions/github-script@d7906e4ad0b1822421a7e6a35d5ca353c962f410 # v6.4.1
81
81
  with:
82
82
  script: |
83
83
  await github.rest.pulls.createReview({
data/CHANGELOG.md CHANGED
@@ -1,6 +1,13 @@
1
1
  Unreleased
2
2
  -----
3
3
 
4
+ 3.2.1
5
+ -----
6
+ * Restrict Measured::Cache::Json initializer to valid filenames. (@caseyshop)
7
+
8
+ 3.2.0
9
+ -----
10
+ * Make the ActiveRecord validation errors have the correct type. (@alexcarruthers)
4
11
 
5
12
  3.1.0
6
13
  -----
@@ -5,7 +5,8 @@ module Measured::Cache
5
5
 
6
6
  def initialize(filename)
7
7
  @filename = filename
8
- @path = Pathname.new(File.join(File.dirname(__FILE__), "../../../cache", @filename)).cleanpath
8
+ raise ArgumentError, "Invalid cache file: #{filename}" unless %w[length.json weight.json volume.json test.json].include?(filename.to_s)
9
+ @path = Pathname.new(File.join(File.dirname(__FILE__), "../../../cache", filename)).cleanpath
9
10
  end
10
11
 
11
12
  def exist?
@@ -24,11 +24,11 @@ class MeasuredValidator < ActiveModel::EachValidator
24
24
  return unless measurable_unit_name.present? || measurable_value.present?
25
25
 
26
26
  measurable_unit = measured_class.unit_system.unit_for(measurable_unit_name)
27
- record.errors.add(attribute, message(record, "is not a valid unit")) unless measurable_unit
27
+ record.errors.add(attribute, :invalid, message: message(record, "is not a valid unit")) unless measurable_unit
28
28
 
29
29
  if options[:units] && measurable_unit.present?
30
30
  valid_units = Array(options[:units]).map { |unit| measured_class.unit_system.unit_for(unit) }
31
- record.errors.add(attribute, message(record, "is not a valid unit")) unless valid_units.include?(measurable_unit)
31
+ record.errors.add(attribute, :invalid, message: message(record, "is not a valid unit")) unless valid_units.include?(measurable_unit)
32
32
  end
33
33
 
34
34
  if measurable_unit && measurable_value.present?
@@ -36,7 +36,7 @@ class MeasuredValidator < ActiveModel::EachValidator
36
36
  comparable_value = value_for(value, record)
37
37
  comparable_value = measured_class.new(comparable_value, measurable_unit) unless comparable_value.is_a?(Measured::Measurable)
38
38
  unless measurable.public_send(CHECKS[option], comparable_value)
39
- record.errors.add(attribute, message(record, "#{measurable.to_s} must be #{CHECKS[option]} #{comparable_value}"))
39
+ record.errors.add(attribute, option, message: message(record, "#{measurable.to_s} must be #{CHECKS[option]} #{comparable_value}"))
40
40
  end
41
41
  end
42
42
  end
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module Measured
3
- VERSION = "3.1.0"
3
+ VERSION = "3.2.1"
4
4
  end
@@ -14,6 +14,24 @@ class Measured::Cache::JsonTest < ActiveSupport::TestCase
14
14
  refute_match "../", @cache.path.to_s
15
15
  end
16
16
 
17
+ test "#initialize accepts valid cache filenames for Measured::Measurable.subclasses, and test file" do
18
+ valid_files = %w[length.json weight.json volume.json test.json]
19
+ valid_files.each do |filename|
20
+ assert_nothing_raised do
21
+ Measured::Cache::Json.new(filename)
22
+ end
23
+ end
24
+ end
25
+
26
+ test "#initialize rejects invalid cache filenames" do
27
+ invalid_files = ["volum.json", "../volume.json", "other.txt"]
28
+ invalid_files.each do |filename|
29
+ assert_raises ArgumentError do
30
+ Measured::Cache::Json.new(filename)
31
+ end
32
+ end
33
+ end
34
+
17
35
  test "#exist? returns false if the file does not exist" do
18
36
  File.expects(:exist?).with(@cache.path).returns(false)
19
37
  refute_predicate @cache, :exist?
@@ -39,6 +39,12 @@ class Measured::Rails::ValidationTest < ActiveSupport::TestCase
39
39
  assert_equal ["Length is not a valid unit"], thing.errors.full_messages
40
40
  end
41
41
 
42
+ test "validation sets error codes when unit is invalid" do
43
+ thing.length_unit = "junk"
44
+ refute thing.valid?
45
+ assert thing.errors.of_kind?(:length, :invalid)
46
+ end
47
+
42
48
  test "validation can override the message with a static string" do
43
49
  thing.length_message_unit = "junk"
44
50
  refute thing.valid?
@@ -181,6 +187,28 @@ class Measured::Rails::ValidationTest < ActiveSupport::TestCase
181
187
  refute thing.valid?
182
188
  end
183
189
 
190
+ test "validation for numericality puts the proper error types" do
191
+ thing.length_numericality_inclusive_value = 5
192
+ refute thing.valid?
193
+ assert thing.errors.of_kind?(:length_numericality_inclusive, :greater_than_or_equal_to)
194
+
195
+ thing.length_numericality_inclusive_value = 25
196
+ refute thing.valid?
197
+ assert thing.errors.of_kind?(:length_numericality_inclusive, :less_than_or_equal_to)
198
+
199
+ thing.length_numericality_exclusive_value = 2
200
+ refute thing.valid?
201
+ assert thing.errors.of_kind?(:length_numericality_exclusive, :greater_than)
202
+
203
+ thing.length_numericality_exclusive_value = 550
204
+ refute thing.valid?
205
+ assert thing.errors.of_kind?(:length_numericality_exclusive, :less_than)
206
+
207
+ thing.length_numericality_equality_value = 200
208
+ refute thing.valid?
209
+ assert thing.errors.of_kind?(:length_numericality_equality, :equal_to)
210
+ end
211
+
184
212
  test "validation for numericality handles a nil unit but a valid value" do
185
213
  thing.length_numericality_exclusive_unit = nil
186
214
  thing.length_numericality_exclusive_value = 1
metadata CHANGED
@@ -1,16 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: measured
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.0
4
+ version: 3.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kevin McPhillips
8
8
  - Jason Gedge
9
9
  - Javier Honduvilla Coto
10
- autorequire:
11
10
  bindir: bin
12
11
  cert_chain: []
13
- date: 2024-10-03 00:00:00.000000000 Z
12
+ date: 1980-01-02 00:00:00.000000000 Z
14
13
  dependencies:
15
14
  - !ruby/object:Gem::Dependency
16
15
  name: activesupport
@@ -227,7 +226,6 @@ licenses:
227
226
  - MIT
228
227
  metadata:
229
228
  allowed_push_host: https://rubygems.org
230
- post_install_message:
231
229
  rdoc_options: []
232
230
  require_paths:
233
231
  - lib
@@ -242,8 +240,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
242
240
  - !ruby/object:Gem::Version
243
241
  version: '0'
244
242
  requirements: []
245
- rubygems_version: 3.5.20
246
- signing_key:
243
+ rubygems_version: 3.6.9
247
244
  specification_version: 4
248
245
  summary: Encapsulate measurements with their units in Ruby
249
246
  test_files: