-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from psantos10/5_relationship_volunteer_and_help
#5 - Relationship between Volunteer and Help Model
- Loading branch information
Showing
10 changed files
with
99 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# frozen_string_literal: true | ||
|
||
class VolunteerHelp < ApplicationRecord | ||
enum status: { pending: 0, accepted: 1, declined: 2, canceled: 3 } | ||
|
||
belongs_to :volunteer | ||
belongs_to :help | ||
|
||
validates :volunteer_id, uniqueness: { scope: :help_id } | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
class CreateVolunteerHelps < ActiveRecord::Migration[6.0] | ||
def change | ||
create_table :volunteer_helps do |t| | ||
t.references :volunteer, null: false, foreign_key: true | ||
t.references :help, null: false, foreign_key: true | ||
t.boolean :anonymous, defualt: false | ||
t.integer :status | ||
|
||
t.timestamps | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# frozen_string_literal: true | ||
|
||
FactoryBot.define do | ||
factory :volunteer_help do | ||
volunteer { create(:volunteer) } | ||
help { create(:help) } | ||
anonymous { false } | ||
status { :pending } | ||
|
||
trait :anonymous do | ||
anonymous { true } | ||
end | ||
|
||
trait :accepted do | ||
status { :accepted } | ||
end | ||
|
||
trait :declined do | ||
status { :declined } | ||
end | ||
|
||
trait :canceled do | ||
status { :canceled } | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'rails_helper' | ||
|
||
RSpec.describe VolunteerHelp, type: :model do | ||
describe 'macros' do | ||
it { is_expected.to define_enum_for(:status).with_values(pending: 0, accepted: 1, declined: 2, canceled: 3) } | ||
end | ||
|
||
describe 'associations' do | ||
it { is_expected.to belong_to(:volunteer) } | ||
it { is_expected.to belong_to(:help) } | ||
end | ||
|
||
describe 'validations' do | ||
before { create(:volunteer_help) } | ||
|
||
it { is_expected.to validate_uniqueness_of(:volunteer_id).scoped_to(:help_id) } | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters