1 # -*- encoding: utf-8 -*-
5 describe DemanderStatusesController do
7 @admin = FactoryGirl.create :admin
8 @sp = FactoryGirl.create :system_picture
9 @lg = FactoryGirl.create :license_group
10 @license = FactoryGirl.create :license, :license_group_id => @lg.id, :system_picture_id => @sp.id
11 @user = FactoryGirl.create :user_yas
12 @author = @user.author #ユーザ作成時に連動して作成される
13 @demand_user = FactoryGirl.create :demand_user
16 describe '一覧表示に於いて' do
18 @ds = FactoryGirl.create :demander_status
19 @demander = FactoryGirl.create :demander, :demander_status_id => @ds.id
20 DemanderStatus.stub(:list).and_return([@ds, @ds, @ds])
21 DemanderStatus.stub(:requested_list).and_return([@ds, @ds])
25 it '与えられたpageがセットされている' do
26 get :index, :page => 5
27 assigns(:page).should eq 5
29 it '省略されると@pageに1値が入る' do
31 assigns(:page).should eq 1
33 it '与えられたpage_sizeがセットされている' do
34 get :index, :page_size => 15
35 assigns(:page_size).should eq 15
37 it '省略されると@page_sizeにデフォルト値が入る' do
39 assigns(:page_size).should eq DemanderStatus.default_page_size
41 it '最大を超えると@page_sizeにデフォルト最大値が入る' do
42 get :index, :page_size => 1500
43 assigns(:page_size).should eq DemanderStatus.max_page_size
45 it '不正な値が入ると@page_sizeにデフォルト最大値が入る' do
46 get :index, :page_size => 0
47 assigns(:page_size).should eq DemanderStatus.default_page_size
50 context 'つつがなく終わるとき' do
51 it 'ステータスコード200 OKを返す' do
53 response.should be_success
57 assigns(:hide).should be_blank
59 it '貸与状況モデルに全一覧取得を問い合わせている' do
60 DemanderStatus.should_receive(:list).exactly(1)
63 it '@demander_statusesにリストを取得している' do
65 assigns(:demander_statuses).should have_at_least(3).items
68 it 'indexテンプレートを描画する' do
70 response.should render_template("index")
75 get :index, :format => :json
76 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
78 it '貸与状況モデルにjson一覧出力オプションを問い合わせている' do
79 DemanderStatus.should_receive(:list_json_opt).exactly(1)
80 get :index, :format => :json
82 it 'データがリスト構造になっている' do
83 get :index, :format => :json
84 json = JSON.parse response.body
85 json.should have_at_least(3).items
87 it 'リストの先頭くらいは貸与状況っぽいものであって欲しい' do
88 get :index, :format => :json
89 json = JSON.parse response.body
90 json.first.has_key?("token").should be_true
91 json.first.has_key?("receive_hour1").should be_true
92 json.first.has_key?("receive_hour2").should be_true
93 json.first.has_key?("requested_at").should be_true
97 context '除外フラグが除外のとき' do
99 get :index, :hide => 1
100 assigns(:hide).should_not be_blank
102 it '貸与状況モデルに申請中一覧取得を問い合わせている' do
103 DemanderStatus.should_receive(:requested_list).exactly(1)
104 get :index, :hide => 1
106 it '@demander_statusesにリストを取得している' do
107 get :index, :hide => 1
108 assigns(:demander_statuses).should have_at_least(2).items
111 context '管理者権限がないとき' do
116 it 'ステータスコード302 Foundを返す' do
118 response.status.should eq 302
120 it 'サインインページへ遷移する' do
122 response.should redirect_to '/admins/sign_in'
126 it 'ステータスコード401 Unauthorizedを返す' do
127 get :index, :format => :json
128 response.status.should eq 401
130 it '応答メッセージにUnauthorizedを返す' do
131 get :index, :format => :json
132 response.message.should match(/Unauthorized/)
138 describe '単体表示に於いて' do
140 @ds = FactoryGirl.create :demander_status
141 @demander = FactoryGirl.create :demander, :demander_status_id => @ds.id
142 DemanderStatus.stub(:show).and_return(@ds)
145 context 'つつがなく終わるとき' do
146 it 'ステータスコード200 OKを返す' do
147 get :show, :id => @ds.id
148 response.should be_success
150 it '貸与状況モデルに単体取得を問い合わせている' do
151 DemanderStatus.should_receive(:show).exactly(1)
154 it '@demander_statusにアレを取得している' do
155 get :show, :id => @ds.id
156 assigns(:demander_status).should eq(@ds)
159 it 'showテンプレートを描画する' do
160 get :show, :id => @ds.id
161 response.should render_template("show")
166 get :show, :id => @ds.id, :format => :json
167 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
169 it '貸与状況モデルにjson単体出力オプションを問い合わせている' do
170 DemanderStatus.should_receive(:show_json_opt).exactly(1)
171 get :show, :id => @ds.id, :format => :json
174 get :show, :id => @ds.id, :format => :json
175 json = JSON.parse response.body
176 json.has_key?("token").should be_true
177 json.has_key?("receive_hour1").should be_true
178 json.has_key?("receive_hour2").should be_true
179 json.has_key?("requested_at").should be_true
183 context '管理者権限がないとき' do
188 it 'ステータスコード302 Foundを返す' do
189 get :show, :id => @ds.id
190 response.status.should eq 302
192 it 'サインインページへ遷移する' do
193 get :show, :id => @ds.id
194 response.body.should redirect_to '/admins/sign_in'
198 it 'ステータスコード401 Unauthorizedを返す' do
199 get :show, :id => @ds.id, :format => :json
200 response.status.should eq 401
202 it '応答メッセージにUnauthorizedを返す' do
203 get :show, :id => @ds.id, :format => :json
204 response.message.should match(/Unauthorized/)
210 describe '編集フォーム表示に於いて' do
212 @ds = FactoryGirl.create :demander_status
213 @demander = FactoryGirl.create :demander, :demander_status_id => @ds.id
215 DemanderStatus.stub(:edit).with(@ds.id.to_s, @admin).and_return(@ds)
217 context 'つつがなく終わるとき' do
218 it 'ステータスコード200 OKを返す' do
219 get :edit, :id => @ds.id
220 response.should be_success
222 it '貸与状況モデルに編集取得を問い合わせている' do
223 DemanderStatus.should_receive(:edit).exactly(1)
224 get :edit, :id => @ds.id
226 it '@demander_statusにデータを用意している' do
227 get :edit, :id => @ds.id
228 assigns(:demander_status).should eq @ds
231 it 'editテンプレートを描画する' do
232 get :edit, :id => @ds.id
233 response.should render_template("edit")
237 context '管理者権限がないとき' do
242 it 'ステータスコード302 Foundを返す' do
243 get :edit, :id => @ds.id
244 response.status.should eq 302
246 it 'サインインページへ遷移する' do
247 get :edit, :id => @ds.id
248 response.body.should redirect_to '/admins/sign_in'
256 @ds = FactoryGirl.create :demander_status, :requested_at => Time.now
257 @demander = FactoryGirl.create :demander, :demander_status_id => @ds.id
258 @attr = {:receive_hour1 => 12, :receive_hour2 => 22}
261 context '事前チェックしておく' do
262 it '貸与状況モデルに編集取得を問い合わせている' do
263 DemanderStatus.stub(:edit).with(any_args()).and_return @ds
264 DemanderStatus.should_receive(:edit).exactly(1)
265 put :update, :id => @ds.id, :demander_status => @attr
267 it '貸与状況モデルに貸与承認を依頼している' do
268 DemanderStatus.any_instance.stub(:approve).with(any_args).and_return true
269 DemanderStatus.any_instance.should_receive(:approve).with('12', '22').exactly(1)
270 put :update, :id => @ds.id, :demander_status => @attr
272 it '@demander_statusにアレを取得している' do
273 put :update, :id => @ds.id, :demander_status => @attr
274 assigns(:demander_status).id.should eq(@ds.id)
277 context 'つつがなく終わるとき' do
279 put :update, :id => @ds.id, :demander_status => @attr
280 DemanderStatus.find(@ds.id).receive_hour1.should eq 12
281 DemanderStatus.find(@ds.id).receive_hour2.should eq 22
286 it 'ステータスコード302 Foundを返す' do
287 put :update, :id => @ds.id, :demander_status => @attr
288 response.status.should eq 302
290 it '更新された貸与状況の表示ページへ遷移する' do
291 put :update, :id => @ds.id, :demander_status => @attr
292 response.should redirect_to(@ds)
294 it '一時的メッセージに処理成功を設定する' do
295 put :update, :id => @ds.id, :demander_status => @attr
296 flash[:notice].should eq I18n.t('demander_statuses.flash.notice.approved')
301 DemanderStatus.any_instance.stub(:approve).with(any_args()).and_return(true)
303 it 'ステータスコード200 OKを返す' do
304 put :update, :id => @ds.id, :demander_status => @attr, :format => :json
305 response.should be_success
308 put :update, :id => @ds.id, :demander_status => @attr, :format => :json
309 response.body.should match /./
313 context '管理者権限がないとき' do
317 it 'ステータスコード302 Foundを返す' do
318 put :update, :id => @ds.id, :demander_status => @attr
319 response.status.should eq 302
322 it 'サインインページへ遷移する' do
323 put :update, :id => @ds.id, :demander_status => @attr
324 response.body.should redirect_to '/admins/sign_in'
328 it '応答メッセージにUnauthorizedを返す' do
329 put :update, :id => @ds.id, :demander_status => @attr, :format => :json
330 response.message.should match(/Unauthorized/)
334 context '検証、保存に失敗したとき' do
336 DemanderStatus.any_instance.stub(:approve).with(any_args()).and_return(false)
339 it 'ステータスコード200 Okを返す' do
340 put :update, :id => @ds.id, :demander_status => @attr
341 response.status.should eq 200
344 put :update, :id => @ds.id, :demander_status => @attr
345 response.should render_template("edit")
349 it 'ステータスコード422 unprocessable_entity を返す' do
350 DemanderStatus.any_instance.stub(:save).and_return(false)
351 put :update, :id => @ds.id, :demander_status => @attr, :format => :json
352 response.status.should eq 422
354 it '応答メッセージUnprocessable Entityを返す' do
355 put :update, :id => @ds.id, :demander_status => @attr, :format => :json
356 response.message.should match(/Unprocessable/)
362 describe '貸与停止に於いて' do
364 @ds = FactoryGirl.create :demander_status
365 @demander = FactoryGirl.create :demander, :demander_status_id => @ds.id
368 context '事前チェックしておく' do
369 it '貸与状況モデルに編集取得を問い合わせている' do
370 DemanderStatus.stub(:edit).with(any_args()).and_return @ds
371 DemanderStatus.should_receive(:edit).exactly(1)
372 delete :destroy, :id => @ds.id
374 it 'モデルに貸与停止を依頼する' do
375 DemanderStatus.any_instance.stub(:reject).with(any_args).and_return true
376 DemanderStatus.any_instance.should_receive(:reject).exactly(1)
377 delete :destroy, :id => @ds.id
379 it '@demander_statusにアレを取得している' do
380 delete :destroy, :id => @ds.id
381 assigns(:demander_status).should eq(@ds)
384 context 'つつがなく終わるとき' do
386 DemanderStatus.any_instance.stub(:reject).with(any_args()).and_return(true)
389 it 'ステータスコード302 Foundを返す' do
390 delete :destroy, :id => @ds.id
391 response.status.should eq 302
393 it '貸与状況閲覧(show)ページに遷移する' do
394 delete :destroy, :id => @ds.id
395 response.should redirect_to(@ds)
397 it '一時的メッセージに処理成功を設定する' do
398 delete :destroy, :id => @ds.id
399 flash[:notice].should eq I18n.t('demander_statuses.flash.notice.rejected')
403 it 'ステータスコード200 OKを返す' do
404 delete :destroy, :id => @ds.id, :format => :json
405 response.should be_success
408 delete :destroy, :id => @ds.id, :format => :json
409 response.body.should match /./
413 context '管理者権限がないとき' do
417 it 'ステータスコード302 Foundを返す' do
418 delete :destroy, :id => @ds.id
419 response.status.should eq 302
422 it 'サインインページへ遷移する' do
423 delete :destroy, :id => @ds.id
424 response.body.should redirect_to '/admins/sign_in'
428 it '応答メッセージにUnauthorizedを返す' do
429 delete :destroy, :id => @ds.id, :format => :json
430 response.message.should match(/Unauthorized/)
435 context '否決に失敗した(否決できる状態でなかった)とき' do
437 DemanderStatus.any_instance.stub(:reject).with(any_args).and_return(false)
440 it 'ステータスコード302 Foundを返す' do
441 delete :destroy, :id => @ds.id
442 response.status.should eq 302
444 it '貸与状況閲覧(show)ページに遷移するする' do
445 delete :destroy, :id => @ds.id
446 response.should redirect_to(@ds)
448 it '一時的メッセージに処理失敗を設定する' do
449 delete :destroy, :id => @ds.id
450 flash[:notice].should eq I18n.t('demander_statuses.flash.notice.not_rejected')
454 it 'ステータスコード422 unprocessable_entity を返す' do
455 delete :destroy, :id => @ds.id, :format => :json
456 response.status.should eq 422
458 it '応答メッセージUnprocessable Entityを返す' do
459 delete :destroy, :id => @ds.id, :format => :json
460 response.message.should match(/Unprocessable/)