@other_user = Factory( :user_yas)
@other_author = @other_user.author
@other_artist = Factory :artist_yas, :author_id => @other_author.id
- @license = Factory :license
+ @sp = Factory :system_picture
+ @lg = Factory :license_group
+ @license = Factory :license, :license_group_id => @lg.id, :system_picture_id => @sp.id
end
describe '検証に於いて' do
end
it 'オーソドックスなデータなら通る' do
- @op = Factory.build :original_picture, :artist_id => @artist.id
+ @op = Factory.build :original_picture, :artist_id => @artist.id, :license_id => @license.id
@op.should be_valid
end
context 'extを検証するとき' do
+ before do
+ @op = Factory.build :original_picture, :artist_id => @artist.id, :license_id => @license.id
+ end
+ it 'テストデータの確認' do
+ @op.ext = 'jpeg'
+ @op.should be_valid
+ end
it 'nullなら失敗する' do
- @op = Factory.build :original_picture, :artist_id => @artist.id, :ext => ''
+ @op.ext = ''
@op.should_not be_valid
end
it '5文字以上なら失敗する' do
- @op = Factory.build :original_picture, :artist_id => @artist.id, :ext => 'a'*5
+ @op.ext = 'a'*5
@op.should_not be_valid
end
it 'png,gif,jpeg以外なら失敗する' do
- @op = Factory.build :original_picture, :artist_id => @artist.id, :ext => 'bmp'
+ @op.ext = 'bmp'
@op.should_not be_valid
end
end
context 'widthを検証するとき' do
+ before do
+ @op = Factory.build :original_picture, :artist_id => @artist.id, :license_id => @license.id
+ end
+ it 'テストデータの確認' do
+ @op.width = 1
+ @op.should be_valid
+ end
it 'nullなら失敗する' do
- @op = Factory.build :original_picture, :artist_id => @artist.id, :width => nil
+ @op.width = nil
@op.should_not be_valid
end
it '数値でなければ失敗する' do
- @op = Factory.build :original_picture, :artist_id => @artist.id, :width => 'a'
+ @op.width = 'a'
@op.should_not be_valid
end
it '0なら失敗する' do
- @op = Factory.build :original_picture, :artist_id => @artist.id, :width => '0'
+ @op.width = '0'
@op.should_not be_valid
end
it '負でも失敗する' do
- @op = Factory.build :original_picture, :artist_id => @artist.id, :width => -1
+ @op.width = -1
@op.should_not be_valid
end
- it '正なら通る' do
- @op = Factory.build :original_picture, :artist_id => @artist.id, :width => 1
- @op.should be_valid
- end
end
context 'heightを検証するとき' do
+ before do
+ @op = Factory.build :original_picture, :artist_id => @artist.id, :license_id => @license.id
+ end
+ it 'テストデータの確認' do
+ @op.height = 1
+ @op.should be_valid
+ end
it 'nullなら失敗する' do
- @op = Factory.build :original_picture, :artist_id => @artist.id, :height => nil
+ @op.height = nil
@op.should_not be_valid
end
it '数値でなければ失敗する' do
- @op = Factory.build :original_picture, :artist_id => @artist.id, :height => 'a'
+ @op.height = 'a'
@op.should_not be_valid
end
it '0なら失敗する' do
- @op = Factory.build :original_picture, :artist_id => @artist.id, :height => '0'
+ @op.height = '0'
@op.should_not be_valid
end
it '負でも失敗する' do
- @op = Factory.build :original_picture, :artist_id => @artist.id, :height => -1
+ @op.height = -1
@op.should_not be_valid
end
- it '正なら通る' do
- @op = Factory.build :original_picture, :artist_id => @artist.id, :height => 1
- @op.should be_valid
- end
end
context 'filesizeを検証するとき' do
+ before do
+ @op = Factory.build :original_picture, :artist_id => @artist.id, :license_id => @license.id
+ end
+ it 'テストデータの確認' do
+ @op.filesize = 1
+ @op.should be_valid
+ end
it 'nullなら失敗する' do
- @op = Factory.build :original_picture, :artist_id => @artist.id, :filesize => nil
+ @op.filesize = nil
@op.should_not be_valid
end
it '数値でなければ失敗する' do
- @op = Factory.build :original_picture, :artist_id => @artist.id, :filesize => 'a'
+ @op.filesize = 'a'
@op.should_not be_valid
end
it '負なら失敗する' do
- @op = Factory.build :original_picture, :artist_id => @artist.id, :filesize => '-1'
+ @op.filesize = '-1'
@op.should_not be_valid
end
it '2MB以上なら失敗する' do
- @op = Factory.build :original_picture, :artist_id => @artist.id, :filesize => 2000000+1
+ @op.filesize = 2000000+1
@op.should_not be_valid
end
end
context 'artist_idを検証するとき' do
+ before do
+ @op = Factory.build :original_picture, :license_id => @license.id
+ end
+ it 'テストデータの確認' do
+ @op.artist_id = @artist.id
+ @op.should be_valid
+ end
it 'nullなら失敗する' do
- @op = Factory.build :original_picture, :artist_id => nil
+ @op.artist_id = nil
@op.should_not be_valid
end
it '数値でなければ失敗する' do
- @op = Factory.build :original_picture, :artist_id => 'a'
+ @op.artist_id = 'a'
@op.should_not be_valid
end
it '存在する絵師でなければ失敗する' do
- @op = Factory.build :original_picture, :artist_id => 0
+ @op.artist_id = 0
@op.should_not be_valid
end
end
context 'license_idを検証するとき' do
+ before do
+ @op = Factory.build :original_picture, :artist_id => @artist.id
+ end
+ it 'テストデータの確認' do
+ @op.license_id = @license.id
+ @op.should be_valid
+ end
it 'nullなら失敗する' do
- @op = Factory.build :original_picture, :artist_id => @artist.id, :license_id => nil
+ @op.license_id = nil
@op.should_not be_valid
end
it '数値でなければ失敗する' do
- @op = Factory.build :original_picture, :artist_id => 'a', :license_id => 'a'
+ @op.license_id = 'a'
@op.should_not be_valid
end
- it '存在する絵師でなければ失敗する' do
- @op = Factory.build :original_picture, :artist_id => 0, :license_id => 0
+ it '存在するlicenseでなければ失敗する' do
+ @op.license_id = 0
@op.should_not be_valid
end
end
before do
@op = Factory :original_picture, :artist_id => @artist.id
end
- it '指定のコミックを返す' do
- pic = OriginalPicture.show @op.id, @author
+ it '指定の原画を返す' do
+ pic = OriginalPicture.show @op.id, @artist
pic.should eq @op
end
context '関連テーブルオプションがないとき' do
- it 'ã\83©ã\82¤ã\82»ã\83³ã\82¹ã\83\87ã\83¼ã\82¿ã\81 ã\81\91を含んでいる' do
+ it 'ã\83©ã\82¤ã\82»ã\83³ã\82¹ã\81¨ç´ æ\9d\90を含んでいる' do
r = OriginalPicture.show_include_opt
- r.should eq [:license]
+ r.should eq [:license, :resource_picture]
end
end
context '関連テーブルオプションで絵師を含ませたとき' do
- it 'ã\83©ã\82¤ã\82»ã\83³ã\82¹ã\83\87ã\83¼ã\82¿と作者データを含んでいる' do
+ it 'ã\83©ã\82¤ã\82»ã\83³ã\82¹ã\81¨ç´ æ\9d\90と作者データを含んでいる' do
r = OriginalPicture.show_include_opt(:include => :artist)
- r.should eq [:license, :artist]
+ r.should eq [:license, :resource_picture, :artist]
+ end
+ end
+ context '他人の原画を開こうとしたとき' do
+ it '403Forbidden例外を返す' do
+ lambda{
+ pic = OriginalPicture.show @op.id, @other_artist
+ }.should raise_error(ActiveRecord::Forbidden)
+ end
+ end
+ context '存在しない原画を開こうとしたとき' do
+ it '404RecordNotFound例外を返す' do
+ lambda{
+ pic = OriginalPicture.show 0, @artist
+ }.should raise_error(ActiveRecord::RecordNotFound)
end
end
end
+ describe 'json単体出力オプションに於いて' do
+ it 'includeキーがライセンスと素材を含んでいる' do
+ r = OriginalPicture.show_json_include_opt
+ r[:include].should eq [:license, :resource_picture]
+ end
+ end
describe '一覧取得に於いて' do
before do
@op = Factory :original_picture, :artist_id => @artist.id
end
end
end
+ describe 'json一覧出力オプションに於いて' do
+ it 'includeキーがライセンスと素材を含んでいる' do
+ r = OriginalPicture.list_json_opt
+ r[:include].should eq [:license, :resource_picture]
+ end
+ end
describe 'RMagick変換に於いて' do
before do
@op = Factory.build :original_picture, :artist_id => @artist.id
describe '作成・更新に於いて' do
before do
@op = Factory.build :original_picture, :artist_id => @artist.id
+ #RMagickのスタブをおいておく
class Mgk ; class Image ; end ; end
@filesize = 76543
Mgk::Image.stub(:from_blob).with(any_args).and_return([Mgk.new])
Mgk.any_instance.stub(:columns).with(any_args).and_return(100)
Mgk.any_instance.stub(:filesize).with(any_args).and_return(@filesize)
Mgk.any_instance.stub(:to_blob).with(any_args).and_return('data')
+ #原画ファイル削除だけは必ず成功するものとしておく
PictureIO::LocalPicture.any_instance.stub(:delete).with(any_args).and_return(true)
-
+ #素材取得は新規作成ケースでテストしておく
ResourcePicture.stub(:update_picture).with(any_args).and_return(
Factory.build :resource_picture, :artist_id => @artist.id
)
end
context '事前チェック' do
before do
+ #すべての処理が正常パターンで通過すれば、一番深い分岐まで通る。
+ #それで外部のメソッド呼び出しだけに着目してテストする。
OriginalPicture.any_instance.stub(:data_to_mgk).with(any_args).and_return(Mgk.new)
OriginalPicture.any_instance.stub(:save).with(any_args).and_return(true)\r
PictureIO::LocalPicture.any_instance.stub(:put).with(any_args).and_return(true)
end
context 'つつがなく終わるとき' do
before do
+ #すべての処理を正常パターンで通過させ、保存機能をチェックする。
OriginalPicture.any_instance.stub(:data_to_mgk).with(any_args).and_return(Mgk.new)
# OriginalPicture.any_instance.stub(:save).with(any_args).and_return(true)\r
PictureIO::LocalPicture.any_instance.stub(:put).with(any_args).and_return(true)
@op.store('bindata', @artist, @license.id).should eq true\r
end
end
-
+ #以下から例外ケース。処理先頭から失敗させていく
context 'RMagick変換が失敗したとき' do
before do
OriginalPicture.any_instance.stub(:data_to_mgk).with(any_args).and_return(false)