\r
describe ResourcePicture do\r
before do\r
- Factory :admin\r
- @user = Factory( :user_yas)\r
+ FactoryGirl.create :admin\r
+ @user = FactoryGirl.create( :user_yas)\r
@author = @user.author\r
- @artist = Factory :artist_yas, :author_id => @author.id\r
- @other_user = Factory( :user_yas)\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 = Factory :artist_yas, :author_id => @other_author.id\r
- @sp = Factory :system_picture\r
- @lg = Factory :license_group\r
- @license = Factory :license, :license_group_id => @lg.id, :system_picture_id => @sp.id\r
- @original_picture = Factory :original_picture, :artist_id => @artist.id\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
class Mgk ; class Image ; end ; end\r
Mgk::Image.stub(:from_blob).with(any_args).and_return([Mgk.new])\r
\r
describe '検証に於いて' do\r
before do\r
- @p = Factory :picture, :original_picture_id => @original_picture.id, :license_id => @license.id, :artist_id => @artist.id\r
- @rp = Factory.build :resource_picture, :artist_id => @artist.id, :original_picture_id => @original_picture.id, :license_id => @license.id, :picture_id => @p.id\r
+ @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
it 'オーソドックスなデータなら通る' do\r
@rp.should_not be_valid\r
end\r
end\r
+ context 'md5を検証するとき' do\r
+ before do\r
+ @rp = FactoryGirl.build :picture\r
+ end\r
+ it 'テストデータの確認' do\r
+ @rp.md5 = 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'\r
+ @rp.should be_valid\r
+ end\r
+ it 'nullなら失敗する' do\r
+ @rp.md5 = ''\r
+ @rp.should_not be_valid\r
+ end\r
+ 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 'テストデータの確認' do\r
@rp.license_id = @license.id\r
\r
describe '単体取得に於いて' do\r
before do\r
- @op = Factory :original_picture, :artist_id => @artist.id\r
- @p = Factory :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id\r
- @rp = Factory :resource_picture, :artist_id => @artist.id, :original_picture_id => @op.id, :license_id => @license.id, :picture_id => @p.id\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
it '指定の素材を返す' do\r
pic = ResourcePicture.show @rp.id\r
end\r
describe '一覧取得に於いて' do\r
before do\r
- @op = Factory :original_picture, :artist_id => @artist.id\r
- @p = Factory :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id\r
- @rp = Factory :resource_picture, :artist_id => @artist.id, :original_picture_id => @op.id, :license_id => @license.id, :picture_id => @p.id\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
pic.should eq [@rp]\r
end\r
it '時系列で並んでいる' do\r
- nop = Factory :original_picture, :artist_id => @artist.id\r
- 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\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
pic = ResourcePicture.list\r
pic.should eq [nrp, @rp]\r
end\r
context 'DBに5件あって1ページの件数を2件に変えたとして' do\r
before do\r
- nop2 = Factory :original_picture, :artist_id => @artist.id\r
- @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\r
- nop3 = Factory :original_picture, :artist_id => @artist.id\r
- @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\r
- nop4 = Factory :original_picture, :artist_id => @artist.id\r
- @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\r
- nop5 = Factory :original_picture, :artist_id => @artist.id\r
- @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\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
describe 'フォーマット変換対象判定に於いて' do\r
before do\r
- @rp = Factory.build :resource_picture, \r
+ @rp = FactoryGirl.build :resource_picture, \r
:artist_id => @artist.id, :license_id => @license.id\r
end\r
context '変換するケース' do\r
\r
describe '原画からのコピーデータセットに於いて' do\r
before do\r
- @op = Factory :original_picture, :ext => 'jpeg', :width => 264, :height => 265, :filesize => 266, \r
+ @op = FactoryGirl.create :original_picture, :ext => 'jpeg', :width => 264, :height => 265, :filesize => 266, \r
:artist_id => @artist.id\r
- @rp = Factory.build :resource_picture, \r
+ @rp = FactoryGirl.build :resource_picture, \r
:artist_id => @artist.id\r
end\r
it '原画オブジェクトから属性を取り出して対象素材にセットしている' do\r
@rp.width.should eq 264\r
@rp.height.should eq 265\r
@rp.filesize.should eq 266\r
+ @rp.md5.should eq @op.md5\r
@rp.artist_id.should eq @artist.id\r
end\r
end\r
\r
describe 'RMagick変換に於いて' do\r
before do\r
- @op = Factory :original_picture, :artist_id => @artist.id\r
- @p = Factory :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id\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 = FactoryGirl.build :resource_picture, attr\r
end\r
context 'つつがなく終わるとき' do\r
it '画像データをオブジェクト化している' do\r
end\r
describe '画像オブジェクトの取得に於いて' do\r
before do\r
- @op = Factory :original_picture, :artist_id => @artist.id\r
- @p = Factory :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id\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 = FactoryGirl.build :resource_picture, attr\r
end\r
context '事前チェック' do\r
before do\r
\r
describe '新規実素材の取得に於いて' do\r
before do\r
- @op = Factory :original_picture, :artist_id => @artist.id\r
- @p = Factory :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id\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\r
+ @rp = FactoryGirl.build :resource_picture, attr\r
@mgk = Mgk.new\r
end\r
context '事前チェック' do\r
\r
describe '作成・更新に於いて' do\r
before do\r
- @op = Factory :original_picture, :artist_id => @artist.id\r
- @p = Factory :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id\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', :classname => 'StandardLicense', :credit => '{}', :settings => {}.to_json.to_s}\r
- @rp = Factory.build :resource_picture, attr\r
+ @rp = FactoryGirl.build :resource_picture, attr\r
end\r
context '事前チェック' do\r
before do\r
\r
describe '画像ファイルの作成・更新に於いて' do\r
before do\r
- @op = Factory :original_picture, :artist_id => @artist.id\r
- @p = Factory :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id\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 = FactoryGirl.build :resource_picture, attr\r
end\r
context '事前チェック' do\r
before do\r
ResourcePicture.stub(:png_to_gif).with(any_args).and_return(@gifmgk)\r
end\r
it '画像ファイルの作成・更新機能で画像を保存している' do\r
- ResourcePicture.any_instance.should_receive(:store_picture).with(@mgk).exactly(1)\r
+ ResourcePicture.any_instance.stub(:filename).with(any_args).and_return('1.png')\r
+ ResourcePicture.any_instance.should_receive(:store_picture).with(@mgk, '1.png').exactly(1)\r
res = @rp.store_picture_with_gif @mgk\r
end\r
it '自身にフォーマット変換対象かを問い合わせている' do\r
end\r
it '画像ファイルの作成・更新機能でgif画像を保存している' do\r
#二回目の保存はgif変換の結果を渡す。\r
- ResourcePicture.any_instance.should_receive(:store_picture).with(@gifmgk).exactly(1)\r
+ ResourcePicture.any_instance.stub(:gifname).with(any_args).and_return('1.gif')\r
+ ResourcePicture.any_instance.should_receive(:store_picture).with(@gifmgk, '1.gif').exactly(1)\r
res = @rp.store_picture_with_gif @mgk\r
end\r
end\r
end\r
context 'gif画像の保存に失敗したとき' do\r
before do\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
@mgk = Mgk.new\r
- ResourcePicture.any_instance.stub(:store_picture).with(@mgk).and_return(true)\r
+ ResourcePicture.any_instance.stub(:store_picture).with(@mgk, '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)\r
- ResourcePicture.any_instance.stub(:store_picture).with(@gifmgk).and_return(false)\r
+ ResourcePicture.any_instance.stub(:store_picture).with(@gifmgk, '1.gif').and_return(false)\r
end\r
it 'Falseを返す' do\r
res = @rp.store_picture_with_gif @mgk\r
describe '画像ファイルの作成・更新に於いて' do\r
#PictureIo経由で画像を保存するための機能。ファイル名に自身のidを使うので事前に自身の保存が必要。\r
before do\r
- @op = Factory :original_picture, :artist_id => @artist.id\r
- @p = Factory :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id\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 = FactoryGirl.build :resource_picture, attr\r
@rp.copy_data @op\r
end\r
context '事前チェック' do\r
end\r
it 'サムネイル化が1回呼ばれる' do\r
ResourcePicture.any_instance.should_receive(:thumbnail).with(any_args).exactly(1)\r
- res = @rp.store_picture(Mgk.new)\r
+ res = @rp.store_picture(Mgk.new, '1.gif')\r
end\r
it '画像ファイルの保存が2回呼ばれる' do\r
PictureIO.resource_picture_io.should_receive(:put).with(any_args).exactly(2)\r
- res = @rp.store_picture(Mgk.new)\r
+ res = @rp.store_picture(Mgk.new, '1.gif')\r
end\r
it '画像ファイルのベースへのサムネイル保存が1回呼ばれる' do\r
- PictureIO.resource_picture_io.should_receive(:put).with('tmbdata', @rp.filename).exactly(1)\r
- res = @rp.store_picture(Mgk.new)\r
+ PictureIO.resource_picture_io.should_receive(:put).with('tmbdata', '1.gif').exactly(1)\r
+ res = @rp.store_picture(Mgk.new, '1.gif')\r
end\r
it '画像ファイルのfullへの保存が1回呼ばれる' do\r
- PictureIO.resource_picture_io.should_receive(:put).with('data', @rp.filename, 'full').exactly(1)\r
- res = @rp.store_picture(Mgk.new)\r
+ PictureIO.resource_picture_io.should_receive(:put).with('data', '1.gif', 'full').exactly(1)\r
+ res = @rp.store_picture(Mgk.new, '1.gif')\r
end\r
end\r
context 'つつがなく終わるとき' 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
+ ResourcePicture.any_instance.stub(:thumbnail).with(any_args).and_return('tmbdata')\r
end\r
it 'Trueを返す' do\r
- res = @rp.store_picture(Mgk.new)\r
+ res = @rp.store_picture(Mgk.new, '1.gif')\r
res.should be_true\r
end\r
end\r
context '例外ケース' do\r
before do\r
ResourcePicture.any_instance.stub(:flag_thumbnail).with(any_args).and_return(1)\r
+ ResourcePicture.any_instance.stub(:thumbnail).with(any_args).and_return('tmbdata')\r
PictureIO.resource_picture_io.stub(:put).with(any_args).and_return(false)\r
end\r
- it 'Falseを返す' do\r
- res = @rp.store_picture(Mgk.new)\r
+ it '画像の保存に失敗したならFalseを返す' do\r
+ res = @rp.store_picture(Mgk.new, '1.gif')\r
res.should be_false\r
end\r
end\r
#サムネイル化した画像データを返すが、スタブをおくので、リサイズと画像データ化を試みるかをチェックする\r
before do\r
ResourcePicture.stub(:resize).with(any_args).and_return(Mgk.new)\r
- @op = Factory :original_picture, :artist_id => @artist.id\r
- @p = Factory :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id\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 = FactoryGirl.build :resource_picture, attr\r
end\r
it 'サムネイルサイズに縮小した画像データを返す' do\r
ResourcePicture.should_receive(:resize).with(any_args).exactly(1)\r
\r
describe 'クレジットデータに於いて' do\r
before do\r
- @op = Factory :original_picture, :artist_id => @artist.id\r
- @p = Factory :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id\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 = Factory.build :resource_picture, attr\r
+ @rp = FactoryGirl.build :resource_picture, attr\r
end\r
it 'system_picture_idが入っている' do\r
res = @rp.credit_data\r