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
110 describe '上書き補充に於いて' do
112 @st = FactoryGirl.build :speech_balloon_template
114 it 'テーブルが空のときは0を返す' do
118 it 'テーブルが1行あるときは1を返す' do
119 FactoryGirl.create :speech_balloon_template
123 it 'テーブルが2行あるときは2を返す' do
124 FactoryGirl.create :speech_balloon_template
125 FactoryGirl.create :speech_balloon_template, :name => "5", :t => 1
129 context 'つつがなく終わるとき' do
131 @st = FactoryGirl.create :speech_balloon_template, :t => 0
140 describe '閲覧許可に於いて' do
142 @st = FactoryGirl.build :speech_balloon_template
145 @st.visible?(@author).should == true
149 describe '一覧取得に於いて' do
151 @st = FactoryGirl.create :speech_balloon_template
153 context 'つつがなく終わるとき' do
154 it '一覧取得オプションを利用している' do
155 SpeechBalloonTemplate.stub(:list_opt).with(any_args).and_return({})
156 SpeechBalloonTemplate.should_receive(:list_opt).with(any_args).exactly(1)
157 r = SpeechBalloonTemplate.list
161 l = SpeechBalloonTemplate.list
165 @st2 = FactoryGirl.create :speech_balloon_template, :name => "5", :t => 1
166 l = SpeechBalloonTemplate.list
167 l.should eq [@st, @st2]
170 describe '一覧取得オプションに於いて' do
172 r = SpeechBalloonTemplate.list_opt
173 r.is_a?(Hash).should be_true
177 describe 'json一覧出力オプションに於いて' do
179 r = SpeechBalloonTemplate.list_json_opt
180 r.is_a?(Hash).should be_true
185 describe '単体取得に於いて' do
187 @st = FactoryGirl.create :speech_balloon_template
189 context 'つつがなく終わるとき' do
190 it '単体取得オプションを利用している' do
191 SpeechBalloonTemplate.stub(:show_opt).with(any_args).and_return({})
192 SpeechBalloonTemplate.should_receive(:show_opt).with(any_args).exactly(1)
193 r = SpeechBalloonTemplate.show @st.id, @author
196 it '指定のフキダシテンプレートを返す' do
197 l = SpeechBalloonTemplate.show @st.id, @author
200 context '他人のフキダシテンプレートを開こうとしたとき' do
201 it '403Forbidden例外を返す' do
202 SpeechBalloonTemplate.any_instance.stub(:visible?).and_return(false)
204 r = SpeechBalloonTemplate.show @st.id, @other_author
205 }.should raise_error(ActiveRecord::Forbidden)
208 context '存在しないフキダシテンプレートを開こうとしたとき' do
209 it '404RecordNotFound例外を返す' do
211 SpeechBalloonTemplate.show 110, @author
212 }.should raise_error(ActiveRecord::RecordNotFound)
216 describe '単体出力オプションに於いて' do
218 r = SpeechBalloonTemplate.show_opt
219 r.is_a?(Hash).should be_true
223 describe 'json単体出力オプションに於いて' do
225 r = SpeechBalloonTemplate.show_json_opt
226 r.is_a?(Hash).should be_true
232 #置換まわりが破壊的でテストしにくいので、外部と連携したテストが多い。
233 #特にシステム画像データはidを直接記述して置換させないようにテストしている。
235 @sp = FactoryGirl.create :system_picture
236 @st = FactoryGirl.create :speech_balloon_template
238 "speech_balloon" => {"default" => 1},
239 "one" => {"balloon" => {"system_picture_id" => @sp.id}}
241 @attr = {"classname" => 'store', "caption" => 'store test',
242 "settings" => @settings
247 SpeechBalloonTemplate.stub(:replace_system_picture).with(@settings).and_return(@settings)
248 SpeechBalloonTemplate.stub(:modify_object).with(any_args).and_return(@st)
249 SpeechBalloonTemplate.any_instance.stub(:overwrite).with(any_args).and_return(true)
250 SpeechBalloonTemplate.any_instance.stub(:save).with(any_args).and_return(true)
252 it 'システム画像置換に依頼している' do
253 SpeechBalloonTemplate.should_receive(:replace_system_picture).with(@settings).exactly(1)
254 r = SpeechBalloonTemplate.store 'circle_v01', @attr
256 it 'インポート処理のデータ更新準備に依頼している' do
257 SpeechBalloonTemplate.should_receive(:modify_object).exactly(1)
258 r = SpeechBalloonTemplate.store 'circle_v01', @attr
261 SpeechBalloonTemplate.any_instance.should_receive(:overwrite).exactly(1)
262 r = SpeechBalloonTemplate.store 'circle_v01', @attr
264 it 'オブジェクトを保存している' do
265 SpeechBalloonTemplate.any_instance.should_receive(:save).exactly(1)
266 r = SpeechBalloonTemplate.store 'circle_v01', @attr
269 context 'つつがなく終わるとき' do
272 it 'カラム値のsettingsをセットしている' do
273 r = SpeechBalloonTemplate.store 'circle_v01', @attr
274 r.settings.should eq @settings.to_json.to_s
278 r = SpeechBalloonTemplate.store 'circle_v01', @attr
279 }.should change SpeechBalloonTemplate, :count
282 r = SpeechBalloonTemplate.store 'circle_v01', @attr
283 r.is_a?(SpeechBalloonTemplate).should be_true