OSDN Git Service

Merge branch 'v05' of git.sourceforge.jp:/gitroot/pettanr/pettanr into v05 v05
authoryasushiito <yas@pen-chan.jp>
Sat, 27 Apr 2013 05:16:12 +0000 (14:16 +0900)
committeryasushiito <yas@pen-chan.jp>
Sat, 27 Apr 2013 05:16:12 +0000 (14:16 +0900)
22 files changed:
app/controllers/provider_statuses_controller.rb
app/models/provider_artist.rb
app/models/provider_license.rb
app/models/provider_original_picture.rb
app/models/provider_status.rb
app/views/provider_statuses/_artists_errors.html.erb [deleted file]
app/views/provider_statuses/_import_errors.html.erb [new file with mode: 0644]
app/views/provider_statuses/_licenses_errors.html.erb [deleted file]
app/views/provider_statuses/_original_pictures_errors.html.erb [deleted file]
app/views/provider_statuses/_pictures_errors.html.erb [deleted file]
app/views/provider_statuses/_resource_pictures_errors.html.erb [deleted file]
app/views/provider_statuses/artists_import.html.erb
app/views/provider_statuses/import.html.erb
app/views/provider_statuses/licenses_import.html.erb
app/views/provider_statuses/original_pictures_import.html.erb
config/environment.rb
lib/import_result.rb [new file with mode: 0644]
spec/controllers/provider_statuses_controller_spec.rb
spec/models/provider_artist_spec.rb
spec/models/provider_license_spec.rb
spec/models/provider_original_picture_spec.rb
spec/models/provider_status_spec.rb

index ab5c043..2892cf8 100644 (file)
@@ -69,37 +69,37 @@ class ProviderStatusesController < ApplicationController
   def licenses_import
     @provider_status = ProviderStatus.show(params[:id], @admin)
     raise ActiveRecord::Forbidden if @provider_status.status == 0
-    @failures = @provider_status.licenses_import params[:date]
+    @import_result = @provider_status.licenses_import params[:date]
     respond_to do |format|
       format.html # show.html.erb
-      format.json { render :json => @failures.to_json() }
+      format.json { render :json => @import_result.to_json() }
     end
   end
   
   def artists_import
     @provider_status = ProviderStatus.show(params[:id], @admin)
     raise ActiveRecord::Forbidden if @provider_status.status == 0
-    @failures = @provider_status.artists_import params[:date]
+    @import_result = @provider_status.artists_import params[:date]
     respond_to do |format|
       format.html # show.html.erb
-      format.json { render :json => @failures.to_json() }
+      format.json { render :json => @import_result.to_json() }
     end
   end
   
   def original_pictures_import
     @provider_status = ProviderStatus.show(params[:id], @admin)
     raise ActiveRecord::Forbidden if @provider_status.status == 0
-    @failures = @provider_status.original_pictures_import params[:date]
+    @import_result = @provider_status.original_pictures_import params[:date]
     respond_to do |format|
       format.html # show.html.erb
-      format.json { render :json => @failures.to_json() }
+      format.json { render :json => @import_result.to_json() }
     end
   end
   
   def import
     @provider_status = ProviderStatus.show(params[:id], @admin)
     raise ActiveRecord::Forbidden if @provider_status.status == 0
-    @failures = port
+    @import_result = @provider_status.import params[:date]
     respond_to do |format|
       format.html # show.html.erb
       format.json { render :json => @failures.to_json() }
@@ -107,10 +107,8 @@ class ProviderStatusesController < ApplicationController
   end
   
   def import_all
-    ProviderStatus.find(:all).each do |provider_status|
-      next unless provider_status.status == 3
-      @provider_status = provider_status
-      @failures = port
+    ProviderStatus.approve_list.each do |provider_status|
+      @provider_status = provider_status params[:date]
     end
     respond_to do |format|
       format.html { render :text => 'ok'}
index 5f9806b..c341f00 100644 (file)
@@ -41,7 +41,7 @@ class ProviderArtist < ActiveRecord::Base
       end
       raise ActiveRecord::Rollback if res.any?
     end
-    res
+    ArtistImportResult.new res
   end
   
 end
index 8f1b541..53e1e20 100644 (file)
@@ -32,7 +32,7 @@ class ProviderLicense < ActiveRecord::Base
       end
       raise ActiveRecord::Rollback if res.any?
     end
-    res
+    LicenseImportResult.new res
   end
   
 end
index 78e8f1c..de173fb 100644 (file)
@@ -166,17 +166,24 @@ class ProviderOriginalPicture < ActiveRecord::Base
   end
   
   def self.import pid, original_pictures, pictures
-    res = {:original_pictures => [], :pictures => [], :resource_pictures => []}
+    res = nil
     ProviderOriginalPicture.transaction do
       r = ProviderOriginalPicture.import_original_pictures(pid, original_pictures)
-      res[:original_pictures] = r
-      raise ActiveRecord::Rollback if r.any?
+      if r.any?
+        res = OriginalPictureImportResult.new r
+        raise ActiveRecord::Rollback
+      end
       r = ProviderOriginalPicture.import_pictures(pid, pictures)
