OSDN Git Service

t#30124:create md5 dupulicate check
authoryasushiito <yas@pen-chan.jp>
Fri, 21 Dec 2012 10:17:02 +0000 (19:17 +0900)
committeryasushiito <yas@pen-chan.jp>
Fri, 21 Dec 2012 10:17:02 +0000 (19:17 +0900)
app/controllers/pictures_controller.rb
app/models/picture.rb
app/views/artists/browse.html.erb
app/views/original_pictures/_exist.html.erb
app/views/original_pictures/show.html.erb
app/views/pictures/md5.html.erb [deleted file]
app/views/pictures/search.html.erb [new file with mode: 0644]
config/locales/pettanr.ja.yml
config/routes.rb
spec/controllers/pictures_controller_spec.rb
spec/models/picture_spec.rb

index 7cfaf3c..8e7444d 100644 (file)
@@ -1,8 +1,7 @@
 class PicturesController < ApplicationController
   layout 'test' if MagicNumber['test_layout']
-  before_filter :authenticate_user!, :only => [:show, :credit, :md5]
-  before_filter :authenticate_author, :only => [:show, :credit, :md5]
-  before_filter :authenticate_artist, :only => [:md5]
+  before_filter :authenticate_user!, :only => [:show, :credit, :search]
+  before_filter :authenticate_author, :only => [:show, :credit, :search]
   before_filter :authenticate_admin!, :only => [:list, :browse]
   
   def show
@@ -27,7 +26,7 @@ class PicturesController < ApplicationController
     end
   end
   
-  def md5
+  def search
     @pictures = Picture.list_by_md5(params[:md5])
     
     respond_to do |format|
index dfaf583..b9d7da1 100644 (file)
@@ -111,8 +111,13 @@ class Picture < ActiveRecord::Base
     r = Picture.find :all, :conditions => ['pictures.md5 = ?', md5], :order => 'pictures.updated_at desc'
   end
   
-  def self.list_by_md5 md5, opid
-    r = Picture.find :all, :conditions => ['pictures.md5 = ? and pictures.original_picture_id <> ?', md5, opid], :order => 'pictures.updated_at desc'
+  def self.list_by_md5 md5, opid = nil
+    cond = if opid.blank?
+      ['pictures.md5 = ?', md5]
+    else
+      ['pictures.md5 = ? and pictures.original_picture_id <> ?', md5, opid]
+    end
+    r = Picture.find :all, :conditions => cond, :order => 'pictures.updated_at desc'
   end
   
   def self.exist_by_md5 md5, opid
index 2602e3a..370b278 100644 (file)
 </p>
 
 <p>
+  <b><%= t_m 'Artist.author_id' -%>:</b>
+  <%= link_to h(@ar.author.name), @ar.author %>
+</p>
+
+<p>
   <b><%= t_m 'Artist.created_at' -%>:</b>
   <%= l @ar.created_at %>
 </p>
index 8129f4f..4a89259 100644 (file)
@@ -1,4 +1,50 @@
-<% case exist -%>
-<% when true -%>
-  この画像は既に公開されています
+<% if pictures.any? -%>
+  <%= t('original_pictures.exist.announce') %>
+  <table>
+    <tr>
+      <th><%= t_m 'Picture' -%></th>
+      <th><%= t_m 'Picture.credit' -%></th>
+      <th><%= t_m 'Picture.artist_id' -%></th>
+      <th><%= t 'original_pictures.exist.status' -%></th>
+      <th><%= t_m 'ResourcePicture' -%></th>
+    </tr>
+    <% pictures.each do |picture| %>
+      <tr>
+        <% if picture.showable? @author %>
+          <td>
+            <%= link_to tag(:img, picture.tmb_opt_img_tag), picture %>
+          </td>
+          <td>
+            <%= render picture.credit_template, :picture => picture %>
+          </td>
+        <% else %>
+          <td>
+            <%= link_to tag(:img, picture.tail_tmb_opt_img_tag(asset_path('error.png'))), picture -%>
+          </td>
+          <td>
+          </td>
+        <% end %>
+        <td>
+          <%= link_to h(picture.artist.name), picture.artist %>
+        </td>
+        <td>
+          <% if picture.enable? %>
+            <% if picture.head? %>
+              <%= t 'original_pictures.exist.head' -%>
+            <% else %>
+              <%= t 'original_pictures.exist.tail' -%>
+            <% end %>
+          <% else %>
+            <%= t 'original_pictures.existe.disable' -%>
+          <% end %>
+        </td>
+        <td>
+          <% if picture.enable? %>
+            <%= link_to tag(:img, picture.resource_picture.tmb_opt_img_tag), picture.resource_picture %>
+          <% else %>
+          <% end %>
+        </td>
+      </tr>
+    <% end %>
+  </table>
 <% end -%>
