Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/controllers/invitation_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ def set_invitation
end

def has_remaining_seats? invitation
invitation.sessions.seats > invitation.sessions.attending_invitations.length
invitation.sessions.host.seats > invitation.sessions.attending_invitations.length
end
end
2 changes: 1 addition & 1 deletion app/models/sponsor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ class Sponsor < ActiveRecord::Base
has_many :sponsor_sessions
has_many :sessions, through: :sponsor_sessions

validates :name, :address, :avatar, :website, presence: true
validates :name, :address, :avatar, :website, :seats, presence: true

scope :latest, -> { order("updated_at desc").limit(7) }
end
5 changes: 5 additions & 0 deletions db/migrate/20131112221451_remove_seats_from_sessions.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class RemoveSeatsFromSessions < ActiveRecord::Migration
def change
remove_column :sessions, :seats, :integer
end
end
5 changes: 5 additions & 0 deletions db/migrate/20131112221641_add_seats_to_sponsor.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddSeatsToSponsor < ActiveRecord::Migration
def change
add_column :sponsors, :seats, :integer, default: 15
end
end
4 changes: 2 additions & 2 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20131111024701) do
ActiveRecord::Schema.define(version: 20131112221641) do

create_table "addresses", force: true do |t|
t.string "flat"
Expand Down Expand Up @@ -106,7 +106,6 @@
t.datetime "date_and_time"
t.datetime "created_at"
t.datetime "updated_at"
t.integer "seats", default: 15
end

create_table "sponsor_sessions", force: true do |t|
Expand All @@ -127,6 +126,7 @@
t.datetime "updated_at"
t.string "avatar"
t.string "website"
t.integer "seats", default: 15
end

end
4 changes: 3 additions & 1 deletion spec/fabricators/session_fabricator.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
Fabricator(:sessions) do
seats 1
date_and_time { DateTime.now+2.days }
title "Course title"
after_build do |sessions|
Fabricate(:sponsor_session, sessions: sessions, sponsor: Fabricate(:sponsor), host: true )
end
end
6 changes: 0 additions & 6 deletions spec/fabricators/sponsor_session_fabricator.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,2 @@
Fabricator(:sponsor_session) do
sponsor
sessions
end

Fabricator(:hosted_session, from: :sponsor_session) do
host true
end
2 changes: 1 addition & 1 deletion spec/features/accepting_invitation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
let(:accepting_invitation_path) { accept_invitation_path(invitation) }
let(:rejecting_invitation_path) { reject_invitation_path(invitation) }

let(:set_no_available_slots) { invitation.sessions.update_attribute(:seats, 0) }
let(:set_no_available_slots) { invitation.sessions.host.update_attribute(:seats, 0) }

it_behaves_like "invitation route"

Expand Down
1 change: 0 additions & 1 deletion spec/models/sessions_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
it { should respond_to(:title) }
it { should respond_to(:description) }
it { should respond_to(:date_and_time) }
it { should respond_to(:seats) }
it { should respond_to(:sponsors) }
it { should respond_to(:sponsor_sessions)}

Expand Down
11 changes: 4 additions & 7 deletions spec/models/sponsor_session_spec.rb
Original file line number Diff line number Diff line change
@@ -1,32 +1,29 @@
require 'spec_helper'

describe SponsorSession do
subject(:sponsor_session) { Fabricate(:hosted_session) }
let!(:session) { Fabricate(:sessions) }

context 'when the session has more than one host' do
let(:other_sponsor) { Fabricate(:sponsor) }

let(:another_host_session) do
Fabricate.build(:sponsor_session,
sponsor: other_sponsor,
sessions: sponsor_session.sessions,
sessions: session,
host: true)
end

it { another_host_session.should have(1).error_on(:host) }
end

context '#scopes' do
let!(:hosted_session) { Fabricate(:hosted_session) }

it '#hosts' do
expect(SponsorSession.hosts.length).to eq(1)
end

describe '#for_session' do
let(:session) { hosted_session.sessions }

it { expect(SponsorSession.for_session(session.id).length).to eq(1) }
it '#for_session' do
expect(SponsorSession.for_session(session.id).length).to eq(1)
end
end
end
7 changes: 7 additions & 0 deletions spec/models/sponsor_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
it { should respond_to(:sessions) }
it { should respond_to(:sponsor_sessions) }
it { should respond_to(:avatar) }
it { should respond_to(:seats) }
it { should be_valid }

context 'validations' do
Expand Down Expand Up @@ -38,6 +39,12 @@
it{ should_not be_valid }
it{ should have(1).error_on(:avatar) }
end

describe '#seats' do
before { sponsor.seats = nil }

it { should have(1).error_on(:seats) }
end
end
end

Expand Down