X-Git-Url: http://git.osdn.net/view?a=blobdiff_plain;f=spec%2Fmodels%2Fspeech_spec.rb;h=51af8e190fede5f317097e6488ae9c63bc7386df;hb=eb397c27a98c59c856b91a5b09d1316b1135a15c;hp=dfeb35b41a6488fe28dc0c7ddb929ed2a7c5effd;hpb=f490b2443e7ad95edda136afda8a2f6f143943dc;p=pettanr%2Fpettanr.git diff --git a/spec/models/speech_spec.rb b/spec/models/speech_spec.rb index dfeb35b4..51af8e19 100644 --- a/spec/models/speech_spec.rb +++ b/spec/models/speech_spec.rb @@ -4,6 +4,7 @@ require 'spec_helper' describe Speech do before do + SpeechBalloonTemplate.delete_all @admin = FactoryGirl.create :admin @user = FactoryGirl.create( :user_yas) @author = FactoryGirl.create :author, :user_id => @user.id @@ -14,19 +15,30 @@ describe Speech do @lg = FactoryGirl.create :license_group @license = FactoryGirl.create :license, :license_group_id => @lg.id, :system_picture_id => @sp.id - @speech_balloon_template = FactoryGirl.create :speech_balloon_template + @writing_format = FactoryGirl.create :writing_format + SpeechBalloonTemplate.delete_all + @speech_balloon_template = FactoryGirl.create :speech_balloon_template, "name" => "circle@pettan.com", "classname" => "CircleSpeechBalloon", "caption" => "cc", "system_picture_id" => @sp.id, "settings" => '{}' @panel = FactoryGirl.create :panel, :author_id => @author.id 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.build :speech, :speech_balloon_id => @sb.id + @sb = FactoryGirl.build :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id + @speech = @sb.build_speech( + FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id) + ) + @balloon = @sb.build_balloon( + FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id) + ) + @sb.boost + @sb.save! end context 'オーソドックスなデータのとき' do it '下限データが通る' do + @speech.font_size = 1.0 + @speech.text_align = 0 + @speech.fore_color = 0 @speech.x = 0 @speech.y = 0 @speech.width = 1 @@ -35,6 +47,9 @@ describe Speech do @speech.should be_valid end it '上限データが通る' do + @speech.font_size = 99999.0 + @speech.text_align = 3 + @speech.fore_color = 0xffffff @speech.x = 99999 @speech.y = 99999 @speech.width = 99999 @@ -57,6 +72,72 @@ describe Speech do end context 'contentを検証するとき' do end + context 'font_sizeを検証するとき' do + it 'nullなら失敗する' do + @speech.font_size = nil + @speech.should_not be_valid + end + it '数値でなければ失敗する' do + @speech.font_size = 'a' + @speech.should_not be_valid + end + it '0なら通る' do + @speech.font_size = '0' + @speech.should be_valid + end + it '10.5なら通る' do + @speech.font_size = '0' + @speech.should be_valid + end + it '負なら失敗する' do + @speech.font_size = 10.5 + @speech.should be_valid + end + end + context 'text_alignを検証するとき' do + it 'nullなら失敗する' do + @speech.text_align = nil + @speech.should_not be_valid + end + it '数値でなければ失敗する' do + @speech.text_align = 'a' + @speech.should_not be_valid + end + it '0なら通る' do + @speech.text_align = '0' + @speech.should be_valid + end + it '負なら失敗する' do + @speech.text_align = -1 + @speech.should_not be_valid + end + it '4なら失敗する' do + @speech.text_align = 4 + @speech.should_not be_valid + end + end + context 'fore_colorを検証するとき' do + it 'nullなら失敗する' do + @speech.fore_color = nil + @speech.should_not be_valid + end + it '数値でなければ失敗する' do + @speech.fore_color = 'a' + @speech.should_not be_valid + end + it '0なら通る' do + @speech.fore_color = '0' + @speech.should be_valid + end + it '負なら失敗する' do + @speech.fore_color = -1 + @speech.should_not be_valid + end + it '24bit colorでなければ失敗する' do + @speech.fore_color = 0x1000000 + @speech.should_not be_valid + end + end context 'xを検証するとき' do it 'nullなら失敗する' do @speech.x = nil @@ -145,9 +226,15 @@ describe Speech 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.build :speech, :speech_balloon_id => @sb.id + @sb = FactoryGirl.build :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id + @speech = @sb.build_speech( + FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id) + ) + @balloon = @sb.build_balloon( + FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id) + ) + @sb.boost + @sb.save! end context 'contentを検証するとき' do @@ -180,9 +267,15 @@ describe Speech 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 + @sb = FactoryGirl.build :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id + @speech = @sb.build_speech( + FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id) + ) + @balloon = @sb.build_balloon( + FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id) + ) + @sb.boost + @sb.save! end context 'オープンモードのとき' do before do @@ -259,9 +352,15 @@ describe Speech 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 + @sb = FactoryGirl.build :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id + @speech = @sb.build_speech( + FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id) + ) + @balloon = @sb.build_balloon( + FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id) + ) + @sb.boost + @sb.save! end context 'page補正について' do it '文字列から数値に変換される' do @@ -302,24 +401,70 @@ describe Speech do it '時系列で並んでいる' do #公開されたコマのセリフは(他人のセリフであっても)含んでいる hc = FactoryGirl.create :panel, :author_id => @other_author.id, :publish => 1 - nsb = FactoryGirl.create :speech_balloon, :panel_id => hc.id, :speech_balloon_template_id => @speech_balloon_template.id, :updated_at => Time.now + 100 - npl = FactoryGirl.create :speech, :speech_balloon_id => nsb.id, :updated_at => Time.now + 100 + nsb = FactoryGirl.build :speech_balloon, :panel_id => hc.id, :speech_balloon_template_id => @speech_balloon_template.id + npl = nsb.build_speech( + FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id, :updated_at => Time.now + 100) + ) + nsb.build_balloon( + FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id) + ) + nsb.boost + nsb.save! r = Speech.list r.should eq [npl, @speech] end it '非公開のコマのセリフは自分のセリフであっても含まない' do hc = FactoryGirl.create :panel, :author_id => @author.id, :publish => 0 - nsb = FactoryGirl.create :speech_balloon, :panel_id => hc.id, :speech_balloon_template_id => @speech_balloon_template.id, :updated_at => Time.now + 100 - npl = FactoryGirl.create :speech, :speech_balloon_id => nsb.id, :updated_at => Time.now + 100 + nsb = FactoryGirl.build :speech_balloon, :panel_id => hc.id, :speech_balloon_template_id => @speech_balloon_template.id + npl = nsb.build_speech( + FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id, :updated_at => Time.now + 100) + ) + nsb.build_balloon( + FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id) + ) + nsb.boost + nsb.save! pl = Speech.list pl.should eq [@speech] end context 'DBに5件あって1ページの件数を2件に変えたとして' do before do - @speech2 = FactoryGirl.create :speech, :speech_balloon_id => @sb.id, :updated_at => Time.now + 100 - @speech3 = FactoryGirl.create :speech, :speech_balloon_id => @sb.id, :updated_at => Time.now + 200 - @speech4 = FactoryGirl.create :speech, :speech_balloon_id => @sb.id, :updated_at => Time.now + 300 - @speech5 = FactoryGirl.create :speech, :speech_balloon_id => @sb.id, :updated_at => Time.now + 400 + @sb2 = FactoryGirl.build :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id + @speech2 = @sb2.build_speech( + FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id, :updated_at => Time.now + 100) + ) + @balloon2 = @sb2.build_balloon( + FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id) + ) + @sb2.boost + @sb2.save! + @sb3 = FactoryGirl.build :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id + @speech3 = @sb3.build_speech( + FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id, :updated_at => Time.now + 200) + ) + @balloon3 = @sb3.build_balloon( + FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id) + ) + @sb3.boost + @sb3.save! + @sb4 = FactoryGirl.build :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id + @speech4 = @sb4.build_speech( + FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id, :updated_at => Time.now + 300) + ) + @balloon4 = @sb4.build_balloon( + FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id) + ) + @sb4.boost + @sb4.save! + @sb5 = FactoryGirl.build :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id + @speech5 = @sb5.build_speech( + FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id, :updated_at => Time.now + 400) + ) + @balloon5 = @sb5.build_balloon( + FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id) + ) + @sb5.boost + @sb5.save! Speech.stub(:default_page_size).and_return(2) end it '通常は2件を返す' do @@ -342,10 +487,42 @@ describe Speech do end context 'DBに5件あって1ページの件数を0件に変えたとして' do before do - @speech2 = FactoryGirl.create :speech, :speech_balloon_id => @sb.id, :updated_at => Time.now + 100 - @speech3 = FactoryGirl.create :speech, :speech_balloon_id => @sb.id, :updated_at => Time.now + 200 - @speech4 = FactoryGirl.create :speech, :speech_balloon_id => @sb.id, :updated_at => Time.now + 300 - @speech5 = FactoryGirl.create :speech, :speech_balloon_id => @sb.id, :updated_at => Time.now + 400 + @sb2 = FactoryGirl.build :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id + @speech2 = @sb2.build_speech( + FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id, :updated_at => Time.now + 100) + ) + @balloon2 = @sb2.build_balloon( + FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id) + ) + @sb2.boost + @sb2.save! + @sb3 = FactoryGirl.build :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id + @speech3 = @sb3.build_speech( + FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id, :updated_at => Time.now + 200) + ) + @balloon3 = @sb3.build_balloon( + FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id) + ) + @sb3.boost + @sb3.save! + @sb4 = FactoryGirl.build :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id + @speech4 = @sb4.build_speech( + FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id, :updated_at => Time.now + 300) + ) + @balloon4 = @sb4.build_balloon( + FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id) + ) + @sb4.boost + @sb4.save! + @sb5 = FactoryGirl.build :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id + @speech5 = @sb5.build_speech( + FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id, :updated_at => Time.now + 400) + ) + @balloon5 = @sb5.build_balloon( + FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id) + ) + @sb5.boost + @sb5.save! Speech.stub(:default_page_size).and_return(2) end it '通常は全件(5件)を返す' do @@ -386,9 +563,15 @@ describe Speech do end describe 'json一覧出力オプションに於いて' 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 + @sb = FactoryGirl.build :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id + @speech = @sb.build_speech( + FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id) + ) + @balloon = @sb.build_balloon( + FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id) + ) + @sb.boost + @sb.save! end it 'フキダシを含んでいる' do r = Speech.list.to_json Speech.list_json_opt @@ -428,9 +611,15 @@ describe Speech 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 + @sb = FactoryGirl.build :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id + @speech = @sb.build_speech( + FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id) + ) + @balloon = @sb.build_balloon( + FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id) + ) + @sb.boost + @sb.save! end context 'つつがなく終わるとき' do it '単体取得オプションを利用している' do @@ -497,9 +686,15 @@ describe Speech do end describe 'json単体出力オプションに於いて' 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 + @sb = FactoryGirl.build :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id + @speech = @sb.build_speech( + FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id) + ) + @balloon = @sb.build_balloon( + FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id) + ) + @sb.boost + @sb.save! end it 'フキダシを含んでいる' do r = Speech.show(@speech.id, @author).to_json Speech.show_json_opt