Skip to content

Commit 77109ab

Browse files
committed
Test clickable ontology terms
1 parent f58261e commit 77109ab

5 files changed

Lines changed: 190 additions & 149 deletions

File tree

app/helpers/materials_helper.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,9 @@ def keywords_and_topics(resource, limit: nil)
135135
end
136136
end
137137

138+
limit_exceeded = limit && (tags.length > limit)
138139
tags = tags.first(limit) if limit
139-
tags << '&hellip;' if limit && (tags.length > limit)
140+
tags << '&hellip;'.html_safe if limit_exceeded
140141
safe_join(tags, ' ')
141142
end
142143
end

test/controllers/learning_paths_controller_test.rb

Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class LearningPathsControllerTest < ActionController::TestCase
1212
description: 'New description'
1313
}
1414
end
15-
#INDEX TESTS
15+
# INDEX TESTS
1616
test 'should get index' do
1717
get :index
1818
assert_response :success
@@ -49,7 +49,7 @@ class LearningPathsControllerTest < ActionController::TestCase
4949
assert_equal learning_paths_path, body['links']['self']
5050
end
5151

52-
#NEW TESTS
52+
# NEW TESTS
5353

5454
test 'should get new page for curators and admins only' do
5555
get :new
@@ -72,14 +72,14 @@ class LearningPathsControllerTest < ActionController::TestCase
7272
assert_response :success
7373
end
7474

75-
#EDIT TESTS
75+
# EDIT TESTS
7676
test 'should not get edit page for not logged in users' do
77-
#Not logged in = Redirect to login
77+
# Not logged in = Redirect to login
7878
get :edit, params: { id: @learning_path }
7979
assert_redirected_to new_user_session_path
8080
end
8181

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

9595
test 'should get edit for admin' do
96-
#Owner of learning_path logged in = SUCCESS
96+
# Owner of learning_path logged in = SUCCESS
9797
sign_in users(:admin)
9898
get :edit, params: { id: @learning_path }
9999
assert_response :success
100100
end
101101

102102
test 'should not get edit page for regular user' do
103-
#Administrator = SUCCESS
103+
# Administrator = SUCCESS
104104
sign_in users(:another_regular_user)
105105
get :edit, params: { id: @learning_path }
106106
assert :forbidden
107107
end
108108

109-
#CREATE TEST
109+
# CREATE TEST
110110
test 'should create learning_path for curator' do
111111
sign_in users(:curator)
112112
assert_difference('LearningPath.count') do
@@ -146,7 +146,7 @@ class LearningPathsControllerTest < ActionController::TestCase
146146
assert_redirected_to new_user_session_path
147147
end
148148

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

186-
#UPDATE TEST
186+
# UPDATE TEST
187187
test 'should update learning_path' do
188188
sign_in @learning_path.user
189189
patch :update, params: { id: @learning_path, learning_path: @updated_learning_path }
190190
assert_redirected_to learning_path_path(assigns(:learning_path))
191191
end
192192

193-
test "should add topics to learning_path" do
193+
test 'should add topics to learning_path' do
194194
sign_in @learning_path.user
195195
learning_path = learning_paths(:two)
196196
assert_no_difference('LearningPathTopic.count') do
197197
assert_difference('LearningPathTopicLink.count', 1) do
198198
assert_difference('learning_path.topics.count', 1) do
199199
patch :update, params: { learning_path: {
200-
topic_links_attributes: { '1': { topic_id: learning_path_topics(:goblet_things).id, order: 300 } } },
200+
topic_links_attributes: { '1': { topic_id: learning_path_topics(:goblet_things).id, order: 300 } }
201+
},
201202
id: learning_path.id }
202203
end
203204
end
@@ -211,14 +212,15 @@ class LearningPathsControllerTest < ActionController::TestCase
211212
assert_equal learning_path_topics(:goblet_things), links[1].topic
212213
end
213214

