summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorazul <azul@riseup.net>2016-08-15 09:26:39 +0000
committerazul <azul@riseup.net>2016-08-15 09:26:39 +0000
commit1457fcdae08a1cd7e1e7b36668f826547d2c7cf6 (patch)
tree59b563bc3f10ed7d2438f6284f96478c592d3ddf
parenta1d62a3a1492ca21e1e1d2344fac88bb4d93f324 (diff)
parent75c037e5d6d8b8f2b98477bdd0359f5687bd7517 (diff)
Merge branch 'test/gitlab-ci' into 'develop'
[ci] get gitlab to run tests See merge request !2
-rw-r--r--.gitlab-ci.yml17
-rw-r--r--.travis.yml8
-rw-r--r--app/models/user.rb3
-rw-r--r--lib/temporary_user.rb (renamed from app/models/temporary_user.rb)32
-rw-r--r--test/config/gitlab/couchdb.yml3
-rw-r--r--test/config/travis/couchdb.admin.yml (renamed from test/config/couchdb.admin.yml)3
-rw-r--r--test/config/travis/couchdb.yml (renamed from test/config/couchdb.yml)1
-rw-r--r--test/config/travis/ruby-version (renamed from test/travis/ruby-version)0
-rwxr-xr-xtest/config/travis/setup_couch.sh (renamed from test/travis/setup_couch.sh)0
-rw-r--r--test/unit/temporary_user_test.rb28
10 files changed, 55 insertions, 40 deletions
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index df920d0..01c4103 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -8,7 +8,7 @@ image: "ruby:2.1"
# Check out: http://docs.gitlab.com/ce/ci/docker/using_docker_images.html#what-is-service
services:
- couchdb:1.6.1
-
+
# Cache gems in between builds
cache:
paths:
@@ -17,13 +17,16 @@ cache:
# This is a basic example for a gem or script which doesn't use
# services such as redis or postgres
before_script:
- - ruby -v # Print out ruby version for debugging
- - gem install bundler --no-ri --no-rdoc # Bundler is not installed with the image
- - bundle install -j $(nproc) --path vendor # Install dependencies into ./vendor/ruby
- - export RAILS_ENV=test
+ - ruby -v
+ - curl -s couchdb:5984
+ - git submodule update --init
+ - cp test/config/gitlab/couchdb.yml config/couchdb.admin.yml
+ - cp test/config/gitlab/couchdb.yml config
+ - gem install bundler --no-ri --no-rdoc
+ - bundle install -j $(nproc) --path vendor --without development debug
+ - bundle exec rake RAILS_ENV=test db:rotate
+ - bundle exec rake RAILS_ENV=test db:migrate
rails:
script:
- - bundle exec rake db:rotate
- - bundle exec rake db:migrate
- bundle exec rake test
diff --git a/.travis.yml b/.travis.yml
index 4e7aad0..2681951 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -6,10 +6,10 @@ before_install:
- "gem install bundler --version 1.11.2"
before_script:
- "rm .ruby-version"
- - "mv test/travis/ruby-version .ruby-version"
- - "test/travis/setup_couch.sh"
- - "mv test/config/couchdb.admin.yml config/couchdb.admin.yml"
- - "mv test/config/couchdb.yml config/couchdb.yml"
+ - "mv test/config/travis/ruby-version .ruby-version"
+ - "test/config/travis/setup_couch.sh"
+ - "mv test/config/travis/couchdb.admin.yml config/couchdb.admin.yml"
+ - "mv test/config/travis/couchdb.yml config/couchdb.yml"
- "bundle exec rake RAILS_ENV=test db:rotate"
- "bundle exec rake RAILS_ENV=test db:migrate"
after_script:
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
diff --git a/app/models/temporary_user.rb b/lib/temporary_user.rb
index 2afae15..d0db1c4 100644
--- a/app/models/temporary_user.rb
+++ b/lib/temporary_user.rb
@@ -12,16 +12,13 @@
module TemporaryUser
extend ActiveSupport::Concern
- include CouchRest::Model::DatabaseMethod
- USER_DB = 'users'
+ 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.
@@ -42,20 +39,15 @@ module TemporaryUser
end
alias :find :get
- # calls db_name(TMP_LOGIN), then creates a CouchRest::Database
- # from the name
- def tmp_database
- choose_database(TMP_LOGIN)
+ def database
+ @database ||= prepare_database USER_DB
end
- def db_name(login=nil)
- if !login.nil? && login.include?(TMP_LOGIN)
- TMP_USER_DB
- else
- USER_DB
- end
+ def tmp_database
+ @tmp_database ||= prepare_database TMP_USER_DB
end
+
# create the tmp db if it doesn't exist.
# requires admin access.
def create_tmp_database!
@@ -71,12 +63,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.
diff --git a/test/config/gitlab/couchdb.yml b/test/config/gitlab/couchdb.yml
new file mode 100644
index 0000000..68761dc
--- /dev/null
+++ b/test/config/gitlab/couchdb.yml
@@ -0,0 +1,3 @@
+test:
+ auto_update_design_doc: false
+ host: "couchdb"
diff --git a/test/config/couchdb.admin.yml b/test/config/travis/couchdb.admin.yml
index 0988bc1..a7677f9 100644
--- a/test/config/couchdb.admin.yml
+++ b/test/config/travis/couchdb.admin.yml
@@ -2,5 +2,4 @@ test:
auto_update_design_doc: false
username: "anna"
password: "secret"
- prefix: ""
-
+
diff --git a/test/config/couchdb.yml b/test/config/travis/couchdb.yml
index 9c8b67b..a57b888 100644
--- a/test/config/couchdb.yml
+++ b/test/config/travis/couchdb.yml
@@ -2,4 +2,3 @@ test:
auto_update_design_doc: false
username: "me"
password: "pwd"
- prefix: ""
diff --git a/test/travis/ruby-version b/test/config/travis/ruby-version
index 68b3a4c..68b3a4c 100644
--- a/test/travis/ruby-version
+++ b/test/config/travis/ruby-version
diff --git a/test/travis/setup_couch.sh b/test/config/travis/setup_couch.sh
index 0502c12..0502c12 100755
--- a/test/travis/setup_couch.sh
+++ b/test/config/travis/setup_couch.sh
diff --git a/test/unit/temporary_user_test.rb b/test/unit/temporary_user_test.rb
index 38ccd67..2c9e70f 100644
--- a/test/unit/temporary_user_test.rb
+++ b/test/unit/temporary_user_test.rb
@@ -6,16 +6,37 @@ class TemporaryUserTest < ActiveSupport::TestCase
InviteCodeValidator.any_instance.stubs(:validate)
end
- test "tmp_user saved to tmp_users" do
- begin
- assert User.ancestors.include?(TemporaryUser)
+ test "TemporaryUser concern is applied" do
+ assert User.ancestors.include?(TemporaryUser)
+ end
+
+ test "temporary user has tmp_users as db" do
+ tmp_user = User.new :login => 'tmp_user_'+SecureRandom.hex(5).downcase
+ assert_equal 'leap_web_tmp_users', tmp_user.database.name
+ end
+ test "normal user has users as db" do
+ user = User.new :login => 'a'+SecureRandom.hex(5).downcase
+ assert_equal 'leap_web_users', user.database.name
+ end
+
+ test "user saved to users" do
+ begin
assert_difference('User.database.info["doc_count"]') do
normal_user = User.create!(:login => 'a'+SecureRandom.hex(5).downcase,
:password_verifier => 'ABCDEF0010101', :password_salt => 'ABCDEF')
refute normal_user.database.to_s.include?('tmp')
end
+ ensure
+ begin
+ normal_user.destroy
+ rescue
+ end
+ end
+ end
+ test "tmp_user saved to tmp_users" do
+ begin
assert_difference('User.tmp_database.info["doc_count"]') do
tmp_user = User.create!(:login => 'tmp_user_'+SecureRandom.hex(5).downcase,
:password_verifier => 'ABCDEF0010101', :password_salt => 'ABCDEF')
@@ -23,7 +44,6 @@ class TemporaryUserTest < ActiveSupport::TestCase
end
ensure
begin
- normal_user.destroy
tmp_user.destroy
rescue
end