14988: Fixes functionals tests (WIP)
authorLucas Di Pentima <ldipentima@veritasgenetics.com>
Mon, 6 May 2019 12:23:36 +0000 (09:23 -0300)
committerLucas Di Pentima <ldipentima@veritasgenetics.com>
Mon, 6 May 2019 12:23:36 +0000 (09:23 -0300)
Arvados-DCO-1.1-Signed-off-by: Lucas Di Pentima <ldipentima@veritasgenetics.com>

apps/workbench/app/controllers/collections_controller.rb
apps/workbench/app/models/arvados_base.rb
apps/workbench/app/views/application/_content.html.erb
apps/workbench/app/views/jobs/show.html.erb
apps/workbench/app/views/pipeline_instances/show.html.erb
apps/workbench/test/controllers/collections_controller_test.rb
apps/workbench/test/controllers/container_requests_controller_test.rb
build/run-tests.sh

index ed10d63e6696cd619906fd01bacb76b987ba2d42..8d7e6ee332af5e3cf53dac674e6185626f43d413 100644 (file)
@@ -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?
index 1752e0aeb121a1711e78a2741d308876564be353..f29147639ceba2596b0ab21395569fae7ffcf858 100644 (file)
@@ -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' }
index 7f3542083e91180f9c943e3a93c16bf416c2930b..c4656e659d51cd08b2d75f8ad1859ad5aa7e1ba7 100644 (file)
@@ -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;"
            >
         <div class="pane-content">
index 1bf8065c31c804148b49bcd90ed80bd1ce91c497..4ac7601c8e57d91a3e460b559d7c0db7e1274b5a 100644 (file)
@@ -4,7 +4,7 @@ SPDX-License-Identifier: AGPL-3.0 %>
 
 <% content_for :tab_line_buttons do %>
   <div class="pane-loaded arv-log-event-listener arv-refresh-on-state-change"
-       data-pane-content-url="<%= url_for(params.merge(tab_pane: "job_buttons")) %>"
+       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}%>
index 881d77102c656e1c7408d72c3d970e32dd5c89ad..e573bf52a23554fc35bb0ef143b6464375f0bbb7 100644 (file)
@@ -23,7 +23,7 @@ SPDX-License-Identifier: AGPL-3.0 %>
 
   <div id="pipeline-instance-tab-buttons"
        class="pane-loaded arv-log-event-listener arv-refresh-on-state-change"
-       data-pane-content-url="<%= url_for(params.merge(tab_pane: "tab_buttons")) %>"
+       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}%>
index b6995da0698c56395b7a02dd6d19602c83f824eb..302820057a62a0830920f565941f8bb03b76c36c 100644 (file)
@@ -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
index 36a040e954805afbfb5f0d44a21475fdd4e7e23d..93686aa6b14668d762185a5f19a5431d8398a60f 100644 (file)
@@ -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]
index 2764f7d344c8da1ebcdf2fbb40b525cbc54f452a..5ca3b8e42599dea5a0a5db952becfe6e51743849 100755 (executable)
@@ -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() {