OSDN Git Service

add OriginalPictureLicenseGroup
[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     Factory :admin
8     @user = Factory( :user_yas)
9     @author = @user.author
10     @artist = Factory :artist_yas, :author_id => @author.id
11     @sp = Factory :system_picture
12     @lg = Factory :license_group, :classname => 'OriginalPicture'
13     @license = Factory :license, :license_group_id => @lg.id, :system_picture_id => @sp.id
14     @op = Factory :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         @attr = {:original_picture_id => @op.id}
24         @attrj = @attr.merge({:format => :js})
25       end
26       it 'ステータスコード200 OKを返す' do
27         get :new, @attr
28         response.should be_success 
29       end
30       it '原画モデルに単体取得を問い合わせている' do
31         OriginalPicture.stub(:show).with(any_args()).and_return(@op)
32         OriginalPicture.should_receive(:show).with(any_args()).exactly(1)\r
33         get :new, @attr
34       end
35       it '@original_pictureにデータを用意している' do
36         get :new, @attr
37         assigns(:original_picture).should eq @op
38       end
39       it '@original_picture_license_groupに新規データを用意している' do
40         get :new, @attr
41         assigns(:original_picture_license_group).should be_a_new(OriginalPictureLicenseGroup)
42       end
43       it '原画ライセンスグループモデルにデフォルト値補充を依頼している' do
44         OriginalPictureLicenseGroup.any_instance.should_receive(:supply_default).exactly(1)\r
45         get :new, @attr
46       end
47       context 'html形式' do
48         it 'ページテンプレートnewを描画する' do
49           get :new, @attr
50           response.should render_template("new")
51         end
52       end
53       context 'js形式' do
54         it '部分テンプレートnew.jsを描画する' do
55           get :new, @attrj
56           response.should render_template("new")
57         end
58       end
59     end
60     context '作家権限がないとき' do
61       before do
62         sign_out @user
63         @attr = {:original_picture_id => @op.id}
64         @attrj = @attr.merge({:format => :js})
65       end
66       context 'html形式' do
67         it 'ステータスコード302 Foundを返す' do
68           get :new, @attr
69           response.status.should eq 302
70         end
71         it 'サインインページへ遷移する' do
72           get :new, @attr
73           response.body.should redirect_to '/users/sign_in'
74         end
75       end
76       context 'js形式' do
77         it 'ステータスコード401 Unauthorizedを返す' do
78           get :new, @attrj
79           response.status.should eq 401
80         end
81         it '応答メッセージにUnauthorizedを返す' do
82           get :new, @attrj
83           response.message.should match(/Unauthorized/)
84         end
85       end
86     end
87     context '作家が絵師でないとき' do
88       before do
89         @attr = {:original_picture_id => @op.id}
90         @attrj = @attr.merge({:format => :js})
91         Author.any_instance.stub(:artist?).and_return(false)
92       end
93       context 'html形式' do
94         it 'ステータスコード302 Foundを返す' do
95           get :new, @attr
96           response.status.should eq 302
97         end
98         it '絵師登録ページへ遷移する' do
99           get :new, @attr
100           response.should redirect_to new_artist_path
101         end
102       end
103       context 'js形式' do
104         it 'ステータスコード200 Okを返す' do
105           get :new, @attrj
106           response.status.should eq 200
107         end
108         it '絵師登録部分テンプレートartists/new.jsを描画する' do
109           get :new, @attrj
110           response.should render_template("artists/new")
111         end
112       end
113     end
114   end
115
116   describe '新規作成に於いて' do
117     before do
118       sign_in @user
119     end
120     context '事前チェックしておく' do
121       before do
122         OriginalPictureLicenseGroup.any_instance.stub(:valid?).with(any_args()).and_return(true)
123         @attr = {:original_picture_id => @op.id, :original_picture_license_group => {:original_picture_id => @op.id, :license_group_id => @lg.id}}
124         @attrj = @attr.merge({:format => :js})
125       end
126       it '原画モデルに単体取得を問い合わせている' do
127         OriginalPicture.stub(:show).with(any_args()).and_return(@op)
128         OriginalPicture.should_receive(:show).exactly(1)\r
129         post :create, @attr
130       end
131       it '@original_pictureにデータを用意している' do
132         post :create, @attr
133         assigns(:original_picture).should eq @op
134       end
135       it 'ライセンスグループモデルに単体取得を問い合わせている' do
136         LicenseGroup.stub(:show).with(any_args()).and_return(@lg)
137         LicenseGroup.should_receive(:show).exactly(1)\r
138         post :create, @attr
139       end
140       it '@license_groupにデータを用意している' do
141         post :create, @attr
142         assigns(:license_group).should eq @lg
143       end
144       it '@ctlにコントローラを用意している' do
145         post :create, @attr
146         assigns(:ctl).should eq 'original_pictures'
147       end
148       it 'モデルに検証依頼する' do
149         OriginalPictureLicenseGroup.any_instance.stub(:valid?).with(any_args()).and_return(true)
150         OriginalPictureLicenseGroup.any_instance.should_receive(:valid?).exactly(1)
151         post :create, @attr
152       end
153     end
154     context 'つつがなく終わるとき' do
155       before do
156         @attr = {:original_picture_id => @op.id, :original_picture_license_group => {:original_picture_id => @op.id, :license_group_id => @lg.id}}
157         @attrj = @attr.merge({:format => :js})
158       end
159       it "検証が通る" do
160         post :create, @attr
161         assigns(:original_picture_license_group).valid?.should eq true
162       end
163       it "DBに変化がない" do
164         lambda {
165           post :create, @attr
166         }.should_not change OriginalPictureLicenseGroup, :count
167       end
168       context 'html形式' do
169         it 'ステータスコード200 OKを返す' do
170           post :create, @attr
171           response.should be_success
172         end
173         it 'ライセンスクラスの新規作成テンプレートnewを描画する' do
174           post :create, @attr
175           response.should render_template("original_pictures/new")
176         end
177       end
178       context 'js形式' do
179         it 'ステータスコード200 OKを返す' do
180           post :create, @attrj
181           response.should be_success 
182         end
183         it 'ライセンスクラスの新規作成部分テンプレートnew.jsを描画する' do
184           post :create, @attrj
185           response.should render_template("original_pictures/new")
186         end
187       end
188     end
189     context '作家権限がないとき' do
190       before do
191         sign_out @user
192         @attr = {:original_picture_id => @op.id, :original_picture_license_group => {:original_picture_id => @op.id, :license_group_id => @lg.id}}
193         @attrj = @attr.merge({:format => :js})
194       end
195       context 'html形式' do
196         it 'ステータスコード302 Foundを返す' do
197           post :create, @attr
198           response.status.should eq 302
199         end
200         it 'サインインページへ遷移する' do
201           post :create, @attr
202           response.body.should redirect_to '/users/sign_in'
203         end
204       end
205       context 'json形式' do
206         it 'ステータスコード401 Unauthorizedを返す' do
207           post :create, @attrj
208           response.status.should eq 401
209         end
210         it '応答メッセージにUnauthorizedを返す' do
211           post :create, @attrj
212           response.message.should match(/Unauthorized/)
213         end
214       end
215     end
216     context '作家が絵師でないとき' do
217       before do
218         Author.any_instance.stub(:artist?).and_return(false)
219         @attr = {:original_picture_id => @op.id, :original_picture_license_group => {:original_picture_id => @op.id, :license_group_id => @lg.id}}
220         @attrj = @attr.merge({:format => :js})
221       end
222       context 'html形式' do
223         it 'ステータスコード302 Foundを返す' do
224           post :create, @attr
225           response.status.should eq 302
226         end
227         it '絵師登録ページへ遷移する' do
228           post :create, @attr
229           response.should redirect_to new_artist_path
230         end
231       end
232       context 'js形式' do
233         it 'ステータスコード200 OKを返す' do
234           post :create, @attrj
235           response.status.should eq 200
236         end
237         it '絵師登録ページへ遷移する' do
238           post :create, @attrj
239           response.should render_template("artists/new")
240         end
241       end
242     end
243     context '検証、保存に失敗した' do
244       before do
245         OriginalPictureLicenseGroup.any_instance.stub(:valid?).and_return(false)
246         @attr = {:original_picture_id => @op.id, :original_picture_license_group => {:original_picture_id => @op.id, :license_group_id => @lg.id}}
247         @attrj = @attr.merge({:format => :js})
248       end
249       it "未保存の原画ライセンスグループを保持している" do
250         post :create, @attr
251         assigns(:original_picture_license_group).should be_a_new(OriginalPictureLicenseGroup)
252       end
253       context 'html形式' do
254         it 'ステータスコード200 OKを返す' do
255           post :create, @attr
256           response.status.should eq 200
257         end
258         it '新規ページを描画する' do
259           post :create, @attr
260           response.should render_template("new")
261         end
262       end
263       context 'js形式' do
264         it 'ステータスコード200 OKを返す' do
265           post :create, @attrj
266           response.status.should eq 200
267         end
268         it '新規ページを描画する' do
269           post :create, @attrj
270           response.should render_template("new")
271         end
272       end
273     end
274   end
275
276 end