Merge branch 'develop' of bitbucket.org:jamkazam/jam-cloud into develop

This commit is contained in:
Seth Call 2014-02-02 13:35:33 -06:00
commit 3ded3ff39c
6 changed files with 32 additions and 16 deletions

View File

@ -47,7 +47,7 @@ ActiveAdmin.register JamRuby::PromoBuzz, :as => 'Buzz' do
def create
promo = PromoBuzz.create_with_params(params[:jam_ruby_promo_buzz])
super
redirect_to('/admin/buzzs')
end
def edit
@ -59,7 +59,8 @@ ActiveAdmin.register JamRuby::PromoBuzz, :as => 'Buzz' do
end
def update
super
resource.update_with_params(params[:jam_ruby_promo_buzz]).save!
redirect_to('/admin/buzzs')
end
end

View File

@ -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?

View File

@ -41,18 +41,23 @@ class JamRuby::Promotional < ActiveRecord::Base
end
class JamRuby::PromoBuzz < JamRuby::Promotional
attr_accessible :image, :text_short, :text_long
attr_accessible :image, :text_short, :text_long, :position, :aasm_state, :key
def self.create_with_params(params)
obj = self.new
obj.text_short = params[:text_short]
obj.text_long = params[:text_long]
obj.position = params[:position]
obj.aasm_state = params[:aasm_state]
obj.update_with_params(params)
obj.save!
obj
end
def update_with_params(params)
self.text_short = params[:text_short]
self.text_long = params[:text_long]
self.position = params[:position]
self.aasm_state = params[:aasm_state]
self
end
def admin_title
"Buzz #{created_at.strftime('%Y-%m-%d %H-%M')}"
end

View File

@ -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

View File

@ -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

View File

@ -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