OSDN Git Service

t#29400:itr3?
[pettanr/pettanr.git] / spec / models / resource_picture_spec.rb
index 820a630..ba5d62a 100644 (file)
 # -*- encoding: utf-8 -*-\r
-require 'spec_helper'
-
-describe ResourcePicture do
-  before do
-    Factory :admin
-    @user = Factory( :user_yas)
-    @author = @user.author
-    @artist = Factory :artist_yas, :author_id => @author.id\r
-    @other_user = Factory( :user_yas)
-    @other_author = @other_user.author
-    @other_artist = Factory :artist_yas, :author_id => @other_author.id
-    @sp = Factory :system_picture
-    @lg = Factory :license_group
-    @license = Factory :license, :license_group_id => @lg.id, :system_picture_id => @sp.id
-    @original_picture = Factory :original_picture, :artist_id => @artist.id\r
-    
-    class Mgk ; class Image ; end ; end
-    Mgk::Image.stub(:from_blob).with(any_args).and_return([Mgk.new])
-    Mgk.any_instance.stub(:format).with(any_args).and_return('png')
-    Mgk.any_instance.stub(:format=).with(any_args)
-    Mgk.any_instance.stub(:rows).with(any_args).and_return(200)
-    Mgk.any_instance.stub(:columns).with(any_args).and_return(100)
-    Mgk.any_instance.stub(:filesize).with(any_args).and_return(20000)
-    Mgk.any_instance.stub(:to_blob).with(any_args).and_return('data')
-    #原画ファイル削除だけは必ず成功するものとしておく
-    PictureIO::LocalPicture.any_instance.stub(:delete).with(any_args).and_return(true)
+#素材\r
+require 'spec_helper'\r
+\r
+describe ResourcePicture do\r
+  before do\r
+    FactoryGirl.create :admin\r
+    @user = FactoryGirl.create( :user_yas)\r
+    @author = @user.author\r
+    @artist = FactoryGirl.create :artist_yas, :author_id => @author.id\r
+    @other_user = FactoryGirl.create( :user_yas)\r
+    @other_author = @other_user.author\r
+    @other_artist = FactoryGirl.create :artist_yas, :author_id => @other_author.id\r
+    @sp = FactoryGirl.create :system_picture\r
+    @lg = FactoryGirl.create :license_group\r
+    @license = FactoryGirl.create :license, :license_group_id => @lg.id, :system_picture_id => @sp.id\r
+    @original_picture = FactoryGirl.create :original_picture, :artist_id => @artist.id\r
+    \r
+    #原画ファイル削除だけは必ず成功するものとしておく\r
+    PictureIO::LocalPicture.any_instance.stub(:delete).with(any_args).and_return(true)\r
     Picture.any_instance.stub(:subdirs).with(any_args).and_return(['', 'v', 'h', 'vh'])\r
-    Picture.any_instance.stub(:h).with(any_args).and_return('data')
-    Picture.any_instance.stub(:v).with(any_args).and_return('data')
-    Picture.any_instance.stub(:vh).with(any_args).and_return('data')
+    Picture.any_instance.stub(:h).with(any_args).and_return('data')\r
+    Picture.any_instance.stub(:v).with(any_args).and_return('data')\r
+    Picture.any_instance.stub(:vh).with(any_args).and_return('data')\r
   end\r
-  
-  describe '検証に於いて' do
+  \r
+  describe '検証に於いて' do\r
     before do\r
-      @p = Factory :picture, :original_picture_id => @original_picture.id, :license_id => @license.id, :artist_id => @artist.id
-      @rp = Factory.build :resource_picture, :artist_id => @artist.id, :original_picture_id => @original_picture.id, :license_id => @license.id, :picture_id => @p.id
-    end
-    
-    it 'オーソドックスなデータなら通る' do
-      @rp.should be_valid
-    end
-    
-    context 'extを検証するとき' do
-      it 'テストデータの確認' do
-        @rp.ext = 'jpeg'
-        @rp.should be_valid
-      end
-      it 'nullなら失敗する' do
-        @rp.ext = ''
-        @rp.should_not be_valid
-      end
-      it '5文字以上なら失敗する' do
-        @rp.ext = 'a'*5
-        @rp.should_not be_valid
-      end
-      it 'png,gif,jpeg以外なら失敗する' do
-        @rp.ext = 'bmp'
-        @rp.should_not be_valid
-      end
-    end
-    context 'widthを検証するとき' do
-      it 'テストデータの確認' do
+      @p = FactoryGirl.create :picture, :original_picture_id => @original_picture.id, :license_id => @license.id, :artist_id => @artist.id\r
+      @rp = FactoryGirl.build :resource_picture, :artist_id => @artist.id, :original_picture_id => @original_picture.id, :license_id => @license.id, :picture_id => @p.id\r
+    end\r
+    \r
+    context 'オーソドックスなデータのとき' do
+      it '下限データが通る' do
+        @rp.ext = 'png' #リストにない拡張子は通らないし
         @rp.width = 1
+        @rp.height = 1
+        @rp.filesize = 1
+        @rp.md5 = 'a'*32
+        @rp.classname = 'a'*1
         @rp.should be_valid
       end
-      it 'nullなら失敗する' do
-        @rp.width = nil
-        @rp.should_not be_valid
-      end
-      it '数値でなければ失敗する' do
-        @rp.width = 'a'
-        @rp.should_not be_valid
-      end
-      it '0なら失敗する' do
-        @rp.width = '0'
-        @rp.should_not be_valid
-      end
-      it '負でも失敗する' do
-        @rp.width = -1
-        @rp.should_not be_valid
-      end
-    end
-    context 'heightを検証するとき' do
-      it 'テストデータの確認' do
-        @rp.height = '1'
-        @rp.should be_valid
-      end
-      it 'nullなら失敗する' do
-        @rp.height = nil
-        @rp.should_not be_valid
-      end
-      it '数値でなければ失敗する' do
-        @rp.height = 'a'
-        @rp.should_not be_valid
-      end
-      it '0なら失敗する' do
-        @rp.height = '0'
-        @rp.should_not be_valid
-      end
-      it '負でも失敗する' do
-        @rp.height = -1
-        @rp.should_not be_valid
-      end
-    end
-    context 'filesizeを検証するとき' do
-      it 'テストデータの確認' do
-        @rp.filesize = '1'
-        @rp.should be_valid
-      end
-      it 'nullなら失敗する' do
-        @rp.filesize = nil
-        @rp.should_not be_valid
-      end
-      it '数値でなければ失敗する' do
-        @rp.filesize = 'a'
-        @rp.should_not be_valid
-      end
-      it '負なら失敗する' do
-        @rp.filesize = '-1'
-        @rp.should_not be_valid
-      end
-      it '2MB以上なら失敗する' do
-        @rp.filesize = 2000000+1
-        @rp.should_not be_valid
-      end
-    end
-    context 'artist_idを検証するとき' do
-      it 'テストデータの確認' do
-        @rp.artist_id = @artist.id
-        @rp.should be_valid
-      end
-      it 'nullなら失敗する' do
-        @rp.artist_id = nil
-        @rp.should_not be_valid
-      end
-      it '数値でなければ失敗する' do
-        @rp.artist_id = 'a'
-        @rp.should_not be_valid
-      end
-      it '存在する絵師でなければ失敗する' do
-        @rp.artist_id = 0
-        @rp.should_not be_valid
-      end
-    end
-    context 'license_idを検証するとき' do
-      it 'テストデータの確認' do
-        @rp.license_id = @license.id
-        @rp.should be_valid
-      end
-      it 'nullなら失敗する' do
-        @rp.license_id = nil
-        @rp.should_not be_valid
-      end
-      it '数値でなければ失敗する' do
-        @rp.license_id = 'a'
-        @rp.should_not be_valid
-      end
-      it '存在する絵師でなければ失敗する' do
-        @rp.license_id = 0
-        @rp.should_not be_valid
-      end
-    end
-    context 'original_picture_idを検証するとき' do
-      it 'テストデータの確認' do
-        @rp.original_picture_id = @original_picture.id
-        @rp.should be_valid
-      end
-      it 'nullなら失敗する' do
-        @rp.original_picture_id = nil
-        @rp.should_not be_valid
-      end
-      it '数値でなければ失敗する' do
-        @rp.original_picture_id = 'a'
-        @rp.should_not be_valid
-      end
-      it '存在する原画でなければ失敗する' do
-        @rp.original_picture_id = 0
-        @rp.should_not be_valid
-      end
-    end
-    context 'artist_nameを検証するとき' do
-      it 'テストデータの確認' do
-        @rp.artist_name = 'a'
-        @rp.should be_valid
-      end
-      it 'nullなら失敗する' do
-        @rp.artist_name = nil
-        @rp.should_not be_valid
-      end
-    end
-    context 'creditを検証するとき' do
-      it 'テストデータの確認' do
-        @rp.credit = 'a'
-        @rp.should be_valid
-      end
-    end
-    context 'settingsを検証するとき' do
-      it 'テストデータの確認' do
-        @rp.settings = 'a'
+      it '上限データが通る' do
+        @rp.ext = 'jpeg'
+        @rp.width = 99999
+        @rp.height = 99999
+        @rp.filesize = 2000000
+        @rp.md5 = 'a'*32
+        @rp.classname = 'a'*50
         @rp.should be_valid
       end
     end
