Skip to content

Commit

Permalink
Test fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
fbacall committed Feb 2, 2024
1 parent c8e4fe2 commit f1bcf97
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 13 deletions.
8 changes: 8 additions & 0 deletions app/policies/learning_path_topic_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,12 @@ def update?
super || @record.collaborator?(@user)
end

def manage?
curators_and_admin
end

def create?
curators_and_admin
end

end
4 changes: 2 additions & 2 deletions test/fixtures/learning_path_topics.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
good_and_bad:
title: My Learning Path Topic
description: MyText
user: regular_user
user: admin
keywords: ["Learning", "Discovery"]

goblet_things:
title: Another Learning Path Topic
description: Some text
user: regular_user
user: admin
keywords: ["Interesting"]
2 changes: 1 addition & 1 deletion test/fixtures/learning_paths.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,5 @@ archived_learning_path:
title: This Learning Path Is Hidden
description: MyText
public: false
user: admin
user: curator
status: development
21 changes: 13 additions & 8 deletions test/models/learning_path_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,20 @@

class LearningPathTest < ActiveSupport::TestCase
test 'visibility scope' do
assert_not_includes LearningPath.visible_by(nil), learning_paths(:archived_learning_path)
assert_not_includes LearningPath.visible_by(users(:another_regular_user)), learning_paths(:archived_learning_path)
assert_includes LearningPath.visible_by(users(:regular_user)), learning_paths(:archived_learning_path)
assert_includes LearningPath.visible_by(users(:admin)), learning_paths(:archived_learning_path)
archived = learning_paths(:archived_learning_path)
archived.collaborators << users(:another_regular_user)
assert_not_includes LearningPath.visible_by(nil), archived
assert_not_includes LearningPath.visible_by(users(:regular_user)), archived
assert_includes LearningPath.visible_by(users(:admin)), archived
assert_includes LearningPath.visible_by(users(:curator)), archived
assert_includes LearningPath.visible_by(users(:another_regular_user)), archived

assert_includes LearningPath.visible_by(nil), learning_paths(:one)
assert_includes LearningPath.visible_by(users(:another_regular_user)), learning_paths(:one)
assert_includes LearningPath.visible_by(users(:regular_user)), learning_paths(:one)
assert_includes LearningPath.visible_by(users(:admin)), learning_paths(:one)
visible = learning_paths(:one)
assert_includes LearningPath.visible_by(nil), visible
assert_includes LearningPath.visible_by(users(:regular_user)), visible
assert_includes LearningPath.visible_by(users(:admin)), visible
assert_includes LearningPath.visible_by(users(:curator)), visible
assert_includes LearningPath.visible_by(users(:another_regular_user)), visible
end

test 'add topic to learning path' do
Expand Down
7 changes: 5 additions & 2 deletions test/models/user_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -282,8 +282,6 @@ class UserTest < ActiveSupport::TestCase
assert_equal user, source.user
assert_equal user, collection.user
assert_equal user, node.user
assert_equal user, learning_path.user
assert_equal user, learning_path_topic.user

user.destroy!

Expand All @@ -295,6 +293,11 @@ class UserTest < ActiveSupport::TestCase
assert_equal default_user, source.reload.user
assert_equal default_user, collection.reload.user
assert_equal default_user, node.reload.user

admin = users(:admin)
assert_equal admin, learning_path.user
assert_equal admin, learning_path_topic.user
admin.destroy!
assert_equal default_user, learning_path.reload.user
assert_equal default_user, learning_path_topic.reload.user
end
Expand Down

0 comments on commit f1bcf97

Please sign in to comment.