1 # -*- encoding: utf-8 -*-
4 describe SpeechBalloonTemplate do
7 @f = Rails.root + 'spec/json/speech_balloon_template.json'
8 @t = File.open(@f, 'r').read
10 @fs = Rails.root + 'spec/json/speech_balloon_templates.json'
11 @ts = File.open(@fs, 'r').read
13 @fes = Rails.root + 'spec/json/invalid_speech_balloon_templates.json'
14 @tes = File.open(@fes, 'r').read
15 @jes = JSON.parse @tes
17 @admin = FactoryGirl.create :admin
18 @user = FactoryGirl.create( :user_yas)
19 @author = FactoryGirl.create :author, :user_id => @user.id
20 @artist = FactoryGirl.create :artist_yas, :author_id => @author.id
21 @other_user = FactoryGirl.create( :user_yas)
22 @other_author = FactoryGirl.create :author, :user_id => @other_user.id
23 @other_artist = FactoryGirl.create :artist_yas, :author_id => @other_author.id
28 @st = FactoryGirl.build :speech_balloon_template
31 context 'オーソドックスなデータのとき' do
42 @st.classname = 'a'*50
45 @st.settings = '{' + 'a'*99999 + '}'
51 context 'nameを検証するとき' do
54 @st.should_not be_valid
58 @st.should_not be_valid
61 context 'classnameを検証するとき' do
64 @st.should_not be_valid
67 @st.classname = 'a'*51
68 @st.should_not be_valid
71 context 'captionを検証するとき' do
74 @st.should_not be_valid
78 @st.should_not be_valid
84 @st.should_not be_valid
88 @st.should_not be_valid
92 @st.should_not be_valid
95 context 'settingsを検証するとき' do
98 @st.should_not be_valid
103 describe '文字コード検証に於いて' do
105 @st = FactoryGirl.build :speech_balloon_template
108 context 'nameを検証するとき' do
109 it 'Shift JISなら失敗する' do
110 @st.name = "\x83G\x83r\x83]\x83D"
113 }.should raise_error(Pettanr::BadRequest)
117 context 'classnameを検証するとき' do
118 it 'Shift JISなら失敗する' do
119 @st.classname = "\x83G\x83r\x83]\x83D"
122 }.should raise_error(Pettanr::BadRequest)
126 context 'captionを検証するとき' do
127 it 'Shift JISなら失敗する' do
128 @st.caption = "\x83G\x83r\x83]\x83D"
131 }.should raise_error(Pettanr::BadRequest)
135 context 'settingsを検証するとき' do
136 it 'Shift JISなら失敗する' do
137 @st.settings = "\x83G\x83r\x83]\x83D"
140 }.should raise_error(Pettanr::BadRequest)
145 describe 'デフォルト値補充に於いて' do
147 @st = FactoryGirl.build :speech_balloon_template
152 describe '上書き補充に於いて' do
154 @st = FactoryGirl.build :speech_balloon_template
156 it 'テーブルが空のときは0を返す' do
160 it 'テーブルが1行あるときは1を返す' do
161 FactoryGirl.create :speech_balloon_template
165 it 'テーブルが2行あるときは2を返す' do
166 FactoryGirl.create :speech_balloon_template
167 FactoryGirl.create :speech_balloon_template, :name => "5", :t => 1
171 context 'つつがなく終わるとき' do
173 @st = FactoryGirl.create :speech_balloon_template, :t => 0
182 describe '閲覧許可に於いて' do
184 @st = FactoryGirl.build :speech_balloon_template
187 @st.visible?(@author).should == true
191 describe '一覧取得に於いて' do
193 @st = FactoryGirl.create :speech_balloon_template
195 context 'つつがなく終わるとき' do
196 it '一覧取得オプションを利用している' do
197 SpeechBalloonTemplate.stub(:list_opt).with(any_args).and_return({})
198 SpeechBalloonTemplate.should_receive(:list_opt).with(any_args).exactly(1)
199 r = SpeechBalloonTemplate.list
203 l = SpeechBalloonTemplate.list
207 @st2 = FactoryGirl.create :speech_balloon_template, :name => "5", :t => 1
208 l = SpeechBalloonTemplate.list
209 l.should eq [@st, @st2]
212 describe '一覧取得オプションに於いて' do
214 r = SpeechBalloonTemplate.list_opt
215 r.is_a?(Hash).should be_true
219 describe 'json一覧出力オプションに於いて' do
221 r = SpeechBalloonTemplate.list_json_opt
222 r.is_a?(Hash).should be_true
227 describe '単体取得に於いて' do
229 @st = FactoryGirl.create :speech_balloon_template
231 context 'つつがなく終わるとき' do
232 it '単体取得オプションを利用している' do
233 SpeechBalloonTemplate.stub(:show_opt).with(any_args).and_return({})
234 SpeechBalloonTemplate.should_receive(:show_opt).with(any_args).exactly(1)
235 r = SpeechBalloonTemplate.show @st.id, @author
238 it '指定のフキダシテンプレートを返す' do
239 l = SpeechBalloonTemplate.show @st.id, @author
242 context '他人のフキダシテンプレートを開こうとしたとき' do
243 it '403Forbidden例外を返す' do
244 SpeechBalloonTemplate.any_instance.stub(:visible?).and_return(false)
246 r = SpeechBalloonTemplate.show @st.id, @other_author
247 }.should raise_error(ActiveRecord::Forbidden)
250 context '存在しないフキダシテンプレートを開こうとしたとき' do
251 it '404RecordNotFound例外を返す' do
253 SpeechBalloonTemplate.show 110, @author
254 }.should raise_error(ActiveRecord::RecordNotFound)
258 describe '単体出力オプションに於いて' do
260 r = SpeechBalloonTemplate.show_opt
261 r.is_a?(Hash).should be_true
265 describe 'json単体出力オプションに於いて' do
267 r = SpeechBalloonTemplate.show_json_opt
268 r.is_a?(Hash).should be_true
274 #置換まわりが破壊的でテストしにくいので、外部と連携したテストが多い。
275 #特にシステム画像データはidを直接記述して置換させないようにテストしている。
277 @sp = FactoryGirl.create :system_picture
278 @st = FactoryGirl.create :speech_balloon_template
280 "speech_balloon" => {"default" => 1},
281 "one" => {"balloon" => {"system_picture_id" => @sp.id}}
283 @attr = {"classname" => 'store', "caption" => 'store test',
284 "settings" => @settings
289 SpeechBalloonTemplate.stub(:replace_system_picture).with(@settings).and_return(@settings)
290 SpeechBalloonTemplate.stub(:modify_object).with(any_args).and_return(@st)
291 SpeechBalloonTemplate.any_instance.stub(:overwrite).with(any_args).and_return(true)
292 SpeechBalloonTemplate.any_instance.stub(:save).with(any_args).and_return(true)
294 it 'システム画像置換に依頼している' do
295 SpeechBalloonTemplate.should_receive(:replace_system_picture).with(@settings).exactly(1)
296 r = SpeechBalloonTemplate.store 'circle_v01', @attr
298 it 'インポート処理のデータ更新準備に依頼している' do
299 SpeechBalloonTemplate.should_receive(:modify_object).exactly(1)
300 r = SpeechBalloonTemplate.store 'circle_v01', @attr
303 SpeechBalloonTemplate.any_instance.should_receive(:overwrite).exactly(1)
304 r = SpeechBalloonTemplate.store 'circle_v01', @attr
306 it 'オブジェクトを保存している' do
307 SpeechBalloonTemplate.any_instance.should_receive(:save).exactly(1)
308 r = SpeechBalloonTemplate.store 'circle_v01', @attr
311 context 'つつがなく終わるとき' do
314 it 'カラム値のsettingsをセットしている' do
315 r = SpeechBalloonTemplate.store 'circle_v01', @attr
316 r.settings.should eq @settings.to_json.to_s
320 r = SpeechBalloonTemplate.store 'circle_v01', @attr
321 }.should change SpeechBalloonTemplate, :count
324 r = SpeechBalloonTemplate.store 'circle_v01', @attr
325 r.is_a?(SpeechBalloonTemplate).should be_true