summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAzul <azul@riseup.net>2016-08-12 11:59:05 +0200
committerAzul <azul@riseup.net>2016-08-12 12:20:55 +0200
commitf0d2f44ea3babdafc793856082d8c532b05187ae (patch)
treeea564ea3175a96e2070664b5c6c016bd2c8a2937
parentb4ff3b959d4dd6a7561ac3be063a43619c0bd89c (diff)
[db] remove DatabaseMethod import from TemporaryUser
It was causing 404s on initializing the database with db:migrate. DatabaseMethods rewrite of #database does not call prepare_database and thus does not create the database when needed. DatabaseMethod is also quite a bit too much for a model that has two databases that can be memoized easily. There's no way to have a separate database instance per record.
-rw-r--r--lib/temporary_user.rb26
1 files changed, 7 insertions, 19 deletions
diff --git a/lib/temporary_user.rb b/lib/temporary_user.rb
index 2afae15..e41add5 100644
--- a/lib/temporary_user.rb
+++ b/lib/temporary_user.rb
@@ -12,16 +12,12 @@
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.
@@ -45,15 +41,7 @@ module TemporaryUser
# 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
+ @tmp_database ||= prepare_database TMP_USER_DB
end
# create the tmp db if it doesn't exist.
@@ -71,12 +59,12 @@ module TemporaryUser
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)
+ def database
+ if login.present? && login.include?(TMP_LOGIN)
+ self.class.tmp_database
+ else
+ self.class.database
+ end
end
# returns true if this User instance is stored in tmp db.