Skip to content

Commit

Permalink
Move validation to policy
Browse files Browse the repository at this point in the history
  • Loading branch information
jorg-vr committed Oct 26, 2023
1 parent bd08828 commit a17cb6a
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 3 deletions.
1 change: 0 additions & 1 deletion app/models/activity.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ class Activity < ApplicationRecord
has_many :labels, through: :activity_labels

validates :path, uniqueness: { scope: :repository_id, case_sensitive: false }, allow_nil: true
validates :draft, inclusion: { in: [false] }, unless: :draft_was

token_generator :repository_token, length: 64
token_generator :access_token
Expand Down
4 changes: 3 additions & 1 deletion app/policies/activity_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ def read?

def permitted_attributes
if update?
%i[access name_nl name_en draft]
permitted_attributes = %i[access name_nl name_en]
permitted_attributes << :draft if record.draft?
permitted_attributes
else
[]
end
Expand Down
2 changes: 1 addition & 1 deletion test/policies/exercise_policy_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ def test_destroy; end
policy = ExercisePolicy.new(create(:temporary_user), create(:exercise, :valid))
User.any_instance.stubs(:repository_admin?).returns(true)

assert_equal %i[access name_nl name_en draft], policy.permitted_attributes
assert_equal %i[access name_nl name_en], policy.permitted_attributes
end
end

0 comments on commit a17cb6a

Please sign in to comment.