OSDN Git Service

t#31566:add mylist sb
[pettanr/pettanr.git] / spec / models / speech_balloon_spec.rb
index 6945590..650975c 100644 (file)
@@ -4,45 +4,49 @@ require 'spec_helper'
 
 describe SpeechBalloon do
   before do
-    Factory :admin
-    @user = Factory( :user_yas)
-    @author = @user.author
-    @artist = Factory :artist_yas, :author_id => @author.id
+    @admin = FactoryGirl.create :admin
+    @user = FactoryGirl.create( :user_yas)
+    @author = FactoryGirl.create :author, :user_id => @user.id
+    @artist = FactoryGirl.create :artist_yas, :author_id => @author.id
+    @other_user = FactoryGirl.create( :user_yas)
+    @other_author = FactoryGirl.create :author, :user_id => @other_user.id
+    @other_artist = FactoryGirl.create :artist_yas, :author_id => @other_author.id
+    @sp = FactoryGirl.create :system_picture
+    @lg = FactoryGirl.create :license_group
+    @license = FactoryGirl.create :license, :license_group_id => @lg.id, :system_picture_id => @sp.id
     
-    @panel = Factory :panel, :author_id => @author.id
-    @speech_balloon_template = Factory :speech_balloon_template
+    @panel = FactoryGirl.create :panel, :author_id => @author.id
+    @speech_balloon_template = FactoryGirl.create :speech_balloon_template
   end
   
   describe '検証に於いて' do
     before do
+      @sb = FactoryGirl.build :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id
     end
     
-    it 'オーソドックスなデータなら通る' do
-      @sb = Factory.build :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id
-      @sb.should be_valid
-    end
-    
-    context 'panel_idを検証するとき' do
-      before do
-        @sb = Factory.build :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id
+    context 'オーソドックスなデータのとき' do
+      it '下限データが通る' do
+        @sb.classname = 'a'
+        @sb.z = 1
+        @sb.t = 0
+        @sb.should be_valid
       end
-      it 'テストデータの確認' do
-        @sb.panel_id = @panel.id
+      it '上限データが通る' do
+        @sb.classname = 'a'*50
+        @sb.z = 99999
+        @sb.t = 99999
         @sb.should be_valid
       end
+    end
+    
+    context 'panel_idを検証するとき' do
+      #ネストの保存はnilを許可しなければならないので数値チェックだけ
       it '数値でなければ失敗する' do
         @sb.panel_id = 'a'
         @sb.should_not be_valid
       end
     end
     context 'speech_balloon_template_idを検証するとき' do
-      before do
-        @sb = Factory.build :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id
-      end
-      it 'テストデータの確認' do
-        @sb.speech_balloon_template_id = @speech_balloon_template.id
-        @sb.should be_valid
-      end
       it 'nullなら失敗する' do
         @sb.speech_balloon_template_id = nil
         @sb.should_not be_valid
@@ -57,13 +61,6 @@ describe SpeechBalloon do
       end
     end
     context 'classnameを検証するとき' do
-      before do
-        @sb = Factory.build :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id
-      end
-      it 'テストデータの確認' do
-        @sb.classname = 'abcdefghi0abcdefghi0abcdefghi0abcdefghi0abcdefghi0'
-        @sb.should be_valid
-      end
       it 'nullなら失敗する' do
         @sb.classname = ''
         @sb.should_not be_valid
@@ -74,13 +71,6 @@ describe SpeechBalloon do
       end
     end
     context 'tを検証するとき' do
-      before do
-        @sb = Factory.build :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id
-      end
-      it 'テストデータの確認' do
-        @sb.t = 0
-        @sb.should be_valid
-      end
       it 'nullなら失敗する' do
         @sb.t = nil
         @sb.should_not be_valid
@@ -95,20 +85,547 @@ describe SpeechBalloon do
       end
     end
     context 'settingsを検証するとき' do
