1 # -*- encoding: utf-8 -*-
5 describe OriginalPictureLicenseGroupsController do
7 @admin = FactoryGirl.create :admin
8 @user = FactoryGirl.create( :user_yas)
9 @author = FactoryGirl.create :author, :user_id => @user.id
10 @artist = FactoryGirl.create :artist_yas, :author_id => @author.id
11 @sp = FactoryGirl.create :system_picture
12 @lg = FactoryGirl.create :license_group, :classname => 'PettanrUnknownV01License'
13 @license = FactoryGirl.create :license, :license_group_id => @lg.id, :system_picture_id => @sp.id
14 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
17 if MagicNumber['run_mode'] == 1
18 describe '新規作成フォーム表示に於いて' do
22 context 'つつがなく終わるとき' do
24 @attr = {:original_picture_id => @op.id}
25 @attrj = @attr.merge({:format => :js})
27 it 'ステータスコード200 OKを返す' do
29 response.should be_success
31 it '原画モデルに単体取得を問い合わせている' do
32 OriginalPicture.stub(:show).with(any_args()).and_return(@op)
33 OriginalPicture.should_receive(:show).with(any_args()).exactly(1)
36 it '@original_pictureにデータを用意している' do
38 assigns(:original_picture).should eq @op
40 it '@original_picture_license_groupに新規データを用意している' do
42 assigns(:original_picture_license_group).should be_a_new(OriginalPictureLicenseGroup)
44 it '原画ライセンスグループモデルにデフォルト値補充を依頼している' do
45 OriginalPictureLicenseGroup.any_instance.should_receive(:supply_default).exactly(1)
49 it 'ページテンプレートnewを描画する' do
51 response.should render_template("new")
55 it '部分テンプレートnew.jsを描画する' do
57 response.should render_template("new")
61 context '作家権限がないとき' do
64 @attr = {:original_picture_id => @op.id}
65 @attrj = @attr.merge({:format => :js})
68 it 'ステータスコード302 Foundを返す' do
70 response.status.should eq 302
74 response.body.should redirect_to '/users/sign_in'
78 it 'ステータスコード401 Unauthorizedを返す' do
80 response.status.should eq 401
82 it '応答メッセージにUnauthorizedを返す' do
84 response.message.should match(/Unauthorized/)
88 context '作家が絵師でないとき' do
90 @attr = {:original_picture_id => @op.id}
91 @attrj = @attr.merge({:format => :js})
92 Author.any_instance.stub(:artist?).and_return(false)
95 it 'ステータスコード302 Foundを返す' do
97 response.status.should eq 302
101 response.should redirect_to new_artist_path
105 it 'ステータスコード200 Okを返す' do
107 response.status.should eq 200
109 it '絵師登録部分テンプレートartists/new.jsを描画する' do
111 response.should render_template("artists/new")
117 describe '新規作成に於いて' do
121 context '事前チェックしておく' do
123 OriginalPictureLicenseGroup.any_instance.stub(:valid?).with(any_args()).and_return(true)
124 @attr = {:original_picture_id => @op.id, :original_picture_license_group => {:original_picture_id => @op.id, :license_group_id => @lg.id}}
125 @attrj = @attr.merge({:format => :js})
127 it '原画モデルに単体取得を問い合わせている' do
128 OriginalPicture.stub(:show).with(any_args()).and_return(@op)
129 OriginalPicture.should_receive(:show).exactly(1)
132 it '@original_pictureにデータを用意している' do
134 assigns(:original_picture).should eq @op
136 it 'ライセンスグループモデルに単体取得を問い合わせている' do
137 LicenseGroup.stub(:show).with(any_args()).and_return(@lg)
138 LicenseGroup.should_receive(:show).exactly(1)
141 it '@license_groupにデータを用意している' do
143 assigns(:license_group).should eq @lg
145 it '@ctlにコントローラを用意している' do
147 assigns(:ctl).should eq 'pettanr_unknown_v01_licenses'
149 it '@original_picture_license_groupにデータを用意している' do
151 assigns(:original_picture_license_group).should be_a_new OriginalPictureLicenseGroup
154 OriginalPictureLicenseGroup.any_instance.stub(:valid?).with(any_args()).and_return(true)
155 OriginalPictureLicenseGroup.any_instance.should_receive(:valid?).exactly(1)
159 context 'つつがなく終わるとき' do
161 @attr = {:original_picture_id => @op.id, :original_picture_license_group => {:original_picture_id => @op.id, :license_group_id => @lg.id}}
162 @attrj = @attr.merge({:format => :js})
166 assigns(:original_picture_license_group).valid?.should eq true
171 }.should_not change OriginalPictureLicenseGroup, :count
174 it 'ステータスコード200 OKを返す' do
176 response.should be_success
178 it 'ライセンスクラスの新規作成テンプレートnewを描画する' do
180 response.should render_template("pettanr_unknown_v01_licenses/attributes/new")
184 it 'ステータスコード200 OKを返す' do
186 response.should be_success
188 it 'ライセンスクラスの新規作成部分テンプレートnew.jsを描画する' do
190 response.should render_template("pettanr_unknown_v01_licenses/attributes/new")
194 context '作家権限がないとき' do
197 @attr = {:original_picture_id => @op.id, :original_picture_license_group => {:original_picture_id => @op.id, :license_group_id => @lg.id}}
198 @attrj = @attr.merge({:format => :js})
201 it 'ステータスコード302 Foundを返す' do
203 response.status.should eq 302
205 it 'サインインページへ遷移する' do
207 response.body.should redirect_to '/users/sign_in'
211 it 'ステータスコード401 Unauthorizedを返す' do
213 response.status.should eq 401
215 it '応答メッセージにUnauthorizedを返す' do
217 response.message.should match(/Unauthorized/)
221 context '作家が絵師でないとき' do
223 Author.any_instance.stub(:artist?).and_return(false)
224 @attr = {:original_picture_id => @op.id, :original_picture_license_group => {:original_picture_id => @op.id, :license_group_id => @lg.id}}
225 @attrj = @attr.merge({:format => :js})
228 it 'ステータスコード302 Foundを返す' do
230 response.status.should eq 302
234 response.should redirect_to new_artist_path
238 it 'ステータスコード200 OKを返す' do
240 response.status.should eq 200
244 response.should render_template("artists/new")
248 context '検証、保存に失敗した' do
250 OriginalPictureLicenseGroup.any_instance.stub(:valid?).and_return(false)
251 @attr = {:original_picture_id => @op.id, :original_picture_license_group => {:original_picture_id => @op.id, :license_group_id => @lg.id}}
252 @attrj = @attr.merge({:format => :js})
254 it "未保存の原画ライセンスグループを保持している" do
256 assigns(:original_picture_license_group).should be_a_new(OriginalPictureLicenseGroup)
259 it 'ステータスコード200 OKを返す' do
261 response.status.should eq 200
265 response.should render_template("new")
269 it 'ステータスコード200 OKを返す' do
271 response.status.should eq 200
275 response.should render_template("new")
282 describe '新規作成フォーム表示に於いて' do
286 context 'つつがなく終わるとき' do
288 @attr = {:original_picture_id => @op.id}
289 @attrj = @attr.merge({:format => :js})
291 it 'ステータスコード200 OKを返す' do
293 response.should be_success
296 it 'ページテンプレートnewを描画する' do
298 response.should render_template("new")
302 it '部分テンプレートnew.jsを描画する' do
304 response.should render_template("new")
308 context '作家権限がないとき' do
311 @attr = {:original_picture_id => @op.id}
312 @attrj = @attr.merge({:format => :js})
315 it 'ステータスコード302 Foundを返す' do
317 response.status.should eq 302
319 it 'サインインページへ遷移する' do
321 response.body.should redirect_to '/users/sign_in'
325 it 'ステータスコード401 Unauthorizedを返す' do
327 response.status.should eq 401
329 it '応答メッセージにUnauthorizedを返す' do
331 response.message.should match(/Unauthorized/)
337 describe '新規作成に於いて' do
341 context 'つつがなく終わるとき' do
343 @attr = {:original_picture_id => @op.id, :original_picture_license_group => {:original_picture_id => @op.id, :license_group_id => @lg.id}}
344 @attrj = @attr.merge({:format => :js})
347 it 'ステータスコード200 OKを返す' do
349 response.should be_success
351 it 'ライセンスクラスの新規作成テンプレートnewを描画する' do
353 response.should render_template("pettanr_unknown_v01_licenses/attributes/new")
357 it 'ステータスコード200 OKを返す' do
359 response.should be_success
361 it 'ライセンスクラスの新規作成部分テンプレートnew.jsを描画する' do
363 response.should render_template("pettanr_unknown_v01_licenses/attributes/new")
367 context '作家権限がないとき' do
370 @attr = {:original_picture_id => @op.id, :original_picture_license_group => {:original_picture_id => @op.id, :license_group_id => @lg.id}}
371 @attrj = @attr.merge({:format => :js})
374 it 'ステータスコード302 Foundを返す' do
376 response.status.should eq 302
378 it 'サインインページへ遷移する' do
380 response.body.should redirect_to '/users/sign_in'
384 it 'ステータスコード401 Unauthorizedを返す' do
386 response.status.should eq 401
388 it '応答メッセージにUnauthorizedを返す' do
390 response.message.should match(/Unauthorized/)