-    context 'picture_idを検証するとき' do
-      it 'テストデータの確認' do
-        @rp.picture_id = @p.id
-        @rp.should be_valid
-      end
-      it 'nullなら失敗する' do
-        @rp.picture_id = nil
-        @rp.should_not be_valid
-      end
-      it '数値でなければ失敗する' do
-        @rp.picture_id = 'a'
-        @rp.should_not be_valid
-      end
-      it '存在する実素材でなければ失敗する' do
-        @rp.picture_id = 0
+    
+    context 'extを検証するとき' do\r
+      it 'nullなら失敗する' do\r
+        @rp.ext = ''\r
+        @rp.should_not be_valid\r
+      end\r
+      it '5文字以上なら失敗する' do\r
+        @rp.ext = 'a'*5\r
+        @rp.should_not be_valid\r
+      end\r
+      it 'png,gif,jpeg以外なら失敗する' do\r
+        @rp.ext = 'bmp'\r
+        @rp.should_not be_valid\r
+      end\r
+    end\r
+    context 'widthを検証するとき' do\r
+      it 'nullなら失敗する' do\r
+        @rp.width = nil\r
+        @rp.should_not be_valid\r
+      end\r
+      it '数値でなければ失敗する' do\r
+        @rp.width = 'a'\r
+        @rp.should_not be_valid\r
+      end\r
+      it '0なら失敗する' do\r
+        @rp.width = '0'\r
+        @rp.should_not be_valid\r
+      end\r
+      it '負でも失敗する' do\r
+        @rp.width = -1\r
+        @rp.should_not be_valid\r
+      end\r
+    end\r
+    context 'heightを検証するとき' do\r
+      it 'nullなら失敗する' do\r
+        @rp.height = nil\r
+        @rp.should_not be_valid\r
+      end\r
+      it '数値でなければ失敗する' do\r
+        @rp.height = 'a'\r
+        @rp.should_not be_valid\r
+      end\r
+      it '0なら失敗する' do\r
+        @rp.height = '0'\r
+        @rp.should_not be_valid\r
+      end\r
+      it '負でも失敗する' do\r
+        @rp.height = -1\r
+        @rp.should_not be_valid\r
+      end\r
+    end\r
+    context 'filesizeを検証するとき' do\r
+      it 'nullなら失敗する' do\r
+        @rp.filesize = nil\r
+        @rp.should_not be_valid\r
+      end\r
+      it '数値でなければ失敗する' do\r
+        @rp.filesize = 'a'\r
+        @rp.should_not be_valid\r
+      end\r
+      it '負なら失敗する' do\r
+        @rp.filesize = '-1'\r
+        @rp.should_not be_valid\r
+      end\r
+      it '2MB以上なら失敗する' do\r
+        @rp.filesize = 2000000+1\r
+        @rp.should_not be_valid\r
+      end\r
+    end\r
+    context 'artist_idを検証するとき' do\r
+      it 'nullなら失敗する' do\r
+        @rp.artist_id = nil\r
+        @rp.should_not be_valid\r
+      end\r
+      it '数値でなければ失敗する' do\r
+        @rp.artist_id = 'a'\r
+        @rp.should_not be_valid\r
+      end\r
+      it '存在する絵師でなければ失敗する' do\r
+        @rp.artist_id = 0\r
+        @rp.should_not be_valid\r
+      end\r
+    end\r
+    context 'md5を検証するとき' do\r
+      it 'nullなら失敗する' do\r
+        @rp.md5 = ''\r
+        @rp.should_not be_valid\r
+      end\r
+      it '31文字なら失敗する' do
+        @rp.md5 = 'a'*31
         @rp.should_not be_valid
       end
+      it '32文字以上なら失敗する' do\r
+        @rp.md5 = 'a'*33\r
+        @rp.should_not be_valid\r
+      end\r
+    end\r
+    context 'license_idを検証するとき' do\r
+      it 'nullなら失敗する' do\r
+        @rp.license_id = nil\r
+        @rp.should_not be_valid\r
+      end\r
+      it '数値でなければ失敗する' do\r
+        @rp.license_id = 'a'\r
+        @rp.should_not be_valid\r
+      end\r
+      it '存在する絵師でなければ失敗する' do\r
+        @rp.license_id = 0\r
+        @rp.should_not be_valid\r
+      end\r
+    end\r
+    context 'original_picture_idを検証するとき' do\r
+      it 'nullなら失敗する' do\r
+        @rp.original_picture_id = nil\r
+        @rp.should_not be_valid\r
+      end\r
+      it '数値でなければ失敗する' do\r
+        @rp.original_picture_id = 'a'\r
+        @rp.should_not be_valid\r
+      end\r
+      it '存在する原画でなければ失敗する' do\r
+        @rp.original_picture_id = 0\r
+        @rp.should_not be_valid\r
+      end\r
+    end\r
+    context 'artist_nameを検証するとき' do\r
+      it 'nullなら失敗する' do\r
+        @rp.artist_name = nil\r
+        @rp.should_not be_valid\r
+      end\r
+    end\r
+    context 'classnameを検証するとき' do\r
+      it 'nullなら失敗する' do\r
+        @rp.classname = ''\r
+        @rp.should_not be_valid\r
+      end\r
+      it '51文字以上なら失敗する' do\r
+        @rp.classname = 'a'*51\r
+        @rp.should_not be_valid\r
+      end\r
+    end\r
+    context 'creditを検証するとき' do\r
+    end\r
+    context 'settingsを検証するとき' do\r
+    end\r
+    context 'picture_idを検証するとき' do\r
+      it 'nullなら失敗する' do\r
+        @rp.picture_id = nil\r
+        @rp.should_not be_valid\r
+      end\r
+      it '数値でなければ失敗する' do\r
+        @rp.picture_id = 'a'\r
+        @rp.should_not be_valid\r
+      end\r
+      it '存在する実素材でなければ失敗する' do\r
+        @rp.picture_id = 0\r
+        @rp.should_not be_valid\r
+      end\r
+    end\r
+  end\r
+  \r
+  describe 'デフォルト値補充に於いて' do
+    it 'defined' do
+      @p = FactoryGirl.create :picture, :original_picture_id => @original_picture.id, :license_id => @license.id, :artist_id => @artist.id\r
+      @rp = FactoryGirl.build :resource_picture, :artist_id => @artist.id, :original_picture_id => @original_picture.id, :license_id => @license.id, :picture_id => @p.id\r
+      @rp.supply_default
     end
   end
   
-  describe 'データ補充に於いて' do
+  describe '上書き補充に於いて' do
     before do
+      @original_picture.attributes = {:ext => 'gif', :width => 267, :height => 268, :filesize => 269, 
+        :artist_id => @artist.id }
+      @rp = FactoryGirl.build :resource_picture, :original_picture_id => @original_picture.id
+    end
+    it 'width, height, ext, filesize, md5, original_picture_id, artist_idが設定されている' do
+      @rp.overwrite @original_picture
+      @rp.width.should eq 267
+      @rp.height.should eq 268
+      @rp.ext.should eq 'gif'
+      @rp.filesize.should eq 269
+      @rp.md5.should eq @rp.md5
+      @rp.original_picture_id.should eq @original_picture.id
+      @rp.artist_id.should eq @artist.id
     end
-    
   end
-  \r
-  describe '単体取得に於いて' do
+  
+  describe '所持判定に於いて' do
     before do
-      @op = Factory :original_picture, :artist_id => @artist.id
-      @p = Factory :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
-      @rp = Factory :resource_picture, :artist_id => @artist.id, :original_picture_id => @op.id, :license_id => @license.id, :picture_id => @p.id
-    end
-    it '指定の素材を返す' do
-      pic = ResourcePicture.show @rp.id
-      pic.should eq @rp
-    end
-    context '関連テーブルオプションがないとき' do
-      it 'ライセンスと絵師を含んでいる' do
-        r = ResourcePicture.show_include_opt
-        r.should eq [:license, :artist]
-      end
+      @p = FactoryGirl.create :picture, :original_picture_id => @original_picture.id, :license_id => @license.id, :artist_id => @artist.id\r
+      @rp = FactoryGirl.build :resource_picture, :artist_id => @artist.id, :original_picture_id => @original_picture.id, :license_id => @license.id, :picture_id => @p.id\r
     end
-    context '関連テーブルオプションで原画を含ませたとき' do
-      it 'ライセンスと絵師と原画データを含んでいる' do
-        r = ResourcePicture.show_include_opt(:include => :original_picture)
-        r.should eq [:license, :artist, :original_picture]
-      end
+    it '素材を更新することはないので、Falseを返す' do
+      @rp.own?(@author).should == false
     end
-    context '存在しない素材を開こうとしたとき' do
-      it '404RecordNotFound例外を返す' do
-        lambda{
-          pic = ResourcePicture.show 0
-        }.should raise_error(ActiveRecord::RecordNotFound)
-      end
+  end
+  
+  describe '閲覧許可に於いて' do
+    before do
+      @p = FactoryGirl.create :picture, :original_picture_id => @original_picture.id, :license_id => @license.id, :artist_id => @artist.id\r
+      @rp = FactoryGirl.build :resource_picture, :artist_id => @artist.id, :original_picture_id => @original_picture.id, :license_id => @license.id, :picture_id => @p.id\r
     end
