OSDN Git Service

t#30138:create original pictures status
authoryasushiito <yas@pen-chan.jp>
Thu, 20 Dec 2012 09:59:16 +0000 (18:59 +0900)
committeryasushiito <yas@pen-chan.jp>
Thu, 20 Dec 2012 09:59:16 +0000 (18:59 +0900)
app/models/original_picture.rb
app/views/original_pictures/index.html.erb
app/views/original_pictures/show.html.erb
config/locales/pettanr.ja.yml
spec/models/original_picture_spec.rb

index cfe8540..33de4f2 100644 (file)
@@ -56,6 +56,22 @@ class OriginalPicture < ActiveRecord::Base
     {:src => self.url, :width => tw, :height => th}
   end
   
+  def unpublished?
+    self.pictures.empty?
+  end
+  
+  def stopped?
+    self.pictures.any? and self.resource_picture == nil
+  end
+  
+  def unlicensed?
+    self.pictures.any? and self.resource_picture and self.updated_at > self.pictures.first.head.updated_at
+  end
+  
+  def published?
+    self.pictures.any? and self.resource_picture and self.updated_at < self.pictures.first.head.updated_at
+  end
+  
   def self.default_page_size
     25
   end
index 8905130..530ea57 100644 (file)
         <% end %>
       </td>
       <td>
+        <% case true %>
+        <% when  original_picture.unpublished? %>
+          <%= t('original_pictures.unpublished') %>
+        <% when  original_picture.stopped? %>
+          <%= t('original_pictures.stopped') %>
+        <% when  original_picture.unlicensed? %>
+          <%= t('original_pictures.unlicensed') %>
+        <% when  original_picture.published? %>
+          <%= t('original_pictures.published') %>
+        <% end %>
+      </td>
+      <td>
+        <% if original_picture.resource_picture %>
+          <%= link_to tag(:img, original_picture.resource_picture.tmb_opt_img_tag), original_picture.resource_picture %>
+        <% else %>
+        <% end %>
       </td>
       <td>
         <% if original_picture.resource_picture %>
index d24737f..cd21ee1 100644 (file)
@@ -8,6 +8,20 @@
       <%= link_to tag(:img, @original_picture.opt_img_tag), @original_picture.url %>
 
       <p>
+        <b><%= t 'original_pictures.index.status' -%>:</b>
+        <% case true %>
+        <% when  @original_picture.unpublished? %>
+          <%= t('original_pictures.unpublished') %>
+        <% when  @original_picture.stopped? %>
+          <%= t('original_pictures.stopped') %>
+        <% when  @original_picture.unlicensed? %>
+          <%= t('original_pictures.unlicensed') %>
+        <% when  @original_picture.published? %>
+          <%= t('original_pictures.published') %>
+        <% end %>
+      </p>
+
+      <p>
         <b><%= t_m 'OriginalPicture.ext' -%>:</b>
         <%= @original_picture.ext %>
       </p>
index 7422996..841c469 100644 (file)
@@ -499,6 +499,10 @@ ja:
     history:
       title: 公開履歴
     upload: 投稿する
+    unpublished: 未公開
+    stopped: 停止中
+    unlicensed: ライセンス待ち
+    published: 公開中
   pictures:
     show:
       title: 実素材詳細
index 28b8119..2a9a964 100644 (file)
@@ -293,6 +293,122 @@ describe OriginalPicture do
     end
   end
   