+    end
+  end
+  
+  describe '文字コード検証に於いて' do
+    before do
+      @sb = FactoryGirl.build :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id
+    end
+    
+    context 'classnameを検証するとき' do
+      it 'Shift JISなら失敗する' do
+        @sb.classname = "\x83G\x83r\x83]\x83D"
+        lambda{
+          @sb.valid_encode
+        }.should raise_error(Pettanr::BadRequest)
+      end
+    end
+    
+    context 'settingsを検証するとき' do
+      it 'Shift JISなら失敗する' do
+        @sb.settings = "\x83G\x83r\x83]\x83D"
+        lambda{
+          @sb.valid_encode
+        }.should raise_error(Pettanr::BadRequest)
+      end
+    end
+    
+    context 'captionを検証するとき' do
+      it 'Shift JISなら失敗する' do
+        @sb.caption = "\x83G\x83r\x83]\x83D"
+        lambda{
+          @sb.valid_encode
+        }.should raise_error(Pettanr::BadRequest)
+      end
+    end
+    
+  end
+  
+  describe '閲覧許可に於いて' do
+    before do
+      @sb = FactoryGirl.create :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id
+    end
+    context 'オープンモードのとき' do
       before do
-        @sb = Factory.build :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id
+        MagicNumber['run_mode'] = 0
       end
-      it 'テストデータの確認' do
-        @sb.settings = '{}'
-        @sb.should be_valid
+      it '自身にゲスト用ロールチェックを問い合わせしている' do
+        SpeechBalloon.any_instance.stub(:guest_role_check).and_return(true)
+        SpeechBalloon.any_instance.should_receive(:guest_role_check).with(any_args).exactly(1)
+        r = @sb.visible?([@author])
+      end
+      it 'ゲスト用ロールチェックが失敗したとき、falseを返す' do
+        SpeechBalloon.any_instance.stub(:guest_role_check).and_return(false)
+        r = @sb.visible?([@author])
+        r.should be_false
+      end
+    end
+    context 'クローズドモードのとき' do
+      before do
+        MagicNumber['run_mode'] = 1
+      end
+      it '自身に読者用ロールチェックを問い合わせしている' do
+        SpeechBalloon.any_instance.stub(:reader_role_check).and_return(true)
+        SpeechBalloon.any_instance.should_receive(:reader_role_check).with(any_args).exactly(1)
+        r = @sb.visible?([@author])
+      end
+      it '読者用ロールチェックが失敗したとき、falseを返す' do
+        SpeechBalloon.any_instance.stub(:reader_role_check).and_return(false)
+        r = @sb.visible?([@author])
+        r.should be_false
+      end
+    end
+    context '事前チェックする' do
+      before do
+        MagicNumber['run_mode'] = 1
+        SpeechBalloon.any_instance.stub(:reader_role_check).and_return(true)
+      end
+      it '自身のコマに所持判定を問い合わせしている' do
+        Panel.any_instance.stub(:own?).and_return(true)
+        Panel.any_instance.should_receive(:own?).with(any_args).exactly(1)
+        r = @sb.visible?([@author])
+      end
+      it '自身のコマに閲覧許可を問い合わせしている' do
+        Panel.any_instance.stub(:own?).and_return(false)
+        Panel.any_instance.stub(:visible?).and_return(true)
+        Panel.any_instance.should_receive(:visible?).with(any_args).exactly(1)
+        r = @sb.visible?([@author])
+      end
+    end
+    context 'つつがなく終わるとき' do
+      before do
+        MagicNumber['run_mode'] = 1
+        Panel.any_instance.stub(:reader_role_check).and_return(true)
+      end
+      it '自分のコマのフキダシなら許可する' do
+        Panel.any_instance.stub(:own?).and_return(true)
+        Panel.any_instance.stub(:visible?).and_return(false)
+        r = @sb.visible?([@author])
+        r.should be_true
+      end
+      it '他人の非公開コマのフキダシなら許可しない' do
+        Panel.any_instance.stub(:own?).and_return(false)
+        Panel.any_instance.stub(:visible?).and_return(false)
+        r = @sb.visible?([@author])
+        r.should be_false
+      end
+      it '他人のコマのフキダシでも公開なら許可する' do
+        Panel.any_instance.stub(:own?).and_return(false)
+        Panel.any_instance.stub(:visible?).and_return(true)
+        r = @sb.visible?([@author])
+        r.should be_true
       end
     end
   end
   
-  describe 'データ補充に於いて' do
+  describe '一覧取得に於いて' do
     before do
