Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions app/assets/stylesheets/application.scss
Original file line number Diff line number Diff line change
Expand Up @@ -1111,3 +1111,7 @@ td.day .calendar-text {
display: flex;
justify-content: center;
}

.tag-topic, .tag-operation {
text-decoration: none;
}
47 changes: 29 additions & 18 deletions app/helpers/materials_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,17 +71,15 @@ def display_attribute(resource, attribute, show_label: true, title: nil, markdow
].any?

value = resource.send(attribute)
if markdown
value = render_markdown(value)
end
value = render_markdown(value) if markdown
if value.present?
if list
value = value.map do |v|
html_escape(block_given? ? yield(v) : v)
end
else
value = html_escape(block_given? ? yield(value) : value)
end
value = if list
value.map do |v|
html_escape(block_given? ? yield(v) : v)
end
else
html_escape(block_given? ? yield(value) : value)
end
end
string = "<p class=\"#{attribute}#{show_label ? ' no-spacing' : ''}\">"
unless value.blank? || value.try(:strip) == 'License Not Specified'
Expand Down Expand Up @@ -119,18 +117,31 @@ def embed_youtube(material)
def keywords_and_topics(resource, limit: nil)
tags = []

%i[scientific_topic_names operation_names keywords].each do |field|
tags |= resource.send(field) if resource.respond_to?(field)
if resource.respond_to?(:scientific_topics)
tags += resource.scientific_topics.map do |term|
content_tag(:span, class: 'label label-info tag-topic') do
content_tag(:i, '', class: 'fa fa-flask') + ' ' + term.preferred_label
end
end
end

limit_exceeded = limit && (tags.length > limit)
tags = tags.first(limit) if limit
if resource.respond_to?(:operations)
tags += resource.operations.map do |term|
content_tag(:span, class: 'label label-info tag-operation') do
content_tag(:i, '', class: 'fa fa-cogs') + ' ' + term.preferred_label
end
end
end

elements = tags.map do |tag|
content_tag(:span, tag, class: 'label label-info')
if resource.respond_to?(:keywords)
tags += resource.keywords.map do |tag|
content_tag(:span, tag, class: 'label label-info tag-keyword')
end
end
elements << '&hellip;' if limit_exceeded

elements.join(' ').html_safe
limit_exceeded = limit && (tags.length > limit)
tags = tags.first(limit) if limit
tags << '&hellip;'.html_safe if limit_exceeded
safe_join(tags, ' ')
end
end
8 changes: 6 additions & 2 deletions app/views/common/_extra_metadata.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@
<%= display_attribute(resource, :contributors) { |values| values.join(', ') } if resource.respond_to?(:contributors) %>
<%= display_attribute(resource, :remote_created_date) if resource.respond_to?(:remote_created_date) %>
<%= display_attribute(resource, :remote_updated_date) if resource.respond_to?(:remote_updated_date) %>
<%= display_attribute(resource, :scientific_topics) { |values| values.map { |x| x.preferred_label }.join(', ') } %>
<%= display_attribute(resource, :scientific_topics) {
|values| safe_join(values.map { |x| link_to(x.preferred_label, x.uri, target: '_blank') }, ', ')
} %>

<% if resource.is_a?(LearningPath) %>
<%= display_attribute(resource, :status) { |value| material_status_title_for_label(value) } %>
Expand All @@ -73,5 +75,7 @@
<% end %>

<% if resource.respond_to?(:operations) -%>
<%= display_attribute(resource, :operations) { |values| values.map { |x| x.preferred_label }.join(', ') } %>
<%= display_attribute(resource, :operations) {
|values| safe_join(values.map { |x| link_to(x.preferred_label, x.uri, target: '_blank') }, ', ')
} %>
<% end %>
59 changes: 30 additions & 29 deletions test/controllers/learning_paths_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class LearningPathsControllerTest < ActionController::TestCase
description: 'New description'
}
end
#INDEX TESTS
# INDEX TESTS
test 'should get index' do
get :index
assert_response :success
Expand Down Expand Up @@ -49,7 +49,7 @@ class LearningPathsControllerTest < ActionController::TestCase
assert_equal learning_paths_path, body['links']['self']
end