+  describe '未公開に於いて' do
+    before do
+      @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
+    end
+    context '実素材がゼロのとき' do
+      it 'Trueを返す' do
+        r = @op.unpublished?
+        r.should be_true
+      end
+    end
+    context '実素材がゼロではないとき' do
+      it 'Falseを返す' do
+        @p = FactoryGirl.create :picture, :artist_id => @artist.id, :original_picture_id => @op.id, :license_id => @license.id 
+        r = @op.unpublished?
+        r.should be_false
+      end
+    end
+  end
+
+  describe '停止中に於いて' do
+    before do
+      @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
+    end
+    context '未公開ではないが、素材がないとき' do
+      it 'Trueを返す' do
+        @p = FactoryGirl.create :picture, :artist_id => @artist.id, :original_picture_id => @op.id, :license_id => @license.id 
+        r = @op.stopped?
+        r.should be_true
+      end
+    end
+    context '未公開のとき' do
+      it 'Falseを返す' do
+        r = @op.stopped?
+        r.should be_false
+      end
+    end
+    context '未公開ではなく、素材もあるとき' do
+      it 'falseを返す' do
+        @p = FactoryGirl.create :picture, :artist_id => @artist.id, :original_picture_id => @op.id, :license_id => @license.id 
+        @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :original_picture_id => @op.id, :license_id => @license.id, :picture_id => @p.id
+        r = @op.stopped?
+        r.should be_false
+      end
+    end
+  end
+
+  describe 'ライセンス待ちに於いて' do
+    before do
+      @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
+    end
+    context '未公開ではなく、素材もあるが、原画の更新日時が実素材のheadのそれより後のとき' do
+      it 'Trueを返す' do
+        @p = FactoryGirl.create :picture, :artist_id => @artist.id, :original_picture_id => @op.id, :license_id => @license.id, :updated_at => Time.now - 1000
+        @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :original_picture_id => @op.id, :license_id => @license.id, :picture_id => @p.id
+        r = @op.unlicensed?
+        r.should be_true
+      end
+    end
+    context '未公開のとき' do
+      it 'Falseを返す' do
+        r = @op.unlicensed?
+        r.should be_false
+      end
+    end
+    context '未公開ではないが、素材がないとき' do
+      it 'Falseを返す' do
+        @p = FactoryGirl.create :picture, :artist_id => @artist.id, :original_picture_id => @op.id, :license_id => @license.id 
+        r = @op.unlicensed?
+        r.should be_false
+      end
+    end
+    context '未公開ではなく、素材もあり、実素材のheadの更新日時が原画のそれより後のとき' do
+      it 'Falseを返す' do
+        @p = FactoryGirl.create :picture, :artist_id => @artist.id, :original_picture_id => @op.id, :license_id => @license.id, :updated_at => Time.now + 1000
+        @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :original_picture_id => @op.id, :license_id => @license.id, :picture_id => @p.id
+        r = @op.unlicensed?
+        r.should be_false
+      end
+    end
+  end
+
+  describe '公開中に於いて' do
+    before do
+      @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
+    end
+    context '未公開ではなく、素材もあり、実素材のheadの更新日時が原画のそれより後のとき' do
+      it 'Trueを返す' do
+        @p = FactoryGirl.create :picture, :artist_id => @artist.id, :original_picture_id => @op.id, :license_id => @license.id, :updated_at => Time.now + 1000
+        @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :original_picture_id => @op.id, :license_id => @license.id, :picture_id => @p.id
+        r = @op.published?
+        r.should be_true
+      end
+    end
+    context '未公開のとき' do
+      it 'Falseを返す' do
+        r = @op.published?
+        r.should be_false
+      end
+    end
+    context '未公開ではないが、素材がないとき' do
+      it 'falseを返す' do
+        @p = FactoryGirl.create :picture, :artist_id => @artist.id, :original_picture_id => @op.id, :license_id => @license.id 
+        r = @op.published?
+        r.should be_false
+      end
+    end
+    context '未公開ではなく、素材もあるが、原画の更新日時が実素材のheadのそれより後のとき' do
+      it 'falseを返す' do
+        @p = FactoryGirl.create :picture, :artist_id => @artist.id, :original_picture_id => @op.id, :license_id => @license.id, :updated_at => Time.now - 1000
+        @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :original_picture_id => @op.id, :license_id => @license.id, :picture_id => @p.id
+        r = @op.published?
+        r.should be_false
+      end
+    end
+  end
+
   describe '一覧取得に於いて' do
     before do
       @op = FactoryGirl.create :original_picture, :artist_id => @artist.id