+      @sb = FactoryGirl.create :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id
+      @balloon = FactoryGirl.create :balloon, :speech_balloon_id => @sb.id, :system_picture_id => @sp.id
+      @speech = FactoryGirl.create :speech, :speech_balloon_id => @sb.id
+    end
+    context 'page補正について' do
+      it '文字列から数値に変換される' do
+        SpeechBalloon.page('8').should eq 8
+      end
+      it 'nilの場合は1になる' do
+        SpeechBalloon.page().should eq 1
+      end
+      it '0以下の場合は1になる' do
+        SpeechBalloon.page('0').should eq 1
+      end
+    end
+    context 'page_size補正について' do
+      it '文字列から数値に変換される' do
+        SpeechBalloon.page_size('7').should eq 7
+      end
+      it 'nilの場合はSpeechBalloon.default_page_sizeになる' do
+        SpeechBalloon.page_size().should eq SpeechBalloon.default_page_size
+      end
+      it '0以下の場合はSpeechBalloon.default_page_sizeになる' do
+        SpeechBalloon.page_size('0').should eq SpeechBalloon.default_page_size
+      end
+      it 'SpeechBalloon.max_page_sizeを超えた場合はSpeechBalloon.max_page_sizeになる' do
+        SpeechBalloon.page_size('1000').should eq SpeechBalloon.max_page_size
+      end
+    end
+    context 'つつがなく終わるとき' do
+      it '一覧取得オプションを利用している' do
+        SpeechBalloon.stub(:list_opt).with(any_args).and_return({:include => :panel})
+        SpeechBalloon.should_receive(:list_opt).with(any_args).exactly(1)
+        r = SpeechBalloon.list
+      end
+    end
+    it 'リストを返す' do
+      r = SpeechBalloon.list
+      r.should eq [@sb]
+    end
+    it '時系列で並んでいる' do
+      #公開されたコマのフキダシは(他人のフキダシであっても)含んでいる
+      hc = FactoryGirl.create :panel, :author_id => @other_author.id, :publish => 1
+      npl = FactoryGirl.create :speech_balloon, :panel_id => hc.id, :speech_balloon_template_id => @speech_balloon_template.id, :updated_at => Time.now + 100
+      r = SpeechBalloon.list
+      r.should eq [npl, @sb]
+    end
+    it '非公開のコマのフキダシは自分のフキダシであっても含まない' do
+      hc = FactoryGirl.create :panel, :author_id => @author.id, :publish => 0
+      npl = FactoryGirl.create :speech_balloon, :panel_id => hc.id, :speech_balloon_template_id => @speech_balloon_template.id, :updated_at => Time.now + 100
+      pl = SpeechBalloon.list
+      pl.should eq [@sb]
+    end
+    context 'DBに5件あって1ページの件数を2件に変えたとして' do
+      before do
+        @sb2 = FactoryGirl.create :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id, :t => 1, :updated_at => Time.now + 100
+        @sb3 = FactoryGirl.create :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id, :t => 2, :updated_at => Time.now + 200
+        @sb4 = FactoryGirl.create :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id, :t => 3, :updated_at => Time.now + 300
+        @sb5 = FactoryGirl.create :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id, :t => 4, :updated_at => Time.now + 400
+        SpeechBalloon.stub(:default_page_size).and_return(2)
+      end
+      it '通常は2件を返す' do
+        pl = SpeechBalloon.list
+        pl.should have(2).items 
+      end
+      it 'page=1なら末尾2件を返す' do
+        #時系列で並んでいる
+        pl = SpeechBalloon.list(1)
+        pl.should eq [@sb5, @sb4]
+      end
+      it 'page=2なら中間2件を返す' do
+        pl = SpeechBalloon.list(2)
+        pl.should eq [@sb3, @sb2]
+      end
+      it 'page=3なら先頭1件を返す' do
+        pl = SpeechBalloon.list(3)
+        pl.should eq [@sb]
+      end
+    end
+  end
+  
+  describe '自分のフキダシ一覧取得に於いて' do
+    before do
+      @sb = FactoryGirl.create :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id
+      @balloon = FactoryGirl.create :balloon, :speech_balloon_id => @sb.id, :system_picture_id => @sp.id
+      @speech = FactoryGirl.create :speech, :speech_balloon_id => @sb.id
+    end
+    context 'つつがなく終わるとき' do
+      it '一覧取得オプションを利用している' do
+        SpeechBalloon.stub(:list_opt).with(any_args).and_return({:include => :panel})
+        SpeechBalloon.should_receive(:list_opt).with(any_args).exactly(1)
+        r = SpeechBalloon.mylist @author
+      end
+    end
+    it 'リストを返す' do
+      pl = SpeechBalloon.mylist @author
+      pl.should eq [@sb]
+    end
+    it '時系列で並んでいる' do
+      npl = FactoryGirl.create :speech_balloon, :panel_id => @panel.id, :t => 1, :speech_balloon_template_id => @speech_balloon_template.id, :updated_at => Time.now + 100
+      pl = SpeechBalloon.mylist @author
+      pl.should eq [npl, @sb]
+    end
+    it '他人のコマのフキダシは公開コマでも含まない' do
+      hpl = FactoryGirl.create :panel, :author_id => @other_author.id, :publish => 1
+      npl = FactoryGirl.create :speech_balloon, :panel_id => hpl.id, :t => 1, :speech_balloon_template_id => @speech_balloon_template.id, :updated_at => Time.now + 100
+      pl = SpeechBalloon.mylist @author
+      pl.should eq [@sb]
+    end
+    it '自分のコマのフキダシは非公開コマでも含んでいる' do
+      pl = FactoryGirl.create :panel, :author_id => @author.id, :publish => 0
+      ni = FactoryGirl.create :speech_balloon, :panel_id => pl.id, :t => 1, :speech_balloon_template_id => @speech_balloon_template.id, :updated_at => Time.now + 100
+      r = SpeechBalloon.mylist @author
+      r.should eq [ni, @sb]
+    end
+    context 'DBに5件あって1ページの件数を2件に変えたとして' do
+      before do
+        @npl2 = FactoryGirl.create :speech_balloon, :panel_id => @panel.id, :t => 1, :speech_balloon_template_id => @speech_balloon_template.id, :updated_at => Time.now + 100
+        @npl3 = FactoryGirl.create :speech_balloon, :panel_id => @panel.id, :t => 2, :speech_balloon_template_id => @speech_balloon_template.id, :updated_at => Time.now + 200
+        @npl4 = FactoryGirl.create :speech_balloon, :panel_id => @panel.id, :t => 3, :speech_balloon_template_id => @speech_balloon_template.id, :updated_at => Time.now + 300
+        @npl5 = FactoryGirl.create :speech_balloon, :panel_id => @panel.id, :t => 4, :speech_balloon_template_id => @speech_balloon_template.id, :updated_at => Time.now + 400
+      end
+      it '通常は2件を返す' do
+        r = SpeechBalloon.mylist @author, 1, 2
+        r.should have(2).items 
+      end
+      it 'page=1なら末尾2件を返す' do
+        #時系列で並んでいる
+        r = SpeechBalloon.mylist(@author, 1, 2)
+        r.should eq [@npl5, @npl4]
+      end
+      it 'page=2なら中間2件を返す' do
+        r = SpeechBalloon.mylist(@author, 2, 2)
+        r.should eq [@npl3, @npl2]
+      end
+      it 'page=3なら先頭1件を返す' do
+        r = SpeechBalloon.mylist(@author, 3, 2)
+        r.should eq [@sb]
+      end
     end
