Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
stop registrtion for taken slots ( doesn't deal with concurrency yet )
  • Loading branch information
Perryn committed Dec 31, 2009
1 parent ea2cfc2 commit bb37e03
Show file tree
Hide file tree
Showing 14 changed files with 73,773 additions and 3 deletions.
8 changes: 6 additions & 2 deletions app/controllers/registrations_controller.rb
Expand Up @@ -10,8 +10,12 @@ def create
registration = Registration.new(params[:registration])
if registration.valid?
time_slot = TimeSlot.find(params[:registration][:time_slot_id])
time_slot.registration = registration
flash[:thanks_for_registering] = "true"
if time_slot.available?
time_slot.registration = registration
flash[:thanks_for_registering] = "true"
else
flash[:too_slow] = "true"
end
end
flash[:registration] = registration
redirect_to :action => :new
Expand Down
4 changes: 4 additions & 0 deletions app/models/time_slot.rb
Expand Up @@ -4,5 +4,9 @@ class TimeSlot < ActiveRecord::Base
def status
registration ? "taken" : "free"
end

def available?
status == "free"
end

end
4 changes: 4 additions & 0 deletions app/views/registrations/new.html.haml
Expand Up @@ -26,5 +26,9 @@
.notice.thanks_for_registering
Thanks for helping out!
We have sent you a confirmation email with further instructions.
- if flash[:too_slow]
.notice.too_slow
Too Slow! Someone else just registered for that time
Please choose another time.


Binary file modified db/development.sqlite3
Binary file not shown.
1 change: 1 addition & 0 deletions db/migrate/20091229030847_create_time_slots.rb
Expand Up @@ -2,6 +2,7 @@ class CreateTimeSlots < ActiveRecord::Migration
def self.up
create_table :time_slots do |t|
t.datetime :start_time
t.integer :lock_version
t.references :day_of_action
t.timestamps
end
Expand Down
1 change: 1 addition & 0 deletions db/schema.rb
Expand Up @@ -27,6 +27,7 @@

create_table "time_slots", :force => true do |t|
t.datetime "start_time"
t.integer "lock_version"
t.integer "day_of_action_id"
t.datetime "created_at"
t.datetime "updated_at"
Expand Down
Binary file modified db/test.sqlite3
Binary file not shown.
7 changes: 7 additions & 0 deletions features/register_for_timeslot.feature
Expand Up @@ -39,6 +39,13 @@ Feature: Volunteer registers for a time slot in a day of action
Then I will be reminded to choose a time
And the "What is your email address?" field should contain "foo@bar.com"

Scenario: picks a taken time
Given a Day of Action has been set up for "1975-07-30" in "Canberra"

When I view the roster for the day of action
And someone else registers for the "09:15" time slot while I am looking
And I register for the "09:15" timeslot
Then I will be asked to pick a different time

Scenario: Someone else gets in first
Scenario: picks a taken time
10 changes: 10 additions & 0 deletions features/step_definitions/register_for_timeslot_steps.rb
Expand Up @@ -8,6 +8,12 @@
click_button "Register"
end

When /^someone else registers for the "([^\"]*)" time slot while I am looking$/ do |time|
time_slot = @day_of_action.time_slots.select{|slot| slot.start_time.strftime("%I:%M") == "09:15"}[0]
time_slot.registration = Registration.new(:email_address => "foo@bar.com")
end


Then /^I will be thanked and asked to look for an email$/ do
response.should have_tag(".thanks_for_registering")
end
Expand All @@ -20,6 +26,10 @@
response.should contain("please choose a time")
end

Then /^I will be asked to pick a different time$/ do
response.should contain("Please choose another time")
end

Then /^the "([^\"]*)" timeslot will still be selected$/ do |time|
field_labeled(time).should be_checked
end
70,654 changes: 70,654 additions & 0 deletions log/cucumber.log

Large diffs are not rendered by default.

2,809 changes: 2,809 additions & 0 deletions log/development.log

Large diffs are not rendered by default.

250 changes: 250 additions & 0 deletions log/test.log
Expand Up @@ -4723,4 +4723,254 @@ Completed in 61ms (View: 0, DB: 0) | 200 OK [http://test.host/days_of_action/3/r
Processing RegistrationsController#new (for 0.0.0.0 at 2009-12-31 17:29:27) [GET]
Parameters: {"days_of_action_id"=>"3"}
Rendering registrations/new
Completed in 1ms (View: 0, DB: 0) | 200 OK [http://test.host/days_of_action/3/registrations/new]
TimeSlot Create (0.4ms) INSERT INTO "time_slots" ("updated_at", "lock_version", "day_of_action_id", "start_time", "created_at") VALUES('2009-12-31 07:39:42', 0, NULL, NULL, '2009-12-31 07:39:42')
Registration Load (0.1ms) SELECT * FROM "registrations" WHERE ("registrations".time_slot_id = 1) LIMIT 1
TimeSlot Create (0.3ms) INSERT INTO "time_slots" ("updated_at", "lock_version", "day_of_action_id", "start_time", "created_at") VALUES('2009-12-31 07:39:42', 0, NULL, NULL, '2009-12-31 07:39:42')
TimeSlot Create (0.2ms) INSERT INTO "time_slots" ("updated_at", "lock_version", "day_of_action_id", "start_time", "created_at") VALUES('2009-12-31 07:39:42', 0, NULL, NULL, '2009-12-31 07:39:42')
Registration Load (0.1ms) SELECT * FROM "registrations" WHERE ("registrations".time_slot_id = 1) LIMIT 1
TimeSlot Create (0.3ms) INSERT INTO "time_slots" ("updated_at", "lock_version", "day_of_action_id", "start_time", "created_at") VALUES('2009-12-31 07:39:42', 0, NULL, NULL, '2009-12-31 07:39:42')
Registration Load (0.1ms) SELECT * FROM "registrations" WHERE ("registrations".time_slot_id = 1) LIMIT 1
TimeSlot Create (0.4ms) INSERT INTO "time_slots" ("updated_at", "lock_version", "day_of_action_id", "start_time", "created_at") VALUES('2009-12-31 07:40:51', 0, NULL, NULL, '2009-12-31 07:40:51')
Registration Load (0.1ms) SELECT * FROM "registrations" WHERE ("registrations".time_slot_id = 1) LIMIT 1
TimeSlot Create (0.3ms) INSERT INTO "time_slots" ("updated_at", "lock_version", "day_of_action_id", "start_time", "created_at") VALUES('2009-12-31 07:40:51', 0, NULL, NULL, '2009-12-31 07:40:51')
Registration Load (0.1ms) SELECT * FROM "registrations" WHERE ("registrations".time_slot_id = 1) LIMIT 1
TimeSlot Create (0.3ms) INSERT INTO "time_slots" ("updated_at", "lock_version", "day_of_action_id", "start_time", "created_at") VALUES('2009-12-31 07:40:51', 0, NULL, NULL, '2009-12-31 07:40:51')
Registration Load (0.1ms) SELECT * FROM "registrations" WHERE ("registrations".time_slot_id = 1) LIMIT 1
TimeSlot Create (0.3ms) INSERT INTO "time_slots" ("updated_at", "lock_version", "day_of_action_id", "start_time", "created_at") VALUES('2009-12-31 07:40:51', 0, NULL, NULL, '2009-12-31 07:40:51')
Registration Load (0.1ms) SELECT * FROM "registrations" WHERE ("registrations".time_slot_id = 1) LIMIT 1
TimeSlot Create (0.4ms) INSERT INTO "time_slots" ("updated_at", "lock_version", "day_of_action_id", "start_time", "created_at") VALUES('2009-12-31 07:41:24', 0, NULL, NULL, '2009-12-31 07:41:24')
Registration Load (0.1ms) SELECT * FROM "registrations" WHERE ("registrations".time_slot_id = 1) LIMIT 1
TimeSlot Create (0.3ms) INSERT INTO "time_slots" ("updated_at", "lock_version", "day_of_action_id", "start_time", "created_at") VALUES('2009-12-31 07:41:24', 0, NULL, NULL, '2009-12-31 07:41:24')
Registration Load (0.1ms) SELECT * FROM "registrations" WHERE ("registrations".time_slot_id = 1) LIMIT 1
TimeSlot Create (0.2ms) INSERT INTO "time_slots" ("updated_at", "lock_version", "day_of_action_id", "start_time", "created_at") VALUES('2009-12-31 07:41:24', 0, NULL, NULL, '2009-12-31 07:41:24')
Registration Load (0.1ms) SELECT * FROM "registrations" WHERE ("registrations".time_slot_id = 1) LIMIT 1
TimeSlot Create (0.3ms) INSERT INTO "time_slots" ("updated_at", "lock_version", "day_of_action_id", "start_time", "created_at") VALUES('2009-12-31 07:41:24', 0, NULL, NULL, '2009-12-31 07:41:24')
Registration Load (0.1ms) SELECT * FROM "registrations" WHERE ("registrations".time_slot_id = 1) LIMIT 1


Processing RegistrationsController#new (for 0.0.0.0 at 2009-12-31 19:00:45) [GET]
Parameters: {"days_of_action_id"=>"3"}
Rendering registrations/new
Completed in 5ms (View: 0, DB: 0) | 200 OK [http://test.host/days_of_action/3/registrations/new]


Processing RegistrationsController#new (for 0.0.0.0 at 2009-12-31 19:00:45) [GET]
Parameters: {"days_of_action_id"=>"3"}
Rendering registrations/new
Completed in 3ms (View: 0, DB: 0) | 200 OK [http://test.host/days_of_action/3/registrations/new]


Processing RegistrationsController#new (for 0.0.0.0 at 2009-12-31 19:00:45) [GET]
Parameters: {"days_of_action_id"=>"3"}
Rendering registrations/new
Completed in 1ms (View: 0, DB: 0) | 200 OK [http://test.host/days_of_action/3/registrations/new]


Processing RegistrationsController#create (for 0.0.0.0 at 2009-12-31 19:00:45) [POST]
Parameters: {"registration"=>{"time_slot_id"=>"3", "foo"=>"bar"}}
Redirected to http://test.host/registrations/new
Completed in 1ms (DB: 0) | 302 Found [http://test.host/registrations/create?registration%5Bfoo%5D=bar&registration%5Btime_slot_id%5D=3]


Processing RegistrationsController#create (for 0.0.0.0 at 2009-12-31 19:00:45) [POST]
Parameters: {"registration"=>{"time_slot_id"=>"3"}}
Redirected to http://test.host/registrations/new
Completed in 1ms (DB: 0) | 302 Found [http://test.host/registrations/create?registration%5Btime_slot_id%5D=3]


Processing RegistrationsController#create (for 0.0.0.0 at 2009-12-31 19:00:45) [POST]
Parameters: {"registration"=>{"time_slot_id"=>"3"}}
Redirected to http://test.host/registrations/new
Completed in 0ms (DB: 0) | 302 Found [http://test.host/registrations/create?registration%5Btime_slot_id%5D=3]


Processing RegistrationsController#new (for 0.0.0.0 at 2009-12-31 19:01:01) [GET]
Parameters: {"days_of_action_id"=>"3"}
Rendering registrations/new
Completed in 5ms (View: 0, DB: 0) | 200 OK [http://test.host/days_of_action/3/registrations/new]


Processing RegistrationsController#new (for 0.0.0.0 at 2009-12-31 19:01:01) [GET]
Parameters: {"days_of_action_id"=>"3"}
Rendering registrations/new
Completed in 3ms (View: 0, DB: 0) | 200 OK [http://test.host/days_of_action/3/registrations/new]


Processing RegistrationsController#new (for 0.0.0.0 at 2009-12-31 19:01:01) [GET]
Parameters: {"days_of_action_id"=>"3"}
Rendering registrations/new
Completed in 1ms (View: 0, DB: 0) | 200 OK [http://test.host/days_of_action/3/registrations/new]


Processing RegistrationsController#create (for 0.0.0.0 at 2009-12-31 19:01:01) [POST]
Parameters: {"registration"=>{"time_slot_id"=>"3", "foo"=>"bar"}}
Redirected to http://test.host/registrations/new
Completed in 1ms (DB: 0) | 302 Found [http://test.host/registrations/create?registration%5Bfoo%5D=bar&registration%5Btime_slot_id%5D=3]


Processing RegistrationsController#create (for 0.0.0.0 at 2009-12-31 19:01:01) [POST]
Parameters: {"registration"=>{"time_slot_id"=>"3"}}
Redirected to http://test.host/registrations/new
Completed in 1ms (DB: 0) | 302 Found [http://test.host/registrations/create?registration%5Btime_slot_id%5D=3]


Processing RegistrationsController#create (for 0.0.0.0 at 2009-12-31 19:01:01) [POST]
Parameters: {"registration"=>{"time_slot_id"=>"3"}}
Redirected to http://test.host/registrations/new
Completed in 0ms (DB: 0) | 302 Found [http://test.host/registrations/create?registration%5Btime_slot_id%5D=3]


Processing RegistrationsController#create (for 0.0.0.0 at 2009-12-31 19:01:01) [POST]
Parameters: {"registration"=>{"time_slot_id"=>"3"}}
Redirected to http://test.host/registrations/new
Completed in 1ms (DB: 0) | 302 Found [http://test.host/registrations/create?registration%5Btime_slot_id%5D=3]


Processing RegistrationsController#new (for 0.0.0.0 at 2009-12-31 19:01:23) [GET]
Parameters: {"days_of_action_id"=>"3"}
Rendering registrations/new
Completed in 5ms (View: 0, DB: 0) | 200 OK [http://test.host/days_of_action/3/registrations/new]


Processing RegistrationsController#new (for 0.0.0.0 at 2009-12-31 19:01:23) [GET]
Parameters: {"days_of_action_id"=>"3"}
Rendering registrations/new
Completed in 3ms (View: 0, DB: 0) | 200 OK [http://test.host/days_of_action/3/registrations/new]


Processing RegistrationsController#new (for 0.0.0.0 at 2009-12-31 19:01:23) [GET]
Parameters: {"days_of_action_id"=>"3"}
Rendering registrations/new
Completed in 1ms (View: 0, DB: 0) | 200 OK [http://test.host/days_of_action/3/registrations/new]


Processing RegistrationsController#create (for 0.0.0.0 at 2009-12-31 19:01:23) [POST]
Parameters: {"registration"=>{"time_slot_id"=>"3", "foo"=>"bar"}}
Redirected to http://test.host/registrations/new
Completed in 1ms (DB: 0) | 302 Found [http://test.host/registrations/create?registration%5Bfoo%5D=bar&registration%5Btime_slot_id%5D=3]


Processing RegistrationsController#create (for 0.0.0.0 at 2009-12-31 19:01:23) [POST]
Parameters: {"registration"=>{"time_slot_id"=>"3"}}
Redirected to http://test.host/registrations/new
Completed in 1ms (DB: 0) | 302 Found [http://test.host/registrations/create?registration%5Btime_slot_id%5D=3]


Processing RegistrationsController#create (for 0.0.0.0 at 2009-12-31 19:01:23) [POST]
Parameters: {"registration"=>{"time_slot_id"=>"3"}}
Redirected to http://test.host/registrations/new
Completed in 0ms (DB: 0) | 302 Found [http://test.host/registrations/create?registration%5Btime_slot_id%5D=3]


Processing RegistrationsController#create (for 0.0.0.0 at 2009-12-31 19:01:24) [POST]
Parameters: {"registration"=>{"time_slot_id"=>"3"}}
Redirected to http://test.host/registrations/new
Completed in 1ms (DB: 0) | 302 Found [http://test.host/registrations/create?registration%5Btime_slot_id%5D=3]
DayOfAction Create (0.5ms) INSERT INTO "day_of_actions" ("updated_at", "date", "time_zone", "created_at") VALUES('2009-12-31 08:01:36', '--- &id002 !ruby/object:Spec::Mocks::Mock
mock_proxy: !ruby/object:Spec::Mocks::Proxy
already_proxied_respond_to: false
error_generator: &id001 !ruby/object:Spec::Mocks::ErrorGenerator
declared_as: Mock
name: date
target: *id002
expectation_ordering: !ruby/object:Spec::Mocks::OrderGroup
error_generator: *id001
ordering: []

expectations: []

messages_received: []

name: date
options:
:__declared_as: Mock
:null_object: false
proxied_methods: []

stubs: []

target: *id002
name: date
options:
:__declared_as: Mock
', '--- &id002 !ruby/object:Spec::Mocks::Mock
mock_proxy: !ruby/object:Spec::Mocks::Proxy
already_proxied_respond_to: false
error_generator: &id001 !ruby/object:Spec::Mocks::ErrorGenerator
declared_as: Mock
name: zone
target: *id002
expectation_ordering: !ruby/object:Spec::Mocks::OrderGroup
error_generator: *id001
ordering: []

expectations: []

messages_received: []

name: zone
options:
:__declared_as: Mock
:null_object: false
proxied_methods: []

stubs: []

target: *id002
name: zone
options:
:__declared_as: Mock
', '2009-12-31 08:01:36')
TimeSlot Create (0.2ms) INSERT INTO "time_slots" ("updated_at", "lock_version", "day_of_action_id", "start_time", "created_at") VALUES('2009-12-31 08:01:36', 0, 1, NULL, '2009-12-31 08:01:36')
TimeSlot Create (0.1ms) INSERT INTO "time_slots" ("updated_at", "lock_version", "day_of_action_id", "start_time", "created_at") VALUES('2009-12-31 08:01:36', 0, 1, NULL, '2009-12-31 08:01:36')
TimeSlot Create (0.3ms) INSERT INTO "time_slots" ("updated_at", "lock_version", "day_of_action_id", "start_time", "created_at") VALUES('2009-12-31 08:01:36', 0, NULL, NULL, '2009-12-31 08:01:36')
Registration Load (0.1ms) SELECT * FROM "registrations" WHERE ("registrations".time_slot_id = 1) LIMIT 1
TimeSlot Create (0.3ms) INSERT INTO "time_slots" ("updated_at", "lock_version", "day_of_action_id", "start_time", "created_at") VALUES('2009-12-31 08:01:36', 0, NULL, NULL, '2009-12-31 08:01:36')
Registration Load (0.1ms) SELECT * FROM "registrations" WHERE ("registrations".time_slot_id = 1) LIMIT 1
TimeSlot Create (0.3ms) INSERT INTO "time_slots" ("updated_at", "lock_version", "day_of_action_id", "start_time", "created_at") VALUES('2009-12-31 08:01:36', 0, NULL, NULL, '2009-12-31 08:01:36')
Registration Load (0.1ms) SELECT * FROM "registrations" WHERE ("registrations".time_slot_id = 1) LIMIT 1
TimeSlot Create (0.3ms) INSERT INTO "time_slots" ("updated_at", "lock_version", "day_of_action_id", "start_time", "created_at") VALUES('2009-12-31 08:01:36', 0, NULL, NULL, '2009-12-31 08:01:36')
Registration Load (0.1ms) SELECT * FROM "registrations" WHERE ("registrations".time_slot_id = 1) LIMIT 1


Processing RegistrationsController#create (for 0.0.0.0 at 2009-12-31 19:01:36) [POST]
Parameters: {"registration"=>{"time_slot_id"=>"3", "foo"=>"bar"}}
Redirected to http://test.host/registrations/new
Completed in 3ms (DB: 2) | 302 Found [http://test.host/registrations/create?registration%5Bfoo%5D=bar&registration%5Btime_slot_id%5D=3]


Processing RegistrationsController#create (for 0.0.0.0 at 2009-12-31 19:01:37) [POST]
Parameters: {"registration"=>{"time_slot_id"=>"3"}}
Redirected to http://test.host/registrations/new
Completed in 1ms (DB: 0) | 302 Found [http://test.host/registrations/create?registration%5Btime_slot_id%5D=3]


Processing RegistrationsController#create (for 0.0.0.0 at 2009-12-31 19:01:37) [POST]
Parameters: {"registration"=>{"time_slot_id"=>"3"}}
Redirected to http://test.host/registrations/new
Completed in 0ms (DB: 0) | 302 Found [http://test.host/registrations/create?registration%5Btime_slot_id%5D=3]


Processing RegistrationsController#create (for 0.0.0.0 at 2009-12-31 19:01:37) [POST]
Parameters: {"registration"=>{"time_slot_id"=>"3"}}
Redirected to http://test.host/registrations/new
Completed in 1ms (DB: 0) | 302 Found [http://test.host/registrations/create?registration%5Btime_slot_id%5D=3]


Processing RegistrationsController#new (for 0.0.0.0 at 2009-12-31 19:01:37) [GET]
Parameters: {"days_of_action_id"=>"3"}
Rendering registrations/new
Completed in 64ms (View: 0, DB: 0) | 200 OK [http://test.host/days_of_action/3/registrations/new]


Processing RegistrationsController#new (for 0.0.0.0 at 2009-12-31 19:01:37) [GET]
Parameters: {"days_of_action_id"=>"3"}
Rendering registrations/new
Completed in 64ms (View: 0, DB: 0) | 200 OK [http://test.host/days_of_action/3/registrations/new]


Processing RegistrationsController#new (for 0.0.0.0 at 2009-12-31 19:01:37) [GET]
Parameters: {"days_of_action_id"=>"3"}
Rendering registrations/new
Completed in 1ms (View: 0, DB: 0) | 200 OK [http://test.host/days_of_action/3/registrations/new]
14 changes: 13 additions & 1 deletion spec/controllers/registrations_controller_spec.rb
Expand Up @@ -42,7 +42,9 @@


@time_slot = mock("Time Slot")
@time_slot.stub!(:available?).and_return(true)
@time_slot.stub!(:registration=)

TimeSlot.stub!(:find).and_return(@time_slot)


Expand All @@ -55,11 +57,12 @@
post 'create', :registration => {:time_slot_id => "3", :foo => "bar"}
end

it "should redirect to new after successful create with flash flag set" do
it "should redirect to new after successful create with OK flag set" do
@registration.should_receive(:valid?).and_return(true)
post 'create', :registration => {:time_slot_id => "3" }
response.should redirect_to(:action => "new")
flash[:thanks_for_registering].should_not be_nil
flash[:too_slow].should be_nil
end

it "should redirect to new after failed create with flash model set" do
Expand All @@ -69,6 +72,15 @@
#so we can carry validation errors over the re-direct
flash[:registration].should be(@registration)
flash[:thanks_for_registering].should be_nil
flash[:too_slow].should be_nil
end

it "should redirect to new with too slow flag set if slot is unavailable" do
@time_slot.should_receive(:available?).and_return(false)
post 'create', :registration => {:time_slot_id => "3" }
response.should redirect_to(:action => "new")
flash[:thanks_for_registering].should be_nil
flash[:too_slow].should_not be_nil
end

end
Expand Down

0 comments on commit bb37e03

Please sign in to comment.