[ARVADOS] created: 14f2906a390d957bc17a9951667daf1eada37e47

git at public.curoverse.com git at public.curoverse.com
Tue Nov 18 03:18:51 EST 2014


        at  14f2906a390d957bc17a9951667daf1eada37e47 (commit)


commit 14f2906a390d957bc17a9951667daf1eada37e47
Author: Tom Clegg <tom at curoverse.com>
Date:   Tue Nov 18 03:15:59 2014 -0500

    4533: Reset fixtures after testing user deactivation.

diff --git a/apps/workbench/test/integration/users_test.rb b/apps/workbench/test/integration/users_test.rb
index 58432f7..00a25ba 100644
--- a/apps/workbench/test/integration/users_test.rb
+++ b/apps/workbench/test/integration/users_test.rb
@@ -3,6 +3,7 @@ require 'selenium-webdriver'
 require 'headless'
 
 class UsersTest < ActionDispatch::IntegrationTest
+  reset_api_fixtures :after_suite
 
   test "login as active user but not admin" do
     Capybara.current_driver = Capybara.javascript_driver

commit 524fba52b54d45e905d0b6603d45b6442f7813fe
Author: Tom Clegg <tom at curoverse.com>
Date:   Tue Nov 18 02:48:28 2014 -0500

    4533: Update bundle.

diff --git a/apps/workbench/Gemfile b/apps/workbench/Gemfile
index 5ab6eac..e2456c4 100644
--- a/apps/workbench/Gemfile
+++ b/apps/workbench/Gemfile
@@ -24,7 +24,7 @@ gem 'coffee-rails'
 # Gems used only for assets and not required
 # in production environments by default.
 group :assets do
-  gem 'sass-rails'
+  gem 'sass-rails', '~> 4.0.4'
 
   # See https://github.com/sstephenson/execjs#readme for more supported runtimes
   gem 'therubyracer', :platforms => :ruby
diff --git a/apps/workbench/Gemfile.lock b/apps/workbench/Gemfile.lock
index 8b9ea94..58fe339 100644
--- a/apps/workbench/Gemfile.lock
+++ b/apps/workbench/Gemfile.lock
@@ -10,27 +10,27 @@ GEM
   remote: https://rubygems.org/
   specs:
     RedCloth (4.2.9)
-    actionmailer (4.1.1)
-      actionpack (= 4.1.1)
-      actionview (= 4.1.1)
-      mail (~> 2.5.4)
-    actionpack (4.1.1)
-      actionview (= 4.1.1)
-      activesupport (= 4.1.1)
+    actionmailer (4.1.8)
+      actionpack (= 4.1.8)
+      actionview (= 4.1.8)
+      mail (~> 2.5, >= 2.5.4)
+    actionpack (4.1.8)
+      actionview (= 4.1.8)
+      activesupport (= 4.1.8)
       rack (~> 1.5.2)
       rack-test (~> 0.6.2)
-    actionview (4.1.1)
-      activesupport (= 4.1.1)
+    actionview (4.1.8)
+      activesupport (= 4.1.8)
       builder (~> 3.1)
       erubis (~> 2.7.0)
-    activemodel (4.1.1)
-      activesupport (= 4.1.1)
+    activemodel (4.1.8)
+      activesupport (= 4.1.8)
       builder (~> 3.1)
-    activerecord (4.1.1)
-      activemodel (= 4.1.1)
-      activesupport (= 4.1.1)
+    activerecord (4.1.8)
+      activemodel (= 4.1.8)
+      activesupport (= 4.1.8)
       arel (~> 5.0.0)
-    activesupport (4.1.1)
+    activesupport (4.1.8)
       i18n (~> 0.6, >= 0.6.9)
       json (~> 1.7, >= 1.7.7)
       minitest (~> 5.1)
@@ -49,7 +49,7 @@ GEM
       addressable (>= 2.3.1)
       extlib (>= 0.9.15)
       multi_json (>= 1.0.0)
-    bootstrap-sass (3.1.0.1)
+    bootstrap-sass (3.1.1.1)
       sass (~> 3.2)
     bootstrap-tab-history-rails (0.1.0)
       railties (>= 3.1)
