OSDN Git Service

9791a6c0d2ebea3515f3a4df9278a5486ec2614d
[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     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         @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 '@original_picture_license_groupにデータを用意している' do
149         post :create, @attr
150         assigns(:original_picture_license_group).should be_a_new OriginalPictureLicenseGroup
151       end
152       it 'モデルに検証依頼する' do
153         OriginalPictureLicenseGroup.any_instance.stub(:valid?).with(any_args()).and_return(true)
154         OriginalPictureLicenseGroup.any_instance.should_receive(:valid?).exactly(1)
155         post :create, @attr
156       end
157     end
158     context 'つつがなく終わるとき' do
159       before do
160         @attr = {:original_picture_id => @op.id, :original_picture_license_group => {:original_picture_id => @op.id, :license_group_id => @lg.id}}
161         @attrj = @attr.merge({:format => :js})
162       end
163       it "検証が通る" do
164         post :create, @attr
165         assigns(:original_picture_license_group).valid?.should eq true
166       end
167       it "DBに変化がない" do
168         lambda {
169           post :create, @attr
170         }.should_not change OriginalPictureLicenseGroup, :count
171       end
172       context 'html形式' do
173         it 'ステータスコード200 OKを返す' do
174           post :create, @attr
175           response.should be_success
176         end
177         it 'ライセンスクラスの新規作成テンプレートnewを描画する' do
178           post :create, @attr
179           response.should render_template("original_pictures/new")
180         end
181       end
182       context 'js形式' do
183         it 'ステータスコード200 OKを返す' do
184           post :create, @attrj
185           response.should be_success 
186         end
187         it 'ライセンスクラスの新規作成部分テンプレートnew.jsを描画する' do
188           post :create, @attrj
189           response.should render_template("original_pictures/new")
190         end
191       end
192     end
193     context '作家権限がないとき' do
194       before do
195         sign_out @user
196         @attr = {:original_picture_id => @op.id, :original_picture_license_group => {:original_picture_id => @op.id, :license_group_id => @lg.id}}
197         @attrj = @attr.merge({:format => :js})
198       end
199       context 'html形式' do
200         it 'ステータスコード302 Foundを返す' do
201           post :create, @attr
202           response.status.should eq 302
203         end
204         it 'サインインページへ遷移する' do
205           post :create, @attr
206           response.body.should redirect_to '/users/sign_in'
207         end
208       end
209       context 'json形式' do
210         it 'ステータスコード401 Unauthorizedを返す' do
211           post :create, @attrj
212           response.status.should eq 401
213         end
214         it '応答メッセージにUnauthorizedを返す' do
215           post :create, @attrj
216           response.message.should match(/Unauthorized/)
217         end
218       end
219     end
220     context '作家が絵師でないとき' do
221       before do
222         Author.any_instance.stub(:artist?).and_return(false)
223         @attr = {:original_picture_id => @op.id, :original_picture_license_group => {:original_picture_id => @op.id, :license_group_id => @lg.id}}
224         @attrj = @attr.merge({:format => :js})
225       end
226       context 'html形式' do
227         it 'ステータスコード302 Foundを返す' do
228           post :create, @attr
229           response.status.should eq 302
230         end
231         it '絵師登録ページへ遷移する' do
232           post :create, @attr
233           response.should redirect_to new_artist_path
234         end
235       end
236       context 'js形式' do
237         it 'ステータスコード200 OKを返す' do
238           post :create, @attrj
239           response.status.should eq 200
240         end
241         it '絵師登録ページへ遷移する' do
242           post :create, @attrj
243           response.should render_template("artists/new")
244         end
245       end
246     end
247     context '検証、保存に失敗した' do
248       before do
249         OriginalPictureLicenseGroup.any_instance.stub(:valid?).and_return(false)
250         @attr = {:original_picture_id => @op.id, :original_picture_license_group => {:original_picture_id => @op.id, :license_group_id => @lg.id}}
251         @attrj = @attr.merge({:format => :js})
252       end
253       it "未保存の原画ライセンスグループを保持している" do
254         post :create, @attr
255         assigns(:original_picture_license_group).should be_a_new(OriginalPictureLicenseGroup)
256       end
257       context 'html形式' do
258         it 'ステータスコード200 OKを返す' do
259           post :create, @attr
260           response.status.should eq 200
261         end
262         it '新規ページを描画する' do
263           post :create, @attr
264           response.should render_template("new")
265         end
266       end
267       context 'js形式' do
268         it 'ステータスコード200 OKを返す' do
269           post :create, @attrj
270           response.status.should eq 200
271         end
272         it '新規ページを描画する' do
273           post :create, @attrj
274           response.should render_template("new")
275         end
276       end
277     end
278   end
279
280 end