1 # -*- encoding: utf-8 -*-
\r
2 require 'spec_helper'
\r
6 SpeechBalloonTemplate.delete_all
\r
7 @admin = FactoryGirl.create :admin
\r
8 @user = FactoryGirl.create( :user_yas)
\r
9 @author = FactoryGirl.create :author, :user_id => @user.id
\r
10 @artist = FactoryGirl.create :artist_yas, :author_id => @author.id
\r
11 @other_user = FactoryGirl.create( :user_yas)
\r
12 @other_author = FactoryGirl.create :author, :user_id => @other_user.id
\r
13 @other_artist = FactoryGirl.create :artist_yas, :author_id => @other_author.id
\r
14 @sp = FactoryGirl.create :system_picture
\r
15 @lg = FactoryGirl.create :license_group
\r
16 @license = FactoryGirl.create :license, :license_group_id => @lg.id, :system_picture_id => @sp.id
\r
18 SpeechBalloonTemplate.delete_all
\r
19 @speech_balloon_template = FactoryGirl.create :speech_balloon_template, "name" => "circle@pettan.com", "classname" => "CircleSpeechBalloon", "caption" => "cc", "system_picture_id" => @sp.id, "settings" => '{}'
\r
20 @writing_format = FactoryGirl.create :writing_format
\r
21 @panel = FactoryGirl.create :panel, :author_id => @author.id
\r
24 describe '検証に於いて' do
\r
26 @sb = FactoryGirl.build :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id
\r
27 @speech = @sb.build_speech(
\r
28 FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)
\r
30 @balloon = @sb.build_balloon(
\r
31 FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id)
\r
36 context 'オーソドックスなデータのとき' do
\r
43 @balloon.should be_valid
\r
48 @balloon.width = 99999
\r
49 @balloon.height = 99999
\r
51 @balloon.should be_valid
\r
55 context 'speech_balloon_idを検証するとき' do
\r
56 #ネストの保存はnilを許可しなければならないので数値チェックだけ
\r
58 @balloon.speech_balloon_id = @sb.id
\r
59 @balloon.should be_valid
\r
62 @balloon.speech_balloon_id = 'a'
\r
63 @balloon.should_not be_valid
\r
66 context 'system_picture_idを検証するとき' do
\r
68 @balloon.system_picture_id = nil
\r
69 @balloon.should_not be_valid
\r
72 @balloon.system_picture_id = 'a'
\r
73 @balloon.should_not be_valid
\r
75 it '存在するシステム画像でなければ失敗する' do
\r
76 @balloon.system_picture_id = 0
\r
77 @balloon.should_not be_valid
\r
80 context 'xを検証するとき' do
\r
83 @balloon.should_not be_valid
\r
87 @balloon.should_not be_valid
\r
91 @balloon.should be_valid
\r
95 @balloon.should be_valid
\r
98 context 'yを検証するとき' do
\r
101 @balloon.should_not be_valid
\r
103 it '数値でなければ失敗する' do
\r
105 @balloon.should_not be_valid
\r
109 @balloon.should be_valid
\r
113 @balloon.should be_valid
\r
116 context 'widthを検証するとき' do
\r
118 @balloon.width = nil
\r
119 @balloon.should_not be_valid
\r
121 it '数値でなければ失敗する' do
\r
122 @balloon.width = 'a'
\r
123 @balloon.should_not be_valid
\r
126 @balloon.width = '0'
\r
127 @balloon.should_not be_valid
\r
130 @balloon.width = -1
\r
131 @balloon.should_not be_valid
\r
134 context 'heightを検証するとき' do
\r
136 @balloon.height = nil
\r
137 @balloon.should_not be_valid
\r
139 it '数値でなければ失敗する' do
\r
140 @balloon.height = 'a'
\r
141 @balloon.should_not be_valid
\r
144 @balloon.height = '0'
\r
145 @balloon.should_not be_valid
\r
148 @balloon.height = -1
\r
149 @balloon.should_not be_valid
\r
152 context 'rを検証するとき' do
\r
155 @balloon.should_not be_valid
\r
157 it '数値でなければ失敗する' do
\r
159 @balloon.should_not be_valid
\r
163 @balloon.should be_valid
\r
167 @balloon.should be_valid
\r
170 context 'settingsを検証するとき' do
\r
174 describe '文字コード検証に於いて' do
\r
176 @sb = FactoryGirl.build :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id
\r
177 @speech = @sb.build_speech(
\r
178 FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)
\r
180 @balloon = @sb.build_balloon(
\r
181 FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id)
\r
187 context 'settingsを検証するとき' do
\r
188 it 'Shift JISなら失敗する' do
\r
189 @balloon.settings = "\x83G\x83r\x83]\x83D"
\r
191 @balloon.valid_encode
\r
192 }.should raise_error(Pettanr::BadRequest)
\r
197 describe '閲覧許可に於いて' do
\r
199 @sb = FactoryGirl.build :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id
\r
200 @speech = @sb.build_speech(
\r
201 FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)
\r
203 @balloon = @sb.build_balloon(
\r
204 FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id)
\r
209 context 'オープンモードのとき' do
\r
211 MagicNumber['run_mode'] = 0
\r
213 it '自身にゲスト用ロールチェックを問い合わせしている' do
\r
214 Balloon.any_instance.stub(:guest_role_check).and_return(true)
\r
215 Balloon.any_instance.should_receive(:guest_role_check).with(any_args).exactly(1)
\r
216 r = @balloon.visible?([@author])
\r
218 it 'ゲスト用ロールチェックが失敗したとき、falseを返す' do
\r
219 Balloon.any_instance.stub(:guest_role_check).and_return(false)
\r
220 r = @balloon.visible?([@author])
\r
224 context 'クローズドモードのとき' do
\r
226 MagicNumber['run_mode'] = 1
\r
228 it '自身に読者用ロールチェックを問い合わせしている' do
\r
229 Balloon.any_instance.stub(:reader_role_check).and_return(true)
\r
230 Balloon.any_instance.should_receive(:reader_role_check).with(any_args).exactly(1)
\r
231 r = @balloon.visible?([@author])
\r
233 it '読者用ロールチェックが失敗したとき、falseを返す' do
\r
234 Balloon.any_instance.stub(:reader_role_check).and_return(false)
\r
235 r = @balloon.visible?([@author])
\r
239 context '事前チェックする' do
\r
241 MagicNumber['run_mode'] = 1
\r
242 Balloon.any_instance.stub(:reader_role_check).and_return(true)
\r
244 it '自身のコマに所持判定を問い合わせしている' do
\r
245 Panel.any_instance.stub(:own?).and_return(true)
\r
246 Panel.any_instance.should_receive(:own?).with(any_args).exactly(1)
\r
247 r = @balloon.visible?([@author])
\r
249 it '自身のコマに閲覧許可を問い合わせしている' do
\r
250 Panel.any_instance.stub(:own?).and_return(false)
\r
251 Panel.any_instance.stub(:visible?).and_return(true)
\r
252 Panel.any_instance.should_receive(:visible?).with(any_args).exactly(1)
\r
253 r = @balloon.visible?([@author])
\r
256 context 'つつがなく終わるとき' do
\r
258 MagicNumber['run_mode'] = 1
\r
259 Panel.any_instance.stub(:reader_role_check).and_return(true)
\r
261 it '自分のコマのコマ絵なら許可する' do
\r
262 Panel.any_instance.stub(:own?).and_return(true)
\r
263 Panel.any_instance.stub(:visible?).and_return(false)
\r
264 r = @balloon.visible?([@author])
\r
267 it '他人の非公開コマのコマ絵なら許可しない' do
\r
268 Panel.any_instance.stub(:own?).and_return(false)
\r
269 Panel.any_instance.stub(:visible?).and_return(false)
\r
270 r = @balloon.visible?([@author])
\r
273 it '他人のコマのコマ絵でも公開なら許可する' do
\r
274 Panel.any_instance.stub(:own?).and_return(false)
\r
275 Panel.any_instance.stub(:visible?).and_return(true)
\r
276 r = @balloon.visible?([@author])
\r
282 describe '一覧取得に於いて' do
\r
284 @sb = FactoryGirl.build :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id
\r
285 @speech = @sb.build_speech(
\r
286 FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)
\r
288 @balloon = @sb.build_balloon(
\r
289 FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id)
\r
294 context 'page補正について' do
\r
295 it '文字列から数値に変換される' do
\r
296 Balloon.page('8').should eq 8
\r
298 it 'nilの場合は1になる' do
\r
299 Balloon.page().should eq 1
\r
301 it '0以下の場合は1になる' do
\r
302 Balloon.page('0').should eq 1
\r
305 context 'page_size補正について' do
\r
306 it '文字列から数値に変換される' do
\r
307 Balloon.page_size('7').should eq 7
\r
309 it 'nilの場合はBalloon.default_page_sizeになる' do
\r
310 Balloon.page_size().should eq Balloon.default_page_size
\r
312 it '0以下の場合はBalloon.default_page_sizeになる' do
\r
313 Balloon.page_size('0').should eq Balloon.default_page_size
\r
315 it 'Balloon.max_page_sizeを超えた場合はBalloon.max_page_sizeになる' do
\r
316 Balloon.page_size('1000').should eq Balloon.max_page_size
\r
319 context 'つつがなく終わるとき' do
\r
320 it '一覧取得オプションを利用している' do
\r
321 Balloon.stub(:list_opt).with(any_args).and_return({:include => {:speech_balloon => {:panel => {}}}})
\r
322 Balloon.should_receive(:list_opt).with(any_args).exactly(1)
\r
328 r.should eq [@balloon]
\r
331 #公開されたコマのフキダシ枠は(他人のフキダシ枠であっても)含んでいる
\r
332 hc = FactoryGirl.create :panel, :author_id => @other_author.id, :publish => 1
\r
333 nsb = FactoryGirl.build :speech_balloon, :panel_id => hc.id, :speech_balloon_template_id => @speech_balloon_template.id, :updated_at => Time.now + 100
\r
335 FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)
\r
337 npl =nsb.build_balloon(
\r
338 FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id, :updated_at => Time.now + 100)
\r
343 r.should eq [npl, @balloon]
\r
345 it '非公開のコマのフキダシ枠は自分のフキダシ枠であっても含まない' do
\r
346 hc = FactoryGirl.create :panel, :author_id => @author.id, :publish => 0
\r
347 nsb = FactoryGirl.build :speech_balloon, :panel_id => hc.id, :speech_balloon_template_id => @speech_balloon_template.id, :updated_at => Time.now + 100
\r
349 FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)
\r
352 FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id, :updated_at => Time.now + 100)
\r
357 pl.should eq [@balloon]
\r
359 context 'DBに5件あって1ページの件数を2件に変えたとして' do
\r
361 @sb2 = FactoryGirl.build :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id
\r
362 @speech2 = @sb2.build_speech(
\r
363 FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)
\r
365 @balloon2 = @sb2.build_balloon(
\r
366 FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id, :updated_at => Time.now + 100)
\r
370 @sb3 = FactoryGirl.build :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id
\r
371 @speech3 = @sb3.build_speech(
\r
372 FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)
\r
374 @balloon3 = @sb3.build_balloon(
\r
375 FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id, :updated_at => Time.now + 200)
\r
379 @sb4 = FactoryGirl.build :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id
\r
380 @speech4 = @sb4.build_speech(
\r
381 FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)
\r
383 @balloon4 = @sb4.build_balloon(
\r
384 FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id, :updated_at => Time.now + 300)
\r
388 @sb5 = FactoryGirl.build :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id
\r
389 @speech5 = @sb5.build_speech(
\r
390 FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)
\r
392 @balloon5 = @sb5.build_balloon(
\r
393 FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id, :updated_at => Time.now + 400)
\r
397 Balloon.stub(:default_page_size).and_return(2)
\r
401 pl.should have(2).items
\r
403 it 'page=1なら末尾2件を返す' do
\r
405 pl = Balloon.list(1)
\r
406 pl.should eq [@balloon5, @balloon4]
\r
408 it 'page=2なら中間2件を返す' do
\r
409 pl = Balloon.list(2)
\r
410 pl.should eq [@balloon3, @balloon2]
\r
412 it 'page=3なら先頭1件を返す' do
\r
413 pl = Balloon.list(3)
\r
414 pl.should eq [@balloon]
\r
417 context 'DBに5件あって1ページの件数を0件に変えたとして' do
\r
419 @sb2 = FactoryGirl.build :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id
\r
420 @speech2 = @sb2.build_speech(
\r
421 FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)
\r
423 @balloon2 = @sb2.build_balloon(
\r
424 FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id, :updated_at => Time.now + 100)
\r
428 @sb3 = FactoryGirl.build :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id
\r
429 @speech3 = @sb3.build_speech(
\r
430 FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)
\r
432 @balloon3 = @sb3.build_balloon(
\r
433 FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id, :updated_at => Time.now + 200)
\r
437 @sb4 = FactoryGirl.build :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id
\r
438 @speech4 = @sb4.build_speech(
\r
439 FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)
\r
441 @balloon4 = @sb4.build_balloon(
\r
442 FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id, :updated_at => Time.now + 300)
\r
446 @sb5 = FactoryGirl.build :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id
\r
447 @speech5 = @sb5.build_speech(
\r
448 FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)
\r
450 @balloon5 = @sb5.build_balloon(
\r
451 FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id, :updated_at => Time.now + 400)
\r
455 Balloon.stub(:default_page_size).and_return(2)
\r
457 it '通常は全件(5件)を返す' do
\r
458 r = Balloon.list 5, 0
\r
459 r.should have(5).items
\r
463 describe '一覧取得オプションに於いて' do
\r
464 it 'includeキーを含んでいる' do
\r
465 r = Balloon.list_opt
\r
466 r.has_key?(:include).should be_true
\r
468 it '1つの項目を含んでいる' do
\r
469 r = Balloon.list_opt[:include]
\r
470 r.should have(1).items
\r
473 r = Balloon.list_opt[:include]
\r
474 r.has_key?(:speech_balloon).should be_true
\r
476 it 'フキダシはコマを含んでいる' do
\r
477 r = Balloon.list_opt[:include]
\r
478 r[:speech_balloon].has_key?(:panel).should be_true
\r
480 it 'コマは作家を含んでいる' do
\r
481 r = Balloon.list_opt[:include]
\r
482 r[:speech_balloon][:panel].has_key?(:author).should be_true
\r
484 it 'フキダシはセリフを含んでいる' do
\r
485 r = Balloon.list_opt[:include]
\r
486 r[:speech_balloon].has_key?(:speech).should be_true
\r
488 it 'フキダシはフキダシテンプレートを含んでいる' do
\r
489 r = Balloon.list_opt[:include]
\r
490 r[:speech_balloon].has_key?(:speech_balloon_template).should be_true
\r
493 describe 'json一覧出力オプションに於いて' do
\r
495 @sb = FactoryGirl.build :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id
\r
496 @speech = @sb.build_speech(
\r
497 FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)
\r
499 @balloon = @sb.build_balloon(
\r
500 FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id)
\r
506 r = Balloon.list.to_json Balloon.list_json_opt
\r
509 i.has_key?('speech_balloon').should be_true
\r
511 it 'フキダシはコマを含んでいる' do
\r
512 r = Balloon.list.to_json Balloon.list_json_opt
\r
515 s = i['speech_balloon']
\r
516 s.has_key?('panel').should be_true
\r
518 it 'コマは作家を含んでいる' do
\r
519 r = Balloon.list.to_json Balloon.list_json_opt
\r
522 s = i['speech_balloon']['panel']
\r
523 s.has_key?('author').should be_true
\r
525 it 'フキダシはセリフを含んでいる' do
\r
526 r = Balloon.list.to_json Balloon.list_json_opt
\r
529 s = i['speech_balloon']
\r
530 s.has_key?('speech').should be_true
\r
532 it 'フキダシはフキダシテンプレートを含んでいる' do
\r
533 r = Balloon.list.to_json Balloon.list_json_opt
\r
536 s = i['speech_balloon']
\r
537 s.has_key?('speech_balloon_template').should be_true
\r
541 describe '単体取得に於いて' do
\r
543 @sb = FactoryGirl.build :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id
\r
544 @speech = @sb.build_speech(
\r
545 FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)
\r
547 @balloon = @sb.build_balloon(
\r
548 FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id)
\r
553 context 'つつがなく終わるとき' do
\r
554 it '単体取得オプションを利用している' do
\r
555 Balloon.stub(:show_opt).with(any_args).and_return({:include => {:speech_balloon => {:panel => {}}}})
\r
556 Balloon.should_receive(:show_opt).with(any_args).exactly(1)
\r
557 r = Balloon.show @balloon.id, @author
\r
559 it '閲覧許可を問い合わせている' do
\r
560 Balloon.any_instance.stub(:visible?).with(any_args).and_return(true)
\r
561 Balloon.any_instance.should_receive(:visible?).with(any_args).exactly(1)
\r
562 r = Balloon.show @balloon.id, @author
\r
565 it '指定のフキダシ枠を返す' do
\r
566 Balloon.any_instance.stub(:visible?).and_return(true)
\r
567 pl = Balloon.show @balloon.id, @author
\r
568 pl.should eq @balloon
\r
570 context '閲覧許可が出なかったとき' do
\r
571 it '403Forbidden例外を返す' do
\r
572 Balloon.any_instance.stub(:visible?).and_return(false)
\r
574 Balloon.show @balloon.id, @author
\r
575 }.should raise_error(ActiveRecord::Forbidden)
\r
578 context '存在しないフキダシ枠を開こうとしたとき' do
\r
579 it '404RecordNotFound例外を返す' do
\r
581 Balloon.show 110, @author
\r
582 }.should raise_error(ActiveRecord::RecordNotFound)
\r
586 describe '単体取得オプションに於いて' do
\r
587 it 'includeキーを含んでいる' do
\r
588 r = Balloon.show_opt
\r
589 r.has_key?(:include).should be_true
\r
591 it '1つの項目を含んでいる' do
\r
592 r = Balloon.show_opt[:include]
\r
593 r.should have(1).items
\r
596 r = Balloon.show_opt[:include]
\r
597 r.has_key?(:speech_balloon).should be_true
\r
599 it 'フキダシはコマを含んでいる' do
\r
600 r = Balloon.show_opt[:include]
\r
601 r[:speech_balloon].has_key?(:panel).should be_true
\r
603 it 'コマは作家を含んでいる' do
\r
604 r = Balloon.show_opt[:include]
\r
605 r[:speech_balloon][:panel].has_key?(:author).should be_true
\r
607 it 'フキダシはセリフを含んでいる' do
\r
608 r = Balloon.show_opt[:include]
\r
609 r[:speech_balloon].has_key?(:speech).should be_true
\r
611 it 'フキダシはフキダシテンプレートを含んでいる' do
\r
612 r = Balloon.show_opt[:include]
\r
613 r[:speech_balloon].has_key?(:speech_balloon_template).should be_true
\r
616 describe 'json単体出力オプションに於いて' do
\r
618 @sb = FactoryGirl.build :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id
\r
619 @speech = @sb.build_speech(
\r
620 FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)
\r
622 @balloon = @sb.build_balloon(
\r
623 FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id)
\r
629 r = Balloon.show(@balloon.id, @author).to_json Balloon.show_json_opt
\r
632 i.has_key?('speech_balloon').should be_true
\r
635 r = Balloon.show(@balloon.id, @author).to_json Balloon.show_json_opt
\r
637 i = j['speech_balloon']
\r
638 i.has_key?('panel').should be_true
\r
640 it 'コマは作家を含んでいる' do
\r
641 r = Balloon.show(@balloon.id, @author).to_json Balloon.show_json_opt
\r
643 i = j['speech_balloon']
\r
645 s.has_key?('author').should be_true
\r
648 r = Balloon.show(@balloon.id, @author).to_json Balloon.show_json_opt
\r
650 i = j['speech_balloon']
\r
651 i.has_key?('speech').should be_true
\r
653 it 'フキダシテンプレートを含んでいる' do
\r
654 r = Balloon.show(@balloon.id, @author).to_json Balloon.show_json_opt
\r
656 i = j['speech_balloon']
\r
657 i.has_key?('speech_balloon_template').should be_true
\r