@@ -72,27 +72,27 @@ GEM
       rack (>= 1.0.0)
       rack-test (>= 0.5.4)
       xpath (~> 2.0)
-    childprocess (0.5.1)
+    childprocess (0.5.5)
       ffi (~> 1.0, >= 1.0.11)
     cliver (0.3.2)
-    coffee-rails (4.0.1)
+    coffee-rails (4.1.0)
       coffee-script (>= 2.2.0)
       railties (>= 4.0.0, < 5.0)
-    coffee-script (2.2.0)
+    coffee-script (2.3.0)
       coffee-script-source
       execjs
-    coffee-script-source (1.7.0)
+    coffee-script-source (1.8.0)
     columnize (0.8.9)
     commonjs (0.2.7)
-    daemon_controller (1.1.7)
+    daemon_controller (1.2.0)
     debugger-linecache (1.2.0)
     deep_merge (1.0.1)
     erubis (2.7.0)
-    execjs (2.0.2)
+    execjs (2.2.2)
     extlib (0.9.16)
     faraday (0.8.9)
       multipart-post (~> 1.2.0)
-    ffi (1.9.3)
+    ffi (1.9.6)
     google-api-client (0.6.4)
       addressable (>= 2.3.2)
       autoparse (>= 0.3.3)
@@ -103,12 +103,12 @@ GEM
       multi_json (>= 1.0.0)
       signet (~> 0.4.5)
       uuidtools (>= 2.1.0)
-    headless (1.0.1)
-    highline (1.6.20)
+    headless (1.0.2)
+    highline (1.6.21)
     hike (1.2.3)
-    httpclient (2.5.0)
-    i18n (0.6.9)
-    jquery-rails (3.0.4)
+    httpclient (2.5.3.3)
+    i18n (0.6.11)
+    jquery-rails (3.1.2)
       railties (>= 3.0, < 5.0)
       thor (>= 0.14, < 2.0)
     json (1.8.1)
@@ -116,82 +116,80 @@ GEM
       multi_json (>= 1.5)
     launchy (2.4.3)
       addressable (~> 2.3)
-    less (2.4.0)
+    less (2.6.0)
       commonjs (~> 0.2.7)
-    less-rails (2.4.2)
+    less-rails (2.6.0)
       actionpack (>= 3.1)
-      less (~> 2.4.0)
-    libv8 (3.16.14.3)
-    mail (2.5.4)
-      mime-types (~> 1.16)
-      treetop (~> 1.4.8)
+      less (~> 2.6.0)
+    libv8 (3.16.14.7)
+    mail (2.6.3)
+      mime-types (>= 1.16, < 3)
     metaclass (0.0.4)
-    mime-types (1.25.1)
-    mini_portile (0.6.0)
-    minitest (5.3.3)
+    mime-types (2.4.3)
+    mini_portile (0.6.1)
+    minitest (5.4.3)
     mocha (1.1.0)
       metaclass (~> 0.0.1)
-    multi_json (1.10.0)
+    multi_json (1.10.1)
     multipart-post (1.2.0)
-    net-scp (1.1.2)
+    net-scp (1.2.1)
       net-ssh (>= 2.6.5)
     net-sftp (2.1.2)
       net-ssh (>= 2.6.5)
-    net-ssh (2.7.0)
+    net-ssh (2.9.1)
     net-ssh-gateway (1.2.0)
       net-ssh (>= 2.6.5)
-    nokogiri (1.6.3.1)
-      mini_portile (= 0.6.0)
-    oj (2.1.7)
-    passenger (4.0.23)
-      daemon_controller (>= 1.1.0)
+    nokogiri (1.6.4.1)
+      mini_portile (~> 0.6.0)
+    oj (2.11.1)
+    passenger (4.0.53)
+      daemon_controller (>= 1.2.0)
       rack
       rake (>= 0.8.1)
     piwik_analytics (1.0.2)
       actionpack
       activesupport
       rails (>= 3.0.0)
