vrfs152: fixed broken tests
This commit is contained in:
parent
a3f8d9288c
commit
61de77c7e1
|
|
@ -14,15 +14,15 @@ module JamRuby
|
|||
belongs_to :sender , :inverse_of => :invited_users, :class_name => "JamRuby::User", :foreign_key => "sender_id"
|
||||
|
||||
# who is the invitation sent to?
|
||||
validates :email, format: {with: VALID_EMAIL_REGEX}, :if => lambda { |iu| iu.email.present? }
|
||||
validates :email, format: {with: VALID_EMAIL_REGEX}, :if => lambda { |iu| iu.email_required? }
|
||||
validates :autofriend, :inclusion => {:in => [nil, true, false]}
|
||||
validates :invitation_code, :presence => true
|
||||
validates :note, length: {maximum: 400}, no_profanity: true # 400 == arbitrary.
|
||||
|
||||
validate :one_facebook_invite_per_user, :if => lambda { |iu| iu.invite_medium == FB_MEDIUM }
|
||||
validate :one_facebook_invite_per_user, :if => lambda { |iu| iu.facebook_invite? }
|
||||
validate :valid_personalized_invitation
|
||||
# validate :not_accepted_twice
|
||||
validate :not_accepted_twice, :if => lambda { |iu| iu.email }
|
||||
validate :not_accepted_twice, :if => lambda { |iu| iu.email_required? }
|
||||
validate :can_invite?
|
||||
|
||||
after_save :track_user_progression
|
||||
|
|
@ -71,6 +71,18 @@ module JamRuby
|
|||
end
|
||||
end
|
||||
|
||||
def facebook_invite?
|
||||
FB_MEDIUM == self.invite_medium
|
||||
end
|
||||
|
||||
def email_required?
|
||||
!self.facebook_invite?
|
||||
end
|
||||
|
||||
def has_required_email?
|
||||
self.email.present? && self.email_required?
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def can_invite?
|
||||
|
|
|
|||
|
|
@ -106,7 +106,7 @@ describe InvitedUser do
|
|||
|
||||
it 'accepts empty emails' do
|
||||
user1 = FactoryGirl.create(:user)
|
||||
invited_user = FactoryGirl.create(:invited_user, :sender_id => user1.id, :email => '')
|
||||
invited_user = FactoryGirl.create(:invited_user, :sender_id => user1.id, :invite_medium => InvitedUser::FB_MEDIUM, :email => '')
|
||||
expect(invited_user.valid?).to eq(true)
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ class UsersController < ApplicationController
|
|||
|
||||
@invited_user = load_invited_user(params)
|
||||
|
||||
if !@invited_user.nil? && @invited_user.email && @invited_user.accepted
|
||||
if !@invited_user.nil? && @invited_user.has_required_email? && @invited_user.accepted
|
||||
# short-circuit out if this invitation is already accepted
|
||||
render "already_signed_up", :layout => 'landing'
|
||||
return
|
||||
|
|
|
|||
|
|
@ -71,21 +71,19 @@ describe "Invited Users API ", :type => :api do
|
|||
end
|
||||
|
||||
it "cant create with no email" do
|
||||
pending "changes to invitations broke this"
|
||||
post '/api/invited_users.json', {:note => "please join"}.to_json, "CONTENT_TYPE" => 'application/json'
|
||||
last_response.status.should eql(422)
|
||||
body = JSON.parse(last_response.body)
|
||||
body["errors"].should_not be_nil
|
||||
body["errors"]["email"].length.should == 2
|
||||
body["errors"]["email"].length.should == 1
|
||||
end
|
||||
|
||||
it "cant create with blank email" do
|
||||
pending "changes to invitations broke this"
|
||||
post '/api/invited_users.json', {:email => "", :note => "please join"}.to_json, "CONTENT_TYPE" => 'application/json'
|
||||
last_response.status.should eql(422)
|
||||
body = JSON.parse(last_response.body)
|
||||
body["errors"].should_not be_nil
|
||||
body["errors"]["email"].length.should == 2
|
||||
body["errors"]["email"].length.should == 1
|
||||
end
|
||||
|
||||
it "cant create with invalid email" do
|
||||
|
|
|
|||
Loading…
Reference in New Issue