Skip to content

Commit

Permalink
Test each activity can render without error
Browse files Browse the repository at this point in the history
  • Loading branch information
fbacall committed Jan 2, 2025
1 parent b4c7a6d commit 0ed9f0b
Show file tree
Hide file tree
Showing 4 changed files with 117 additions and 1 deletion.
7 changes: 6 additions & 1 deletion app/controllers/activities_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,15 @@
class ActivitiesController < ApplicationController

before_action :set_resource, only: [:index]
before_action :set_breadcrumbs
before_action :set_breadcrumbs, only: [:index]

MODELS = %w[content_provider material collection event node workflow source learning_path learning_path_topic].freeze

def show
raise ActionController::RoutingError.new("") unless current_user&.is_admin?
@activity = PublicActivity::Activity.find(params[:id])
end

def index
if request.xhr?
@activities = @resource.activities.order('created_at desc')
Expand Down
3 changes: 3 additions & 0 deletions app/views/activities/show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<h1>Activity</h1>

<%= render_activity(@activity, layout: :activity, display: "common/#{@activity.key.split('.').last}") %>
2 changes: 2 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@
end
end

resources :activities, only: [:show]

get 'stars' => 'stars#index'
post 'stars' => 'stars#create'
delete 'stars' => 'stars#destroy'
Expand Down
106 changes: 106 additions & 0 deletions test/controllers/activities_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,110 @@ class ActivitiesControllerTest < ActionController::TestCase

assert_select '.activity span.label', text: 'Approval requested'
end

test 'should render each activity' do
resources = {
collection: collections(:one),
content_provider: content_providers(:goblet),
event: events(:one),
learning_path: learning_paths(:one),
learning_path_topic: learning_path_topics(:good_and_bad),
learning_path_topic_item: learning_path_topic_items(:item1a),
material: materials(:good_material),
node: nodes(:good),
source: sources(:first_source),
user: users(:regular_user),
workflow: workflows(:one)
}

resources[:collection].events << resources[:event]
resources[:collection_item] = resources[:collection].items.first

activities = {
'collection.add_event' => { event_title: resources[:event].title, event_id: resources[:event].id },
'collection.add_item' => { resource_type: 'Event', resource_title: resources[:event].title, resource_id: resources[:event].id },
'collection.add_material' => { material_title: resources[:material].title, material_id: resources[:material].id },
'collection.create' => {},
'collection.destroy' => {},
'collection.update' => {},
'collection.update_parameter' => { attr: 'title', new_val: 'Hello' },

'content_provider.create' => {},
'content_provider.destroy' => {},
'content_provider.update' => {},
'content_provider.update_parameter' => { attr: 'title', new_val: 'Hello' },

'event.add_data' => { data_field: 'geographic_coordinates', data_value: [25, 25] },
'event.add_term' => { uri: 'http://edamontology.org/topic_3372', name: 'Software engineering', field: 'topics' },
'event.add_to_collection' => { collection_title: resources[:collection].title, collection_id: resources[:collection].id },
'event.create' => {},
'event.destroy' => {},
'event.reject_data' => { data_field: 'geographic_coordinates', data_value: [25, 25] },
'event.reject_term' => { uri: 'http://edamontology.org/topic_3372', name: 'Software engineering', field: 'topics' },
'event.report' => {},
'event.update' => {},
'event.update_parameter' => { attr: 'content_provider_id', association_name: 'new-provider!', new_val: resources[:content_provider].id },

'learning_path.add_topic' => { topic_title: resources[:learning_path_topic].title, topic_id: resources[:learning_path_topic].id },
'learning_path.create' => {},
'learning_path.destroy' => {},
'learning_path.update' => {},
'learning_path.update_parameter' => { attr: 'title', new_val: 'Hello' },

'learning_path_topic.add_item' => { resource_type: 'Material', resource_title: resources[:material].title, resource_id: resources[:material].id },
'learning_path_topic.create' => {},
'learning_path_topic.destroy' => {},
'learning_path_topic.update' => {},
'learning_path_topic.update_parameter' => { attr: 'title', new_val: 'Hello' },

'material.add_data' => { data_field: 'title', data_value: 'Hello World!' },
'material.add_term' => { uri: 'http://edamontology.org/topic_3372', name: 'Software engineering', field: 'topics' },
'material.add_to_collection' => { collection_title: resources[:collection].title, collection_id: resources[:collection].id },
'material.add_to_topic' => { topic_title: resources[:learning_path_topic].title, topic_id: resources[:learning_path_topic].id },
'material.create' => {},
'material.destroy' => {},
'material.reject_data' => { data_field: 'title', data_value: 'Hello World!' },
'material.reject_term' => { uri: 'http://edamontology.org/topic_3372', name: 'Software engineering', field: 'topics' },
'material.update' => {},
'material.update_parameter' => { attr: 'title', new_val: 'Hello' },

'node.create' => {},
'node.destroy' => {},
'node.update' => {},
'node.update_parameter' => { attr: 'title', new_val: 'Hello' },

'source.approval_status_changed' => { old: 'not_approved', new: 'requested' },
'source.create' => {},
'source.destroy' => {},
'source.update' => {},
'source.update_parameter' => { attr: 'title', new_val: 'Hello' },

'user.change_role' => { old: roles(:unverified_user).id, new: roles(:basic_user).id },
'user.create' => {},
'user.destroy' => {},
'user.update' => {},
'user.update_parameter' => { attr: 'title', new_val: 'Hello' },

'workflow.create' => {},
'workflow.destroy' => {},
'workflow.modify_diagram' => {
added_nodes: [{ 'data' => { 'name' => 'Node 1' } }, { 'data' => { 'name' => 'Node 2' } }],
removed_nodes: [],
modified_nodes: [{ 'data' => { 'name' => 'Node A' } }, { 'data' => { 'name' => 'Node B' } }],
},
'workflow.update' => {},
'workflow.update_parameter' => { attr: 'title', new_val: 'Hello' }
}

user = users(:admin)
sign_in(user)
activities.each do |key, parameters|
resource_key = key.split('.').first.to_sym
resource = resources[resource_key]
raise "Missing resource: #{resource_key}" unless resource
activity = resource.activities.create!(key: key, owner: user, parameters: parameters)
get :show, params: { id: activity.id }
assert_response :success, "Error rendering #{key} activity"
end
end
end

0 comments on commit 0ed9f0b

Please sign in to comment.