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 +4 -4
- data/.github/dependabot.yml +4 -0
- data/.github/workflows/ci.yml +2 -2
- data/.github/workflows/dependabot_auto_merge.yml +4 -4
- data/CHANGELOG.md +7 -0
- data/lib/measured/cache/json.rb +2 -1
- data/lib/measured/rails/validations.rb +3 -3
- data/lib/measured/version.rb +1 -1
- data/test/cache/json_test.rb +18 -0
- data/test/rails/validation_test.rb +28 -0
- metadata +3 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1e8794e944fe077ce5f8fe1271de15dbd7aae08e9faa25870d5a2f1df2fecfe3
|
4
|
+
data.tar.gz: d6250b4975dbf4a2972b998cc68971b983f6ee2d45c2a22fe7839d672c951233
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 30590d0e624813f1cbc0bc8bbe5a397b0197e799cd36070c91eba906890cea07fbf2b1755db57fc73aea8e1ce5bbf220edd608cf27ee809afccc0d18a0abafe7
|
7
|
+
data.tar.gz: 4197246ef6225ab834396b9287e705d1e12878f90ed9892a372d552c566ab387cfee24b083f0a6018a4e6515d1245167db548f123521c510af1671a835373599
|
data/.github/dependabot.yml
CHANGED
@@ -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:
|
data/.github/workflows/ci.yml
CHANGED
@@ -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
data/lib/measured/cache/json.rb
CHANGED
@@ -5,7 +5,8 @@ module Measured::Cache
|
|
5
5
|
|
6
6
|
def initialize(filename)
|
7
7
|
@filename = filename
|
8
|
-
|
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
|
data/lib/measured/version.rb
CHANGED
data/test/cache/json_test.rb
CHANGED
@@ -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
|
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:
|
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.
|
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:
|