1 # -*- encoding: utf-8 -*-
4 describe SpeechBalloonTemplate do
6 SpeechBalloonTemplate.delete_all
8 @f = Rails.root + 'spec/json/speech_balloon_template.json'
9 @t = File.open(@f, 'r').read
11 @fs = Rails.root + 'spec/json/speech_balloon_templates.json'
12 @ts = File.open(@fs, 'r').read
14 @fes = Rails.root + 'spec/json/invalid_speech_balloon_templates.json'
15 @tes = File.open(@fes, 'r').read
16 @jes = JSON.parse @tes
18 @admin = FactoryGirl.create :admin
19 @user = FactoryGirl.create( :user_yas)
20 @author = FactoryGirl.create :author, :user_id => @user.id
21 @artist = FactoryGirl.create :artist_yas, :author_id => @author.id
22 @other_user = FactoryGirl.create( :user_yas)
23 @other_author = FactoryGirl.create :author, :user_id => @other_user.id
24 @other_artist = FactoryGirl.create :artist_yas, :author_id => @other_author.id
25 @sp = FactoryGirl.create :system_picture
30 @st = FactoryGirl.build :speech_balloon_template
33 context 'オーソドックスなデータのとき' do
44 @st.classname = 'a'*50
47 @st.settings = '{' + 'a'*99999 + '}'
53 context 'nameを検証するとき' do
56 @st.should_not be_valid
60 @st.should_not be_valid
63 context 'classnameを検証するとき' do
66 @st.should_not be_valid
69 @st.classname = 'a'*51
70 @st.should_not be_valid
73 context 'captionを検証するとき' do
76 @st.should_not be_valid
80 @st.should_not be_valid
86 @st.should_not be_valid
90 @st.should_not be_valid
94 @st.should_not be_valid
97 context 'system_picture_idを検証するとき' do
99 @st.system_picture_id = nil
100 @st.should_not be_valid
103 @st.system_picture_id = 'a'
104 @st.should_not be_valid
106 it '存在するシステム画像でなければ失敗する' do
107 @st.system_picture_id = 0
108 @st.should_not be_valid
111 context 'settingsを検証するとき' do
114 @st.should_not be_valid
119 describe '文字コード検証に於いて' do
121 @st = FactoryGirl.build :speech_balloon_template
124 context 'nameを検証するとき' do
125 it 'Shift JISなら失敗する' do
126 @st.name = "\x83G\x83r\x83]\x83D"
129 }.should raise_error(Pettanr::BadRequest)
133 context 'classnameを検証するとき' do
134 it 'Shift JISなら失敗する' do
135 @st.classname = "\x83G\x83r\x83]\x83D"
138 }.should raise_error(Pettanr::BadRequest)
142 context 'captionを検証するとき' do
143 it 'Shift JISなら失敗する' do
144 @st.caption = "\x83G\x83r\x83]\x83D"
147 }.should raise_error(Pettanr::BadRequest)
151 context 'settingsを検証するとき' do
152 it 'Shift JISなら失敗する' do
153 @st.settings = "\x83G\x83r\x83]\x83D"
156 }.should raise_error(Pettanr::BadRequest)
161 describe 'デフォルト値補充に於いて' do
163 @st = FactoryGirl.build :speech_balloon_template
168 describe '上書き補充に於いて' do
170 @st = FactoryGirl.build :speech_balloon_template
172 it 'テーブルが空のときは0を返す' do
176 it 'テーブルが1行あるときは1を返す' do
177 FactoryGirl.create :speech_balloon_template
181 it 'テーブルが2行あるときは2を返す' do
182 FactoryGirl.create :speech_balloon_template
183 FactoryGirl.create :speech_balloon_template, :name => "5", :t => 1
187 context 'つつがなく終わるとき' do
189 @st = FactoryGirl.create :speech_balloon_template, :t => 0
198 describe '閲覧許可に於いて' do
200 @st = FactoryGirl.build :speech_balloon_template
203 @st.visible?(@author).should == true
207 describe '一覧取得に於いて' do
209 @st = FactoryGirl.create :speech_balloon_template
211 context 'つつがなく終わるとき' do
212 it '一覧取得オプションを利用している' do
213 SpeechBalloonTemplate.stub(:list_opt).with(any_args).and_return({})
214 SpeechBalloonTemplate.should_receive(:list_opt).with(any_args).exactly(1)
215 r = SpeechBalloonTemplate.list
219 l = SpeechBalloonTemplate.list
223 @st2 = FactoryGirl.create :speech_balloon_template, :name => "5", :t => 1
224 l = SpeechBalloonTemplate.list
225 l.should eq [@st, @st2]
228 describe '一覧取得オプションに於いて' do
230 r = SpeechBalloonTemplate.list_opt
231 r.is_a?(Hash).should be_true
235 describe 'json一覧出力オプションに於いて' do
237 r = SpeechBalloonTemplate.list_json_opt
238 r.is_a?(Hash).should be_true
243 describe '単体取得に於いて' do
245 @st = FactoryGirl.create :speech_balloon_template
247 context 'つつがなく終わるとき' do
248 it '単体取得オプションを利用している' do
249 SpeechBalloonTemplate.stub(:show_opt).with(any_args).and_return({})
250 SpeechBalloonTemplate.should_receive(:show_opt).with(any_args).exactly(1)
251 r = SpeechBalloonTemplate.show @st.id, @author
254 it '指定のフキダシテンプレートを返す' do
255 l = SpeechBalloonTemplate.show @st.id, @author
258 context '他人のフキダシテンプレートを開こうとしたとき' do
259 it '403Forbidden例外を返す' do
260 SpeechBalloonTemplate.any_instance.stub(:visible?).and_return(false)
262 r = SpeechBalloonTemplate.show @st.id, @other_author
263 }.should raise_error(ActiveRecord::Forbidden)
266 context '存在しないフキダシテンプレートを開こうとしたとき' do
267 it '404RecordNotFound例外を返す' do
269 SpeechBalloonTemplate.show 110, @author
270 }.should raise_error(ActiveRecord::RecordNotFound)
274 describe '単体出力オプションに於いて' do
276 r = SpeechBalloonTemplate.show_opt
277 r.is_a?(Hash).should be_true
281 describe 'json単体出力オプションに於いて' do
283 r = SpeechBalloonTemplate.show_json_opt
284 r.is_a?(Hash).should be_true
290 #置換まわりが破壊的でテストしにくいので、外部と連携したテストが多い。
291 #特にシステム画像データはidを直接記述して置換させないようにテストしている。
293 @sp = FactoryGirl.create :system_picture
294 @st = FactoryGirl.create :speech_balloon_template
296 "speech_balloon" => {"default" => 1},
297 "one" => {"balloon" => {"system_picture_id" => @sp.id}}
299 @attr = {"classname" => 'store', "caption" => 'store test', "system_picture_id" => @sp.id,
300 "settings" => @settings
305 SpeechBalloonTemplate.stub(:replace_system_picture).with(@attr).and_return(@attr)
306 SpeechBalloonTemplate.stub(:modify_object).with(any_args).and_return(@st)
307 SpeechBalloonTemplate.any_instance.stub(:overwrite).with(any_args).and_return(true)
308 SpeechBalloonTemplate.any_instance.stub(:save).with(any_args).and_return(true)
310 it 'システム画像置換に依頼している' do
311 SpeechBalloonTemplate.should_receive(:replace_system_picture).with(@attr).exactly(1)
312 r = SpeechBalloonTemplate.store 'circle_v01', @attr
314 it 'インポート処理のデータ更新準備に依頼している' do
315 SpeechBalloonTemplate.should_receive(:modify_object).exactly(1)
316 r = SpeechBalloonTemplate.store 'circle_v01', @attr
319 SpeechBalloonTemplate.any_instance.should_receive(:overwrite).exactly(1)
320 r = SpeechBalloonTemplate.store 'circle_v01', @attr
322 it 'オブジェクトを保存している' do
323 SpeechBalloonTemplate.any_instance.should_receive(:save).exactly(1)
324 r = SpeechBalloonTemplate.store 'circle_v01', @attr
327 context 'つつがなく終わるとき' do
330 it 'カラム値のsettingsをセットしている' do
331 r = SpeechBalloonTemplate.store 'circle_v01', @attr
332 r.settings.should eq @settings.to_json.to_s
336 r = SpeechBalloonTemplate.store 'circle_v01', @attr
337 }.should change SpeechBalloonTemplate, :count
340 r = SpeechBalloonTemplate.store 'circle_v01', @attr
341 r.is_a?(SpeechBalloonTemplate).should be_true