{}
end
- def self.templates_json_from attr
- #templatesのballoonがフキダシ画像を持っているはずなので置換しておく
- #templates => {hoge => {balloon => system_picture}}
- (attr["templates"] || {}).each do |n, v|
- next if n == 'speech_balloon'
- res = replace_system_picture(v["balloon"] || {})
- return nil if res == false #置換なしでnil 失敗でfalse
- end
- (attr["templates"] || {}).to_json.to_s
- end
-
def self.store name, attr
#settingsにはHashデータが丸っと文字列化されて入る
- attr["settings"] = SpeechBalloonTemplate.templates_json_from(attr)
- #templatesデータがあるとフキダシテンプレート生成で邪魔するので削除しておく
- attr.delete "templates"
+ r = SpeechBalloonTemplate.replace_system_picture(attr["settings"] || {})
+ attr["settings"] = r ? r.to_json : nil
r = SpeechBalloonTemplate.modify_object name, attr
r.overwrite
r.save
end
end
- describe '拡張データ補充に於いて' do
- #置換まわりが破壊的でテストしにくいので、外部と連携したテストが多い。
- #特にシステム画像データはidを直接記述して置換させないようにテストしている。
- before do
- @sp = FactoryGirl.create :system_picture
- @st = FactoryGirl.build :speech_balloon_template
- @templates = {
- "speech_balloon" => {"default" => 1},
- "one" => {"balloon" => {"system_picture" => 'BASE64'}}
- }
- @sp_replaced_templates = {
- "speech_balloon" => {"default" => 1},
- "one" => {"balloon" => {"system_picture_id" => @sp.id}}
- }
- @attr = {"classname" => 'store', "caption" => 'store test',
- "templates" => @templates
- }
- @sp_replaced_attr = {"classname" => 'store', "caption" => 'store test',
- "templates" => @sp_replaced_templates
- }
- end
- context '事前チェック' do
- it 'システム画像置換に依頼して、テキストの画像データをシステム画像idに置換している' do
- SpeechBalloonTemplate.stub(:replace_system_picture).with(any_args).and_return(true)
- SpeechBalloonTemplate.should_receive(:replace_system_picture).exactly(1)
- r = SpeechBalloonTemplate.templates_json_from @attr
- end
- end
- context 'つつがなく終わるとき' do
- before do
- end
- it 'templates以下をjsonテキスト化して返す' do
- r = SpeechBalloonTemplate.templates_json_from @sp_replaced_attr
- r.should eq @sp_replaced_templates.to_json.to_s
- end
- end
- context 'システム画像の作成に失敗したとき' do
- before do
- SpeechBalloonTemplate.stub(:replace_system_picture).with(any_args).and_return(false)
- end
- it 'nilを返す' do
- r = SpeechBalloonTemplate.templates_json_from @attr
- r.should be_nil
- end
- end
- context 'カラム値にtemplatesがないとき' do
- before do
- @attr.delete "templates"
- SpeechBalloonTemplate.stub(:replace_system_picture).with(any_args).and_return(true)
- end
- it '{}をjsonテキスト化して返す' do
- r = SpeechBalloonTemplate.templates_json_from @attr
- r.should eq '{}'
- end
- end
- context 'templateにballoonがないとき' do
- before do
- @templates = {
- "speech_balloon" => {"default" => 1},
- "one" => {}
- }
- @attr = {"classname" => 'store', "caption" => 'store test',
- "templates" => @templates
- }
- end
- it 'templates以下をjsonテキスト化してを返す' do
- r = SpeechBalloonTemplate.templates_json_from @attr
- r.should eq @templates.to_json.to_s
- end
- end
- end
-
describe '更新に於いて' do
#置換まわりが破壊的でテストしにくいので、外部と連携したテストが多い。
#特にシステム画像データはidを直接記述して置換させないようにテストしている。
before do
@sp = FactoryGirl.create :system_picture
@st = FactoryGirl.create :speech_balloon_template
- @templates = {
+ @settings = {
"speech_balloon" => {"default" => 1},
"one" => {"balloon" => {"system_picture_id" => @sp.id}}
}
@attr = {"classname" => 'store', "caption" => 'store test',
- "templates" => @templates
+ "settings" => @settings
}
end
context '事前チェック' do
before do
- SpeechBalloonTemplate.stub(:templates_json_from).with(any_args).and_return('{}')
+ SpeechBalloonTemplate.stub(:replace_system_picture).with(@settings).and_return(@settings)
SpeechBalloonTemplate.stub(:modify_object).with(any_args).and_return(@st)
SpeechBalloonTemplate.any_instance.stub(:overwrite).with(any_args).and_return(true)
SpeechBalloonTemplate.any_instance.stub(:save).with(any_args).and_return(true)
end
- it 'ã\83\86ã\83³ã\83\97ã\83¬ã\83¼ã\83\88ç½®æ\8f\9bã\81«å\95\8fã\81\84å\90\88ã\82\8fã\81\9bている' do
- SpeechBalloonTemplate.should_receive(:templates_json_from).exactly(1)
+ it 'ã\82·ã\82¹ã\83\86ã\83 ç\94»å\83\8fç½®æ\8f\9bã\81«ä¾\9dé ¼ã\81\97ている' do
+ SpeechBalloonTemplate.should_receive(:replace_system_picture).with(@settings).exactly(1)
r = SpeechBalloonTemplate.store 'circle_v01', @attr
end
it 'インポート処理のデータ更新準備に依頼している' do
end
it 'カラム値のsettingsをセットしている' do
r = SpeechBalloonTemplate.store 'circle_v01', @attr
- r.settings.should eq @templates.to_json.to_s
+ r.settings.should eq @settings.to_json.to_s
end
it 'モデルが作成されている' do
lambda {