Skip to content

Commit

Permalink
Add devise gem and create user, company and team models
Browse files Browse the repository at this point in the history
  • Loading branch information
canan8 committed May 9, 2020
1 parent 6514294 commit e6c0603
Show file tree
Hide file tree
Showing 22 changed files with 609 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ gem 'turbolinks', '~> 5'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.7'
gem 'rename'
gem 'awesome_print', '1.8.0'
gem 'devise'
# Use Redis adapter to run Action Cable in production
# gem 'redis', '~> 4.0'
# Use Active Model has_secure_password
Expand Down
16 changes: 16 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ GEM
zeitwerk (~> 2.2, >= 2.2.2)
addressable (2.7.0)
public_suffix (>= 2.0.2, < 5.0)
awesome_print (1.8.0)
bcrypt (3.1.13)
bindex (0.8.1)
bootsnap (1.4.6)
msgpack (~> 1.0)
Expand All @@ -74,6 +76,12 @@ GEM
childprocess (3.0.0)
concurrent-ruby (1.1.6)
crass (1.0.6)
devise (4.7.1)
bcrypt (~> 3.0)
orm_adapter (~> 0.1)
railties (>= 4.1.0)
responders
warden (~> 1.2.3)
erubi (1.9.0)
ffi (1.12.2)
globalid (0.4.2)
Expand Down Expand Up @@ -102,6 +110,7 @@ GEM
nio4r (2.5.2)
nokogiri (1.10.9)
mini_portile2 (~> 2.4.0)
orm_adapter (0.5.0)
pg (1.2.3)
public_suffix (4.0.4)
puma (4.3.3)
Expand Down Expand Up @@ -146,6 +155,9 @@ GEM
activesupport
rails (>= 3.0.0)
thor (>= 0.19.1)
responders (3.0.0)
actionpack (>= 5.0)
railties (>= 5.0)
ruby_dep (1.5.0)
rubyzip (2.3.0)
sass-rails (6.0.0)
Expand Down Expand Up @@ -181,6 +193,8 @@ GEM
turbolinks-source (5.2.0)
tzinfo (1.2.7)
thread_safe (~> 0.1)
warden (1.2.8)
rack (>= 2.0.6)
web-console (4.0.2)
actionview (>= 6.0.0)
activemodel (>= 6.0.0)
Expand All @@ -205,9 +219,11 @@ PLATFORMS
ruby

DEPENDENCIES
awesome_print (= 1.8.0)
bootsnap (>= 1.4.2)
byebug
capybara (>= 2.15)
devise
jbuilder (~> 2.7)
listen (>= 3.0.5, < 3.2)
pg
Expand Down
5 changes: 5 additions & 0 deletions app/models/company.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class Company < ApplicationRecord
validates :name, presence: true, length: { minimum: 3, maximum: 255 }
has_many :users
has_many :teams
end
7 changes: 7 additions & 0 deletions app/models/team.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class Team < ApplicationRecord
validates :name, presence: true
validates :company_id, presence: true

belongs_to :company
has_many :users, through: :user_teams
end
15 changes: 15 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
class User < ApplicationRecord
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable, :trackable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :validatable
VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i

validates :name, presence: true, length: { maximum: 255 }
validates :email, presence: true, length: { maximum: 255 },
uniqueness: { case_sensitive: false },
format: { with: VALID_EMAIL_REGEX }
validates :company_id, presence: true

has_many :teams, through: :user_teams
end
4 changes: 4 additions & 0 deletions app/models/user_team.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class UserTeam < ApplicationRecord
validates :user_id, presence: true
validates :team_id, presence: true
end
Loading

0 comments on commit e6c0603

Please sign in to comment.