Skip to content
This repository has been archived by the owner on May 19, 2022. It is now read-only.

Commit

Permalink
Game confirmed email
Browse files Browse the repository at this point in the history
  • Loading branch information
proglottis committed Mar 21, 2013
1 parent 818a1a4 commit a0b5e6b
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 5 deletions.
5 changes: 5 additions & 0 deletions app/controllers/games_controller.rb
Expand Up @@ -37,6 +37,11 @@ def show
def confirm
@game = Game.with_participant(current_user).readonly(false).find(params[:id])
if @game.confirm_user(current_user)
@game.game_ranks.each do |game_rank|
if game_rank.user != current_user && game_rank.user.game_confirmed_email?
Notifications.game_confirmed(game_rank.user, @game).deliver
end
end
redirect_to games_path
else
redirect_to game_path(@game)
Expand Down
7 changes: 7 additions & 0 deletions app/mailers/notifications.rb
Expand Up @@ -14,6 +14,13 @@ def game_confirmation(user, game)
mail(:to => @user.email, :subject => t('notifications.game_confirmation.subject'))
end

def game_confirmed(user, game)
@user = user
@game = game
@tournament = @game.tournament
mail(:to => @user.email, :subject => t('notifications.game_confirmed.subject'))
end

def challenged(challenge)
@challenge = challenge
@defender = challenge.defender
Expand Down
4 changes: 4 additions & 0 deletions app/views/notifications/game_confirmed.text.erb
@@ -0,0 +1,4 @@
<%= t '.confirmed' %>
<%= @tournament.name %> - <%= @game.versus %>
<%= game_url @game %>
3 changes: 3 additions & 0 deletions config/locales/en.yml
Expand Up @@ -111,6 +111,9 @@ en:
game_confirmation:
subject: Confirm game
game_logged: "A game you participated in has been logged. Follow the link to confirm:"
game_confirmed:
subject: Game confirmed
confirmed: "A game you participated in has been confirmed."
challenged:
subject: You have been challenged
challenged: "%{challenger} has challenged you on %{tournament}."
Expand Down
21 changes: 16 additions & 5 deletions test/integration/games_controller_test.rb
Expand Up @@ -43,11 +43,22 @@
must_have_content I18n.t('games.show.confirmed', :time => 'less than a minute')
end

it "must update game on final confirmation" do
@game_rank2.confirm
visit game_path @game
click_link I18n.t('games.show.confirm')
@game.reload.confirmed?.must_equal true
describe "on final confirmation" do
it "must update game on final confirmation" do
@game_rank2.confirm
visit game_path @game
click_link I18n.t('games.show.confirm')
@game.reload.confirmed?.must_equal true
end

it "must send game confirmed email to other users" do
@game_rank2.confirm
visit game_path @game
click_link I18n.t('games.show.confirm')
ActionMailer::Base.deliveries.length.must_equal 1
email = ActionMailer::Base.deliveries.first
email.to.must_equal [@user2.email]
end
end
end

Expand Down
18 changes: 18 additions & 0 deletions test/mailers/notifications_test.rb
Expand Up @@ -31,6 +31,24 @@
end
end

describe "#game_confirmed" do
before do
@game = create(:game)
@user1 = create(:user)
@user2 = create(:user)
@game_rank1 = create(:game_rank, :game => @game, :user => @user1, :position => 1)
@game_rank2 = create(:game_rank, :game => @game, :user => @user2, :position => 2)
end

it "must contain game details" do
mail = Notifications.game_confirmed @user1, @game
mail.subject.must_equal I18n.t('notifications.game_confirmed.subject')
mail.to.must_equal [@user1.email]
mail.body.encoded.must_match @game.tournament.name
mail.body.encoded.must_match @game.versus
end
end

describe "#challenged" do
it "must contain challenge details" do
challenge = create(:challenge)
Expand Down

0 comments on commit a0b5e6b

Please sign in to comment.