+    it '必ず許可となる' do\r
+      r = @rp.visible?(@author)
+      r.should == true
+    end\r
   end
-  describe 'json単体出力オプションに於いて' do
-    it 'includeキーがライセンスと絵師を含んでいる' do
-      r = ResourcePicture.show_json_include_opt
-      r[:include].should eq [:license, :artist]
+  
+  describe 'ファイル名に於いて' do
+    before do
+      @p = FactoryGirl.create :picture, :original_picture_id => @original_picture.id, :license_id => @license.id, :artist_id => @artist.id\r
+      @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :original_picture_id => @original_picture.id, :license_id => @license.id, :picture_id => @p.id\r
+    end
+    it 'id+拡張子のフォーマットで返す' do
+      r = @rp.filename
+      r.should eq "#{@rp.id}.png"
     end
   end
-  describe '一覧取得に於いて' do
+  
+  describe 'MimeTypeに於いて' do
     before do
-      @op = Factory :original_picture, :artist_id => @artist.id
-      @p = Factory :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
-      @rp = Factory :resource_picture, :artist_id => @artist.id, :original_picture_id => @op.id, :license_id => @license.id, :picture_id => @p.id
+      @p = FactoryGirl.create :picture, :original_picture_id => @original_picture.id, :license_id => @license.id, :artist_id => @artist.id\r
+      @rp = FactoryGirl.build :resource_picture, :artist_id => @artist.id, :original_picture_id => @original_picture.id, :license_id => @license.id, :picture_id => @p.id\r
     end
-    context 'page補正について' do
-      it '文字列から数値に変換される' do
-        ResourcePicture.page('8').should eq 8
-      end
-      it 'nilの場合は1になる' do
-        ResourcePicture.page().should eq 1
-      end
-      it '0以下の場合は1になる' do
-        ResourcePicture.page('0').should eq 1
-      end
+    it 'image/拡張子のフォーマットで返す' do
+      r = @rp.mime_type
+      r.should eq "image/png"
     end
-    context 'page_size補正について' do
-      it '文字列から数値に変換される' do
-        ResourcePicture.page_size('7').should eq 7
-      end
-      it 'nilの場合はResourcePicture.default_page_sizeになる' do
-        ResourcePicture.page_size().should eq ResourcePicture.default_page_size
-      end
-      it '0以下の場合はResourcePicture.default_page_sizeになる' do
-        ResourcePicture.page_size('0').should eq ResourcePicture.default_page_size
-      end
-      it 'ResourcePicture.max_page_sizeを超えた場合はResourcePicture.max_page_sizeになる' do
-        ResourcePicture.page_size('1000').should eq ResourcePicture.max_page_size
-      end
+  end
+  
+  describe 'ファイルのurlに於いて' do
+    before do
+      @p = FactoryGirl.create :picture, :original_picture_id => @original_picture.id, :license_id => @license.id, :artist_id => @artist.id\r
+      @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :original_picture_id => @original_picture.id, :license_id => @license.id, :picture_id => @p.id\r
+      ResourcePicture.any_instance.stub(:filename).and_return('3.gif')
     end
-    it 'ã\83ªã\82¹ã\83\88ã\82\92è¿\94ã\81\99' do
-      pic = ResourcePicture.list
-      pic.should eq [@rp]
+    it 'ã\83\95ã\82¡ã\82¤ã\83«å\90\8då\8f\96å¾\97ã\82\92ä¾\9dé ¼ã\81\97ã\81¦ã\81\84ã\82\8b' do
+      ResourcePicture.any_instance.should_receive(:filename).exactly(1)
+      @rp.url
     end
-    it '時系列で並んでいる' do
-      nop = Factory :original_picture, :artist_id => @artist.id
-      nrp = Factory :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => nop.id, :picture_id => @p.id, :updated_at => Time.now + 100
-      pic = ResourcePicture.list
-      pic.should eq [nrp, @rp]
+    it '/resource_pictures/3.gifのフォーマットで返す' do
+      r = @rp.url
+      r.should eq "/resource_pictures/3.gif"
     end
+  end
+  
+  describe '一覧取得に於いて' do\r
+    before do\r
+      @op = FactoryGirl.create :original_picture, :artist_id => @artist.id\r
+      @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id\r
+      @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :original_picture_id => @op.id, :license_id => @license.id, :picture_id => @p.id\r
+    end\r
+    context 'page補正について' do\r
+      it '文字列から数値に変換される' do\r
+        ResourcePicture.page('8').should eq 8\r
+      end\r
+      it 'nilの場合は1になる' do\r
+        ResourcePicture.page().should eq 1\r
+      end\r
+      it '0以下の場合は1になる' do\r
+        ResourcePicture.page('0').should eq 1\r
+      end\r
+    end\r
+    context 'page_size補正について' do\r
+      it '文字列から数値に変換される' do\r
+        ResourcePicture.page_size('7').should eq 7\r
+      end\r
+      it 'nilの場合はResourcePicture.default_page_sizeになる' do\r
+        ResourcePicture.page_size().should eq ResourcePicture.default_page_size\r
+      end\r
+      it '0以下の場合はResourcePicture.default_page_sizeになる' do\r
+        ResourcePicture.page_size('0').should eq ResourcePicture.default_page_size\r
+      end\r
+      it 'ResourcePicture.max_page_sizeを超えた場合はResourcePicture.max_page_sizeになる' do\r
+        ResourcePicture.page_size('1000').should eq ResourcePicture.max_page_size\r
+      end\r
+    end\r
+    it 'リストを返す' do\r
+      r = ResourcePicture.list\r
+      r.should eq [@rp]\r
+    end\r
+    it '時系列で並んでいる' do\r
+      nop = FactoryGirl.create :original_picture, :artist_id => @artist.id\r
+      nrp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => nop.id, :picture_id => @p.id, :updated_at => Time.now + 100\r
+      r = ResourcePicture.list\r
+      r.should eq [nrp, @rp]\r
+    end\r
+    context 'DBに5件あって1ページの件数を2件に変えたとして' do\r
+      before do\r
+        nop2 = FactoryGirl.create :original_picture, :artist_id => @artist.id\r
+        @nrp2 = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => nop2.id, :picture_id => @p.id, :updated_at => Time.now + 100\r
+        nop3 = FactoryGirl.create :original_picture, :artist_id => @artist.id\r
+        @nrp3 = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => nop3.id, :picture_id => @p.id, :updated_at => Time.now + 200\r
+        nop4 = FactoryGirl.create :original_picture, :artist_id => @artist.id\r
+        @nrp4 = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => nop4.id, :picture_id => @p.id, :updated_at => Time.now + 300\r
+        nop5 = FactoryGirl.create :original_picture, :artist_id => @artist.id\r
+        @nrp5 = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => nop5.id, :picture_id => @p.id, :updated_at => Time.now + 400\r
+        ResourcePicture.stub(:default_page_size).and_return(2)\r
+      end\r
+      it '通常は2件を返す' do\r
+        r = ResourcePicture.list\r
+        r.should have(2).items \r
+      end\r
+      it 'page=1なら末尾2件を返す' do\r
+        #時系列で並んでいる\r
+        r = ResourcePicture.list(1)\r
+        r.should eq [@nrp5, @nrp4]\r
+      end\r
+      it 'page=2なら中間2件を返す' do\r
+        r = ResourcePicture.list(2)\r
+        r.should eq [@nrp3, @nrp2]\r
+      end\r
+      it 'page=3なら先頭1件を返す' do\r
+        r = ResourcePicture.list(3)\r
+        r.should eq [@rp]\r
+      end\r
+    end\r
     context 'DBに5件あって1ページの件数を2件に変えたとして' do
       before do
-        nop2 = Factory :original_picture, :artist_id => @artist.id
-        @nrp2 = Factory :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => nop2.id, :picture_id => @p.id, :updated_at => Time.now + 100
-        nop3 = Factory :original_picture, :artist_id => @artist.id
-        @nrp3 = Factory :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => nop3.id, :picture_id => @p.id, :updated_at => Time.now + 200
-        nop4 = Factory :original_picture, :artist_id => @artist.id
-        @nrp4 = Factory :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => nop4.id, :picture_id => @p.id, :updated_at => Time.now + 300
-        nop5 = Factory :original_picture, :artist_id => @artist.id
-        @nrp5 = Factory :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => nop5.id, :picture_id => @p.id, :updated_at => Time.now + 400
-        ResourcePicture.stub(:default_page_size).and_return(2)
-      end
-      it '通常は2件を返す' do
-        pic = ResourcePicture.list
-        pic.should have(2).items 
-      end
-      it 'page=1なら末尾2件を返す' do
-        #時系列で並んでいる
-        pic = ResourcePicture.list({}, 1)
-        pic.should eq [@nrp5, @nrp4]
-      end
-      it 'page=2なら中間2件を返す' do
-        pic = ResourcePicture.list({}, 2)
-        pic.should eq [@nrp3, @nrp2]
+        nop2 = FactoryGirl.create :original_picture, :artist_id => @artist.id\r
+        @nrp2 = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => nop2.id, :picture_id => @p.id, :updated_at => Time.now + 100\r
+        nop3 = FactoryGirl.create :original_picture, :artist_id => @artist.id\r
+        @nrp3 = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => nop3.id, :picture_id => @p.id, :updated_at => Time.now + 200\r
+        nop4 = FactoryGirl.create :original_picture, :artist_id => @artist.id\r
+        @nrp4 = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => nop4.id, :picture_id => @p.id, :updated_at => Time.now + 300\r
+        nop5 = FactoryGirl.create :original_picture, :artist_id => @artist.id\r
+        @nrp5 = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => nop5.id, :picture_id => @p.id, :updated_at => Time.now + 400\r
+        ResourcePicture.stub(:default_page_size).and_return(2)\r
       end
