Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mails restriction removed #3

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 76 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -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
5 changes: 2 additions & 3 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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') }

Expand All @@ -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
Expand Down
16 changes: 9 additions & 7 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand All @@ -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"
Expand All @@ -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

Expand All @@ -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

Expand Down Expand Up @@ -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"
Expand All @@ -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

Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions test/controllers/team_invitations_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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: '[email protected]'
}

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
Expand Down
4 changes: 2 additions & 2 deletions test/models/user_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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: '[email protected]',
password: 'normalUser',
password_confirmation: 'normalUser')
refute user.valid?
assert user.valid?
end

test 'user must be valid' do
Expand Down
6 changes: 3 additions & 3 deletions test/system/team_invitation_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,15 @@ 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

visit new_match_team_path(@match)
fill_in 'user_invitations[email_1]', with: '[email protected]'

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
Expand All @@ -98,7 +98,7 @@ class TeamInvitationTest < ApplicationSystemTestCase
fill_in 'user_invitations[email_1]', with: '[email protected]'

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
Expand Down
4 changes: 2 additions & 2 deletions test/system/user/login_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,15 @@ 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: '[email protected]'
fill_in 'user[password]', with: '123456'
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
Expand Down