-      res[:pictures] = r
-      raise ActiveRecord::Rollback if r.any?
+      if r.any?
+        res = PictureImportResult.new r
+        raise ActiveRecord::Rollback
+      end
       r = ProviderOriginalPicture.import_resource_pictures(pid, original_pictures)
-      res[:resource_pictures] = r
-      raise ActiveRecord::Rollback if r.any?
+      if r.any?
+        res = ResourcePictureImportResult.new r
+        raise ActiveRecord::Rollback
+      end
+      res = OriginalPictureImportResult.new []
     end
     res
   end
index e9dc46d..f49a98e 100644 (file)
@@ -123,12 +123,19 @@ class ProviderStatus < ActiveRecord::Base
   end
   
   def ymd_to_time ymd_str
-    return nil if ymd_str.blank?
     date = nil
-    begin
-      date = Time.parse(ymd_str[0..3] + '/' + ymd_str[4..5] + '/' + ymd_str[6..7])
-    rescue
-      date = nil
+    if ymd_str.blank?
+      date = if self.received_at
+        self.received_at
+      else
+        nil
+      end
+    else
+      begin
+        date = Time.parse(ymd_str[0..3] + '/' + ymd_str[4..5] + '/' + ymd_str[6..7])
+      rescue
+        date = nil
+      end
     end
     date
   end
@@ -159,41 +166,56 @@ class ProviderStatus < ActiveRecord::Base
   
   def licenses_import date
     licenses = self.export_by('licenses_export', date)
-    return nil unless licenses
-    ProviderLicense.import self.provider.id, licenses
+    if  licenses
+      ProviderLicense.import self.provider.id, licenses
+    else
+      LicenseImportResult.new nil
+    end
   end
   
   def artists_import date
     artists = self.export_by('artists_export', date)
-    return nil unless artists
-    ProviderArtist.import self.provider.id, artists
+    if artists
+      ProviderArtist.import self.provider.id, artists
+    else
+      ArtistImportResult.new nil
+    end
   end
   
   def original_pictures_import date
     original_pictures = self.export_by('original_pictures_export', date)
-    return nil unless original_pictures
     pictures = self.export_by('pictures_export', date)
-    return nil unless pictures
-    ProviderOriginalPicture.import self.provider.id, original_pictures, pictures
-  end
-  
-  def port
-    exports = export_by('export', @provider_status, params[:date])
-    return nil unless exports
-    ProviderStatus.import @provider_status.provider.id, exports
+    if original_pictures and pictures
+      ProviderOriginalPicture.import self.provider.id, original_pictures, pictures
+    else
+      OriginalPictureImportResult.new nil
+    end
   end
   
-  def self.import pid, exports
-    res = {}
+  def import date
+    import_result = nil
     ProviderStatus.transaction do
-      res[:licenses] = ProviderLicense.import pid, exports['licenses']
-      raise ActiveRecord::Rollback if res[:licenses].any?
-      res[:artists] = ProviderArtist.import pid, exports['artists']
-      raise ActiveRecord::Rollback if res[:artists].any?
-      res[:original_pictures] = ProviderOriginalPicture.import pid, exports['original_pictures'], exports['pictures']
-      raise ActiveRecord::Rollback if res[:original_pictures][:original_pictures].any? or res[:original_pictures][:resource_pictures].any? or res[:original_pictures][:pictures].any?
+      import_result = self.licenses_import date
+      raise ActiveRecord::Rollback unless import_result.success?
+      import_result = self.artists_import date
+      raise ActiveRecord::Rollback unless import_result.success?
+      import_result = self.original_pictures_import date
+      raise ActiveRecord::Rollback unless import_result.success?
+      self.received_at = Time.now
+      self.save
     end
-    res
+    import_result
   end
   
+  def self.import_all date = nil
+    failures = {}
+    ProviderStatus.approve_list.each do |provider_status|
+      import_result = provider_status.import date
+      next if import_result.success?
+      failures[provider_status.provider.name] = import_result
+    end
+    failures.each do |name, import_result|
+      puts name
+    end
+  end
 end