214-
test "should remove topic from learning_path" do
215+
test 'should remove topic from learning_path' do
215216
sign_in @learning_path.user
216217
learning_path = learning_paths(:two)
217218
assert_no_difference('LearningPathTopic.count') do
218219
assert_difference('LearningPathTopicLink.count', -1) do
219220
assert_difference('learning_path.topics.count', -1) do
220221
patch :update, params: { learning_path: {
221-
topic_links_attributes: { '1': { id: learning_path.topic_link_ids.first, _destroy: '1' } } },
222+
topic_links_attributes: { '1': { id: learning_path.topic_link_ids.first, _destroy: '1' } }
223+
},
222224
id: learning_path.id }
223225
end
224226
end
@@ -227,7 +229,7 @@ class LearningPathsControllerTest < ActionController::TestCase
227229
assert_empty assigns(:learning_path).topic_links
228230
end
229231

230-
test "should modify items in learning_path" do
232+
test 'should modify items in learning_path' do
231233
sign_in @learning_path.user
232234

233235
l1 = @learning_path.topic_links[0]
@@ -248,7 +250,7 @@ class LearningPathsControllerTest < ActionController::TestCase
248250
end
249251
end
250252

251-
#DESTROY TEST
253+
# DESTROY TEST
252254
test 'should destroy learning_path owned by user' do
253255
sign_in @learning_path.user
254256
assert_difference('LearningPath.count', -1) do
@@ -273,9 +275,8 @@ class LearningPathsControllerTest < ActionController::TestCase
273275
assert_response :forbidden
274276
end
275277

276-
277-
#CONTENT TESTS
278-
#BREADCRUMBS
278+
# CONTENT TESTS
279+
# BREADCRUMBS
279280
test 'breadcrumbs for learning_paths index' do
280281
get :index
281282
assert_response :success
@@ -326,7 +327,7 @@ class LearningPathsControllerTest < ActionController::TestCase
326327
end
327328
end
328329

329-
#OTHER CONTENT
330+
# OTHER CONTENT
330331
test 'learning path lists topics' do
331332
sign_in(users(:regular_user))
332333

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

346347
assert_response :success
347-
assert_select 'a.btn[href=?]', edit_learning_path_path(@learning_path), count: 0 #No Edit
348-
assert_select 'a.btn[href=?]', learning_path_path(@learning_path), count: 0 #No Edit
348+
assert_select 'a.btn[href=?]', edit_learning_path_path(@learning_path), count: 0 # No Edit
349+
assert_select 'a.btn[href=?]', learning_path_path(@learning_path), count: 0 # No Edit
349350
end
350351

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

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

356-
assert_select 'a.btn[href=?]', edit_learning_path_path(@learning_path), count: 0 #No Edit
357-
assert_select 'a.btn[href=?]', learning_path_path(@learning_path), count: 0 #No Edit
357+
assert_select 'a.btn[href=?]', edit_learning_path_path(@learning_path), count: 0 # No Edit
358+
assert_select 'a.btn[href=?]', learning_path_path(@learning_path), count: 0 # No Edit
358359
end
359360

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

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

454455
assert_difference('LearningPathTopicLink.count', -1) do
455456
patch :update, params: { learning_path: {
456-
topic_links_attributes: { '1': { id: @learning_path.topic_link_ids.first, _destroy: '1' } } },
457+
topic_links_attributes: { '1': { id: @learning_path.topic_link_ids.first, _destroy: '1' } }
458+
},
457459
id: @learning_path.id }
458460
assert_redirected_to learning_path_path(assigns(:learning_path))
459461
end
460-
461462
end
462463

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

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

516517
response_events = body.dig('data', 'relationships', 'events', 'data')
517-
assert_equal [events[1].id, events[0].id], response_events.map { |e| e['id'].to_i }
518+
assert_equal([events[1].id, events[0].id], response_events.map { |e| e['id'].to_i })
518519
end
519520

520521
test 'should include back-reference to learning path in item links' do
@@ -524,7 +525,7 @@ class LearningPathsControllerTest < ActionController::TestCase
524525
topic_link = @learning_path.topic_links.first
525526
topic_item = topic_link.topic.items.first
526527

527-
assert_select '.link-overlay[href=?]',
528+
assert_select '.link-overlay a[href=?]',
528529
material_path(topic_item.resource, lp: [topic_link, topic_item].map(&:id).join(':'))
529530
end
530531

0 commit comments

Comments
 (0)