1 # -*- encoding: utf-8 -*-
5 describe ResourcePicturesController 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 = FactoryGirl.create :author, :user_id => @user.id
13 @artist = FactoryGirl.create :artist_yas, :author_id => @author.id
14 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
17 describe '一覧表示に於いて' do
19 @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
20 @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id
22 ResourcePicture.stub(:list).and_return([@rp, @rp, @rp])
24 context 'パラメータ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 ResourcePicture.default_page_size
41 it '最大を超えると@page_sizeにデフォルト最大値が入る' do
42 get :index, :page_size => 1500
43 assigns(:page_size).should eq ResourcePicture.max_page_size
45 it '不正な値が入ると@page_sizeにデフォルト最大値が入る' do
46 get :index, :page_size => 0
47 assigns(:page_size).should eq ResourcePicture.default_page_size
50 context 'つつがなく終わるとき' do
51 it '素材モデルに一覧を問い合わせている' do
52 ResourcePicture.should_receive(:list).exactly(1)
55 it '@resource_picturesにリストを取得している' do
57 assigns(:resource_pictures).should have_at_least(3).items
60 it 'ステータスコード200 OKを返す' do
62 response.should be_success
64 it 'indexテンプレートを描画する' do
66 response.should render_template("index")
70 it 'ステータスコード200 OKを返す' do
71 get :index, :format => :json
72 response.should be_success
75 get :index, :format => :json
76 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
78 it '素材モデルにjson一覧出力オプションを問い合わせている' do
79 ResourcePicture.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?("ext").should be_true
91 json.first.has_key?("md5").should be_true
92 json.first.has_key?("picture_id").should be_true
96 context '作家権限がないとき' do
101 it 'ステータスコード302 Foundを返す' do
103 response.status.should eq 302
105 it 'サインインページへ遷移する' do
107 response.should redirect_to '/users/sign_in'
111 it 'ステータスコード401 Unauthorizedを返す' do
112 get :index, :format => :json
113 response.status.should eq 401
115 it '応答メッセージにUnauthorizedを返す' do
116 get :index, :format => :json
117 response.message.should match(/Unauthorized/)
123 describe '単体表示に於いて' do
125 @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
126 @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id
128 ResourcePicture.stub(:show).with(@rp.id.to_s, @author).and_return(@rp)
130 context 'つつがなく終わるとき' do
131 it '素材モデルに単体取得を問い合わせている' do
132 ResourcePicture.should_receive(:show).exactly(1)
133 get :show, :id => @rp.id
135 it '@resource_pictureにアレを取得している' do
136 get :show, :id => @rp.id
137 assigns(:resource_picture).id.should eq(@rp.id)
140 it 'ステータスコード200 OKを返す' do
141 get :show, :id => @rp.id
142 response.should be_success
144 it 'showテンプレートを描画する' do
145 get :show, :id => @rp.id
146 response.should render_template("show")
150 it 'ステータスコード200 OKを返す' do
151 get :show, :id => @rp.id, :format => :json
152 response.should be_success
155 get :show, :id => @rp.id, :format => :json
156 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
158 it '素材モデルにjson単体出力オプションを問い合わせている' do
159 ResourcePicture.should_receive(:show_json_opt).exactly(1)
160 get :show, :id => @rp.id, :format => :json
163 get :show, :id => @rp.id, :format => :json
164 json = JSON.parse response.body
165 json["ext"].should match(/png/)
166 json["md5"].should_not be_nil
167 json["picture_id"].should_not be_nil
170 #画像送信では、send_dataにスタブをおいてテストしたいが、ここに噛ませると
171 #renderが働かず、エラーとなってしまう。そこで、素材のファイル取得部分に
172 #スタブをおいてsend_dataがデータを返す体裁でテストする。
175 ResourcePicture.any_instance.stub(:mime_type).and_return('image/png')
176 ResourcePicture.any_instance.stub(:restore).and_return('aaa')
178 it '画像モデルに画像データを問い合わせる' do
179 ResourcePicture.any_instance.should_receive(:restore).exactly(1)
180 get :show, :id => @rp.id, :format => :png
182 it '画像モデルにMimeTypeを問い合わせる' do
183 ResourcePicture.any_instance.should_receive(:mime_type).exactly(1)
184 get :show, :id => @rp.id, :format => :png
187 get :show, :id => @rp.id, :format => :png
188 response.body.should eq 'aaa'
193 ResourcePicture.any_instance.stub(:mime_type).and_return('image/gif')
194 ResourcePicture.any_instance.stub(:restore).and_return('bbb')
196 it '画像モデルに画像データを問い合わせる' do
197 ResourcePicture.any_instance.should_receive(:restore).exactly(1)
198 get :show, :id => @rp.id, :format => :gif
200 it '画像モデルにMimeTypeを問い合わせる' do
201 ResourcePicture.any_instance.should_receive(:mime_type).exactly(1)
202 get :show, :id => @rp.id, :format => :png
205 get :show, :id => @rp.id, :format => :gif
206 response.body.should eq 'bbb'
211 ResourcePicture.any_instance.stub(:mime_type).and_return('image/jpeg')
212 ResourcePicture.any_instance.stub(:restore).and_return('ccc')
214 it '画像モデルに画像データを問い合わせる' do
215 ResourcePicture.any_instance.should_receive(:restore).exactly(1)
216 get :show, :id => @rp.id, :format => :jpeg
218 it '画像モデルにMimeTypeを問い合わせる' do
219 ResourcePicture.any_instance.should_receive(:mime_type).exactly(1)
220 get :show, :id => @rp.id, :format => :png
223 get :show, :id => @rp.id, :format => :jpeg
224 response.body.should eq 'ccc'
228 context '作家権限がないとき' do
233 it 'ステータスコード302 Foundを返す' do
234 get :show, :id => @rp.id
235 response.status.should eq 302
237 it 'サインインページへ遷移する' do
238 get :show, :id => @rp.id
239 response.body.should redirect_to '/users/sign_in'
243 it 'ステータスコード401 Unauthorizedを返す' do
244 get :show, :id => @rp.id, :format => :json
245 response.status.should eq 401
247 it '応答メッセージにUnauthorizedを返す' do
248 get :show, :id => @rp.id, :format => :json
249 response.message.should match(/Unauthorized/)
254 context '対象素材がないとき' do
256 ResourcePicture.unstub(:show)
259 it '例外404 not_foundを返す' do
262 }.should raise_error(ActiveRecord::RecordNotFound)
266 it '例外404 not_foundを返す' do
268 get :show, :id => 0, :format => :json
269 }.should raise_error(ActiveRecord::RecordNotFound)
273 context '他人の素材を見ようとしたとき' do
275 ResourcePicture.stub(:show).and_return(@rp)
276 ResourcePicture.any_instance.stub(:own?).with(any_args()).and_return(false)
279 it '例外403 forbiddenを返す' do
281 get :show, :id => @rp.id
282 }.should raise_error(ActiveRecord::Forbidden)
286 it '例外403 forbiddenを返す' do
288 get :show, :id => @rp.id, :format => :json
289 }.should raise_error(ActiveRecord::Forbidden)
296 describe '素材数取得に於いて' do
298 ResourcePicture.should_receive(:visible_count).and_return(3)
301 context 'つつがなく終わるとき' do
302 it 'ステータスコード200 OKを返す' do
303 get :count, :format => :json
304 response.should be_success
308 get :count, :format => :json
309 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
311 it 'データがHash構造になっていてコマ絵数が3である' do
312 get :count, :format => :json
313 json = JSON.parse response.body
314 json["count"].should == 3
320 describe 'クレジット表示に於いて' do
322 @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
323 @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id
325 ResourcePicture.stub(:show).with(@rp.id.to_s, @author).and_return(@rp)
327 context 'つつがなく終わるとき' do
328 it '素材モデルに単体取得を問い合わせている' do
329 ResourcePicture.should_receive(:show).exactly(1)
330 get :credit, :id => @rp.id
332 it '@resource_pictureにアレを取得している' do
333 get :credit, :id => @rp.id
334 assigns(:resource_picture).id.should eq(@rp.id)
337 it 'ステータスコード200 OKを返す' do
338 get :credit, :id => @rp.id
339 response.should be_success
341 it 'creditテンプレートを描画する' do
342 get :credit, :id => @rp.id
343 response.should render_template("credit")
347 it 'ステータスコード200 OKを返す' do
348 get :credit, :id => @rp.id, :format => :json
349 response.should be_success
352 get :credit, :id => @rp.id, :format => :json
353 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
355 it '素材モデルにjson単体出力オプションを問い合わせている' do
356 ResourcePicture.should_receive(:show_json_opt).exactly(1)
357 get :credit, :id => @rp.id, :format => :json
360 get :credit, :id => @rp.id, :format => :json
361 json = JSON.parse response.body
362 json["ext"].should match(/png/)
363 json["md5"].should_not be_nil
364 json["picture_id"].should_not be_nil
368 context '作家権限がないとき' do
373 it 'ステータスコード302 Foundを返す' do
374 get :credit, :id => @rp.id
375 response.status.should eq 302
377 it 'サインインページへ遷移する' do
378 get :credit, :id => @rp.id
379 response.body.should redirect_to '/users/sign_in'
383 it 'ステータスコード401 Unauthorizedを返す' do
384 get :credit, :id => @rp.id, :format => :json
385 response.status.should eq 401
387 it '応答メッセージにUnauthorizedを返す' do
388 get :credit, :id => @rp.id, :format => :json
389 response.message.should match(/Unauthorized/)
394 context '対象素材がないとき' do
396 ResourcePicture.unstub(:show)
399 it '例外404 not_foundを返す' do
402 }.should raise_error(ActiveRecord::RecordNotFound)
406 it '例外404 not_foundを返す' do
408 get :show, :id => 0, :format => :json
409 }.should raise_error(ActiveRecord::RecordNotFound)
416 #原画にライセンスを与えるため際の確認フォーム
417 describe '新規作成フォーム表示に於いて' do
420 @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
421 @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id
422 @attr = {:original_picture_id => @op.id, :original_picture_license_group => {:original_picture_id => @op.id, :license_group_id => @lg.id},
423 :resource_picture => {:original_picture_id => @op.id, :license_id => @license.id, :artist_name => @artist.name, :credit => '{}', :settings => '{}' }}
424 @newop = FactoryGirl.create :original_picture, :artist_id => @artist.id
425 @newattr = {:original_picture_id => @newop.id, :original_picture_license_group => {:original_picture_id => @newop.id, :license_group_id => @lg.id},
426 :resource_picture => {:original_picture_id => @newop.id, :license_id => @license.id, :artist_name => @artist.name, :credit => '{}', :settings => '{}' }}
427 @imager = ImagerTest.load("abc\ndef\nghi")
429 context '事前チェックしておく' do
431 OriginalPicture.stub(:edit).with(@op.id.to_s, @artist).and_return(@op)
432 OriginalPicture.stub(:edit).with(@newop.id.to_s, @artist).and_return(@newop)
433 OriginalPicture.any_instance.stub(:restore).with(any_args()).and_return(@imager.binary)
434 PettanImager.stub(:load).with(@imager.binary).and_return(@imager)
435 LicenseGroup.stub(:show).with(@lg.id).and_return(@lg)
436 ResourcePicture.any_instance.stub(:overwrite).with(@op).and_return(true)
437 ResourcePicture.any_instance.stub(:overwrite).with(@newop).and_return(true)
439 it '原画モデルに編集取得を依頼してしている' do
440 OriginalPicture.should_receive(:edit).with(@op.id.to_s, @artist).exactly(1)
443 it '原画モデルに画像データを問い合わせている' do
444 OriginalPicture.any_instance.should_receive(:restore).with(any_args()).exactly(1)
447 it '画像ライブラリをロードしている' do
448 PettanImager.should_receive(:load).with(any_args()).exactly(1)
451 it 'ライセンスグループモデルに単体取得を依頼している' do
452 LicenseGroup.should_receive(:show).with(any_args()).exactly(1)
455 context 'ライセンスを与えようとしている原画が素材を作成してないとき' do
456 it '素材モデルにデフォルト値補充を依頼している' do
457 ResourcePicture.any_instance.should_receive(:supply_default).with(any_args()).exactly(1)
461 context 'ライセンスを与えようとしている原画が既に素材を作成しているとき' do
462 it '素材モデルにデフォルト値補充を依頼してない' do
463 ResourcePicture.any_instance.should_not_receive(:supply_default).with(any_args())
467 it '素材モデルに上書き補充を依頼している' do
468 ResourcePicture.any_instance.should_receive(:overwrite).with(@op).exactly(1)
472 context 'つつがなく終わるとき' do
474 OriginalPicture.stub(:edit).with(@op.id.to_s, @artist).and_return(@op)
475 OriginalPicture.stub(:edit).with(@newop.id.to_s, @artist).and_return(@newop)
476 OriginalPicture.any_instance.stub(:restore).with(any_args()).and_return(@imager.binary)
477 PettanImager.stub(:load).with(@imager.binary).and_return(@imager)
478 LicenseGroup.stub(:show).with(@lg.id).and_return(@lg)
479 ResourcePicture.any_instance.stub(:overwrite).with(@op).and_return(true)
480 ResourcePicture.any_instance.stub(:overwrite).with(@newop).and_return(true)
482 it '@original_pictureに原画を取得している' do
484 assigns(:original_picture).should eq @op
486 it '@imagerに画像ライブラリをロードしている' do
488 assigns(:imager).should eq @imager
490 it '@original_picture_license_groupに新規原画ライセンスグループデータを用意している' do
492 assigns(:original_picture_license_group).should be_a_new(OriginalPictureLicenseGroup)
494 it '@license_groupにライセンスグループを取得している' do
496 assigns(:license_group).should eq @lg
498 context 'ライセンスを与えようとしている原画が素材を作成してないとき' do
499 it '@resource_pictureに新規素材データを用意している' do
501 assigns(:resource_picture).should be_a_new(ResourcePicture)
504 context 'ライセンスを与えようとしている原画が既に素材を作成しているとき' do
505 it '@resource_pictureに素材データを用意している' do
507 assigns(:resource_picture).is_a?(ResourcePicture).should be_true
508 assigns(:resource_picture).should_not be_a_new(ResourcePicture)
512 it 'ステータスコード200 OKを返す' do
514 response.should be_success
516 it 'ページテンプレートnewを描画する' do
518 response.should render_template("new")
523 @attr.merge!({:format => :js})
525 it 'ステータスコード200 OKを返す' do
527 response.should be_success
529 it '部分テンプレートnew.jsを描画する' do
531 response.should render_template("new")
535 context '作家権限がないとき' do
540 it 'ステータスコード302 Foundを返す' do
542 response.status.should eq 302
544 it 'サインインページへ遷移する' do
546 response.body.should redirect_to '/users/sign_in'
551 @attr.merge!({:format => :js})
553 it 'ステータスコード401 Unauthorizedを返す' do
555 response.status.should eq 401
557 it '応答メッセージにUnauthorizedを返す' do
559 response.message.should match(/Unauthorized/)
563 context '作家が絵師でないとき' do
565 Author.any_instance.stub(:artist?).and_return(false)
568 it 'ステータスコード302 Foundを返す' do
570 response.status.should eq 302
574 response.should redirect_to new_artist_path
579 @attr.merge!({:format => :js})
581 it 'ステータスコード200 Okを返す' do
583 response.status.should eq 200
585 it '絵師登録部分テンプレートartists/new.jsを描画する' do
587 response.should render_template("artists/new")
591 context '対象ライセンスグループがないとき' do
593 @attr = {:original_picture_id => @op.id, :original_picture_license_group => {:original_picture_id => @op.id, :license_group_id => 0},
594 :resource_picture => {:original_picture_id => @op.id, :license_id => @license.id, :artist_name => @artist.name, :credit => '{}', :settings => '{}' }}
597 it '例外404 not_foundを返す' do
600 }.should raise_error(ActiveRecord::RecordNotFound)
605 @attr.merge!({:format => :js})
607 it '例外404 not_foundを返す' do
610 }.should raise_error(ActiveRecord::RecordNotFound)
616 describe '新規作成に於いて' do
619 @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
620 @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id
621 @attr = {:original_picture_id => @op.id, :original_picture_license_group => {:original_picture_id => @op.id, :license_group_id => @lg.id},
622 :resource_picture => {:original_picture_id => @op.id, :license_id => @license.id, :artist_name => @artist.name, :credit => '{}', :settings => '{"new":0}' }}
623 @newop = FactoryGirl.create :original_picture, :artist_id => @artist.id
624 @newattr = {:original_picture_id => @newop.id, :original_picture_license_group => {:original_picture_id => @newop.id, :license_group_id => @lg.id},
625 :resource_picture => {:original_picture_id => @newop.id, :license_id => @license.id, :artist_name => @artist.name, :credit => '{}', :settings => '{"new":1}' }}
626 @imager = ImagerTest.load("abc\ndef\nghi")
628 context '事前チェックしておく' do
630 OriginalPicture.stub(:edit).with(@op.id.to_s, @artist).and_return(@op)
631 OriginalPicture.stub(:edit).with(@newop.id.to_s, @artist).and_return(@newop)
632 OriginalPicture.any_instance.stub(:restore).with(any_args()).and_return(@imager.binary)
633 PettanImager.stub(:load).with(@imager.binary).and_return(@imager)
634 LicenseGroup.stub(:show).with(@lg.id).and_return(@lg)
635 ResourcePicture.any_instance.stub(:overwrite).with(@op).and_return(true)
636 ResourcePicture.any_instance.stub(:overwrite).with(@newop).and_return(true)
637 ResourcePicture.any_instance.stub(:store).with(@imager).and_return(true)
639 it '原画モデルに編集取得を依頼してしている' do
640 OriginalPicture.should_receive(:edit).with(@op.id.to_s, @artist).exactly(1)
643 it '原画モデルに画像データを問い合わせている' do
644 OriginalPicture.any_instance.should_receive(:restore).with(any_args()).exactly(1)
647 it '画像ライブラリをロードしている' do
648 PettanImager.should_receive(:load).with(any_args()).exactly(1)
651 it 'ライセンスグループモデルに単体取得を依頼している' do
652 LicenseGroup.should_receive(:show).with(any_args()).exactly(1)
655 context 'ライセンスを与えようとしている原画が素材を作成してないとき' do
656 it '素材モデルにデフォルト値補充を依頼している' do
657 ResourcePicture.any_instance.should_receive(:supply_default).with(any_args()).exactly(1)
658 post :create, @newattr
661 context 'ライセンスを与えようとしている原画が既に素材を作成しているとき' do
662 it '素材モデルにデフォルト値補充を依頼してない' do
663 ResourcePicture.any_instance.should_not_receive(:supply_default).with(any_args())
667 it '素材モデルに上書き補充を依頼している' do
668 ResourcePicture.any_instance.should_receive(:overwrite).with(@op).exactly(1)
671 it '素材モデルに保存を依頼している' do
672 ResourcePicture.any_instance.should_receive(:store).with(@imager).exactly(1)
676 context 'つつがなく終わるとき[ライセンスを与えようとしている原画が素材を作成してない]' do
678 OriginalPicture.stub(:edit).with(@newop.id.to_s, @artist).and_return(@newop)
679 OriginalPicture.any_instance.stub(:restore).with(any_args()).and_return(@imager.binary)
680 PettanImager.stub(:load).with(@imager.binary).and_return(@imager)
681 LicenseGroup.stub(:show).with(@lg.id).and_return(@lg)
682 ResourcePicture.any_instance.stub(:store).with(@imager).and_return {
683 assigns(:resource_picture).attributes = @newattr[:resource_picture]
684 assigns(:resource_picture).overwrite @newop
685 assigns(:resource_picture).picture_id = @p.id
686 assigns(:resource_picture).save!
690 it '@original_pictureに原画を取得している' do
691 post :create, @newattr
692 assigns(:original_picture).should eq @newop
694 it '@imagerに画像ライブラリをロードしている' do
695 post :create, @newattr
696 assigns(:imager).should eq @imager
698 it '@original_picture_license_groupに新規原画ライセンスグループデータを用意している' do
699 post :create, @newattr
700 assigns(:original_picture_license_group).should be_a_new(OriginalPictureLicenseGroup)
702 it '@license_groupにライセンスグループを取得している' do
703 post :create, @newattr
704 assigns(:license_group).should eq @lg
706 it '素材データにPOSTデータの素材情報を適用している' do
707 post :create, @newattr
708 assigns(:resource_picture).license_id.should eq @license.id
709 assigns(:resource_picture).artist_name.should eq @artist.name
710 assigns(:resource_picture).credit.should eq '{}'
711 assigns(:resource_picture).settings.should eq '{"new":1}'
713 it "作成された素材がDBにある" do
715 post :create, @newattr
716 }.should change(ResourcePicture, :count)
719 it 'ステータスコード302 Foundを返す' do
720 post :create, @newattr
721 response.status.should eq 302
723 it '作成された素材の表示ページへ遷移する' do
724 post :create, @newattr
725 response.should redirect_to(ResourcePicture.last)
730 @newattr.merge!({:format => :json})
732 it 'ステータスコード200 OKを返す' do
733 post :create, @newattr
734 response.should be_success
736 it '作成された素材をjsonデータで返す' do
737 post :create, @newattr
738 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
740 it '素材モデルにjson単体出力オプションを問い合わせている' do
741 ResourcePicture.should_receive(:show_json_opt).exactly(1)
742 post :create, @newattr
745 post :create, @newattr
746 json = JSON.parse response.body
747 json["ext"].should match(/png/)
748 json["md5"].should_not be_nil
749 json["picture_id"].should_not be_nil
753 context 'つつがなく終わるとき[ライセンスを与えようとしている原画が既に素材を作成している]' do
755 OriginalPicture.stub(:edit).with(@op.id.to_s, @artist).and_return(@op)
756 OriginalPicture.any_instance.stub(:restore).with(any_args()).and_return(@imager.binary)
757 PettanImager.stub(:load).with(@imager.binary).and_return(@imager)
758 LicenseGroup.stub(:show).with(@lg.id).and_return(@lg)
759 ResourcePicture.any_instance.stub(:store).with(@imager).and_return {
760 assigns(:resource_picture).attributes = @attr[:resource_picture]
761 assigns(:resource_picture).overwrite @op
762 assigns(:resource_picture).save!
766 it '@original_pictureに原画を取得している' do
768 assigns(:original_picture).should eq @op
770 it '素材データにPOSTデータの素材情報を適用している' do
772 assigns(:resource_picture).license_id.should eq @license.id
773 assigns(:resource_picture).artist_name.should eq @artist.name
774 assigns(:resource_picture).credit.should eq '{}'
775 assigns(:resource_picture).settings.should eq '{"new":0}'
779 r = ResourcePicture.find(@rp.id)
780 r.settings.should eq '{"new":0}'
782 it "上書きなので件数は変化しない" do
785 }.should_not change(ResourcePicture, :count)
788 context '作家権限がないとき' do
793 it 'ステータスコード302 Foundを返す' do
795 response.status.should eq 302
797 it 'サインインページへ遷移する' do
799 response.body.should redirect_to '/users/sign_in'
804 @attr.merge!({:format => :js})
806 it 'ステータスコード401 Unauthorizedを返す' do
808 response.status.should eq 401
810 it '応答メッセージにUnauthorizedを返す' do
812 response.message.should match(/Unauthorized/)
816 context '作家が絵師でないとき' do
818 Author.any_instance.stub(:artist?).and_return(false)
821 it 'ステータスコード302 Foundを返す' do
823 response.status.should eq 302
827 response.should redirect_to new_artist_path
832 @attr.merge!({:format => :json})
834 it '例外403 forbiddenを返す' do
837 }.should raise_error(ActiveRecord::Forbidden)
841 context '検証、保存に失敗した' do
843 ResourcePicture.any_instance.stub(:store).and_return(false)
845 it "未保存の素材を保持している" do
846 post :create, @newattr
847 assigns(:resource_picture).should be_a_new(ResourcePicture)
850 it 'ステータスコード200 OKを返す' do
851 post :create, @newattr
852 response.status.should eq 200
855 post :create, @newattr
856 response.should render_template("new")
861 @newattr.merge!({:format => :json})
863 it 'ステータスコード422 unprocessable_entity を返す' do
864 post :create, @newattr
865 response.status.should eq 422
867 it '応答メッセージUnprocessable Entityを返す' do
868 post :create, @newattr
869 response.message.should match(/Unprocessable/)