diff --git a/app/views/provider_statuses/_artists_errors.html.erb b/app/views/provider_statuses/_artists_errors.html.erb
deleted file mode 100644 (file)
index a8e2fb7..0000000
+++ /dev/null
@@ -1,18 +0,0 @@
-<h2>
-  <%= t('provider_statuses.artists_import.fail', :size => failures.size) %>
-</h2>
-<table>
-  <tr>
-    <th><%= t_m 'Artist.name' -%></th>
-  </tr>
-  <% failures.each do |artist| %>
-    <tr>
-      <td>
-        <%= h(artist['name']) %>
-      </td>
-      <td>
-        <%= h(artist) %>
-      </td>
-    </tr>
-  <% end %>
-</table>
diff --git a/app/views/provider_statuses/_import_errors.html.erb b/app/views/provider_statuses/_import_errors.html.erb
new file mode 100644 (file)
index 0000000..24ff78c
--- /dev/null
@@ -0,0 +1,19 @@
+<h2>
+  <%= t("provider_statuses.#{import_result.translate}.fail", :size => import_result.failures.size) %>
+</h2>
+<table>
+  <tr>
+    <% import_result.columns.each do |column| %>
+      <th><%= t_m "#{import_result.obj}.#{column}" -%></th>
+    <% end %>
+  </tr>
+  <% import_result.failures.each do |failure| %>
+    <tr>
+      <% import_result.columns.each do |column| %>
+        <td>
+          <%= h(failure[column]) %>
+        </td>
+      <% end %>
+    </tr>
+  <% end %>
+</table>
diff --git a/app/views/provider_statuses/_licenses_errors.html.erb b/app/views/provider_statuses/_licenses_errors.html.erb
deleted file mode 100644 (file)
index 894b2f4..0000000
+++ /dev/null
@@ -1,19 +0,0 @@
-<h2>
-  <%= t('provider_statuses.licenses_import.fail', :size => failures.size) %>
-</h2>
-<table>
-  <tr>
-    <th><%= t_m 'License.caption' -%></th>
-    <th><%= t_m 'License.name' -%></th>
-  </tr>
-  <% failures.each do |license| %>
-    <tr>
-      <td>
-        <%= link_to h(license['caption']), license['url'] %>
-      </td>
-      <td>
-        <%= h(license['name']) %>
-      </td>
-    </tr>
-  <% end %>
-</table>
diff --git a/app/views/provider_statuses/_original_pictures_errors.html.erb b/app/views/provider_statuses/_original_pictures_errors.html.erb
deleted file mode 100644 (file)
index ba5dd40..0000000
+++ /dev/null
@@ -1,23 +0,0 @@
-<h2>
-  <%= t('provider_statuses.original_pictures_import.fail', :size => failures.size) %>
-</h2>
-<table>
-  <tr>
-    <th><%= t_m 'OriginalPicture.id' -%></th>
-    <th><%= t_m 'OriginalPicture.artist_id' -%></th>
-    <th><%= t_m 'OriginalPicture.md5' -%></th>
-  </tr>
-  <% failures.each do |original_picture| %>
-    <tr>
-      <td>
-        <%= h(original_picture['id']) %>
-      </td>
-      <td>
-        <%= h(original_picture['artist_id']) %>
-      </td>
-      <td>
-        <%= h(original_picture['md5']) %>
-      </td>
-    </tr>
-  <% end %>
-</table>
diff --git a/app/views/provider_statuses/_pictures_errors.html.erb b/app/views/provider_statuses/_pictures_errors.html.erb
deleted file mode 100644 (file)
index 9dcbf05..0000000
+++ /dev/null
@@ -1,31 +0,0 @@
-<h2>
-  <%= t('provider_statuses.pictures_import.fail', :size => failures.size) %>
-</h2>
-<table>
-  <tr>
-    <th><%= t_m 'Picture.id' -%></th>
-    <th><%= t_m 'Picture.original_picture_id' -%></th>
-    <th><%= t_m 'Picture.revision' -%></th>
-    <th><%= t_m 'Picture.artist_id' -%></th>
-    <th><%= t_m 'Picture.md5' -%></th>
-  </tr>
-  <% failures.each do |picture| %>
-    <tr>
-      <td>
-        <%= h(picture['id']) %>
-      </td>
-      <td>
-        <%= h(picture['original_picture_id']) %>
-      </td>
-      <td>
-        <%= h(picture['revision']) %>
-      </td>
-      <td>
-        <%= h(picture['artist_id']) %>
-      </td>
-      <td>
-        <%= h(picture['md5']) %>
-      </td>
-    </tr>
-  <% end %>
-</table>
diff --git a/app/views/provider_statuses/_resource_pictures_errors.html.erb b/app/views/provider_statuses/_resource_pictures_errors.html.erb
deleted file mode 100644 (file)
index ebd88aa..0000000
+++ /dev/null
@@ -1,31 +0,0 @@
-<h2>
-  <%= t('provider_statuses.resource_pictures_import.fail', :size => failures.size) %>
-</h2>
-<table>
-  <tr>
-    <th><%= t_m 'ResourcePicture.id' -%></th>
-    <th><%= t_m 'ResourcePicture.original_picture_id' -%></th>
-    <th><%= t_m 'ResourcePicture.picture_id' -%></th>
-    <th><%= t_m 'ResourcePicture.artist_id' -%></th>
-    <th><%= t_m 'ResourcePicture.md5' -%></th>
-  </tr>
-  <% failures.each do |resource_picture| %>
-    <tr>
-      <td>
-        <%= h(resource_picture['id']) %>
-      </td>
-      <td>
-        <%= h(resource_picture['original_picture_id']) %>
-      </td>
-      <td>
-        <%= h(resource_picture['picture_id']) %>
-      </td>
-      <td>
-        <%= h(resource_picture['artist_id']) %>
-      </td>
-      <td>
-        <%= h(resource_picture['md5']) %>
-      </td>
-    </tr>
-  <% end %>
-</table>
index d89a6cf..58045d8 100644 (file)
@@ -1,13 +1,15 @@
 <h1><%= t('.title') %></h1>
 <p id="notice"><%= notice %></p>
 
