[84047] branches/gsoc11-statistics/stats-server/app/models/os_statistic.rb
derek at macports.org
derek at macports.org
Thu Sep 15 13:56:54 PDT 2011
Revision: 84047
http://trac.macports.org/changeset/84047
Author: derek at macports.org
Date: 2011-09-15 13:56:54 -0700 (Thu, 15 Sep 2011)
Log Message:
-----------
Updated validations, safety checks in add_os_data
- Validate user to which the model belongs
- Removed presence validation on user_id
- removed attr_accessible :user_id
in add_os_data
- return false without saving if os is nil, user is nil, or if user has not already been added to the database
- removed log messages
- return the result of os_stats.save
Modified Paths:
--------------
branches/gsoc11-statistics/stats-server/app/models/os_statistic.rb
Modified: branches/gsoc11-statistics/stats-server/app/models/os_statistic.rb
===================================================================
--- branches/gsoc11-statistics/stats-server/app/models/os_statistic.rb 2011-09-15 20:15:26 UTC (rev 84046)
+++ branches/gsoc11-statistics/stats-server/app/models/os_statistic.rb 2011-09-15 20:56:54 UTC (rev 84047)
@@ -1,7 +1,6 @@
class OsStatistic < ActiveRecord::Base
- belongs_to :user
-
- attr_accessible :user_id
+ belongs_to :user, :validate => true
+
attr_accessible :macports_version
attr_accessible :osx_version
attr_accessible :os_arch
@@ -9,8 +8,7 @@
attr_accessible :build_arch
attr_accessible :gcc_version
attr_accessible :xcode_version
-
- validates :user_id, :presence => true
+
validates :macports_version, :presence => true
validates :osx_version, :presence => true
validates :os_arch, :presence => true
@@ -21,10 +19,10 @@
# Populate an OsStatistics row with data
def self.add_os_data(user, os)
- logger.debug "In OsStatistic.add_os_data"
-
- if os.nil?
- return
+ # os and user must not be nil
+ # Also, user must not be a new record (i.e. it should be in the database)
+ if os.nil? || user.nil? || user.new_record?
+ return false
end
macports_version = os['macports_version']
@@ -52,10 +50,7 @@
os_stats[:gcc_version] = gcc_version
os_stats[:xcode_version] = xcode_version
- if not os_stats.save
- logger.debug "Unable to save os_stats"
- logger.debug "Error message: #{os_stats.errors.full_messages}"
- end
+ return os_stats.save
end
end
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macports-changes/attachments/20110915/dad0e9e4/attachment-0001.html>
More information about the macports-changes
mailing list