Modified: trunk/app/models/user.rb (2728 => 2729)
--- trunk/app/models/user.rb 2011-10-20 22:30:31 UTC (rev 2728)
+++ trunk/app/models/user.rb 2011-10-20 22:35:26 UTC (rev 2729)
@@ -9,8 +9,6 @@
require 'acts_as_contributor'
require 'acts_as_creditor'
-require 'write_once_of'
-
class User < ActiveRecord::Base
has_many :citations,
@@ -127,8 +125,6 @@
:message => "can only contain characters, numbers and _",
:if => Proc.new { |user| !user.username.nil? }
- validates_write_once_of :username, :on => :update, :if => Proc.new { |user| !user.username.nil? }, :message => "cannot be changed"
-
validates_presence_of :openid_url, :if => Proc.new { |user| !user.openid_url.nil? }
validates_uniqueness_of :openid_url, :if => Proc.new { |user| !user.openid_url.nil? }
Deleted: trunk/lib/write_once_of.rb (2728 => 2729)
--- trunk/lib/write_once_of.rb 2011-10-20 22:30:31 UTC (rev 2728)
+++ trunk/lib/write_once_of.rb 2011-10-20 22:35:26 UTC (rev 2729)
@@ -1,23 +0,0 @@
-# Modified from: http://forums.pragprog.com/forums/8/topics/2
-
-module WriteOnceOf
- def validates_write_once_of(*attr_names)
- configuration = { :message => "can't be changed" }
- configuration.merge!(attr_names.pop) if attr_names.last.is_a?(Hash)
- send( validation_method(:update) ) do |record|
- unless configuration[:if] and not evaluate_condition(configuration[:if], record)
- previous = self.find record.id
- attr_names.each do |attr_name|
- # Updated from original [Jits, 2008-01-09]: added condition below, to allow attributes to be set at a later stage.
- # So write once check is only done if the old value was not nil.
- unless eval("previous.#{attr_name}.nil?")
- record.errors.add( attr_name, configuration[:message] ) if record.respond_to?(attr_name) and previous.send(attr_name) != record.send(attr_name)
- # replace the 'and' above with a double ampersand
- end
- end
- end
- end
- end
-end
-
-ActiveRecord::Base.extend WriteOnceOf
\ No newline at end of file