summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/models/invite_code_validator.rb8
-rw-r--r--lib/tasks/invite_code.rake21
-rw-r--r--test/unit/invite_code_test.rb17
3 files changed, 16 insertions, 30 deletions
diff --git a/app/models/invite_code_validator.rb b/app/models/invite_code_validator.rb
index d52e698..9dfe6fa 100644
--- a/app/models/invite_code_validator.rb
+++ b/app/models/invite_code_validator.rb
@@ -1,4 +1,5 @@
class InviteCodeValidator < ActiveModel::Validator
+
def validate(user)
user_invite_code = InviteCode.find_by_invite_code user.invite_code
@@ -8,9 +9,6 @@ class InviteCodeValidator < ActiveModel::Validator
elsif has_no_uses_left?(user_invite_code)
add_error_to_user("This code has already been used", user)
-
- # elsif count_greater_than_zero?(user_invite_code)
- # add_error_to_user("This code has already been used", user)
end
end
@@ -23,10 +21,6 @@ class InviteCodeValidator < ActiveModel::Validator
code.invite_count >= code.invite_max_uses
end
- # def count_greater_than_zero?(code)
- # code.invite_count > 0
- # end
-
def add_error_to_user(error, user)
user.errors[:invite_code] << error
end
diff --git a/lib/tasks/invite_code.rake b/lib/tasks/invite_code.rake
index f3bafac..6623640 100644
--- a/lib/tasks/invite_code.rake
+++ b/lib/tasks/invite_code.rake
@@ -1,16 +1,25 @@
desc "Generate a batch of invite codes"
-task :generate_invites, [:n] => :environment do |task, args|
+task :generate_invites, [:n, :u] => :environment do |task, args|
- codes = args.n
- codes = codes.to_i
+ codes = args.n
+ codes = codes.to_i
- codes.times do |x|
+ if args.u == nil
+ max_uses = 1
+
+ elsif
+ max_uses = args.u
+ max_uses = max_uses.to_i
+ end
+
+ codes.times do |x|
x = InviteCode.new
+ x.invite_max_uses = max_uses
x.save
- puts "#{x.invite_code} Code generated."
-
+ puts "#{x.invite_code} Code generated with #{x.invite_max_uses} uses."
end
+
end
diff --git a/test/unit/invite_code_test.rb b/test/unit/invite_code_test.rb
index 7e14a03..adaf397 100644
--- a/test/unit/invite_code_test.rb
+++ b/test/unit/invite_code_test.rb
@@ -20,23 +20,6 @@ class InviteCodeTest < ActiveSupport::TestCase
assert_equal code1.invite_count, 0
end
-
- # test "Invite count >0 is not accepted for new account signup" do
- # validator = InviteCodeValidator.new nil
- #
- # user_code = InviteCode.new
- # user_code.invite_count = 1
- # user_code.save
- #
- # user = FactoryGirl.build :user
- # user.invite_code = user_code.invite_code
- #
- # validator.validate(user)
- #
- # assert_equal ["This code has already been used"], user.errors[:invite_code]
- #
- # end
-
test "Invite count >= invite max uses is not accepted for new account signup" do
validator = InviteCodeValidator.new nil