From b62c07359a9cbc7bad93c375c50d266a40dfe539 Mon Sep 17 00:00:00 2001 From: tkimia Date: Thu, 3 Apr 2014 16:24:36 -0400 Subject: Users can't join twice --- app/models/tournament.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app/models') diff --git a/app/models/tournament.rb b/app/models/tournament.rb index 87b516e..4483535 100644 --- a/app/models/tournament.rb +++ b/app/models/tournament.rb @@ -9,7 +9,7 @@ class Tournament < ActiveRecord::Base end def joinable_by?(user) - return ((not user.nil?) and user.in_group?(:player) and open?) + return ((not user.nil?) and user.in_group?(:player) and open? and !players.include?(user)) end def join(user) -- cgit v1.2.3-2-g168b From dfe5dbd2ada1841b09f70bfd742c10ba878f74fe Mon Sep 17 00:00:00 2001 From: shumakl Date: Thu, 3 Apr 2014 16:44:29 -0400 Subject: Use the null object pattern for current_user when not logged in --- app/models/user.rb | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'app/models') diff --git a/app/models/user.rb b/app/models/user.rb index 277d885..016c155 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -91,3 +91,18 @@ class User < ActiveRecord::Base validates :password, length: { minimum: 6 } end +class NilUser + def nil? + return true + end + def can?(action) + return false + end + def method_missing(name, *args) + # Throw an error if User doesn't have this method + super unless User.new.respond_to?(name) + # User has this method -- return a blank value + # 'false' if the method ends with '?'; 'nil' otherwise. + name.ends_with?('?') ? false : nil + end +end -- cgit v1.2.3-2-g168b