-
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 #13 from concertmate/ca_attendees
attendee controller, serializer and tests are now up and running
- Loading branch information
Showing
12 changed files
with
127 additions
and
125 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
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 |
---|---|---|
@@ -1,10 +1,9 @@ | ||
require "rails_helper" | ||
|
||
class UserEvent < ApplicationRecord | ||
class Attendee < ApplicationRecord | ||
belongs_to :user | ||
belongs_to :event | ||
|
||
validates :host, inclusion: { in: [true, false] } | ||
validates :user_id, presence: true | ||
validates :event_id, presence: true | ||
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 |
---|---|---|
@@ -1,10 +1,10 @@ | ||
class User < ApplicationRecord | ||
has_many :user_events | ||
has_many :attendees | ||
has_many :events | ||
has_many :user_artists, through: :user_artists | ||
has_many :user_artists | ||
has_many :artists, through: :user_artists | ||
|
||
validates :name, presence: true | ||
validates :email, presence: true | ||
|
||
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,6 @@ | ||
class AttendeeSerializer | ||
|
||
include JSONAPI::Serializer | ||
attributes :user_id, :event_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
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,81 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.describe 'Attendees API', type: :request do | ||
|
||
before :each do | ||
@user1 = User.create(name: 'John Doe', email: '[email protected]') | ||
@user2 = User.create(name: 'Jane Doe', email: '[email protected]') | ||
|
||
@event1 = Event.create(venue_name: 'The Fillmore', date_time: '2021-09-01T20:00:00.000Z', artist: 'The Beatles', location: 'San Francisco') | ||
|
||
@attendee = Attendee.create(user_id: @user1.id, event_id: @event1.id) | ||
end | ||
|
||
# it "returns all attendee by its id" do | ||
# atttendee_id = @attendee.id | ||
|
||
# get "/api/v1/users/#{@user1.id}/attendees/#{atttendee_id}" | ||
|
||
# attendee = JSON.parse(response.body, symbolize_names: true) | ||
|
||
# expect(response).to be_successful | ||
# expect(response.status).to eq(200) | ||
|
||
# expect(attendee).to be_a(Hash) | ||
# expect(attendee).to have_key(:data) | ||
|
||
# expect(attendee[:data][:attributes][:user_id]).to eq(@user1.id) | ||
# expect(attendee[:data][:attributes][:event_id]).to eq(@event1.id) | ||
# end | ||
|
||
it "creates a new attendee" do | ||
user_id = @user2.id | ||
event_id = @event1.id | ||
host = false | ||
|
||
post "/api/v1/attendees", params: { attendee: { user_id: user_id, event_id: event_id } } | ||
# require 'pry'; binding.pry | ||
attendee = JSON.parse(response.body, symbolize_names: true) | ||
|
||
expect(response).to be_successful | ||
expect(response.status).to eq(201) | ||
|
||
expect(attendee).to be_a(Hash) | ||
# require 'pry'; binding.pry | ||
expect(attendee).to have_key(:data) | ||
|
||
expect(attendee[:data][:attributes][:user_id]).to eq(user_id) | ||
expect(attendee[:data][:attributes][:event_id]).to eq(event_id) | ||
|
||
end | ||
|
||
# it "updates an existing attendee" do | ||
# atttendee_id = @attendee.id | ||
# new_user_id = @user2.id | ||
# new_event_id = @event1.id | ||
|
||
# put "/api/v1/attendees/#{atttendee_id}", params: { attendee: { user_id: new_user_id, event_id: new_event_id } } | ||
|
||
# attendee = JSON.parse(response.body, symbolize_names: true) | ||
|
||
# expect(response).to be_successful | ||
# expect(response.status).to eq(200) | ||
|
||
# expect(attendee).to be_a(Hash) | ||
# expect(attendee).to have_key(:data) | ||
|
||
# expect(attendee[:data][:attributes][:user_id]).to eq(new_user_id) | ||
# expect(attendee[:data][:attributes][:event_id]).to eq(new_event_id) | ||
# end | ||
|
||
it "destroys an existing attendee" do | ||
atttendee_id = @attendee.id | ||
|
||
|
||
delete "/api/v1/attendees/#{atttendee_id}" | ||
expect(response).to be_successful | ||
expect(response.status).to eq(204) | ||
|
||
expect(Attendee.find_by(id: atttendee_id)).to be_nil | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.