#NEW TESTS
# NEW TESTS

test 'should get new page for curators and admins only' do
get :new
Expand All @@ -72,14 +72,14 @@ class LearningPathsControllerTest < ActionController::TestCase
assert_response :success
end

#EDIT TESTS
# EDIT TESTS
test 'should not get edit page for not logged in users' do
#Not logged in = Redirect to login
# Not logged in = Redirect to login
get :edit, params: { id: @learning_path }
assert_redirected_to new_user_session_path
end

#logged in but insufficient permissions = ERROR
# logged in but insufficient permissions = ERROR
test 'should get edit for learning_path owner' do
sign_in @learning_path.user
get :edit, params: { id: @learning_path }
Expand All @@ -93,20 +93,20 @@ class LearningPathsControllerTest < ActionController::TestCase
end

test 'should get edit for admin' do
#Owner of learning_path logged in = SUCCESS
# Owner of learning_path logged in = SUCCESS
sign_in users(:admin)
get :edit, params: { id: @learning_path }
assert_response :success
end

test 'should not get edit page for regular user' do
#Administrator = SUCCESS
# Administrator = SUCCESS
sign_in users(:another_regular_user)
get :edit, params: { id: @learning_path }
assert :forbidden
end

#CREATE TEST
# CREATE TEST
test 'should create learning_path for curator' do
sign_in users(:curator)
assert_difference('LearningPath.count') do
Expand Down Expand Up @@ -146,7 +146,7 @@ class LearningPathsControllerTest < ActionController::TestCase
assert_redirected_to new_user_session_path
end

#SHOW TEST
# SHOW TEST
test 'should show learning_path' do
get :show, params: { id: @learning_path }
assert_response :success
Expand Down Expand Up @@ -183,21 +183,22 @@ class LearningPathsControllerTest < ActionController::TestCase
assert_equal learning_path_path(assigns(:learning_path)), body['data']['links']['self']
end

#UPDATE TEST
# UPDATE TEST
test 'should update learning_path' do
sign_in @learning_path.user
patch :update, params: { id: @learning_path, learning_path: @updated_learning_path }
assert_redirected_to learning_path_path(assigns(:learning_path))
end

test "should add topics to learning_path" do
test 'should add topics to learning_path' do
sign_in @learning_path.user
learning_path = learning_paths(:two)
assert_no_difference('LearningPathTopic.count') do
assert_difference('LearningPathTopicLink.count', 1) do
assert_difference('learning_path.topics.count', 1) do
patch :update, params: { learning_path: {
topic_links_attributes: { '1': { topic_id: learning_path_topics(:goblet_things).id, order: 300 } } },
topic_links_attributes: { '1': { topic_id: learning_path_topics(:goblet_things).id, order: 300 } }
},
id: learning_path.id }
end
end
Expand All @@ -211,14 +212,15 @@ class LearningPathsControllerTest < ActionController::TestCase
assert_equal learning_path_topics(:goblet_things), links[1].topic
end

test "should remove topic from learning_path" do
test 'should remove topic from learning_path' do
sign_in @learning_path.user
learning_path = learning_paths(:two)
assert_no_difference('LearningPathTopic.count') do
assert_difference('LearningPathTopicLink.count', -1) do
assert_difference('learning_path.topics.count', -1) do
patch :update, params: { learning_path: {
topic_links_attributes: { '1': { id: learning_path.topic_link_ids.first, _destroy: '1' } } },
topic_links_attributes: { '1': { id: learning_path.topic_link_ids.first, _destroy: '1' } }
},
id: learning_path.id }
end
end
Expand All @@ -227,7 +229,7 @@ class LearningPathsControllerTest < ActionController::TestCase
assert_empty assigns(:learning_path).topic_links
end

