describe Comic do
before do
Factory :admin
+ @sp = Factory :system_picture
+ @lg = Factory :license_group
+ @license = Factory :license, :license_group_id => @lg.id, :system_picture_id => @sp.id
@user = Factory( :user_yas)
@author = @user.author
@artist = Factory :artist_yas, :author_id => @author.id
end
it 'オーソドックスなデータなら通る' do
- @comic = Factory.build :normal_comic, :author_id => @author.id
+ @comic = Factory.build :comic, :author_id => @author.id
@comic.should be_valid
end
context 'titleを検証するとき' do
it 'nullなら失敗する' do
- @comic = Factory.build :normal_comic, :author_id => @author.id, :title => nil
+ @comic = Factory.build :comic, :author_id => @author.id, :title => nil
@comic.should_not be_valid
end
it '100文字以上なら失敗する' do
- @comic = Factory.build :normal_comic, :author_id => @author.id, :title => 'a'*101
+ @comic = Factory.build :comic, :author_id => @author.id, :title => 'a'*101
@comic.should_not be_valid
end
end
context 'widthを検証するとき' do
it 'nullなら失敗する' do
- @comic = Factory.build :normal_comic, :author_id => @author.id, :width => nil
+ @comic = Factory.build :comic, :author_id => @author.id, :width => nil
@comic.should_not be_valid
end
it '0なら失敗する' do
- @comic = Factory.build :normal_comic, :author_id => @author.id, :width => 0
+ @comic = Factory.build :comic, :author_id => @author.id, :width => 0
@comic.should_not be_valid
end
it '負でも失敗する' do
- @comic = Factory.build :normal_comic, :author_id => @author.id, :width => -1
+ @comic = Factory.build :comic, :author_id => @author.id, :width => -1
@comic.should_not be_valid
end
it '正なら通る' do
- @comic = Factory.build :normal_comic, :author_id => @author.id, :width => 1
+ @comic = Factory.build :comic, :author_id => @author.id, :width => 1
@comic.should be_valid
end
end
context 'heightを検証するとき' do
it 'nullなら失敗する' do
- @comic = Factory.build :normal_comic, :author_id => @author.id, :height => nil
+ @comic = Factory.build :comic, :author_id => @author.id, :height => nil
@comic.should_not be_valid
end
it '0なら失敗する' do
- @comic = Factory.build :normal_comic, :author_id => @author.id, :height => 0
+ @comic = Factory.build :comic, :author_id => @author.id, :height => 0
@comic.should_not be_valid
end
it '負でも失敗する' do
- @comic = Factory.build :normal_comic, :author_id => @author.id, :height => -1
+ @comic = Factory.build :comic, :author_id => @author.id, :height => -1
@comic.should_not be_valid
end
it '正なら通る' do
- @comic = Factory.build :normal_comic, :author_id => @author.id, :height => 1
+ @comic = Factory.build :comic, :author_id => @author.id, :height => 1
@comic.should be_valid
end
end
context 'visibleを検証するとき' do
it 'nullなら失敗する' do
- @comic = Factory.build :normal_comic, :author_id => @author.id, :visible => nil
+ @comic = Factory.build :comic, :author_id => @author.id, :visible => nil
@comic.should_not be_valid
end
it '負なら失敗する' do
- @comic = Factory.build :normal_comic, :author_id => @author.id, :visible => -1
+ @comic = Factory.build :comic, :author_id => @author.id, :visible => -1
@comic.should_not be_valid
end
it '4以上なら失敗する' do
- @comic = Factory.build :normal_comic, :author_id => @author.id, :visible => 4
- @comic.should_not be_valid
- end
- end
- context 'editableを検証するとき' do
- it 'nullなら失敗する' do
- @comic = Factory.build :normal_comic, :author_id => @author.id, :editable => nil
- @comic.should_not be_valid
- end
- it '負なら失敗する' do
- @comic = Factory.build :normal_comic, :author_id => @author.id, :visible => -1
- @comic.should_not be_valid
- end
- it '4以上なら失敗する' do
- @comic = Factory.build :normal_comic, :author_id => @author.id, :visible => 4
+ @comic = Factory.build :comic, :author_id => @author.id, :visible => 4
@comic.should_not be_valid
end
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)
before do
end
it '自作のコミックならyes' do
- comic = Factory :normal_comic, :author_id => @author.id
+ comic = Factory :comic, :author_id => @author.id
comic.own?(@author).should == true
end
it '他人のコミックならno' do
- comic = Factory :normal_comic, :author_id => @author.id - 1
+ comic = Factory :comic, :author_id => 0
comic.own?(@author).should == false
end
it '作家が不明ならno' do
- comic = Factory :normal_comic, :author_id => @author.id
+ comic = Factory :comic, :author_id => @author.id
comic.own?(nil).should == false
end
end
end
it '自作の公開コミックを見るときは許可する' do
Comic.any_instance.stub(:own?).and_return(true)
- comic = Factory :normal_comic, :author_id => @author.id
+ comic = Factory :comic, :author_id => @author.id, :visible => 3
comic.visible?(@author).should == true
end
it '自作のコミックは非公開でも許可する' do
Comic.any_instance.stub(:own?).and_return(true)
- comic = Factory :hidden_comic, :author_id => @author.id
+ comic = Factory :comic, :author_id => @author.id, :visible => 0
comic.visible?(@author).should == true
end
it '他人のコミックでも公開コミックなら許可する' do
Comic.any_instance.stub(:own?).and_return(false)
- comic = Factory :normal_comic, :author_id => @author.id - 1
+ comic = Factory :comic, :author_id => 0, :visible => 3
comic.visible?(@author).should == true
end
it '他人のコミックで非公開コミックなら許可しない' do
Comic.any_instance.stub(:own?).and_return(false)
- comic = Factory :hidden_comic, :author_id => @author.id - 1
+ comic = Factory :comic, :author_id => 0, :visible => 0
comic.visible?(@author).should == false
end
end
describe '単体取得に於いて' do
before do
- @comic = Factory :normal_comic, :author_id => @author.id
+ @comic = Factory :comic, :author_id => @author.id
end
it '指定のコミックを返す' do
c = Comic.show @comic.id, @author.id
c.should eq @comic
end
- context '関連テーブルオプションがないとき' do
- it '作家データだけを含んでいる' do
+ end
+ describe '関連テーブルプションに於いて' do
+ context 'オプションがないとき' do
+ it '2つの項目を含んでいる' do
r = Comic.show_include_opt
- r.should eq [:author]
+ r.should have(2).items
end
- end
- context '関連テーブルオプションでコマを含ませたとき' do
- it '作家データとコマデータを含んでいる' do
- r = Comic.show_include_opt(:include => :panels)
- r.should eq [:author, :panels]
+ it '作家を含んでいる' do
+ r = Comic.show_include_opt
+ r.has_key?(:author).should be_true
+ end
+ it 'ストーリーを含んでいる' do
+ r = Comic.show_include_opt
+ r.has_key?(:stories).should be_true
end
+ it 'ストーリーはコマを含んでいる' do
+ r = Comic.show_include_opt
+ r[:stories].has_key?(:panel).should be_true
+ end
+ end
+ end
+ describe 'json単体出力オプションに於いて' do
+ it 'includeキーを含んでいる' do
+ r = Comic.show_json_include_opt
+ r.has_key?(:include).should be_true
+ end
+ it '2つの項目を含んでいる' do
+ r = Comic.show_json_include_opt[:include]
+ r.should have(2).items
+ end
+ it '作家を含んでいる' do
+ r = Comic.show_json_include_opt[:include]
+ r.has_key?(:author).should be_true
end
+ it 'ストーリーを含んでいる' do
+ r = Comic.show_json_include_opt[:include]
+ r.has_key?(:stories).should be_true
+ end
+ it 'ストーリーはコマを含んでいる' do
+ r = Comic.show_json_include_opt[:include]
+ r[:stories].has_key?(:panel).should be_true
+ end
end
describe '一覧取得に於いて' do
before do
- @comic = Factory :normal_comic, :author_id => @author.id
+ @comic = Factory :comic, :author_id => @author.id
end
context 'page補正について' do
it '文字列から数値に変換される' do
c.should eq [@comic]
end
it '非公開コミックは(自分のコミックであっても)含んでいない' do
- Factory :hidden_comic, :author_id => @author.id
+ Factory :comic, :author_id => @author.id, :visible => 0
c = Comic.list
c.should eq [@comic]
end
it '時系列で並んでいる' do
- v = Factory :visible_comic, :author_id => @author.id, :updated_at => Time.now + 100
+ v = Factory :comic, :author_id => @author.id, :updated_at => Time.now + 100
c = Comic.list
c.should eq [v, @comic]
end
context 'DBに5件あって1ページの件数を2件に変えたとして' do
before do
- @comic2 = Factory :visible_comic, :author_id => @author.id, :updated_at => Time.now + 100
- @comic3 = Factory :editable_comic, :author_id => @author.id, :updated_at => Time.now + 200
- @comic4 = Factory :normal_comic, :author_id => @author.id, :updated_at => Time.now + 300
- @comic5 = Factory :editable_comic, :author_id => @author.id, :updated_at => Time.now + 400
+ @comic2 = Factory :comic, :author_id => @author.id, :updated_at => Time.now + 100
+ @comic3 = Factory :comic, :author_id => @author.id, :updated_at => Time.now + 200
+ @comic4 = Factory :comic, :author_id => @author.id, :updated_at => Time.now + 300
+ @comic5 = Factory :comic, :author_id => @author.id, :updated_at => Time.now + 400
Comic.stub(:default_page_size).and_return(2)
end
it '通常は2件を返す' do
end
end
end
+ describe 'list関連テーブルプションに於いて' do
+ it 'includeキーを含んでいる' do
+ r = Comic.list_opt
+ r.has_key?(:include).should be_true
+ end
+ it '2つの項目を含んでいる' do
+ r = Comic.list_opt[:include]
+ r.should have(2).items
+ end
+ it 'ストーリーを含んでいる' do
+ r = Comic.list_opt[:include]
+ r.has_key?(:stories).should be_true
+ end
+ it 'ストーリーはコマを含んでいる' do
+ r = Comic.list_opt[:include]
+ r[:stories].has_key?(:panel).should be_true
+ end
+ it '作家を含んでいる' do
+ r = Comic.list_opt[:include]
+ r.has_key?(:author).should be_true
+ end
+ end
+ describe 'json一覧出力オプションに於いて' do
+ it 'includeキーを含んでいる' do
+ r = Comic.list_json_opt
+ r.has_key?(:include).should be_true
+ end
+ it '2つの項目を含んでいる' do
+ r = Comic.list_json_opt[:include]
+ r.should have(2).items
+ end
+ it 'ストーリーを含んでいる' do
+ r = Comic.list_json_opt[:include]
+ r.has_key?(:stories).should be_true
+ end
+ it 'ストーリーはコマを含んでいる' do
+ r = Comic.list_json_opt[:include]
+ r[:stories].has_key?(:panel).should be_true
+ end
+ it '作家を含んでいる' do
+ r = Comic.list_json_opt[:include]
+ r.has_key?(:author).should be_true
+ end
+ end
end