-<% if @failures == nil %>
-  <h1>No Response</h1>
-<% elsif @failures.empty? %>
-  <h2>
-    <%= t('provider_statuses.artists_import.success') %>
-  </h2>
+<% if @import_result.response? %>
+  <% if @import_result.success? %>
+    <h2>
+      <%= t("provider_statuses.#{@import_result.action}.success") %>
+    </h2>
+  <% else %>
+    <%= render 'import_errors', :import_result => @import_result %>
+    <%= link_to t("provider_statuses.#{@import_result.action}.to_show"), provider_status_path(@provider_status) %>
+  <% end %>
 <% else %>
-  <%= render 'artists_errors', :failures => @failures %>
-  <%= link_to t('provider_statuses.artists_import.to_show'), provider_status_path(@provider_status) %>
+  <h1>No Response</h1>
 <% end %>
index 2f38278..dc3fa49 100644 (file)
@@ -1,20 +1,15 @@
 <h1><%= t('.title') %></h1>
 <p id="notice"><%= notice %></p>
 
-<% if @failures == nil %>
-  <h1>No Response</h1>
-<% elsif @failures[:licenses].any? %>
-  <%= render 'licenses_errors', :failures => @failures[:licenses] %>
-<% elsif @failures[:artists].any? %>
-  <%= render 'artists_errors', :failures => @failures[:artists] %>
-<% elsif @failures[:original_pictures][:original_pictures].any? %>
-  <%= render 'original_pictures_errors', :failures => @failures[:original_pictures][:original_pictures] %>
-<% elsif @failures[:original_pictures][:pictures].any? %>
-  <%= render 'pictures_errors', :failures => @failures[:original_pictures][:pictures] %>
-<% elsif @failures[:original_pictures][:resource_pictures].any? %>
-  <%= render 'resource_pictures_errors', :failures => @failures[:original_pictures][:resource_pictures] %>
+<% if @import_result.response? %>
+  <% if @import_result.success? %>
+    <h2>
+      <%= t("provider_statuses.import.success") %>
+    </h2>
+  <% else %>
+    <%= render 'import_errors', :import_result => @import_result %>
+    <%= link_to t("provider_statuses.#{@import_result.action}.to_show"), provider_status_path(@provider_status) %>
+  <% end %>
 <% else %>
-  <h2>
-    <%= t('provider_statuses.import.success') %>
-  </h2>
+  <h1>No Response</h1>
 <% end %>
index f120386..58045d8 100644 (file)
@@ -1,13 +1,15 @@
 <h1><%= t('.title') %></h1>
 <p id="notice"><%= notice %></p>
 
-<% if @failures == nil %>
-  <h1>No Response</h1>
-<% elsif @failures.empty? %>
-  <h2>
-    <%= t('provider_statuses.licenses_import.success') %>
-  </h2>
+<% if @import_result.response? %>
+  <% if @import_result.success? %>
+    <h2>
+      <%= t("provider_statuses.#{@import_result.action}.success") %>
+    </h2>
+  <% else %>
+    <%= render 'import_errors', :import_result => @import_result %>
+    <%= link_to t("provider_statuses.#{@import_result.action}.to_show"), provider_status_path(@provider_status) %>
+  <% end %>
 <% else %>
-  <%= render 'licenses_errors', :failures => @failures %>
-  <%= link_to t('provider_statuses.licenses_import.to_show'), provider_status_path(@provider_status) %>
+  <h1>No Response</h1>
 <% end %>
index 23bdd04..58045d8 100644 (file)
@@ -1,19 +1,15 @@
 <h1><%= t('.title') %></h1>
 <p id="notice"><%= notice %></p>
 
-<% if @failures == nil %>
-  <h1>No Response</h1>
-<% elsif @failures[:original_pictures].any? %>
-  <%= render 'original_pictures_errors', :failures => @failures[:original_pictures] %>
-  <%= link_to t('provider_statuses.original_pictures_import.to_show'), provider_status_path(@provider_status) %>
-<% elsif @failures[:pictures].any? %>
-  <%= render 'pictures_errors', :failures => @failures[:pictures] %>
-  <%= link_to t('provider_statuses.original_pictures_import.to_show'), provider_status_path(@provider_status) %>
-<% elsif @failures[:resource_pictures].any? %>
-  <%= render 'resource_pictures_errors', :failures => @failures[:resource_pictures] %>
-  <%= link_to t('provider_statuses.original_pictures_import.to_show'), provider_status_path(@provider_status) %>
+<% if @import_result.response? %>
+  <% if @import_result.success? %>
+    <h2>
+      <%= t("provider_statuses.#{@import_result.action}.success") %>
+    </h2>
+  <% else %>
+    <%= render 'import_errors', :import_result => @import_result %>
+    <%= link_to t("provider_statuses.#{@import_result.action}.to_show"), provider_status_path(@provider_status) %>
+  <% end %>
 <% else %>
