Skip to content

Commit

Permalink
asscociate quotes and users to companies
Browse files Browse the repository at this point in the history
  • Loading branch information
dalima-dev committed Aug 26, 2024
1 parent 5fefbb3 commit bbaf368
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 1 deletion.
3 changes: 3 additions & 0 deletions app/models/company.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
class Company < ApplicationRecord
has_many :users, dependent: :destroy
has_many :quotes, dependent: :destroy

validates :name, presence: true
end
2 changes: 2 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
class User < ApplicationRecord
devise :database_authenticatable, :validatable

belongs_to :company
end
5 changes: 5 additions & 0 deletions db/migrate/20240826230630_add_company_reference_to_quotes.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddCompanyReferenceToQuotes < ActiveRecord::Migration[7.1]
def change
add_reference :quotes, :company, null: false, foreign_key: true
end
end
5 changes: 5 additions & 0 deletions db/migrate/20240826230631_add_company_reference_to_users.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddCompanyReferenceToUsers < ActiveRecord::Migration[7.1]
def change
add_reference :users, :company, null: false, foreign_key: true
end
end
8 changes: 7 additions & 1 deletion db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions test/fixtures/quotes.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
first:
company: kpmg
name: First quote

second:
company: kpmg
name: Second quote

third:
company: kpmg
name: Third quote
3 changes: 3 additions & 0 deletions test/fixtures/users.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
accountant:
company: kpmg
email: [email protected]
encrypted_password: <%= Devise::Encryptor.digest(User, 'password') %>

manager:
company: kpmg
email: [email protected]
encrypted_password: <%= Devise::Encryptor.digest(User, 'password') %>

eavesdropper:
company: pwc
email: [email protected]
encrypted_password: <%= Devise::Encryptor.digest(User, 'password') %>

0 comments on commit bbaf368

Please sign in to comment.