From 3b695342f170cafcc457f8042056fc8eb73bc0f2 Mon Sep 17 00:00:00 2001 From: yasushiito Date: Sat, 4 May 2013 11:21:28 +0900 Subject: [PATCH] t#31281:add comic.description --- app/models/comic.rb | 2 +- app/models/panel.rb | 9 +++++++++ app/views/comics/_form.html.erb | 4 ++++ app/views/comics/_list_item.html.erb | 5 +++++ app/views/comics/index.atom.builder | 2 +- app/views/comics/index.rss.builder | 2 +- app/views/comics/show.html.erb | 5 +++++ app/views/panels/_standard.html.erb | 2 ++ app/views/panels/index.html.erb | 5 ----- config/locales/pettanr.ja.yml | 2 ++ db/migrate/20130504004559_add_description_on_comics.rb | 9 +++++++++ spec/factories.rb | 2 ++ spec/models/comic_spec.rb | 9 +++++++++ spec/models/panel_spec.rb | 16 ++++++++++++++++ 14 files changed, 66 insertions(+), 8 deletions(-) create mode 100644 db/migrate/20130504004559_add_description_on_comics.rb diff --git a/app/models/comic.rb b/app/models/comic.rb index fe587602..7023214d 100644 --- a/app/models/comic.rb +++ b/app/models/comic.rb @@ -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 diff --git a/app/models/panel.rb b/app/models/panel.rb index 208def02..421a2794 100644 --- a/app/models/panel.rb +++ b/app/models/panel.rb @@ -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 diff --git a/app/views/comics/_form.html.erb b/app/views/comics/_form.html.erb index 6bb664e0..84b983cc 100644 --- a/app/views/comics/_form.html.erb +++ b/app/views/comics/_form.html.erb @@ -6,6 +6,10 @@ <%= f.text_field :title %>
+ <%= f.label :description %>
+ <%= f.text_area :description %> +
+
<%= f.label :visible %>
<%= f.collection_select :visible, t_select_items(MagicNumber['comic_visible_items']), :last, :first, :html => {:selected => @comic.visible} %>
diff --git a/app/views/comics/_list_item.html.erb b/app/views/comics/_list_item.html.erb index 1bf947a0..2e9d719a 100644 --- a/app/views/comics/_list_item.html.erb +++ b/app/views/comics/_list_item.html.erb @@ -18,3 +18,8 @@ <% end %> + + + <%= h(truncate(comic.description, :length => 40)) %> + + diff --git a/app/views/comics/index.atom.builder b/app/views/comics/index.atom.builder index ddf8c879..a1e9b0c0 100644 --- a/app/views/comics/index.atom.builder +++ b/app/views/comics/index.atom.builder @@ -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 diff --git a/app/views/comics/index.rss.builder b/app/views/comics/index.rss.builder index abbf1c33..b319a9d0 100644 --- a/app/views/comics/index.rss.builder +++ b/app/views/comics/index.rss.builder @@ -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 diff --git a/app/views/comics/show.html.erb b/app/views/comics/show.html.erb index fee9107e..81a1bbf3 100644 --- a/app/views/comics/show.html.erb +++ b/app/views/comics/show.html.erb @@ -8,6 +8,11 @@

+ <%= t_m 'Comic.description' -%>: + <%= h(@comic.description) %> +

+ +

<%= t_m 'Comic.visible' -%>: <%= t_selected_item('comic_visible_items', @comic.visible) %>

diff --git a/app/views/panels/_standard.html.erb b/app/views/panels/_standard.html.erb index 02c0dfdf..a67b70aa 100644 --- a/app/views/panels/_standard.html.erb +++ b/app/views/panels/_standard.html.erb @@ -1,3 +1,5 @@ +<%= t_m 'Panel.caption' -%>: +<%= 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 %> diff --git a/app/views/panels/index.html.erb b/app/views/panels/index.html.erb index 9f511b9b..0f61452a 100644 --- a/app/views/panels/index.html.erb +++ b/app/views/panels/index.html.erb @@ -3,8 +3,3 @@ <%= render 'standard', :panel => panel, :author => @author %> <% end %> <%= link_to t('panels.new.title'), new_panel_path %> - diff --git a/config/locales/pettanr.ja.yml b/config/locales/pettanr.ja.yml index ee9fc453..e5006a65 100644 --- a/config/locales/pettanr.ja.yml +++ b/config/locales/pettanr.ja.yml @@ -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 index 00000000..73920f5e --- /dev/null +++ b/db/migrate/20130504004559_add_description_on_comics.rb @@ -0,0 +1,9 @@ +class AddDescriptionOnComics < ActiveRecord::Migration + def up + add_column :comics, :description, :string + end + + def down + remove_column :comics, :description + end +end diff --git a/spec/factories.rb b/spec/factories.rb index 3dba65e8..e5967d74 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -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 diff --git a/spec/models/comic_spec.rb b/spec/models/comic_spec.rb index 64acd7e0..f9978aa7 100644 --- a/spec/models/comic_spec.rb +++ b/spec/models/comic_spec.rb @@ -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 diff --git a/spec/models/panel_spec.rb b/spec/models/panel_spec.rb index 9fa263d2..308bc3b4 100644 --- a/spec/models/panel_spec.rb +++ b/spec/models/panel_spec.rb @@ -171,6 +171,22 @@ describe Panel do end end + describe '文字コード検証に於いて' do + before do + @panel = FactoryGirl.build :panel, :author_id => @author.id + end + + context 'captionを検証するとき' do + it 'Shift JISなら失敗する' do + @panel.caption = "\x83G\x83r\x83]\x83D" + lambda{ + @panel.valid_encode + }.should raise_error(Pettanr::BadRequest) + end + end + + end + describe 'デフォルト値補充に於いて' do before do @panel = FactoryGirl.build :panel, :author_id => @author.id -- 2.11.0