• R/O
  • HTTP
  • SSH
  • HTTPS

pettanr: コミット

サーバ側、Railsシステム本体


コミットメタ情報

リビジョン0abef1b231256336612e82c288a821112795400b (tree)
日時2013-04-27 14:16:12
作者yasushiito <yas@pen-...>
コミッターyasushiito

ログメッセージ

Merge branch 'v05' of git.sourceforge.jp:/gitroot/pettanr/pettanr into v05

変更サマリ

差分

--- a/app/controllers/provider_statuses_controller.rb
+++ b/app/controllers/provider_statuses_controller.rb
@@ -69,37 +69,37 @@ class ProviderStatusesController < ApplicationController
6969 def licenses_import
7070 @provider_status = ProviderStatus.show(params[:id], @admin)
7171 raise ActiveRecord::Forbidden if @provider_status.status == 0
72- @failures = @provider_status.licenses_import params[:date]
72+ @import_result = @provider_status.licenses_import params[:date]
7373 respond_to do |format|
7474 format.html # show.html.erb
75- format.json { render :json => @failures.to_json() }
75+ format.json { render :json => @import_result.to_json() }
7676 end
7777 end
7878
7979 def artists_import
8080 @provider_status = ProviderStatus.show(params[:id], @admin)
8181 raise ActiveRecord::Forbidden if @provider_status.status == 0
82- @failures = @provider_status.artists_import params[:date]
82+ @import_result = @provider_status.artists_import params[:date]
8383 respond_to do |format|
8484 format.html # show.html.erb
85- format.json { render :json => @failures.to_json() }
85+ format.json { render :json => @import_result.to_json() }
8686 end
8787 end
8888
8989 def original_pictures_import
9090 @provider_status = ProviderStatus.show(params[:id], @admin)
9191 raise ActiveRecord::Forbidden if @provider_status.status == 0
92- @failures = @provider_status.original_pictures_import params[:date]
92+ @import_result = @provider_status.original_pictures_import params[:date]
9393 respond_to do |format|
9494 format.html # show.html.erb
95- format.json { render :json => @failures.to_json() }
95+ format.json { render :json => @import_result.to_json() }
9696 end
9797 end
9898
9999 def import
100100 @provider_status = ProviderStatus.show(params[:id], @admin)
101101 raise ActiveRecord::Forbidden if @provider_status.status == 0
102- @failures = port
102+ @import_result = @provider_status.import params[:date]
103103 respond_to do |format|
104104 format.html # show.html.erb
105105 format.json { render :json => @failures.to_json() }
@@ -107,10 +107,8 @@ class ProviderStatusesController < ApplicationController
107107 end
108108
109109 def import_all
110- ProviderStatus.find(:all).each do |provider_status|
111- next unless provider_status.status == 3
112- @provider_status = provider_status
113- @failures = port
110+ ProviderStatus.approve_list.each do |provider_status|
111+ @provider_status = provider_status params[:date]
114112 end
115113 respond_to do |format|
116114 format.html { render :text => 'ok'}
--- a/app/models/provider_artist.rb
+++ b/app/models/provider_artist.rb
@@ -41,7 +41,7 @@ class ProviderArtist < ActiveRecord::Base
4141 end
4242 raise ActiveRecord::Rollback if res.any?
4343 end
44- res
44+ ArtistImportResult.new res
4545 end
4646
4747 end
--- a/app/models/provider_license.rb
+++ b/app/models/provider_license.rb
@@ -32,7 +32,7 @@ class ProviderLicense < ActiveRecord::Base
3232 end
3333 raise ActiveRecord::Rollback if res.any?
3434 end
35- res
35+ LicenseImportResult.new res
3636 end
3737
3838 end
--- a/app/models/provider_original_picture.rb
+++ b/app/models/provider_original_picture.rb
@@ -166,17 +166,24 @@ class ProviderOriginalPicture < ActiveRecord::Base
166166 end
167167
168168 def self.import pid, original_pictures, pictures
169- res = {:original_pictures => [], :pictures => [], :resource_pictures => []}
169+ res = nil
170170 ProviderOriginalPicture.transaction do
171171 r = ProviderOriginalPicture.import_original_pictures(pid, original_pictures)
172- res[:original_pictures] = r
173- raise ActiveRecord::Rollback if r.any?
172+ if r.any?
173+ res = OriginalPictureImportResult.new r
174+ raise ActiveRecord::Rollback
175+ end
174176 r = ProviderOriginalPicture.import_pictures(pid, pictures)
175- res[:pictures] = r
176- raise ActiveRecord::Rollback if r.any?
177+ if r.any?
178+ res = PictureImportResult.new r
179+ raise ActiveRecord::Rollback
180+ end
177181 r = ProviderOriginalPicture.import_resource_pictures(pid, original_pictures)
178- res[:resource_pictures] = r
179- raise ActiveRecord::Rollback if r.any?
182+ if r.any?
183+ res = ResourcePictureImportResult.new r
184+ raise ActiveRecord::Rollback
185+ end
186+ res = OriginalPictureImportResult.new []
180187 end
181188 res
182189 end
--- a/app/models/provider_status.rb
+++ b/app/models/provider_status.rb
@@ -123,12 +123,19 @@ class ProviderStatus < ActiveRecord::Base
123123 end
124124
125125 def ymd_to_time ymd_str
126- return nil if ymd_str.blank?
127126 date = nil
128- begin
129- date = Time.parse(ymd_str[0..3] + '/' + ymd_str[4..5] + '/' + ymd_str[6..7])
130- rescue
131- date = nil
127+ if ymd_str.blank?
128+ date = if self.received_at
129+ self.received_at
130+ else
131+ nil
132+ end
133+ else
134+ begin
135+ date = Time.parse(ymd_str[0..3] + '/' + ymd_str[4..5] + '/' + ymd_str[6..7])
136+ rescue
137+ date = nil
138+ end
132139 end
133140 date
134141 end
@@ -159,41 +166,56 @@ class ProviderStatus < ActiveRecord::Base
159166
160167 def licenses_import date
161168 licenses = self.export_by('licenses_export', date)
162- return nil unless licenses
163- ProviderLicense.import self.provider.id, licenses
169+ if licenses
170+ ProviderLicense.import self.provider.id, licenses
171+ else
172+ LicenseImportResult.new nil
173+ end
164174 end
165175
166176 def artists_import date
167177 artists = self.export_by('artists_export', date)
168- return nil unless artists
169- ProviderArtist.import self.provider.id, artists
178+ if artists
179+ ProviderArtist.import self.provider.id, artists
180+ else
181+ ArtistImportResult.new nil
182+ end
170183 end
171184
172185 def original_pictures_import date
173186 original_pictures = self.export_by('original_pictures_export', date)
174- return nil unless original_pictures
175187 pictures = self.export_by('pictures_export', date)
176- return nil unless pictures
177- ProviderOriginalPicture.import self.provider.id, original_pictures, pictures
178- end
179-
180- def port
181- exports = export_by('export', @provider_status, params[:date])
182- return nil unless exports
183- ProviderStatus.import @provider_status.provider.id, exports
188+ if original_pictures and pictures
189+ ProviderOriginalPicture.import self.provider.id, original_pictures, pictures
190+ else
191+ OriginalPictureImportResult.new nil
192+ end
184193 end
185194
186- def self.import pid, exports
187- res = {}
195+ def import date
196+ import_result = nil
188197 ProviderStatus.transaction do
189- res[:licenses] = ProviderLicense.import pid, exports['licenses']
190- raise ActiveRecord::Rollback if res[:licenses].any?
191- res[:artists] = ProviderArtist.import pid, exports['artists']
192- raise ActiveRecord::Rollback if res[:artists].any?
193- res[:original_pictures] = ProviderOriginalPicture.import pid, exports['original_pictures'], exports['pictures']
194- raise ActiveRecord::Rollback if res[:original_pictures][:original_pictures].any? or res[:original_pictures][:resource_pictures].any? or res[:original_pictures][:pictures].any?
198+ import_result = self.licenses_import date
199+ raise ActiveRecord::Rollback unless import_result.success?
200+ import_result = self.artists_import date
201+ raise ActiveRecord::Rollback unless import_result.success?
202+ import_result = self.original_pictures_import date
203+ raise ActiveRecord::Rollback unless import_result.success?
204+ self.received_at = Time.now
205+ self.save
195206 end
196- res
207+ import_result
197208 end
198209
210+ def self.import_all date = nil
211+ failures = {}
212+ ProviderStatus.approve_list.each do |provider_status|
213+ import_result = provider_status.import date
214+ next if import_result.success?
215+ failures[provider_status.provider.name] = import_result
216+ end
217+ failures.each do |name, import_result|
218+ puts name
219+ end
220+ end
199221 end
--- a/app/views/provider_statuses/_artists_errors.html.erb
+++ /dev/null
@@ -1,18 +0,0 @@
1-<h2>
2- <%= t('provider_statuses.artists_import.fail', :size => failures.size) %>
3-</h2>
4-<table>
5- <tr>
6- <th><%= t_m 'Artist.name' -%></th>
7- </tr>
8- <% failures.each do |artist| %>
9- <tr>
10- <td>
11- <%= h(artist['name']) %>
12- </td>
13- <td>
14- <%= h(artist) %>
15- </td>
16- </tr>
17- <% end %>
18-</table>
--- /dev/null
+++ b/app/views/provider_statuses/_import_errors.html.erb
@@ -0,0 +1,19 @@
1+<h2>
2+ <%= t("provider_statuses.#{import_result.translate}.fail", :size => import_result.failures.size) %>
3+</h2>
4+<table>
5+ <tr>
6+ <% import_result.columns.each do |column| %>
7+ <th><%= t_m "#{import_result.obj}.#{column}" -%></th>
8+ <% end %>
9+ </tr>
10+ <% import_result.failures.each do |failure| %>
11+ <tr>
12+ <% import_result.columns.each do |column| %>
13+ <td>
14+ <%= h(failure[column]) %>
15+ </td>
16+ <% end %>
17+ </tr>
18+ <% end %>
19+</table>
--- a/app/views/provider_statuses/_licenses_errors.html.erb
+++ /dev/null
@@ -1,19 +0,0 @@
1-<h2>
2- <%= t('provider_statuses.licenses_import.fail', :size => failures.size) %>
3-</h2>
4-<table>
5- <tr>
6- <th><%= t_m 'License.caption' -%></th>
7- <th><%= t_m 'License.name' -%></th>
8- </tr>
9- <% failures.each do |license| %>
10- <tr>
11- <td>
12- <%= link_to h(license['caption']), license['url'] %>
13- </td>
14- <td>
15- <%= h(license['name']) %>
16- </td>
17- </tr>
18- <% end %>
19-</table>
--- a/app/views/provider_statuses/_original_pictures_errors.html.erb
+++ /dev/null
@@ -1,23 +0,0 @@
1-<h2>
2- <%= t('provider_statuses.original_pictures_import.fail', :size => failures.size) %>
3-</h2>
4-<table>
5- <tr>
6- <th><%= t_m 'OriginalPicture.id' -%></th>
7- <th><%= t_m 'OriginalPicture.artist_id' -%></th>
8- <th><%= t_m 'OriginalPicture.md5' -%></th>
9- </tr>
10- <% failures.each do |original_picture| %>
11- <tr>
12- <td>
13- <%= h(original_picture['id']) %>
14- </td>
15- <td>
16- <%= h(original_picture['artist_id']) %>
17- </td>
18- <td>
19- <%= h(original_picture['md5']) %>
20- </td>
21- </tr>
22- <% end %>
23-</table>
--- a/app/views/provider_statuses/_pictures_errors.html.erb
+++ /dev/null
@@ -1,31 +0,0 @@
1-<h2>
2- <%= t('provider_statuses.pictures_import.fail', :size => failures.size) %>
3-</h2>
4-<table>
5- <tr>
6- <th><%= t_m 'Picture.id' -%></th>
7- <th><%= t_m 'Picture.original_picture_id' -%></th>
8- <th><%= t_m 'Picture.revision' -%></th>
9- <th><%= t_m 'Picture.artist_id' -%></th>
10- <th><%= t_m 'Picture.md5' -%></th>
11- </tr>
12- <% failures.each do |picture| %>
13- <tr>
14- <td>
15- <%= h(picture['id']) %>
16- </td>
17- <td>
18- <%= h(picture['original_picture_id']) %>
19- </td>
20- <td>
21- <%= h(picture['revision']) %>
22- </td>
23- <td>
24- <%= h(picture['artist_id']) %>
25- </td>
26- <td>
27- <%= h(picture['md5']) %>
28- </td>
29- </tr>
30- <% end %>
31-</table>
--- a/app/views/provider_statuses/_resource_pictures_errors.html.erb
+++ /dev/null
@@ -1,31 +0,0 @@
1-<h2>
2- <%= t('provider_statuses.resource_pictures_import.fail', :size => failures.size) %>
3-</h2>
4-<table>
5- <tr>
6- <th><%= t_m 'ResourcePicture.id' -%></th>
7- <th><%= t_m 'ResourcePicture.original_picture_id' -%></th>
8- <th><%= t_m 'ResourcePicture.picture_id' -%></th>
9- <th><%= t_m 'ResourcePicture.artist_id' -%></th>
10- <th><%= t_m 'ResourcePicture.md5' -%></th>
11- </tr>
12- <% failures.each do |resource_picture| %>
13- <tr>
14- <td>
15- <%= h(resource_picture['id']) %>
16- </td>
17- <td>
18- <%= h(resource_picture['original_picture_id']) %>
19- </td>
20- <td>
21- <%= h(resource_picture['picture_id']) %>
22- </td>
23- <td>
24- <%= h(resource_picture['artist_id']) %>
25- </td>
26- <td>
27- <%= h(resource_picture['md5']) %>
28- </td>
29- </tr>
30- <% end %>
31-</table>
--- a/app/views/provider_statuses/artists_import.html.erb
+++ b/app/views/provider_statuses/artists_import.html.erb
@@ -1,13 +1,15 @@
11 <h1><%= t('.title') %></h1>
22 <p id="notice"><%= notice %></p>
33
4-<% if @failures == nil %>
5- <h1>No Response</h1>
6-<% elsif @failures.empty? %>
7- <h2>
8- <%= t('provider_statuses.artists_import.success') %>
9- </h2>
4+<% if @import_result.response? %>
5+ <% if @import_result.success? %>
6+ <h2>
7+ <%= t("provider_statuses.#{@import_result.action}.success") %>
8+ </h2>
9+ <% else %>
10+ <%= render 'import_errors', :import_result => @import_result %>
11+ <%= link_to t("provider_statuses.#{@import_result.action}.to_show"), provider_status_path(@provider_status) %>
12+ <% end %>
1013 <% else %>
11- <%= render 'artists_errors', :failures => @failures %>
12- <%= link_to t('provider_statuses.artists_import.to_show'), provider_status_path(@provider_status) %>
14+ <h1>No Response</h1>
1315 <% end %>
--- a/app/views/provider_statuses/import.html.erb
+++ b/app/views/provider_statuses/import.html.erb
@@ -1,20 +1,15 @@
11 <h1><%= t('.title') %></h1>
22 <p id="notice"><%= notice %></p>
33
4-<% if @failures == nil %>
5- <h1>No Response</h1>
6-<% elsif @failures[:licenses].any? %>
7- <%= render 'licenses_errors', :failures => @failures[:licenses] %>
8-<% elsif @failures[:artists].any? %>
9- <%= render 'artists_errors', :failures => @failures[:artists] %>
10-<% elsif @failures[:original_pictures][:original_pictures].any? %>
11- <%= render 'original_pictures_errors', :failures => @failures[:original_pictures][:original_pictures] %>
12-<% elsif @failures[:original_pictures][:pictures].any? %>
13- <%= render 'pictures_errors', :failures => @failures[:original_pictures][:pictures] %>
14-<% elsif @failures[:original_pictures][:resource_pictures].any? %>
15- <%= render 'resource_pictures_errors', :failures => @failures[:original_pictures][:resource_pictures] %>
4+<% if @import_result.response? %>
5+ <% if @import_result.success? %>
6+ <h2>
7+ <%= t("provider_statuses.import.success") %>
8+ </h2>
9+ <% else %>
10+ <%= render 'import_errors', :import_result => @import_result %>
11+ <%= link_to t("provider_statuses.#{@import_result.action}.to_show"), provider_status_path(@provider_status) %>
12+ <% end %>
1613 <% else %>
17- <h2>
18- <%= t('provider_statuses.import.success') %>
19- </h2>
14+ <h1>No Response</h1>
2015 <% end %>
--- a/app/views/provider_statuses/licenses_import.html.erb
+++ b/app/views/provider_statuses/licenses_import.html.erb
@@ -1,13 +1,15 @@
11 <h1><%= t('.title') %></h1>
22 <p id="notice"><%= notice %></p>
33
4-<% if @failures == nil %>
5- <h1>No Response</h1>
6-<% elsif @failures.empty? %>
7- <h2>
8- <%= t('provider_statuses.licenses_import.success') %>
9- </h2>
4+<% if @import_result.response? %>
5+ <% if @import_result.success? %>
6+ <h2>
7+ <%= t("provider_statuses.#{@import_result.action}.success") %>
8+ </h2>
9+ <% else %>
10+ <%= render 'import_errors', :import_result => @import_result %>
11+ <%= link_to t("provider_statuses.#{@import_result.action}.to_show"), provider_status_path(@provider_status) %>
12+ <% end %>
1013 <% else %>
11- <%= render 'licenses_errors', :failures => @failures %>
12- <%= link_to t('provider_statuses.licenses_import.to_show'), provider_status_path(@provider_status) %>
14+ <h1>No Response</h1>
1315 <% end %>
--- a/app/views/provider_statuses/original_pictures_import.html.erb
+++ b/app/views/provider_statuses/original_pictures_import.html.erb
@@ -1,19 +1,15 @@
11 <h1><%= t('.title') %></h1>
22 <p id="notice"><%= notice %></p>
33
4-<% if @failures == nil %>
5- <h1>No Response</h1>
6-<% elsif @failures[:original_pictures].any? %>
7- <%= render 'original_pictures_errors', :failures => @failures[:original_pictures] %>
8- <%= link_to t('provider_statuses.original_pictures_import.to_show'), provider_status_path(@provider_status) %>
9-<% elsif @failures[:pictures].any? %>
10- <%= render 'pictures_errors', :failures => @failures[:pictures] %>
11- <%= link_to t('provider_statuses.original_pictures_import.to_show'), provider_status_path(@provider_status) %>
12-<% elsif @failures[:resource_pictures].any? %>
13- <%= render 'resource_pictures_errors', :failures => @failures[:resource_pictures] %>
14- <%= link_to t('provider_statuses.original_pictures_import.to_show'), provider_status_path(@provider_status) %>
4+<% if @import_result.response? %>
5+ <% if @import_result.success? %>
6+ <h2>
7+ <%= t("provider_statuses.#{@import_result.action}.success") %>
8+ </h2>
9+ <% else %>
10+ <%= render 'import_errors', :import_result => @import_result %>
11+ <%= link_to t("provider_statuses.#{@import_result.action}.to_show"), provider_status_path(@provider_status) %>
12+ <% end %>
1513 <% else %>
16- <h2>
17- <%= t('provider_statuses.original_pictures_import.success') %>
18- </h2>
14+ <h1>No Response</h1>
1915 <% end %>
--- a/config/environment.rb
+++ b/config/environment.rb
@@ -8,4 +8,5 @@ Pettanr::Application.initialize!
88 require 'picture_io'
99 require 'pettan_imager'
1010 require 'ar_helper'
11+require 'import_result'
1112
--- /dev/null
+++ b/lib/import_result.rb
@@ -0,0 +1,129 @@
1+#
2+class ImportResult
3+
4+ def initialize results
5+ @results = results
6+ end
7+
8+ def response?
9+ @results != nil
10+ end
11+
12+ def success?
13+ @results.empty?
14+ end
15+
16+ def failures
17+ @results
18+ end
19+
20+ def to_json
21+ if response?
22+ @results.to_json
23+ else
24+ 'No Response'
25+ end
26+ end
27+
28+end
29+
30+class LicenseImportResult < ImportResult
31+
32+ def columns
33+ ['caption', 'name']
34+ end
35+
36+ def obj
37+ 'License'
38+ end
39+
40+ def action
41+ 'licenses_import'
42+ end
43+
44+ def translate
45+ 'licenses_import'
46+ end
47+
48+end
49+
50+class ArtistImportResult < ImportResult
51+
52+ def columns
53+ ['name']
54+ end
55+
56+ def obj
57+ 'Artist'
58+ end
59+
60+ def action
61+ 'artists_import'
62+ end
63+
64+ def translate
65+ 'licenses_import'
66+ end
67+
68+end
69+
70+class OriginalPictureImportResult < ImportResult
71+
72+ def columns
73+ ['id', 'artist_id', 'md5']
74+ end
75+
76+ def obj
77+ 'OriginalPicture'
78+ end
79+
80+ def action
81+ 'original_pictures_import'
82+ end
83+
84+ def translate
85+ 'original_pictures_import'
86+ end
87+
88+end
89+
90+class ResourcePictureImportResult < ImportResult
91+
92+ def columns
93+ ['id', 'original_picture_id', 'picture_id', 'artist_id', 'md5']
94+ end
95+
96+ def obj
97+ 'ResourcePicture'
98+ end
99+
100+ def action
101+ 'original_pictures_import'
102+ end
103+
104+ def translate
105+ 'resource_pictures_import'
106+ end
107+
108+end
109+
110+class PictureImportResult < ImportResult
111+
112+ def columns
113+ ['id', 'original_picture_id', 'revision', 'artist_id', 'md5']
114+ end
115+
116+ def obj
117+ 'Picture'
118+ end
119+
120+ def action
121+ 'original_pictures_import'
122+ end
123+
124+ def translate
125+ 'pictures_import'
126+ end
127+
128+end
129+
--- a/spec/controllers/provider_statuses_controller_spec.rb
+++ b/spec/controllers/provider_statuses_controller_spec.rb
@@ -369,7 +369,7 @@ describe ProviderStatusesController do
369369 context '事前チェックしておく' do
370370 before do
371371 ProviderStatus.any_instance.stub(:status).with(any_args).and_return(1)
372- ProviderStatus.stub(:licenses_import).with(any_args).and_return([])
372+ ProviderStatus.stub(:licenses_import).with(any_args).and_return(LicenseImportResult.new([]))
373373 end
374374 it '借受状況モデルに単体取得を問い合わせている' do
375375 ProviderStatus.should_receive(:show).exactly(1)
@@ -383,7 +383,7 @@ describe ProviderStatusesController do
383383 context 'つつがなく終わるとき' do
384384 before do
385385 ProviderStatus.any_instance.stub(:status).with(any_args).and_return(1)
386- ProviderStatus.any_instance.stub(:licenses_import).with(any_args).and_return([])
386+ ProviderStatus.any_instance.stub(:licenses_import).with(any_args).and_return(LicenseImportResult.new([]))
387387 end
388388 it 'ステータスコード200 OKを返す' do
389389 get :licenses_import, :id => @ps.id
@@ -393,9 +393,9 @@ describe ProviderStatusesController do
393393 get :licenses_import, :id => @ps.id
394394 assigns(:provider_status).should eq(@ps)
395395 end
396- it '@failuresにインポート失敗リストを取得している' do
396+ it '@import_resultにインポート結果を取得している' do
397397 get :licenses_import, :id => @ps.id
398- assigns(:failures).should eq([])
398+ assigns(:import_result).is_a?(ImportResult).should be_true
399399 end
400400 context 'html形式' do
401401 it 'licenses_importテンプレートを描画する' do
@@ -466,7 +466,7 @@ describe ProviderStatusesController do
466466 context '事前チェックしておく' do
467467 before do
468468 ProviderStatus.any_instance.stub(:status).with(any_args).and_return(1)
469- ProviderStatus.any_instance.stub(:artists_import).with(any_args).and_return([])
469+ ProviderStatus.any_instance.stub(:artists_import).with(any_args).and_return(ArtistImportResult.new([]))
470470 end
471471 it '借受状況モデルに単体取得を問い合わせている' do
472472 ProviderStatus.should_receive(:show).exactly(1)
@@ -480,7 +480,7 @@ describe ProviderStatusesController do
480480 context 'つつがなく終わるとき' do
481481 before do
482482 ProviderStatus.any_instance.stub(:status).with(any_args).and_return(1)
483- ProviderStatus.any_instance.stub(:artists_import).with(any_args).and_return([])
483+ ProviderStatus.any_instance.stub(:artists_import).with(any_args).and_return(ArtistImportResult.new([]))
484484 end
485485 it 'ステータスコード200 OKを返す' do
486486 get :artists_import, :id => @ps.id
@@ -490,9 +490,9 @@ describe ProviderStatusesController do
490490 get :artists_import, :id => @ps.id
491491 assigns(:provider_status).should eq(@ps)
492492 end
493- it '@failuresにインポート失敗リストを取得している' do
493+ it '@import_resultにインポート結果を取得している' do
494494 get :artists_import, :id => @ps.id
495- assigns(:failures).should eq([])
495+ assigns(:import_result).is_a?(ImportResult).should be_true
496496 end
497497 context 'html形式' do
498498 it 'artists_importテンプレートを描画する' do
@@ -572,7 +572,7 @@ describe ProviderStatusesController do
572572 context '事前チェックしておく' do
573573 before do
574574 ProviderStatus.any_instance.stub(:status).with(any_args).and_return(1)
575- ProviderStatus.any_instance.stub(:original_pictures_import).with(any_args).and_return({:original_pictures => [], :pictures => [], :resource_pictures => []})
575+ ProviderStatus.any_instance.stub(:original_pictures_import).with(any_args).and_return(OriginalPictureImportResult.new([]))
576576 end
577577 it '借受状況モデルに単体取得を問い合わせている' do
578578 ProviderStatus.should_receive(:show).exactly(1)
@@ -586,7 +586,7 @@ describe ProviderStatusesController do
586586 context 'つつがなく終わるとき' do
587587 before do
588588 ProviderStatus.any_instance.stub(:status).with(any_args).and_return(1)
589- ProviderStatus.any_instance.stub(:original_pictures_import).with(any_args).and_return({:original_pictures => [], :pictures => [], :resource_pictures => []})
589+ ProviderStatus.any_instance.stub(:original_pictures_import).with(any_args).and_return(OriginalPictureImportResult.new([]))
590590 end
591591 it 'ステータスコード200 OKを返す' do
592592 get :original_pictures_import, :id => @ps.id
@@ -596,12 +596,9 @@ describe ProviderStatusesController do
596596 get :original_pictures_import, :id => @ps.id
597597 assigns(:provider_status).should eq(@ps)
598598 end
599- it '@failuresにインポート失敗リストを取得している' do
599+ it '@import_resultにインポート結果を取得している' do
600600 get :original_pictures_import, :id => @ps.id
601- assigns(:failures).should_not be_nil
602- assigns(:failures)[:original_pictures].should be_empty
603- assigns(:failures)[:pictures].should be_empty
604- assigns(:failures)[:resource_pictures].should be_empty
601+ assigns(:import_result).is_a?(ImportResult).should be_true
605602 end
606603 context 'html形式' do
607604 it 'artists_importテンプレートを描画する' do
--- a/spec/models/provider_artist_spec.rb
+++ b/spec/models/provider_artist_spec.rb
@@ -143,9 +143,10 @@ describe ProviderArtist do
143143 end
144144 end
145145 context 'つつがなく終わるとき' do
146- it '空っぽの配列を返す' do
146+ it 'ImportResultを返す' do
147147 r = ProviderArtist.import @provider.id, [@artist.attributes]
148- r.should be_empty
148+ r.is_a?(ImportResult).should be_true
149+ r.should be_success
149150 end
150151 it '対照表が追加される' do
151152 lambda {
@@ -154,9 +155,10 @@ describe ProviderArtist do
154155 end
155156 end
156157 context '複数インポートのとき' do
157- it '空っぽの配列を返す' do
158+ it 'ImportResultを返す' do
158159 r = ProviderArtist.import @provider.id, [@artist.attributes, @artist2.attributes]
159- r.should be_empty
160+ r.is_a?(ImportResult).should be_true
161+ r.should be_success
160162 end
161163 it '対照表が追加される' do
162164 lambda {
@@ -169,18 +171,20 @@ describe ProviderArtist do
169171 before do
170172 ProviderArtist.any_instance.stub(:save).with(any_args).and_return(false)
171173 end
172- it '結果に貸手側絵師のカラム値を追加している' do
174+ it '結果が失敗している' do
173175 r = ProviderArtist.import @provider.id, [@artist.attributes]
174- r.should_not be_empty
176+ r.should_not be_success
177+ r.failures.should_not be_empty
175178 end
176179 end
177180 context '絵師オブジェクトの保存に失敗したとき' do
178181 before do
179182 Artist.any_instance.stub(:save).with(any_args).and_return(false)
180183 end
181- it '結果に貸手側絵師のカラム値を追加している' do
184+ it '結果が失敗している' do
182185 r = ProviderArtist.import @provider.id, [@artist.attributes]
183- r.should_not be_empty
186+ r.should_not be_success
187+ r.failures.should_not be_empty
184188 end
185189 end
186190 end
--- a/spec/models/provider_license_spec.rb
+++ b/spec/models/provider_license_spec.rb
@@ -101,9 +101,10 @@ describe ProviderLicense do
101101 end
102102 end
103103 context 'つつがなく終わるとき' do
104- it '空っぽの配列を返す' do
104+ it 'ImportResultを返す' do
105105 r = ProviderLicense.import @provider.id, [@license.attributes]
106- r.should be_empty
106+ r.is_a?(ImportResult).should be_true
107+ r.should be_success
107108 end
108109 it '対照表が追加される' do
109110 lambda {
@@ -112,9 +113,10 @@ describe ProviderLicense do
112113 end
113114 end
114115 context '複数インポートのとき' do
115- it '空っぽの配列を返す' do
116+ it 'ImportResultを返す' do
116117 r = ProviderLicense.import @provider.id, [@license.attributes, @license2.attributes]
117- r.should be_empty
118+ r.is_a?(ImportResult).should be_true
119+ r.should be_success
118120 end
119121 it '対照表が追加される' do
120122 lambda {
@@ -127,18 +129,20 @@ describe ProviderLicense do
127129 before do
128130 ProviderLicense.any_instance.stub(:save).with(any_args).and_return(false)
129131 end
130- it '結果に貸手側ライセンスのカラム値を追加している' do
132+ it '結果が失敗している' do
131133 r = ProviderLicense.import @provider.id, [@license.attributes]
132- r.should_not be_empty
134+ r.should_not be_success
135+ r.failures.should_not be_empty
133136 end
134137 end
135138 context 'ライセンスの管理名取得に失敗したとき' do
136139 before do
137140 License.stub(:find_by_name).with(any_args).and_return(nil)
138141 end
139- it '結果に貸手側ライセンスのカラム値を追加している' do
142+ it '結果が失敗している' do
140143 r = ProviderLicense.import @provider.id, [@license.attributes]
141- r.should_not be_empty
144+ r.should_not be_success
145+ r.failures.should_not be_empty
142146 end
143147 end
144148 end
--- a/spec/models/provider_original_picture_spec.rb
+++ b/spec/models/provider_original_picture_spec.rb
@@ -882,11 +882,10 @@ describe ProviderOriginalPicture do
882882 ProviderOriginalPicture.stub(:import_pictures).with(any_args).and_return([])
883883 ProviderOriginalPicture.stub(:import_resource_pictures).with(any_args).and_return([])
884884 end
885- it '各失敗したカラム値をHashで返す' do
885+ it 'ImportResultを返す' do
886886 r = ProviderOriginalPicture.import @provider.id, [@opattr], [@pattr]
887- r[:original_pictures].should be_empty
888- r[:pictures].should be_empty
889- r[:resource_pictures].should be_empty
887+ r.is_a?(ImportResult).should be_true
888+ r.should be_success
890889 end
891890 end
892891 #警告ケース
@@ -896,11 +895,11 @@ describe ProviderOriginalPicture do
896895 ProviderOriginalPicture.stub(:import_pictures).with(any_args).and_return([])
897896 ProviderOriginalPicture.stub(:import_resource_pictures).with(any_args).and_return([])
898897 end
899- it '失敗した原画のカラム値を配列でoriginal_picturesに追加している' do
898+ it '結果が失敗している' do
900899 r = ProviderOriginalPicture.import @provider.id, [@opattr], [@pattr]
901- r[:original_pictures].should_not be_empty
902- r[:pictures].should be_empty
903- r[:resource_pictures].should be_empty
900+ r.should_not be_success
901+ r.is_a?(OriginalPictureImportResult).should be_true
902+ r.failures.should_not be_empty
904903 end
905904 end
906905 context '実素材インポートに失敗したとき' do
@@ -909,11 +908,11 @@ describe ProviderOriginalPicture do
909908 ProviderOriginalPicture.stub(:import_pictures).with(any_args).and_return([@pattr])
910909 ProviderOriginalPicture.stub(:import_resource_pictures).with(any_args).and_return([])
911910 end
912- it '失敗した原画のカラム値を配列でpicturesに追加している' do
911+ it '結果が失敗している' do
913912 r = ProviderOriginalPicture.import @provider.id, [@opattr], [@pattr]
914- r[:original_pictures].should be_empty
915- r[:pictures].should_not be_empty
916- r[:resource_pictures].should be_empty
913+ r.should_not be_success
914+ r.is_a?(PictureImportResult).should be_true
915+ r.failures.should_not be_empty
917916 end
918917 end
919918 context '素材インポートに失敗したとき' do
@@ -922,11 +921,11 @@ describe ProviderOriginalPicture do
922921 ProviderOriginalPicture.stub(:import_pictures).with(any_args).and_return([])
923922 ProviderOriginalPicture.stub(:import_resource_pictures).with(any_args).and_return([@rpattr])
924923 end
925- it '失敗した原画のカラム値を配列でresource_picturesに追加している' do
924+ it '結果が失敗している' do
926925 r = ProviderOriginalPicture.import @provider.id, [@opattr], [@pattr]
927- r[:original_pictures].should be_empty
928- r[:pictures].should be_empty
929- r[:resource_pictures].should_not be_empty
926+ r.should_not be_success
927+ r.is_a?(ResourcePictureImportResult).should be_true
928+ r.failures.should_not be_empty
930929 end
931930 end
932931 end
--- a/spec/models/provider_status_spec.rb
+++ b/spec/models/provider_status_spec.rb
@@ -636,7 +636,7 @@ describe ProviderStatus do
636636 context '事前チェックしておく' do
637637 before do
638638 ProviderStatus.any_instance.stub(:export_by).with(any_args).and_return([@license.attributes])
639- ProviderLicense.stub(:import).with(any_args).and_return([])
639+ ProviderLicense.stub(:import).with(any_args).and_return(LicenseImportResult.new([]))
640640 end
641641 it '貸手からのエクスポートを依頼している' do
642642 ProviderStatus.any_instance.should_receive(:export_by).exactly(1)
@@ -650,20 +650,20 @@ describe ProviderStatus do
650650 context 'つつがなく終わるとき' do
651651 before do
652652 ProviderStatus.any_instance.stub(:export_by).with(any_args).and_return([@license.attributes])
653- ProviderLicense.stub(:import).with(any_args).and_return([])
653+ ProviderLicense.stub(:import).with(any_args).and_return(LicenseImportResult.new([]))
654654 end
655655 it 'ライセンスインポート結果を返す' do
656656 r = @ps.licenses_import '20111010'
657- r.should eq []
657+ r.should be_response
658658 end
659659 end
660660 context 'エクスポートに失敗したとき' do
661661 before do
662662 ProviderStatus.any_instance.stub(:export_by).with(any_args).and_return(nil)
663663 end
664- it 'nilを返す' do
664+ it '受信に失敗したImportResultを返す' do
665665 r = @ps.licenses_import '20111010'
666- r.should be_nil
666+ r.should_not be_response
667667 end
668668 end
669669 end
@@ -676,7 +676,7 @@ describe ProviderStatus do
676676 context '事前チェックしておく' do
677677 before do
678678 ProviderStatus.any_instance.stub(:export_by).with(any_args).and_return([])
679- ProviderArtist.stub(:import).with(any_args).and_return([])
679+ ProviderArtist.stub(:import).with(any_args).and_return(ArtistImportResult.new([]))
680680 end
681681 it '貸手からのエクスポートを依頼している' do
682682 ProviderStatus.any_instance.should_receive(:export_by).exactly(1)
@@ -690,20 +690,20 @@ describe ProviderStatus do
690690 context 'つつがなく終わるとき' do
691691 before do
692692 ProviderStatus.any_instance.stub(:export_by).with(any_args).and_return([])
693- ProviderArtist.stub(:import).with(any_args).and_return([])
693+ ProviderArtist.stub(:import).with(any_args).and_return(ArtistImportResult.new([]))
694694 end
695695 it '絵師インポート結果を返す' do
696696 r = @ps.artists_import '20111010'
697- r.should eq []
697+ r.should be_response
698698 end
699699 end
700700 context 'エクスポートに失敗したとき' do
701701 before do
702702 ProviderStatus.any_instance.stub(:export_by).with(any_args).and_return(nil)
703703 end
704- it 'nilを返す' do
705- r = @ps.artists_import '20111010'
706- r.should be_nil
704+ it '受信に失敗したImportResultを返す' do
705+ r = @ps.licenses_import '20111010'
706+ r.should_not be_response
707707 end
708708 end
709709 end
@@ -716,7 +716,7 @@ describe ProviderStatus do
716716 context '事前チェックしておく' do
717717 before do
718718 ProviderStatus.any_instance.stub(:export_by).with(any_args).and_return([])
719- ProviderOriginalPicture.stub(:import).with(any_args).and_return({:original_pictures => [], :pictures => [], :resource_pictures => []})
719+ ProviderOriginalPicture.stub(:import).with(any_args).and_return(OriginalPictureImportResult.new([]))
720720 end
721721 it '貸手からのエクスポートを依頼している' do
722722 ProviderStatus.any_instance.should_receive(:export_by).exactly(2)
@@ -730,26 +730,20 @@ describe ProviderStatus do
730730 context 'つつがなく終わるとき' do
731731 before do
732732 ProviderStatus.any_instance.stub(:export_by).with(any_args).and_return([])
733- ProviderOriginalPicture.stub(:import).with(any_args).and_return({:original_pictures => [], :pictures => [], :resource_pictures => []})
733+ ProviderOriginalPicture.stub(:import).with(any_args).and_return(OriginalPictureImportResult.new([]))
734734 end
735735 it '原画インポート結果を返す' do
736736 r = @ps.original_pictures_import '20111010'
737- r.is_a?(Hash).should be_true
738- end
739- it 'インポート失敗リストを取得している' do
740- r = @ps.original_pictures_import '20111010'
741- r[:original_pictures].should be_empty
742- r[:pictures].should be_empty
743- r[:resource_pictures].should be_empty
737+ r.should be_response
744738 end
745739 end
746740 context 'エクスポートに失敗したとき' do
747741 before do
748742 ProviderStatus.any_instance.stub(:export_by).with(any_args).and_return(nil)
749743 end
750- it 'nilを返す' do
751- r = @ps.original_pictures_import '20111010'
752- r.should be_nil
744+ it '受信に失敗したImportResultを返す' do
745+ r = @ps.licenses_import '20111010'
746+ r.should_not be_response
753747 end
754748 end
755749 end
旧リポジトリブラウザで表示