-      it 'page=3なら先頭1件を返す' do
-        pic = ResourcePicture.list({}, 3)
-        pic.should eq [@rp]
+      it '件数0は全件(5件)を返す' do
+        r = ResourcePicture.list 5, 0
+        r.should have(5).items 
       end
     end
-  end
-  describe 'json一覧出力オプションに於いて' do
-    it 'includeキーがライセンスと絵師を含んでいる' do
-      r = ResourcePicture.list_json_opt
-      r[:include].should eq [:license, :artist]
-    end
   end\r
-  
-  describe 'サイズの調整に於いて' do
-    before do
+  describe '一覧出力オプションに於いて' do\r
+    it 'includeキーを含んでいる' do
+      r = ResourcePicture.list_opt
+      r.has_key?(:include).should be_true
     end
-    
-    it 'サイズに収まるときはそのまま使う' do
-      ResourcePicture.fix_size_both(64, 64, 64, 64).should eq [64, 64]
+    it '3つの項目を含んでいる' do
+      r = ResourcePicture.list_opt[:include]
+      r.should have(3).items
     end
-    it '小さくても拡大しない' do
-      ResourcePicture.fix_size_both(64, 64, 32, 32).should eq [32, 32]
+    it 'ライセンスを含んでいる' do
+      r = ResourcePicture.list_opt[:include]
+      r.has_key?(:license).should be_true
     end
-    it '縦長のときは縦に合わせて縮小' do
-      ResourcePicture.fix_size_both(64, 64, 64, 128).should eq [32, 64]
+    it '絵師を含んでいる' do
+      r = ResourcePicture.list_opt[:include]
+      r.has_key?(:artist).should be_true
     end
-    it '横長のときは横に合わせて縮小' do
-      ResourcePicture.fix_size_both(64, 64, 128, 64).should eq [64, 32]
+    it '実素材を含んでいる' do
+      r = ResourcePicture.list_opt[:include]
+      r.has_key?(:picture).should be_true
     end
-  end
-  \r
-  describe 'フォーマット変換対象判定に於いて' do
-    before do
-      @rp = Factory.build :resource_picture, \r
-        :artist_id => @artist.id, :license_id => @license.id
+  end\r
+  describe 'json一覧出力オプションに於いて' do\r
+    it 'includeキーを含んでいる' do
+      r = ResourcePicture.list_json_opt
+      r.has_key?(:include).should be_true
     end
-    context '変換するケース' do\r
-      it '画像フォーマットがpngかつライセンスの変換禁止フラグが無効のときTrue' do\r
-        ResourcePicture.any_instance.stub(:flag_gif_convert).with(any_args).and_return(0)
-        @rp.ext = 'png'\r
-        @rp.to_gif?.should be_true
-      end
+    it '3つの項目を含んでいる' do
+      r = ResourcePicture.list_json_opt[:include]
+      r.should have(3).items
     end
-    context '変換しないケース' do
-      it '画像フォーマットがでない' do\r
-        ResourcePicture.any_instance.stub(:flag_gif_convert).with(any_args).and_return(0)
-        @rp.ext = 'gif'\r
-        @rp.to_gif?.should be_false
-      end
-      it '変換禁止フラグが無効' do\r
-        ResourcePicture.any_instance.stub(:flag_gif_convert).with(any_args).and_return(-1)
-        @rp.ext = 'png'\r
-        @rp.to_gif?.should be_false
-      end
+    it 'ライセンスを含んでいる' do
+      r = ResourcePicture.list_json_opt[:include]
+      r.has_key?(:license).should be_true
     end
-  end
-  
-  describe 'Gifフォーマット変換に於いて' do
-    before do
-      Magick::Image.stub(:from_blob).with(any_args).and_return([Mgk.new])
+    it '絵師を含んでいる' do
+      r = ResourcePicture.list_json_opt[:include]
+      r.has_key?(:artist).should be_true
+    end
+    it '実素材を含んでいる' do
+      r = ResourcePicture.list_json_opt[:include]
+      r.has_key?(:picture).should be_true
     end
+  end\r
+  \r
+  describe '単体取得に於いて' do\r
+    before do\r
+      @op = FactoryGirl.create :original_picture, :artist_id => @artist.id\r
+      @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id\r
+      @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :original_picture_id => @op.id, :license_id => @license.id, :picture_id => @p.id\r
+    end\r
     context 'つつがなく終わるとき' do
-      it 'Mgkオブジェクトが返る' do
-        mgk = ResourcePicture.png_to_gif('mgkbin')\r
-        mgk.is_a?(Mgk).should be_true
+      it '単体取得オプションを利用している' do
+        ResourcePicture.stub(:show_opt).with(any_args).and_return({})
+        ResourcePicture.should_receive(:show_opt).with(any_args).exactly(1)
+        r = ResourcePicture.show @rp.id, @author
       end
-      it 'Mgkオブジェクトはgif変換されている' do\r
-        #スタブばかりで変換できないので代入されているかでチェックする
-        Mgk.any_instance.should_receive(:format=).with('gif').exactly(1)
-        ResourcePicture.png_to_gif('mgkbin')\r
+      it '閲覧許可を問い合わせている' do
+        ResourcePicture.any_instance.stub(:visible?).with(any_args).and_return(true)
+        ResourcePicture.any_instance.should_receive(:visible?).with(any_args).exactly(1)
+        r = ResourcePicture.show @rp.id, @author
       end
     end
-    context 'RMagick変換が失敗したとき' do
-      before do
-        Magick::Image.should_receive(:from_blob).with(any_args).and_raise('StandardError')
-      end
-      it 'falseを返す' do
-        res = ResourcePicture.png_to_gif('mgkbin')\r
-        res.should be_false\r
+    it '指定の素材を返す' do\r
+      r = ResourcePicture.show @rp.id, @author\r
+      r.should eq @rp\r
+    end\r
+    context '他人の素材を開こうとしたとき' do
+      it '403Forbidden例外を返す' do
+        ResourcePicture.any_instance.stub(:visible?).and_return(false)
+        lambda{
+          r = ResourcePicture.show @rp.id, @other_author
+        }.should raise_error(ActiveRecord::Forbidden)
       end
     end
-  end
-  
-  describe '原画からのコピーデータセットに於いて' do
-    before do\r
-      @op = Factory :original_picture, :ext => 'jpeg', :width => 264, :height => 265, :filesize => 266, \r
-        :artist_id => @artist.id
-      @rp = Factory.build :resource_picture, \r
-        :artist_id => @artist.id
-    end
-    it '原画オブジェクトから属性を取り出して対象素材にセットしている' do
-      res = @rp.copy_data(@op)\r
-      @rp.ext.should eq 'jpeg'\r
-      @rp.width.should eq 264\r
-      @rp.height.should eq 265\r
-      @rp.filesize.should eq 266\r
-      @rp.artist_id.should eq @artist.id\r
+    context '存在しない素材を開こうとしたとき' do\r
+      it '404RecordNotFound例外を返す' do\r
+        lambda{\r
+          r = ResourcePicture.show 0, @author\r
+        }.should raise_error(ActiveRecord::RecordNotFound)\r
+      end\r
     end\r
-  end
-  
-  describe 'RMagick変換に於いて' do
-    before do
-      @op = Factory :original_picture, :artist_id => @artist.id
-      @p = Factory :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
-      attr = {:original_picture_id => @op.id, :license_id => @license.id, :artist_name => 'tester', :credit => '{}', :settings => {}.to_json.to_s}\r
-      @rp = Factory.build :resource_picture, attr
+  end\r
+  describe '単体出力オプションに於いて' do\r
+    it 'includeキーを含んでいる' do
+      r = ResourcePicture.show_opt
+      r.has_key?(:include).should be_true
     end
-    context 'つつがなく終わるとき' do
-      it '画像データをオブジェクト化している' do
-        Magick::Image.stub(:from_blob).and_return(['mgkobj'])
-        @rp.data_to_mgk('mgkbin').should eq 'mgkobj'
-      end
+    it '3つの項目を含んでいる' do
+      r = ResourcePicture.show_opt[:include]
+      r.should have(3).items
     end
-    context '失敗するとき' do
-      it 'Falseを返す' do
-        Magick::Image.should_receive(:from_blob).with(any_args).and_raise('StandardError')
-        @rp.data_to_mgk('mgkbin').should be_false
-      end
-      it '全体エラーがセットされている' do
-        Magick::Image.should_receive(:from_blob).with(any_args).and_raise('StandardError')
-        lambda {
-          @rp.data_to_mgk('mgkbin')
-        }.should change(@rp.errors[:base], :count)
-      end
+    it 'ライセンスを含んでいる' do
+      r = ResourcePicture.show_opt[:include]
+      r.has_key?(:license).should be_true
     end
