Skip to content

Commit

Permalink
run validations even when invite_key is blank. fix scambra#136
Browse files Browse the repository at this point in the history
  • Loading branch information
scambra committed Oct 25, 2011
1 parent f831f30 commit f8b283b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/devise_invitable/model.rb
Expand Up @@ -131,7 +131,7 @@ def _invite(attributes={}, invited_by=nil, &block)
invitable.errors.add(invite_key, :taken) unless invitable.invited? && self.resend_invitation
end

if invitable.errors.empty?
if self.validate_on_invite || invitable.errors.empty?
yield invitable if block_given?
mail = invitable.invite!
end
Expand Down
2 changes: 1 addition & 1 deletion lib/devise_invitable/version.rb
@@ -1,3 +1,3 @@
module DeviseInvitable
VERSION = '0.5.5'
VERSION = '0.5.6'
end
11 changes: 10 additions & 1 deletion test/models/invitable_test.rb
Expand Up @@ -173,7 +173,16 @@ def setup
validate_on_invite = User.validate_on_invite
User.validate_on_invite = true
invited_user = User.invite!(:email => "valid@email.com", :username => "a"*50)
assert !invited_user.errors.empty?
assert invited_user.errors[:username].present?
User.validate_on_invite = validate_on_invite
end

test 'should validate other attributes when validate_on_invite is enabled and email is not present' do
validate_on_invite = User.validate_on_invite
User.validate_on_invite = true
invited_user = User.invite!(:email => "", :username => "a"*50)
assert invited_user.errors[:email].present?
assert invited_user.errors[:username].present?
User.validate_on_invite = validate_on_invite
end

Expand Down

0 comments on commit f8b283b

Please sign in to comment.