+ before do
+ Factory :admin
+ @user = Factory( :user_yas)
+ @author = @user.author
+ @artist = Factory :artist_yas, :author_id => @author.id
+ @other_user = Factory( :user_yas)
+ @other_author = @other_user.author
+ @other_artist = Factory :artist_yas, :author_id => @other_author.id
+ end
+
+ describe '検証に於いて' do
+ before do
+ end
+
+ it 'オーソドックスなデータなら通る' do
+ @op = Factory.build :original_picture, :artist_id => @artist.id
+ @op.should be_valid
+ end
+
+ context 'extを検証するとき' do
+ it 'nullなら失敗する' do
+ @op = Factory.build :original_picture, :artist_id => @artist.id, :ext => ''
+ @op.should_not be_valid
+ end
+ it '5文字以上なら失敗する' do
+ @op = Factory.build :original_picture, :artist_id => @artist.id, :ext => 'a'*5
+ @op.should_not be_valid
+ end
+ end
+ context 'widthを検証するとき' do
+ it 'nullなら失敗する' do
+ @op = Factory.build :original_picture, :artist_id => @artist.id, :width => nil
+ @op.should_not be_valid
+ end
+ it '数値でなければ失敗する' do
+ @op = Factory.build :original_picture, :artist_id => @artist.id, :width => 'a'
+ @op.should_not be_valid
+ end
+ it '0なら失敗する' do
+ @op = Factory.build :original_picture, :artist_id => @artist.id, :width => '0'
+ @op.should_not be_valid
+ end
+ it '負でも失敗する' do
+ @op = Factory.build :original_picture, :artist_id => @artist.id, :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
+ it 'nullなら失敗する' do
+ @op = Factory.build :original_picture, :artist_id => @artist.id, :height => nil
+ @op.should_not be_valid
+ end
+ it '数値でなければ失敗する' do
+ @op = Factory.build :original_picture, :artist_id => @artist.id, :height => 'a'
+ @op.should_not be_valid
+ end
+ it '0なら失敗する' do
+ @op = Factory.build :original_picture, :artist_id => @artist.id, :height => '0'
+ @op.should_not be_valid
+ end
+ it '負でも失敗する' do
+ @op = Factory.build :original_picture, :artist_id => @artist.id, :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
+ it 'nullなら失敗する' do
+ @op = Factory.build :original_picture, :artist_id => @artist.id, :filesize => nil
+ @op.should_not be_valid
+ end
+ it '数値でなければ失敗する' do
+ @op = Factory.build :original_picture, :artist_id => @artist.id, :filesize => 'a'
+ @op.should_not be_valid
+ end
+ it '負なら失敗する' do
+ @op = Factory.build :original_picture, :artist_id => @artist.id, :filesize => '-1'
+ @op.should_not be_valid
+ end
+ it '2MB以上なら失敗する' do
+ @op = Factory.build :original_picture, :artist_id => @artist.id, :filesize => 2000000
+ @op.should_not be_valid
+ end
+ end
+ context 'artist_idを検証するとき' do
+ it 'nullなら失敗する' do
+ @op = Factory.build :original_picture, :artist_id => nil
+ @op.should_not be_valid
+ end
+ it '数値でなければ失敗する' do
+ @op = Factory.build :original_picture, :artist_id => 'a'
+ @op.should_not be_valid
+ end
+ it '存在する絵師でなければ失敗する' do
+ @op = Factory.build :original_picture, :artist_id => 0
+ @op.should_not be_valid
+ end
+ end
+ context 'license_idを検証するとき' do
+ it 'nullなら失敗する' do
+ @op = Factory.build :original_picture, :artist_id => @artist.id, :license_id => nil
+ @op.should_not be_valid
+ end
+ it '数値でなければ失敗する' do
+ @op = Factory.build :original_picture, :artist_id => 'a', :license_id => 'a'
+ @op.should_not be_valid
+ end
+ it '存在する絵師でなければ失敗する' do
+ @op = Factory.build :original_picture, :artist_id => 0, :license_id => 0
+ @op.should_not be_valid
+ end
+ end
+ end
+
+ describe 'データ補充に於いて' do
+ before do
+ end
+
+ context '初期値を補充するとき' do
+ it '空なら0が補充される' do
+ @comic.supply_default
+ @comic.editable.should == 0
+ @comic.visible.should == 0
+ end
+ it 'editableが空でないなら変化なし' do
+ @comic.editable = 1
+ lambda{@comic.supply_default}.should_not change(@comic, :editable)
+ end
+ it 'visibleが空でないなら変化なし' do
+ @comic.visible = 1
+ lambda{@comic.supply_default}.should_not change(@comic, :visible)
+ end
+ end
+ end
+
+ describe '作者判定に於いて' do
+ before do
+ end
+ it '自作の原画ならyes' do
+ op = Factory :original_picture, :artist_id => @artist.id
+ op.own?(@author).should == true
+ end
+ it '他人のならno' do
+ op = Factory :original_picture, :artist_id => @other_artist. id
+ op.own?(@author).should_not == true
+ end
+ it '作家が不明ならno' do
+ op = Factory :original_picture, :artist_id => @artist.id
+ op.own?(nil).should_not == true
+ end
+ it '作家が絵師でないならno' do
+ other_user = Factory( :user_yas)
+ op = Factory :original_picture, :artist_id => @artist.id
+ op.own?(other_user).should_not == true
+ end
+ end
+ describe '単体取得に於いて' do
+ before do
+ @op = Factory :original_picture, :artist_id => @artist.id
+ end
+ it '指定のコミックを返す' do
+ pic = OriginalPicture.show @op.id
+ pic.should eq @op
+ end
+ context '関連テーブルオプションがないとき' do
+ it 'ライセンスデータだけを含んでいる' do
+ r = OriginalPicture.show_include_opt
+ r.should eq [:license]
+ end
+ end
+ context '関連テーブルオプションで絵師を含ませたとき' do
+ it 'ライセンスデータと作者データを含んでいる' do
+ r = OriginalPicture.show_include_opt(:include => :artist)
+ r.should eq [:license, :artist]
+ end
+ end
+ end
+ describe '一覧取得に於いて' do
+ before do
+ @op = Factory :original_picture, :artist_id => @artist.id
+ end
+ context 'page補正について' do
+ it '文字列から数値に変換される' do
+ OriginalPicture.page('8').should eq 8
+ end
+ it 'nilの場合は1になる' do
+ OriginalPicture.page().should eq 1
+ end
+ it '0以下の場合は1になる' do
+ OriginalPicture.page('0').should eq 1
+ end
+ end
+ context 'page_size補正について' do
+ it '文字列から数値に変換される' do
+ OriginalPicture.page_size('7').should eq 7
+ end
+ it 'nilの場合はOriginalPicture.default_page_sizeになる' do
+ OriginalPicture.page_size().should eq OriginalPicture.default_page_size
+ end
+ it '0以下の場合はOriginalPicture.default_page_sizeになる' do
+ OriginalPicture.page_size('0').should eq OriginalPicture.default_page_size
+ end
+ it 'OriginalPicture.max_page_sizeを超えた場合はOriginalPicture.max_page_sizeになる' do
+ OriginalPicture.page_size('1000').should eq OriginalPicture.max_page_size
+ end
+ end
+ it 'リストを返す' do
+ pic = OriginalPicture.list
+ pic.should eq [@op]
+ end
+ it '他人の原画は含んでいない' do
+ Factory :original_picture, :artist_id => @other_artist.id
+ pic = OriginalPicture.list
+ pic.should eq [@op]
+ end
+ it '時系列で並んでいる' do
+ newpic = Factory :original_picture, :artist_id => @artist.id
+ pic = OriginalPicture.list
+ pic.should eq [newpic, @op]
+ end
+ context 'DBに5件あって1ページの件数を2件に変えたとして' do
+ before do
+ @op2 = Factory :original_picture, :artist_id => @artist.id
+ @op3 = Factory :original_picture, :artist_id => @artist.id
+ @op4 = Factory :original_picture, :artist_id => @artist.id
+ @op5 = Factory :original_picture, :artist_id => @artist.id
+ OriginalPicture.stub(:default_page_size).and_return(2)
+ end
+ it '通常は2件を返す' do
+ pic = OriginalPicture.list
+ pic.should have(2).items
+ end
+ it 'page=1なら末尾2件を返す' do
+ #時系列で並んでいる
+ pic = OriginalPicture.list({}, 1)
+ pic.should eq [@op5, @op4]
+ end
+ it 'page=2なら中間2件を返す' do
+ pic = OriginalPicture.list({}, 2)
+ pic.should eq [@op3, @op2]
+ end
+ it 'page=3なら先頭1件を返す' do
+ pic = OriginalPicture.list({}, 3)
+ pic.should eq [@op]
+ end
+ end
+ end
+ describe '画像データ変換に於いて' do
+ before do
+ @op = Factory :original_picture, :artist_id => @artist.id
+ end
+ context 'つつがなく終わるとき' do
+ it '画像データをオブジェクト化している' do
+ end
+ end
+ end
+ describe '新規作成に於いて' do
+ before do
+ @op = Factory :original_picture, :artist_id => @artist.id
+ end
+ context 'つつがなく終わるとき' do
+ it '画像データをオブジェクト化している' do
+ end
+ end
+ end