Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove references to aggregation attribute on Workflows #4339

Merged
merged 7 commits into from
Jun 5, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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: 3 additions & 1 deletion app/models/workflow.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ class Workflow < ApplicationRecord
include Translatable
include Versioning

self.ignored_columns = ['aggregation']

versioned association: :workflow_versions, attributes: %w(tasks first_task strings major_version minor_version)

belongs_to :project
Expand Down Expand Up @@ -44,7 +46,7 @@ class Workflow < ApplicationRecord
'options' => {'count' => 15}
}.freeze

JSON_ATTRIBUTES = %w(tasks retirement aggregation strings steps).freeze
JSON_ATTRIBUTES = %w[tasks retirement strings steps].freeze

SELECTOR_PAGE_SIZE_KEY = 'subject_queue_page_size'.freeze

Expand Down
4 changes: 0 additions & 4 deletions app/schemas/workflow_create_schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,6 @@ class WorkflowCreateSchema < JsonSchema
type "array"
end

property "aggregation" do
type "object"
end

property "configuration" do
type "object"
end
Expand Down
4 changes: 0 additions & 4 deletions app/schemas/workflow_update_schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,6 @@ class WorkflowUpdateSchema < JsonSchema
type "array"
end

property "aggregation" do
type "object"
end

property "configuration" do
type "object"
end
Expand Down
2 changes: 1 addition & 1 deletion app/serializers/workflow_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class WorkflowSerializer
:created_at, :updated_at, :finished_at, :first_task, :primary_language,
:version, :content_language, :prioritized, :grouped, :pairwise,
:retirement, :retired_set_member_subjects_count, :href, :active, :mobile_friendly,
:aggregation, :configuration, :public_gold_standard, :completeness
:configuration, :public_gold_standard, :completeness

can_include :project, :subject_sets, :tutorial_subject, :published_version

Expand Down
8 changes: 4 additions & 4 deletions lib/formatter/csv/workflow.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ module Csv
class Workflow
attr_reader :workflow_version

JSON_FIELDS = [:tasks, :aggregation, :strings ].freeze
JSON_FIELDS = %i[tasks strings].freeze

def headers
%w(workflow_id display_name version active classifications_count pairwise
grouped prioritized primary_language first_task tutorial_subject_id
retired_set_member_subjects_count tasks retirement aggregation strings minor_version)
%w[workflow_id display_name version active classifications_count pairwise
grouped prioritized primary_language first_task tutorial_subject_id
retired_set_member_subjects_count tasks retirement strings minor_version]
end

def to_rows(workflow_version)
Expand Down
71 changes: 36 additions & 35 deletions spec/controllers/api/v1/workflows_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -1,31 +1,33 @@
# frozen_string_literal: true

require 'spec_helper'

describe Api::V1::WorkflowsController, type: :controller do
let(:user) { create(:user) }
let(:workflows) { create_list :workflow_with_contents, 2 }
let(:workflow){ workflows.first }
let(:project){ workflow.project }
let(:owner){ project.owner }
let(:api_resource_name){ 'workflows' }
let(:workflow) { workflows.first }
let(:project) { workflow.project }
let(:owner) { project.owner }
let(:api_resource_name) { 'workflows' }
let(:resource_class) { Workflow }
let(:authorized_user) { owner }
let(:default_params) { { format: :json } }

let(:api_resource_attributes) do
%w(id display_name tasks classifications_count subjects_count
created_at updated_at first_task primary_language content_language
version grouped prioritized pairwise retirement aggregation
active mobile_friendly configuration finished_at steps public_gold_standard)
%w[id display_name tasks classifications_count subjects_count
created_at updated_at first_task primary_language content_language
version grouped prioritized pairwise retirement
active mobile_friendly configuration finished_at steps public_gold_standard]
end
let(:api_resource_links) do
%w(workflows.project workflows.subject_sets workflows.tutorial_subject
workflows.attached_images)
%w[workflows.project workflows.subject_sets workflows.tutorial_subject
workflows.attached_images]
end
let(:scopes) { %w(public project) }
let(:scopes) { %w[public project] }

describe '#index' do
let(:filterable_resources) { create_list(:workflow_with_subjects, 2) }
let(:expected_filtered_ids) { [ filterable_resources.first.id.to_s ] }
let(:expected_filtered_ids) { [filterable_resources.first.id.to_s] }
let(:private_project) { create(:private_project) }
let(:private_resource) { create(:workflow, project: private_project) }
let(:n_visible) { 2 }
Expand All @@ -39,7 +41,7 @@
it_behaves_like 'has many filterable', :subject_sets

describe 'filter by' do
before(:each) do
before do
filterable_resources
default_request user_id: user.id, scopes: scopes
get :index, params: filter_opts
Expand All @@ -51,17 +53,17 @@

it 'only returns activated workflows', :aggregate_failures do
expect(json_response[api_resource_name].length).to eq(2)
expect(json_response[api_resource_name].map{ |w| w['active'] }).to all( be true )
expect(json_response[api_resource_name].map { |w| w['active'] }).to all(be true)
end

it 'does not include in active workflows' do
expect(json_response[api_resource_name].map{ |w| w['id'] }).to_not include(inactive_workflow.id)
expect(json_response[api_resource_name].map { |w| w['id'] }).not_to include(inactive_workflow.id)
end
end
end

