From bb0844d2d5f498cb1be426064bdbf15c5f2359b1 Mon Sep 17 00:00:00 2001 From: yasushiito Date: Fri, 19 Oct 2012 07:40:54 +0900 Subject: [PATCH] t#29875:up;sbt sp import update --- app/models/speech_balloon_template.rb | 16 +---- ...121017105739_add_credit_pictures_on_licenses.rb | 9 +++ db/speech_balloon_templates.json | 4 +- spec/models/speech_balloon_template_spec.rb | 84 ++-------------------- 4 files changed, 19 insertions(+), 94 deletions(-) create mode 100644 db/migrate/20121017105739_add_credit_pictures_on_licenses.rb diff --git a/app/models/speech_balloon_template.rb b/app/models/speech_balloon_template.rb index 2e907aa2..b560c3f4 100644 --- a/app/models/speech_balloon_template.rb +++ b/app/models/speech_balloon_template.rb @@ -50,22 +50,10 @@ class SpeechBalloonTemplate < ActiveRecord::Base {} 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 diff --git a/db/migrate/20121017105739_add_credit_pictures_on_licenses.rb b/db/migrate/20121017105739_add_credit_pictures_on_licenses.rb new file mode 100644 index 00000000..4cc6317a --- /dev/null +++ b/db/migrate/20121017105739_add_credit_pictures_on_licenses.rb @@ -0,0 +1,9 @@ +class AddCreditPicturesOnLicenses < ActiveRecord::Migration + def up + add_column :licenses, :credit_pictures, :string + end + + def down + remove_column :licenses, :credit_pictures + end +end diff --git a/db/speech_balloon_templates.json b/db/speech_balloon_templates.json index 5c4421a6..5691110f 100644 --- a/db/speech_balloon_templates.json +++ b/db/speech_balloon_templates.json @@ -2,7 +2,7 @@ "square@pettan.com": { "classname": "Square", "caption": "長方形", - "templates": { + "settings": { "speech_balloon": { "default_width": 150, "default_height": 150 @@ -25,7 +25,7 @@ "square with size@pettan.com": { "classname": "SquareWithSize", "caption": "長方形改", - "templates": { + "settings": { "speech_balloon": { "default_width": 150, "default_height": 100, diff --git a/spec/models/speech_balloon_template_spec.rb b/spec/models/speech_balloon_template_spec.rb index 0c40e529..01a5bbc5 100644 --- a/spec/models/speech_balloon_template_spec.rb +++ b/spec/models/speech_balloon_template_spec.rb @@ -228,101 +228,29 @@ describe SpeechBalloonTemplate do 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 'テンプレート置換に問い合わせている' do - SpeechBalloonTemplate.should_receive(:templates_json_from).exactly(1) + it 'システム画像置換に依頼している' do + SpeechBalloonTemplate.should_receive(:replace_system_picture).with(@settings).exactly(1) r = SpeechBalloonTemplate.store 'circle_v01', @attr end it 'インポート処理のデータ更新準備に依頼している' do @@ -343,7 +271,7 @@ describe SpeechBalloonTemplate 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 { -- 2.11.0