-  end
-  describe '画像オブジェクトの取得に於いて' do
-    before do
-      @op = Factory :original_picture, :artist_id => @artist.id
-      @p = Factory :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
-      attr = {:original_picture_id => @op.id, :license_id => @license.id, :artist_name => 'tester', :credit => '{}', :settings => {}.to_json.to_s}\r
-      @rp = Factory.build :resource_picture, attr
+    it '絵師を含んでいる' do
+      r = ResourcePicture.show_opt[:include]
+      r.has_key?(:artist).should be_true
     end
-    context '事前チェック' do
-      before do
-        OriginalPicture.any_instance.stub(:restore).with(any_args).and_return('data')\r
-        ResourcePicture.any_instance.stub(:data_to_mgk).with(any_args).and_return(Mgk.new)
-      end
-      it '原画から画像データを取得している' do
-        OriginalPicture.any_instance.should_receive(:restore).with(any_args).exactly(1)
-        res = @rp.op_mgk\r
-      end\r
-      it '素材に原画データのRMagick変換を依頼している' do
-        ResourcePicture.any_instance.should_receive(:data_to_mgk).with(any_args).exactly(1)
-        res = @rp.op_mgk\r
+    it '実素材を含んでいる' do
+      r = ResourcePicture.show_opt[:include]
+      r.has_key?(:picture).should be_true
+    end
+  end\r
+  describe 'json単体出力オプションに於いて' do\r
+    it 'includeキーを含んでいる' do
+      r = ResourcePicture.show_json_opt
+      r.has_key?(:include).should be_true
+    end
+    it '3つの項目を含んでいる' do
+      r = ResourcePicture.show_json_opt[:include]
+      r.should have(3).items
+    end
+    it 'ライセンスを含んでいる' do
+      r = ResourcePicture.show_json_opt[:include]
+      r.has_key?(:license).should be_true
+    end
+    it '絵師を含んでいる' do
+      r = ResourcePicture.show_json_opt[:include]
+      r.has_key?(:artist).should be_true
+    end
+    it '実素材を含んでいる' do
+      r = ResourcePicture.show_json_opt[:include]
+      r.has_key?(:picture).should be_true
+    end
+  end\r
+  \r
+  describe 'フォーマット変換対象判定に於いて' do\r
+    before do\r
+      @rp = FactoryGirl.build :resource_picture, \r
+        :artist_id => @artist.id, :license_id => @license.id\r
+    end\r
+    context '変換するケース' do\r
+      it '画像フォーマットがpngかつライセンスの変換禁止フラグが無効のときTrue' do\r
+        ResourcePicture.any_instance.stub(:flag_gif_convert).with(any_args).and_return(0)\r
+        @rp.ext = 'png'\r
+        @rp.to_gif?.should be_true\r
       end\r
     end\r
-    context 'つつがなく終わるとき' do
-      #原画から画像データを取得する。\r
-      #素材に原画データのRMagick変換を依頼し、画像オブジェクトを返す。 \r
-      before do
-        @mgk = Mgk.new\r
-        OriginalPicture.any_instance.stub(:restore).with(any_args).and_return('data')\r
-        ResourcePicture.any_instance.stub(:data_to_mgk).with(any_args).and_return(@mgk)
-      end
-      it '画像オブジェクトを返す' do
-        res = @rp.op_mgk\r
-        res.should eq @mgk\r
+    context '変換しないケース' do\r
+      it '画像フォーマットがでない' do\r
+        ResourcePicture.any_instance.stub(:flag_gif_convert).with(any_args).and_return(0)\r
+        @rp.ext = 'gif'\r
+        @rp.to_gif?.should be_false\r
+      end\r
+      it '変換禁止フラグが無効' do\r
+        ResourcePicture.any_instance.stub(:flag_gif_convert).with(any_args).and_return(-1)\r
+        @rp.ext = 'png'\r
+        @rp.to_gif?.should be_false\r
       end\r
     end\r
-  end
-  
-  describe '新規実素材の取得に於いて' do
-    before do
-      @op = Factory :original_picture, :artist_id => @artist.id
-      @p = Factory :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
+  end\r
+  \r
+  describe '新規実素材の取得に於いて' do\r
+    before do\r
+      @op = FactoryGirl.create :original_picture, :artist_id => @artist.id\r
+      @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id\r
       attr = {:original_picture_id => @op.id, :license_id => @license.id, :artist_name => 'tester', \r
         :credit => '{}', :settings => {:reverse => 1, :gif_convert => 1}.to_json.to_s}\r
-      @rp = Factory.build :resource_picture, attr
-      @mgk = Mgk.new
-    end
-    context '事前チェック' do
-      before do
-        Picture.any_instance.stub(:copy_data).with(any_args).and_return(true)\r
+      @rp = FactoryGirl.build :resource_picture, attr\r
+      @imager = ImagerTest.load "abc\ndef\nghi"
+    end\r
+    context '事前チェック' do\r
+      before do\r
         Picture.any_instance.stub(:store).with(any_args).and_return(true)\r
-      end
-      it '実素材に原画からのコピーデータを依頼している' do
-        Picture.any_instance.should_receive(:copy_data).with(any_args).exactly(1)
-        res = @rp.new_picture @mgk\r
       end\r
-      it 'å®\9fç´ æ\9d\90ã\82\92ä¿\9då­\98ã\81\97ã\81¦ã\81\84ã\82\8b' do
-        Picture.any_instance.should_receive(:store).with(any_args).exactly(1)
-        res = @rp.new_picture @mgk\r
+      it 'å®\9fç´ æ\9d\90ã\83¢ã\83\87ã\83«ã\81«ã\83\87ã\83\95ã\82©ã\83«ã\83\88å\80¤è£\9cå\85\85ã\82\92ä¾\9dé ¼ã\81\97ã\81¦ã\81\84ã\82\8b' do\r
+        Picture.any_instance.should_receive(:supply_default).with(any_args).exactly(1)\r
+        r = @rp.new_picture @imager\r
       end\r
-    end
-    context 'つつがなく終わるとき' do
-      it '実素材に原画からのコピーデータをセットしている' do
-        res = @rp.new_picture @mgk\r
-        @rp.ext.should eq @op.ext\r
-        @rp.width.should eq @op.width\r
-        @rp.height.should eq @op.height\r
-        @rp.filesize.should eq @op.filesize\r
-        @rp.artist_id.should eq @op.artist_id\r
-        @rp.original_picture_id.should eq @op.id\r
+      it '実素材モデルに上書き補充を依頼している' do\r
+        Picture.any_instance.should_receive(:overwrite).with(any_args).exactly(1)\r
+        r = @rp.new_picture @imager\r
       end\r
-      it '実素材を返す' do
-        res = @rp.new_picture @mgk\r
-        res.is_a?(Picture).should be_true\r
+      it '実素材を保存している' do\r
+        Picture.any_instance.should_receive(:store).with(any_args).exactly(1)\r
+        r = @rp.new_picture @imager\r
       end\r
-    end
-  end
-  
-  describe '作成・更新に於いて' do
-    before do
-      @op = Factory :original_picture, :artist_id => @artist.id
-      @p = Factory :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
-      attr = {:original_picture_id => @op.id, :license_id => @license.id, :artist_name => 'tester', :credit => '{}', :settings => {}.to_json.to_s}\r
-      @rp = Factory.build :resource_picture, attr
-    end
-    context '事前チェック' do
-      before do
-        #すべての処理が正常パターンで通過すれば、一番深い分岐まで通る。
-        #それで外部のメソッド呼び出しだけに着目してテストする。
-        @mgk = Mgk.new   #一回目の本画像保存は与えたオブジェクトを使って保存する。
-        ResourcePicture.any_instance.stub(:op_mgk).with(any_args).and_return(@mgk)\r
+    end\r
+    context 'つつがなく終わるとき' do\r
+      it '保存された実素材を返す' do\r
+        r = @rp.new_picture @imager\r
+        r.is_a?(Picture).should be_true\r
+      end\r
+    end\r
+    #以下から例外ケース。処理先頭から失敗させていく\r
+    context '実素材の保存に失敗したとき' do\r
+      before do\r
+        Picture.any_instance.stub(:store).with(any_args).and_return(false)\r
+      end\r
+      it 'Falseを返す' do\r
+        r = @rp.new_picture @imager\r
+        r.should be_false\r
+      end\r
+      it '自身の全体エラーメッセージにその旨をセットしている' do\r
+        r = @rp.new_picture @imager\r
+        @rp.errors[:base].should_not be_empty\r
+      end\r
+    end\r
+  end\r
+  \r
+  describe '作成・更新に於いて' do\r
+    before do\r
+      @op = FactoryGirl.create :original_picture, :artist_id => @artist.id\r
+      @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id\r
+      attr = {:original_picture_id => @op.id, :picture_id => nil, :license_id => @license.id, :artist_name => 'tester', :classname => 'StandardLicense', :credit => '{}', :settings => {}.to_json.to_s}\r
+      @rp = FactoryGirl.build :resource_picture, attr\r
+      @imager = ImagerTest.load "abc\ndef\nghi"
+    end\r
+    context '事前チェック' do\r
+      before do\r
+        #すべての処理が正常パターンで通過すれば、一番深い分岐まで通る。\r
+        #それで外部のメソッド呼び出しだけに着目してテストする。\r
         ResourcePicture.any_instance.stub(:new_picture).with(any_args).and_return(@p)\r
         ResourcePicture.any_instance.stub(:store_picture_with_gif).with(any_args).and_return(true)\r
