We have three filters: "pending", "all" and "reviewed". Where "pending" is the default one. Now we are rendering the `shared/_filter_subnav` partial we need to stub helper methods defined at the controller and the helper methods that rely on the request parameters to test the component.
47 lines
1.2 KiB
Ruby
47 lines
1.2 KiB
Ruby
class SDGManagement::RelationsController < SDGManagement::BaseController
|
|
before_action :check_feature_flags
|
|
before_action :load_record, only: [:edit, :update]
|
|
|
|
FILTERS = %w[pending_sdg_review all sdg_reviewed].freeze
|
|
has_filters FILTERS, only: :index
|
|
|
|
def index
|
|
@records = relatable_class
|
|
.send(@current_filter)
|
|
.accessible_by(current_ability)
|
|
.by_goal(params[:goal_code])
|
|
.by_target(params[:target_code])
|
|
.order(:id)
|
|
.page(params[:page])
|
|
|
|
@records = @records.search(params[:search]) if params[:search].present?
|
|
end
|
|
|
|
def edit
|
|
end
|
|
|
|
def update
|
|
@record.sdg_target_list = params[@record.class.table_name.singularize][:sdg_target_list]
|
|
|
|
redirect_to action: :index
|
|
end
|
|
|
|
private
|
|
|
|
def load_record
|
|
@record = relatable_class.find(params[:id])
|
|
end
|
|
|
|
def relatable_class
|
|
params[:relatable_type].classify.constantize
|
|
end
|
|
|
|
def check_feature_flags
|
|
process_name = params[:relatable_type].split("/").first
|
|
process_name = process_name.pluralize unless process_name == "legislation"
|
|
|
|
check_feature_flag(process_name)
|
|
raise FeatureDisabled, process_name unless Setting["sdg.process.#{process_name}"]
|
|
end
|
|
end
|