-    poltergeist (1.5.0)
+    poltergeist (1.5.1)
       capybara (~> 2.1)
       cliver (~> 0.3.1)
       multi_json (~> 1.0)
       websocket-driver (>= 0.2.0)
-    polyglot (0.3.4)
     rack (1.5.2)
     rack-test (0.6.2)
       rack (>= 1.0)
-    rails (4.1.1)
-      actionmailer (= 4.1.1)
-      actionpack (= 4.1.1)
-      actionview (= 4.1.1)
-      activemodel (= 4.1.1)
-      activerecord (= 4.1.1)
-      activesupport (= 4.1.1)
+    rails (4.1.8)
+      actionmailer (= 4.1.8)
+      actionpack (= 4.1.8)
+      actionview (= 4.1.8)
+      activemodel (= 4.1.8)
+      activerecord (= 4.1.8)
+      activesupport (= 4.1.8)
       bundler (>= 1.3.0, < 2.0)
-      railties (= 4.1.1)
+      railties (= 4.1.8)
       sprockets-rails (~> 2.0)
-    railties (4.1.1)
-      actionpack (= 4.1.1)
-      activesupport (= 4.1.1)
+    railties (4.1.8)
+      actionpack (= 4.1.8)
+      activesupport (= 4.1.8)
       rake (>= 0.8.7)
       thor (>= 0.18.1, < 2.0)
-    rake (10.3.1)
+    rake (10.3.2)
     ref (1.0.5)
     ruby-debug-passenger (0.2.0)
-    rubyzip (1.1.0)
-    rvm-capistrano (1.5.1)
+    rubyzip (1.1.6)
+    rvm-capistrano (1.5.5)
       capistrano (~> 2.15.4)
-    sass (3.2.12)
-    sass-rails (4.0.3)
+    sass (3.2.19)
+    sass-rails (4.0.4)
       railties (>= 4.0.0, < 5.0)
-      sass (~> 3.2.0)
-      sprockets (~> 2.8, <= 2.11.0)
+      sass (~> 3.2.2)
+      sprockets (~> 2.8, < 2.12)
       sprockets-rails (~> 2.0)
-    selenium-webdriver (2.40.0)
-      childprocess (>= 0.5.0)
+    selenium-webdriver (2.44.0)
+      childprocess (~> 0.5)
       multi_json (~> 1.0)
       rubyzip (~> 1.0)
-      websocket (~> 1.0.4)
+      websocket (~> 1.0)
     signet (0.4.5)
       addressable (>= 2.2.3)
       faraday (~> 0.8.1)
@@ -204,34 +202,31 @@ GEM
     simplecov-rcov (0.2.3)
       simplecov (>= 0.4.1)
     slop (3.6.0)
-    sprockets (2.11.0)
+    sprockets (2.11.3)
       hike (~> 1.2)
       multi_json (~> 1.0)
       rack (~> 1.0)
       tilt (~> 1.1, != 1.3.0)
-    sprockets-rails (2.1.3)
+    sprockets-rails (2.2.0)
       actionpack (>= 3.0)
       activesupport (>= 3.0)
-      sprockets (~> 2.8)
-    sqlite3 (1.3.8)
+      sprockets (>= 2.8, < 4.0)
+    sqlite3 (1.3.10)
     sshkey (1.6.1)
-    therubyracer (0.12.0)
+    therubyracer (0.12.1)
       libv8 (~> 3.16.14.0)
       ref
     thor (0.19.1)
-    thread_safe (0.3.3)
+    thread_safe (0.3.4)
     tilt (1.4.1)
-    treetop (1.4.15)
-      polyglot
-      polyglot (>= 0.3.1)
-    tzinfo (1.1.0)
+    tzinfo (1.2.2)
       thread_safe (~> 0.1)
-    uglifier (2.3.1)
+    uglifier (2.5.3)
       execjs (>= 0.3.0)
       json (>= 1.8.0)
     uuidtools (2.1.5)
-    websocket (1.0.7)
-    websocket-driver (0.3.2)
+    websocket (1.2.1)
+    websocket-driver (0.4.0)
     wiselinks (1.2.1)
     xpath (2.0.0)
       nokogiri (~> 1.3)