test "should modify items in learning_path" do
test 'should modify items in learning_path' do
sign_in @learning_path.user

l1 = @learning_path.topic_links[0]
Expand All @@ -248,7 +250,7 @@ class LearningPathsControllerTest < ActionController::TestCase
end
end

#DESTROY TEST
# DESTROY TEST
test 'should destroy learning_path owned by user' do
sign_in @learning_path.user
assert_difference('LearningPath.count', -1) do
Expand All @@ -273,9 +275,8 @@ class LearningPathsControllerTest < ActionController::TestCase
assert_response :forbidden
end


#CONTENT TESTS
#BREADCRUMBS
# CONTENT TESTS
# BREADCRUMBS
test 'breadcrumbs for learning_paths index' do
get :index
assert_response :success
Expand Down Expand Up @@ -326,7 +327,7 @@ class LearningPathsControllerTest < ActionController::TestCase
end
end

#OTHER CONTENT
# OTHER CONTENT
test 'learning path lists topics' do
sign_in(users(:regular_user))

Expand All @@ -344,17 +345,17 @@ class LearningPathsControllerTest < ActionController::TestCase
get :show, params: { id: @learning_path }

assert_response :success
assert_select 'a.btn[href=?]', edit_learning_path_path(@learning_path), count: 0 #No Edit
assert_select 'a.btn[href=?]', learning_path_path(@learning_path), count: 0 #No Edit
assert_select 'a.btn[href=?]', edit_learning_path_path(@learning_path), count: 0 # No Edit
assert_select 'a.btn[href=?]', learning_path_path(@learning_path), count: 0 # No Edit
end

test 'do not show action buttons when not owner or admin' do
sign_in users(:another_regular_user)

get :show, params: { id: @learning_path }

assert_select 'a.btn[href=?]', edit_learning_path_path(@learning_path), count: 0 #No Edit
assert_select 'a.btn[href=?]', learning_path_path(@learning_path), count: 0 #No Edit
assert_select 'a.btn[href=?]', edit_learning_path_path(@learning_path), count: 0 # No Edit
assert_select 'a.btn[href=?]', learning_path_path(@learning_path), count: 0 # No Edit
end

test 'show action buttons when learning_path_curator' do
Expand All @@ -375,7 +376,7 @@ class LearningPathsControllerTest < ActionController::TestCase
assert_select 'a.btn[href=?]', learning_path_path(@learning_path), text: 'Delete', count: 1
end

#API Actions
# API Actions
test 'should not allow access to private learning_paths' do
sign_in users(:regular_user)
get :show, params: { id: learning_paths(:in_development_learning_path) }
Expand Down Expand Up @@ -453,11 +454,11 @@ class LearningPathsControllerTest < ActionController::TestCase

assert_difference('LearningPathTopicLink.count', -1) do
patch :update, params: { learning_path: {
topic_links_attributes: { '1': { id: @learning_path.topic_link_ids.first, _destroy: '1' } } },
topic_links_attributes: { '1': { id: @learning_path.topic_link_ids.first, _destroy: '1' } }
},
id: @learning_path.id }
assert_redirected_to learning_path_path(assigns(:learning_path))
end

end

test 'should not allow non-collaborator to edit' do
Expand Down Expand Up @@ -511,10 +512,10 @@ class LearningPathsControllerTest < ActionController::TestCase
end

response_materials = body.dig('data', 'relationships', 'materials', 'data')
assert_equal [materials[1].id, materials[0].id, materials[2].id], response_materials.map { |m| m['id'].to_i }
assert_equal([materials[1].id, materials[0].id, materials[2].id], response_materials.map { |m| m['id'].to_i })

response_events = body.dig('data', 'relationships', 'events', 'data')
assert_equal [events[1].id, events[0].id], response_events.map { |e| e['id'].to_i }
assert_equal([events[1].id, events[0].id], response_events.map { |e| e['id'].to_i })
end

test 'should include back-reference to learning path in item links' do
Expand Down
Loading
Loading