index cd21ee1..12a7fa2 100644 (file)
@@ -1,5 +1,5 @@
 <h1><%= t '.title' -%></h1>
-<%= render 'exist', :exist => Picture.exist_by_md5(@original_picture.md5, @original_picture.id) %>
+<%= render 'exist', :pictures => Picture.list_by_md5(@original_picture.md5, @original_picture.id) %>
 <p id="notice"><%= notice %></p>
 
 <table class="no-border">
       </p>
 
       <p>
+        <b><%= t_m 'OriginalPicture.md5' -%>:</b>
+        <%= h(@original_picture.md5) %>
+      </p>
+
+      <p>
         <b><%= t_m 'OriginalPicture.created_at' -%>:</b>
         <%= l @original_picture.created_at %>
       </p>
diff --git a/app/views/pictures/md5.html.erb b/app/views/pictures/md5.html.erb
deleted file mode 100644 (file)
index e69de29..0000000
diff --git a/app/views/pictures/search.html.erb b/app/views/pictures/search.html.erb
new file mode 100644 (file)
index 0000000..b8e90a1
--- /dev/null
@@ -0,0 +1 @@
+<%= render 'original_pictures/exist', :pictures => @pictures %>\r
index 841c469..4f901e6 100644 (file)
@@ -503,6 +503,12 @@ ja:
     stopped: 停止中
     unlicensed: ライセンス待ち
     published: 公開中
+    exist:
+      announce: この画像は既に公開されています
+      status: 状態
+      head: 公開中
+      tail: 廃盤
+      disable: 停止中
   pictures:
     show:
       title: 実素材詳細
index 6f5efb5..48a716e 100644 (file)
@@ -97,7 +97,7 @@ Pettanr::Application.routes.draw do
     collection do
       get :show
       get :credit
-      get :md5
+      get :search
       get :list
     end
     member do
index faeb442..7dcbf81 100644 (file)
@@ -251,38 +251,38 @@ describe PicturesController do
     context 'つつがなく終わるとき' do
       it '実素材モデルにmd5検索を問い合わせている' do
         Picture.should_receive(:list_by_md5).exactly(1)
-        get :md5, :md5 => 'a'*32
+        get :search, :md5 => 'a'*32
       end
       it '@picturesにリストを取得している' do
-        get :md5, :md5 => 'a'*32
+        get :search, :md5 => 'a'*32
         assigns(:pictures).should have_at_least(3).items
       end
       context 'html形式' do
         it 'ステータスコード200 OKを返す' do
-          get :md5, :md5 => 'a'*32
+          get :search, :md5 => 'a'*32
           response.should be_success 
         end
-        it 'md5テンプレートを描画する' do
-          get :md5, :md5 => 'a'*32
-          response.should render_template("md5")
+        it 'searchテンプレートを描画する' do
+          get :search, :md5 => 'a'*32
+          response.should render_template("search")
         end
       end
       context 'json形式' do
         it 'ステータスコード200 OKを返す' do
-          get :md5, :md5 => 'a'*32, :format => :json
+          get :search, :md5 => 'a'*32, :format => :json
           response.should be_success 
         end
         it 'jsonデータを返す' do
-          get :md5, :md5 => 'a'*32, :format => :json
+          get :search, :md5 => 'a'*32, :format => :json
           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
         end
         it 'データがリスト構造になっている' do
-          get :md5, :md5 => 'a'*32, :format => :json
+          get :search, :md5 => 'a'*32, :format => :json
           json = JSON.parse response.body
           json.should have_at_least(3).items
         end
         it 'リストの先頭くらいは実素材っぽいものであって欲しい' do
-          get :md5, :md5 => 'a'*32, :format => :json
+          get :search, :md5 => 'a'*32, :format => :json
           json = JSON.parse response.body
           json.first.has_key?("ext").should be_true
           json.first.has_key?("md5").should be_true
@@ -297,47 +297,25 @@ describe PicturesController do
       end
       context 'html形式' do
         it 'ステータスコード302 Foundを返す' do
