Skip to content

Commit 51fe6fc

Browse files
authored
fix: update tests to avoid warning syntax (#47)
1 parent 4d748e3 commit 51fe6fc

14 files changed

+102
-67
lines changed

.github/workflows/ruby.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,8 @@ jobs:
1212
strategy:
1313
fail-fast: false
1414
matrix:
15-
ruby-version: ['3.2', '3.3', '3.4']
15+
ruby-version: ['3.2', '3.4']
1616
gemfiles:
17-
- gemfiles/active_model_7.1.gemfile
1817
- gemfiles/active_model_7.2.gemfile
1918
- gemfiles/active_model_8.0.gemfile
2019
- gemfiles/active_model_edge.gemfile

.rubocop.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
AllCops:
2+
NewCops: enable
3+
TargetRubyVersion: 3.0
4+
SuggestExtensions: false
5+
6+
# Allow nested method definitions in tests - they're used for test setup
7+
Lint/NestedMethodDefinition:
8+
Exclude:
9+
- 'test/**/*_test.rb'
10+
11+
# Test setup methods can be longer
12+
Metrics/MethodLength:
13+
Exclude:
14+
- 'test/**/*_test.rb'
15+
- 'test/test_helper.rb'
16+
Max: 10
17+
18+
# Use bracket style for percent literals
19+
Style/PercentLiteralDelimiters:
20+
PreferredDelimiters:
21+
'%w': '[]'
22+
'%W': '[]'
23+
'%i': '[]'
24+
'%I': '[]'
25+
26+
# The save method in tests returns a boolean, it's not a predicate method
27+
Naming/PredicateMethod:
28+
Exclude:
29+
- 'test/**/*_test.rb'
30+
31+
# In tests, we sometimes need empty initialize methods for stubbing
32+
Style/RedundantInitialize:
33+
Exclude:
34+
- 'test/**/*_test.rb'

state_machines-activemodel.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Gem::Specification.new do |spec|
1616
spec.test_files = Dir.glob('test/**/{*_test,test_*}.rb')
1717
spec.require_paths = ['lib']
1818
spec.required_ruby_version = '>= 3.2.0'
19-
spec.add_dependency 'state_machines', '>= 0.100.0'
19+
spec.add_dependency 'state_machines', '>= 0.100.1'
2020
spec.add_dependency 'activemodel', '>= 7.2'
2121

2222
spec.add_development_dependency 'bundler', '>= 1.6'

test/integration_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def test_should_match_if_class_includes_validations_feature
2020
end
2121

2222
def test_should_not_match_if_class_does_not_include_active_model_features
23-
refute StateMachines::Integrations::ActiveModel.matches?(new_model)
23+
refute StateMachines::Integrations::ActiveModel.matches?(new_plain_model)
2424
end
2525

2626
def test_should_have_no_defaults

test/machine_initialization_compatibility_test.rb

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ class MachineInitializationCompatibilityTest < BaseTestCase
66
def setup
77
@model = new_model do
88
include ActiveModel::Validations
9-
attr_accessor :state
109
end
1110

1211
@machine = StateMachines::Machine.new(@model, initial: :parked)
@@ -31,9 +30,7 @@ def test_should_accept_empty_initialization
3130

3231
def test_should_handle_attribute_aliases
3332
@model.class_eval do
34-
def self.attribute_aliases
35-
{ 'status' => 'state' }
36-
end
33+
alias_attribute :status, :state
3734
end
3835

3936
record = @model.new(status: 'idling')

test/machine_multiple_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
class MachineMultipleTest < BaseTestCase
66
def setup
77
@model = new_model do
8-
model_attribute :status
8+
attribute :status, :string
99
end
1010

1111
@state_machine = StateMachines::Machine.new(@model, initial: :parked, integration: :active_model)

test/machine_with_dirty_attribute_and_custom_attributes_during_loopback_test.rb

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@
55
class MachineWithDirtyAttributeAndCustomAttributesDuringLoopbackTest < BaseTestCase
66
def setup
77
@model = new_model do
8-
include ActiveModel::Dirty
9-
model_attribute :status
10-
define_attribute_methods [:status]
8+
attribute :status, :string
119

1210
def save
13-
super.tap do
11+
if valid?
1412
changes_applied
13+
true
14+
else
15+
false
1516
end
1617
end
1718
end

test/machine_with_dirty_attribute_and_state_events_test.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
class MachineWithDirtyAttributeAndStateEventsTest < BaseTestCase
66
def setup
77
@model = new_model do
8-
include ActiveModel::Dirty
9-
define_attribute_methods [:state]
10-
118
def save
12-
super.tap do
9+
if valid?
1310
changes_applied
11+
true
12+
else
13+
false
1414
end
1515
end
1616
end

test/machine_with_dirty_attributes_and_custom_attribute_test.rb

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@
55
class MachineWithDirtyAttributesAndCustomAttributeTest < BaseTestCase
66
def setup
77
@model = new_model do
8-
include ActiveModel::Dirty
9-
model_attribute :status
10-
define_attribute_methods [:status]
8+
attribute :status, :string
119

1210
def save
13-
super.tap do
11+
if valid?
1412
changes_applied
13+
true
14+
else
15+
false
1516
end
1617
end
1718
end
@@ -26,17 +27,17 @@ def save
2627
end
2728

2829
def test_should_include_state_in_changed_attributes
29-
assert_equal %w(status), @record.changed
30+
assert_equal %w[status], @record.changed
3031
end
3132

3233
def test_should_track_attribute_change
33-
assert_equal %w(parked idling), @record.changes['status']
34+
assert_equal %w[parked idling], @record.changes['status']
3435
end
3536

3637
def test_should_not_reset_changes_on_multiple_transitions
3738
transition = StateMachines::Transition.new(@record, @machine, :ignite, :idling, :idling)
3839
transition.perform
3940

40-
assert_equal %w(parked idling), @record.changes['status']
41+
assert_equal %w[parked idling], @record.changes['status']
4142
end
4243
end

test/machine_with_dirty_attributes_during_loopback_test.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
class MachineWithDirtyAttributesDuringLoopbackTest < BaseTestCase
66
def setup
77
@model = new_model do
8-
include ActiveModel::Dirty
9-
define_attribute_methods [:state]
10-
118
def save
12-
super.tap do
9+
if valid?
1310
changes_applied
11+
true
12+
else
13+
false
1414
end
1515
end
1616
end

0 commit comments

Comments
 (0)