-  <h2>
-    <%= t('provider_statuses.original_pictures_import.success') %>
-  </h2>
+  <h1>No Response</h1>
 <% end %>
index 1871570..9a94584 100644 (file)
@@ -8,4 +8,5 @@ Pettanr::Application.initialize!
 require 'picture_io'
 require 'pettan_imager'
 require 'ar_helper'
+require 'import_result'
 
diff --git a/lib/import_result.rb b/lib/import_result.rb
new file mode 100644 (file)
index 0000000..ffeef41
--- /dev/null
@@ -0,0 +1,129 @@
+#
+class ImportResult
+  
+  def initialize results
+    @results = results
+  end
+  
+  def response?
+    @results != nil
+  end
+  
+  def success?
+    @results.empty?
+  end
+  
+  def failures
+    @results
+  end
+  
+  def to_json
+    if response?
+      @results.to_json
+    else
+      'No Response'
+    end
+  end
+  
+end
+
+class LicenseImportResult < ImportResult
+  
+  def columns
+    ['caption', 'name']
+  end
+  
+  def obj
+    'License'
+  end
+  
+  def action
+    'licenses_import'
+  end
+  
+  def translate
+    'licenses_import'
+  end
+  
+end
+
+class ArtistImportResult < ImportResult
+  
+  def columns
+    ['name']
+  end
+  
+  def obj
+    'Artist'
+  end
+  
+  def action
+    'artists_import'
+  end
+  
+  def translate
+    'licenses_import'
+  end
+  
+end
+
+class OriginalPictureImportResult < ImportResult
+  
+  def columns
+    ['id', 'artist_id', 'md5']
+  end
+  
+  def obj
+    'OriginalPicture'
+  end
+  
+  def action
+    'original_pictures_import'
+  end
+  
+  def translate
+    'original_pictures_import'
+  end
+  
+end
+
+class ResourcePictureImportResult < ImportResult
+  
+  def columns
+    ['id', 'original_picture_id', 'picture_id', 'artist_id', 'md5']
+  end
+  
+  def obj
+    'ResourcePicture'
+  end
+  
+  def action
+    'original_pictures_import'
+  end
+  
+  def translate
+    'resource_pictures_import'
+  end
+  
+end
+
+class PictureImportResult < ImportResult
+  
+  def columns
+    ['id', 'original_picture_id', 'revision', 'artist_id', 'md5']
+  end
+  
+  def obj
+    'Picture'
+  end
+  
+  def action
+    'original_pictures_import'
+  end
+  
+  def translate
+    'pictures_import'
+  end
+  
+end
+
index 7f3fa43..3af7034 100644 (file)
@@ -369,7 +369,7 @@ describe ProviderStatusesController do
     context '事前チェックしておく' do
       before do
         ProviderStatus.any_instance.stub(:status).with(any_args).and_return(1)
-        ProviderStatus.stub(:licenses_import).with(any_args).and_return([])
+        ProviderStatus.stub(:licenses_import).with(any_args).and_return(LicenseImportResult.new([]))
       end
       it '借受状況モデルに単体取得を問い合わせている' do
         ProviderStatus.should_receive(:show).exactly(1)
@@ -383,7 +383,7 @@ describe ProviderStatusesController do
     context 'つつがなく終わるとき' do
       before do
         ProviderStatus.any_instance.stub(:status).with(any_args).and_return(1)
-        ProviderStatus.any_instance.stub(:licenses_import).with(any_args).and_return([])
+        ProviderStatus.any_instance.stub(:licenses_import).with(any_args).and_return(LicenseImportResult.new([]))
       end
       it 'ステータスコード200 OKを返す' do
         get :licenses_import, :id => @ps.id
@@ -393,9 +393,9 @@ describe ProviderStatusesController do
         get :licenses_import, :id => @ps.id
         assigns(:provider_status).should eq(@ps)
       end
-      it '@failuresにインポート失敗リストを取得している' do
+      it '@import_resultにインポート結果を取得している' do
         get :licenses_import, :id => @ps.id
-        assigns(:failures).should eq([])
+        assigns(:import_result).is_a?(ImportResult).should be_true
       end
       context 'html形式' do
         it 'licenses_importテンプレートを描画する' do
@@ -466,7 +466,7 @@ describe ProviderStatusesController do
     context '事前チェックしておく' do
       before do
         ProviderStatus.any_instance.stub(:status).with(any_args).and_return(1)
-        ProviderStatus.any_instance.stub(:artists_import).with(any_args).and_return([])
+        ProviderStatus.any_instance.stub(:artists_import).with(any_args).and_return(ArtistImportResult.new([]))
       end
       it '借受状況モデルに単体取得を問い合わせている' do
         ProviderStatus.should_receive(:show).exactly(1)
@@ -480,7 +480,7 @@ describe ProviderStatusesController do
     context 'つつがなく終わるとき' do
       before do
         ProviderStatus.any_instance.stub(:status).with(any_args).and_return(1)
