diff --git a/.circleci/config.yml b/.circleci/config.yml new file mode 100644 index 0000000..b481f87 --- /dev/null +++ b/.circleci/config.yml @@ -0,0 +1,76 @@ +uby CircleCI 2.0 configuration file +# +# Check https://circleci.com/docs/2.0/language-ruby/ for more details +# +version: 2 +jobs: + build: + docker: + # specify the version you desire here + - image: circleci/ruby:2.5.3-node-browsers + environment: + PGHOST: 127.0.0.1 + PGUSER: postgres + RAILS_ENV: test + RAKE_ENV: test + # Specify service dependencies here if necessary + # CircleCI maintains a library of pre-built images + # documented at https://circleci.com/docs/2.0/circleci-images/ + - image: circleci/postgres:9.4 + environment: + POSTGRES_USER: postgres + POSTGRES_DB: mcm_test + POSTGRES_PASSWORD: "" + + + steps: + - checkout + + # Download and cache dependencies + - restore_cache: + keys: + - v1-dependencies-{{ checksum "Gemfile.lock" }} + # fallback to using the latest cache if no exact match is found + - v1-dependencies- + + - run: + name: Configure Bundler + command: | + echo 'export BUNDLER_VERSION=$(cat Gemfile.lock | tail -1 | tr -d " ")' >> $BASH_ENV + source $BASH_ENV + gem install bundler + - run: + name: install dependencies + command: | + bundle install --jobs=4 --retry=3 --no-deployment --path vendor/bundle + - save_cache: + paths: + - ./vendor/bundle + key: v1-dependencies-{{ checksum "Gemfile.lock" }} + + - run: bin/rails app:update:bin + + # Database setup + - run: + name: Wait for DB + command: dockerize -wait tcp://localhost:5432 -timeout 1m + + - run: bundle exec rake db:create + - run: bundle exec rake db:schema:load + + # run tests! + - run: + name: run tests + command: bundle exec rails test + + # run tests! + - run: + name: run system test + command: bundle exec rails test:system + + # collect reports + - store_test_results: + path: /tmp/test-results + - store_artifacts: + path: /tmp/test-results + destination: test-results diff --git a/app/models/user.rb b/app/models/user.rb index 9b03661..83cd3c1 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -32,8 +32,7 @@ class User < ApplicationRecord has_many :feedback, dependent: :destroy devise :invitable, :database_authenticatable, :registerable, :recoverable, :validatable, validate_on_invite: true - VALID_EMAIL_REGEX = /~*@michelada.io\z/i.freeze - validates :email, presence: true, format: { with: VALID_EMAIL_REGEX }, uniqueness: { case_sensitive: false } + validates :email, presence: true enum role: %i[user judge admin] scope :all_except_actual, ->(actual_user) { where.not(id: actual_user).order('email ASC') } @@ -56,7 +55,7 @@ def project end def can_be_invited? - !User.find_by_email(email)&.current_team && email.match?(VALID_EMAIL_REGEX) + !User.find_by_email(email)&.current_team end def initialize_user diff --git a/db/schema.rb b/db/schema.rb index 5092ae3..97cc872 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -22,7 +22,7 @@ t.bigint "blob_id", null: false t.datetime "created_at", null: false t.index ["blob_id"], name: "index_active_storage_attachments_on_blob_id" - t.index %w[record_type record_id name blob_id], name: "index_active_storage_attachments_uniqueness", unique: true + t.index ["record_type", "record_id", "name", "blob_id"], name: "index_active_storage_attachments_uniqueness", unique: true end create_table "active_storage_blobs", force: :cascade do |t| @@ -39,13 +39,14 @@ create_table "activities", force: :cascade do |t| t.string "name", null: false t.boolean "english", null: false + t.string "location" t.datetime "created_at", null: false t.datetime "updated_at", null: false - t.bigint "user_id", null: false + t.bigint "user_id" t.integer "activity_type", null: false t.integer "status", default: 0, null: false t.text "notes" - t.integer "score", default: 0 + t.integer "score" t.text "description" t.text "pitch_audience" t.text "abstract_outline" @@ -65,7 +66,7 @@ t.datetime "updated_at", null: false t.string "content_type" t.bigint "content_id" - t.index %w[content_type content_id], name: "index_content_approvations_on_content_type_and_content_id" + t.index ["content_type", "content_id"], name: "index_content_approvations_on_content_type_and_content_id" t.index ["user_id"], name: "index_content_approvations_on_user_id" end @@ -77,7 +78,7 @@ t.string "commentable_type" t.bigint "commentable_id" t.string "file" - t.index %w[commentable_type commentable_id], name: "index_feedbacks_on_commentable_type_and_commentable_id" + t.index ["commentable_type", "commentable_id"], name: "index_feedbacks_on_commentable_type_and_commentable_id" t.index ["user_id"], name: "index_feedbacks_on_user_id" end @@ -148,6 +149,7 @@ t.string "name", default: "", null: false t.string "reset_password_token" t.datetime "reset_password_sent_at" + t.datetime "remember_created_at" t.datetime "created_at", null: false t.datetime "updated_at", null: false t.string "invitation_token" @@ -163,7 +165,7 @@ t.index ["invitation_token"], name: "index_users_on_invitation_token", unique: true t.index ["invitations_count"], name: "index_users_on_invitations_count" t.index ["invited_by_id"], name: "index_users_on_invited_by_id" - t.index %w[invited_by_type invited_by_id], name: "index_users_on_invited_by_type_and_invited_by_id" + t.index ["invited_by_type", "invited_by_id"], name: "index_users_on_invited_by_type_and_invited_by_id" t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true end @@ -175,7 +177,7 @@ t.integer "value", null: false t.string "content_type" t.bigint "content_id" - t.index %w[content_type content_id], name: "index_votes_on_content_type_and_content_id" + t.index ["content_type", "content_id"], name: "index_votes_on_content_type_and_content_id" t.index ["poll_id"], name: "index_votes_on_poll_id" t.index ["user_id"], name: "index_votes_on_user_id" end diff --git a/test/controllers/team_invitations_controller_test.rb b/test/controllers/team_invitations_controller_test.rb index 9037566..1f9ffe1 100644 --- a/test/controllers/team_invitations_controller_test.rb +++ b/test/controllers/team_invitations_controller_test.rb @@ -8,13 +8,13 @@ def setup @match = Match.last end - test 'user can not invite with an invalid email' do + test 'user can invite with with any email' do user = users(:user_test1) post match_team_invitations_path(@match, user.current_team), params: { email: 'example_user@michelado.io' } - assert_equal flash[:alert], I18n.t('team.invalid_user') + assert_equal flash[:notice], "El usuario ha sido agregado a tu equipo" end test 'user can invite a new user' do diff --git a/test/models/user_test.rb b/test/models/user_test.rb index 5d98b4b..ddc2930 100644 --- a/test/models/user_test.rb +++ b/test/models/user_test.rb @@ -36,11 +36,11 @@ def setup refute user.valid? end - test 'user must be invalid if email is not from michelada domain' do + test 'user must valid if email is not from michelada domain' do user = User.new(email: 'miguel.urbina@gmail.com', password: 'normalUser', password_confirmation: 'normalUser') - refute user.valid? + assert user.valid? end test 'user must be valid' do diff --git a/test/system/team_invitation_test.rb b/test/system/team_invitation_test.rb index 17472d9..5320e3c 100644 --- a/test/system/team_invitation_test.rb +++ b/test/system/team_invitation_test.rb @@ -79,7 +79,7 @@ class TeamInvitationTest < ApplicationSystemTestCase assert page.has_content?(I18n.t('team.invalid_user')) end - test 'user can not invite someone with an invalid email when creating a team' do + test 'user can invite someone with any email when creating a team' do user = users(:user) sign_in user @@ -87,7 +87,7 @@ class TeamInvitationTest < ApplicationSystemTestCase fill_in 'user_invitations[email_1]', with: 'miguel.urbina@mich.io' click_button 'Crear' - assert page.has_content?(I18n.t('team.messages.error_users')) + assert page.has_content?('Equipo creado') end test 'user can not invite someone with an invalid email through invitation view' do @@ -98,7 +98,7 @@ class TeamInvitationTest < ApplicationSystemTestCase fill_in 'user_invitations[email_1]', with: 'miguel.urbina@michelado.io' click_button 'Crear' - assert page.has_content?(I18n.t('team.messages.error_users')) + assert page.has_content?("Equipo creado") end test 'user can see the link and go to the invitation view' do diff --git a/test/system/user/login_test.rb b/test/system/user/login_test.rb index c16c04b..f973fb8 100644 --- a/test/system/user/login_test.rb +++ b/test/system/user/login_test.rb @@ -40,7 +40,7 @@ def setup assert page.has_content?('Bienvenido') end - test 'users email is invalid if it is not part of @michelada domain' do + test 'users email is valid even if it is not part of @michelada domain' do visit new_user_registration_path fill_in 'user[email]', with: 'normal_user@gmail.com' @@ -48,7 +48,7 @@ def setup fill_in 'user[password_confirmation]', with: '123456' click_button 'Registrarse' - assert page.has_content?('E-mail no vĂ¡lido') + assert page.has_content?('Debes crear primero tu equipo') end test 'user can logout' do