- context 'nameが一致するフキダシテンプレートがあるとき' do
- it '該当フキダシテンプレートを値設定して返す' do
- r = SpeechBalloonTemplate.update_speech_balloon_template @st.name, {:classname => 'Update'}
- r.is_a?(SpeechBalloonTemplate).should be_true
- r.should_not be_a_new SpeechBalloonTemplate
- r[:classname].should eq 'Update'
+ context 'つつがなく終わるとき' do
+ before do
+ SystemPicture.stub(:store).with(any_args).and_return(@sp)
+ end
+ it 'システム画像のidを作成している' do
+ r = @st.pic_rehash @hash
+ @hash["templates"]["one"]["balloon"].has_key?("system_picture_id").should be_true
+ @hash["templates"]["one"]["balloon"]["system_picture_id"].should eq @sp.id
+ end
+ it 'システム画像のテキストデータを削除している' do
+ r = @st.pic_rehash @hash
+ @hash["templates"]["one"]["balloon"].has_key?("system_picture").should_not be_true
+ end
+ it 'trueを返す' do
+ r = @st.pic_rehash @hash
+ r.should be_true
+ end
+ end
+ context 'システム画像の作成に失敗したとき' do
+ before do
+ SystemPicture.stub(:store).with(any_args).and_return(false)
+ end
+ it 'Falseを返す' do
+ r = @st.pic_rehash @hash
+ r.should be_false
+ end
+ end
+ context '複数のとき' do
+ before do
+ SystemPicture.stub(:store).with(any_args).and_return(@sp)
+ end
+ it 'システム画像のidを作成している' do
+ r = @st.pic_rehash @hashs
+ @hashs["templates"]["one"]["balloon"].has_key?("system_picture_id").should be_true
+ @hashs["templates"]["one"]["balloon"]["system_picture_id"].should eq @sp.id
+ @hashs["templates"]["two"]["balloon"].has_key?("system_picture_id").should be_true
+ @hashs["templates"]["two"]["balloon"]["system_picture_id"].should eq @sp.id
+ end
+ it 'システム画像のテキストデータを削除している' do
+ r = @st.pic_rehash @hashs
+ @hashs["templates"]["one"]["balloon"].has_key?("system_picture").should_not be_true
+ @hashs["templates"]["two"]["balloon"].has_key?("system_picture").should_not be_true
+ end
+ end
+ context '例外データのとき' do
+ it 'templatesがなくても何ごともなく続行する' do
+ r = @st.pic_rehash({})
+ r.should be_true
+ end
+ it 'templatesが空でも何ごともなく続行する' do
+ r = @st.pic_rehash( {"templates" => nil})
+ r.should be_true
+ end
+ it 'balloonがなくても何ごともなく続行する' do
+ r = @st.pic_rehash({"templates" => {
+ "one" => {}
+ }})
+ r.should be_true
+ end
+ it 'balloonが空でも何ごともなく続行する' do
+ r = @st.pic_rehash({"templates" => {
+ "one" => {"balloon" => nil}
+ }})
+ r.should be_true
+ end
+ it 'system_pictureがなくても何ごともなく続行する' do
+ r = @st.pic_rehash({"templates" => {
+ "one" => {"balloon" => {}}
+ }})
+ r.should be_true