@@ -266,7 +261,7 @@ DEPENDENCIES
   ruby-debug-passenger
   rvm-capistrano
   sass
-  sass-rails
+  sass-rails (~> 4.0.4)
   selenium-webdriver
   simplecov (~> 0.7.1)
   simplecov-rcov

commit d99ef829ba0fce58c3ba928ad2a2aefeb7f9a0ac
Author: Tom Clegg <tom at curoverse.com>
Date:   Sat Nov 15 14:01:34 2014 -0500

    4533: Add /database/reset API to roll everything back to fixtures.

diff --git a/apps/workbench/test/integration/collections_test.rb b/apps/workbench/test/integration/collections_test.rb
index f4fc4cb..5925cd5 100644
--- a/apps/workbench/test/integration/collections_test.rb
+++ b/apps/workbench/test/integration/collections_test.rb
@@ -3,6 +3,8 @@ require 'selenium-webdriver'
 require 'headless'
 
 class CollectionsTest < ActionDispatch::IntegrationTest
+  reset_api_fixtures :after_suite
+
   setup do
     Capybara.current_driver = :rack_test
   end
diff --git a/apps/workbench/test/integration/pipeline_instances_test.rb b/apps/workbench/test/integration/pipeline_instances_test.rb
index 027616b..8fc7154 100644
--- a/apps/workbench/test/integration/pipeline_instances_test.rb
+++ b/apps/workbench/test/integration/pipeline_instances_test.rb
@@ -3,6 +3,8 @@ require 'selenium-webdriver'
 require 'headless'
 
 class PipelineInstancesTest < ActionDispatch::IntegrationTest
+  reset_api_fixtures :after_suite
+
   setup do
     # Selecting collections requiresLocalStorage
     headless = Headless.new
diff --git a/apps/workbench/test/integration/projects_test.rb b/apps/workbench/test/integration/projects_test.rb
index 5da6153..b439b8a 100644
--- a/apps/workbench/test/integration/projects_test.rb
+++ b/apps/workbench/test/integration/projects_test.rb
@@ -3,6 +3,8 @@ require 'selenium-webdriver'
 require 'headless'
 
 class ProjectsTest < ActionDispatch::IntegrationTest
+  reset_api_fixtures :after_suite
+
   setup do
     Capybara.current_driver = Capybara.javascript_driver
   end
@@ -48,8 +50,7 @@ class ProjectsTest < ActionDispatch::IntegrationTest
 
     # visit project page
     visit current_path
