Skip to content

Commit

Permalink
Allow export of previous year sessions
Browse files Browse the repository at this point in the history
  • Loading branch information
caseyhelbling committed Mar 19, 2016
1 parent 1dfd3a1 commit df0cba4
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
7 changes: 6 additions & 1 deletion src/app/controllers/sessions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,12 @@ def update
end

def index
@sessions = Event.current_event.sessions
if params[:event_id].present?
@event = Event.find(params[:event_id])
else
@event = Event.current_event
end
@sessions = @event.sessions
respond_with @sessions do |format|
format.json {
render json: SessionsJsonBuilder.new.to_json(@sessions.uniq.flatten)
Expand Down
22 changes: 21 additions & 1 deletion src/spec/controllers/sessions_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
end

let(:user) { create(:participant) }
let(:event) { create(:event) }

context "with an existing session" do
let!(:session) { create(:session) }
let!(:session) { create(:session, event: event) }

describe "update" do
it "should not be updatable by someone who doesn't own it" do
Expand Down Expand Up @@ -68,6 +69,25 @@
expect(response.body).to eq SessionsJsonBuilder.new.to_json([session])
end
end

describe "when there are multiple events" do
let!(:event2) { create :event }
let!(:joe) { create :joe }
let!(:session2) { create(:session, event: event2, participant: joe) }
before do
Settings.instance.update_attribute(:current_event_id, event.id)
end

it "should allow exporting previous events" do
get :index, { event_id: event2.id }
expect(response).to be_successful
expect(assigns[:sessions]).to eq [session2]

get :index, { event_id: event.id }
expect(response).to be_successful
expect(assigns[:sessions]).to eq [session]
end
end
end
end

Expand Down

0 comments on commit df0cba4

Please sign in to comment.