#コマ\r
describe Panel do\r
before do\r
- FactoryGirl.create :admin\r
+ @admin = FactoryGirl.create :admin\r
@sp = FactoryGirl.create :system_picture\r
@lg = FactoryGirl.create :license_group\r
@license = FactoryGirl.create :license, :license_group_id => @lg.id, :system_picture_id => @sp.id\r
@user = FactoryGirl.create( :user_yas)\r
- @author = @user.author\r
+ @author = FactoryGirl.create :author, :user_id => @user.id\r
@artist = FactoryGirl.create :artist_yas, :author_id => @author.id\r
@other_user = FactoryGirl.create( :user_yas)\r
- @other_author = @other_user.author\r
+ @other_author = FactoryGirl.create :author, :user_id => @other_user.id\r
@other_artist = FactoryGirl.create :artist_yas, :author_id => @other_author.id\r
@op = FactoryGirl.create :original_picture, :artist_id => @artist.id\r
@p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id\r
\r
describe '検証に於いて' do\r
before do\r
- end\r
- \r
- it 'オーソドックスなデータなら通る' do\r
@panel = FactoryGirl.build :panel, :author_id => @author.id\r
- @panel.should be_valid\r
end\r
\r
- context 'widthを検証するとき' do\r
- before do\r
- @panel = FactoryGirl.build :panel, :author_id => @author.id\r
- end\r
- it 'テストデータの確認' do\r
+ context 'オーソドックスなデータのとき' do\r
+ it '下限データが通る' do\r
@panel.width = 1\r
+ @panel.height = 1\r
+ @panel.border = 0\r
+ @panel.x = -99999\r
+ @panel.y = -99999\r
+ @panel.z = 1\r
+ @panel.publish = 0\r
+ @panel.should be_valid\r
+ end\r
+ it '上限データが通る' do\r
+ @panel.width = 99999\r
+ @panel.height = 99999\r
+ @panel.border = 99999\r
+ @panel.x = 99999\r
+ @panel.y = 99999\r
+ @panel.z = 99999\r
+ @panel.publish = 99999\r
@panel.should be_valid\r
end\r
+ end\r
+ \r
+ context 'widthを検証するとき' do\r
it 'nullなら失敗する' do\r
@panel.width = nil\r
@panel.should_not be_valid\r
end\r
end\r
context 'heightを検証するとき' do\r
- before do\r
- @panel = FactoryGirl.build :panel, :author_id => @author.id\r
- end\r
- it 'テストデータの確認' do\r
- @panel.height = '1'\r
- @panel.should be_valid\r
- end\r
it 'nullなら失敗する' do\r
@panel.height = nil\r
@panel.should_not be_valid\r
end\r
end\r
context 'borderを検証するとき' do\r
- before do\r
- @panel = FactoryGirl.build :panel, :author_id => @author.id\r
- end\r
- it 'テストデータの確認' do\r
- @panel.border = '1'\r
- @panel.should be_valid\r
- end\r
it 'nullなら失敗する' do\r
@panel.border = nil\r
@panel.should_not be_valid\r
end\r
end\r
context 'xを検証するとき' do\r
- before do\r
- @panel = FactoryGirl.build :panel, :author_id => @author.id\r
- end\r
- it 'テストデータの確認' do\r
- @panel.x = '1'\r
- @panel.should be_valid\r
- end\r
it '数値でなければ失敗する' do\r
@panel.x = 'a'\r
@panel.should_not be_valid\r
end\r
end\r
context 'yを検証するとき' do\r
- before do\r
- @panel = FactoryGirl.build :panel, :author_id => @author.id\r
- end\r
- it 'テストデータの確認' do\r
- @panel.y = '1'\r
- @panel.should be_valid\r
- end\r
it '数値でなければ失敗する' do\r
@panel.y = 'a'\r
@panel.should_not be_valid\r
end\r
end\r
context 'zを検証するとき' do\r
- before do\r
- @panel = FactoryGirl.build :panel, :author_id => @author.id\r
- end\r
- it 'テストデータの確認' do\r
- @panel.z = '1'\r
- @panel.should be_valid\r
- end\r
it '数値でなければ失敗する' do\r
@panel.z = 'a'\r
@panel.should_not be_valid\r
end\r
end\r
context 'author_idを検証するとき' do\r
- before do\r
- @panel = FactoryGirl.build :panel, :author_id => @author.id\r
- end\r
- it 'テストデータの確認' do\r
- @panel.author_id = @author.id\r
- @panel.should be_valid\r
- end\r
it 'nullなら失敗する' do\r
@panel.author_id = nil\r
@panel.should_not be_valid\r
@panel.author_id = 'a'\r
@panel.should_not be_valid\r
end\r
- it '存在する絵師でなければ失敗する' do\r
+ it '存在する作家でなければ失敗する' do\r
@panel.author_id = 0\r
@panel.should_not be_valid\r
end\r
end\r
+ context '公開フラグを検証するとき' do\r
+ it '数値でなければ失敗する' do\r
+ @panel.publish = 'a'\r
+ @panel.should_not be_valid\r
+ end\r
+ end\r
context '全体を検証するとき' do\r
before do\r
@panel = FactoryGirl.create :panel, :author_id => @author.id\r
end\r
end\r
\r
+ describe '文字コード検証に於いて' do\r
+ before do\r
+ @panel = FactoryGirl.build :panel, :author_id => @author.id\r
+ end\r
+ \r
+ context 'captionを検証するとき' do\r
+ it 'Shift JISなら失敗する' do\r
+ @panel.caption = "\x83G\x83r\x83]\x83D"\r
+ lambda{\r
+ @panel.valid_encode\r
+ }.should raise_error(Pettanr::BadRequest)\r
+ end\r
+ end\r
+ \r
+ end\r
+ \r
describe 'デフォルト値補充に於いて' do\r
before do\r
@panel = FactoryGirl.build :panel, :author_id => @author.id\r
@panel.supply_default\r
@panel.border.should eq 2\r
end\r
+ it 'publishは0を補充する' do\r
+ @panel.publish = nil\r
+ @panel.supply_default\r
+ @panel.publish.should eq 0\r
+ end\r
end\r
\r
describe '上書き補充に於いて' do\r
\r
end\r
\r
- describe '作者判定に於いて' do\r
- before do\r
- end\r
- it '自作のコマならyes' do\r
- panel = FactoryGirl.create :panel, :author_id => @author.id\r
- panel.own?(@author).should == true\r
- end\r
- it '他人のコマならno' do\r
- panel = FactoryGirl.create :panel, :author_id => @author.id\r
- panel.own?(@other_author).should == false\r
- end\r
- it '作家が不明ならno' do\r
- panel = FactoryGirl.create :panel, :author_id => @author.id\r
- panel.own?(nil).should == false\r
- end\r
- end\r
- describe '閲覧許可に於いて' do\r
- before do\r
- end\r
- it '自作のコマを見るときは許可する' do\r
- Panel.any_instance.stub(:own?).and_return(true)\r
- Panel.any_instance.stub(:publish?).and_return(true)\r
- panel = FactoryGirl.create :panel, :author_id => @author.id\r
- panel.visible?(@author).should == true\r
- end\r
- it '自作のコマは非公開でも許可する' do\r
- Panel.any_instance.stub(:own?).and_return(true)\r
- Panel.any_instance.stub(:publish?).and_return(false)\r
- panel = FactoryGirl.create :panel, :author_id => @author.id\r
- panel.visible?(@author).should == true\r
- end\r
- it '他人のコマでも公開なら許可する' do\r
- Panel.any_instance.stub(:own?).and_return(false)\r
- Panel.any_instance.stub(:publish?).and_return(true)\r
- panel = FactoryGirl.create :panel, :author_id => @author.id\r
- panel.visible?(@author).should == true\r
- end\r
- it '他人のコマで非公開なら許可しない' do\r
- Panel.any_instance.stub(:own?).and_return(false)\r
- Panel.any_instance.stub(:publish?).and_return(false)\r
- panel = FactoryGirl.create :panel, :author_id => @author.id\r
- panel.visible?(@author).should == false\r
- end\r
- end\r
- describe '単体取得に於いて' do\r
+ describe '所持判定に於いて' do\r
before do\r
@panel = FactoryGirl.create :panel, :author_id => @author.id\r
end\r
- it '指定のコマを返す' do\r
- Panel.any_instance.stub(:visible?).and_return(true)\r
- pl = Panel.show @panel.id, @author\r
- pl.should eq @panel\r
+ context '事前チェックする' do\r
+ it '自身にロールリストからの作家取得を依頼している' do\r
+ Panel.should_receive(:get_author_from_roles).with(any_args).exactly(1)\r
+ r = @panel.own?([@author])\r
+ end\r
end\r
- context '他人の非公開コミックのコマを開こうとしたとき' do\r
- it '403Forbidden例外を返す' do\r
- Panel.any_instance.stub(:visible?).and_return(false)\r
- lambda{\r
- Panel.show @panel.id, @author\r
- }.should raise_error(ActiveRecord::Forbidden)\r
+ context 'ロール内作家が取得できるとき' do\r
+ before do\r
+ end\r
+ it 'ロール内作家のidが自身の作家idと一致するなら許可する' do\r
+ Panel.stub(:get_author_from_roles).with(any_args).and_return(@author)\r
+ r = @panel.own?([@author])\r
+ r.should be_true\r
+ end\r
+ it 'ロール内作家のidが自身の作家idと一致しないならno' do\r
+ Panel.stub(:get_author_from_roles).with(any_args).and_return(@other_author)\r
+ @panel.own?(@other_author).should be_false\r
end\r
end\r
- context '存在しないコマを開こうとしたとき' do\r
- it '404RecordNotFound例外を返す' do\r
- lambda{\r
- Panel.show 110, @author\r
- }.should raise_error(ActiveRecord::RecordNotFound)\r
+ context 'ロール内作家が取得できないとき' do\r
+ before do\r
+ Panel.stub(:get_author_from_roles).with(any_args).and_return(nil)\r
+ end\r
+ it 'Falseを返す' do\r
+ r = @panel.own?([@author])\r
+ r.should be_false\r
end\r
end\r
end\r
- describe '単体取得に於いて' do\r
+ \r
+ describe '閲覧許可に於いて' do\r
before do\r
+ @comic = FactoryGirl.create :comic, :author_id => @author.id\r
@panel = FactoryGirl.create :panel, :author_id => @author.id\r
+ @story = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id\r
end\r
- it '指定のコマを返す' do\r
- Panel.any_instance.stub(:own?).and_return(true)\r
- pl = Panel.edit @panel.id, @author\r
- pl.should eq @panel\r
- end\r
- context '他人のコマを開こうとしたとき' do\r
- it '403Forbidden例外を返す' do\r
- Panel.any_instance.stub(:own?).and_return(false)\r
- lambda{\r
- Panel.edit @panel.id, @author\r
- }.should raise_error(ActiveRecord::Forbidden)\r
+ context 'オープンモードのとき' do\r
+ before do\r
+ MagicNumber['run_mode'] = 0\r
end\r
- end\r
- context '存在しないコマを開こうとしたとき' do\r
- it '404RecordNotFound例外を返す' do\r
- lambda{\r
- Panel.edit 110, @author\r
- }.should raise_error(ActiveRecord::RecordNotFound)\r
+ it '自身にゲスト用ロールチェックを問い合わせしている' do\r
+ Panel.any_instance.stub(:guest_role_check).and_return(true)\r
+ Panel.any_instance.should_receive(:guest_role_check).with(any_args).exactly(1)\r
+ r = @panel.visible?([@author])\r
+ end\r
+ it 'ゲスト用ロールチェックが失敗したとき、falseを返す' do\r
+ Panel.any_instance.stub(:guest_role_check).and_return(false)\r
+ r = @panel.visible?([@author])\r
+ r.should be_false\r
end\r
end\r
- end\r
- describe '関連テーブルプションに於いて' do\r
- context 'オプションがないとき' do\r
- it '3つの項目を含んでいる' do\r
- r = Panel.show_include_opt\r
- r.should have(3).items\r
+ context 'クローズドモードのとき' do\r
+ before do\r
+ MagicNumber['run_mode'] = 1\r
end\r
- it 'コマ絵を含んでいる' do\r
- r = Panel.show_include_opt\r
- r.has_key?(:panel_pictures).should be_true\r
+ it '自身に読者用ロールチェックを問い合わせしている' do\r
+ Panel.any_instance.stub(:reader_role_check).and_return(true)\r
+ Panel.any_instance.should_receive(:reader_role_check).with(any_args).exactly(1)\r
+ r = @panel.visible?([@author])\r
end\r
- it 'コマ絵は実素材を含んでいる' do\r
- r = Panel.show_include_opt\r
- r[:panel_pictures].has_key?(:picture).should be_true\r
- end\r
- it '実素材は絵師を含んでいる' do\r
- r = Panel.show_include_opt\r
- r[:panel_pictures][:picture].has_key?(:artist).should be_true\r
- end\r
- it '実素材はライセンスを含んでいる' do\r
- r = Panel.show_include_opt\r
- r[:panel_pictures][:picture].has_key?(:license).should be_true\r
- end\r
- it 'フキダシを含んでいる' do\r
- r = Panel.show_include_opt\r
- r.has_key?(:speech_balloons).should be_true\r
- end\r
- it 'フキダシはフキダシ枠を含んでいる' do\r
- r = Panel.show_include_opt\r
- r[:speech_balloons].has_key?(:balloons).should be_true\r
- end\r
- it 'フキダシはセリフを含んでいる' do\r
- r = Panel.show_include_opt\r
- r[:speech_balloons].has_key?(:speeches).should be_true\r
- end\r
- it '作家を含んでいる' do\r
- r = Panel.show_include_opt\r
- r.has_key?(:author).should be_true\r
+ it '読者用ロールチェックが失敗したとき、falseを返す' do\r
+ Panel.any_instance.stub(:reader_role_check).and_return(false)\r
+ r = @panel.visible?([@author])\r
+ r.should be_false\r
end\r
end\r
- context 'オプションで原画を含ませたとき' do\r
- it '4つの項目を含んでいる' do\r
- r = Panel.show_include_opt(:include => {:test => {}})\r
- r.should have(4).items\r
+ context '事前チェックする' do\r
+ before do\r
+ MagicNumber['run_mode'] = 1\r
+ Panel.any_instance.stub(:reader_role_check).and_return(true)\r
end\r
- it 'testを含んでいる' do\r
- r = Panel.show_include_opt(:include => {:test => {}})\r
- r.has_key?(:test).should be_true\r
+ it '自身に所持判定を問い合わせしている' do\r
+ Panel.any_instance.stub(:own?).and_return(true)\r
+ Panel.any_instance.should_receive(:own?).with(any_args).exactly(1)\r
+ r = @panel.visible?([@author])\r
end\r
- end\r
- end\r
- describe 'json単体出力オプションに於いて' do\r
- it 'includeキーを含んでいる' do\r
- r = Panel.show_json_include_opt\r
- r.has_key?(:include).should be_true\r
- end\r
- it '3つの項目を含んでいる' do\r
- r = Panel.show_json_include_opt[:include]\r
- r.should have(3).items\r
- end\r
- it 'コマ絵を含んでいる' do\r
- r = Panel.show_json_include_opt[:include]\r
- r.has_key?(:panel_pictures).should be_true\r
- end\r
- it 'コマ絵は実素材を含んでいる' do\r
- r = Panel.show_json_include_opt[:include]\r
- r[:panel_pictures].has_key?(:picture).should be_true\r
+ it '自身に閲覧許可を問い合わせしている' do\r
+ Panel.any_instance.stub(:own?).and_return(false)\r
+ Panel.any_instance.stub(:publish?).and_return(true)\r
+ Panel.any_instance.should_receive(:publish?).with(any_args).exactly(1)\r
+ r = @panel.visible?([@author])\r
end\r
- it '実素材は絵師を含んでいる' do\r
- r = Panel.show_json_include_opt[:include]\r
- r[:panel_pictures][:picture].has_key?(:artist).should be_true\r
- end\r
- it '実素材はライセンスを含んでいる' do\r
- r = Panel.show_json_include_opt[:include]\r
- r[:panel_pictures][:picture].has_key?(:license).should be_true\r
- end\r
- it 'フキダシを含んでいる' do\r
- r = Panel.show_include_opt\r
- r.has_key?(:speech_balloons).should be_true\r
end\r
- it 'フキダシはフキダシ枠を含んでいる' do\r
- r = Panel.show_include_opt\r
- r[:speech_balloons].has_key?(:balloons).should be_true\r
+ context 'つつがなく終わるとき' do\r
+ before do\r
+ MagicNumber['run_mode'] = 1\r
+ Panel.any_instance.stub(:reader_role_check).and_return(true)\r
end\r
- it 'フキダシはセリフを含んでいる' do\r
- r = Panel.show_include_opt\r
- r[:speech_balloons].has_key?(:speeches).should be_true\r
+ it '自分のコマなら許可する' do\r
+ Panel.any_instance.stub(:own?).and_return(true)\r
+ Panel.any_instance.stub(:publish?).and_return(false)\r
+ r = @panel.visible?([@author])\r
+ r.should be_true\r
+ end\r
+ it '他人の非公開コマなら許可しない' do\r
+ Panel.any_instance.stub(:own?).and_return(false)\r
+ Panel.any_instance.stub(:publish?).and_return(false)\r
+ r = @panel.visible?([@author])\r
+ r.should be_false\r
+ end\r
+ it '他人のコマでも公開なら許可する' do\r
+ Panel.any_instance.stub(:own?).and_return(false)\r
+ Panel.any_instance.stub(:publish?).and_return(true)\r
+ r = @panel.visible?([@author])\r
+ r.should be_true\r
end\r
- it '作家を含んでいる' do\r
- r = Panel.show_json_include_opt[:include]\r
- r.has_key?(:author).should be_true\r
end\r
end\r
+ \r
describe '一覧取得に於いて' do\r
before do\r
@panel = FactoryGirl.create :panel, :author_id => @author.id\r
end\r
end\r
it 'リストを返す' do\r
- pl = Panel.list\r
- pl.should eq [@panel]\r
+ r = Panel.list\r
+ r.should eq [@panel]\r
end\r
it '時系列で並んでいる' do\r
- npl = FactoryGirl.create :panel, :author_id => @author.id, :updated_at => Time.now + 100\r
- pl = Panel.list\r
- pl.should eq [npl, @panel]\r
+ #公開コミックは(他人のコミックであっても)含んでいる\r
+ npl = FactoryGirl.create :panel, :author_id => @other_author.id, :updated_at => Time.now + 100\r
+ r = Panel.list\r
+ r.should eq [npl, @panel]\r
end\r
- it '非公開のコマは含まない' do\r
+ it '非公開のコマ(自分のコマであっても)は含まない' do\r
npl = FactoryGirl.create :panel, :author_id => @author.id, :publish => 0\r
- pl = Panel.list\r
- pl.should eq [@panel]\r
+ r = Panel.list\r
+ r.should eq [@panel]\r
end\r
context 'DBに5件あって1ページの件数を2件に変えたとして' do\r
before do\r
end\r
it 'page=1なら末尾2件を返す' do\r
#時系列で並んでいる\r
- pl = Panel.list( {}, 1)\r
+ pl = Panel.list 1\r
pl.should eq [@npl5, @npl4]\r
end\r
it 'page=2なら中間2件を返す' do\r
- pl = Panel.list({}, 2)\r
+ pl = Panel.list 2\r
pl.should eq [@npl3, @npl2]\r
end\r
it 'page=3なら先頭1件を返す' do\r
- pl = Panel.list({}, 3)\r
+ pl = Panel.list 3\r
pl.should eq [@panel]\r
end\r
end\r
end\r
- describe 'list関連テーブルプションに於いて' do\r
- it 'includeキーを含んでいる' do\r
- r = Panel.list_opt\r
- r.has_key?(:include).should be_true\r
- end\r
- it '3つの項目を含んでいる' do\r
- r = Panel.list_opt[:include]\r
- r.should have(3).items\r
- end\r
- it 'コマ絵を含んでいる' do\r
- r = Panel.list_opt[:include]\r
- r.has_key?(:panel_pictures).should be_true\r
- end\r
- it 'コマ絵は実素材を含んでいる' do\r
- r = Panel.list_opt[:include]\r
- r[:panel_pictures].has_key?(:picture).should be_true\r
- end\r
- it '実素材は絵師を含んでいる' do\r
- r = Panel.list_opt[:include]\r
- r[:panel_pictures][:picture].has_key?(:artist).should be_true\r
- end\r
- it '実素材はライセンスを含んでいる' do\r
- r = Panel.list_opt[:include]\r
- r[:panel_pictures][:picture].has_key?(:license).should be_true\r
- end\r
- it 'フキダシを含んでいる' do\r
- r = Panel.show_include_opt\r
- r.has_key?(:speech_balloons).should be_true\r
- end\r
- it 'フキダシはフキダシ枠を含んでいる' do\r
- r = Panel.show_include_opt\r
- r[:speech_balloons].has_key?(:balloons).should be_true\r
- end\r
- it 'フキダシはセリフを含んでいる' do\r
- r = Panel.show_include_opt\r
- r[:speech_balloons].has_key?(:speeches).should be_true\r
- end\r
- it '作家を含んでいる' do\r
- r = Panel.list_opt[:include]\r
- r.has_key?(:author).should be_true\r
- end\r
- end\r
- describe 'json一覧出力オプションに於いて' do\r
- it 'includeキーを含んでいる' do\r
- r = Panel.list_json_opt\r
- r.has_key?(:include).should be_true\r
- end\r
- it '3つの項目を含んでいる' do\r
- r = Panel.list_json_opt[:include]\r
- r.should have(3).items\r
- end\r
- it 'コマ絵を含んでいる' do\r
- r = Panel.list_json_opt[:include]\r
- r.has_key?(:panel_pictures).should be_true\r
- end\r
- it 'コマ絵は実素材を含んでいる' do\r
- r = Panel.list_json_opt[:include]\r
- r[:panel_pictures].has_key?(:picture).should be_true\r
- end\r
- it '実素材は絵師を含んでいる' do\r
- r = Panel.list_json_opt[:include]\r
- r[:panel_pictures][:picture].has_key?(:artist).should be_true\r
- end\r
- it '実素材はライセンスを含んでいる' do\r
- r = Panel.list_json_opt[:include]\r
- r[:panel_pictures][:picture].has_key?(:license).should be_true\r
- end\r
- it 'フキダシを含んでいる' do\r
- r = Panel.show_include_opt\r
- r.has_key?(:speech_balloons).should be_true\r
- end\r
- it 'フキダシはフキダシ枠を含んでいる' do\r
- r = Panel.show_include_opt\r
- r[:speech_balloons].has_key?(:balloons).should be_true\r
- end\r
- it 'フキダシはセリフを含んでいる' do\r
- r = Panel.show_include_opt\r
- r[:speech_balloons].has_key?(:speeches).should be_true\r
- end\r
- it '作家を含んでいる' do\r
- r = Panel.list_json_opt[:include]\r
- r.has_key?(:author).should be_true\r
- end\r
- end\r
\r
describe '自分のコマ一覧取得に於いて' do\r
before do\r
pl = Panel.mylist @author\r
pl.should eq [npl, @panel]\r
end\r
- end\r
- \r
- #異常データ検出\r
- #コマはコミックに従属しなくなったのでtで入れ替えるチェックは要らなくなった\r
- #コマ絵とフキダシの整合チェックをする\r
- describe 'id収集に於いて' do\r
- context 'つつがなく終わるとき' do\r
- it '第一パラメータで指定された配列中から第二引数のidを収集している' do\r
- a = [[{:panel_id => 1, :a => 'a'}, {:panel_id => 2, :a => 'a'}], \r
- [{:panel_id => 3, :a => 'a'}, {:panel_id => 4, :a => 'a'}]]\r
- r = Panel.collect_element_value a, :panel_id\r
- r.should eq [1, 2, 3, 4]\r
+ context 'DBに5件あって1ページの件数を2件に変えたとして' do\r
+ before do\r
+ @npl2 = FactoryGirl.create :panel, :author_id => @author.id, :updated_at => Time.now + 100\r
+ @npl3 = FactoryGirl.create :panel, :author_id => @author.id, :updated_at => Time.now + 200\r
+ @npl4 = FactoryGirl.create :panel, :author_id => @author.id, :updated_at => Time.now + 300\r
+ @npl5 = FactoryGirl.create :panel, :author_id => @author.id, :updated_at => Time.now + 400\r
end\r
- end\r
- context 'Nil除外指示があるとき' do\r
- it '収集したpanel_idのうちnilは除外している' do\r
- a = [[{:panel_id => 1, :a => 'a'}, {:panel_id => 2, :a => 'a'}, {:panel_id => nil, :a => 'a'}], \r
- [{:panel_id => 3, :a => 'a'}, {:panel_id => nil, :a => 'a'}, {:panel_id => 4, :a => 'a'}]]\r
- r = Panel.collect_element_value a, :panel_id, true\r
- r.should eq [1, 2, 3, 4]\r
+ it '通常は2件を返す' do\r
+ pl = Panel.mylist @author, 1, 2\r
+ pl.should have(2).items \r
end\r
- end\r
- end\r
- describe 'id一致チェックに於いて' do\r
- #parent.idがNilのときはすべてNil。数値のときは全一致\r
- context '親が既存(idが数値)のとき' do\r
- it 'すべてid一致するときTrueを返す' do\r
- r = Panel.validate_id [1, 1, 1, 1], 1\r
- r.should be_true\r
+ it 'page=1なら末尾2件を返す' do\r
+ #時系列で並んでいる\r
+ pl = Panel.mylist @author, 1, 2\r
+ pl.should eq [@npl5, @npl4]\r
end\r
- it 'idが一致する中にNilが混じってもTrueを返す' do\r
- r = Panel.validate_id [1, 1, 1, 1, nil], 1\r
- r.should be_true\r
+ it 'page=2なら中間2件を返す' do\r
+ pl = Panel.mylist @author, 2, 2\r
+ pl.should eq [@npl3, @npl2]\r
end\r
- it 'すべて数値でも一致しないときFalseを返す' do\r
- r = Panel.validate_id [1, 1, 1, 1, 2], 1\r
- r.should be_false\r
+ it 'page=3なら先頭1件を返す' do\r
+ pl = Panel.mylist @author, 3, 2\r
+ pl.should eq [@panel]\r
+ end\r
+ end\r
+ end\r
+ \r
+ describe '他作家のコマ一覧取得に於いて' do\r
+ before do\r
+ @panel = FactoryGirl.create :panel, :author_id => @author.id\r
+ @other_panel = FactoryGirl.create :panel, :author_id => @other_author.id, :publish => 1\r
+ end\r
+ it 'リストを返す' do\r
+ r = Panel.himlist @other_author\r
+ r.should eq [@other_panel]\r
+ end\r
+ it '時系列で並んでいる' do\r
+ npl = FactoryGirl.create :panel, :author_id => @other_author.id, :updated_at => Time.now + 100\r
+ r = Panel.himlist @other_author\r
+ r.should eq [npl, @other_panel]\r
+ end\r
+ it '公開コマに限る' do\r
+ npl = FactoryGirl.create :panel, :author_id => @other_author.id, :publish => 0\r
+ r = Panel.himlist @other_author\r
+ r.should eq [@other_panel]\r
+ end\r
+ context 'DBに5件あって1ページの件数を2件に変えたとして' do\r
+ before do\r
+ @other_panel2 = FactoryGirl.create :panel, :author_id => @other_author.id, :updated_at => Time.now + 100\r
+ @other_panel3 = FactoryGirl.create :panel, :author_id => @other_author.id, :updated_at => Time.now + 200\r
+ @other_panel4 = FactoryGirl.create :panel, :author_id => @other_author.id, :updated_at => Time.now + 300\r
+ @other_panel5 = FactoryGirl.create :panel, :author_id => @other_author.id, :updated_at => Time.now + 400\r
+ end\r
+ it '通常は2件を返す' do\r
+ pl = Panel.himlist @other_author, 1, 2\r
+ pl.should have(2).items \r
+ end\r
+ it 'page=1なら末尾2件を返す' do\r
+ #時系列で並んでいる\r
+ pl = Panel.himlist @other_author, 1, 2\r
+ pl.should eq [@other_panel5, @other_panel4]\r
+ end\r
+ it 'page=2なら中間2件を返す' do\r
+ pl = Panel.himlist @other_author, 2, 2\r
+ pl.should eq [@other_panel3, @other_panel2]\r
+ end\r
+ it 'page=3なら先頭1件を返す' do\r
+ pl = Panel.himlist @other_author, 3, 2\r
+ pl.should eq [@other_panel]\r
+ end\r
+ end\r
+ end\r
+ \r
+ describe 'コマ一覧ページ制御に於いて' do\r
+ before do\r
+ Panel.stub(:count).with(any_args).and_return(100)\r
+ end\r
+ it 'ページ制御を返す' do\r
+ r = Panel.list_paginate \r
+ r.is_a?(Kaminari::PaginatableArray).should be_true\r
+ end\r
+ it 'コマ一覧の取得条件を利用している' do\r
+ Panel.stub(:list_where).with(any_args).and_return('')\r
+ Panel.should_receive(:list_where).with(any_args).exactly(1)\r
+ r = Panel.list_paginate \r
+ end\r
+ it 'ページ件数10のとき、3ページ目のオフセットは20から始まる' do\r
+ r = Panel.list_paginate 3, 10\r
+ r.limit_value.should eq 10\r
+ r.offset_value.should eq 20\r
+ end\r
+ end\r
+ \r
+ describe '自分のコマ一覧ページ制御に於いて' do\r
+ before do\r
+ Panel.stub(:count).with(any_args).and_return(100)\r
+ end\r
+ it 'ページ制御を返す' do\r
+ r = Panel.mylist_paginate @author\r
+ r.is_a?(Kaminari::PaginatableArray).should be_true\r
+ end\r
+ it '自分のコマ一覧の取得条件を利用している' do\r
+ Panel.stub(:mylist_where).with(any_args).and_return('')\r
+ Panel.should_receive(:mylist_where).with(any_args).exactly(1)\r
+ r = Panel.mylist_paginate @author\r
+ end\r
+ it 'ページ件数10のとき、3ページ目のオフセットは20から始まる' do\r
+ r = Panel.mylist_paginate @author, 3, 10\r
+ r.limit_value.should eq 10\r
+ r.offset_value.should eq 20\r
+ end\r
+ end\r
+ \r
+ describe '他作家のコマ一覧ページ制御に於いて' do\r
+ before do\r
+ Panel.stub(:count).with(any_args).and_return(100)\r
+ end\r
+ it 'ページ制御を返す' do\r
+ r = Panel.himlist_paginate @other_author\r
+ r.is_a?(Kaminari::PaginatableArray).should be_true\r
+ end\r
+ it '他作家のコマ一覧の取得条件を利用している' do\r
+ Panel.stub(:himlist_where).with(any_args).and_return('')\r
+ Panel.should_receive(:himlist_where).with(any_args).exactly(1)\r
+ r = Panel.himlist_paginate @other_author\r
+ end\r
+ it 'ページ件数10のとき、3ページ目のオフセットは20から始まる' do\r
+ r = Panel.himlist_paginate @other_author, 3, 10\r
+ r.limit_value.should eq 10\r
+ r.offset_value.should eq 20\r
+ end\r
+ end\r
+ \r
+ describe '一覧取得オプションに於いて' do\r
+ it '5つの項目を含んでいる' do\r
+ r = Panel.list_opt\r
+ r.should have(5).items\r
+ end\r
+ it 'コマ絵を含んでいる' do\r
+ r = Panel.list_opt\r
+ r.has_key?(:panel_pictures).should be_true\r
+ end\r
+ it 'コマ絵は実素材を含んでいる' do\r
+ r = Panel.list_opt\r
+ r[:panel_pictures].has_key?(:picture).should be_true\r
+ end\r
+ it '実素材は絵師を含んでいる' do\r
+ r = Panel.list_opt\r
+ r[:panel_pictures][:picture].has_key?(:artist).should be_true\r
+ end\r
+ it '実素材はライセンスを含んでいる' do\r
+ r = Panel.list_opt\r
+ r[:panel_pictures][:picture].has_key?(:license).should be_true\r
+ end\r
+ it 'フキダシを含んでいる' do\r
+ r = Panel.list_opt\r
+ r.has_key?(:speech_balloons).should be_true\r
+ end\r
+ it 'フキダシはフキダシ枠を含んでいる' do\r
+ r = Panel.list_opt\r
+ r[:speech_balloons].has_key?(:balloon).should be_true\r
+ end\r
+ it 'フキダシはセリフを含んでいる' do\r
+ r = Panel.list_opt\r
+ r[:speech_balloons].has_key?(:speech).should be_true\r
+ end\r
+ it '絵地を含んでいる' do\r
+ r = Panel.list_opt\r
+ r.has_key?(:ground_pictures).should be_true\r
+ end\r
+ it '絵地は実素材を含んでいる' do\r
+ r = Panel.list_opt\r
+ r[:ground_pictures].has_key?(:picture).should be_true\r
+ end\r
+ it '実素材は絵師を含んでいる' do\r
+ r = Panel.list_opt\r
+ r[:ground_pictures][:picture].has_key?(:artist).should be_true\r
+ end\r
+ it '実素材はライセンスを含んでいる' do\r
+ r = Panel.list_opt\r
+ r[:ground_pictures][:picture].has_key?(:license).should be_true\r
+ end\r
+ it '色地を含んでいる' do\r
+ r = Panel.list_opt\r
+ r.has_key?(:ground_colors).should be_true\r
+ end\r
+ it '作家を含んでいる' do\r
+ r = Panel.list_opt\r
+ r.has_key?(:author).should be_true\r
+ end\r
+ end\r
+ describe 'json一覧出力オプションに於いて' do\r
+ end\r
+ \r
+ describe '単体取得に於いて' do\r
+ before do\r
+ @panel = FactoryGirl.create :panel, :author_id => @author.id\r
+ end\r
+ context 'つつがなく終わるとき' do\r
+ it '単体取得オプションを利用している' do\r
+ Panel.stub(:show_opt).with(any_args).and_return({})\r
+ Panel.should_receive(:show_opt).with(any_args).exactly(1)\r
+ r = Panel.show @panel.id, @author\r
+ end\r
+ it '閲覧許可を問い合わせている' do\r
+ Panel.any_instance.stub(:visible?).with(any_args).and_return(true)\r
+ Panel.any_instance.should_receive(:visible?).with(any_args).exactly(1)\r
+ r = Panel.show @panel.id, @author\r
+ end\r
+ end\r
+ it '指定のコマを返す' do\r
+ Panel.any_instance.stub(:visible?).and_return(true)\r
+ pl = Panel.show @panel.id, @author\r
+ pl.should eq @panel\r
+ end\r
+ context '閲覧許可が出なかったとき' do\r
+ it '403Forbidden例外を返す' do\r
+ Panel.any_instance.stub(:visible?).and_return(false)\r
+ lambda{\r
+ Panel.show @panel.id, @author\r
+ }.should raise_error(ActiveRecord::Forbidden)\r
+ end\r
+ end\r
+ context '存在しないコマを開こうとしたとき' do\r
+ it '404RecordNotFound例外を返す' do\r
+ lambda{\r
+ Panel.show 110, @author\r
+ }.should raise_error(ActiveRecord::RecordNotFound)\r
+ end\r
+ end\r
+ end\r
+ describe '編集取得に於いて' do\r
+ before do\r
+ @panel = FactoryGirl.create :panel, :author_id => @author.id\r
+ end\r
+ context 'つつがなく終わるとき' do\r
+ it '単体取得オプションを利用している' do\r
+ Panel.stub(:show_opt).with(any_args).and_return({})\r
+ Panel.should_receive(:show_opt).with(any_args).exactly(1)\r
+ r = Panel.edit @panel.id, @author\r
+ end\r
+ it '所持判定を問い合わせている' do\r
+ Panel.any_instance.stub(:own?).with(any_args).and_return(true)\r
+ Panel.any_instance.should_receive(:own?).with(any_args).exactly(1)\r
+ r = Panel.edit @panel.id, @author\r
+ end\r
+ end\r
+ it '指定のコマを返す' do\r
+ Panel.any_instance.stub(:own?).and_return(true)\r
+ pl = Panel.edit @panel.id, @author\r
+ pl.should eq @panel\r
+ end\r
+ context '他人のコマを開こうとしたとき' do\r
+ it '403Forbidden例外を返す' do\r
+ Panel.any_instance.stub(:own?).and_return(false)\r
+ lambda{\r
+ Panel.edit @panel.id, @author\r
+ }.should raise_error(ActiveRecord::Forbidden)\r
+ end\r
+ end\r
+ context '存在しないコマを開こうとしたとき' do\r
+ it '404RecordNotFound例外を返す' do\r
+ lambda{\r
+ Panel.edit 110, @author\r
+ }.should raise_error(ActiveRecord::RecordNotFound)\r
+ end\r
+ end\r
+ end\r
+ describe '単体取得オプションに於いて' do\r
+ it 'includeキーを含んでいる' do\r
+ r = Panel.show_opt\r
+ r.has_key?(:include).should be_true\r
+ end\r
+ it '5つの項目を含んでいる' do\r
+ r = Panel.show_opt[:include]\r
+ r.should have(5).items\r
+ end\r
+ it 'コマ絵を含んでいる' do\r
+ r = Panel.show_opt[:include]\r
+ r.has_key?(:panel_pictures).should be_true\r
+ end\r
+ it 'コマ絵は実素材を含んでいる' do\r
+ r = Panel.show_opt[:include]\r
+ r[:panel_pictures].has_key?(:picture).should be_true\r
+ end\r
+ it '実素材は絵師を含んでいる' do\r
+ r = Panel.show_opt[:include]\r
+ r[:panel_pictures][:picture].has_key?(:artist).should be_true\r
+ end\r
+ it '実素材はライセンスを含んでいる' do\r
+ r = Panel.show_opt[:include]\r
+ r[:panel_pictures][:picture].has_key?(:license).should be_true\r
+ end\r
+ it 'フキダシを含んでいる' do\r
+ r = Panel.show_opt[:include]\r
+ r.has_key?(:speech_balloons).should be_true\r
+ end\r
+ it 'フキダシはフキダシ枠を含んでいる' do\r
+ r = Panel.show_opt[:include]\r
+ r[:speech_balloons].has_key?(:balloon).should be_true\r
+ end\r
+ it 'フキダシはセリフを含んでいる' do\r
+ r = Panel.show_opt[:include]\r
+ r[:speech_balloons].has_key?(:speech).should be_true\r
+ end\r
+ it '絵地を含んでいる' do\r
+ r = Panel.show_opt[:include]\r
+ r.has_key?(:ground_pictures).should be_true\r
+ end\r
+ it '絵地は実素材を含んでいる' do\r
+ r = Panel.show_opt[:include]\r
+ r[:ground_pictures].has_key?(:picture).should be_true\r
+ end\r
+ it '実素材は絵師を含んでいる' do\r
+ r = Panel.show_opt[:include]\r
+ r[:ground_pictures][:picture].has_key?(:artist).should be_true\r
+ end\r
+ it '実素材はライセンスを含んでいる' do\r
+ r = Panel.show_opt[:include]\r
+ r[:ground_pictures][:picture].has_key?(:license).should be_true\r
+ end\r
+ it '色地を含んでいる' do\r
+ r = Panel.show_opt[:include]\r
+ r.has_key?(:ground_colors).should be_true\r
+ end\r
+ it '作家を含んでいる' do\r
+ r = Panel.show_opt[:include]\r
+ r.has_key?(:author).should be_true\r
+ end\r
+ end\r
+ describe 'json単体出力オプションに於いて' do\r
+ end\r
+ describe 'コマ部品集合に於いて' do\r
+ before do\r
+ #コマを作成しておく。\r
+ @panel = FactoryGirl.create :panel, :author_id => @author.id\r
+ @pp = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 1, :width => @p.width, :height => @p.height\r
+ @sb = @panel.speech_balloons.create(\r
+ FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 0)\r
+ )\r
+ @gc = @panel.ground_colors.create(\r
+ FactoryGirl.attributes_for(:ground_color, :panel_id => @panel.id, :t => 2)\r
+ )\r
+ @gp = @panel.ground_pictures.create(\r
+ FactoryGirl.attributes_for(:ground_picture, :panel_id => @panel.id, :picture_id => @p.id, :t => 3)\r
+ )\r
+ @panel.reload\r
+ end\r
+ it 'リストを返している' do\r
+ r = @panel.parts_element\r
+ r.is_a?(Array).should be_true\r
+ end\r
+ it 'コマ絵とフキダシと絵地と色地を合わせている' do\r
+ r = @panel.parts_element\r
+ r.include?(@pp).should be_true\r
+ r.include?(@sb).should be_true\r
+ r.include?(@gc).should be_true\r
+ r.include?(@gp).should be_true\r
+ end\r
+ end\r
+ describe 'コマ部品に於いて' do\r
+ before do\r
+ #コマを作成しておく。\r
+ @panel = FactoryGirl.create :panel, :author_id => @author.id\r
+ @pp = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 1, :width => @p.width, :height => @p.height\r
+ @sb = @panel.speech_balloons.create(\r
+ FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 0)\r
+ )\r
+ @gc = @panel.ground_colors.create(\r
+ FactoryGirl.attributes_for(:ground_color, :panel_id => @panel.id, :t => 2)\r
+ )\r
+ @gp = @panel.ground_pictures.create(\r
+ FactoryGirl.attributes_for(:ground_picture, :panel_id => @panel.id, :picture_id => @p.id, :t => 3)\r
+ )\r
+ @panel.reload\r
+ end\r
+ context 'つつがなく終わるとき' do\r
+ it 'コマ部品集合を利用している' do\r
+ Panel.any_instance.stub(:parts_element).with(any_args).and_return([])\r
+ Panel.any_instance.should_receive(:parts_element).with(any_args).exactly(1)\r
+ r = @panel.parts\r
+ end\r
+ end\r
+ it 'リストを返している' do\r
+ r = @panel.parts\r
+ r.is_a?(Array).should be_true\r
+ r.size.should eq 4\r
+ end\r
+ it 'tでソートしている' do\r
+ r = @panel.parts\r
+ r[0].should eq @sb\r
+ r[1].should eq @pp\r
+ r[2].should eq @gc\r
+ r[3].should eq @gp\r
+ end\r
+ context 'さらに末尾にフキダシを追加したとき' do\r
+ before do\r
+ @sb2 = @panel.speech_balloons.create(\r
+ FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 4)\r
+ )\r
+ @panel.reload\r
+ end\r
+ it 'tでソートしている' do\r
+ r = @panel.parts\r
+ r[0].should eq @sb\r
+ r[1].should eq @pp\r
+ r[2].should eq @gc\r
+ r[3].should eq @gp\r
+ r[4].should eq @sb2\r
+ end\r
+ end\r
+ end\r
+ describe 'コマ要素に於いて' do\r
+ before do\r
+ #コマを作成しておく。\r
+ @panel = FactoryGirl.create :panel, :author_id => @author.id\r
+ @pp = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 1, :width => @p.width, :height => @p.height\r
+ @sb = @panel.speech_balloons.create(\r
+ FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 0)\r
+ )\r
+ @gc = @panel.ground_colors.create(\r
+ FactoryGirl.attributes_for(:ground_color, :panel_id => @panel.id, :t => 2)\r
+ )\r
+ @gp = @panel.ground_pictures.create(\r
+ FactoryGirl.attributes_for(:ground_picture, :panel_id => @panel.id, :picture_id => @p.id, :t => 3)\r
+ )\r
+ @panel.reload\r
+ end\r
+ context 'つつがなく終わるとき' do\r
+ it 'コマ部品を利用している' do\r
+ Panel.any_instance.stub(:parts).with(any_args).and_return([])\r
+ Panel.any_instance.should_receive(:parts).with(any_args).exactly(1)\r
+ r = @panel.panel_elements\r
+ end\r
+ end\r
+ it 'リストを返している' do\r
+ r = @panel.panel_elements\r
+ r.is_a?(Array).should be_true\r
+ end\r
+ it 'tでソートしている' do\r
+ r = @panel.panel_elements\r
+ r[0].should eq @sb\r
+ r[1].should eq @pp\r
+ r[2].should eq @gc\r
+ r[3].should eq @gp\r
+ end\r
+ end\r
+ describe 'コマ要素のjson出力に於いて' do\r
+ before do\r
+ #コマを作成しておく。\r
+ @panel = FactoryGirl.create :panel, :author_id => @author.id\r
+ @pp = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 1, :width => @p.width, :height => @p.height\r
+ @sb = @panel.speech_balloons.create(\r
+ FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 0)\r
+ )\r
+ @gc = @panel.ground_colors.create(\r
+ FactoryGirl.attributes_for(:ground_color, :panel_id => @panel.id, :t => 2)\r
+ )\r
+ @gp = @panel.ground_pictures.create(\r
+ FactoryGirl.attributes_for(:ground_picture, :panel_id => @panel.id, :picture_id => @p.id, :t => 3)\r
+ )\r
+ @panel.reload\r
+ end\r
+ context 'つつがなく終わるとき' do\r
+ before do\r
+ Panel.stub(:elm_json_opt).with(@pp).and_return({})\r
+ Panel.stub(:elm_json_opt).with(@sb).and_return({})\r
+ Panel.stub(:elm_json_opt).with(@gp).and_return({})\r
+ Panel.stub(:elm_json_opt).with(@gc).and_return({})\r
+ end\r
+ it 'コマ要素のjson出力オプションにコマ絵json出力オプションを依頼している' do\r
+ Panel.should_receive(:elm_json_opt).with(@pp).exactly(1)\r
+ r = @panel.elements\r
+ end\r
+ it 'コマ要素のjson出力オプションにフキダシjson出力オプションを依頼している' do\r
+ Panel.should_receive(:elm_json_opt).with(@sb).exactly(1)\r
+ r = @panel.elements\r
+ end\r
+ it 'コマ要素のjson出力オプションに絵地json出力オプションを依頼している' do\r
+ Panel.should_receive(:elm_json_opt).with(@gp).exactly(1)\r
+ r = @panel.elements\r
+ end\r
+ it 'コマ要素のjson出力オプションに色地json出力オプションを依頼している' do\r
+ Panel.should_receive(:elm_json_opt).with(@gc).exactly(1)\r
+ r = @panel.elements\r
+ end\r
+ end\r
+ it 'リストを返している' do\r
+ r = @panel.elements\r
+ r.is_a?(Array).should be_true\r
+ end\r
+ end\r
+ describe 'コマのjson出力に於いて' do\r
+ before do\r
+ #コマを作成しておく。\r
+ @panel = FactoryGirl.create :panel, :author_id => @author.id\r
+ @pp = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 1, :width => @p.width, :height => @p.height\r
+ @sb = @panel.speech_balloons.create(\r
+ FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 0)\r
+ )\r
+ @sb.create_balloon(\r
+ FactoryGirl.attributes_for(:balloon, :speech_balloon_id => @sb.id)\r
+ )\r
+ @sb.create_speech(\r
+ FactoryGirl.attributes_for(:speech, :speech_balloon_id => @sb.id)\r
+ )\r
+ @gc = @panel.ground_colors.create(\r
+ FactoryGirl.attributes_for(:ground_color, :panel_id => @panel.id, :t => 2)\r
+ )\r
+ @gp = @panel.ground_pictures.create(\r
+ FactoryGirl.attributes_for(:ground_picture, :panel_id => @panel.id, :picture_id => @p.id, :t => 3)\r
+ )\r
+ @panel.reload\r
+ end\r
+ context 'つつがなく終わるとき' do\r
+ before do\r
+ Panel.any_instance.stub(:elements).with(any_args).and_return({})\r
+ end\r
+ it 'コマ要素のjson出力を依頼している' do\r
+ Panel.any_instance.should_receive(:elements).with(any_args).exactly(1)\r
+ r = @panel.panel_elements_as_json\r
+ end\r
+ end\r
+ it 'json textを返している' do\r
+ r = JSON.parse @panel.panel_elements_as_json\r
+ r.is_a?(Hash).should be_true\r
+ end\r
+ it 'author,コマ要素を含んでいる' do\r
+ r = JSON.parse @panel.panel_elements_as_json\r
+ r.has_key?('author').should be_true\r
+ r.has_key?('elements').should be_true\r
+ #t:0\r
+ sb = r['elements'].first\r
+ sb.has_key?('classname').should be_true\r
+ sb.has_key?('balloon').should be_true\r
+ sb.has_key?('speech').should be_true\r
+ #t:1\r
+ end\r
+ end\r
+ describe 'コマリストのjson出力に於いて' do\r
+ before do\r
+ @panel = FactoryGirl.create :panel, :author_id => @author.id\r
+ Panel.any_instance.stub(:panel_elements_as_json).with(any_args).and_return('{"p": 5}')\r
+ end\r
+ context 'つつがなく終わるとき' do\r
+ it 'コマのjson出力を依頼している' do\r
+ Panel.any_instance.should_receive(:panel_elements_as_json).with(any_args).exactly(1)\r
+ r = Panel.list_as_json_text [@panel]\r
+ end\r
+ end\r
+ it 'json textを返している' do\r
+ r = Panel.list_as_json_text [@panel]\r
+ j = JSON.parse r\r
+ j.is_a?(Array).should be_true\r
+ end\r
+ it 'コマを含んでいる' do\r
+ r = Panel.list_as_json_text [@panel]\r
+ j = JSON.parse r\r
+ j.first.has_key?('p').should be_true\r
+ end\r
+ end\r
+ \r
+ describe 'ライセンス素材に於いて' do\r
+ before do\r
+ #コマを作成しておく。\r
+ @op2 = FactoryGirl.create :original_picture, :artist_id => @artist.id\r
+ @p2 = FactoryGirl.create :picture, :original_picture_id => @op2.id, :license_id => @license.id, :artist_id => @artist.id\r
+ @rp2 = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op2.id, :picture_id => @p2.id\r
+ @panel = FactoryGirl.create :panel, :author_id => @author.id\r
+ @pp = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 1, :width => @p.width, :height => @p.height, :picture_id => @p.id\r
+ @sb = @panel.speech_balloons.create(\r
+ FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 0)\r
+ )\r
+ @gc = @panel.ground_colors.create(\r
+ FactoryGirl.attributes_for(:ground_color, :panel_id => @panel.id, :t => 2)\r
+ )\r
+ @gp = @panel.ground_pictures.create(\r
+ FactoryGirl.attributes_for(:ground_picture, :panel_id => @panel.id, :picture_id => @p2.id, :t => 3)\r
+ )\r
+ @panel.reload\r
+ end\r
+ context '事前チェック' do\r
+ end\r
+ context 'つつがなく終わるとき' do\r
+ end\r
+ it '連想配列(値は実素材、キーは実素材id)を返している' do\r
+ r = @panel.licensed_pictures\r
+ r.is_a?(Hash).should be_true\r
+ r.should have(2).items\r
+ r[@pp.picture_id].should eq @p\r
+ r[@gp.picture_id].should eq @p2\r
+ end\r
+ end\r
+ \r
+ describe '検証値収集に於いて' do\r
+ context 'つつがなく終わるとき' do\r
+ it '第一パラメータで指定された配列中から第二引数のカラム値を収集している' do\r
+ elements = [[{:panel_id => 1, :a => 'a'}, {:panel_id => 2, :a => 'a'}], \r
+ [{:panel_id => 3, :a => 'a'}, {:panel_id => 4, :a => 'a'}]]\r
+ r = Panel.collect_element_value elements, :panel_id\r
+ r.should eq [1, 2, 3, 4]\r
+ end\r
+ it '第一パラメータで指定された配列中から第二引数のカラム値を収集している' do\r
+ elements = [[{:t => 1, :a => 'a'}, {:t => 2, :a => 'a'}], \r
+ [{:t => 3, :a => 'a'}, {:t => 0, :a => 'a'}]]\r
+ r = Panel.collect_element_value elements, :t\r
+ r.should eq [1, 2, 3, 0]\r
+ end\r
+ end\r
+ end\r
+ describe 'シリアライズチェックに於いて' do\r
+ context 'つつがなく終わるとき' do\r
+ it '0からシリアライズされているならTrueを返す' do\r
+ r = Panel.validate_serial [0, 1, 2]\r
+ r.should be_true\r
+ end\r
+ it '見た目はシリアライズされてなくてもソート結果が無事ならtrueを返す' do\r
+ r = Panel.validate_serial [0, 2, 1]\r
+ r.should be_true\r
+ end\r
+ it '見た目はシリアライズされてなくてもソート結果が無事ならtrueを返す' do\r
+ r = Panel.validate_serial [ 2, 1, 4, 3, 0]\r
+ r.should be_true\r
+ end\r
+ end\r
+ context 'オフセットが1のとき' do\r
+ it '0からシリアライズされているならFalseを返す' do\r
+ r = Panel.validate_serial [0, 1, 2], 1\r
+ r.should be_false\r
+ end\r
+ it '1からシリアライズされているならTrueを返す' do\r
+ r = Panel.validate_serial [1, 2, 3], 1\r
+ r.should be_true\r
+ end\r
+ end\r
+ context '異常なとき' do\r
+ it '0から始まらないならFalseを返す' do\r
+ r = Panel.validate_serial [1, 2, 3]\r
+ r.should be_false\r
+ end\r
+ it '連続していないならFalseを返す' do\r
+ r = Panel.validate_serial [0, 1, 2, 4]\r
+ r.should be_false\r
+ end\r
+ it '連続していないならFalseを返す' do\r
+ r = Panel.validate_serial [0, 1, 2, 4, 5]\r
+ r.should be_false\r
+ end\r
+ end\r
+ end\r
+ describe 'シリアライズチェック単体に於いて' do\r
+ before do\r
+ end\r
+ context 'つつがなく終わるとき' do\r
+ it '検証値収集を依頼している' do\r
+ Panel.should_receive(:collect_element_value).with(any_args).exactly(1)\r
+ Panel.stub(:collect_element_value).with(any_args).and_return([])\r
+ Panel.stub(:validate_serial).with(any_args).and_return(true)\r
+ r = Panel.validate_element_serial [], :t\r
+ end\r
+ it 'シリアライズチェック依頼している' do\r
+ Panel.stub(:collect_element_value).with(any_args).and_return([])\r
+ Panel.should_receive(:validate_serial).with(any_args).exactly(1)\r
+ Panel.stub(:validate_serial).with(any_args).and_return(true)\r
+ r = Panel.validate_element_serial [], :t\r
+ end\r
+ end\r
+ end\r
+ describe '従属データの検証に於いて' do\r
+ context 'つつがなく終わるとき' do\r
+ it 'trueを返している' do\r
+ @panel = FactoryGirl.build :panel, :author_id => @author.id\r
+ @panel.panel_pictures.build(\r
+ FactoryGirl.attributes_for(:panel_picture, :panel_id => @panel.id, :picture_id => @p.id, :t => 0, :z => 0+1)\r
+ )\r
+ @panel.panel_pictures.build(\r
+ FactoryGirl.attributes_for(:panel_picture, :panel_id => @panel.id, :picture_id => @p.id, :t => 1, :z => 1+1)\r
+ )\r
+ sb1 = @panel.speech_balloons.build(\r
+ FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 2, :z => 2+1)\r
+ )\r
+ sb1.build_balloon(\r
+ FactoryGirl.attributes_for(:balloon, :speech_balloon_id => sb1.id)\r
+ )\r
+ sb1.build_speech(\r
+ FactoryGirl.attributes_for(:speech, :speech_balloon_id => sb1.id)\r
+ )\r
+ sb2 = @panel.speech_balloons.build(\r
+ FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 3, :z => 3+1)\r
+ )\r
+ sb2.build_balloon(\r
+ FactoryGirl.attributes_for(:balloon, :speech_balloon_id => sb2.id)\r
+ )\r
+ sb2.build_speech(\r
+ FactoryGirl.attributes_for(:speech, :speech_balloon_id => sb2.id)\r
+ )\r
+ @gc = @panel.ground_colors.build(\r
+ FactoryGirl.attributes_for(:ground_color, :panel_id => @panel.id, :t => 4, :z => 4+1)\r
+ )\r
+ @gp = @panel.ground_pictures.build(\r
+ FactoryGirl.attributes_for(:ground_picture, :panel_id => @panel.id, :picture_id => @p.id, :t => 5, :z => 5+1)\r
+ )\r
+ r = @panel.validate_child\r
+ r.should be_true\r
+ end\r
+ end\r
+ context 'tシリアライズされていないとき' do\r
+ it 'falseを返している' do\r
+ @panel = FactoryGirl.build :panel, :author_id => @author.id\r
+ @panel.panel_pictures.build(\r
+ FactoryGirl.attributes_for(:panel_picture, :panel_id => @panel.id, :picture_id => @p.id, :t => 0, :z => 0+1)\r
+ )\r
+ @panel.panel_pictures.build(\r
+ FactoryGirl.attributes_for(:panel_picture, :panel_id => @panel.id, :picture_id => @p.id, :t => 1, :z => 1+1)\r
+ )\r
+ sb1 = @panel.speech_balloons.build(\r
+ FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 2, :z => 2+1)\r
+ )\r
+ sb1.build_balloon(\r
+ FactoryGirl.attributes_for(:balloon, :speech_balloon_id => sb1.id)\r
+ )\r
+ sb1.build_speech(\r
+ FactoryGirl.attributes_for(:speech, :speech_balloon_id => sb1.id)\r
+ )\r
+ sb2 = @panel.speech_balloons.build(\r
+ FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 4, :z => 3+1)\r
+ )\r
+ sb2.build_balloon(\r
+ FactoryGirl.attributes_for(:balloon, :speech_balloon_id => sb2.id)\r
+ )\r
+ sb2.build_speech(\r
+ FactoryGirl.attributes_for(:speech, :speech_balloon_id => sb2.id)\r
+ )\r
+ @gc = @panel.ground_colors.build(\r
+ FactoryGirl.attributes_for(:ground_color, :panel_id => @panel.id, :t => 4, :z => 4+1)\r
+ )\r
+ @gp = @panel.ground_pictures.build(\r
+ FactoryGirl.attributes_for(:ground_picture, :panel_id => @panel.id, :picture_id => @p.id, :t => 5, :z => 5+1)\r
+ )\r
+ r = @panel.validate_child\r
+ r.should be_false\r
+ end\r
+ end\r
+ context 'zシリアライズされていないとき' do\r
+ it 'falseを返している' do\r
+ @panel = FactoryGirl.build :panel, :author_id => @author.id\r
+ @panel.panel_pictures.build(\r
+ FactoryGirl.attributes_for(:panel_picture, :panel_id => @panel.id, :picture_id => @p.id, :t => 0, :z => 0+1)\r
+ )\r
+ @panel.panel_pictures.build(\r
+ FactoryGirl.attributes_for(:panel_picture, :panel_id => @panel.id, :picture_id => @p.id, :t => 1, :z => 0+1)\r
+ )\r
+ sb1 = @panel.speech_balloons.build(\r
+ FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 2, :z => 2+1)\r
+ )\r
+ sb1.build_balloon(\r
+ FactoryGirl.attributes_for(:balloon, :speech_balloon_id => sb1.id)\r
+ )\r
+ sb1.build_speech(\r
+ FactoryGirl.attributes_for(:speech, :speech_balloon_id => sb1.id)\r
+ )\r
+ sb2 = @panel.speech_balloons.build(\r
+ FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 3, :z => 3+1)\r
+ )\r
+ sb2.build_balloon(\r
+ FactoryGirl.attributes_for(:balloon, :speech_balloon_id => sb2.id)\r
+ )\r
+ sb2.build_speech(\r
+ FactoryGirl.attributes_for(:speech, :speech_balloon_id => sb2.id)\r
+ )\r
+ @gc = @panel.ground_colors.build(\r
+ FactoryGirl.attributes_for(:ground_color, :panel_id => @panel.id, :t => 4, :z => 4+1)\r
+ )\r
+ @gp = @panel.ground_pictures.build(\r
+ FactoryGirl.attributes_for(:ground_picture, :panel_id => @panel.id, :picture_id => @p.id, :t => 5, :z => 5+1)\r
+ )\r
+ r = @panel.validate_child\r
+ r.should be_false\r
+ end\r
+ end\r
+ end\r
+ describe '保存に於いて' do\r
+ before do\r
+ @attr = FactoryGirl.attributes_for :panel\r
+ @panel = Panel.new\r
+ @panel.supply_default\r
+ end\r
+ context 'つつがなく終わるとき' do\r
+ before do\r
+ Panel.any_instance.stub(:validate_child).with(any_args).and_return(true)\r
+ Panel.any_instance.stub(:save).with(any_args).and_return(true)\r
+ end\r
+ it 'コマモデルに上書き補充を依頼している' do\r
+ Panel.any_instance.should_receive(:overwrite).exactly(1)\r
+ r = @panel.store @attr, @author\r
+ end\r
+ it '保存を依頼している' do\r
+ Panel.any_instance.should_receive(:save).with(any_args).exactly(1)\r
+ @panel = FactoryGirl.build :panel, :author_id => @author.id\r
+ r = @panel.store @attr, @author\r
+ end\r
+ it '従属データの検証を依頼している' do\r
+ Panel.any_instance.should_receive(:validate_child).with(any_args).exactly(1)\r
+ r = @panel.store @attr, @author\r
+ end\r
+ end\r
+ context 'つつがなく終わるとき' do\r
+ before do\r
+ Panel.any_instance.stub(:validate_child).with(any_args).and_return(true)\r
+ end\r
+ it 'Trueを返す' do\r
+ r = @panel.store @attr, @author\r
+ r.should be_true\r
+ end\r
+ it '行が追加されている' do\r
+ Panel.any_instance.stub(:validate_child).with(any_args).and_return(true)\r
+ lambda {\r
+ r = @panel.store @attr, @author\r
+ }.should change(Panel, :count)\r
+ end\r
+ end\r
+ context '不正なjsonデータのとき' do\r
+ before do\r
+ end\r
+ it 'エラーメッセージがセットされている' do\r
+ r = @panel.store false, @author\r
+ @panel.errors[:base].should_not be_blank\r
+ end\r
+ end\r
+ context '従属データの検証に失敗したとき' do\r
+ before do\r
+ Panel.any_instance.stub(:save).with(any_args).and_return(true)\r
+ Panel.any_instance.stub(:validate_child).with(any_args).and_return(false)\r
+ end\r
+ it 'エラーメッセージがセットされている' do\r
+ r = @panel.store @attr, @author\r
+ @panel.errors[:base].should_not be_blank\r
+ end\r
+ end\r
+ context 'カラム値がFalseしたとき' do\r
+ before do\r
+ Panel.any_instance.stub(:validate_child).with(any_args).and_return(true)\r
+ end\r
+ it 'エラーメッセージがセットされている' do\r
+ r = @panel.store false, @author\r
+ @panel.errors.should_not be_empty\r
+ end\r
+ end\r
+ end\r
+ \r
+ describe '削除に於いて' do\r
+ before do\r
+ @comic = FactoryGirl.create :comic, :author_id => @author.id\r
+ @panel = FactoryGirl.create :panel, :author_id => @author.id, :publish => 1\r
+ @pp = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 1, :width => @p.width, :height => @p.height\r
+ @sb = @panel.speech_balloons.create(\r
+ FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 0)\r
+ )\r
+ @gc = @panel.ground_colors.create(\r
+ FactoryGirl.attributes_for(:ground_color, :panel_id => @panel.id)\r
+ )\r
+ @gp = @panel.ground_pictures.create(\r
+ FactoryGirl.attributes_for(:ground_picture, :panel_id => @panel.id, :picture_id => @p.id)\r
+ )\r
+ end\r
+ context 'つつがなく終わるとき' do\r
+ it '自身を削除する' do\r
+ lambda {\r
+ r = @panel.destroy_with_elements\r
+ }.should change(Panel, :count).by(-1)\r
+ lambda {\r
+ r = Panel.find @panel.id\r
+ }.should raise_error\r
+ end\r
+ it '自身にリンクしているコマ要素をすべて削除する' do\r
+ lambda {\r
+ r = @panel.destroy_with_elements\r
+ }.should change(PanelPicture, :count).by(-1)\r
+ lambda {\r
+ r = PanelPicture.find @pp.id\r
+ }.should raise_error \r
+ end\r
+ it '自身にリンクしているコマ要素をすべて削除する' do\r
+ lambda {\r
+ r = @panel.destroy_with_elements\r
+ }.should change(GroundPicture, :count).by(-1)\r
+ lambda {\r
+ r = GroundPicture.find @gp.id\r
+ }.should raise_error \r
+ end\r
+ it 'Trueを返す' do\r
+ r = @panel.destroy_with_elements\r
+ r.should be_true\r
+ end\r
+ end\r
+ context '削除に失敗したとき' do\r
+ before do\r
+ PanelPicture.any_instance.stub(:destroy).with(any_args).and_return(false)\r
+ end\r
+ it 'Falseを返す' do\r
+ r = @panel.destroy_with_elements\r
+ r.should be_false\r
+ end\r
+ it 'ロールバックしている' do\r
+ lambda {\r
+ r = @panel.destroy_with_elements\r
+ }.should_not change(Panel, :count)\r
+ lambda {\r
+ r = @panel.destroy_with_elements\r
+ }.should_not change(PanelPicture, :count)\r
+ end\r
+ end\r
+ end\r
+=begin\r
+ describe 'id挿げ替え防止確認に於いて' do\r
+ before do\r
+ #コマを作成しておく。\r
+ @panel = FactoryGirl.create :panel, :author_id => @author.id\r
+ @pp = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 1, :width => @p.width, :height => @p.height\r
+ @sb = @panel.speech_balloons.create(\r
+ FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 0)\r
+ )\r
+ @gc = @panel.ground_colors.create(\r
+ FactoryGirl.attributes_for(:ground_color, :panel_id => @panel.id, :color_id => @color.id)\r
+ )\r
+ @gp = @panel.ground_pictures.create(\r
+ FactoryGirl.attributes_for(:ground_picture, :panel_id => @panel.id, :picture_id => @p.id)\r
+ )\r
+ @pc = @panel.panel_colors.create(\r
+ FactoryGirl.attributes_for(:panel_color, :panel_id => @panel.id, :code => 0xff0000)\r
+ )\r
+ @panel.reload\r
+ end\r
+ it 'author,コマ要素を含んでいる' do\r
+ @panel2 = FactoryGirl.create :panel, :author_id => @author.id\r
+ @panel2.panel_pictures.create(\r
+ FactoryGirl.attributes_for(:panel_picture, :panel_id => @panel.id, :t => 1, :width => @p.width, :height => @p.height)\r
+ )\r
+ @panel2.save!\r
+ end\r
+ end\r
+ describe 'id一致チェックに於いて' do\r
+ #parent.idがNilのときはすべてNil。数値のときは全一致\r
+ context '親が既存(idが数値)のとき' do\r
+ it 'すべてid一致するときTrueを返す' do\r
+ r = Panel.validate_id [1, 1, 1, 1], 1\r
+ r.should be_true\r
+ end\r
+ it 'idが一致する中にNilが混じってもTrueを返す' do\r
+ r = Panel.validate_id [1, 1, 1, 1, nil], 1\r
+ r.should be_true\r
+ end\r
+ it 'すべて数値でも一致しないときFalseを返す' do\r
+ r = Panel.validate_id [1, 1, 1, 1, 2], 1\r
+ r.should be_false\r
end\r
it '数値とNilが混ざってもIDが一致しないときFalseを返す' do\r
r = Panel.validate_id [1, 1, nil, 2], 1\r
end\r
end\r
end\r
- describe 'シリアライズチェックに於いて' do\r
- context 'つつがなく終わるとき' do\r
- it '0からシリアライズされているならTrueを返す' do\r
- r = Panel.validate_t [0, 1, 2]\r
- r.should be_true\r
- end\r
- it '見た目はシリアライズされてなくてもソート結果が無事ならtrueを返す' do\r
- r = Panel.validate_t [0, 2, 1]\r
- r.should be_true\r
- end\r
- it '見た目はシリアライズされてなくてもソート結果が無事ならtrueを返す' do\r
- r = Panel.validate_t [ 2, 1, 4, 3, 0]\r
- r.should be_true\r
- end\r
- end\r
- context '異常なとき' do\r
- it '0から始まらないならFalseを返す' do\r
- r = Panel.validate_t [1, 2, 3]\r
- r.should be_false\r
- end\r
- it '連続していないならFalseを返す' do\r
- r = Panel.validate_t [0, 1, 2, 4]\r
- r.should be_false\r
- end\r
- it '連続していないならFalseを返す' do\r
- r = Panel.validate_t [0, 1, 2, 4, 5]\r
- r.should be_false\r
- end\r
- end\r
- end\r
- describe 'tチェック単体に於いて' do\r
- before do\r
- end\r
- context 'つつがなく終わるとき' do\r
- it 'コマ絵とフキダシのtを収集依頼している' do\r
- Panel.should_receive(:collect_element_value).with(any_args).exactly(1)\r
- Panel.stub(:collect_element_value).with(any_args).and_return([])\r
- Panel.stub(:validate_t).with(any_args).and_return(true)\r
- r = Panel.validate_element_t [], :t\r
- end\r
- it '収集したtをシリアライズチェック依頼している' do\r
- Panel.stub(:collect_element_value).with(any_args).and_return([])\r
- Panel.should_receive(:validate_t).with(any_args).exactly(1)\r
- Panel.stub(:validate_t).with(any_args).and_return(true)\r
- r = Panel.validate_element_t [], :t\r
- end\r
- end\r
- #実データでチェック\r
- #依頼チェックだけでは不安なので最低限のチェックを\r
- context '新規のとき' do\r
- it 'コマ絵で正常通過している' do\r
- @panel = FactoryGirl.build :panel, :author_id => @author.id\r
- @panel.panel_pictures.build(\r
- FactoryGirl.attributes_for(:panel_picture, :panel_id => nil, :picture_id => @p.id, :t => nil)\r
- )\r
- r = Panel.validate_element_t [@panel.panel_pictures, @panel.speech_balloons], :t\r
- r.should be_true\r
- end\r
- it 'フキダシで正常通過している' do\r
- @panel = FactoryGirl.build :panel, :author_id => @author.id\r
- @panel.speech_balloons.build(\r
- FactoryGirl.attributes_for(:speech_balloon, :panel_id => nil, :speech_balloon_template_id => @sbt.id, :t => nil)\r
- )\r
- r = Panel.validate_element_t [@panel.panel_pictures, @panel.speech_balloons], :t\r
- r.should be_true\r
- end\r
- end\r
- context '既存のとき' do\r
- it 'コマ絵で正常通過している' do\r
- @panel = FactoryGirl.create :panel, :author_id => @author.id\r
- @panel.panel_pictures.build(\r
- FactoryGirl.attributes_for(:panel_picture, :panel_id => @panel.id, :picture_id => @p.id, :t => 0)\r
- )\r
- r = Panel.validate_element_t [@panel.panel_pictures, @panel.speech_balloons], :t\r
- r.should be_true\r
- end\r
- it 'フキダシで正常通過している' do\r
- @panel = FactoryGirl.create :panel, :author_id => @author.id\r
- @panel.speech_balloons.build(\r
- FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 0)\r
- )\r
- r = Panel.validate_element_t [@panel.panel_pictures, @panel.speech_balloons], :t\r
- r.should be_true\r
- end\r
- end\r
- end\r
- describe '複合チェックに於いて' do\r
- context 'つつがなく終わるとき' do\r
- it 'している' do\r
- @panel = FactoryGirl.build :panel, :author_id => @author.id\r
- @panel.panel_pictures.build(\r
- FactoryGirl.attributes_for(:panel_picture, :panel_id => @panel.id, :picture_id => @p.id, :t => 0)\r
- )\r
- @panel.panel_pictures.build(\r
- FactoryGirl.attributes_for(:panel_picture, :panel_id => @panel.id, :picture_id => @p.id, :t => 1)\r
- )\r
- sb1 = @panel.speech_balloons.build(\r
- FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 2)\r
- )\r
- sb1.balloons.build(\r
- FactoryGirl.attributes_for(:balloon, :speech_balloon_id => sb1.id)\r
- )\r
- sb1.speeches.build(\r
- FactoryGirl.attributes_for(:speech, :speech_balloon_id => sb1.id)\r
- )\r
- sb2 = @panel.speech_balloons.build(\r
- FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 3)\r
- )\r
- sb2.balloons.build(\r
- FactoryGirl.attributes_for(:balloon, :speech_balloon_id => sb2.id)\r
- )\r
- sb2.speeches.build(\r
- FactoryGirl.attributes_for(:speech, :speech_balloon_id => sb2.id)\r
- )\r
- r = @panel.validate_child\r
- r.should be_true\r
- end\r
- end\r
- end\r
- describe '複合チェックに於いて' do\r
- context 'つつがなく終わるとき' do\r
- it 'している' do\r
- @panel = FactoryGirl.build :panel, :author_id => @author.id\r
- @panel.panel_pictures.build(\r
- FactoryGirl.attributes_for(:panel_picture, :panel_id => @panel.id, :picture_id => @p.id, :t => 0)\r
- )\r
- @panel.panel_pictures.build(\r
- FactoryGirl.attributes_for(:panel_picture, :panel_id => @panel.id, :picture_id => @p.id, :t => 1)\r
- )\r
- sb1 = @panel.speech_balloons.build(\r
- FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 2)\r
- )\r
- sb1.balloons.build(\r
- FactoryGirl.attributes_for(:balloon, :speech_balloon_id => sb1.id)\r
- )\r
- sb1.speeches.build(\r
- FactoryGirl.attributes_for(:speech, :speech_balloon_id => sb1.id)\r
- )\r
- sb2 = @panel.speech_balloons.build(\r
- FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 3)\r
- )\r
- sb2.balloons.build(\r
- FactoryGirl.attributes_for(:balloon, :speech_balloon_id => sb2.id)\r
- )\r
- sb2.speeches.build(\r
- FactoryGirl.attributes_for(:speech, :speech_balloon_id => sb2.id)\r
- )\r
- r = @panel.validate_child\r
- r.should be_true\r
- end\r
- end\r
- end\r
- describe '保存に於いて' do\r
- context 'つつがなく終わるとき' do\r
- it 'idチェックを依頼している' do\r
- Panel.should_receive(:validate_elements_id).with(any_args).exactly(1)\r
- Panel.stub(:validate_elements_id).with(any_args).and_return(true)\r
- @panel = FactoryGirl.build :panel, :author_id => @author.id\r
- r = @panel.store\r
- end\r
- it '保存を依頼している' do\r
- Panel.stub(:validate_elements_id).with(any_args).and_return(true)\r
- Panel.any_instance.should_receive(:save).with(any_args).exactly(1)\r
- Panel.any_instance.stub(:save).with(any_args).and_return(true)\r
- @panel = FactoryGirl.build :panel, :author_id => @author.id\r
- r = @panel.store\r
- end\r
- it 'Trueを返す' do\r
- Panel.stub(:validate_elements_id).with(any_args).and_return(true)\r
- @panel = FactoryGirl.build :panel, :author_id => @author.id\r
- r = @panel.store\r
- r.should be_true\r
- end\r
- it 'エラーメッセージがセットされていない' do\r
- Panel.stub(:validate_elements_id).with(any_args).and_return(true)\r
- @panel = FactoryGirl.create :panel, :author_id => @author.id\r
- r = @panel.store\r
- @panel.errors.empty?.should be_true\r
- end\r
- context '新規のとき' do\r
- it 'Trueを返す' do\r
- Panel.stub(:validate_elements_id).with(any_args).and_return(true)\r
- @panel = FactoryGirl.build :panel, :author_id => @author.id\r
- r = @panel.store\r
- r.should be_true\r
- end\r
- it '行が追加されている' do\r
- Panel.stub(:validate_elements_id).with(any_args).and_return(true)\r
- @panel = FactoryGirl.build :panel, :author_id => @author.id\r
- lambda {\r
- r = @panel.store\r
- }.should change(Panel, :count)\r
- end\r
- end\r
- context '更新のとき' do\r
- it 'Trueを返す' do\r
- Panel.stub(:validate_elements_id).with(any_args).and_return(true)\r
- @panel = FactoryGirl.create :panel, :author_id => @author.id\r
- r = @panel.store\r
- r.should be_true\r
- end\r
- it '行が追加されていない' do\r
- Panel.stub(:validate_elements_id).with(any_args).and_return(true)\r
- @panel = FactoryGirl.create :panel, :author_id => @author.id\r
- lambda {\r
- r = @panel.store\r
- }.should_not change(Panel, :count)\r
- end\r
- end\r
- end\r
- context 'idチェックが失敗するとき' do\r
- it 'Falseを返す' do\r
- Panel.stub(:validate_elements_id).with(any_args).and_return(false)\r
- @panel = FactoryGirl.create :panel, :author_id => @author.id\r
- r = @panel.store\r
- r.should be_false\r
- end\r
- it 'エラーメッセージがセットされている' do\r
- Panel.stub(:validate_elements_id).with(any_args).and_return(false)\r
- @panel = FactoryGirl.create :panel, :author_id => @author.id\r
- r = @panel.store\r
- @panel.errors.empty?.should be_false\r
- end\r
- it '行が追加されていない' do\r
- Panel.stub(:validate_elements_id).with(any_args).and_return(false)\r
- @panel = FactoryGirl.build :panel, :author_id => @author.id\r
- lambda {\r
- r = @panel.store\r
- }.should_not change(Panel, :count)\r
- end\r
- end\r
- end\r
+=end\r
end\r