Skip to content

Commit

Permalink
Hook up ability to move signups around a raid
Browse files Browse the repository at this point in the history
Accepting, unaccepting, cancelling and re-enqueuing are now fully
supported and only allowed by the appropriate party.
  • Loading branch information
jasonroelofs committed Jul 13, 2012
1 parent 381e670 commit cf14657
Show file tree
Hide file tree
Showing 7 changed files with 104 additions and 2 deletions.
14 changes: 14 additions & 0 deletions app/controllers/signups_controller.rb
Expand Up @@ -2,6 +2,9 @@ class SignupsController < ApplicationController

requires_user

# /raids/:raid_id/signups
#
# Sign a character up to the given Raid
def create
raid_id = params[:raid_id].to_i

Expand All @@ -11,4 +14,15 @@ def create
redirect_to raid_path(raid_id)
end

# /signups/:id/:command
#
# Run +command+ on the given signup
def update
signup = Repository.for(Signup).find params[:id].to_i
action = UpdateSignup.new current_user, signup
action.run params[:command]

redirect_to raid_path(signup.raid)
end

end
1 change: 0 additions & 1 deletion app/interactors/update_signup.rb
Expand Up @@ -41,7 +41,6 @@ def run(action)
@signup.acceptance_status = @processor.new_status

Repository.for(Signup).save @signup
@signup
end

def initialize_processor_and_permissions
Expand Down
5 changes: 5 additions & 0 deletions app/views/raids/_signup.html.erb
@@ -1,4 +1,9 @@
<div class="signup">
<span><%= signup.character_name %></span>
<span><%= signup.role %></span>
<span class="actions">
<% list_available_signup_actions(signup).each do |action| %>
<%= link_to action.name, update_signup_path(signup.id, command: action.action) %>
<% end %>
</span>
</div>
2 changes: 2 additions & 0 deletions config/routes.rb
Expand Up @@ -8,6 +8,8 @@
resources :signups
end

match "/signups/:id/:command", :to => "signups#update", :as => "update_signup"

match "/login", :to => "sessions#new", :as => "login"
match "/logout", :to => "sessions#destroy", :as => "logout"
end
47 changes: 47 additions & 0 deletions features/raids/manage_raid.feature
@@ -0,0 +1,47 @@
Feature: Managing Raid Signups

Background:
Given I am signed in as "jason"
And today is "2012/07/01"
And "jason" has scheduled the following raids
| where | when | start | invite_offset |
| ICC | 2012/07/01 | 20:00 | 15 |
And "jason" has the following characters
| game | region | server | name |
| wow | US | Detheroc | Weemuu |

And "jason" signed up "Weemuu" for "ICC"
When I am at the home page
And I follow "ICC"

Scenario: Raid leader can manage signup acceptance
# Available -> Accept
Then I should see "Accept" within ".available"

When I follow "Accept"
Then I should see "Weemuu" within ".accepted"
And I should see "Unaccept" within ".accepted"

# Accept -> Available
When I follow "Unaccept"
Then I should see "Weemuu" within ".available"
And I should see "Accept" within ".available"

# Available -> Cancelled
When I follow "Cancel"
Then I should see "Weemuu" within ".cancelled"
And I should see "Enqueue" within ".cancelled"
And I should not see "Accept" within ".cancelled"

# Cancelled -> Available
When I follow "Enqueue"
Then I should see "Weemuu" within ".available"
And I should see "Accept" within ".available"
And I should see "Cancel" within ".available"

# Accepted -> Cancelled
When I follow "Accept"
And I follow "Cancel"
Then I should see "Weemuu" within ".cancelled"
And I should see "Enqueue" within ".cancelled"
And I should not see "Accept" within ".cancelled"
15 changes: 14 additions & 1 deletion features/step_definitions/raid_steps.rb
@@ -1,6 +1,10 @@
def find_user_by_login(login)
Repository.for(User).find_by_login(login)
end

Given /^"(.*?)" has scheduled the following raids$/ do |login, table|
repo = Repository.for(Raid)
current_user = Repository.for(User).find_by_login(login)
current_user = find_user_by_login(login)

table.hashes.each_with_index do |row, i|
r = Raid.new(
Expand All @@ -21,3 +25,12 @@
repo.save r
end
end

Given /^"(.*?)" signed up "(.*?)" for "(.*?)"$/ do |login, char_name, raid_location|
current_user = find_user_by_login(login)
character = Repository.for(Character).find_all_for_user(current_user).find {|c| c.name == char_name }
raid = Repository.for(Raid).all.find {|r| r.where == raid_location }

s = Signup.new raid: raid, character: character, user: current_user
Repository.for(Signup).save s
end
22 changes: 22 additions & 0 deletions test/integration/signups_controller_test.rb
Expand Up @@ -29,4 +29,26 @@ class SignupsControllerTest < ActionController::TestCase
end
end

describe "#update" do
it "requires a logged in user" do
put :update, {}
must_redirect_to login_path
end

describe "when authenticated" do
it "runs the given command to update given signup" do
login_as_user
raid = Raid.new id: 7
signup = Signup.new raid: raid

Repository.for(Signup).expects(:find).with(14).returns(signup)
UpdateSignup.any_instance.expects(:run).with("accept")

put :update, :id => 14, :command => :accept

must_redirect_to raid_path(:id => 7)
end
end
end

end

0 comments on commit cf14657

Please sign in to comment.