end
end
- describe '対象フキダシテンプレートの取得に於いて' do
+ describe 'システム画像置換に於いて' do
before do
- @st = Factory :speech_balloon_template
+ @sp = Factory :system_picture
+ @sp2 = Factory :system_picture
+ @st = Factory.build :speech_balloon_template
+ @hash = {"classname" => 'sore', "caption" => 'store test',
+ "templates" => {
+ "one" => {"balloon" => {"system_picture" => 'BASE64'}}
+ }
+ }
+ @hashs = {"classname" => 'sore2', "caption" => 'store test2',
+ "templates" => {
+ "one" => {"balloon" => {"system_picture" => 'DUAL'}},
+ "two" => {"balloon" => {"system_picture" => 'BASE64ENC'}}
+ }
+ }
end
- context 'nameが一致するフキダシテンプレートがないとき' do
- it '新規フキダシテンプレートを準備して返す' do
- r = SpeechBalloonTemplate.update_speech_balloon_template 'newtemplate', {:classname => 'New'}
- r.should be_a_new SpeechBalloonTemplate
- r[:classname].should eq 'New'
+ context '事前チェック' do
+ it 'システム画像に保存を依頼している' do
+ SystemPicture.stub(:store).with(any_args).and_return(@sp)
+ SystemPicture.should_receive(:store).exactly(1)
+ r = @st.pic_rehash @hash
end
end
- 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
end
end
end
describe 'フキダシテンプレート保存に於いて' do
before do
@st = Factory.build :speech_balloon_template
+ @hash = {"classname" => 'sore', "caption" => 'store test'}
+ end
+ context '事前チェック' do
+ it 'システム画像置換を依頼している' do
+ SpeechBalloonTemplate.any_instance.stub(:pic_rehash).with(@hash).and_return(true)
+ SpeechBalloonTemplate.any_instance.should_receive(:pic_rehash).exactly(1)
+ r = @st.store @hash
+ end
end
context 'つつがなく終わるとき' do
- it '保存を問い合わせている' do
- SpeechBalloonTemplate.any_instance.should_receive(:save).exactly(1)
- @st.store
+ before do
+ SpeechBalloonTemplate.any_instance.stub(:pic_rehash).with(@hash).and_return(true)
+ end
+ it 'hashから取り出したclassnameをセットしている' do
+ @st.store @hash
+ @st.classname.should eq @hash["classname"]
+ end
+ it 'hashから取り出したcaptionをセットしている' do
+ @st.store @hash
+ @st.caption.should eq @hash["caption"]
+ end
+ it 'hashをテキスト化してsettingsにセットしている' do
+ @st.store @hash
+ @st.settings.should eq @hash.to_s
end
it 'フキダシテンプレートが作成されている' do
lambda {
- @st.store
+ @st.store @hash
}.should change SpeechBalloonTemplate, :count
end
end
+ context 'システム画像置換が失敗したとき' do
+ before do
+ SpeechBalloonTemplate.any_instance.stub(:pic_rehash).with(@hash).and_return(false)
+ end
+ it 'Falseを返す' do
+ r = @st.store @hash
+ r.should be_false
+ end
+ end
+ context '保存が失敗したとき' do
+ before do
+ SpeechBalloonTemplate.any_instance.stub(:pic_rehash).with(@hash).and_return(true)
+ SpeechBalloonTemplate.any_instance.stub(:save).with(any_args).and_return(false)
+ end
+ it 'Falseを返す' do
+ r = @st.store @hash
+ r.should be_false
+ end
+ end
end
describe 'フキダシテンプレート更新に於いて' do
before do
@st = Factory :speech_balloon_template
- @attr = {:name => @st.name, :classname => 'Update', :t => 0, :caption => 'yp', :settings => '{}'}
- @newattr = {:name => @st.name, :classname => 'New', :t => 1, :caption => 'nw', :settings => '{}'}
+ @hash = {}
end
context 'つつがなく終わるとき' do
- it '対象フキダシテンプレートを問い合わせている' do
- SpeechBalloonTemplate.stub(:update_speech_balloon_template).with(any_args).and_return(SpeechBalloonTemplate.new(@attr))
- SpeechBalloonTemplate.should_receive(:update_speech_balloon_template).exactly(1)
- SpeechBalloonTemplate.store @st.name, @attr
+ it '保存依頼している' do
+ SpeechBalloonTemplate.any_instance.stub(:store).with(@hash).and_return(true)
+ SpeechBalloonTemplate.should_receive(:store).exactly(1)
+ SpeechBalloonTemplate.store @st.name, @hash
end
context '新規のとき' do
- it 'フキダシテンプレートを保存しようとしている' do
- SpeechBalloonTemplate.any_instance.should_receive(:save).exactly(1)
- SpeechBalloonTemplate.store 'newtemplate', @newattr
- end
- it 'フキダシテンプレートが作成されている' do
- lambda {
- SpeechBalloonTemplate.store 'newtemplate', @newattr
- }.should change SpeechBalloonTemplate, :count
+ #新規作成をチェックしたいが、楽するために(storeが保存しないことを利用して)新規オブジェクト生成かでテスト
+ it 'フキダシテンプレートは新規オブジェクトである' do
+ SpeechBalloonTemplate.any_instance.stub(:store).with(@hash).and_return(true)
+ r = SpeechBalloonTemplate.store :newsbtname, @hash
+ r.should be_a_new SpeechBalloonTemplate
end
end
context '更新のとき' do
- it 'フキダシテンプレートを保存しようとしている' do
- SpeechBalloonTemplate.any_instance.should_receive(:save).exactly(1)
- SpeechBalloonTemplate.store @st.name, @attr
- end
- it 'フキダシテンプレートの数に変化がない' do
- lambda {
- SpeechBalloonTemplate.store @st.name, @attr
- }.should_not change SpeechBalloonTemplate, :count
+ it '名前が一致するテンプレを返す' do
+ SpeechBalloonTemplate.any_instance.stub(:store).with(@hash).and_return(true)
+ r = SpeechBalloonTemplate.store @st.name, @hash
+ r.name.should eq @st.name
+ r.should_not be_a_new SpeechBalloonTemplate
end
end
- it '属性が一致している' do
- r = SpeechBalloonTemplate.store 'newtemplate', @newattr
- r.classname.should eq 'New'
- end
- it '保存されたSpeechBalloonTemplateオブジェクトを返す' do
- r = SpeechBalloonTemplate.store 'newtemplate', @newattr
-p r.errors.full_messages
- r.should_not be_a_new SpeechBalloonTemplate
- end
end
context 'フキダシテンプレートの作成に失敗するとき' do
before do
- SpeechBalloonTemplate.any_instance.stub(:save).with(any_args).and_return(false)
- end
- context '新規のとき' do
- it 'フキダシテンプレートに変化がない' do
- lambda {
- r = SpeechBalloonTemplate.store 'newtemplate', @newattr
- }.should_not change License, :count
- end
- end
- context '更新のとき' do
- it 'フキダシテンプレート属性に変化がない' do
- lambda {
- r = SpeechBalloonTemplate.store @st.name, @attr
- }.should_not change License.find(@st.id), :classname
- end
+ SpeechBalloonTemplate.any_instance.stub(:store).with(any_args).and_return(false)
end
+ #成功失敗に関わらずオブジェクトを返すのでテストのやりようがない
+
end
end
it '配列の中身は失敗したフキダシテンプレートオブジェクトが入っている' do
r = SpeechBalloonTemplate.import(@tes)
r[0].is_a?(SpeechBalloonTemplate).should be_true
- r[0]["name"].should eq 'fail1'
+ r[0]["name"].should eq 'squareR@pettan.com'
r[1].is_a?(SpeechBalloonTemplate).should be_true
- r[1]["name"].should eq 'fail2'
+ r[1]["name"].should eq 'squareRR@pettan.com'
end
end
end