Project

General

Profile

« Previous | Next » 

Revision f1313e54

Added by Nofar Alfassi 4 months ago

Fixes #37015 - Refactor OwnerClassifier

- Introduce `classify_owner` class method for owner classification.
- Implement private method for input validation.
- Add error handling to raise the necessary exceptions.
- Add deprecation warning to the `user_or_usergroup` method.

View differences:

test/unit/owner_classifier_test.rb
class OwnerClassifierTest < ActiveSupport::TestCase
test "Should return user if id_and_type is a user" do
usergrop = FactoryBot.create(:user)
id_and_type = usergrop.id_and_type
assert_equal usergrop, OwnerClassifier.new(id_and_type).user_or_usergroup
user = FactoryBot.create(:user)
id_and_type = user.id_and_type
assert_equal user, OwnerClassifier.classify_owner(id_and_type)
end
test "Should return usergroup if id_and_type is a usergroup" do
usergrop = FactoryBot.create(:usergroup)
id_and_type = usergrop.id_and_type
assert_equal usergrop, OwnerClassifier.new(id_and_type).user_or_usergroup
usergroup = FactoryBot.create(:usergroup)
id_and_type = usergroup.id_and_type
assert_equal usergroup, OwnerClassifier.classify_owner(id_and_type)
end
test "Should return nil if id_and_type does not exist" do
test "Should raise exception if id_and_type does not exist" do
id_and_type = "0-Users"
assert_nil OwnerClassifier.new(id_and_type).user_or_usergroup
assert_raises(ActiveRecord::RecordNotFound) { OwnerClassifier.classify_owner(id_and_type) }
end
test "Should return nil if id_and_type is ilegal" do
test "Should raise exception if id_and_type format is invalid" do
id_and_type = "5-UsErS"
assert_nil OwnerClassifier.new(id_and_type).user_or_usergroup
assert_raises(ArgumentError) { OwnerClassifier.classify_owner(id_and_type) }
end
test "Deprecated method: user_or_usergroup should return user if id_and_type is a user" do
user = FactoryBot.create(:user)
id_and_type = user.id_and_type
assert_deprecated do
owner = OwnerClassifier.new(id_and_type).user_or_usergroup
assert_equal user, owner
end
end
end

Also available in: Unified diff