OSDN Git Service

fix: any
[pettanr/pettanr.git] / spec / controllers / original_picture_license_groups_controller_spec.rb
1 # -*- encoding: utf-8 -*-
2 #原画ライセンスグループ
3 require 'spec_helper'
4
5 describe OriginalPictureLicenseGroupsController do
6   before 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
15   end
16
17 if MagicNumber['run_mode'] == 1
18   describe '新規作成フォーム表示に於いて' do
19     before do
20       sign_in @user
21     end
22     context 'つつがなく終わるとき' do
23       before do
24         @attr = {:original_picture_id => @op.id}
25         @attrj = @attr.merge({:format => :js})
26       end
27       it 'ステータスコード200 OKを返す' do
28         get :new, @attr
29         response.should be_success 
30       end
31       it '原画モデルに単体取得を問い合わせている' do
32         OriginalPicture.stub(:show).with(any_args()).and_return(@op)
33         OriginalPicture.should_receive(:show).with(any_args()).exactly(1)
34         get :new, @attr
35       end
36       it '@original_pictureにデータを用意している' do
37         get :new, @attr
38         assigns(:original_picture).should eq @op
39       end
40       it '@original_picture_license_groupに新規データを用意している' do
41         get :new, @attr
42         assigns(:original_picture_license_group).should be_a_new(OriginalPictureLicenseGroup)
43       end
44       it '原画ライセンスグループモデルにデフォルト値補充を依頼している' do
45         OriginalPictureLicenseGroup.any_instance.should_receive(:supply_default).exactly(1)
46         get :new, @attr
47       end
48       context 'html形式' do
49         it 'ページテンプレートnewを描画する' do
50           get :new, @attr
51           response.should render_template("new")
52         end
53       end
54       context 'js形式' do
55         it '部分テンプレートnew.jsを描画する' do
56           get :new, @attrj
57           response.should render_template("new")
58         end
59       end
60     end
61     context '作家権限がないとき' do
62       before do
63         sign_out @user
64         @attr = {:original_picture_id => @op.id}
65         @attrj = @attr.merge({:format => :js})
66       end
67       context 'html形式' do
68         it 'ステータスコード302 Foundを返す' do
69           get :new, @attr
70           response.status.should eq 302
71         end
72         it 'サインインページへ遷移する' do
73           get :new, @attr
74           response.body.should redirect_to '/users/sign_in'
75         end
76       end
77       context 'js形式' do
78         it 'ステータスコード401 Unauthorizedを返す' do
79           get :new, @attrj
80           response.status.should eq 401
81         end
82         it '応答メッセージにUnauthorizedを返す' do
83           get :new, @attrj
84           response.message.should match(/Unauthorized/)
85         end
86       end
87     end
88     context '作家が絵師でないとき' do
89       before do
90         @attr = {:original_picture_id => @op.id}
91         @attrj = @attr.merge({:format => :js})
92         Author.any_instance.stub(:artist?).and_return(false)
93       end
94       context 'html形式' do
95         it 'ステータスコード302 Foundを返す' do
96           get :new, @attr
97           response.status.should eq 302
98         end
99         it '絵師登録ページへ遷移する' do
100           get :new, @attr
101           response.should redirect_to new_artist_path
102         end
103       end
104       context 'js形式' do
105         it 'ステータスコード200 Okを返す' do
106           get :new, @attrj
107           response.status.should eq 200
108         end
109         it '絵師登録部分テンプレートartists/new.jsを描画する' do
110           get :new, @attrj
111           response.should render_template("artists/new")
112         end
113       end
114     end
115   end
116
117   describe '新規作成に於いて' do
118     before do
119       sign_in @user
120     end
121     context '事前チェックしておく' do
122       before 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})
126       end
127       it '原画モデルに単体取得を問い合わせている' do
128         OriginalPicture.stub(:show).with(any_args()).and_return(@op)
129         OriginalPicture.should_receive(:show).exactly(1)
130         post :create, @attr
131       end
132       it '@original_pictureにデータを用意している' do
133         post :create, @attr
134         assigns(:original_picture).should eq @op
135       end
136       it 'ライセンスグループモデルに単体取得を問い合わせている' do
137         LicenseGroup.stub(:show).with(any_args()).and_return(@lg)
138         LicenseGroup.should_receive(:show).exactly(1)
139         post :create, @attr
140       end
141       it '@license_groupにデータを用意している' do
142         post :create, @attr
143         assigns(:license_group).should eq @lg
144       end
145       it '@ctlにコントローラを用意している' do
146         post :create, @attr
147         assigns(:ctl).should eq 'pettanr_unknown_v01_licenses'
148       end
149       it '@original_picture_license_groupにデータを用意している' do
150         post :create, @attr
151         assigns(:original_picture_license_group).should be_a_new OriginalPictureLicenseGroup
152       end
153       it 'モデルに検証依頼する' do
154         OriginalPictureLicenseGroup.any_instance.stub(:valid?).with(any_args()).and_return(true)
155         OriginalPictureLicenseGroup.any_instance.should_receive(:valid?).exactly(1)
156         post :create, @attr
157       end
158     end
159     context 'つつがなく終わるとき' do
160       before 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})
163       end
164       it "検証が通る" do
165         post :create, @attr
166         assigns(:original_picture_license_group).valid?.should eq true
167       end
168       it "DBに変化がない" do
169         lambda {
170           post :create, @attr
171         }.should_not change OriginalPictureLicenseGroup, :count
172       end
173       context 'html形式' do
174         it 'ステータスコード200 OKを返す' do
175           post :create, @attr
176           response.should be_success
177         end
178         it 'ライセンスクラスの新規作成テンプレートnewを描画する' do
179           post :create, @attr
180           response.should render_template("pettanr_unknown_v01_licenses/attributes/new")
181         end
182       end
183       context 'js形式' do
184         it 'ステータスコード200 OKを返す' do
185           post :create, @attrj
186           response.should be_success 
187         end
188         it 'ライセンスクラスの新規作成部分テンプレートnew.jsを描画する' do
189           post :create, @attrj
190           response.should render_template("pettanr_unknown_v01_licenses/attributes/new")
191         end
192       end
193     end
194     context '作家権限がないとき' do
195       before do
196         sign_out @user
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})
199       end
200       context 'html形式' do
201         it 'ステータスコード302 Foundを返す' do
202           post :create, @attr
203           response.status.should eq 302
204         end
205         it 'サインインページへ遷移する' do
206           post :create, @attr
207           response.body.should redirect_to '/users/sign_in'
208         end
209       end
210       context 'json形式' do
211         it 'ステータスコード401 Unauthorizedを返す' do
212           post :create, @attrj
213           response.status.should eq 401
214         end
215         it '応答メッセージにUnauthorizedを返す' do
216           post :create, @attrj
217           response.message.should match(/Unauthorized/)
218         end
219       end
220     end
221     context '作家が絵師でないとき' do
222       before 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})
226       end
227       context 'html形式' do
228         it 'ステータスコード302 Foundを返す' do
229           post :create, @attr
230           response.status.should eq 302
231         end
232         it '絵師登録ページへ遷移する' do
233           post :create, @attr
234           response.should redirect_to new_artist_path
235         end
236       end
237       context 'js形式' do
238         it 'ステータスコード200 OKを返す' do
239           post :create, @attrj
240           response.status.should eq 200
241         end
242         it '絵師登録ページへ遷移する' do
243           post :create, @attrj
244           response.should render_template("artists/new")
245         end
246       end
247     end
248     context '検証、保存に失敗した' do
249       before 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})
253       end
254       it "未保存の原画ライセンスグループを保持している" do
255         post :create, @attr
256         assigns(:original_picture_license_group).should be_a_new(OriginalPictureLicenseGroup)
257       end
258       context 'html形式' do
259         it 'ステータスコード200 OKを返す' do
260           post :create, @attr
261           response.status.should eq 200
262         end
263         it '新規ページを描画する' do
264           post :create, @attr
265           response.should render_template("new")
266         end
267       end
268       context 'js形式' do
269         it 'ステータスコード200 OKを返す' do
270           post :create, @attrj
271           response.status.should eq 200
272         end
273         it '新規ページを描画する' do
274           post :create, @attrj
275           response.should render_template("new")
276         end
277       end
278     end
279   end
280   
281 else
282   describe '新規作成フォーム表示に於いて' do
283     before do
284       sign_in @user
285     end
286     context 'つつがなく終わるとき' do
287       before do
288         @attr = {:original_picture_id => @op.id}
289         @attrj = @attr.merge({:format => :js})
290       end
291       it 'ステータスコード200 OKを返す' do
292         get :new, @attr
293         response.should be_success 
294       end
295       context 'html形式' do
296         it 'ページテンプレートnewを描画する' do
297           get :new, @attr
298           response.should render_template("new")
299         end
300       end
301       context 'js形式' do
302         it '部分テンプレートnew.jsを描画する' do
303           get :new, @attrj
304           response.should render_template("new")
305         end
306       end
307     end
308     context '作家権限がないとき' do
309       before do
310         sign_out @user
311         @attr = {:original_picture_id => @op.id}
312         @attrj = @attr.merge({:format => :js})
313       end
314       context 'html形式' do
315         it 'ステータスコード302 Foundを返す' do
316           get :new, @attr
317           response.status.should eq 302
318         end
319         it 'サインインページへ遷移する' do
320           get :new, @attr
321           response.body.should redirect_to '/users/sign_in'
322         end
323       end
324       context 'js形式' do
325         it 'ステータスコード401 Unauthorizedを返す' do
326           get :new, @attrj
327           response.status.should eq 401
328         end
329         it '応答メッセージにUnauthorizedを返す' do
330           get :new, @attrj
331           response.message.should match(/Unauthorized/)
332         end
333       end
334     end
335   end
336
337   describe '新規作成に於いて' do
338     before do
339       sign_in @user
340     end
341     context 'つつがなく終わるとき' do
342       before 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})
345       end
346       context 'html形式' do
347         it 'ステータスコード200 OKを返す' do
348           post :create, @attr
349           response.should be_success
350         end
351         it 'ライセンスクラスの新規作成テンプレートnewを描画する' do
352           post :create, @attr
353           response.should render_template("pettanr_unknown_v01_licenses/attributes/new")
354         end
355       end
356       context 'js形式' do
357         it 'ステータスコード200 OKを返す' do
358           post :create, @attrj
359           response.should be_success 
360         end
361         it 'ライセンスクラスの新規作成部分テンプレートnew.jsを描画する' do
362           post :create, @attrj
363           response.should render_template("pettanr_unknown_v01_licenses/attributes/new")
364         end
365       end
366     end
367     context '作家権限がないとき' do
368       before do
369         sign_out @user
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})
372       end
373       context 'html形式' do
374         it 'ステータスコード302 Foundを返す' do
375           post :create, @attr
376           response.status.should eq 302
377         end
378         it 'サインインページへ遷移する' do
379           post :create, @attr
380           response.body.should redirect_to '/users/sign_in'
381         end
382       end
383       context 'json形式' do
384         it 'ステータスコード401 Unauthorizedを返す' do
385           post :create, @attrj
386           response.status.should eq 401
387         end
388         it '応答メッセージにUnauthorizedを返す' do
389           post :create, @attrj
390           response.message.should match(/Unauthorized/)
391         end
392       end
393     end
394   end
395   
396 end
397
398 end