-          get :md5, :md5 => 'a'*32
+          get :search, :md5 => 'a'*32
           response.status.should eq 302
         end
         it 'サインインページへ遷移する' do
-          get :md5, :md5 => 'a'*32
+          get :search, :md5 => 'a'*32
           response.should redirect_to '/users/sign_in'
         end
       end
       context 'json形式' do
         it 'ステータスコード401 Unauthorizedを返す' do
-          get :md5, :md5 => 'a'*32, :format => :json
+          get :search, :md5 => 'a'*32, :format => :json
           response.status.should eq 401
         end
         it '応答メッセージにUnauthorizedを返す' do
-          get :md5, :md5 => 'a'*32, :format => :json
+          get :search, :md5 => 'a'*32, :format => :json
           response.message.should match(/Unauthorized/)
         end
       end
     end
-    context '作家が絵師でないとき' do
-      before do
-        Author.any_instance.stub(:artist?).and_return(false)
-      end
-      context 'html形式' do
-        it 'ステータスコード302 Foundを返す' do
-          get :md5, :md5 => 'a'*32
-          response.status.should eq 302
-        end
-        it '絵師登録ページへ遷移する' do
-          get :md5, :md5 => 'a'*32
-          response.should redirect_to new_artist_path
-        end
-      end
-      context 'json形式' do
-        it '例外403 forbiddenを返す' do
-          lambda{
-            get :md5, :md5 => 'a'*32, :format => :json
-          }.should raise_error(ActiveRecord::Forbidden)
-        end
-      end
-    end
   end
   
 end
index 8166400..e37eac7 100644 (file)
@@ -530,35 +530,6 @@ describe Picture do
     end
   end
   
-  describe 'md5検索に於いて' do
-    before do
-      @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
-      @p = FactoryGirl.create :picture, :artist_id => @artist.id, :license_id => @license.id, :revision => 0,
-        :original_picture_id => @op.id, :md5 => 'a' * 32
-      @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :original_picture_id => @op.id, :license_id => @license.id, :picture_id => @p.id
-      @op2 = FactoryGirl.create :original_picture, :artist_id => @artist.id
-      @p2 = FactoryGirl.create :picture, :artist_id => @artist.id, :license_id => @license.id, :revision => 0,
-        :original_picture_id => @op2.id, :md5 => 'b' * 32
-      @op3 = FactoryGirl.create :original_picture, :artist_id => @artist.id
-    end
-    it 'リストを返す' do
-      res = Picture.find_by_md5(@p.md5)
-      res.is_a?(Array).should be_true
-    end
-    it 'md5が違えば含まない' do
-      res = Picture.find_by_md5(@p.md5)
-      res.include?(@p2).should be_false
-    end
-    it '更新日時順' do
-      @p3 = FactoryGirl.create :picture, :artist_id => @artist.id, :license_id => @license.id, :revision => 1,
-        :original_picture_id => @op2.id, :md5 => 'C' * 32
-      @p4 = FactoryGirl.create :picture, :artist_id => @artist.id, :license_id => @license.id, :revision => 1,
-        :original_picture_id => @op3.id, :md5 => @p3.md5, :updated_at => Time.now + 100
-      res = Picture.find_by_md5(@p3.md5)
-      res.should eq [@p4, @p3]
-    end
-  end
-  
   describe 'md5重複リストに於いて' do
     before do
       @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
@@ -570,43 +541,63 @@ describe Picture do
         :original_picture_id => @op2.id, :md5 => 'b' * 32
       @op3 = FactoryGirl.create :original_picture, :artist_id => @artist.id
     end
