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 if MagicNumber['run_mode'] == 1
18 describe '一覧表示に於いて' do
20 @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
21 @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id
23 ResourcePicture.stub(:list).and_return([@rp, @rp, @rp])
25 context 'パラメータpageについて' do
27 get :index, :page => 5
28 assigns(:page).should eq 5
30 it '省略されると@pageに1値が入る' do
32 assigns(:page).should eq 1
34 it '与えられたpage_sizeがセットされている' do
35 get :index, :page_size => 15
36 assigns(:page_size).should eq 15
38 it '省略されると@page_sizeにデフォルト値が入る' do
40 assigns(:page_size).should eq ResourcePicture.default_page_size
42 it '最大を超えると@page_sizeにデフォルト最大値が入る' do
43 get :index, :page_size => 1500
44 assigns(:page_size).should eq ResourcePicture.max_page_size
46 it '不正な値が入ると@page_sizeにデフォルト最大値が入る' do
47 get :index, :page_size => 0
48 assigns(:page_size).should eq ResourcePicture.default_page_size
51 context 'つつがなく終わるとき' do
52 it '素材モデルに一覧を問い合わせている' do
53 ResourcePicture.should_receive(:list).exactly(1)
56 it '@resource_picturesにリストを取得している' do
58 assigns(:resource_pictures).should have_at_least(3).items
61 it 'ステータスコード200 OKを返す' do
63 response.should be_success
65 it 'indexテンプレートを描画する' do
67 response.should render_template("index")
71 it 'ステータスコード200 OKを返す' do
72 get :index, :format => :json
73 response.should be_success
76 get :index, :format => :json
77 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
79 it '素材モデルにjson一覧出力オプションを問い合わせている' do
80 ResourcePicture.should_receive(:list_json_opt).exactly(1)
81 get :index, :format => :json
83 it 'データがリスト構造になっている' do
84 get :index, :format => :json
85 json = JSON.parse response.body
86 json.should have_at_least(3).items
88 it 'リストの先頭くらいは素材っぽいものであって欲しい' do
89 get :index, :format => :json
90 json = JSON.parse response.body
91 json.first.has_key?("ext").should be_true
92 json.first.has_key?("md5").should be_true
93 json.first.has_key?("picture_id").should be_true
97 context '作家権限がないとき' do
102 it 'ステータスコード302 Foundを返す' do
104 response.status.should eq 302
106 it 'サインインページへ遷移する' do
108 response.should redirect_to '/users/sign_in'
112 it 'ステータスコード401 Unauthorizedを返す' do
113 get :index, :format => :json
114 response.status.should eq 401
116 it '応答メッセージにUnauthorizedを返す' do
117 get :index, :format => :json
118 response.message.should match(/Unauthorized/)
124 describe '単体表示に於いて' do
126 @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
127 @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id
129 ResourcePicture.stub(:show).with(@rp.id.to_s, @author).and_return(@rp)
131 context 'つつがなく終わるとき' do
132 it '素材モデルに単体取得を問い合わせている' do
133 ResourcePicture.should_receive(:show).exactly(1)
134 get :show, :id => @rp.id
136 it '@resource_pictureにアレを取得している' do
137 get :show, :id => @rp.id
138 assigns(:resource_picture).id.should eq(@rp.id)
141 it 'ステータスコード200 OKを返す' do
142 get :show, :id => @rp.id
143 response.should be_success
145 it 'showテンプレートを描画する' do
146 get :show, :id => @rp.id
147 response.should render_template("show")
151 it 'ステータスコード200 OKを返す' do
152 get :show, :id => @rp.id, :format => :json
153 response.should be_success
156 get :show, :id => @rp.id, :format => :json
157 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
159 it '素材モデルにjson単体出力オプションを問い合わせている' do
160 ResourcePicture.should_receive(:show_json_opt).exactly(1)
161 get :show, :id => @rp.id, :format => :json
164 get :show, :id => @rp.id, :format => :json
165 json = JSON.parse response.body
166 json["ext"].should match(/png/)
167 json["md5"].should_not be_nil
168 json["picture_id"].should_not be_nil
171 #画像送信では、send_dataにスタブをおいてテストしたいが、ここに噛ませると
172 #renderが働かず、エラーとなってしまう。そこで、素材のファイル取得部分に
173 #スタブをおいてsend_dataがデータを返す体裁でテストする。
176 ResourcePicture.any_instance.stub(:mime_type).and_return('image/png')
177 ResourcePicture.any_instance.stub(:restore).and_return('aaa')
179 it '画像モデルに画像データを問い合わせる' do
180 ResourcePicture.any_instance.should_receive(:restore).exactly(1)
181 get :show, :id => @rp.id, :format => :png
183 it '画像モデルにMimeTypeを問い合わせる' do
184 ResourcePicture.any_instance.should_receive(:mime_type).exactly(1)
185 get :show, :id => @rp.id, :format => :png
188 get :show, :id => @rp.id, :format => :png
189 response.body.should eq 'aaa'
194 ResourcePicture.any_instance.stub(:mime_type).and_return('image/gif')
195 ResourcePicture.any_instance.stub(:restore).and_return('bbb')
197 it '画像モデルに画像データを問い合わせる' do
198 ResourcePicture.any_instance.should_receive(:restore).exactly(1)
199 get :show, :id => @rp.id, :format => :gif
201 it '画像モデルにMimeTypeを問い合わせる' do
202 ResourcePicture.any_instance.should_receive(:mime_type).exactly(1)
203 get :show, :id => @rp.id, :format => :png
206 get :show, :id => @rp.id, :format => :gif
207 response.body.should eq 'bbb'
212 ResourcePicture.any_instance.stub(:mime_type).and_return('image/jpeg')
213 ResourcePicture.any_instance.stub(:restore).and_return('ccc')
215 it '画像モデルに画像データを問い合わせる' do
216 ResourcePicture.any_instance.should_receive(:restore).exactly(1)
217 get :show, :id => @rp.id, :format => :jpeg
219 it '画像モデルにMimeTypeを問い合わせる' do
220 ResourcePicture.any_instance.should_receive(:mime_type).exactly(1)
221 get :show, :id => @rp.id, :format => :png
224 get :show, :id => @rp.id, :format => :jpeg
225 response.body.should eq 'ccc'
229 context '作家権限がないとき' do
234 it 'ステータスコード302 Foundを返す' do
235 get :show, :id => @rp.id
236 response.status.should eq 302
238 it 'サインインページへ遷移する' do
239 get :show, :id => @rp.id
240 response.body.should redirect_to '/users/sign_in'
244 it 'ステータスコード401 Unauthorizedを返す' do
245 get :show, :id => @rp.id, :format => :json
246 response.status.should eq 401
248 it '応答メッセージにUnauthorizedを返す' do
249 get :show, :id => @rp.id, :format => :json
250 response.message.should match(/Unauthorized/)
255 context '対象素材がないとき' do
257 ResourcePicture.unstub(:show)
260 it '例外404 not_foundを返す' do
263 }.should raise_error(ActiveRecord::RecordNotFound)
267 it '例外404 not_foundを返す' do
269 get :show, :id => 0, :format => :json
270 }.should raise_error(ActiveRecord::RecordNotFound)
274 context '他人の素材を見ようとしたとき' do
276 ResourcePicture.stub(:show).and_return(@rp)
277 ResourcePicture.any_instance.stub(:own?).with(any_args()).and_return(false)
280 it '例外403 forbiddenを返す' do
282 get :show, :id => @rp.id
283 }.should raise_error(ActiveRecord::Forbidden)
287 it '例外403 forbiddenを返す' do
289 get :show, :id => @rp.id, :format => :json
290 }.should raise_error(ActiveRecord::Forbidden)
297 describe '素材数取得に於いて' do
299 ResourcePicture.should_receive(:visible_count).and_return(3)
302 context 'つつがなく終わるとき' do
303 it 'ステータスコード200 OKを返す' do
304 get :count, :format => :json
305 response.should be_success
309 get :count, :format => :json
310 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
312 it 'データがHash構造になっていてコマ絵数が3である' do
313 get :count, :format => :json
314 json = JSON.parse response.body
315 json["count"].should == 3
321 describe 'クレジット表示に於いて' do
323 @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
324 @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id
326 ResourcePicture.stub(:show).with(@rp.id.to_s, @author).and_return(@rp)
328 context 'つつがなく終わるとき' do
329 it '素材モデルに単体取得を問い合わせている' do
330 ResourcePicture.should_receive(:show).exactly(1)
331 get :credit, :id => @rp.id
333 it '@resource_pictureにアレを取得している' do
334 get :credit, :id => @rp.id
335 assigns(:resource_picture).id.should eq(@rp.id)
338 it 'ステータスコード200 OKを返す' do
339 get :credit, :id => @rp.id
340 response.should be_success
342 it 'creditテンプレートを描画する' do
343 get :credit, :id => @rp.id
344 response.should render_template("credit")
348 it 'ステータスコード200 OKを返す' do
349 get :credit, :id => @rp.id, :format => :json
350 response.should be_success
353 get :credit, :id => @rp.id, :format => :json
354 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
356 it '素材モデルにjson単体出力オプションを問い合わせている' do
357 ResourcePicture.should_receive(:show_json_opt).exactly(1)
358 get :credit, :id => @rp.id, :format => :json
361 get :credit, :id => @rp.id, :format => :json
362 json = JSON.parse response.body
363 json["ext"].should match(/png/)
364 json["md5"].should_not be_nil
365 json["picture_id"].should_not be_nil
369 context '作家権限がないとき' do
374 it 'ステータスコード302 Foundを返す' do
375 get :credit, :id => @rp.id
376 response.status.should eq 302
378 it 'サインインページへ遷移する' do
379 get :credit, :id => @rp.id
380 response.body.should redirect_to '/users/sign_in'
384 it 'ステータスコード401 Unauthorizedを返す' do
385 get :credit, :id => @rp.id, :format => :json
386 response.status.should eq 401
388 it '応答メッセージにUnauthorizedを返す' do
389 get :credit, :id => @rp.id, :format => :json
390 response.message.should match(/Unauthorized/)
395 context '対象素材がないとき' do
397 ResourcePicture.unstub(:show)
400 it '例外404 not_foundを返す' do
403 }.should raise_error(ActiveRecord::RecordNotFound)
407 it '例外404 not_foundを返す' do
409 get :show, :id => 0, :format => :json
410 }.should raise_error(ActiveRecord::RecordNotFound)
417 #原画にライセンスを与えるため際の確認フォーム
418 describe '新規作成フォーム表示に於いて' do
421 @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
422 @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id
423 @attr = {:original_picture_id => @op.id, :original_picture_license_group => {:original_picture_id => @op.id, :license_group_id => @lg.id},
424 :resource_picture => {:original_picture_id => @op.id, :license_id => @license.id, :artist_name => @artist.name, :credit => '{}', :settings => '{}' }}
425 @newop = FactoryGirl.create :original_picture, :artist_id => @artist.id
426 @newattr = {:original_picture_id => @newop.id, :original_picture_license_group => {:original_picture_id => @newop.id, :license_group_id => @lg.id},
427 :resource_picture => {:original_picture_id => @newop.id, :license_id => @license.id, :artist_name => @artist.name, :credit => '{}', :settings => '{}' }}
428 @imager = ImagerTest.load("abc\ndef\nghi")
430 context '事前チェックしておく' do
432 OriginalPicture.stub(:edit).with(@op.id.to_s, @artist).and_return(@op)
433 OriginalPicture.stub(:edit).with(@newop.id.to_s, @artist).and_return(@newop)
434 OriginalPicture.any_instance.stub(:restore).with(any_args()).and_return(@imager.binary)
435 PettanImager.stub(:load).with(@imager.binary).and_return(@imager)
436 LicenseGroup.stub(:show).with(@lg.id).and_return(@lg)
437 ResourcePicture.any_instance.stub(:overwrite).with(@op).and_return(true)
438 ResourcePicture.any_instance.stub(:overwrite).with(@newop).and_return(true)
440 it '原画モデルに編集取得を依頼してしている' do
441 OriginalPicture.should_receive(:edit).with(@op.id.to_s, @artist).exactly(1)
444 it '原画モデルに画像データを問い合わせている' do
445 OriginalPicture.any_instance.should_receive(:restore).with(any_args()).exactly(1)
448 it '画像ライブラリをロードしている' do
449 PettanImager.should_receive(:load).with(any_args()).exactly(1)
452 it 'ライセンスグループモデルに単体取得を依頼している' do
453 LicenseGroup.should_receive(:show).with(any_args()).exactly(1)
456 context 'ライセンスを与えようとしている原画が素材を作成してないとき' do
457 it '素材モデルにデフォルト値補充を依頼している' do
458 ResourcePicture.any_instance.should_receive(:supply_default).with(any_args()).exactly(1)
462 context 'ライセンスを与えようとしている原画が既に素材を作成しているとき' do
463 it '素材モデルにデフォルト値補充を依頼してない' do
464 ResourcePicture.any_instance.should_not_receive(:supply_default).with(any_args())
468 it '素材モデルに上書き補充を依頼している' do
469 ResourcePicture.any_instance.should_receive(:overwrite).with(@op).exactly(1)
473 context 'つつがなく終わるとき' do
475 OriginalPicture.stub(:edit).with(@op.id.to_s, @artist).and_return(@op)
476 OriginalPicture.stub(:edit).with(@newop.id.to_s, @artist).and_return(@newop)
477 OriginalPicture.any_instance.stub(:restore).with(any_args()).and_return(@imager.binary)
478 PettanImager.stub(:load).with(@imager.binary).and_return(@imager)
479 LicenseGroup.stub(:show).with(@lg.id).and_return(@lg)
480 ResourcePicture.any_instance.stub(:overwrite).with(@op).and_return(true)
481 ResourcePicture.any_instance.stub(:overwrite).with(@newop).and_return(true)
483 it '@original_pictureに原画を取得している' do
485 assigns(:original_picture).should eq @op
487 it '@imagerに画像ライブラリをロードしている' do
489 assigns(:imager).should eq @imager
491 it '@original_picture_license_groupに新規原画ライセンスグループデータを用意している' do
493 assigns(:original_picture_license_group).should be_a_new(OriginalPictureLicenseGroup)
495 it '@license_groupにライセンスグループを取得している' do
497 assigns(:license_group).should eq @lg
499 context 'ライセンスを与えようとしている原画が素材を作成してないとき' do
500 it '@resource_pictureに新規素材データを用意している' do
502 assigns(:resource_picture).should be_a_new(ResourcePicture)
505 context 'ライセンスを与えようとしている原画が既に素材を作成しているとき' do
506 it '@resource_pictureに素材データを用意している' do
508 assigns(:resource_picture).is_a?(ResourcePicture).should be_true
509 assigns(:resource_picture).should_not be_a_new(ResourcePicture)
513 it 'ステータスコード200 OKを返す' do
515 response.should be_success
517 it 'ページテンプレートnewを描画する' do
519 response.should render_template("new")
524 @attr.merge!({:format => :js})
526 it 'ステータスコード200 OKを返す' do
528 response.should be_success
530 it '部分テンプレートnew.jsを描画する' do
532 response.should render_template("new")
536 context '作家権限がないとき' do
541 it 'ステータスコード302 Foundを返す' do
543 response.status.should eq 302
545 it 'サインインページへ遷移する' do
547 response.body.should redirect_to '/users/sign_in'
552 @attr.merge!({:format => :js})
554 it 'ステータスコード401 Unauthorizedを返す' do
556 response.status.should eq 401
558 it '応答メッセージにUnauthorizedを返す' do
560 response.message.should match(/Unauthorized/)
564 context '作家が絵師でないとき' do
566 Author.any_instance.stub(:artist?).and_return(false)
569 it 'ステータスコード302 Foundを返す' do
571 response.status.should eq 302
575 response.should redirect_to new_artist_path
580 @attr.merge!({:format => :js})
582 it 'ステータスコード200 Okを返す' do
584 response.status.should eq 200
586 it '絵師登録部分テンプレートartists/new.jsを描画する' do
588 response.should render_template("artists/new")
592 context '対象ライセンスグループがないとき' do
594 @attr = {:original_picture_id => @op.id, :original_picture_license_group => {:original_picture_id => @op.id, :license_group_id => 0},
595 :resource_picture => {:original_picture_id => @op.id, :license_id => @license.id, :artist_name => @artist.name, :credit => '{}', :settings => '{}' }}
598 it '例外404 not_foundを返す' do
601 }.should raise_error(ActiveRecord::RecordNotFound)
606 @attr.merge!({:format => :js})
608 it '例外404 not_foundを返す' do
611 }.should raise_error(ActiveRecord::RecordNotFound)
617 describe '新規作成に於いて' do
620 @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
621 @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id
622 @attr = {:original_picture_id => @op.id, :original_picture_license_group => {:original_picture_id => @op.id, :license_group_id => @lg.id},
623 :resource_picture => {:original_picture_id => @op.id, :license_id => @license.id, :artist_name => @artist.name, :credit => '{}', :settings => '{"new":0}' }}
624 @newop = FactoryGirl.create :original_picture, :artist_id => @artist.id
625 @newattr = {:original_picture_id => @newop.id, :original_picture_license_group => {:original_picture_id => @newop.id, :license_group_id => @lg.id},
626 :resource_picture => {:original_picture_id => @newop.id, :license_id => @license.id, :artist_name => @artist.name, :credit => '{}', :settings => '{"new":1}' }}
627 @imager = ImagerTest.load("abc\ndef\nghi")
629 context '事前チェックしておく' do
631 OriginalPicture.stub(:edit).with(@op.id.to_s, @artist).and_return(@op)
632 OriginalPicture.stub(:edit).with(@newop.id.to_s, @artist).and_return(@newop)
633 OriginalPicture.any_instance.stub(:restore).with(any_args()).and_return(@imager.binary)
634 PettanImager.stub(:load).with(@imager.binary).and_return(@imager)
635 LicenseGroup.stub(:show).with(@lg.id).and_return(@lg)
636 ResourcePicture.any_instance.stub(:overwrite).with(@op).and_return(true)
637 ResourcePicture.any_instance.stub(:overwrite).with(@newop).and_return(true)
638 ResourcePicture.any_instance.stub(:store).with(@imager).and_return(true)
640 it '原画モデルに編集取得を依頼してしている' do
641 OriginalPicture.should_receive(:edit).with(@op.id.to_s, @artist).exactly(1)
644 it '原画モデルに画像データを問い合わせている' do
645 OriginalPicture.any_instance.should_receive(:restore).with(any_args()).exactly(1)
648 it '画像ライブラリをロードしている' do
649 PettanImager.should_receive(:load).with(any_args()).exactly(1)
652 it 'ライセンスグループモデルに単体取得を依頼している' do
653 LicenseGroup.should_receive(:show).with(any_args()).exactly(1)
656 context 'ライセンスを与えようとしている原画が素材を作成してないとき' do
657 it '素材モデルにデフォルト値補充を依頼している' do
658 ResourcePicture.any_instance.should_receive(:supply_default).with(any_args()).exactly(1)
659 post :create, @newattr
662 context 'ライセンスを与えようとしている原画が既に素材を作成しているとき' do
663 it '素材モデルにデフォルト値補充を依頼してない' do
664 ResourcePicture.any_instance.should_not_receive(:supply_default).with(any_args())
668 it '素材モデルに上書き補充を依頼している' do
669 ResourcePicture.any_instance.should_receive(:overwrite).with(@op).exactly(1)
672 it '素材モデルに保存を依頼している' do
673 ResourcePicture.any_instance.should_receive(:store).with(@imager).exactly(1)
677 context 'つつがなく終わるとき[ライセンスを与えようとしている原画が素材を作成してない]' do
679 OriginalPicture.stub(:edit).with(@newop.id.to_s, @artist).and_return(@newop)
680 OriginalPicture.any_instance.stub(:restore).with(any_args()).and_return(@imager.binary)
681 PettanImager.stub(:load).with(@imager.binary).and_return(@imager)
682 LicenseGroup.stub(:show).with(@lg.id).and_return(@lg)
683 ResourcePicture.any_instance.stub(:store).with(@imager).and_return {
684 assigns(:resource_picture).attributes = @newattr[:resource_picture]
685 assigns(:resource_picture).overwrite @newop
686 assigns(:resource_picture).picture_id = @p.id
687 assigns(:resource_picture).save!
691 it '@original_pictureに原画を取得している' do
692 post :create, @newattr
693 assigns(:original_picture).should eq @newop
695 it '@imagerに画像ライブラリをロードしている' do
696 post :create, @newattr
697 assigns(:imager).should eq @imager
699 it '@original_picture_license_groupに新規原画ライセンスグループデータを用意している' do
700 post :create, @newattr
701 assigns(:original_picture_license_group).should be_a_new(OriginalPictureLicenseGroup)
703 it '@license_groupにライセンスグループを取得している' do
704 post :create, @newattr
705 assigns(:license_group).should eq @lg
707 it '素材データにPOSTデータの素材情報を適用している' do
708 post :create, @newattr
709 assigns(:resource_picture).license_id.should eq @license.id
710 assigns(:resource_picture).artist_name.should eq @artist.name
711 assigns(:resource_picture).credit.should eq '{}'
712 assigns(:resource_picture).settings.should eq '{"new":1}'
714 it "作成された素材がDBにある" do
716 post :create, @newattr
717 }.should change(ResourcePicture, :count)
720 it 'ステータスコード302 Foundを返す' do
721 post :create, @newattr
722 response.status.should eq 302
724 it '作成された素材の表示ページへ遷移する' do
725 post :create, @newattr
726 response.should redirect_to(ResourcePicture.last)
731 @newattr.merge!({:format => :json})
733 it 'ステータスコード200 OKを返す' do
734 post :create, @newattr
735 response.should be_success
737 it '作成された素材をjsonデータで返す' do
738 post :create, @newattr
739 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
741 it '素材モデルにjson単体出力オプションを問い合わせている' do
742 ResourcePicture.should_receive(:show_json_opt).exactly(1)
743 post :create, @newattr
746 post :create, @newattr
747 json = JSON.parse response.body
748 json["ext"].should match(/png/)
749 json["md5"].should_not be_nil
750 json["picture_id"].should_not be_nil
754 context 'つつがなく終わるとき[ライセンスを与えようとしている原画が既に素材を作成している]' do
756 OriginalPicture.stub(:edit).with(@op.id.to_s, @artist).and_return(@op)
757 OriginalPicture.any_instance.stub(:restore).with(any_args()).and_return(@imager.binary)
758 PettanImager.stub(:load).with(@imager.binary).and_return(@imager)
759 LicenseGroup.stub(:show).with(@lg.id).and_return(@lg)
760 ResourcePicture.any_instance.stub(:store).with(@imager).and_return {
761 assigns(:resource_picture).attributes = @attr[:resource_picture]
762 assigns(:resource_picture).overwrite @op
763 assigns(:resource_picture).save!
767 it '@original_pictureに原画を取得している' do
769 assigns(:original_picture).should eq @op
771 it '素材データにPOSTデータの素材情報を適用している' do
773 assigns(:resource_picture).license_id.should eq @license.id
774 assigns(:resource_picture).artist_name.should eq @artist.name
775 assigns(:resource_picture).credit.should eq '{}'
776 assigns(:resource_picture).settings.should eq '{"new":0}'
780 r = ResourcePicture.find(@rp.id)
781 r.settings.should eq '{"new":0}'
783 it "上書きなので件数は変化しない" do
786 }.should_not change(ResourcePicture, :count)
789 context '作家権限がないとき' do
794 it 'ステータスコード302 Foundを返す' do
796 response.status.should eq 302
798 it 'サインインページへ遷移する' do
800 response.body.should redirect_to '/users/sign_in'
805 @attr.merge!({:format => :js})
807 it 'ステータスコード401 Unauthorizedを返す' do
809 response.status.should eq 401
811 it '応答メッセージにUnauthorizedを返す' do
813 response.message.should match(/Unauthorized/)
817 context '作家が絵師でないとき' do
819 Author.any_instance.stub(:artist?).and_return(false)
822 it 'ステータスコード302 Foundを返す' do
824 response.status.should eq 302
828 response.should redirect_to new_artist_path
833 @attr.merge!({:format => :json})
835 it '応答メッセージにUnauthorizedを返す' do
837 response.message.should match(/Unauthorized/)
841 context '検証、保存に失敗した' do
843 OriginalPicture.any_instance.stub(:restore).with(any_args()).and_return(@imager.binary)
844 PettanImager.stub(:load).with(@imager.binary).and_return(@imager)
845 ResourcePicture.any_instance.stub(:store).and_return(false)
847 it "未保存の素材を保持している" do
848 post :create, @newattr
849 assigns(:resource_picture).should be_a_new(ResourcePicture)
852 it 'ステータスコード200 OKを返す' do
853 post :create, @newattr
854 response.status.should eq 200
857 post :create, @newattr
858 response.should render_template("new")
863 @newattr.merge!({:format => :json})
865 it 'ステータスコード422 unprocessable_entity を返す' do
866 post :create, @newattr
867 response.status.should eq 422
869 it '応答メッセージUnprocessable Entityを返す' do
870 post :create, @newattr
871 response.message.should match(/Unprocessable/)
879 @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
880 @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id
883 context '事前チェックしておく' do
885 ResourcePicture.stub(:edit).with(any_args()).and_return @rp
886 ResourcePicture.any_instance.stub(:unpublish).with(any_args()).and_return(true)
888 it '素材モデルに編集取得を問い合わせている' do
889 ResourcePicture.should_receive(:edit).exactly(1)
890 delete :destroy, :id => @rp.id
893 ResourcePicture.any_instance.should_receive(:unpublish).exactly(1)
894 delete :destroy, :id => @rp.id
896 it '@resource_pictureにアレを取得している' do
897 delete :destroy, :id => @rp.id
898 assigns(:resource_picture).id.should eq(@rp.id)
901 context 'つつがなく終わるとき' do
903 ResourcePicture.any_instance.stub(:unpublish).with(any_args()).and_return(true)
906 it 'ステータスコード302 Foundを返す' do
907 delete :destroy, :id => @rp.id
908 response.status.should eq 302
910 it 'マイ素材の一覧ページへ遷移する' do
911 delete :destroy, :id => @rp.id
912 response.should redirect_to('/home/resource_picture')
916 it 'ステータスコード200 OKを返す' do
917 delete :destroy, :id => @rp.id, :format => :json
918 response.should be_success
921 delete :destroy, :id => @rp.id, :format => :json
922 response.body.should match /./
926 context '作家権限がないとき' do
930 it 'ステータスコード302 Foundを返す' do
931 delete :destroy, :id => @rp.id
932 response.status.should eq 302
935 it 'サインインページへ遷移する' do
936 delete :destroy, :id => @rp.id
937 response.body.should redirect_to '/users/sign_in'
941 it '応答メッセージにUnauthorizedを返す' do
942 delete :destroy, :id => @rp.id, :format => :json
943 response.message.should match(/Unauthorized/)
947 context '作家が絵師でないとき' do
949 Author.any_instance.stub(:artist?).and_return(false)
952 it 'ステータスコード302 Foundを返す' do
953 delete :destroy, :id => @rp.id
954 response.status.should eq 302
957 delete :destroy, :id => @rp.id
958 response.should redirect_to new_artist_path
962 it '応答メッセージにUnauthorizedを返す' do
963 delete :destroy, :id => @rp.id, :format => :json
964 response.message.should match(/Unauthorized/)
968 context '削除に失敗したとき' do
970 ResourcePicture.any_instance.stub(:unpublish).and_return(false)
973 it 'ステータスコード302 Foundを返す' do
974 delete :destroy, :id => @rp.id
975 response.status.should eq 302
977 it 'その素材の詳細ページへ遷移する' do
978 delete :destroy, :id => @rp.id
979 response.should redirect_to(resource_picture_path(@rp))
983 it 'ステータスコード422 unprocessable_entity を返す' do
984 delete :destroy, :id => @rp.id, :format => :json
985 response.status.should eq 422
987 it '応答メッセージUnprocessable Entityを返す' do
988 delete :destroy, :id => @rp.id, :format => :json
989 response.message.should match(/Unprocessable/)
996 describe '一覧表示に於いて' do
998 @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
999 @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id
1001 ResourcePicture.stub(:list).and_return([@rp, @rp, @rp])
1003 context 'つつがなく終わるとき' do
1005 it 'ステータスコード200 OKを返す' do
1007 response.should be_success
1009 it 'indexテンプレートを描画する' do
1011 response.should render_template("index")
1015 it 'ステータスコード200 OKを返す' do
1016 get :index, :format => :json
1017 response.should be_success
1020 get :index, :format => :json
1021 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1025 context '作家権限がないとき' do
1030 it 'ステータスコード200 OKを返す' do
1032 response.should be_success
1034 it 'indexテンプレートを描画する' do
1036 response.should render_template("index")
1040 it 'ステータスコード200 OKを返す' do
1041 get :index, :format => :json
1042 response.should be_success
1045 get :index, :format => :json
1046 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1052 describe '単体表示に於いて' do
1054 @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
1055 @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id
1057 ResourcePicture.stub(:show).with(@rp.id.to_s, @author).and_return(@rp)
1058 ResourcePicture.stub(:show).with(@rp.id.to_s, nil).and_return(@rp)
1060 context 'つつがなく終わるとき' do
1062 it 'ステータスコード200 OKを返す' do
1063 get :show, :id => @rp.id
1064 response.should be_success
1066 it 'showテンプレートを描画する' do
1067 get :show, :id => @rp.id
1068 response.should render_template("show")
1072 it 'ステータスコード200 OKを返す' do
1073 get :show, :id => @rp.id, :format => :json
1074 response.should be_success
1077 get :show, :id => @rp.id, :format => :json
1078 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1082 context '作家権限がないとき' do
1087 it 'ステータスコード200 OKを返す' do
1088 get :show, :id => @rp.id
1089 response.should be_success
1091 it 'showテンプレートを描画する' do
1092 get :show, :id => @rp.id
1093 response.should render_template("show")
1097 it 'ステータスコード200 OKを返す' do
1098 get :show, :id => @rp.id, :format => :json
1099 response.should be_success
1102 get :show, :id => @rp.id, :format => :json
1103 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1109 describe '素材数取得に於いて' do
1111 ResourcePicture.should_receive(:visible_count).and_return(3)
1114 context 'つつがなく終わるとき' do
1115 it 'ステータスコード200 OKを返す' do
1116 get :count, :format => :json
1117 response.should be_success
1121 get :count, :format => :json
1122 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1128 describe 'クレジット表示に於いて' do
1130 @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
1131 @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id
1133 ResourcePicture.stub(:show).with(@rp.id.to_s, @author).and_return(@rp)
1134 ResourcePicture.stub(:show).with(@rp.id.to_s, nil).and_return(@rp)
1136 context 'つつがなく終わるとき' do
1138 it 'ステータスコード200 OKを返す' do
1139 get :credit, :id => @rp.id
1140 response.should be_success
1142 it 'creditテンプレートを描画する' do
1143 get :credit, :id => @rp.id
1144 response.should render_template("credit")
1148 it 'ステータスコード200 OKを返す' do
1149 get :credit, :id => @rp.id, :format => :json
1150 response.should be_success
1153 get :credit, :id => @rp.id, :format => :json
1154 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1158 context '作家権限がないとき' do
1163 it 'ステータスコード200 OKを返す' do
1164 get :credit, :id => @rp.id
1165 response.should be_success
1167 it 'creditテンプレートを描画する' do
1168 get :credit, :id => @rp.id
1169 response.should render_template("credit")
1173 it 'ステータスコード200 OKを返す' do
1174 get :credit, :id => @rp.id, :format => :json
1175 response.should be_success
1178 get :credit, :id => @rp.id, :format => :json
1179 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1185 #原画にライセンスを与えるため際の確認フォーム
1186 describe '新規作成フォーム表示に於いて' do
1189 @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
1190 @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id
1191 @attr = {:original_picture_id => @op.id, :original_picture_license_group => {:original_picture_id => @op.id, :license_group_id => @lg.id},
1192 :resource_picture => {:original_picture_id => @op.id, :license_id => @license.id, :artist_name => @artist.name, :credit => '{}', :settings => '{}' }}
1193 @newop = FactoryGirl.create :original_picture, :artist_id => @artist.id
1194 @newattr = {:original_picture_id => @newop.id, :original_picture_license_group => {:original_picture_id => @newop.id, :license_group_id => @lg.id},
1195 :resource_picture => {:original_picture_id => @newop.id, :license_id => @license.id, :artist_name => @artist.name, :credit => '{}', :settings => '{}' }}
1196 @imager = ImagerTest.load("abc\ndef\nghi")
1198 context 'つつがなく終わるとき' do
1200 OriginalPicture.stub(:edit).with(@op.id.to_s, @artist).and_return(@op)
1201 OriginalPicture.stub(:edit).with(@newop.id.to_s, @artist).and_return(@newop)
1202 OriginalPicture.any_instance.stub(:restore).with(any_args()).and_return(@imager.binary)
1203 PettanImager.stub(:load).with(@imager.binary).and_return(@imager)
1204 LicenseGroup.stub(:show).with(@lg.id).and_return(@lg)
1205 ResourcePicture.any_instance.stub(:overwrite).with(@op).and_return(true)
1206 ResourcePicture.any_instance.stub(:overwrite).with(@newop).and_return(true)
1209 it 'ステータスコード200 OKを返す' do
1211 response.should be_success
1213 it 'ページテンプレートnewを描画する' do
1215 response.should render_template("new")
1220 @attr.merge!({:format => :js})
1222 it 'ステータスコード200 OKを返す' do
1224 response.should be_success
1226 it '部分テンプレートnew.jsを描画する' do
1228 response.should render_template("new")
1232 context '作家権限がないとき' do
1237 it 'ステータスコード302 Foundを返す' do
1239 response.status.should eq 302
1241 it 'サインインページへ遷移する' do
1243 response.body.should redirect_to '/users/sign_in'
1248 @attr.merge!({:format => :js})
1250 it 'ステータスコード401 Unauthorizedを返す' do
1252 response.status.should eq 401
1254 it '応答メッセージにUnauthorizedを返す' do
1256 response.message.should match(/Unauthorized/)
1262 describe '新規作成に於いて' do
1265 @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
1266 @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id
1267 @attr = {:original_picture_id => @op.id, :original_picture_license_group => {:original_picture_id => @op.id, :license_group_id => @lg.id},
1268 :resource_picture => {:original_picture_id => @op.id, :license_id => @license.id, :artist_name => @artist.name, :credit => '{}', :settings => '{"new":0}' }}
1269 @newop = FactoryGirl.create :original_picture, :artist_id => @artist.id
1270 @newattr = {:original_picture_id => @newop.id, :original_picture_license_group => {:original_picture_id => @newop.id, :license_group_id => @lg.id},
1271 :resource_picture => {:original_picture_id => @newop.id, :license_id => @license.id, :artist_name => @artist.name, :credit => '{}', :settings => '{"new":1}' }}
1272 @imager = ImagerTest.load("abc\ndef\nghi")
1274 context 'つつがなく終わるとき[ライセンスを与えようとしている原画が素材を作成してない]' do
1276 OriginalPicture.stub(:edit).with(@newop.id.to_s, @artist).and_return(@newop)
1277 OriginalPicture.any_instance.stub(:restore).with(any_args()).and_return(@imager.binary)
1278 PettanImager.stub(:load).with(@imager.binary).and_return(@imager)
1279 LicenseGroup.stub(:show).with(@lg.id).and_return(@lg)
1280 ResourcePicture.any_instance.stub(:store).with(@imager).and_return {
1281 assigns(:resource_picture).attributes = @newattr[:resource_picture]
1282 assigns(:resource_picture).overwrite @newop
1283 assigns(:resource_picture).picture_id = @p.id
1284 assigns(:resource_picture).save!
1289 it 'ステータスコード302 Foundを返す' do
1290 post :create, @newattr
1291 response.status.should eq 302
1293 it '作成された素材の表示ページへ遷移する' do
1294 post :create, @newattr
1295 response.should redirect_to(ResourcePicture.last)
1300 @newattr.merge!({:format => :json})
1302 it 'ステータスコード200 OKを返す' do
1303 post :create, @newattr
1304 response.should be_success
1306 it '作成された素材をjsonデータで返す' do
1307 post :create, @newattr
1308 lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
1314 describe '削除に於いて' do
1316 @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
1317 @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id
1320 context 'つつがなく終わるとき' do
1322 ResourcePicture.any_instance.stub(:unpublish).with(any_args()).and_return(true)
1325 it 'ステータスコード302 Foundを返す' do
1326 delete :destroy, :id => @rp.id
1327 response.status.should eq 302
1329 it 'マイ素材の一覧ページへ遷移する' do
1330 delete :destroy, :id => @rp.id
1331 response.should redirect_to('/home/resource_picture')
1335 it 'ステータスコード200 OKを返す' do
1336 delete :destroy, :id => @rp.id, :format => :json
1337 response.should be_success
1339 it 'ページ本体は特に返さない' do
1340 delete :destroy, :id => @rp.id, :format => :json
1341 response.body.should match /./
1345 context '作家権限がないとき' do
1349 it 'ステータスコード302 Foundを返す' do
1350 delete :destroy, :id => @rp.id
1351 response.status.should eq 302
1354 it 'サインインページへ遷移する' do
1355 delete :destroy, :id => @rp.id
1356 response.body.should redirect_to '/users/sign_in'
1360 it '応答メッセージにUnauthorizedを返す' do
1361 delete :destroy, :id => @rp.id, :format => :json
1362 response.message.should match(/Unauthorized/)