Permalink
Browse files

When there is only one attendee signing up for a tournament, activity…

…, or editing travel plans, skip the "choose attendee" page
  • Loading branch information...
jaredbeck committed Jun 11, 2012
1 parent b79a8a7 commit 6e5fccd820377fbd0b221ee4f4fb5e0532235364
Showing with 39 additions and 0 deletions.
  1. +4 −0 app/controllers/users_controller.rb
  2. +35 −0 spec/controllers/users_controller_spec.rb
@@ -15,6 +15,10 @@ def choose_attendee
raise 'Invalid destination page'
end
+ if @user.attendees.count == 1
+ redirect_to edit_attendee_path(@user.attendees.first, @destination_page)
+ end
+
@destination_page_description = "sign up for " + @destination_page
end
@@ -8,6 +8,41 @@
end
describe UsersController do
+
+ describe "#choose_attendee" do
+ let(:user) { FactoryGirl.create :user }
+ let(:page) { :events }
+
+ before do
+ sign_in user
+ end
+
+ def get_choose_attendee user, page
+ get :choose_attendee, year: user.year, id: user.id, destination_page: page
+ end
+
+ it "is succesful when there are no attendees" do
+ get_choose_attendee user, page
+ response.should be_success
+ end
+
+ it "redirects to the destination page when there is only one attendee" do
+ attendee = FactoryGirl.create :attendee, user: user
+ get_choose_attendee user, page
+ response.should redirect_to edit_attendee_path(attendee, page)
+ end
+
+ it "is succesful when there are two or more attendees" do
+ 1.upto(2) { FactoryGirl.create :attendee, user: user }
+ get_choose_attendee user, page
+ response.should be_success
+ end
+
+ it "is raises an error if given an invalid page" do
+ expect { get_choose_attendee user, "foobar" }.to raise_error
+ end
+ end
+
context "even when the user has zero attendees" do
# Nomrally, rspec-rails controller specs do not render views

0 comments on commit 6e5fccd

Please sign in to comment.