summaryrefslogtreecommitdiff
path: root/app/models
diff options
context:
space:
mode:
Diffstat (limited to 'app/models')
-rw-r--r--app/models/tournament.rb2
-rw-r--r--app/models/user.rb15
2 files changed, 16 insertions, 1 deletions
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)
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