-      end
-      it '素材に原画からのコピーデータをセットしている' do
-        ResourcePicture.any_instance.stub(:copy_data).with(any_args).and_return(true)\r
-        ResourcePicture.any_instance.should_receive(:copy_data).with(any_args).exactly(1)
-        res = @rp.store\r
-      end\r
-      it '画像オブジェクトの取得を依頼している' do
-        ResourcePicture.any_instance.should_receive(:op_mgk).with(any_args).exactly(1)
-        res = @rp.store\r
       end\r
-      it '新規実素材の取得を依頼している' do
-        ResourcePicture.any_instance.should_receive(:new_picture).with(any_args).exactly(1)
-        res = @rp.store\r
+      it '新規実素材の取得を依頼している' do\r
+        ResourcePicture.any_instance.should_receive(:new_picture).with(any_args).exactly(1)\r
+        r = @rp.store @imager\r
       end\r
-      it '自身を保存している' do
-        ResourcePicture.any_instance.should_receive(:save).with(any_args).exactly(1)
-        res = @rp.store\r
+      it '自身を保存している' do\r
+        ResourcePicture.any_instance.should_receive(:save).with(any_args).exactly(1)\r
+        r = @rp.store @imager\r
       end\r
-      it '画像ファイルの作成・更新機能で画像を保存している' do\r
-        ResourcePicture.any_instance.should_receive(:store_picture_with_gif).with(@mgk).exactly(1)
-        res = @rp.store\r
+      it 'gif付き画像ファイルの作成・更新機能で画像を保存している' do\r
+        ResourcePicture.any_instance.should_receive(:store_picture_with_gif).with(@imager).exactly(1)\r
+        r = @rp.store @imager\r
       end\r
-    end
-    context 'つつがなく終わるとき' do
-      before do
-        #すべての処理を正常パターンで通過させ、保存機能をチェックする。
-        @mgk = Mgk.new   #一回目の本画像保存は与えたオブジェクトを使って保存する。
-        ResourcePicture.any_instance.stub(:op_mgk).with(any_args).and_return(@mgk)\r
+    end\r
+    context 'つつがなく終わるとき' do\r
+      before do\r
+        #すべての処理を正常パターンで通過させ、保存機能をチェックする。\r
         ResourcePicture.any_instance.stub(:new_picture).with(any_args).and_return(@p)\r
-        ResourcePicture.any_instance.stub(:store_picture_with_gif).with(any_args).and_return(true)\r
-      end
-      it 'Trueを返す' do
-        res = @rp.store\r
-        res.should be_true\r
+        ResourcePicture.any_instance.stub(:store_picture_with_gif).with(@imager).and_return(true)\r
       end\r
-      it '実素材idをセットしている' do
-        res = @rp.store\r
-        @rp.picture_id.should_not be_nil\r
+      it 'Trueを返す' do\r
+        r = @rp.store @imager\r
+        r.should be_true\r
       end\r
-      it '実素材idから最新画像idを取得してセットしている' do
-        res = @rp.store\r
+      it '実素材idから最新画像idを取得してセットしている' do\r
+        r = @rp.store @imager\r
         @rp.picture_id.should eq @p.id\r
       end\r
       it '自身が保存されている' do\r
