This repository has been archived by the owner on Dec 8, 2021. It is now read-only.
-
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.
- Loading branch information
torresed
committed
Feb 22, 2021
1 parent
2c367b7
commit 0be5fcc
Showing
13 changed files
with
102 additions
and
100 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# frozen_string_literal: true | ||
|
||
class Friends < ApplicationRecord | ||
belongs_to :sent_to, class_name: 'User' | ||
belongs_to :sent_by, class_name: 'User' | ||
|
||
enum status: { pending: 0, confirmed: 1 } | ||
scope :pending, -> { where(status: :pending) } | ||
scope :confirmed, -> { where(status: :confirmed) } | ||
|
||
def self.request(user, friend) | ||
return if (user == friend) || find_by(sent_by: user, sent_to: friend).present? | ||
|
||
user.requests_sent.create(sent_to: friend, status: :pending) | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
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
4 changes: 2 additions & 2 deletions
4
...rate/20210206031504_create_friendships.rb → db/migrate/20210206031504_create_friends.rb
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,27 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'rails_helper' | ||
|
||
RSpec.describe FriendsController, type: :routing do | ||
describe 'routing' do | ||
it 'routes to #show via GET' do | ||
expect(get: '/friends').to route_to('friends#show') | ||
end | ||
|
||
it 'routes to #create via POST' do | ||
expect(post: '/friends').to route_to('friends#create') | ||
end | ||
|
||
it 'routes to #update via PUT' do | ||
expect(put: '/friends').to route_to('friends#update') | ||
end | ||
|
||
it 'routes to #update via PATCH' do | ||
expect(patch: '/friends').to route_to('friends#update') | ||
end | ||
|
||
it 'routes to #destroy via DELETE' do | ||
expect(delete: '/friends').to route_to('friends#destroy') | ||
end | ||
end | ||
end |
Oops, something went wrong.