OSDN Git Service

pass test license controller
[pettanr/pettanr.git] / app / models / license.rb
index 4414a15..d150059 100644 (file)
@@ -1,3 +1,4 @@
+#
 class License < ActiveRecord::Base
   belongs_to :license_group
   belongs_to :system_picture
@@ -8,19 +9,28 @@ class License < ActiveRecord::Base
   validates :url, :presence => true, :length => {:maximum => 200}, :uniqueness => true, :url => true #{:allow_blank => true}
   validates :system_picture_id, :presence => true, :numericality => true, :existence => true
   
-  def self.update_license cl
-    l = License.find_by_url cl.url
-    l = License.new unless l
-    l.attributes = {
-      :name => cl.name, :url => cl.url, :cc_by => cl.cc_by, :cc_sa => cl.cc_sa, :cc_nd => cl.cc_nd, :cc_nc => cl.cc_nc, 
-      :no_resize => cl.no_resize, :no_flip => cl.no_flip, :no_convert => cl.no_convert, :keep_aspect_ratio => cl.keep_aspect_ratio
-    }
-    if cl.new_record? and l.new_record? == false
-      l.errors.add :base, 'dupulicate url'
+  def self.store name, attr
+    r = License.replace_system_picture attr
+    l = License.modify_object name, attr
+    if r == false
+      l.errors.add :base, 'system picture can not create'
+    else
+      l.save
     end
     l
   end
   
+  def self.stores attrs, lg_id
+    res = 0
+    return 0 unless attrs.is_a?(Hash)
+    attrs.each do |name, attr|
+      attr["license_group_id"] = lg_id
+      l = License.store name, attr
+      res += 1 unless l.valid?
+    end
+    res
+  end
+  
   def self.list lg_id, opt = {}
     opt.merge!(self.list_opt) unless opt[:include]
     opt.merge!({:conditions => ['licenses.license_group_id = ?', lg_id], :order => 'name'})