+# -*- encoding: utf-8 -*-
require 'spec_helper'
describe Comic do
- pending "add some examples to (or delete) #{__FILE__}"
+ before do
+ Factory :admin
+ @user = Factory( :user_yas)
+ @author = Factory( :author_yas, :user_id => @user.id)
+ @artist = Factory :artist_yas, :author_id => @author.id
+ @comic = Comic.new
+ end
+
+ describe '検証に於いて' do
+ before do
+ @comic = Comic.new
+ end
+
+ context 'titleを検証するとき' do
+ it '100文字以上なら失敗する' do
+ end
+ end
+ end
+
+ describe 'データ補充に於いて' do
+ before do
+ @comic = Comic.new
+ end
+
+ context '初期値を補充するとき' do
+ it '空なら0が補充される' do
+ @comic.supply_default
+ @comic.editable.should == 0
+ @comic.visible.should == 0
+ end
+ it 'editableが空でないなら変化なし' do
+ @comic.editable = 1
+ {@comic.supply_default}.should_not change(@comic, :editable)
+ end
+ it 'visibleが空でないなら変化なし' do
+ @comic.visible = 1
+ {@comic.supply_default}.should_not change(@comic, :visible)
+ end
+ end
+ end
+
+ describe '作者判定に於いて' do
+ before do
+ end
+ it '自作のコミックならyes' do
+ comic = Factory :normal_comic, :author_id => @author.id
+ comic.own?(@author).should == true
+ end
+ it '他人のコミックならno' do
+ comic = Factory :normal_comic, :author_id => @author.id - 1
+ comic.own?(@author).should == false
+ end
+ it '作家が不明ならno' do
+ comic = Factory :normal_comic, :author_id => @author.id
+ comic.own?(nil).should == false
+ end
+ end
+ describe '閲覧許可に於いて' do
+ before do
+ end
+ it '自作の公開コミックを見るときは許可する' do
+ Comic.any_instance.stub('own?').and_return(true)
+ comic = Factory :normal_comic, :author_id => @author.id
+ comic.vis(@author).should == true
+ end
+ it '自作のコミックは非公開でも許可する' do
+ Comic.any_instance.stub('own?').and_return(true)
+ comic = Factory :hidden_comic, :author_id => @author.id
+ comic.vis(@author).should == true
+ end
+ it '他人のコミックでも公開コミックなら許可する' do
+ Comic.any_instance.stub('own?').and_return(false)
+ comic = Factory :normal_comic, :author_id => @author.id - 1
+ comic.vis(@author).should == true
+ end
+ it '他人のコミックで非公開コミックなら許可しない' do
+ Comic.any_instance.stub('own?').and_return(false)
+ comic = Factory :hidden_comic, :author_id => @author.id - 1
+ comic.vis(@author).should == false
+ end
+ end
+ describe '保存検証に於いて' do
+ before do
+ end
+ context '同一作家のとき' do
+ it 'trueを返す' do
+ end
+ end
+ end
end