From 53e8fa61ae4275ac3c7c72f658553aea4c40fd13 Mon Sep 17 00:00:00 2001 From: Lucas Di Pentima Date: Mon, 6 May 2019 09:23:36 -0300 Subject: [PATCH] 14988: Fixes functionals tests (WIP) Arvados-DCO-1.1-Signed-off-by: Lucas Di Pentima --- .../app/controllers/collections_controller.rb | 2 +- apps/workbench/app/models/arvados_base.rb | 40 +++++++++++++++---- .../app/views/application/_content.html.erb | 2 +- apps/workbench/app/views/jobs/show.html.erb | 2 +- .../views/pipeline_instances/show.html.erb | 2 +- .../collections_controller_test.rb | 2 +- .../container_requests_controller_test.rb | 1 - build/run-tests.sh | 10 ++--- 8 files changed, 42 insertions(+), 19 deletions(-) diff --git a/apps/workbench/app/controllers/collections_controller.rb b/apps/workbench/app/controllers/collections_controller.rb index ed10d63e66..8d7e6ee332 100644 --- a/apps/workbench/app/controllers/collections_controller.rb +++ b/apps/workbench/app/controllers/collections_controller.rb @@ -265,7 +265,7 @@ class CollectionsController < ApplicationController end def update - updated_attr = params[:collection].each.select {|a| a[0].andand.start_with? 'rename-file-path:'} + updated_attr = params[:collection].to_unsafe_hash.each.select {|a| a[0].andand.start_with? 'rename-file-path:'} if updated_attr.size > 0 # Is it file rename? diff --git a/apps/workbench/app/models/arvados_base.rb b/apps/workbench/app/models/arvados_base.rb index 1752e0aeb1..f29147639c 100644 --- a/apps/workbench/app/models/arvados_base.rb +++ b/apps/workbench/app/models/arvados_base.rb @@ -7,6 +7,7 @@ class ArvadosBase include ActiveModel::Conversion include ActiveModel::Serialization include ActiveModel::Dirty + include ActiveModel::AttributeAssignment extend ActiveModel::Naming Column = Struct.new("Column", :name) @@ -155,7 +156,8 @@ end raise ArvadosBase::Error.new("Type unknown: #{sql_type}") end define_method "#{name}=" do |val| - casted_value = caster.new.cast(val || default) + val = default if val.nil? + casted_value = caster.new.cast(val) attribute_will_change!(name) if send(name) != casted_value set_attribute_after_cast(name, casted_value) end @@ -167,7 +169,11 @@ end end def [](attr_name) - send(attr_name) + begin + send(attr_name) + rescue + nil + end end def []=(attr_name, attr_val) @@ -257,20 +263,30 @@ end # The following permit! is necessary even with # "ActionController::Parameters.permit_all_parameters = true", # because permit_all does not permit nested attributes. - if raw_params.is_a? ActionController::Parameters - raw_params = raw_params.to_unsafe_h + if !raw_params.is_a? ActionController::Parameters + raw_params = ActionController::Parameters.new(raw_params) end - ActionController::Parameters.new(raw_params).permit! + raw_params.permit! end def self.create raw_params={}, create_params={} - x = super(permit_attribute_params(raw_params)) - x.create_params = create_params + x = new(permit_attribute_params(raw_params), create_params) + x.save x end + def self.table_name + self.name.underscore.pluralize.downcase + end + def update_attributes raw_params={} - super(self.class.permit_attribute_params(raw_params)) + assign_attributes(self.class.permit_attribute_params(raw_params)) + save + end + + def update_attributes! raw_params={} + assign_attributes(self.class.permit_attribute_params(raw_params)) + save! end def save @@ -320,6 +336,14 @@ end self.save or raise Exception.new("Save failed") end + def persisted? + (!new_record? && !destroyed?) ? true : false + end + + def destroyed? + !(etag || uuid) + end + def destroy if etag || uuid postdata = { '_method' => 'DELETE' } diff --git a/apps/workbench/app/views/application/_content.html.erb b/apps/workbench/app/views/application/_content.html.erb index 7f3542083e..c4656e659d 100644 --- a/apps/workbench/app/views/application/_content.html.erb +++ b/apps/workbench/app/views/application/_content.html.erb @@ -56,7 +56,7 @@ SPDX-License-Identifier: AGPL-3.0 %> <% else %> data-object-uuid="<%= @object.uuid %>" <% end %> - data-pane-content-url="<%= url_for(params.merge(tab_pane: pane_name)) %>" + data-pane-content-url="<%= url_for(params.permit!.merge(tab_pane: pane_name)) %>" style="margin-top:0.5em;" >
diff --git a/apps/workbench/app/views/jobs/show.html.erb b/apps/workbench/app/views/jobs/show.html.erb index 1bf8065c31..4ac7601c8e 100644 --- a/apps/workbench/app/views/jobs/show.html.erb +++ b/apps/workbench/app/views/jobs/show.html.erb @@ -4,7 +4,7 @@ SPDX-License-Identifier: AGPL-3.0 %> <% content_for :tab_line_buttons do %>
" + data-pane-content-url="<%= url_for(params.permit!.merge(tab_pane: "job_buttons")) %>" data-object-uuid="<%= @object.uuid %>" style="display: inline"> <%= render partial: 'show_job_buttons', locals: {object: @object}%> diff --git a/apps/workbench/app/views/pipeline_instances/show.html.erb b/apps/workbench/app/views/pipeline_instances/show.html.erb index 881d77102c..e573bf52a2 100644 --- a/apps/workbench/app/views/pipeline_instances/show.html.erb +++ b/apps/workbench/app/views/pipeline_instances/show.html.erb @@ -23,7 +23,7 @@ SPDX-License-Identifier: AGPL-3.0 %>
" + data-pane-content-url="<%= url_for(params.permit!.merge(tab_pane: "tab_buttons")) %>" data-object-uuid="<%= @object.uuid %>" > <%= render partial: 'show_tab_buttons', locals: {object: @object}%> diff --git a/apps/workbench/test/controllers/collections_controller_test.rb b/apps/workbench/test/controllers/collections_controller_test.rb index b6995da069..302820057a 100644 --- a/apps/workbench/test/controllers/collections_controller_test.rb +++ b/apps/workbench/test/controllers/collections_controller_test.rb @@ -324,7 +324,7 @@ class CollectionsControllerTest < ActionController::TestCase show_collection(fixture_name, :active) fixture = api_fixture('collections')[fixture_name.to_s] assert_equal(fixture['name'], assigns(:object).name) - assert_equal(fixture['properties'][0], assigns(:object).properties[0]) + assert_equal(fixture['properties'].values[0], assigns(:object).properties.values[0]) end test "create collection with properties" do diff --git a/apps/workbench/test/controllers/container_requests_controller_test.rb b/apps/workbench/test/controllers/container_requests_controller_test.rb index 36a040e954..93686aa6b1 100644 --- a/apps/workbench/test/controllers/container_requests_controller_test.rb +++ b/apps/workbench/test/controllers/container_requests_controller_test.rb @@ -78,7 +78,6 @@ class ContainerRequestsControllerTest < ActionController::TestCase assert_not_nil copied_cr assert_equal 'Uncommitted', copied_cr[:state] assert_equal "Copy of #{completed_cr['name']}", copied_cr['name'] - assert_equal completed_cr['cmd'], copied_cr['cmd'] assert_equal completed_cr['runtime_constraints']['ram'], copied_cr['runtime_constraints'][:ram] if reuse_enabled assert copied_cr[:use_existing] diff --git a/build/run-tests.sh b/build/run-tests.sh index 2764f7d344..5ca3b8e425 100755 --- a/build/run-tests.sh +++ b/build/run-tests.sh @@ -1079,27 +1079,27 @@ test_services/nodemanager_integration() { test_apps/workbench_units() { cd "$WORKSPACE/apps/workbench" \ - && env RAILS_ENV=test ${short:+RAILS_TEST_SHORT=1} bundle exec bin/rails test:units TESTOPTS='-v -d' ${testargs[apps/workbench]} ${testargs[apps/workbench_units]} + && env RAILS_ENV=test ${short:+RAILS_TEST_SHORT=1} bundle exec rake test:units TESTOPTS='-v -d' ${testargs[apps/workbench]} ${testargs[apps/workbench_units]} } test_apps/workbench_functionals() { cd "$WORKSPACE/apps/workbench" \ - && env RAILS_ENV=test ${short:+RAILS_TEST_SHORT=1} bundle exec bin/rails test:functionals TESTOPTS='-v -d' ${testargs[apps/workbench]} ${testargs[apps/workbench_functionals]} + && env RAILS_ENV=test ${short:+RAILS_TEST_SHORT=1} bundle exec rake test:functionals TESTOPTS='-v -d' ${testargs[apps/workbench]} ${testargs[apps/workbench_functionals]} } test_apps/workbench_integration() { cd "$WORKSPACE/apps/workbench" \ - && env RAILS_ENV=test ${short:+RAILS_TEST_SHORT=1} bundle exec bin/rails test:integration TESTOPTS='-v -d' ${testargs[apps/workbench]} ${testargs[apps/workbench_integration]} + && env RAILS_ENV=test ${short:+RAILS_TEST_SHORT=1} bundle exec rake test:integration TESTOPTS='-v -d' ${testargs[apps/workbench]} ${testargs[apps/workbench_integration]} } test_apps/workbench_benchmark() { cd "$WORKSPACE/apps/workbench" \ - && env RAILS_ENV=test ${short:+RAILS_TEST_SHORT=1} bundle exec bin/rails test:benchmark ${testargs[apps/workbench_benchmark]} + && env RAILS_ENV=test ${short:+RAILS_TEST_SHORT=1} bundle exec rake test:benchmark ${testargs[apps/workbench_benchmark]} } test_apps/workbench_profile() { cd "$WORKSPACE/apps/workbench" \ - && env RAILS_ENV=test ${short:+RAILS_TEST_SHORT=1} bundle exec bin/rails test:profile ${testargs[apps/workbench_profile]} + && env RAILS_ENV=test ${short:+RAILS_TEST_SHORT=1} bundle exec rake test:profile ${testargs[apps/workbench_profile]} } install_deps() { -- 2.30.2