OSDN Git Service

t#31281:add comic.description
authoryasushiito <yas@pen-chan.jp>
Sat, 4 May 2013 02:21:28 +0000 (11:21 +0900)
committeryasushiito <yas@pen-chan.jp>
Sat, 4 May 2013 02:21:28 +0000 (11:21 +0900)
14 files changed:
app/models/comic.rb
app/models/panel.rb
app/views/comics/_form.html.erb
app/views/comics/_list_item.html.erb
app/views/comics/index.atom.builder
app/views/comics/index.rss.builder
app/views/comics/show.html.erb
app/views/panels/_standard.html.erb
app/views/panels/index.html.erb
config/locales/pettanr.ja.yml
db/migrate/20130504004559_add_description_on_comics.rb [new file with mode: 0644]
spec/factories.rb
spec/models/comic_spec.rb
spec/models/panel_spec.rb

index fe58760..7023214 100644 (file)
@@ -8,7 +8,7 @@ class Comic < ActiveRecord::Base
   before_validation :valid_encode
   
   def valid_encode
-    ['title'].each do |a|
+    ['title', 'description'].each do |a|
       next if attributes[a] == nil
       raise Pettanr::BadRequest unless attributes[a].valid_encoding?
     end
index 208def0..421a279 100644 (file)
@@ -23,6 +23,15 @@ class Panel < ActiveRecord::Base
   validates :author_id, :presence => true, :numericality => true, :existence => {:both => false}
   validates :publish, :presence => true, :numericality => true
   
+  before_validation :valid_encode
+  
+  def valid_encode
+    ['caption'].each do |a|
+      next if attributes[a] == nil
+      raise Pettanr::BadRequest unless attributes[a].valid_encoding?
+    end
+  end
+  
   def supply_default
     self.border = 2
     self.publish = 0
index 6bb664e..84b983c 100644 (file)
@@ -6,6 +6,10 @@
     <%= f.text_field :title %>
   </div>
   <div class="field">
+    <%= f.label :description %><br />
+    <%= f.text_area :description %>
+  </div>
+  <div class="field">
     <%= f.label :visible %><br />
     <%= f.collection_select :visible, t_select_items(MagicNumber['comic_visible_items']), :last, :first, :html => {:selected => @comic.visible} %>
   </div>
index 1bf947a..2e9d719 100644 (file)
@@ -18,3 +18,8 @@
     <% end %>
   </td>
 </tr>
+<tr>
+  <td colspan="4">
+    <%= h(truncate(comic.description, :length => 40)) %>
+  </td>
+</tr>
index ddf8c87..a1e9b0c 100644 (file)
@@ -18,7 +18,7 @@ atom_feed(
       :updated => comic.updated_at
     ) do |item|
       item.title(comic.title)
-      item.content(comic.title, :type => 'html')
+      item.content(comic.description, :type => 'html')
       item.author {|author| author.name(comic.author.name)}
     end
   end
index abbf1c3..b319a9d 100644 (file)
@@ -15,7 +15,7 @@ xml.rss("version"    => "2.0",
         xml.title        comic.title
         xml.link         comic_url(comic)
         xml.guid         comic_url(comic)
-        xml.description  comic.title
+        xml.description  comic.description
         xml.pubDate      comic.updated_at.to_formatted_s(:rfc822)
         xml.dc :creator, comic.author.name
       end
index fee9107..81a1bbf 100644 (file)
@@ -8,6 +8,11 @@
 </p>
 
 <p>
+  <b><%= t_m 'Comic.description' -%>:</b>
+  <%= h(@comic.description) %>
+</p>
+
+<p>
   <b><%= t_m 'Comic.visible' -%>:</b>
   <%= t_selected_item('comic_visible_items', @comic.visible) %>
 </p>
index 02c0dfd..a67b70a 100644 (file)
@@ -1,3 +1,5 @@
+<b><%= t_m 'Panel.caption' -%>:</b>
+<%= h(panel.caption) %>
 <%= render 'panels/body', :panel => panel, :author => author %>
 <%= render 'panels/footer', :panel => panel, :author => author %>
 <%= render 'panels/licensed_pictures', :licensed_pictures => panel.licensed_pictures %>
index 9f511b9..0f61452 100644 (file)
@@ -3,8 +3,3 @@
   <%= render 'standard', :panel => panel, :author => @author %>
 <% end %>
 <%= link_to t('panels.new.title'), new_panel_path %>
-<noscript>
-  <% @panels.each do |panel| %>
-    <%= raw panel.scenario %>
-  <% end %>
-</noscript> 
index ee9fc45..e5006a6 100644 (file)
@@ -70,6 +70,7 @@ ja:
         authentication_token: 認証トークン
       comic:
         title: タイトル
+        description: あらすじ
         visible: 公開
         author_id: 作家
         created_at: 更新
@@ -88,6 +89,7 @@ ja:
         x: X
         y: Y
         z: 重なり
+        caption: 要約
         publish: 公開
         author_id: 作家
       panel_picture:
diff --git a/db/migrate/20130504004559_add_description_on_comics.rb b/db/migrate/20130504004559_add_description_on_comics.rb
new file mode 100644 (file)
index 0000000..73920f5
--- /dev/null
@@ -0,0 +1,9 @@
+class AddDescriptionOnComics < ActiveRecord::Migration
+  def up
+    add_column :comics, :description, :string
+  end
+
+  def down
+    remove_column :comics, :description
+  end
+end
index 3dba65e..e5967d7 100644 (file)
@@ -69,6 +69,7 @@ FactoryGirl.define do
 
   factory :comic, :class => Comic do |comic|
     comic.title "comic"
+    comic.description 'comic description'
     comic.visible 1
   end
 
@@ -196,6 +197,7 @@ FactoryGirl.define do
     panel.border 1
     panel.width 100
     panel.height 300
+    panel.caption 'panel caption'
     panel.publish 1
     panel.author_id 1
   end
index 64acd7e..f9978aa 100644 (file)
@@ -74,6 +74,15 @@ describe Comic do
         }.should raise_error(Pettanr::BadRequest)
       end
     end
+    
+    context 'descriptionを検証するとき' do
+      it 'Shift JISなら失敗する' do
+        @comic.description = "\x83G\x83r\x83]\x83D"
+        lambda{
+          @comic.valid_encode
+        }.should raise_error(Pettanr::BadRequest)
+      end
+    end
   end
   
   describe 'デフォルト値補充に於いて' do
index 9fa263d..308bc3b 100644 (file)
@@ -171,6 +171,22 @@ describe Panel do
     end\r
   end\r
   \r
+  describe '文字コード検証に於いて' do\r
+    before do\r
+      @panel = FactoryGirl.build :panel, :author_id => @author.id\r
+    end\r
+    \r
+    context 'captionを検証するとき' do\r
+      it 'Shift JISなら失敗する' do\r
+        @panel.caption = "\x83G\x83r\x83]\x83D"\r
+        lambda{\r
+          @panel.valid_encode\r
+        }.should raise_error(Pettanr::BadRequest)\r
+      end\r
+    end\r
+    \r
+  end\r
+  \r
   describe 'デフォルト値補充に於いて' do\r
     before do\r
       @panel = FactoryGirl.build :panel, :author_id => @author.id\r