OSDN Git Service

t#29061/t#29089/t#29076:add mylist. modify panel picture
[pettanr/pettanr.git] / spec / controllers / standard_licenses_controller_spec.rb
1 # -*- encoding: utf-8 -*-
2 #ライセンス選択
3 require 'spec_helper'
4
5 describe StandardLicensesController do
6   before do
7     FactoryGirl.create :admin
8     @user = FactoryGirl.create( :user_yas)
9     @author = @user.author
10     @artist = FactoryGirl.create :artist_yas, :author_id => @author.id
11     @sp = FactoryGirl.create :system_picture
12     @lg = FactoryGirl.create :license_group, :classname => 'OriginalPicture'
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   describe '新規作成フォーム表示に於いて' do
18     before do
19       sign_in @user
20     end
21     context 'つつがなく終わるとき' do
22       before do
23         @oplg = FactoryGirl.build :oplg, :original_picture_id => @op.id, :license_group_id => @lg.id
24         @attr = {:original_picture_id => @op.id, :original_picture_license_group => {:original_picture_id => @oplg.original_picture_id, :license_group_id => @oplg.license_group_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)\r
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         LicenseGroup.stub(:show).with(any_args()).and_return(@lg)
46         LicenseGroup.should_receive(:show).with(any_args()).exactly(1)\r
47         get :new, @attr
48       end
49       it '@license_groupにデータを用意している' do
50         get :new, @attr
51         assigns(:license_group).should eq @lg
52       end
53       it '@standard_licenseにライセンス選択新規データを用意している' do
54         get :new, @attr
55         assigns(:standard_license).should be_a_new(StandardLicense)
56       end
57       it 'ライセンス選択にデフォルト値補充を依頼している' do
58         StandardLicense.any_instance.should_receive(:supply_default).exactly(1)\r
59         get :new, @attr
60       end
61       context 'html形式' do
62         it 'ページテンプレートnewを描画する' do
63           get :new, @attr
64           response.should render_template("new")
65         end
66       end
67       context 'js形式' do
68         it '部分テンプレートnew.jsを描画する' do
69           get :new, @attrj
70           response.should render_template("new")
71         end
72       end
73     end
74     context '作家権限がないとき' do
75       before do
76         sign_out @user
77         @oplg = FactoryGirl.build :oplg, :original_picture_id => @op.id, :license_group_id => @lg.id
78         @attr = {:original_picture_id => @op.id, :original_picture_license_group => {:original_picture_id => @oplg.original_picture_id, :license_group_id => @oplg.license_group_id}}
79         @attrj = @attr.merge({:format => :js})
80       end
81       context 'html形式' do
82         it 'ステータスコード302 Foundを返す' do
83           get :new, @attr
84           response.status.should eq 302
85         end
86         it 'サインインページへ遷移する' do
87           get :new, @attr
88           response.body.should redirect_to '/users/sign_in'
89         end
90       end
91       context 'js形式' do
92         it 'ステータスコード401 Unauthorizedを返す' do
93           get :new, @attrj
94           response.status.should eq 401
95         end
96         it '応答メッセージにUnauthorizedを返す' do
97           get :new, @attrj
98           response.message.should match(/Unauthorized/)
99         end
100       end
101     end
102     context '作家が絵師でないとき' do
103       before do
104         @oplg = FactoryGirl.build :oplg, :original_picture_id => @op.id, :license_group_id => @lg.id
105         @attr = {:original_picture_id => @op.id, :original_picture_license_group => {:original_picture_id => @oplg.original_picture_id, :license_group_id => @oplg.license_group_id}}
106         @attrj = @attr.merge({:format => :js})
107         Author.any_instance.stub(:artist?).and_return(false)
108       end
109       context 'html形式' do
110         it 'ステータスコード302 Foundを返す' do
111           get :new, @attr
112           response.status.should eq 302
113         end
114         it '絵師登録ページへ遷移する' do
115           get :new, @attr
116           response.should redirect_to new_artist_path
117         end
118       end
119       context 'js形式' do
120         it 'ステータスコード200 Okを返す' do
121           get :new, @attrj
122           response.status.should eq 200
123         end
124         it '絵師登録部分テンプレートartists/new.jsを描画する' do
125           get :new, @attrj
126           response.should render_template("artists/new")
127         end
128       end
129     end
130   end
131
132   describe '新規作成に於いて' do
133     before do
134       sign_in @user
135     end
136     context '事前チェックしておく' do
137       before do
138         StandardLicense.any_instance.stub(:valid?).with(any_args()).and_return(true)
139         @oplg = FactoryGirl.build :oplg, :original_picture_id => @op.id, :license_group_id => @lg.id
140         @attr = {:original_picture_id => @op.id, :original_picture_license_group => {:original_picture_id => @oplg.original_picture_id, :license_group_id => @oplg.license_group_id},
141           :standard_license => {:license_id => @license.id, :artist_name => @artist.name}
142         }
143         @attrj = @attr.merge({:format => :js})
144       end
145       it '原画モデルに単体取得を問い合わせている' do
146         OriginalPicture.stub(:show).with(any_args()).and_return(@op)
147         OriginalPicture.should_receive(:show).exactly(1)\r
148         post :create, @attr
149       end
150       it '@original_pictureにデータを用意している' do
151         post :create, @attr
152         assigns(:original_picture).should eq @op
153       end
154       it '@original_picture_license_groupにデータを用意している' do
155         post :create, @attr
156         assigns(:original_picture_license_group).should be_a_new OriginalPictureLicenseGroup
157       end
158       it 'ライセンスグループモデルに単体取得を問い合わせている' do
159         LicenseGroup.stub(:show).with(any_args()).and_return(@lg)
160         LicenseGroup.should_receive(:show).exactly(1)\r
161         post :create, @attr
162       end
163       it '@license_groupにデータを用意している' do
164         post :create, @attr
165         assigns(:license_group).should eq @lg
166       end
167       it '@standard_licenseにデータを用意している' do
168         post :create, @attr
169         assigns(:standard_license).should be_a_new StandardLicense
170       end
171       it '@licenseにデータを用意している' do
172         post :create, @attr
173         assigns(:license).should eq @license
174       end
175       it '@creditにデータを用意している' do
176         post :create, @attr
177         assigns(:credit).should eq nil
178       end
179       it 'モデルに検証依頼する' do
180         StandardLicense.any_instance.stub(:valid?).with(any_args()).and_return(true)
181         StandardLicense.any_instance.should_receive(:valid?).exactly(1)
182         post :create, @attr
183       end
184     end
185     context 'つつがなく終わるとき' do
186       before do
187         @oplg = FactoryGirl.build :oplg, :original_picture_id => @op.id, :license_group_id => @lg.id
188         @attr = {:original_picture_id => @op.id, :original_picture_license_group => {:original_picture_id => @oplg.original_picture_id, :license_group_id => @oplg.license_group_id},
189           :standard_license => {:license_id => @license.id, :artist_name => @artist.name}
190         }
191         @attrj = @attr.merge({:format => :js})
192       end
193       it "検証が通る" do
194         post :create, @attr
195         assigns(:standard_license).valid?.should eq true
196       end
197       it "DBに変化がない" do
198         lambda {
199           post :create, @attr
200         }.should_not change StandardLicense, :count
201       end
202       context 'html形式' do
203         it 'ステータスコード200 OKを返す' do
204           post :create, @attr
205           response.should be_success
206         end
207         it 'ライセンスクラスの新規作成テンプレートnewを描画する' do
208           post :create, @attr
209           response.should render_template("resource_pictures/new")
210         end
211       end
212       context 'js形式' do
213         it 'ステータスコード200 OKを返す' do
214           post :create, @attrj
215           response.should be_success 
216         end
217         it 'ライセンスクラスの新規作成部分テンプレートnew.jsを描画する' do
218           post :create, @attrj
219           response.should render_template("resource_pictures/new")
220         end
221       end
222     end
223     context '作家権限がないとき' do
224       before do
225         sign_out @user
226         @oplg = FactoryGirl.build :oplg, :original_picture_id => @op.id, :license_group_id => @lg.id
227         @attr = {:original_picture_id => @op.id, :original_picture_license_group => {:original_picture_id => @oplg.original_picture_id, :license_group_id => @oplg.license_group_id},
228           :standard_license => {:license_id => @license.id, :artist_name => @artist.name}
229         }
230         @attrj = @attr.merge({:format => :js})
231       end
232       context 'html形式' do
233         it 'ステータスコード302 Foundを返す' do
234           post :create, @attr
235           response.status.should eq 302
236         end
237         it 'サインインページへ遷移する' do
238           post :create, @attr
239           response.body.should redirect_to '/users/sign_in'
240         end
241       end
242       context 'json形式' do
243         it 'ステータスコード401 Unauthorizedを返す' do
244           post :create, @attrj
245           response.status.should eq 401
246         end
247         it '応答メッセージにUnauthorizedを返す' do
248           post :create, @attrj
249           response.message.should match(/Unauthorized/)
250         end
251       end
252     end
253     context '作家が絵師でないとき' do
254       before do
255         Author.any_instance.stub(:artist?).and_return(false)
256         @oplg = FactoryGirl.build :oplg, :original_picture_id => @op.id, :license_group_id => @lg.id
257         @attr = {:original_picture_id => @op.id, :original_picture_license_group => {:original_picture_id => @oplg.original_picture_id, :license_group_id => @oplg.license_group_id},
258           :standard_license => {:license_id => @license.id, :artist_name => @artist.name}
259         }
260         @attrj = @attr.merge({:format => :js})
261       end
262       context 'html形式' do
263         it 'ステータスコード302 Foundを返す' do
264           post :create, @attr
265           response.status.should eq 302
266         end
267         it '絵師登録ページへ遷移する' do
268           post :create, @attr
269           response.should redirect_to new_artist_path
270         end
271       end
272       context 'js形式' do
273         it 'ステータスコード200 OKを返す' do
274           post :create, @attrj
275           response.status.should eq 200
276         end
277         it '絵師登録ページへ遷移する' do
278           post :create, @attrj
279           response.should render_template("artists/new")
280         end
281       end
282     end
283     context '検証、保存に失敗した' do
284       before do
285         StandardLicense.any_instance.stub(:valid?).and_return(false)
286         @oplg = FactoryGirl.build :oplg, :original_picture_id => @op.id, :license_group_id => @lg.id
287         @attr = {:original_picture_id => @op.id, :original_picture_license_group => {:original_picture_id => @oplg.original_picture_id, :license_group_id => @oplg.license_group_id},
288           :standard_license => {:license_id => @license.id, :artist_name => @artist.name}
289         }
290         @attrj = @attr.merge({:format => :js})
291       end
292       it "未保存の原画ライセンスグループを保持している" do
293         post :create, @attr
294         assigns(:standard_license).should be_a_new(StandardLicense)
295       end
296       context 'html形式' do
297         it 'ステータスコード200 OKを返す' do
298           post :create, @attr
299           response.status.should eq 200
300         end
301         it '新規ページを描画する' do
302           post :create, @attr
303           response.should render_template("new")
304         end
305       end
306       context 'js形式' do
307         it 'ステータスコード200 OKを返す' do
308           post :create, @attrj
309           response.status.should eq 200
310         end
311         it '新規ページを描画する' do
312           post :create, @attrj
313           response.should render_template("new")
314         end
315       end
316     end
317   end
318
319 end