-    assert(has_no_text?('.container-fluid', text: '*Textile description for A project*'),
-           "Description is not rendered properly")
+    assert_no_text '*Textile description for A project*'
     assert(find?('.container-fluid', text: 'Textile description for A project'),
            "Description update did not survive page refresh")
     assert(find?('.container-fluid', text: 'And a new paragraph in description'),
diff --git a/apps/workbench/test/integration/user_agreements_test.rb b/apps/workbench/test/integration/user_agreements_test.rb
index dd263a2..acc3bca 100644
--- a/apps/workbench/test/integration/user_agreements_test.rb
+++ b/apps/workbench/test/integration/user_agreements_test.rb
@@ -3,6 +3,8 @@ require 'selenium-webdriver'
 require 'headless'
 
 class UserAgreementsTest < ActionDispatch::IntegrationTest
+  # We might change user activation status here, which can affect other test suites.
+  reset_api_fixtures :after_suite
 
   setup do
     Capybara.current_driver = Capybara.javascript_driver
diff --git a/apps/workbench/test/integration/user_manage_account_test.rb b/apps/workbench/test/integration/user_manage_account_test.rb
index ff2b7dd..4f124fc 100644
--- a/apps/workbench/test/integration/user_manage_account_test.rb
+++ b/apps/workbench/test/integration/user_manage_account_test.rb
@@ -3,6 +3,8 @@ require 'selenium-webdriver'
 require 'headless'
 
 class UserManageAccountTest < ActionDispatch::IntegrationTest
+  reset_api_fixtures :after_suite
+
   setup do
     headless = Headless.new
     headless.start
diff --git a/apps/workbench/test/integration/user_profile_test.rb b/apps/workbench/test/integration/user_profile_test.rb
index fd190a2..e79a132 100644
--- a/apps/workbench/test/integration/user_profile_test.rb
+++ b/apps/workbench/test/integration/user_profile_test.rb
@@ -3,6 +3,8 @@ require 'selenium-webdriver'
 require 'headless'
 
 class UserProfileTest < ActionDispatch::IntegrationTest
+  reset_api_fixtures :after_suite
+
   setup do
     headless = Headless.new
     headless.start
diff --git a/apps/workbench/test/test_helper.rb b/apps/workbench/test/test_helper.rb
index ab2ac39..4fd5aaf 100644
--- a/apps/workbench/test/test_helper.rb
+++ b/apps/workbench/test/test_helper.rb
@@ -204,6 +204,35 @@ class ActionController::TestCase
   end
 end
 
+# Test classes can call reset_api_fixtures(:before_suite) or
+# ...(:after_suite)
+class ActiveSupport::TestCase
+  class << self
+    attr_accessor :want_reset_api_fixtures
+  end
+
+  def self.reset_api_fixtures where, t=true
+    raise unless [:before_suite, :after_suite].include? where
+    self.want_reset_api_fixtures ||= {}
+    self.want_reset_api_fixtures[where] = t
+  end
+
+  def self.run *args
+    self.want_reset_api_fixtures ||= {}
+    reset_api_fixtures_now if want_reset_api_fixtures[:before_suite]
+    super
+    reset_api_fixtures_now if want_reset_api_fixtures[:after_suite]
+  end
+
+  protected
+  def self.reset_api_fixtures_now
+    auth = api_fixture('api_client_authorizations')['admin_trustedclient']
+    Thread.current[:arvados_api_token] = auth['api_token']
+    ArvadosApiClient.new.api(nil, '../../database/reset', {})
+    Thread.current[:arvados_api_token] = nil
+  end
+end
+
 # If it quacks like a duck, it must be a HTTP request object.
 class RequestDuck
   def self.host
diff --git a/services/api/Gemfile b/services/api/Gemfile
index 996d3fc..edc08d6 100644
--- a/services/api/Gemfile
+++ b/services/api/Gemfile
@@ -7,6 +7,7 @@ gem 'rails', '~> 3.2.0'
 
 group :test, :development do
   gem 'factory_girl_rails'
+  gem 'database_cleaner'
   # Note: "require: false" here tells bunder not to automatically
   # 'require' the packages during application startup. Installation is
   # still mandatory.
@@ -67,7 +68,6 @@ gem 'test_after_commit', :group => :test
 gem 'google-api-client', '~> 0.6.3'
 gem 'trollop'
 gem 'faye-websocket'
-gem 'database_cleaner'
 
 gem 'themes_for_rails'
 
diff --git a/services/api/app/controllers/database_controller.rb b/services/api/app/controllers/database_controller.rb
new file mode 100644
index 0000000..e0db2a7
--- /dev/null
+++ b/services/api/app/controllers/database_controller.rb
@@ -0,0 +1,33 @@
+class DatabaseController < ApplicationController
+  skip_before_filter :find_object_by_uuid
+  skip_before_filter :render_404_if_no_object
+  before_filter :admin_required
+  def reset
+    raise ArvadosModel::PermissionDeniedError unless ENV['RAILS_ENV'] == 'test'
+
+    require 'active_record/fixtures'
+
+    # What kinds of fixtures do we have?
+    fixturesets = Dir.glob(Rails.root.join('test', 'fixtures', '*.yml')).
+      collect { |yml| yml.match(/([^\/]*)\.yml$/)[1] }
+
+    # Delete existing fixtures (and everything else) from fixture
+    # tables
+    fixturesets.each do |x|
+      x.classify.constantize.unscoped.delete_all
+    end
+
+    # create_fixtures() is a no-op for cached fixture sets, so uncache
+    # them all.
+    ActiveRecord::Fixtures.reset_cache
+    ActiveRecord::Fixtures.
+      create_fixtures(Rails.root.join('test', 'fixtures'), fixturesets)
+
+    # Dump cache of permissions etc.
+    Rails.cache.clear
+    ActiveRecord::Base.connection.clear_query_cache
+
+    # Done.
+    render json: {success: true}
+  end
+end
diff --git a/services/api/config/application.default.yml b/services/api/config/application.default.yml
index cc46d04..a357439 100644
--- a/services/api/config/application.default.yml
+++ b/services/api/config/application.default.yml
@@ -46,6 +46,7 @@ test:
   user_profile_notification_address: arvados at example.com
   workbench_address: https://localhost:3001/
   websocket_address: ws://127.0.0.1:3333/websocket
+  enable_remote_database_reset: true
 
 common:
   uuid_prefix: <%= Digest::MD5.hexdigest(`hostname`).to_i(16).to_s(36)[0..4] %>
@@ -241,3 +242,7 @@ common:
 
   # Default lifetime for ephemeral collections: 2 weeks.
   default_trash_lifetime: 1209600
+
+  # Allow resetting the database to fixtures via API call. This only
+  # makes sense if RAILS_ENV=test. It requires an admin token.
+  enable_remote_database_reset: false
diff --git a/services/api/config/routes.rb b/services/api/config/routes.rb
index 705822a..3537504 100644
--- a/services/api/config/routes.rb
+++ b/services/api/config/routes.rb
@@ -63,6 +63,10 @@ Server::Application.routes.draw do
     end
   end
 
+  if Rails.configuration.enable_remote_database_reset
+    post '/database/reset', to: 'database#reset'
+  end
+
   # omniauth
   match '/auth/:provider/callback', :to => 'user_sessions#create'
   match '/auth/failure', :to => 'user_sessions#failure'
diff --git a/services/api/test/functional/database_controller_test.rb b/services/api/test/functional/database_controller_test.rb
new file mode 100644
index 0000000..7909e60
--- /dev/null
+++ b/services/api/test/functional/database_controller_test.rb
@@ -0,0 +1,32 @@
+require 'test_helper'
+
+class DatabaseControllerTest < ActionController::TestCase
+  include CurrentApiClient
+
+  test "reset fails with non-admin token" do
+    authorize_with :active
+    post :reset
+    assert_response 403
+  end
+
+  test "reset fails when not in test mode" do
+    authorize_with :admin
+    env_was = ENV['RAILS_ENV']
+    ENV['RAILS_ENV'] = 'development'
+    post :reset
+    assert_response 403
+    ENV['RAILS_ENV'] = env_was
+  end
+
+  test "reset succeeds with admin token" do
+    new_uuid = nil
+    act_as_system_user do
+      new_uuid = Specimen.create.uuid
+    end
+    assert_not_empty Specimen.where(uuid: new_uuid)
+    authorize_with :admin
+    post :reset
+    assert_response 200
+    assert_empty Specimen.where(uuid: new_uuid)
+  end
+end
diff --git a/services/api/test/integration/errors_test.rb b/services/api/test/integration/errors_test.rb
index b2ef13e..984f81f 100644
--- a/services/api/test/integration/errors_test.rb
+++ b/services/api/test/integration/errors_test.rb
@@ -19,7 +19,7 @@ class ErrorsTest < ActionDispatch::IntegrationTest
       # Generally, new routes should appear under /arvados/v1/. If
       # they appear elsewhere, that might have been caused by default
       # rails generator behavior that we don't want.
-      assert_match(/^\/(|\*a|arvados\/v1\/.*|auth\/.*|login|logout|discovery\/.*|static\/.*|themes\/.*)(\(\.:format\))?$/,
+      assert_match(/^\/(|\*a|arvados\/v1\/.*|auth\/.*|login|logout|database\/reset|discovery\/.*|static\/.*|themes\/.*)(\(\.:format\))?$/,
                    route.path.spec.to_s,
                    "Unexpected new route: #{route.path.spec}")
     end

-----------------------------------------------------------------------


hooks/post-receive
-- 




More information about the arvados-commits mailing list