-        ProviderStatus.any_instance.stub(:artists_import).with(any_args).and_return([])
+        ProviderStatus.any_instance.stub(:artists_import).with(any_args).and_return(ArtistImportResult.new([]))
       end
       it 'ステータスコード200 OKを返す' do
         get :artists_import, :id => @ps.id
@@ -490,9 +490,9 @@ describe ProviderStatusesController do
         get :artists_import, :id => @ps.id
         assigns(:provider_status).should eq(@ps)
       end
-      it '@failuresにインポート失敗リストを取得している' do
+      it '@import_resultにインポート結果を取得している' do
         get :artists_import, :id => @ps.id
-        assigns(:failures).should eq([])
+        assigns(:import_result).is_a?(ImportResult).should be_true
       end
       context 'html形式' do
         it 'artists_importテンプレートを描画する' do
@@ -572,7 +572,7 @@ describe ProviderStatusesController do
     context '事前チェックしておく' do
       before do
         ProviderStatus.any_instance.stub(:status).with(any_args).and_return(1)
-        ProviderStatus.any_instance.stub(:original_pictures_import).with(any_args).and_return({:original_pictures => [], :pictures => [], :resource_pictures => []})
+        ProviderStatus.any_instance.stub(:original_pictures_import).with(any_args).and_return(OriginalPictureImportResult.new([]))
       end
       it '借受状況モデルに単体取得を問い合わせている' do
         ProviderStatus.should_receive(:show).exactly(1)
@@ -586,7 +586,7 @@ describe ProviderStatusesController do
     context 'つつがなく終わるとき' do
       before do
         ProviderStatus.any_instance.stub(:status).with(any_args).and_return(1)
-        ProviderStatus.any_instance.stub(:original_pictures_import).with(any_args).and_return({:original_pictures => [], :pictures => [], :resource_pictures => []})
+        ProviderStatus.any_instance.stub(:original_pictures_import).with(any_args).and_return(OriginalPictureImportResult.new([]))
       end
       it 'ステータスコード200 OKを返す' do
         get :original_pictures_import, :id => @ps.id
@@ -596,12 +596,9 @@ describe ProviderStatusesController do
         get :original_pictures_import, :id => @ps.id
         assigns(:provider_status).should eq(@ps)
       end
-      it '@failuresにインポート失敗リストを取得している' do
+      it '@import_resultにインポート結果を取得している' do
         get :original_pictures_import, :id => @ps.id
-        assigns(:failures).should_not be_nil
-        assigns(:failures)[:original_pictures].should be_empty
-        assigns(:failures)[:pictures].should be_empty
-        assigns(:failures)[:resource_pictures].should be_empty
+        assigns(:import_result).is_a?(ImportResult).should be_true
       end
       context 'html形式' do
         it 'artists_importテンプレートを描画する' do
index 1f4e275..8996c01 100644 (file)
@@ -143,9 +143,10 @@ describe ProviderArtist do
       end
     end
     context 'つつがなく終わるとき' do
-      it '空っぽの配列を返す' do
+      it 'ImportResultを返す' do
         r = ProviderArtist.import @provider.id, [@artist.attributes]