describe 'limiting fields' do
before(:each) do
before do
filterable_resources
default_request user_id: user.id, scopes: scopes
end
Expand Down Expand Up @@ -98,24 +100,23 @@
display_name: 'A Better Name',
active: false,
retirement: { criteria: 'classification_count' },
aggregation: {},
configuration: {},
public_gold_standard: true,
tasks: {
interest: {
type: 'draw',
question: 'Draw a Circle',
next: 'shape',
tools: [
{ value: 'red', label: 'Red', type: 'point', color: 'red' },
{ value: 'green', label: 'Green', type: 'point', color: 'lime' },
{ value: 'blue', label: 'Blue', type: 'point', color: 'blue' }
]
}
},
steps: [['S0', { 'taskKeys' => ['T0', 'T1'] }]],
display_order_position: 1,
links: {
type: 'draw',
question: 'Draw a Circle',
next: 'shape',
tools: [
{ value: 'red', label: 'Red', type: 'point', color: 'red' },
{ value: 'green', label: 'Green', type: 'point', color: 'lime' },
{ value: 'blue', label: 'Blue', type: 'point', color: 'blue' }
]
}
},
steps: [['S0', { 'taskKeys' => %w[T0 T1] }]],
display_order_position: 1,
links: {
subject_sets: [subject_set.id.to_s],
tutorials: [tutorial.id.to_s]
}
Expand All @@ -136,8 +137,8 @@
end
end

it_behaves_like "is updatable"
it_behaves_like "has updatable links"
it_behaves_like 'is updatable'
it_behaves_like 'has updatable links'

it_behaves_like 'it syncs the resource translation strings' do
let(:translated_klass_name) { resource.class.name }
Expand All @@ -161,6 +162,7 @@

context 'when extracting strings from workflow' do
let(:new_question) { 'Contemplate' }

before do
default_request scopes: scopes, user_id: authorized_user.id
update_params[:workflows][:tasks][:interest][:question] = new_question
Expand Down Expand Up @@ -233,7 +235,7 @@
end

context 'when a project is live' do
before(:each) do
before do
resource.update!(active: true)
project = resource.project
project.live = true
Expand Down Expand Up @@ -309,7 +311,7 @@
end

it 'updates the content model' do
expect{ resource.reload }.to change{ resource.strings }
expect{ resource.reload }.to change(resource, :strings)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Layout/SpaceBeforeBlockBraces: Space missing to the left of {.

end
end
end
Expand Down Expand Up @@ -523,7 +525,6 @@
first_task: 'interest',
active: true,
retirement: { criteria: 'classification_count' },
aggregation: { public: true },
configuration: { autoplay_subjects: true },
public_gold_standard: true,
tasks: create_task_params,
Expand Down
21 changes: 12 additions & 9 deletions spec/lib/formatter/csv/workflow_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
require "spec_helper"
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Formatter::Csv::Workflow do
let(:workflow) { create(:workflow) }
Expand Down Expand Up @@ -26,30 +28,31 @@ def retirement_json
workflow.retired_set_member_subjects_count,
workflow_version.tasks.to_json,
retirement_json,
workflow.aggregation.to_json,
workflow_version.strings.to_json,
workflow_version.minor_number
]
]
end

let(:header) do
%w(workflow_id display_name version minor_version active classifications_count pairwise grouped prioritized primary_language first_task tutorial_subject_id retired_set_member_subjects_count tasks retirement aggregation strings)
%w[workflow_id display_name version minor_version active classifications_count pairwise grouped
prioritized primary_language first_task tutorial_subject_id retired_set_member_subjects_count
tasks retirement strings]
end

describe "#headers" do
it 'should contain the required headers' do
describe '#headers' do
it 'contains the required headers' do
expect(described_class.new.headers).to match_array(header)
end
end

describe "#to_rows" do
describe '#to_rows' do
subject { described_class.new.to_rows(workflow_version) }

it { is_expected.to match_array(rows) }
end

context "with a versioned workflow" do
context 'with a versioned workflow' do
let(:q_workflow) { build(:workflow, :question_task) }
let(:tasks) { q_workflow.tasks }

Expand All @@ -61,13 +64,13 @@ def retirement_json
workflow.update(updates)
end

describe "#to_rows on the latest version" do
describe '#to_rows on the latest version' do
subject { described_class.new.to_rows(workflow_version) }

it { is_expected.to match_array(rows) }
end

describe "#to_rows on the previous version" do
describe '#to_rows on the previous version' do
let(:workflow_version) { workflow.workflow_versions.order(:created_at).first }

subject { described_class.new.to_rows(workflow_version) }
Expand Down
20 changes: 0 additions & 20 deletions spec/models/workflow_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -388,26 +388,6 @@
end
end

describe "#aggregation" do
let(:workflow) { build(:workflow, aggregation: aggregation_config ) }

context "empty" do
let(:aggregation_config) { Hash.new }

it "should be valid" do
expect(workflow).to be_valid
end
end

context "with values" do
let(:aggregation_config) { { public: true } }

it "should be valid" do
expect(workflow).to be_valid
end
end
end

describe "#configuration" do
let(:workflow) { build(:workflow, configuration: config ) }

Expand Down
Loading