-    
   end
   
+  describe '他作家のフキダシ一覧取得に於いて' do
+    before do
+      @sb = FactoryGirl.create :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id
+      @balloon = FactoryGirl.create :balloon, :speech_balloon_id => @sb.id, :system_picture_id => @sp.id
+      @speech = FactoryGirl.create :speech, :speech_balloon_id => @sb.id
+      @other_panel = FactoryGirl.create :panel, :author_id => @other_author.id, :publish => 1
+      @other_sb = FactoryGirl.create :speech_balloon, :panel_id => @other_panel.id, :speech_balloon_template_id => @speech_balloon_template.id
+    end
+    it 'リストを返す' do
+      r = SpeechBalloon.himlist @other_author
+      r.should eq [@other_sb]
+    end
+    it '時系列で並んでいる' do
+      new_panel = FactoryGirl.create :panel, :author_id => @other_author.id, :updated_at => Time.now + 100
+      new_sb = FactoryGirl.create :speech_balloon, :panel_id => new_panel.id, :speech_balloon_template_id => @speech_balloon_template.id, :updated_at => Time.now + 100
+      r = SpeechBalloon.himlist @other_author
+      r.should eq [new_sb, @other_sb]
+    end
+    it '公開コマに限る' do
+      hidden_panel = FactoryGirl.create :panel, :author_id => @other_author.id, :publish => 0
+      hidden_sb = FactoryGirl.create :speech_balloon, :panel_id => hidden_panel.id, :speech_balloon_template_id => @speech_balloon_template.id
+      r = SpeechBalloon.himlist @other_author
+      r.should eq [@other_sb]
+    end
+    context 'DBに5件あって1ページの件数を2件に変えたとして' do
+      before do
+        @other_sb2 = FactoryGirl.create :speech_balloon, :panel_id => @other_panel.id, :t => 1, :speech_balloon_template_id => @speech_balloon_template.id, :updated_at => Time.now + 100
+        @other_sb3 = FactoryGirl.create :speech_balloon, :panel_id => @other_panel.id, :t => 2, :speech_balloon_template_id => @speech_balloon_template.id, :updated_at => Time.now + 200
+        @other_sb4 = FactoryGirl.create :speech_balloon, :panel_id => @other_panel.id, :t => 3, :speech_balloon_template_id => @speech_balloon_template.id, :updated_at => Time.now + 300
+        @other_sb5 = FactoryGirl.create :speech_balloon, :panel_id => @other_panel.id, :t => 4, :speech_balloon_template_id => @speech_balloon_template.id, :updated_at => Time.now + 400
+      end
+      it '通常は2件を返す' do
+        r = SpeechBalloon.himlist @other_author, 1, 2
+        r.should have(2).items 
+      end
+      it 'page=1なら末尾2件を返す' do
+        #時系列で並んでいる
+        r = SpeechBalloon.himlist @other_author, 1, 2
+        r.should eq [@other_sb5, @other_sb4]
+      end
+      it 'page=2なら中間2件を返す' do
+        r = SpeechBalloon.himlist @other_author, 2, 2
+        r.should eq [@other_sb3, @other_sb2]
+      end
+      it 'page=3なら先頭1件を返す' do
+        r = SpeechBalloon.himlist @other_author, 3, 2
+        r.should eq [@other_sb]
+      end
+    end
+  end
+  
+  describe 'フキダシ一覧ページ制御に於いて' do
+    before do
+      SpeechBalloon.stub(:count).with(any_args).and_return(100)
+    end
+    it 'ページ制御を返す' do
+      r = SpeechBalloon.list_paginate 
+      r.is_a?(Kaminari::PaginatableArray).should be_true
+    end
+    it 'フキダシ一覧の取得条件を利用している' do
+      SpeechBalloon.stub(:list_where).with(any_args).and_return('')
+      SpeechBalloon.should_receive(:list_where).with(any_args).exactly(1)
+      r = SpeechBalloon.list_paginate 
+    end
+    it 'ページ件数10のとき、3ページ目のオフセットは20から始まる' do
+      r = SpeechBalloon.list_paginate 3, 10
+      r.limit_value.should eq 10
+      r.offset_value.should eq 20
+    end
+  end
+  
+  describe '自分のフキダシ一覧ページ制御に於いて' do
+    before do
+      SpeechBalloon.stub(:count).with(any_args).and_return(100)
+    end
+    it 'ページ制御を返す' do
+      r = SpeechBalloon.mylist_paginate @author
+      r.is_a?(Kaminari::PaginatableArray).should be_true
+    end
+    it '自分のフキダシ一覧の取得条件を利用している' do
+      SpeechBalloon.stub(:mylist_where).with(any_args).and_return('')
+      SpeechBalloon.should_receive(:mylist_where).with(any_args).exactly(1)
+      r = SpeechBalloon.mylist_paginate @author
+    end
+    it 'ページ件数10のとき、3ページ目のオフセットは20から始まる' do
+      r = SpeechBalloon.mylist_paginate @author, 3, 10
+      r.limit_value.should eq 10
+      r.offset_value.should eq 20
+    end
+  end
+  
+  describe '他作家のフキダシ一覧ページ制御に於いて' do
+    before do
+      SpeechBalloon.stub(:count).with(any_args).and_return(100)
+    end
+    it 'ページ制御を返す' do
+      r = SpeechBalloon.himlist_paginate @other_author
+      r.is_a?(Kaminari::PaginatableArray).should be_true
+    end
+    it '他作家のフキダシ一覧の取得条件を利用している' do
+      SpeechBalloon.stub(:himlist_where).with(any_args).and_return('')
+      SpeechBalloon.should_receive(:himlist_where).with(any_args).exactly(1)
+      r = SpeechBalloon.himlist_paginate @other_author
+    end
+    it 'ページ件数10のとき、3ページ目のオフセットは20から始まる' do
+      r = SpeechBalloon.himlist_paginate @other_author, 3, 10
+      r.limit_value.should eq 10
+      r.offset_value.should eq 20
+    end
+  end
+  
+  describe '一覧取得オプションに於いて' do
+    it '4つの項目を含んでいる' do
+      r = SpeechBalloon.list_opt
+      r.should have(4).items
+    end
+    it 'コマを含んでいる' do
+      r = SpeechBalloon.list_opt
+      r.has_key?(:panel).should be_true
+    end
+      it 'コマは作家を含んでいる' do
+        r = SpeechBalloon.list_opt
+        r[:panel].has_key?(:author).should be_true
+      end
+    it 'フキダシ枠を含んでいる' do
+      r = SpeechBalloon.list_opt
+      r.has_key?(:balloon).should be_true
+    end
+    it 'セリフを含んでいる' do
+      r = SpeechBalloon.list_opt
+      r.has_key?(:speech).should be_true
+    end
+    it 'フキダシテンプレートを含んでいる' do
+      r = SpeechBalloon.list_opt
+      r.has_key?(:speech_balloon_template).should be_true
+    end
+  end
+  describe 'json一覧出力オプションに於いて' do
+    before do
+      @panel = FactoryGirl.create :panel, :author_id => @author.id, :publish => 1
+      @sb = FactoryGirl.create :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id
+      @balloon = FactoryGirl.create :balloon, :speech_balloon_id => @sb.id, :system_picture_id => @sp.id
+      @speech = FactoryGirl.create :speech, :speech_balloon_id => @sb.id
+    end
+    it 'コマを含んでいる' do
+      r = SpeechBalloon.list.to_json SpeechBalloon.list_json_opt
+      j = JSON.parse r
+      i = j.first
+      i.has_key?('panel').should be_true
+    end
+      it 'コマは作家を含んでいる' do
+        r = SpeechBalloon.list.to_json SpeechBalloon.list_json_opt
+        j = JSON.parse r
+        i = j.first
+        s = i['panel']
+        s.has_key?('author').should be_true
+      end
+    it 'フキダシ枠を含んでいる' do
+      r = SpeechBalloon.list.to_json SpeechBalloon.list_json_opt
+      j = JSON.parse r
+      i = j.first
+      i.has_key?('balloon').should be_true
+    end
+    it 'セリフを含んでいる' do
+      r = SpeechBalloon.list.to_json SpeechBalloon.list_json_opt
+      j = JSON.parse r
+      i = j.first
+      i.has_key?('speech').should be_true
+    end
+    it 'フキダシテンプレートを含んでいる' do
+      r = SpeechBalloon.list.to_json SpeechBalloon.list_json_opt
+      j = JSON.parse r
+      i = j.first
+      i.has_key?('speech_balloon_template').should be_true
+    end
+  end
+  
+  describe '単体取得に於いて' do
+    before do
+      @sb = FactoryGirl.create :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id
+      @balloon = FactoryGirl.create :balloon, :speech_balloon_id => @sb.id, :system_picture_id => @sp.id
+      @speech = FactoryGirl.create :speech, :speech_balloon_id => @sb.id
+    end
+    context 'つつがなく終わるとき' do
+      it '単体取得オプションを利用している' do
+        SpeechBalloon.stub(:show_opt).with(any_args).and_return({:include => :panel})
+        SpeechBalloon.should_receive(:show_opt).with(any_args).exactly(1)
+        r = SpeechBalloon.show @sb.id, @author
+      end
+      it '閲覧許可を問い合わせている' do
+        SpeechBalloon.any_instance.stub(:visible?).with(any_args).and_return(true)
+        SpeechBalloon.any_instance.should_receive(:visible?).with(any_args).exactly(1)
+        r = SpeechBalloon.show @sb.id, @author
+      end
+    end
+    it '指定のフキダシを返す' do
+      SpeechBalloon.any_instance.stub(:visible?).and_return(true)
+      pl = SpeechBalloon.show @sb.id, @author
+      pl.should eq @sb
+    end
+    context '閲覧許可が出なかったとき' do
+      it '403Forbidden例外を返す' do
+        SpeechBalloon.any_instance.stub(:visible?).and_return(false)
+        lambda{
+          SpeechBalloon.show @sb.id, @author
+        }.should raise_error(ActiveRecord::Forbidden)
+      end
+    end
+    context '存在しないフキダシを開こうとしたとき' do
+      it '404RecordNotFound例外を返す' do
+        lambda{
+          SpeechBalloon.show 110, @author
+        }.should raise_error(ActiveRecord::RecordNotFound)
+      end
+    end
+  end
+  describe '単体取得オプションに於いて' do
+    it 'includeキーを含んでいる' do
+      r = SpeechBalloon.show_opt
+      r.has_key?(:include).should be_true
+    end
+    it '4つの項目を含んでいる' do
+      r = SpeechBalloon.show_opt[:include]
+      r.should have(4).items
+    end
+    it 'コマを含んでいる' do
+      r = SpeechBalloon.show_opt[:include]
+      r.has_key?(:panel).should be_true
+    end
+      it 'コマは作家を含んでいる' do
+        r = SpeechBalloon.show_opt[:include]
+        r[:panel].has_key?(:author).should be_true
+      end
+    it 'フキダシ枠を含んでいる' do
+      r = SpeechBalloon.show_opt[:include]
+      r.has_key?(:balloon).should be_true
+    end
+    it 'セリフを含んでいる' do
+      r = SpeechBalloon.show_opt[:include]
+      r.has_key?(:speech).should be_true
+    end
+    it 'フキダシテンプレートを含んでいる' do
+      r = SpeechBalloon.show_opt[:include]
+      r.has_key?(:speech_balloon_template).should be_true
+    end
+  end
+  describe 'json単体出力オプションに於いて' do
+    before do
+      @panel = FactoryGirl.create :panel, :author_id => @author.id, :publish => 1
+      @sb = FactoryGirl.create :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id
+      @balloon = FactoryGirl.create :balloon, :speech_balloon_id => @sb.id, :system_picture_id => @sp.id
+      @speech = FactoryGirl.create :speech, :speech_balloon_id => @sb.id
+    end
+    it 'コマを含んでいる' do
+      r = SpeechBalloon.show(@sb.id, @author).to_json SpeechBalloon.show_json_opt
+      j = JSON.parse r
+      i = j
+      i.has_key?('panel').should be_true
+    end
+      it 'コマは作家を含んでいる' do
+        r = SpeechBalloon.show(@sb.id, @author).to_json SpeechBalloon.show_json_opt
+        j = JSON.parse r
+        i = j
+        s = i['panel']
+        s.has_key?('author').should be_true
+      end
+    it 'フキダシ枠を含んでいる' do
+      r = SpeechBalloon.show(@sb.id, @author).to_json SpeechBalloon.show_json_opt
+      j = JSON.parse r
+      i = j
+      i.has_key?('balloon').should be_true
+    end
+    it 'セリフを含んでいる' do
+      r = SpeechBalloon.show(@sb.id, @author).to_json SpeechBalloon.show_json_opt
+      j = JSON.parse r
+      i = j
+      i.has_key?('speech').should be_true
+    end
+    it 'フキダシテンプレートを含んでいる' do
+      r = SpeechBalloon.show(@sb.id, @author).to_json SpeechBalloon.show_json_opt
+      j = JSON.parse r
+      i = j
+      i.has_key?('speech_balloon_template').should be_true
+    end
+  end
 end