diff options
author | azul <azul@riseup.net> | 2016-08-15 09:26:39 +0000 |
---|---|---|
committer | azul <azul@riseup.net> | 2016-08-15 09:26:39 +0000 |
commit | 1457fcdae08a1cd7e1e7b36668f826547d2c7cf6 (patch) | |
tree | 59b563bc3f10ed7d2438f6284f96478c592d3ddf /app | |
parent | a1d62a3a1492ca21e1e1d2344fac88bb4d93f324 (diff) | |
parent | 75c037e5d6d8b8f2b98477bdd0359f5687bd7517 (diff) |
Merge branch 'test/gitlab-ci' into 'develop'
[ci] get gitlab to run tests
See merge request !2
Diffstat (limited to 'app')
-rw-r--r-- | app/models/temporary_user.rb | 93 | ||||
-rw-r--r-- | app/models/user.rb | 3 |
2 files changed, 1 insertions, 95 deletions
diff --git a/app/models/temporary_user.rb b/app/models/temporary_user.rb deleted file mode 100644 index 2afae15..0000000 --- a/app/models/temporary_user.rb +++ /dev/null @@ -1,93 +0,0 @@ -# -# For users with login '*test_user*', we don't want to store these documents in -# the main users db. This is because we create and destroy a lot of test -# users. This weirdness of using a different db for some users breaks a lot of -# things, such as associations. However, this is OK for now since we don't need -# those for running the frequent nagios tests. -# -# This module is included in user.rb. This will only work if it is included -# after designs are defined, otherwise, the design definition will overwrite -# find_by_login(). -# - -module TemporaryUser - extend ActiveSupport::Concern - include CouchRest::Model::DatabaseMethod - - USER_DB = 'users' - TMP_USER_DB = 'tmp_users' - TMP_LOGIN = 'tmp_user' # created and deleted frequently - TEST_LOGIN = 'test_user' # created, rarely deleted - - included do - use_database_method :db_name - - # since the original find_by_login is dynamically created with - # instance_eval, it appears that we also need to use instance eval to - # override it. - instance_eval <<-EOS, __FILE__, __LINE__ + 1 - def find_by_login(*args) - if args.grep(/^#{TMP_LOGIN}/).any? - by_login.database(tmp_database).key(*args).first() - else - by_login.key(*args).first() - end - end - EOS - end - - module ClassMethods - def get(id, db = database) - super(id, db) || super(id, tmp_database) - end - alias :find :get - - # calls db_name(TMP_LOGIN), then creates a CouchRest::Database - # from the name - def tmp_database - choose_database(TMP_LOGIN) - end - - def db_name(login=nil) - if !login.nil? && login.include?(TMP_LOGIN) - TMP_USER_DB - else - USER_DB - end - end - - # create the tmp db if it doesn't exist. - # requires admin access. - def create_tmp_database! - design_doc.sync!(tmp_database.tap{|db|db.create!}) - end - - def is_tmp?(login) - !login.nil? && login =~ /^#{TMP_LOGIN}/ - end - - def is_test?(login) - !login.nil? && (login =~ /^#{TMP_LOGIN}/ || login =~ /^#{TEST_LOGIN}/) - end - end - - # - # this gets called each and every time a User object needs to - # access the database. - # - def db_name - self.class.db_name(self.login) - end - - # returns true if this User instance is stored in tmp db. - def is_tmp? - self.class.is_tmp?(self.login) - end - - # returns true if this user is used for testing purposes - # (either a temporary or long lived) - def is_test? - self.class.is_test?(self.login) - end - -end diff --git a/app/models/user.rb b/app/models/user.rb index 93830cc..9cebbca 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,11 +1,10 @@ require 'login_format_validation' require 'local_email' +require 'temporary_user' class User < CouchRest::Model::Base include LoginFormatValidation - use_database :users - property :login, String, :accessible => true property :password_verifier, String, :accessible => true property :password_salt, String, :accessible => true |