Skip to content

Commit

Permalink
Fix broken tests due to bad syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
fbacall committed Jan 15, 2025
1 parent 655c08a commit bf37a6a
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 39 deletions.
57 changes: 27 additions & 30 deletions test/controllers/materials_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,6 @@ class MaterialsControllerTest < ActionController::TestCase
url: 'http://new.url.com',
content_provider_id: ContentProvider.first.id
}
@material_with_suggestions = materials(:material_with_suggestions)
@updated_material_with_suggestions = {
title: 'New title for suggestion material',
description: 'New description',
url: 'http://new.url.com',
content_provider_id: ContentProvider.first.id
}
@failing_material = materials(:failing_material)
@failing_material.title = 'Fail!'
@monitor = @failing_material.create_link_monitor(url: @failing_material.url, code: 404, fail_count: 5)
Expand Down Expand Up @@ -358,14 +351,13 @@ class MaterialsControllerTest < ActionController::TestCase

#SHOW TEST
test 'should show material' do
get :show, params: { id: @material } do
assert_response :success
assert assigns(:material)
assert_select 'fa-commenting-o', count: 0
assert_select '.broken-link-notice', count: 0
assert_select '.archived-notice', count: 0
assert_select '.learning-path-navigation', count: 0
end
get :show, params: { id: @material }
assert_response :success
assert assigns(:material)
assert_select 'fa-commenting-o', count: 0
assert_select '.broken-link-notice', count: 0
assert_select '.archived-notice', count: 0
assert_select '.learning-path-navigation', count: 0
end

test 'should show material as json' do
Expand Down Expand Up @@ -446,24 +438,29 @@ class MaterialsControllerTest < ActionController::TestCase
end

test 'should apply edit suggestions to material' do
material = materials(:material_with_suggestions)
sign_in users(:admin)
assert_empty @material_with_suggestions.scientific_topics
assert_not_equal @material_with_suggestions.edit_suggestion, nil
get :show, params: { id: @material_with_suggestions } do
assert_response :success
assert_select 'Training Material Example', :count => 1
assert_select 'fa-commenting-o', :count => 1
end
get :edit, params: { id: @material_with_suggestions } do
assert_response :success
assert_select 'fa-commenting-o', :count => 0
assert_select 'a#add-topic-topiconename', :count => 1
assert_select 'a#add-topic-topictwoname', :count => 1
assert_empty material.scientific_topics
refute_nil material.edit_suggestion

get :show, params: { id: material }
assert_response :success
assert_select 'h2', text: 'Material with suggestions', count: 1
assert_select 'i.fa-commenting-o', count: 1
assert_select 'ul[data-uri=?]', 'http://edamontology.org/topic_3168', count: 1
assert_select 'ul[data-uri=?]', 'http://edamontology.org/topic_0199', count: 1

assert_no_difference('EditSuggestion.count') do
post :add_term, params: { id: material.id, field: 'scientific_topics', uri: 'http://edamontology.org/topic_3168' }
end
patch :update, params: { id: @material_with_suggestions, material: @updated_material_with_suggestions } do
assert_redirected_to material_path(assigns(:material))
assert_equal @material_with_suggestions.edit_suggestion, nil
assert_response :success

assert_difference('EditSuggestion.count', -1) do
post :add_term, params: { id: material.id, field: 'scientific_topics', uri: 'http://edamontology.org/topic_0199' }
end
assert_response :success

assert_nil material.reload.edit_suggestion
end

#DESTROY TEST
Expand Down
14 changes: 6 additions & 8 deletions test/controllers/sources_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,12 @@ class SourcesControllerTest < ActionController::TestCase

test 'registered should show source' do
sign_in users(:regular_user)
get :show, params: { id: @source } do
assert_response :success
assert assigns(:source)
assert_select "h4", count: 2
assert_select "h4", { count: 1, text: 'Source Details' }
assert_select "h4", { count: 1, text: 'Last Run' }
assert_select "strong", { count: 1, text: 'No results found' }
end
get :show, params: { id: @source }
assert_response :success
assert assigns(:source)
assert_select 'h4', { count: 1, text: 'Source Details' }
assert_select 'h4', { count: 1, text: 'Last Run' }
assert_select 'strong', { count: 1, text: 'No results found' }
end

# NEW Tests
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/edit_suggestions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ one:
suggestible: material_with_suggestions (Material)

two:
suggestible: material_with_suggestions (Material)
suggestible: failing_material (Material)
data_fields:
fruit: banana

Expand Down

0 comments on commit bf37a6a

Please sign in to comment.