- describe 'Gifフォーマット変換に於いて' do\r
- before do\r
- Magick::Image.stub(:from_blob).with(any_args).and_return([Mgk.new])\r
- end\r
- context 'つつがなく終わるとき' do\r
- it 'Mgkオブジェクトが返る' do\r
- mgk = ResourcePicture.png_to_gif('mgkbin')\r
- mgk.is_a?(Mgk).should be_true\r
- end\r
- it 'Mgkオブジェクトはgif変換されている' do\r
- #スタブばかりで変換できないので代入されているかでチェックする\r
- Mgk.any_instance.should_receive(:format=).with('gif').exactly(1)\r
- ResourcePicture.png_to_gif('mgkbin')\r
- end\r
- end\r
- context 'RMagick変換が失敗したとき' do\r
- before do\r
- Magick::Image.should_receive(:from_blob).with(any_args).and_raise('StandardError')\r
- end\r
- it 'falseを返す' do\r
- res = ResourcePicture.png_to_gif('mgkbin')\r
- res.should be_false\r
- end\r
- end\r
- end\r
- \r
- describe '原画からのコピーデータセットに於いて' do\r
- before do\r
- @op = Factory :original_picture, :ext => 'jpeg', :width => 264, :height => 265, :filesize => 266, \r
- :artist_id => @artist.id\r
- @rp = Factory.build :resource_picture, \r
- :artist_id => @artist.id\r
- end\r
- it '原画オブジェクトから属性を取り出して対象素材にセットしている' do\r
- 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
- 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
- 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\r
- context 'つつがなく終わるとき' do\r
- it '画像データをオブジェクト化している' do\r
- Magick::Image.stub(:from_blob).and_return(['mgkobj'])\r
- @rp.data_to_mgk('mgkbin').should eq 'mgkobj'\r
- end\r
- end\r
- context '失敗するとき' do\r
- it 'Falseを返す' do\r
- Magick::Image.should_receive(:from_blob).with(any_args).and_raise('StandardError')\r
- @rp.data_to_mgk('mgkbin').should be_false\r
- end\r
- it '全体エラーがセットされている' do\r
- Magick::Image.should_receive(:from_blob).with(any_args).and_raise('StandardError')\r
- lambda {\r
- @rp.data_to_mgk('mgkbin')\r
- }.should change(@rp.errors[:base], :count)\r
- end\r
- end\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
- 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\r
- context '事前チェック' do\r
- before do\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.new)\r
- end\r
- it '原画から画像データを取得している' do\r
- OriginalPicture.any_instance.should_receive(:restore).with(any_args).exactly(1)\r
- res = @rp.op_mgk\r
- end\r
- it '素材に原画データのRMagick変換を依頼している' do\r
- ResourcePicture.any_instance.should_receive(:data_to_mgk).with(any_args).exactly(1)\r
- res = @rp.op_mgk\r
- end\r
- end\r
- context 'つつがなく終わるとき' do\r
- #原画から画像データを取得する。\r
- #素材に原画データのRMagick変換を依頼し、画像オブジェクトを返す。 \r
- before do\r
- @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)\r
- end\r
- it '画像オブジェクトを返す' do\r
- res = @rp.op_mgk\r
- res.should eq @mgk\r
- end\r
- end\r
- end\r
- \r