Permalink
Browse files

Removed validation constraint on account name.

  • Loading branch information...
1 parent 54c9f81 commit effd7749b17262a8e0f34ea9e3b0fae5bd09ee24 @steveyken steveyken committed Mar 13, 2013
Showing with 70 additions and 10 deletions.
  1. +48 −1 .rvmrc
  2. +22 −9 app/controllers/merge_controller.rb
View
49 .rvmrc
@@ -1 +1,48 @@
-rvm use ruby-1.9.3-p362
+#!/usr/bin/env bash
+
+# This is an RVM Project .rvmrc file, used to automatically load the ruby
+# development environment upon cd'ing into the directory
+
+# First we specify our desired <ruby>[@<gemset>], the @gemset name is optional,
+# Only full ruby name is supported here, for short names use:
+# echo "rvm use 1.9.3" > .rvmrc
+environment_id="ruby-1.9.3-p362"
+
+# Uncomment the following lines if you want to verify rvm version per project
+# rvmrc_rvm_version="1.18.6 (stable)" # 1.10.1 seams as a safe start
+# eval "$(echo ${rvm_version}.${rvmrc_rvm_version} | awk -F. '{print "[[ "$1*65536+$2*256+$3" -ge "$4*65536+$5*256+$6" ]]"}' )" || {
+# echo "This .rvmrc file requires at least RVM ${rvmrc_rvm_version}, aborting loading."
+# return 1
+# }
+
+# First we attempt to load the desired environment directly from the environment
+# file. This is very fast and efficient compared to running through the entire
+# CLI and selector. If you want feedback on which environment was used then
+# insert the word 'use' after --create as this triggers verbose mode.
+if [[ -d "${rvm_path:-$HOME/.rvm}/environments"
+ && -s "${rvm_path:-$HOME/.rvm}/environments/$environment_id" ]]
+then
+ \. "${rvm_path:-$HOME/.rvm}/environments/$environment_id"
+ [[ -s "${rvm_path:-$HOME/.rvm}/hooks/after_use" ]] &&
+ \. "${rvm_path:-$HOME/.rvm}/hooks/after_use" || true
+else
+ # If the environment file has not yet been created, use the RVM CLI to select.
+ rvm --create "$environment_id" || {
+ echo "Failed to create RVM environment '${environment_id}'."
+ return 1
+ }
+fi
+
+# If you use bundler, this might be useful to you:
+# if [[ -s Gemfile ]] && {
+# ! builtin command -v bundle >/dev/null ||
+# builtin command -v bundle | GREP_OPTIONS= \grep $rvm_path/bin/bundle >/dev/null
+# }
+# then
+# printf "%b" "The rubygem 'bundler' is not installed. Installing it now.\n"
+# gem install bundler
+# fi
+# if [[ -s Gemfile ]] && builtin command -v bundle >/dev/null
+# then
+# bundle install | GREP_OPTIONS= \grep -vE '^Using|Your bundle is complete'
+# fi
@@ -9,9 +9,9 @@ class MergeController < EntitiesController
before_filter :require_application, :only => :aliases
respond_to :html, :js
-
+
helper_method :klass
-
+
# GET /merge/contact/1/into/2 HTML
# GET /merge/contact/1/into/2 JS
# PUT /merge/account/1/into/2 HTML
@@ -24,9 +24,9 @@ def into
authorize! :manage, @duplicate
# don't merge if either is invalid to start with
- if !@master.valid?
+ if !valid_object?(@master)
flash[:error] = I18n.t('assets_merge_invalid', :name => @master.name)
- elsif !@duplicate.valid?
+ elsif !valid_object?(@duplicate)
flash[:error] = I18n.t('assets_merge_invalid', :name => @duplicate.name)
elsif request.put?
do_merge(@master, @duplicate)
@@ -36,7 +36,7 @@ def into
respond_with(@duplicate)
end
-
+
#
# List out the aliases for a given set of contact ids
#
@@ -56,7 +56,7 @@ def respond_to_access_denied
flash[:warning] = t(:msg_asset_not_authorized, klass.to_s.humanize.downcase)
redirect_to :controller => klass.to_s.underscore.pluralize, :action => :index
end
-
+
def respond_to_not_found
flash[:warning] = t(:msg_asset_not_available, klass.to_s.humanize.downcase)
redirect_to :controller => klass.to_s.underscore.pluralize, :action => :index
@@ -67,7 +67,7 @@ def klass
name = params[:klass_name].classify
klass = (ENTITIES.include?(name) ? name.constantize : nil)
end
-
+
# Carefully sanitize params[:ids] by converting to integers and remove 0's since 'test'.to_i == 0
def santize_ids
(params[:ids] || []).split(',').flatten.map(&:to_i).reject{|x| x == 0}.compact
@@ -78,7 +78,7 @@ def do_merge(master, duplicate)
ignored = params["ignore"]["_self"].map{|k,v| k if v == "yes" }.compact
duplicate.merge_with(master, ignored)
end
-
+
# rudimentary API KEY authentication for the aliases action
def require_application
error = ""
@@ -89,9 +89,22 @@ def require_application
else
error = 'Please specify a valid api_key in the url.'
end
-
+
render :js => {:errors => error}.to_json
false
end
+ # Return true if object is valid, except in case where object is account
+ # AND just account name is duplicate. That case is dealt with during the merge
+ def valid_object?(obj)
+
+ if obj.class.to_s == 'Account'
+ v = obj.valid?
+ obj.errors.keys.compact == [:name] || v
+ else
+ obj.valid?
+ end
+
+ end
+
end

0 comments on commit effd774

Please sign in to comment.