-    it 'リストを返す' do
-      res = Picture.list_by_md5(@p.md5, @p.original_picture_id)
-      res.is_a?(Array).should be_true
-    end
-    it 'md5が違えば含まない' do
-      res = Picture.list_by_md5(@p.md5, @p.original_picture_id)
-      res.include?(@p2).should be_false
-    end
-    it '同一原画は含まない' do
-      res = Picture.list_by_md5(@p.md5, @p.original_picture_id)
-      res.empty?.should be_true
-    end
-    it '同一原画は旧版でも含まない' do
-      @p3 = FactoryGirl.create :picture, :artist_id => @artist.id, :license_id => @license.id, :revision => 1,
-        :original_picture_id => @op.id, :md5 => 'a' * 32
-      res = Picture.list_by_md5(@p.md5, @p.original_picture_id)
-      res.empty?.should be_true
-    end
-    it '他所の原画なら含む' do
-      @p3 = FactoryGirl.create :picture, :artist_id => @artist.id, :license_id => @license.id, :revision => 1,
-        :original_picture_id => @op2.id, :md5 => 'a' * 32
-      res = Picture.list_by_md5(@p.md5, @p.original_picture_id)
-      res.should eq [@p3]
-    end
-    it '他所の原画でもmd5が違えば含まない' do
-      @p3 = FactoryGirl.create :picture, :artist_id => @artist.id, :license_id => @license.id, :revision => 1,
-        :original_picture_id => @op2.id, :md5 => 'c' * 32
-      res = Picture.list_by_md5(@p.md5, @p.original_picture_id)
-      res.empty?.should be_true
-    end
-    it '更新日時順' do
-      @p3 = FactoryGirl.create :picture, :artist_id => @artist.id, :license_id => @license.id, :revision => 1,
-        :original_picture_id => @op2.id, :md5 => 'a' * 32
-      @p4 = FactoryGirl.create :picture, :artist_id => @artist.id, :license_id => @license.id, :revision => 1,
-        :original_picture_id => @op3.id, :md5 => 'a' * 32, :updated_at => Time.now + 100
-      res = Picture.list_by_md5(@p.md5, @p.original_picture_id)
-      res.should eq [@p4, @p3]
+    context '除外する原画idで指定されていないとき' do
+      it 'リストを返す' do
+        res = Picture.list_by_md5(@p.md5)
+        res.is_a?(Array).should be_true
+      end
+      it 'md5が違えば含まない' do
+        res = Picture.list_by_md5(@p.md5)
+        res.include?(@p2).should be_false
+      end
+      it '更新日時順' do
+        @p3 = FactoryGirl.create :picture, :artist_id => @artist.id, :license_id => @license.id, :revision => 1,
+          :original_picture_id => @op2.id, :md5 => 'C' * 32
+        @p4 = FactoryGirl.create :picture, :artist_id => @artist.id, :license_id => @license.id, :revision => 1,
+          :original_picture_id => @op3.id, :md5 => @p3.md5, :updated_at => Time.now + 100
+        res = Picture.find_by_md5(@p3.md5)
+        res.should eq [@p4, @p3]
+      end
+    end
+    context '除外する原画idで指定されたとき' do
+      it 'リストを返す' do
+        res = Picture.list_by_md5(@p.md5, @p.original_picture_id)
+        res.is_a?(Array).should be_true
+      end
+      it 'md5が違えば含まない' do
+        res = Picture.list_by_md5(@p.md5, @p.original_picture_id)
+        res.include?(@p2).should be_false
+      end
+      it '同一原画は含まない' do
+        res = Picture.list_by_md5(@p.md5, @p.original_picture_id)
+        res.empty?.should be_true
+      end
+      it '同一原画は旧版でも含まない' do
+        @p3 = FactoryGirl.create :picture, :artist_id => @artist.id, :license_id => @license.id, :revision => 1,
+          :original_picture_id => @op.id, :md5 => 'a' * 32
+        res = Picture.list_by_md5(@p.md5, @p.original_picture_id)
+        res.empty?.should be_true
+      end
+      it '他所の原画なら含む' do
+        @p3 = FactoryGirl.create :picture, :artist_id => @artist.id, :license_id => @license.id, :revision => 1,
+          :original_picture_id => @op2.id, :md5 => 'a' * 32
+        res = Picture.list_by_md5(@p.md5, @p.original_picture_id)
+        res.should eq [@p3]
+      end
+      it '他所の原画でもmd5が違えば含まない' do
+        @p3 = FactoryGirl.create :picture, :artist_id => @artist.id, :license_id => @license.id, :revision => 1,
+          :original_picture_id => @op2.id, :md5 => 'c' * 32
+        res = Picture.list_by_md5(@p.md5, @p.original_picture_id)
+        res.empty?.should be_true
+      end
+      it '更新日時順' do
+        @p3 = FactoryGirl.create :picture, :artist_id => @artist.id, :license_id => @license.id, :revision => 1,
+          :original_picture_id => @op2.id, :md5 => 'a' * 32
+        @p4 = FactoryGirl.create :picture, :artist_id => @artist.id, :license_id => @license.id, :revision => 1,
+          :original_picture_id => @op3.id, :md5 => 'a' * 32, :updated_at => Time.now + 100
+        res = Picture.list_by_md5(@p.md5, @p.original_picture_id)
+        res.should eq [@p4, @p3]
+      end
     end
   end