-        r.should be_empty
+        r.is_a?(ImportResult).should be_true
+        r.should be_success
       end
       it '対照表が追加される' do
         lambda {
@@ -154,9 +155,10 @@ describe ProviderArtist do
       end
     end
     context '複数インポートのとき' do
-      it '空っぽの配列を返す' do
+      it 'ImportResultを返す' do
         r = ProviderArtist.import @provider.id, [@artist.attributes, @artist2.attributes]
-        r.should be_empty
+        r.is_a?(ImportResult).should be_true
+        r.should be_success
       end
       it '対照表が追加される' do
         lambda {
@@ -169,18 +171,20 @@ describe ProviderArtist do
       before do
         ProviderArtist.any_instance.stub(:save).with(any_args).and_return(false)
       end
-     it '結果に貸手側絵師のカラム値を追加している' do
+      it '結果が失敗している' do
         r = ProviderArtist.import @provider.id, [@artist.attributes]
-        r.should_not be_empty
+        r.should_not be_success
+        r.failures.should_not be_empty
       end
     end
     context '絵師オブジェクトの保存に失敗したとき' do
       before do
         Artist.any_instance.stub(:save).with(any_args).and_return(false)
       end
-      it 'çµ\90æ\9e\9cã\81«è²¸æ\89\8bå\81´çµµå¸«ã\81®ã\82«ã\83©ã\83 å\80¤ã\82\92追å\8a している' do
+      it 'çµ\90æ\9e\9cã\81\8c失æ\95\97している' do
         r = ProviderArtist.import @provider.id, [@artist.attributes]
-        r.should_not be_empty
+        r.should_not be_success
+        r.failures.should_not be_empty
       end
     end
   end
index 3983a3f..e7300c6 100644 (file)
@@ -101,9 +101,10 @@ describe ProviderLicense do
       end
     end
     context 'つつがなく終わるとき' do
-      it '空っぽの配列を返す' do
+      it 'ImportResultを返す' do
         r = ProviderLicense.import @provider.id, [@license.attributes]
-        r.should be_empty
+        r.is_a?(ImportResult).should be_true
+        r.should be_success
       end
       it '対照表が追加される' do
         lambda {
@@ -112,9 +113,10 @@ describe ProviderLicense do
       end
     end
     context '複数インポートのとき' do
-      it '空っぽの配列を返す' do
+      it 'ImportResultを返す' do
         r = ProviderLicense.import @provider.id, [@license.attributes, @license2.attributes]
-        r.should be_empty
+        r.is_a?(ImportResult).should be_true
+        r.should be_success
       end
       it '対照表が追加される' do
         lambda {
@@ -127,18 +129,20 @@ describe ProviderLicense do
       before do
         ProviderLicense.any_instance.stub(:save).with(any_args).and_return(false)
       end
-      it 'çµ\90æ\9e\9cã\81«è²¸æ\89\8bå\81´ã\83©ã\82¤ã\82»ã\83³ã\82¹ã\81®ã\82«ã\83©ã\83 å\80¤ã\82\92追å\8a している' do
+      it 'çµ\90æ\9e\9cã\81\8c失æ\95\97している' do
         r = ProviderLicense.import @provider.id, [@license.attributes]
-        r.should_not be_empty
+        r.should_not be_success
+        r.failures.should_not be_empty
       end
     end
     context 'ライセンスの管理名取得に失敗したとき' do
       before do
         License.stub(:find_by_name).with(any_args).and_return(nil)
       end
-      it 'çµ\90æ\9e\9cã\81«è²¸æ\89\8bå\81´ã\83©ã\82¤ã\82»ã\83³ã\82¹ã\81®ã\82«ã\83©ã\83 å\80¤ã\82\92追å\8a している' do
+      it 'çµ\90æ\9e\9cã\81\8c失æ\95\97している' do
         r = ProviderLicense.import @provider.id, [@license.attributes]
-        r.should_not be_empty
+        r.should_not be_success
+        r.failures.should_not be_empty
       end
     end
   end
index dc4adf7..7d3ca0d 100644 (file)
@@ -882,11 +882,10 @@ describe ProviderOriginalPicture do
         ProviderOriginalPicture.stub(:import_pictures).with(any_args).and_return([])
         ProviderOriginalPicture.stub(:import_resource_pictures).with(any_args).and_return([])
       end
-      it '各失敗したカラム値をHashで返す' do
+      it 'ImportResultを返す' do
         r = ProviderOriginalPicture.import @provider.id, [@opattr], [@pattr]
-        r[:original_pictures].should be_empty
-        r[:pictures].should be_empty
-        r[:resource_pictures].should be_empty
+        r.is_a?(ImportResult).should be_true
+        r.should be_success
       end
     end
     #警告ケース
@@ -896,11 +895,11 @@ describe ProviderOriginalPicture do
         ProviderOriginalPicture.stub(:import_pictures).with(any_args).and_return([])
         ProviderOriginalPicture.stub(:import_resource_pictures).with(any_args).and_return([])
       end
-      it '失敗した原画のカラム値を配列でoriginal_picturesに追加している' do
+      it '結果が失敗している' do
         r = ProviderOriginalPicture.import @provider.id, [@opattr], [@pattr]
-        r[:original_pictures].should_not be_empty
-        r[:pictures].should be_empty
-        r[:resource_pictures].should be_empty
+        r.should_not be_success
+        r.is_a?(OriginalPictureImportResult).should be_true
+        r.failures.should_not be_empty
       end
     end
     context '実素材インポートに失敗したとき' do
@@ -909,11 +908,11 @@ describe ProviderOriginalPicture do
         ProviderOriginalPicture.stub(:import_pictures).with(any_args).and_return([@pattr])
         ProviderOriginalPicture.stub(:import_resource_pictures).with(any_args).and_return([])
       end
-      it '失敗した原画のカラム値を配列でpicturesに追加している' do
+      it '結果が失敗している' do
         r = ProviderOriginalPicture.import @provider.id, [@opattr], [@pattr]
-        r[:original_pictures].should be_empty
-        r[:pictures].should_not be_empty
-        r[:resource_pictures].should be_empty
+        r.should_not be_success
+        r.is_a?(PictureImportResult).should be_true
+        r.failures.should_not be_empty
       end
     end
     context '素材インポートに失敗したとき' do
@@ -922,11 +921,11 @@ describe ProviderOriginalPicture do
         ProviderOriginalPicture.stub(:import_pictures).with(any_args).and_return([])
         ProviderOriginalPicture.stub(:import_resource_pictures).with(any_args).and_return([@rpattr])
       end
-      it '失敗した原画のカラム値を配列でresource_picturesに追加している' do
+      it '結果が失敗している' do
         r = ProviderOriginalPicture.import @provider.id, [@opattr], [@pattr]
-        r[:original_pictures].should be_empty
-        r[:pictures].should be_empty
-        r[:resource_pictures].should_not be_empty
+        r.should_not be_success
+        r.is_a?(ResourcePictureImportResult).should be_true
+        r.failures.should_not be_empty
       end
     end
   end
index af1e290..7887d43 100644 (file)
@@ -636,7 +636,7 @@ describe ProviderStatus do
     context '事前チェックしておく' do
       before do
         ProviderStatus.any_instance.stub(:export_by).with(any_args).and_return([@license.attributes])
-        ProviderLicense.stub(:import).with(any_args).and_return([])
+        ProviderLicense.stub(:import).with(any_args).and_return(LicenseImportResult.new([]))
       end
       it '貸手からのエクスポートを依頼している' do
         ProviderStatus.any_instance.should_receive(:export_by).exactly(1)
@@ -650,20 +650,20 @@ describe ProviderStatus do
     context 'つつがなく終わるとき' do
       before do
         ProviderStatus.any_instance.stub(:export_by).with(any_args).and_return([@license.attributes])
-        ProviderLicense.stub(:import).with(any_args).and_return([])
+        ProviderLicense.stub(:import).with(any_args).and_return(LicenseImportResult.new([]))
       end
       it 'ライセンスインポート結果を返す' do
         r = @ps.licenses_import '20111010'
-        r.should eq []
+        r.should be_response
       end
     end
     context 'エクスポートに失敗したとき' do
       before do
         ProviderStatus.any_instance.stub(:export_by).with(any_args).and_return(nil)
       end
-      it 'nilを返す' do
+      it '受信に失敗したImportResultを返す' do
         r = @ps.licenses_import '20111010'
-        r.should be_nil
+        r.should_not be_response
       end
     end
   end
@@ -676,7 +676,7 @@ describe ProviderStatus do
     context '事前チェックしておく' do
       before do
         ProviderStatus.any_instance.stub(:export_by).with(any_args).and_return([])
-        ProviderArtist.stub(:import).with(any_args).and_return([])
+        ProviderArtist.stub(:import).with(any_args).and_return(ArtistImportResult.new([]))
       end
       it '貸手からのエクスポートを依頼している' do
         ProviderStatus.any_instance.should_receive(:export_by).exactly(1)
@@ -690,20 +690,20 @@ describe ProviderStatus do
     context 'つつがなく終わるとき' do
       before do
         ProviderStatus.any_instance.stub(:export_by).with(any_args).and_return([])
-        ProviderArtist.stub(:import).with(any_args).and_return([])
+        ProviderArtist.stub(:import).with(any_args).and_return(ArtistImportResult.new([]))
       end
       it '絵師インポート結果を返す' do
         r = @ps.artists_import '20111010'
-        r.should eq []
+        r.should be_response
       end
     end
     context 'エクスポートに失敗したとき' do
       before do
         ProviderStatus.any_instance.stub(:export_by).with(any_args).and_return(nil)
       end
-      it 'nilを返す' do
-        r = @ps.artists_import '20111010'
-        r.should be_nil
+      it '受信に失敗したImportResultを返す' do
+        r = @ps.licenses_import '20111010'
+        r.should_not be_response
       end
     end
   end
@@ -716,7 +716,7 @@ describe ProviderStatus do
     context '事前チェックしておく' do
       before do
         ProviderStatus.any_instance.stub(:export_by).with(any_args).and_return([])
-        ProviderOriginalPicture.stub(:import).with(any_args).and_return({:original_pictures => [], :pictures => [], :resource_pictures => []})
+        ProviderOriginalPicture.stub(:import).with(any_args).and_return(OriginalPictureImportResult.new([]))
       end
       it '貸手からのエクスポートを依頼している' do
         ProviderStatus.any_instance.should_receive(:export_by).exactly(2)
@@ -730,26 +730,20 @@ describe ProviderStatus do
     context 'つつがなく終わるとき' do
       before do
         ProviderStatus.any_instance.stub(:export_by).with(any_args).and_return([])
-        ProviderOriginalPicture.stub(:import).with(any_args).and_return({:original_pictures => [], :pictures => [], :resource_pictures => []})
+        ProviderOriginalPicture.stub(:import).with(any_args).and_return(OriginalPictureImportResult.new([]))
       end
       it '原画インポート結果を返す' do
         r = @ps.original_pictures_import '20111010'
-        r.is_a?(Hash).should be_true
-      end
-      it 'インポート失敗リストを取得している' do
-        r = @ps.original_pictures_import '20111010'
-        r[:original_pictures].should be_empty
-        r[:pictures].should be_empty
-        r[:resource_pictures].should be_empty
+        r.should be_response
       end
     end
     context 'エクスポートに失敗したとき' do
       before do
         ProviderStatus.any_instance.stub(:export_by).with(any_args).and_return(nil)
       end
-      it 'nilを返す' do
-        r = @ps.original_pictures_import '20111010'
-        r.should be_nil
+      it '受信に失敗したImportResultを返す' do
+        r = @ps.licenses_import '20111010'
+        r.should_not be_response
       end
     end
   end