1 # -*- encoding: utf-8 -*-
7 SpeechBalloonTemplate.delete_all
8 @admin = FactoryGirl.create :admin
9 @demand_user = FactoryGirl.create :demand_user
10 @sp = FactoryGirl.create :system_picture
11 @lg = FactoryGirl.create :license_group
12 @license = FactoryGirl.create :license, :license_group_id => @lg.id, :system_picture_id => @sp.id
13 @user = FactoryGirl.create( :user_yas)
14 @author = FactoryGirl.create :author, :user_id => @user.id
15 @artist = FactoryGirl.create :artist_yas, :author_id => @author.id
16 @other_user = FactoryGirl.create( :user_yas)
17 @other_author = FactoryGirl.create :author, :user_id => @other_user.id
18 @other_artist = FactoryGirl.create :artist_yas, :author_id => @other_author.id
23 @sheet = FactoryGirl.build :sheet, :author_id => @author.id
26 context 'オーソドックスなデータのとき' do
32 @sheet.should be_valid
35 @sheet.caption = 'a'*100
39 @sheet.should be_valid
43 context 'captionを検証するとき' do
46 @sheet.should_not be_valid
49 @sheet.caption = 'a'*101
50 @sheet.should_not be_valid
53 context 'widthを検証するとき' do
56 @sheet.should_not be_valid
60 @sheet.should_not be_valid
64 @sheet.should_not be_valid
68 @sheet.should_not be_valid
71 context 'heightを検証するとき' do
74 @sheet.should_not be_valid
78 @sheet.should_not be_valid
82 @sheet.should_not be_valid
86 @sheet.should_not be_valid
89 context 'visibleを検証するとき' do
92 @sheet.should_not be_valid
96 @sheet.should_not be_valid
100 @sheet.should_not be_valid
105 describe '文字コード検証に於いて' do
107 @sheet = FactoryGirl.build :sheet, :author_id => @author.id
110 context 'captionを検証するとき' do
111 it 'Shift JISなら失敗する' do
112 @sheet.caption = "\x83G\x83r\x83]\x83D"
115 }.should raise_error(Pettanr::BadRequest)
121 describe 'デフォルト値補充に於いて' do
122 it 'visibleが0になっている' do
123 @sheet = FactoryGirl.build :sheet, :visible => nil
124 @sheet.supply_default
125 @sheet.visible.should eq 0
129 describe '上書き補充に於いて' do
131 @sheet = FactoryGirl.build :sheet, :author_id => nil
132 @sheet.overwrite @author
133 @sheet.author_id.should eq @author.id
137 describe '所持判定に於いて' do
139 @sheet = FactoryGirl.build :sheet, :author_id => @author.id
141 context '事前チェックする' do
142 it '自身にロールリストからの作家取得を依頼している' do
143 Sheet.should_receive(:get_author_from_roles).with(any_args).exactly(1)
144 r = @sheet.own?([@author])
147 context 'ロール内作家が取得できるとき' do
150 it 'ロール内作家のidが自身の作家idと一致するなら許可する' do
151 Sheet.stub(:get_author_from_roles).with(any_args).and_return(@author)
152 r = @sheet.own?([@author])
155 it 'ロール内作家のidが自身の作家idと一致しないならno' do
156 Sheet.stub(:get_author_from_roles).with(any_args).and_return(@other_author)
157 @sheet.own?(@other_author).should be_false
160 context 'ロール内作家が取得できないとき' do
162 Sheet.stub(:get_author_from_roles).with(any_args).and_return(nil)
165 r = @sheet.own?([@author])
171 describe '閲覧許可に於いて' do
173 @sheet = FactoryGirl.create :sheet, :author_id => @author.id
175 context 'オープンモードのとき' do
177 MagicNumber['run_mode'] = 0
179 it '自身にゲスト用ロールチェックを問い合わせしている' do
180 Sheet.any_instance.stub(:guest_role_check).and_return(true)
181 Sheet.any_instance.should_receive(:guest_role_check).with(any_args).exactly(1)
182 r = @sheet.visible?([@author])
184 it 'ゲスト用ロールチェックが失敗したとき、falseを返す' do
185 Sheet.any_instance.stub(:guest_role_check).and_return(false)
186 r = @sheet.visible?([@author])
190 context 'クローズドモードのとき' do
192 MagicNumber['run_mode'] = 1
194 it '自身に読者用ロールチェックを問い合わせしている' do
195 Sheet.any_instance.stub(:reader_role_check).and_return(true)
196 Sheet.any_instance.should_receive(:reader_role_check).with(any_args).exactly(1)
197 r = @sheet.visible?([@author])
199 it '読者用ロールチェックが失敗したとき、falseを返す' do
200 Sheet.any_instance.stub(:reader_role_check).and_return(false)
201 r = @sheet.visible?([@author])
205 context '事前チェックする' do
207 MagicNumber['run_mode'] = 1
208 Sheet.any_instance.stub(:reader_role_check).and_return(true)
209 Sheet.any_instance.stub(:own?).and_return(true)
211 it '自身に所持判定を問い合わせしている' do
212 Sheet.any_instance.should_receive(:own?).with(any_args).exactly(1)
213 r = @sheet.visible?([@author])
216 context 'つつがなく終わるとき' do
218 MagicNumber['run_mode'] = 1
219 Sheet.any_instance.stub(:reader_role_check).and_return(true)
222 Sheet.any_instance.stub(:own?).and_return(true)
223 Sheet.any_instance.stub(:visible).and_return(0)
224 r = @sheet.visible?([@author])
227 it '他人の非公開用紙なら許可しない' do
228 Sheet.any_instance.stub(:own?).and_return(false)
229 Sheet.any_instance.stub(:visible).and_return(0)
230 r = @sheet.visible?([@author])
233 it '他人の用紙でも公開なら許可する' do
234 Sheet.any_instance.stub(:own?).and_return(false)
235 Sheet.any_instance.stub(:visible).and_return(1)
236 r = @sheet.visible?([@author])
242 describe '一覧取得に於いて' do
244 @sheet = FactoryGirl.create :sheet, :author_id => @author.id
246 context 'page補正について' do
247 it '文字列から数値に変換される' do
248 Sheet.page('8').should eq 8
251 Sheet.page().should eq 1
254 Sheet.page('0').should eq 1
257 context 'page_size補正について' do
258 it '文字列から数値に変換される' do
259 Sheet.page_size('7').should eq 7
261 it 'nilの場合はSheet.default_page_sizeになる' do
262 Sheet.page_size().should eq Sheet.default_page_size
264 it '0以下の場合はSheet.default_page_sizeになる' do
265 Sheet.page_size('0').should eq Sheet.default_page_size
267 it 'Sheet.max_page_sizeを超えた場合はSheet.max_page_sizeになる' do
268 Sheet.page_size('1000').should eq Sheet.max_page_size
271 context 'つつがなく終わるとき' do
272 it '一覧取得オプションを利用している' do
273 Sheet.stub(:list_opt).with(any_args).and_return({})
274 Sheet.should_receive(:list_opt).with(any_args).exactly(1)
282 it '非公開用紙は(自分の用紙であっても)含んでいない' do
283 FactoryGirl.create :sheet, :author_id => @author.id, :visible => 0
288 #公開用紙は(他人の用紙であっても)含んでいる
289 v = FactoryGirl.create :sheet, :author_id => @other_author.id, :updated_at => Time.now + 100
291 c.should eq [v, @sheet]
293 context 'DBに5件あって1ページの件数を2件に変えたとして' do
295 @sheet2 = FactoryGirl.create :sheet, :author_id => @author.id, :updated_at => Time.now + 100
296 @sheet3 = FactoryGirl.create :sheet, :author_id => @author.id, :updated_at => Time.now + 200
297 @sheet4 = FactoryGirl.create :sheet, :author_id => @author.id, :updated_at => Time.now + 300
298 @sheet5 = FactoryGirl.create :sheet, :author_id => @author.id, :updated_at => Time.now + 400
299 Sheet.stub(:default_page_size).and_return(2)
303 c.should have(2).items
305 it 'page=1なら末尾2件を返す' do
308 c.should eq [@sheet5, @sheet4]
310 it 'page=2なら中間2件を返す' do
312 c.should eq [@sheet3, @sheet2]
314 it 'page=3なら先頭1件を返す' do
321 describe '自分の用紙一覧取得に於いて' do
323 @sheet = FactoryGirl.create :sheet, :author_id => @author.id
325 context 'つつがなく終わるとき' do
326 it '一覧取得オプションを利用している' do
327 Sheet.stub(:list_opt).with(any_args).and_return({})
328 Sheet.should_receive(:list_opt).with(any_args).exactly(1)
329 r = Sheet.mylist @author
333 c = Sheet.mylist @author
337 nc = FactoryGirl.create :sheet, :author_id => @author.id, :updated_at => Time.now + 100
338 cl = Sheet.mylist @author
339 cl.should eq [nc, @sheet]
341 it '他人の用紙は公開でも含まない' do
342 nc = FactoryGirl.create :sheet, :author_id => @other_author.id, :visible => 1
343 cl = Sheet.mylist @author
344 cl.should eq [@sheet]
346 it '自分の用紙は非公開でも含んでいる' do
347 nc = FactoryGirl.create :sheet, :author_id => @author.id, :visible => 0, :updated_at => Time.now + 100
348 cl = Sheet.mylist @author
349 cl.should eq [nc, @sheet]
351 context 'DBに5件あって1ページの件数を2件に変えたとして' do
353 @sheet2 = FactoryGirl.create :sheet, :author_id => @author.id, :updated_at => Time.now + 100
354 @sheet3 = FactoryGirl.create :sheet, :author_id => @author.id, :updated_at => Time.now + 200
355 @sheet4 = FactoryGirl.create :sheet, :author_id => @author.id, :updated_at => Time.now + 300
356 @sheet5 = FactoryGirl.create :sheet, :author_id => @author.id, :updated_at => Time.now + 400
359 c = Sheet.mylist @author, 1, 2
360 c.should have(2).items
362 it 'page=1なら末尾2件を返す' do
364 c = Sheet.mylist(@author, 1, 2)
365 c.should eq [@sheet5, @sheet4]
367 it 'page=2なら中間2件を返す' do
368 c = Sheet.mylist(@author, 2, 2)
369 c.should eq [@sheet3, @sheet2]
371 it 'page=3なら先頭1件を返す' do
372 c = Sheet.mylist(@author, 3, 2)
378 describe '他作家の用紙一覧取得に於いて' do
380 @sheet = FactoryGirl.create :sheet, :author_id => @author.id
381 @other_sheet = FactoryGirl.create :sheet, :author_id => @other_author.id, :visible => 1
383 context 'つつがなく終わるとき' do
384 it '一覧取得オプションを利用している' do
385 Sheet.stub(:list_opt).with(any_args).and_return({})
386 Sheet.should_receive(:list_opt).with(any_args).exactly(1)
387 r = Sheet.himlist @other_author
390 it '指定した作家のリストを返す' do
391 r = Sheet.himlist @other_author
392 r.should eq [@other_sheet]
395 nc = FactoryGirl.create :sheet, :author_id => @other_author.id, :updated_at => Time.now + 100
396 r = Sheet.himlist @other_author
397 r.should eq [nc, @other_sheet]
400 hidden = FactoryGirl.create :sheet, :author_id => @other_author.id, :visible => 0
401 r = Sheet.himlist @other_author
402 r.should eq [@other_sheet]
404 context 'DBに5件あって1ページの件数を2件に変えたとして' do
406 @other_sheet2 = FactoryGirl.create :sheet, :author_id => @other_author.id, :updated_at => Time.now + 100
407 @other_sheet3 = FactoryGirl.create :sheet, :author_id => @other_author.id, :updated_at => Time.now + 200
408 @other_sheet4 = FactoryGirl.create :sheet, :author_id => @other_author.id, :updated_at => Time.now + 300
409 @other_sheet5 = FactoryGirl.create :sheet, :author_id => @other_author.id, :updated_at => Time.now + 400
412 c = Sheet.himlist @other_author, 1, 2
413 c.should have(2).items
415 it 'page=1なら末尾2件を返す' do
417 c = Sheet.himlist(@other_author, 1, 2)
418 c.should eq [@other_sheet5, @other_sheet4]
420 it 'page=2なら中間2件を返す' do
421 c = Sheet.himlist(@other_author, 2, 2)
422 c.should eq [@other_sheet3, @other_sheet2]
424 it 'page=3なら先頭1件を返す' do
425 c = Sheet.himlist(@other_author, 3, 2)
426 c.should eq [@other_sheet]
431 describe '用紙一覧ページ制御に於いて' do
433 Sheet.stub(:count).with(any_args).and_return(100)
436 r = Sheet.list_paginate
437 r.is_a?(Kaminari::PaginatableArray).should be_true
439 it '用紙一覧の取得条件を利用している' do
440 Sheet.stub(:list_where).with(any_args).and_return('')
441 Sheet.should_receive(:list_where).with(any_args).exactly(1)
442 r = Sheet.list_paginate
444 it 'ページ件数10のとき、3ページ目のオフセットは20から始まる' do
445 r = Sheet.list_paginate 3, 10
446 r.limit_value.should eq 10
447 r.offset_value.should eq 20
451 describe '自分の用紙一覧ページ制御に於いて' do
453 Sheet.stub(:count).with(any_args).and_return(100)
456 r = Sheet.mylist_paginate @author
457 r.is_a?(Kaminari::PaginatableArray).should be_true
459 it '自分の用紙一覧の取得条件を利用している' do
460 Sheet.stub(:mylist_where).with(any_args).and_return('')
461 Sheet.should_receive(:mylist_where).with(any_args).exactly(1)
462 r = Sheet.mylist_paginate @author
464 it 'ページ件数10のとき、3ページ目のオフセットは20から始まる' do
465 r = Sheet.mylist_paginate @author, 3, 10
466 r.limit_value.should eq 10
467 r.offset_value.should eq 20
471 describe '他作家の用紙一覧ページ制御に於いて' do
473 Sheet.stub(:count).with(any_args).and_return(100)
476 r = Sheet.himlist_paginate @other_author
477 r.is_a?(Kaminari::PaginatableArray).should be_true
479 it '他作家の用紙一覧の取得条件を利用している' do
480 Sheet.stub(:himlist_where).with(any_args).and_return('')
481 Sheet.should_receive(:himlist_where).with(any_args).exactly(1)
482 r = Sheet.himlist_paginate @other_author
484 it 'ページ件数10のとき、3ページ目のオフセットは20から始まる' do
485 r = Sheet.himlist_paginate @other_author, 3, 10
486 r.limit_value.should eq 10
487 r.offset_value.should eq 20
491 describe '一覧取得オプションに於いて' do
494 r.should have(2).items
498 r.has_key?(:sheet_panels).should be_true
500 it 'スクコマはコマを含んでいる' do
502 r[:sheet_panels].has_key?(:panel).should be_true
506 r.has_key?(:author).should be_true
509 describe 'json一覧出力オプションに於いて' do
511 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
512 @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
513 @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id
514 @sbt = FactoryGirl.create :speech_balloon_template
515 @sheet = FactoryGirl.create :sheet, :author_id => @author.id, :visible => 1
516 @panel = FactoryGirl.create :panel, :author_id => @author.id, :publish => 1
517 @sheet_panel = FactoryGirl.create :sheet_panel, :author_id => @author.id, :sheet_id => @sheet.id, :panel_id => @panel.id
520 r = Sheet.list.to_json Sheet.list_json_opt
523 i.has_key?('sheet_panels').should be_true
525 it 'スクコマはコマを含んでいる' do
526 r = Sheet.list.to_json Sheet.list_json_opt
529 s = i['sheet_panels'].first
530 s.has_key?('panel').should be_true
533 r = Sheet.list.to_json Sheet.list_json_opt
536 i.has_key?('author').should be_true
540 describe '単体取得に於いて' do
542 @sheet = FactoryGirl.create :sheet, :author_id => @author.id
544 context 'つつがなく終わるとき' do
545 it '単体取得オプションを利用している' do
546 Sheet.stub(:show_opt).with(any_args).and_return({})
547 Sheet.should_receive(:show_opt).with(any_args).exactly(1)
548 r = Sheet.show @sheet.id, @author
550 it '閲覧許可を問い合わせている' do
551 Sheet.any_instance.stub(:visible?).with(any_args).and_return(true)
552 Sheet.any_instance.should_receive(:visible?).with(any_args).exactly(1)
553 r = Sheet.show @sheet.id, @author
557 c = Sheet.show @sheet.id, @author
560 context '閲覧許可が出なかったとき' do
561 it '403Forbidden例外を返す' do
562 Sheet.any_instance.stub(:visible?).and_return(false)
564 Sheet.show @sheet.id, @author
565 }.should raise_error(ActiveRecord::Forbidden)
568 context '存在しない用紙を開こうとしたとき' do
569 it '404RecordNotFound例外を返す' do
571 Sheet.show 110, @author
572 }.should raise_error(ActiveRecord::RecordNotFound)
577 describe '編集取得に於いて' do
579 @sheet = FactoryGirl.create :sheet, :author_id => @author.id
581 context 'つつがなく終わるとき' do
582 it '単体取得オプションを利用している' do
583 Sheet.stub(:show_opt).with(any_args).and_return({})
584 Sheet.should_receive(:show_opt).with(any_args).exactly(1)
585 r = Sheet.edit @sheet.id, @author
587 it '所持判定を問い合わせている' do
588 Sheet.any_instance.stub(:own?).with(any_args).and_return(true)
589 Sheet.any_instance.should_receive(:own?).with(any_args).exactly(1)
590 r = Sheet.edit @sheet.id, @author
594 Sheet.any_instance.stub(:own?).and_return(true)
595 c = Sheet.edit @sheet.id, @author.id
598 context '他人の用紙を開こうとしたとき' do
599 it '403Forbidden例外を返す' do
600 Sheet.any_instance.stub(:own?).and_return(false)
602 Sheet.edit @sheet.id, @author
603 }.should raise_error(ActiveRecord::Forbidden)
606 context '存在しない用紙を開こうとしたとき' do
607 it '404RecordNotFound例外を返す' do
609 Sheet.edit 110, @author
610 }.should raise_error(ActiveRecord::RecordNotFound)
614 describe '単体取得オプションに於いて' do
615 it 'includeキーを含んでいる' do
617 r.has_key?(:include).should be_true
620 r = Sheet.show_opt[:include]
621 r.should have(2).items
624 r = Sheet.show_opt[:include]
625 r.has_key?(:author).should be_true
628 r = Sheet.show_opt[:include]
629 r.has_key?(:sheet_panels).should be_true
631 it 'スクコマはコマを含んでいる' do
632 r = Sheet.show_opt[:include]
633 r[:sheet_panels].has_key?(:panel).should be_true
636 describe 'json単体出力オプションに於いて' do
638 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
639 @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
640 @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id
641 @sbt = FactoryGirl.create :speech_balloon_template
642 @sheet = FactoryGirl.create :sheet, :author_id => @author.id, :visible => 1
643 @panel = FactoryGirl.create :panel, :author_id => @author.id, :publish => 1
644 @sheet_panel = FactoryGirl.create :sheet_panel, :author_id => @author.id, :sheet_id => @sheet.id, :panel_id => @panel.id
647 r = Sheet.show(@sheet.id, @author).to_json Sheet.show_json_opt
650 i.has_key?('sheet_panels').should be_true
652 it 'スクコマはコマを含んでいる' do
653 r = Sheet.show(@sheet.id, @author).to_json Sheet.show_json_opt
656 s = i['sheet_panels'].first
657 s.has_key?('panel').should be_true
660 r = Sheet.show(@sheet.id, @author).to_json Sheet.show_json_opt
663 i.has_key?('author').should be_true
667 describe '検証値収集に於いて' do
668 context 'つつがなく終わるとき' do
669 it '第一パラメータで指定された配列中から第二引数のカラム値を収集している' do
670 elements = [[{:sheet_id => 1, :a => 'a'}, {:sheet_id => 2, :a => 'a'}],
671 [{:sheet_id => 3, :a => 'a'}, {:sheet_id => 4, :a => 'a'}]]
672 r = Sheet.collect_element_value elements, :sheet_id
673 r.should eq [1, 2, 3, 4]
675 it '第一パラメータで指定された配列中から第二引数のカラム値を収集している' do
676 elements = [[{:t => 1, :a => 'a'}, {:t => 2, :a => 'a'}],
677 [{:t => 3, :a => 'a'}, {:t => 0, :a => 'a'}]]
678 r = Sheet.collect_element_value elements, :t
679 r.should eq [1, 2, 3, 0]
683 describe 'シリアライズチェックに於いて' do
684 context 'つつがなく終わるとき' do
685 it '0からシリアライズされているならTrueを返す' do
686 r = Sheet.validate_serial [0, 1, 2]
689 it '見た目はシリアライズされてなくてもソート結果が無事ならtrueを返す' do
690 r = Sheet.validate_serial [0, 2, 1]
693 it '見た目はシリアライズされてなくてもソート結果が無事ならtrueを返す' do
694 r = Sheet.validate_serial [ 2, 1, 4, 3, 0]
698 context 'オフセットが1のとき' do
699 it '0からシリアライズされているならFalseを返す' do
700 r = Sheet.validate_serial [0, 1, 2], 1
703 it '1からシリアライズされているならTrueを返す' do
704 r = Sheet.validate_serial [1, 2, 3], 1
709 it '0から始まらないならFalseを返す' do
710 r = Sheet.validate_serial [1, 2, 3]
713 it '連続していないならFalseを返す' do
714 r = Sheet.validate_serial [0, 1, 2, 4]
717 it '連続していないならFalseを返す' do
718 r = Sheet.validate_serial [0, 1, 2, 4, 5]
723 describe 'シリアライズチェック単体に於いて' do
726 context 'つつがなく終わるとき' do
728 Sheet.should_receive(:collect_element_value).with(any_args).exactly(1)
729 Sheet.stub(:collect_element_value).with(any_args).and_return([])
730 Sheet.stub(:validate_serial).with(any_args).and_return(true)
731 r = Sheet.validate_element_serial [], :t
733 it 'シリアライズチェック依頼している' do
734 Sheet.stub(:collect_element_value).with(any_args).and_return([])
735 Sheet.should_receive(:validate_serial).with(any_args).exactly(1)
736 Sheet.stub(:validate_serial).with(any_args).and_return(true)
737 r = Sheet.validate_element_serial [], :t
741 describe '従属データの検証に於いて' do
742 context 'つつがなく終わるとき' do
744 @sheet = FactoryGirl.create :sheet, :author_id => @author.id
745 @panel = FactoryGirl.create :panel, :author_id => @author.id
746 @sheet.sheet_panels.create(
747 FactoryGirl.attributes_for(:sheet_panel, :sheet_id => @sheet.id, :panel_id => @panel.id, :t => 0, :z => 0+1)
749 @sheet.sheet_panels.create(
750 FactoryGirl.attributes_for(:sheet_panel, :sheet_id => @sheet.id, :panel_id => @panel.id, :t => 1, :z => 1+1)
752 r = @sheet.validate_child
756 context 'tシリアライズされていないとき' do
758 @sheet = FactoryGirl.create :sheet, :author_id => @author.id
759 @panel = FactoryGirl.create :panel, :author_id => @author.id
760 @sheet.sheet_panels.create(
761 FactoryGirl.attributes_for(:sheet_panel, :sheet_id => @sheet.id, :panel_id => @panel.id, :t => 2, :z => 0+1)
763 @sheet.sheet_panels.create(
764 FactoryGirl.attributes_for(:sheet_panel, :sheet_id => @sheet.id, :panel_id => @panel.id, :t => 1, :z => 1+1)
766 r = @sheet.validate_child
770 context 'zシリアライズされていないとき' do
772 @sheet = FactoryGirl.create :sheet, :author_id => @author.id
773 @panel = FactoryGirl.create :panel, :author_id => @author.id
774 @sheet.sheet_panels.create(
775 FactoryGirl.attributes_for(:sheet_panel, :sheet_id => @sheet.id, :panel_id => @panel.id, :t => 0, :z => 0+2)
777 @sheet.sheet_panels.create(
778 FactoryGirl.attributes_for(:sheet_panel, :sheet_id => @sheet.id, :panel_id => @panel.id, :t => 1, :z => 1+1)
780 r = @sheet.validate_child
787 @attr = FactoryGirl.attributes_for :sheet
789 @sheet.supply_default
791 context 'つつがなく終わるとき' do
793 Sheet.any_instance.stub(:validate_child).with(any_args).and_return(true)
794 Sheet.any_instance.stub(:save).with(any_args).and_return(true)
796 it 'コマモデルに上書き補充を依頼している' do
797 Sheet.any_instance.should_receive(:overwrite).exactly(1)
798 r = @sheet.store @attr, @author
801 Sheet.any_instance.should_receive(:save).with(any_args).exactly(1)
802 @sheet = FactoryGirl.build :sheet, :author_id => @author.id
803 r = @sheet.store @attr, @author
805 it '従属データの検証を依頼している' do
806 Sheet.any_instance.should_receive(:validate_child).with(any_args).exactly(1)
807 r = @sheet.store @attr, @author
810 context 'つつがなく終わるとき' do
812 Sheet.any_instance.stub(:validate_child).with(any_args).and_return(true)
815 r = @sheet.store @attr, @author
819 Sheet.any_instance.stub(:validate_child).with(any_args).and_return(true)
821 r = @sheet.store @attr, @author
822 }.should change(Sheet, :count)
825 context '不正なjsonデータのとき' do
828 it 'エラーメッセージがセットされている' do
829 r = @sheet.store false, @author
830 @sheet.errors[:base].should_not be_blank
833 context '従属データの検証に失敗したとき' do
835 Sheet.any_instance.stub(:save).with(any_args).and_return(true)
836 Sheet.any_instance.stub(:validate_child).with(any_args).and_return(false)
838 it 'エラーメッセージがセットされている' do
839 r = @sheet.store @attr, @author
840 @sheet.errors[:base].should_not be_blank
843 context 'カラム値がFalseしたとき' do
845 Sheet.any_instance.stub(:validate_child).with(any_args).and_return(true)
847 it 'エラーメッセージがセットされている' do
848 r = @sheet.store false, @author
849 @sheet.errors.should_not be_empty
856 @sheet = FactoryGirl.create :sheet, :author_id => @author.id
857 @panel = FactoryGirl.create :panel, :author_id => @author.id, :publish => 1
858 @sheet_panel = FactoryGirl.create :sheet_panel, :author_id => @author.id, :sheet_id => @sheet.id, :panel_id => @panel.id
859 @other_sheet = FactoryGirl.create :sheet, :author_id => @author.id
860 @other_sheet_panel = FactoryGirl.create :sheet_panel, :author_id => @author.id, :sheet_id => @other_sheet.id, :panel_id => @panel.id
862 context 'つつがなく終わるとき' do
865 r = @sheet.destroy_with_sheet_panel
866 }.should change(Sheet, :count).by(-1)
868 r = Sheet.find @sheet.id
871 it '自身にリンクしているスクコマをすべて削除する' do
873 r = @sheet.destroy_with_sheet_panel
874 }.should change(SheetPanel, :count).by(-1)
876 r = SheetPanel.find @sheet_panel.id
880 r = @sheet.destroy_with_sheet_panel
884 context '削除に失敗したとき' do
886 SheetPanel.any_instance.stub(:destroy).with(any_args).and_return(false)
889 r = @sheet.destroy_with_sheet_panel
894 r = @sheet.destroy_with_sheet_panel
895 }.should_not change(Sheet, :count)
897 r = @sheet.destroy_with_sheet_panel
898 }.should_not change(SheetPanel, :count)