OSDN Git Service

fix panel test
[pettanr/pettanr.git] / app / models / panel.rb
index 7f47768..0254dd4 100644 (file)
@@ -4,9 +4,9 @@ class Panel < ActiveRecord::Base
   belongs_to :resource_picture
 #  belongs_to :background_picture, :class_name => 'ResourcePicture'
   has_many :panel_pictures, :dependent => :destroy
-  has_many :balloons, :dependent => :destroy
+  has_many :speech_balloons, :dependent => :destroy
   accepts_nested_attributes_for :panel_pictures, :allow_destroy => true
-  accepts_nested_attributes_for :balloons, :allow_destroy => true
+  accepts_nested_attributes_for :speech_balloons, :allow_destroy => true
 
 #  validates :comic_id, :presence => true, :numericality => true, :existence => true, :uniqueness => {:scope => :t} 
   validates :resource_picture_id, :numericality => {:allow_blank => true}
@@ -20,6 +20,7 @@ class Panel < ActiveRecord::Base
   validates :author_id, :presence => true, :numericality => true, :existence => true
   
   def supply_default au
+    return false unless au
     c = self.comic_id ? Comic.show(self.comic_id, au) : nil
     if c
       self.width = c.width if self.width.blank?
@@ -45,7 +46,7 @@ class Panel < ActiveRecord::Base
 
   #更新する時にPanelIDをチェックしとかないと勝手に所属先を変えられるゾ!?
 
-  def vdt_save
+  def store
     f = nil
     f = Panel.find_t(self.comic_id, self.t) if self.t
     if f
@@ -116,18 +117,18 @@ class Panel < ActiveRecord::Base
       :panel_pictures => {
         :resource_picture => {:artist => {}, :license => {}}
       }, 
-      :balloons => {:speeches => {}},
+      :speech_balloons => {:balloons => {}, :speeches => {}},
       :author => {}
     }}
   end
   
   def self.list_json_opt
     {:include => {
-      :comic => :author
+      :comic => {:author => {}}
       :panel_pictures => {
         :resource_picture => {:artist => {}, :license => {}}
       }, 
-      :balloons => {:speeches => {}},
+      :speech_balloons => {:balloons => {}, :speeches => {}},
       :author => {}
     }}
   end
@@ -144,7 +145,7 @@ class Panel < ActiveRecord::Base
       :panel_pictures => {
         :resource_picture => {:artist => {}, :license => {}}
       }, 
-      :balloons => {:speeches => {}},
+      :speech_balloons => {:balloons => {}, :speeches => {}},
       :author => {}
     }
     res.merge!(opt[:include]) if opt[:include]
@@ -153,11 +154,11 @@ class Panel < ActiveRecord::Base
   
   def self.show_json_include_opt
     {:include => {
-      :comic => :author
+      :comic => {:author => {}}
       :panel_pictures => {
         :resource_picture => {:artist => {}, :license => {}}
       }, 
-      :balloons => {:speeches => {}},
+      :speech_balloons => {:balloons => {}, :speeches => {}},
       :author => {}
     }}
   end
@@ -206,4 +207,9 @@ class Panel < ActiveRecord::Base
   def to_json_play
     self.to_json :methods => :panel_elements
   end
+  
+  def self.visible_count
+    Panel.count
+  end
+  
 end