-        lambda {
-          res = @rp.store\r
+        lambda {\r
+          r = @rp.store @imager\r
         }.should change ResourcePicture, :count\r
       end\r
-    end
-    #以下から例外ケース。処理先頭から失敗させていく
-    context '画像オブジェクトの取得に失敗したとき' do
-      before do
-        ResourcePicture.any_instance.stub(:op_mgk).with(any_args).and_return(false)\r
-      end
-      it 'Falseを返す' do
-        res = @rp.store\r
-        res.should be_false\r
+    end\r
+    #以下から例外ケース。処理先頭から失敗させていく\r
+    context '画像オブジェクトの取得に失敗したとき' do\r
+      before do\r
+        @imager = false\r
+      end\r
+      it 'Falseを返す' do\r
+        r = @rp.store @imager\r
+        r.should be_false\r
       end\r
-      it '更新されていない' do
-        @rp.store
+      it '更新されていない' do\r
+        r = @rp.store @imager\r
         @rp.should be_a_new ResourcePicture\r
-      end
-    end
-    context '新規実素材の取得に失敗したとき' do
-      before do
-        @mgk = Mgk.new   #一回目の本画像保存は与えたオブジェクトを使って保存する。
-        ResourcePicture.any_instance.stub(:op_mgk).with(any_args).and_return(@mgk)\r
-        ResourcePicture.any_instance.stub(:new_picture).with(any_args).and_return(@p)\r
-        Picture.any_instance.stub(:valid?).with(any_args).and_return(false)\r
-      end
-      it 'Falseを返す' do
-        res = @rp.store\r
-        res.should be_false\r
       end\r
-      it '更新されていない' do
-        @rp.store
+      it '処理を中断してロールバックする' do\r
+        lambda {\r
+          r = @rp.store @imager\r
+        }.should_not change Picture, :count\r
+      end\r
+    end\r
+    context '新規実素材の取得に失敗したとき' do\r
+      before do\r
+        ResourcePicture.any_instance.stub(:new_picture).with(any_args).and_return(false)\r
+      end\r
+      it 'Falseを返す' do\r
+        r = @rp.store @imager\r
+        r.should be_false\r
+      end\r
+      it '更新されていない' do\r
+        r = @rp.store @imager\r
         @rp.should be_a_new ResourcePicture\r
-      end
-    end
-    context '自身の保存に失敗したとき' do
-      before do
-        @mgk = Mgk.new   #一回目の本画像保存は与えたオブジェクトを使って保存する。
-        ResourcePicture.any_instance.stub(:op_mgk).with(any_args).and_return(@mgk)\r
+      end\r
+      it '処理を中断してロールバックする' do\r
+        lambda {\r
+          r = @rp.store @imager\r
+        }.should_not change Picture, :count\r
+      end\r
+    end\r
+    context '自身の保存に失敗したとき' do\r
+      before do\r
         ResourcePicture.any_instance.stub(:new_picture).with(any_args).and_return(@p)\r
         ResourcePicture.any_instance.stub(:save).with(any_args).and_return(false)\r
-      end
-      it 'Falseを返す' do
-        res = @rp.store\r
-        res.should be_false\r
       end\r
-      it '更新されていない' do
-        @rp.store
+      it 'Falseを返す' do\r
+        r = @rp.store @imager\r
+        r.should be_false\r
+      end\r
+      it '更新されていない' do\r
+        r = @rp.store @imager\r
         @rp.should be_a_new ResourcePicture\r
-      end
-      it '処理を中断してロールバックする' do
-        lambda {
-          res = @rp.store\r
+      end\r
+      it '処理を中断してロールバックする' do\r
+        lambda {\r
+          r = @rp.store @imager\r
         }.should_not change Picture, :count\r
-      end
-    end
+      end\r
+    end\r
+    context 'gif付き画像ファイルの作成・更新機能に失敗したとき' do\r
+      before do\r
+        ResourcePicture.any_instance.stub(:new_picture).with(any_args).and_return(@p)\r
+        ResourcePicture.any_instance.stub(:store_picture_with_gif).with(any_args).and_return(false)\r
+      end\r
+      it 'Falseを返す' do\r
+        r = @rp.store @imager\r
+        r.should be_false\r
+      end\r
+      it '更新されていない' do\r
+        r = @rp.store @imager\r
+        @rp.should be_a_new ResourcePicture\r
+      end\r
+      it '処理を中断してロールバックする' do\r
+        lambda {\r
+          r = @rp.store @imager\r
+        }.should_not change Picture, :count\r
+      end\r
+    end\r
   end\r
-  
-  describe '画像ファイルの作成・更新に於いて' do\r
-    before do
-      @op = Factory :original_picture, :artist_id => @artist.id
-      @p = Factory :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
+  \r
+  describe 'gif付き画像ファイルの作成・更新に於いて' do\r
+    before do\r
+      @op = FactoryGirl.create :original_picture, :artist_id => @artist.id\r
+      @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id\r
       attr = {:original_picture_id => @op.id, :license_id => @license.id, :artist_name => 'tester', :credit => '{}', :settings => {}.to_json.to_s}\r
-      @rp = Factory.build :resource_picture, attr
-    end
-    context '事前チェック' do
-      before do
-        #すべての処理が正常パターンで通過すれば、一番深い分岐まで通る。
-        #ã\81\9dã\82\8cã\81§å¤\96é\83¨ã\81®ã\83¡ã\82½ã\83\83ã\83\89å\91¼ã\81³å\87ºã\81\97ã\81 ã\81\91ã\81«ç\9d\80ç\9b®ã\81\97ã\81¦ã\83\86ã\82¹ã\83\88ã\81\99ã\82\8bã\80\82
-        @mgk = Mgk.new   #一回目の本画像保存は与えたオブジェクトを使って保存する。
+      @rp = FactoryGirl.build :resource_picture, attr\r
+      @imager = ImagerTest.load "abc\ndef\nghi"
+    end\r
+    context '事前チェック' do\r
+      before do\r
+        #ã\81\99ã\81¹ã\81¦ã\81®å\87¦ç\90\86ã\81\8c正常ã\83\91ã\82¿ã\83¼ã\83³ã\81§é\80\9aé\81\8eã\81\99ã\82\8cã\81°ã\80\81ä¸\80ç\95ªæ·±ã\81\84å\88\86å²\90ã\81¾ã\81§é\80\9aã\82\8bã\80\82\r
+        #それで外部のメソッド呼び出しだけに着目してテストする。\r
         ResourcePicture.any_instance.stub(:store_picture).with(any_args).and_return(true)\r
         ResourcePicture.any_instance.stub(:to_gif?).with(any_args).and_return(true)\r
-        class GifMgk < Mgk ; end  #store_pictureは二回呼び出される。区別をつけるために\r
-        @gifmgk = GifMgk.new      #パラメータを二種類用意する。\r
-        ResourcePicture.stub(:png_to_gif).with(any_args).and_return(@gifmgk)
-      end
-      it '画像ファイルの作成・更新機能で画像を保存している' do\r
-        ResourcePicture.any_instance.should_receive(:store_picture).with(@mgk).exactly(1)
-        res = @rp.store_picture_with_gif @mgk\r
+        ResourcePicture.any_instance.stub(:filename).with(any_args).and_return('1.png')\r
+        ResourcePicture.any_instance.stub(:gifname).with(any_args).and_return('1.gif')\r
       end\r
-      it '自身にフォーマット変換対象かを問い合わせている' do
-        ResourcePicture.any_instance.should_receive(:to_gif?).with(any_args).exactly(1)
-        res = @rp.store_picture_with_gif @mgk\r
+      it '画像ファイルの作成・更新機能で画像を保存している' do\r
+        #二回目の保存はgif変換の結果を渡す。\r
+        ResourcePicture.any_instance.should_receive(:store_picture).with(any_args).exactly(2)\r
+        r = @rp.store_picture_with_gif @imager\r
       end\r
-      it '自身にGifフォーマット変換を依頼している' do
-        ResourcePicture.should_receive(:png_to_gif).with(any_args).exactly(1)
-        res = @rp.store_picture_with_gif @mgk\r
+      it '自身にフォーマット変換対象かを問い合わせている' do\r
+        ResourcePicture.any_instance.should_receive(:to_gif?).with(any_args).exactly(1)\r
+        r = @rp.store_picture_with_gif @imager\r
       end\r
-      it '画像ファイルの作成・更新機能でgif画像を保存している' do\r
-        #二回目の保存はgif変換の結果を渡す。
-        ResourcePicture.any_instance.should_receive(:store_picture).with(@gifmgk).exactly(1)
-        res = @rp.store_picture_with_gif @mgk\r
+      it '画像ライブラリにGifフォーマット変換を依頼している' do\r
+        ImagerTest.any_instance.should_receive(:to_gif).with(any_args).exactly(1)\r
+        r = @rp.store_picture_with_gif @imager\r
       end\r
-    end
-    context 'つつがなく終わるとき' do
-      before do
-        #すべての処理を正常パターンで通過させ、保存機能をチェックする。
-        @mgk = Mgk.new   #一回目の本画像保存は与えたオブジェクトを使って保存する。
+    end\r
+    context 'つつがなく終わるとき' do\r
+      before do\r
+        #すべての処理を正常パターンで通過させ、保存機能をチェックする。\r
         ResourcePicture.any_instance.stub(:store_picture).with(any_args).and_return(true)\r
         ResourcePicture.any_instance.stub(:to_gif?).with(any_args).and_return(true)\r
-        class GifMgk < Mgk ; end  #store_pictureは二回呼び出される。区別をつけるために\r
-        @gifmgk = GifMgk.new      #パラメータを二種類用意する。\r
-        ResourcePicture.stub(:png_to_gif).with(any_args).and_return(@gifmgk)
-      end
-      it 'Trueを返す' do
-        res = @rp.store_picture_with_gif @mgk\r
-        res.should be_true\r
+        ResourcePicture.any_instance.stub(:filename).with(any_args).and_return('1.png')\r
+        ResourcePicture.any_instance.stub(:gifname).with(any_args).and_return('1.gif')\r
       end\r
-    end
-    context 'gif変換なしで、つつがなく終わるとき' do
-      before do
-        #すべての処理を正常パターンで通過させ、保存機能をチェックする。
-        @mgk = Mgk.new   #一回目の本画像保存は与えたオブジェクトを使って保存する。
+      it 'Trueを返す' do\r
+        r = @rp.store_picture_with_gif @imager\r
+        r.should be_true\r
+      end\r
+    end\r
+    context 'gif変換なしで、つつがなく終わるとき' do\r
+      before do\r
+        #すべての処理を正常パターンで通過させ、保存機能をチェックする。\r
         ResourcePicture.any_instance.stub(:store_picture).with(any_args).and_return(true)\r
         ResourcePicture.any_instance.stub(:to_gif?).with(any_args).and_return(false)\r
-      end
-      it 'Trueを返す' do
-        res = @rp.store_picture_with_gif @mgk\r
-        res.should be_true\r
+        ResourcePicture.any_instance.stub(:filename).with(any_args).and_return('1.png')\r
+        ResourcePicture.any_instance.stub(:gifname).with(any_args).and_return('1.gif')\r
+      end\r
+      it 'Trueを返す' do\r
+        r = @rp.store_picture_with_gif @imager\r
+        r.should be_true\r
       end\r
       it 'gif保存は呼ばれていない' do\r
-        ResourcePicture.any_instance.should_receive(:store_picture).with(any_args).exactly(1)
-        res = @rp.store_picture_with_gif @mgk\r
+        ResourcePicture.any_instance.should_receive(:store_picture).with(any_args).exactly(1)\r
+        r = @rp.store_picture_with_gif @imager\r
       end\r
-    end
-    #以下から例外ケース。処理先頭から失敗させていく
-    context '画像の保存に失敗したとき' do
-      before do
-        @mgk = Mgk.new   #一回目の本画像保存は与えたオブジェクトを使って保存する。
+    end\r
+    #以下から例外ケース。処理先頭から失敗させていく\r
+    context '画像の保存に失敗したとき' do\r
+      before do\r
         ResourcePicture.any_instance.stub(:store_picture).with(any_args).and_return(false)\r
-      end
-      it 'Falseを返す' do
-        res = @rp.store_picture_with_gif @mgk\r
-        res.should be_false\r
+      end\r
+      it 'Falseを返す' do\r
+        r = @rp.store_picture_with_gif @imager\r
+        r.should be_false\r
       end\r
       it 'gif変換判定は呼ばれていない' do\r
-        ResourcePicture.any_instance.should_not_receive(:to_gif?).with(any_args)
-        res = @rp.store_picture_with_gif @mgk\r
+        ResourcePicture.any_instance.should_not_receive(:to_gif?).with(any_args)\r
+        r = @rp.store_picture_with_gif @imager\r
       end\r
-    end
-    context 'gif変換に失敗したとき' do
-      before do
-        @mgk = Mgk.new   #一回目の本画像保存は与えたオブジェクトを使って保存する。
+    end\r
+    context 'gif変換に失敗したとき' do\r
+      before do\r
         ResourcePicture.any_instance.stub(:store_picture).with(any_args).and_return(true)\r
         ResourcePicture.any_instance.stub(:to_gif?).with(any_args).and_return(true)\r
-        ResourcePicture.stub(:png_to_gif).with(any_args).and_return(false)
-      end
-      it 'Falseを返す' do
-        res = @rp.store_picture_with_gif @mgk\r
-        res.should be_false\r
+        ImagerTest.any_instance.stub(:to_gif).with(any_args).and_return(false)\r
+      end\r
+      it 'Falseを返す' do\r
+        r = @rp.store_picture_with_gif @imager\r
+        r.should be_false\r
       end\r
       it 'gif画像の保存は呼ばれていない' do\r
         #本画像の保存があるので、一度は呼ばれる\r
-        ResourcePicture.any_instance.should_receive(:store_picture).with(any_args).exactly(1)
-        res = @rp.store_picture_with_gif @mgk\r
+        ResourcePicture.any_instance.should_receive(:store_picture).with(any_args).exactly(1)\r
+        r = @rp.store_picture_with_gif @imager\r
       end\r
-    end
-    context 'gif画像の保存に失敗したとき' do
+    end\r
+    context 'gif画像の保存に失敗したとき' do\r
       before do\r
-        @mgk = Mgk.new
-        ResourcePicture.any_instance.stub(:store_picture).with(@mgk).and_return(true)\r
+        ResourcePicture.any_instance.stub(:store_picture).with(@imager, '1.png').and_return(true)\r
         ResourcePicture.any_instance.stub(:to_gif?).with(any_args).and_return(true)\r
-        class GifMgk < Mgk ; end  #store_pictureは二回呼び出される。区別をつけるために\r
-        @gifmgk = GifMgk.new      #パラメータを二種類用意する。\r
-        ResourcePicture.stub(:png_to_gif).with(any_args).and_return(@gifmgk)
-        ResourcePicture.any_instance.stub(:store_picture).with(@gifmgk).and_return(false)\r
-      end
-      it 'Falseを返す' do
-        res = @rp.store_picture_with_gif @mgk\r
-        res.should be_false\r
+        @gifimager = @imager.to_gif\r
+        ImagerTest.any_instance.stub(:to_gif).with(any_args).and_return(@gifimager)\r
+        ResourcePicture.any_instance.stub(:store_picture).with(@gifimager, '1.gif').and_return(false)\r
+        ResourcePicture.any_instance.stub(:filename).with(any_args).and_return('1.png')\r
+        ResourcePicture.any_instance.stub(:gifname).with(any_args).and_return('1.gif')\r
       end\r
-    end
+      it 'Falseを返す' do\r
+        r = @rp.store_picture_with_gif @imager\r
+        r.should be_false\r
+      end\r
+    end\r
   end\r
-  
+  \r
   describe '画像ファイルの作成・更新に於いて' do\r
     #PictureIo経由で画像を保存するための機能。ファイル名に自身のidを使うので事前に自身の保存が必要。\r
-    before do
-      @op = Factory :original_picture, :artist_id => @artist.id
-      @p = Factory :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
+    before do\r
+      @op = FactoryGirl.create :original_picture, :artist_id => @artist.id\r
+      @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id\r
       attr = {:original_picture_id => @op.id, :license_id => @license.id, :artist_name => 'tester', :credit => '{}', :settings => {}.to_json.to_s}\r
-      @rp = Factory.build :resource_picture, attr\r
-      @rp.copy_data @op
-    end
-    context '事前チェック' do
-      before do
-        #すべての処理を正常パターンで通過させ、保存機能をチェックする。
-        PictureIO.resource_picture_io.stub(:put).with(any_args).and_return(true)
-        ResourcePicture.any_instance.stub(:flag_thumbnail).with(any_args).and_return(1)
-        ResourcePicture.any_instance.stub(:thumbnail).with(any_args).and_return('tmbdata')
-      end
+      @rp = FactoryGirl.build :resource_picture, attr\r
+      @rp.overwrite @op\r
+      @imager = ImagerTest.load "abc\ndef\nghi"
+    end\r
+    context '事前チェック' do\r
+      before do\r
+        #すべての処理を正常パターンで通過させ、保存機能をチェックする。\r
+        PictureIO.resource_picture_io.stub(:put).with(any_args).and_return(true)\r
+        ResourcePicture.any_instance.stub(:flag_thumbnail).with(any_args).and_return(1)\r
+      end\r
       it 'サムネイル化が1回呼ばれる' do\r
-        ResourcePicture.any_instance.should_receive(:thumbnail).with(any_args).exactly(1)
-        res = @rp.store_picture(Mgk.new)\r
+        ImagerTest.any_instance.should_receive(:to_thumbnail).with(any_args).exactly(1)\r
+        r = @rp.store_picture(@imager, '1.png')\r
       end\r
       it '画像ファイルの保存が2回呼ばれる' do\r
-        PictureIO.resource_picture_io.should_receive(:put).with(any_args).exactly(2)
-        res = @rp.store_picture(Mgk.new)\r
+        PictureIO.resource_picture_io.should_receive(:put).with(any_args).exactly(2)\r
+        r = @rp.store_picture(@imager, '1.gif')\r
       end\r
       it '画像ファイルのベースへのサムネイル保存が1回呼ばれる' do\r
-        PictureIO.resource_picture_io.should_receive(:put).with('tmbdata', @rp.filename).exactly(1)
-        res = @rp.store_picture(Mgk.new)\r
+        PictureIO.resource_picture_io.should_receive(:put).with(@imager.to_thumbnail.binary, '1.gif').exactly(1)\r
+        r = @rp.store_picture(@imager, '1.gif')\r
       end\r
       it '画像ファイルのfullへの保存が1回呼ばれる' do\r
-        PictureIO.resource_picture_io.should_receive(:put).with('data', @rp.filename, 'full').exactly(1)
-        res = @rp.store_picture(Mgk.new)\r
+        PictureIO.resource_picture_io.should_receive(:put).with(@imager.binary, '1.gif', 'full').exactly(1)\r
+        r = @rp.store_picture(@imager, '1.gif')\r
       end\r
-    end
-    context 'つつがなく終わるとき' do
-      before do
+    end\r
+    context 'つつがなく終わるとき' do\r
+      before do\r
         #すべての処理を正常パターンで通過させ、保存機能をチェックする。\r
-        PictureIO.resource_picture_io.stub(:put).with(any_args).and_return(true)
-        ResourcePicture.any_instance.stub(:flag_thumbnail).with(any_args).and_return(1)
-      end
-      it 'Trueを返す' do
-        res = @rp.store_picture(Mgk.new)\r
-        res.should be_true\r
+        PictureIO.resource_picture_io.stub(:put).with(any_args).and_return(true)\r
+        ResourcePicture.any_instance.stub(:flag_thumbnail).with(any_args).and_return(1)\r
       end\r
-    end
-    context '例外ケース' do
-      before do
-        ResourcePicture.any_instance.stub(:flag_thumbnail).with(any_args).and_return(1)
-        PictureIO.resource_picture_io.stub(:put).with(any_args).and_return(false)
-      end
-      it 'Falseを返す' do
-        res = @rp.store_picture(Mgk.new)\r
-        res.should be_false\r
+      it 'Trueを返す' do\r
+        r = @rp.store_picture(@imager, '1.gif')\r
+        r.should be_true\r
       end\r
-    end
-    
-  end
-  
-  describe 'サムネイル変換に於いて' do
-    #サムネイル化した画像データを返すが、スタブをおくので、リサイズと画像データ化を試みるかをチェックする
-    before do
-      ResourcePicture.stub(:resize).with(any_args).and_return(Mgk.new)
-      @op = Factory :original_picture, :artist_id => @artist.id
-      @p = Factory :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
-      attr = {:original_picture_id => @op.id, :license_id => @license.id, :artist_name => 'tester', :credit => '{}', :settings => {}.to_json.to_s}\r
-      @rp = Factory.build :resource_picture, attr\r
-    end
-    it 'サムネイルサイズに縮小した画像データを返す' do\r
-      ResourcePicture.should_receive(:resize).with(any_args).exactly(1)
-      @rp.thumbnail(Mgk.new)\r
     end\r
-    it 'データが返る' do\r
-      #全体スタブより\r
-      @rp.thumbnail(Mgk.new).should eq 'data'\r
+    #以下から例外ケース。処理先頭から失敗させていく\r
+    context 'サムネイル化に失敗したとき' do\r
+      before do\r
+        ResourcePicture.any_instance.stub(:flag_thumbnail).with(any_args).and_return(1)\r
+        ImagerTest.any_instance.stub(:to_thumbnail).with(any_args).and_return(false)\r
+      end\r
+      it 'Falseを返す' do\r
+        r = @rp.store_picture(@imager, '1.gif')\r
+        r.should be_false\r
+      end\r
+      it '画像ファイルの保存は呼ばれていない' do\r
+        PictureIO.resource_picture_io.should_not_receive(:put).with(any_args)\r
+        r = @rp.store_picture(@imager, '1.gif')\r
+      end\r
     end\r
-  end
-  
-end
+    context 'サムネイル画像の保存に失敗したとき' do\r
+      before do\r
+        ResourcePicture.any_instance.stub(:flag_thumbnail).with(any_args).and_return(1)\r
+        @tmbimager = @imager.to_thumbnail\r
+        ImagerTest.any_instance.stub(:to_thumbnail).with(any_args).and_return(@tmbimager)\r
+        PictureIO.resource_picture_io.stub(:put).with(@tmbimager.binary, '1.gif').and_return(false)\r
+      end\r
+      it 'Falseを返す' do\r
+        r = @rp.store_picture(@imager, '1.gif')\r
+        r.should be_false\r
+      end\r
+      it '画像ファイルの保存は呼ばれていない' do\r
+        PictureIO.resource_picture_io.should_receive(:put).with(any_args).exactly(1)\r
+        r = @rp.store_picture(@imager, '1.gif')\r
+      end\r
+    end\r
+    context '画像の保存に失敗したとき' do\r
+      before do\r
+        ResourcePicture.any_instance.stub(:flag_thumbnail).with(any_args).and_return(1)\r
+        @tmbimager = @imager.to_thumbnail\r
+        ImagerTest.any_instance.stub(:to_thumbnail).with(any_args).and_return(@tmbimager)\r
+        PictureIO.resource_picture_io.stub(:put).with(@tmbimager.binary, '1.gif').and_return(true)\r
+        PictureIO.resource_picture_io.stub(:put).with(@imager.binary, '1.gif', 'full').and_return(false)\r
+      end\r
+      it 'Falseを返す' do\r
+        r = @rp.store_picture(@imager, '1.gif')\r
+        r.should be_false\r
+      end\r
+    end\r
+    \r
+  end\r
+  \r
+  describe 'クレジットデータに於いて' do\r
+    before do\r
+      @op = FactoryGirl.create :original_picture, :artist_id => @artist.id\r
+      @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id\r
+      attr = {:original_picture_id => @op.id, :license_id => @license.id, :artist_name => 'tester', :credit => '{"system_picture_id": 2}', :settings => {}.to_json.to_s}\r
+      @rp = FactoryGirl.build :resource_picture, attr\r
+    end\r
+    it 'system_picture_idが入っている' do\r
+      res = @rp.credit_data\r
+      res["system_picture_id"].should eq 2\r
+    end\r
+  end\r
+  \r
+end\r
 \r