1 # -*- encoding: utf-8 -*-
\r
2 require 'spec_helper'
\r
6 @admin = FactoryGirl.create :admin
\r
7 @user = FactoryGirl.create( :user_yas)
\r
8 @author = FactoryGirl.create :author, :user_id => @user.id
\r
9 @artist = FactoryGirl.create :artist_yas, :author_id => @author.id
\r
10 @other_user = FactoryGirl.create( :user_yas)
\r
11 @other_author = FactoryGirl.create :author, :user_id => @other_user.id
\r
12 @other_artist = FactoryGirl.create :artist_yas, :author_id => @other_author.id
\r
13 @sp = FactoryGirl.create :system_picture
\r
14 @lg = FactoryGirl.create :license_group
\r
15 @license = FactoryGirl.create :license, :license_group_id => @lg.id, :system_picture_id => @sp.id
\r
17 @speech_balloon_template = FactoryGirl.create :speech_balloon_template, "name" => "circle@pettan.com", "classname" => "CircleSpeechBalloon", "caption" => "cc", "system_picture_id" => @sp.id, "settings" => '{}'
\r
18 @writing_format = FactoryGirl.create :writing_format
\r
19 @panel = FactoryGirl.create :panel, :author_id => @author.id
\r
22 describe '検証に於いて' do
\r
24 @sb = FactoryGirl.build :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id
\r
25 @speech = @sb.build_speech(
\r
26 FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)
\r
28 @balloon = @sb.build_balloon(
\r
29 FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id)
\r
34 context 'オーソドックスなデータのとき' do
\r
41 @balloon.should be_valid
\r
46 @balloon.width = 99999
\r
47 @balloon.height = 99999
\r
49 @balloon.should be_valid
\r
53 context 'speech_balloon_idを検証するとき' do
\r
54 #ネストの保存はnilを許可しなければならないので数値チェックだけ
\r
56 @balloon.speech_balloon_id = @sb.id
\r
57 @balloon.should be_valid
\r
60 @balloon.speech_balloon_id = 'a'
\r
61 @balloon.should_not be_valid
\r
64 context 'system_picture_idを検証するとき' do
\r
66 @balloon.system_picture_id = nil
\r
67 @balloon.should_not be_valid
\r
70 @balloon.system_picture_id = 'a'
\r
71 @balloon.should_not be_valid
\r
73 it '存在するシステム画像でなければ失敗する' do
\r
74 @balloon.system_picture_id = 0
\r
75 @balloon.should_not be_valid
\r
78 context 'xを検証するとき' do
\r
81 @balloon.should_not be_valid
\r
85 @balloon.should_not be_valid
\r
89 @balloon.should be_valid
\r
93 @balloon.should be_valid
\r
96 context 'yを検証するとき' do
\r
99 @balloon.should_not be_valid
\r
101 it '数値でなければ失敗する' do
\r
103 @balloon.should_not be_valid
\r
107 @balloon.should be_valid
\r
111 @balloon.should be_valid
\r
114 context 'widthを検証するとき' do
\r
116 @balloon.width = nil
\r
117 @balloon.should_not be_valid
\r
119 it '数値でなければ失敗する' do
\r
120 @balloon.width = 'a'
\r
121 @balloon.should_not be_valid
\r
124 @balloon.width = '0'
\r
125 @balloon.should_not be_valid
\r
128 @balloon.width = -1
\r
129 @balloon.should_not be_valid
\r
132 context 'heightを検証するとき' do
\r
134 @balloon.height = nil
\r
135 @balloon.should_not be_valid
\r
137 it '数値でなければ失敗する' do
\r
138 @balloon.height = 'a'
\r
139 @balloon.should_not be_valid
\r
142 @balloon.height = '0'
\r
143 @balloon.should_not be_valid
\r
146 @balloon.height = -1
\r
147 @balloon.should_not be_valid
\r
150 context 'rを検証するとき' do
\r
153 @balloon.should_not be_valid
\r
155 it '数値でなければ失敗する' do
\r
157 @balloon.should_not be_valid
\r
161 @balloon.should be_valid
\r
165 @balloon.should be_valid
\r
168 context 'settingsを検証するとき' do
\r
172 describe '文字コード検証に於いて' do
\r
174 @sb = FactoryGirl.build :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id
\r
175 @speech = @sb.build_speech(
\r
176 FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)
\r
178 @balloon = @sb.build_balloon(
\r
179 FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id)
\r
185 context 'settingsを検証するとき' do
\r
186 it 'Shift JISなら失敗する' do
\r
187 @balloon.settings = "\x83G\x83r\x83]\x83D"
\r
189 @balloon.valid_encode
\r
190 }.should raise_error(Pettanr::BadRequest)
\r
195 describe '閲覧許可に於いて' do
\r
197 @sb = FactoryGirl.build :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id
\r
198 @speech = @sb.build_speech(
\r
199 FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)
\r
201 @balloon = @sb.build_balloon(
\r
202 FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id)
\r
207 context 'オープンモードのとき' do
\r
209 MagicNumber['run_mode'] = 0
\r
211 it '自身にゲスト用ロールチェックを問い合わせしている' do
\r
212 Balloon.any_instance.stub(:guest_role_check).and_return(true)
\r
213 Balloon.any_instance.should_receive(:guest_role_check).with(any_args).exactly(1)
\r
214 r = @balloon.visible?([@author])
\r
216 it 'ゲスト用ロールチェックが失敗したとき、falseを返す' do
\r
217 Balloon.any_instance.stub(:guest_role_check).and_return(false)
\r
218 r = @balloon.visible?([@author])
\r
222 context 'クローズドモードのとき' do
\r
224 MagicNumber['run_mode'] = 1
\r
226 it '自身に読者用ロールチェックを問い合わせしている' do
\r
227 Balloon.any_instance.stub(:reader_role_check).and_return(true)
\r
228 Balloon.any_instance.should_receive(:reader_role_check).with(any_args).exactly(1)
\r
229 r = @balloon.visible?([@author])
\r
231 it '読者用ロールチェックが失敗したとき、falseを返す' do
\r
232 Balloon.any_instance.stub(:reader_role_check).and_return(false)
\r
233 r = @balloon.visible?([@author])
\r
237 context '事前チェックする' do
\r
239 MagicNumber['run_mode'] = 1
\r
240 Balloon.any_instance.stub(:reader_role_check).and_return(true)
\r
242 it '自身のコマに所持判定を問い合わせしている' do
\r
243 Panel.any_instance.stub(:own?).and_return(true)
\r
244 Panel.any_instance.should_receive(:own?).with(any_args).exactly(1)
\r
245 r = @balloon.visible?([@author])
\r
247 it '自身のコマに閲覧許可を問い合わせしている' do
\r
248 Panel.any_instance.stub(:own?).and_return(false)
\r
249 Panel.any_instance.stub(:visible?).and_return(true)
\r
250 Panel.any_instance.should_receive(:visible?).with(any_args).exactly(1)
\r
251 r = @balloon.visible?([@author])
\r
254 context 'つつがなく終わるとき' do
\r
256 MagicNumber['run_mode'] = 1
\r
257 Panel.any_instance.stub(:reader_role_check).and_return(true)
\r
259 it '自分のコマのコマ絵なら許可する' do
\r
260 Panel.any_instance.stub(:own?).and_return(true)
\r
261 Panel.any_instance.stub(:visible?).and_return(false)
\r
262 r = @balloon.visible?([@author])
\r
265 it '他人の非公開コマのコマ絵なら許可しない' do
\r
266 Panel.any_instance.stub(:own?).and_return(false)
\r
267 Panel.any_instance.stub(:visible?).and_return(false)
\r
268 r = @balloon.visible?([@author])
\r
271 it '他人のコマのコマ絵でも公開なら許可する' do
\r
272 Panel.any_instance.stub(:own?).and_return(false)
\r
273 Panel.any_instance.stub(:visible?).and_return(true)
\r
274 r = @balloon.visible?([@author])
\r
280 describe '一覧取得に於いて' do
\r
282 @sb = FactoryGirl.build :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id
\r
283 @speech = @sb.build_speech(
\r
284 FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)
\r
286 @balloon = @sb.build_balloon(
\r
287 FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id)
\r
292 context 'page補正について' do
\r
293 it '文字列から数値に変換される' do
\r
294 Balloon.page('8').should eq 8
\r
296 it 'nilの場合は1になる' do
\r
297 Balloon.page().should eq 1
\r
299 it '0以下の場合は1になる' do
\r
300 Balloon.page('0').should eq 1
\r
303 context 'page_size補正について' do
\r
304 it '文字列から数値に変換される' do
\r
305 Balloon.page_size('7').should eq 7
\r
307 it 'nilの場合はBalloon.default_page_sizeになる' do
\r
308 Balloon.page_size().should eq Balloon.default_page_size
\r
310 it '0以下の場合はBalloon.default_page_sizeになる' do
\r
311 Balloon.page_size('0').should eq Balloon.default_page_size
\r
313 it 'Balloon.max_page_sizeを超えた場合はBalloon.max_page_sizeになる' do
\r
314 Balloon.page_size('1000').should eq Balloon.max_page_size
\r
317 context 'つつがなく終わるとき' do
\r
318 it '一覧取得オプションを利用している' do
\r
319 Balloon.stub(:list_opt).with(any_args).and_return({:include => {:speech_balloon => {:panel => {}}}})
\r
320 Balloon.should_receive(:list_opt).with(any_args).exactly(1)
\r
326 r.should eq [@balloon]
\r
329 #公開されたコマのフキダシ枠は(他人のフキダシ枠であっても)含んでいる
\r
330 hc = FactoryGirl.create :panel, :author_id => @other_author.id, :publish => 1
\r
331 nsb = FactoryGirl.build :speech_balloon, :panel_id => hc.id, :speech_balloon_template_id => @speech_balloon_template.id, :updated_at => Time.now + 100
\r
333 FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)
\r
335 npl =nsb.build_balloon(
\r
336 FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id, :updated_at => Time.now + 100)
\r
341 r.should eq [npl, @balloon]
\r
343 it '非公開のコマのフキダシ枠は自分のフキダシ枠であっても含まない' do
\r
344 hc = FactoryGirl.create :panel, :author_id => @author.id, :publish => 0
\r
345 nsb = FactoryGirl.build :speech_balloon, :panel_id => hc.id, :speech_balloon_template_id => @speech_balloon_template.id, :updated_at => Time.now + 100
\r
347 FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)
\r
350 FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id, :updated_at => Time.now + 100)
\r
355 pl.should eq [@balloon]
\r
357 context 'DBに5件あって1ページの件数を2件に変えたとして' do
\r
359 @sb2 = FactoryGirl.build :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id
\r
360 @speech2 = @sb2.build_speech(
\r
361 FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)
\r
363 @balloon2 = @sb2.build_balloon(
\r
364 FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id, :updated_at => Time.now + 100)
\r
368 @sb3 = FactoryGirl.build :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id
\r
369 @speech3 = @sb3.build_speech(
\r
370 FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)
\r
372 @balloon3 = @sb3.build_balloon(
\r
373 FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id, :updated_at => Time.now + 200)
\r
377 @sb4 = FactoryGirl.build :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id
\r
378 @speech4 = @sb4.build_speech(
\r
379 FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)
\r
381 @balloon4 = @sb4.build_balloon(
\r
382 FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id, :updated_at => Time.now + 300)
\r
386 @sb5 = FactoryGirl.build :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id
\r
387 @speech5 = @sb5.build_speech(
\r
388 FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)
\r
390 @balloon5 = @sb5.build_balloon(
\r
391 FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id, :updated_at => Time.now + 400)
\r
395 Balloon.stub(:default_page_size).and_return(2)
\r
399 pl.should have(2).items
\r
401 it 'page=1なら末尾2件を返す' do
\r
403 pl = Balloon.list(1)
\r
404 pl.should eq [@balloon5, @balloon4]
\r
406 it 'page=2なら中間2件を返す' do
\r
407 pl = Balloon.list(2)
\r
408 pl.should eq [@balloon3, @balloon2]
\r
410 it 'page=3なら先頭1件を返す' do
\r
411 pl = Balloon.list(3)
\r
412 pl.should eq [@balloon]
\r
415 context 'DBに5件あって1ページの件数を0件に変えたとして' do
\r
417 @sb2 = FactoryGirl.build :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id
\r
418 @speech2 = @sb2.build_speech(
\r
419 FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)
\r
421 @balloon2 = @sb2.build_balloon(
\r
422 FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id, :updated_at => Time.now + 100)
\r
426 @sb3 = FactoryGirl.build :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id
\r
427 @speech3 = @sb3.build_speech(
\r
428 FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)
\r
430 @balloon3 = @sb3.build_balloon(
\r
431 FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id, :updated_at => Time.now + 200)
\r
435 @sb4 = FactoryGirl.build :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id
\r
436 @speech4 = @sb4.build_speech(
\r
437 FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)
\r
439 @balloon4 = @sb4.build_balloon(
\r
440 FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id, :updated_at => Time.now + 300)
\r
444 @sb5 = FactoryGirl.build :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id
\r
445 @speech5 = @sb5.build_speech(
\r
446 FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)
\r
448 @balloon5 = @sb5.build_balloon(
\r
449 FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id, :updated_at => Time.now + 400)
\r
453 Balloon.stub(:default_page_size).and_return(2)
\r
455 it '通常は全件(5件)を返す' do
\r
456 r = Balloon.list 5, 0
\r
457 r.should have(5).items
\r
461 describe '一覧取得オプションに於いて' do
\r
462 it 'includeキーを含んでいる' do
\r
463 r = Balloon.list_opt
\r
464 r.has_key?(:include).should be_true
\r
466 it '1つの項目を含んでいる' do
\r
467 r = Balloon.list_opt[:include]
\r
468 r.should have(1).items
\r
471 r = Balloon.list_opt[:include]
\r
472 r.has_key?(:speech_balloon).should be_true
\r
474 it 'フキダシはコマを含んでいる' do
\r
475 r = Balloon.list_opt[:include]
\r
476 r[:speech_balloon].has_key?(:panel).should be_true
\r
478 it 'コマは作家を含んでいる' do
\r
479 r = Balloon.list_opt[:include]
\r
480 r[:speech_balloon][:panel].has_key?(:author).should be_true
\r
482 it 'フキダシはセリフを含んでいる' do
\r
483 r = Balloon.list_opt[:include]
\r
484 r[:speech_balloon].has_key?(:speech).should be_true
\r
486 it 'フキダシはフキダシテンプレートを含んでいる' do
\r
487 r = Balloon.list_opt[:include]
\r
488 r[:speech_balloon].has_key?(:speech_balloon_template).should be_true
\r
491 describe 'json一覧出力オプションに於いて' do
\r
493 @sb = FactoryGirl.build :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id
\r
494 @speech = @sb.build_speech(
\r
495 FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)
\r
497 @balloon = @sb.build_balloon(
\r
498 FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id)
\r
504 r = Balloon.list.to_json Balloon.list_json_opt
\r
507 i.has_key?('speech_balloon').should be_true
\r
509 it 'フキダシはコマを含んでいる' do
\r
510 r = Balloon.list.to_json Balloon.list_json_opt
\r
513 s = i['speech_balloon']
\r
514 s.has_key?('panel').should be_true
\r
516 it 'コマは作家を含んでいる' do
\r
517 r = Balloon.list.to_json Balloon.list_json_opt
\r
520 s = i['speech_balloon']['panel']
\r
521 s.has_key?('author').should be_true
\r
523 it 'フキダシはセリフを含んでいる' do
\r
524 r = Balloon.list.to_json Balloon.list_json_opt
\r
527 s = i['speech_balloon']
\r
528 s.has_key?('speech').should be_true
\r
530 it 'フキダシはフキダシテンプレートを含んでいる' do
\r
531 r = Balloon.list.to_json Balloon.list_json_opt
\r
534 s = i['speech_balloon']
\r
535 s.has_key?('speech_balloon_template').should be_true
\r
539 describe '単体取得に於いて' do
\r
541 @sb = FactoryGirl.build :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id
\r
542 @speech = @sb.build_speech(
\r
543 FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)
\r
545 @balloon = @sb.build_balloon(
\r
546 FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id)
\r
551 context 'つつがなく終わるとき' do
\r
552 it '単体取得オプションを利用している' do
\r
553 Balloon.stub(:show_opt).with(any_args).and_return({:include => {:speech_balloon => {:panel => {}}}})
\r
554 Balloon.should_receive(:show_opt).with(any_args).exactly(1)
\r
555 r = Balloon.show @balloon.id, @author
\r
557 it '閲覧許可を問い合わせている' do
\r
558 Balloon.any_instance.stub(:visible?).with(any_args).and_return(true)
\r
559 Balloon.any_instance.should_receive(:visible?).with(any_args).exactly(1)
\r
560 r = Balloon.show @balloon.id, @author
\r
563 it '指定のフキダシ枠を返す' do
\r
564 Balloon.any_instance.stub(:visible?).and_return(true)
\r
565 pl = Balloon.show @balloon.id, @author
\r
566 pl.should eq @balloon
\r
568 context '閲覧許可が出なかったとき' do
\r
569 it '403Forbidden例外を返す' do
\r
570 Balloon.any_instance.stub(:visible?).and_return(false)
\r
572 Balloon.show @balloon.id, @author
\r
573 }.should raise_error(ActiveRecord::Forbidden)
\r
576 context '存在しないフキダシ枠を開こうとしたとき' do
\r
577 it '404RecordNotFound例外を返す' do
\r
579 Balloon.show 110, @author
\r
580 }.should raise_error(ActiveRecord::RecordNotFound)
\r
584 describe '単体取得オプションに於いて' do
\r
585 it 'includeキーを含んでいる' do
\r
586 r = Balloon.show_opt
\r
587 r.has_key?(:include).should be_true
\r
589 it '1つの項目を含んでいる' do
\r
590 r = Balloon.show_opt[:include]
\r
591 r.should have(1).items
\r
594 r = Balloon.show_opt[:include]
\r
595 r.has_key?(:speech_balloon).should be_true
\r
597 it 'フキダシはコマを含んでいる' do
\r
598 r = Balloon.show_opt[:include]
\r
599 r[:speech_balloon].has_key?(:panel).should be_true
\r
601 it 'コマは作家を含んでいる' do
\r
602 r = Balloon.show_opt[:include]
\r
603 r[:speech_balloon][:panel].has_key?(:author).should be_true
\r
605 it 'フキダシはセリフを含んでいる' do
\r
606 r = Balloon.show_opt[:include]
\r
607 r[:speech_balloon].has_key?(:speech).should be_true
\r
609 it 'フキダシはフキダシテンプレートを含んでいる' do
\r
610 r = Balloon.show_opt[:include]
\r
611 r[:speech_balloon].has_key?(:speech_balloon_template).should be_true
\r
614 describe 'json単体出力オプションに於いて' do
\r
616 @sb = FactoryGirl.build :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id
\r
617 @speech = @sb.build_speech(
\r
618 FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)
\r
620 @balloon = @sb.build_balloon(
\r
621 FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id)
\r
627 r = Balloon.show(@balloon.id, @author).to_json Balloon.show_json_opt
\r
630 i.has_key?('speech_balloon').should be_true
\r
633 r = Balloon.show(@balloon.id, @author).to_json Balloon.show_json_opt
\r
635 i = j['speech_balloon']
\r
636 i.has_key?('panel').should be_true
\r
638 it 'コマは作家を含んでいる' do
\r
639 r = Balloon.show(@balloon.id, @author).to_json Balloon.show_json_opt
\r
641 i = j['speech_balloon']
\r
643 s.has_key?('author').should be_true
\r
646 r = Balloon.show(@balloon.id, @author).to_json Balloon.show_json_opt
\r
648 i = j['speech_balloon']
\r
649 i.has_key?('speech').should be_true
\r
651 it 'フキダシテンプレートを含んでいる' do
\r
652 r = Balloon.show(@balloon.id, @author).to_json Balloon.show_json_opt
\r
654 i = j['speech_balloon']
\r
655 i.has_key?('speech_balloon_template').should be_true
\r