1 # -*- encoding: utf-8 -*-
5 describe OriginalPictureLicenseGroupsController do
8 @user = Factory( :user_yas)
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
17 describe '新規作成フォーム表示に於いて' do
21 context 'つつがなく終わるとき' do
23 @attr = {:original_picture_id => @op.id}
24 @attrj = @attr.merge({:format => :js})
26 it 'ステータスコード200 OKを返す' do
28 response.should be_success
30 it '原画モデルに単体取得を問い合わせている' do
31 OriginalPicture.stub(:show).with(any_args()).and_return(@op)
32 OriginalPicture.should_receive(:show).with(any_args()).exactly(1)
\r
35 it '@original_pictureにデータを用意している' do
37 assigns(:original_picture).should eq @op
39 it '@original_picture_license_groupに新規データを用意している' do
41 assigns(:original_picture_license_group).should be_a_new(OriginalPictureLicenseGroup)
43 it '原画ライセンスグループモデルにデフォルト値補充を依頼している' do
44 OriginalPictureLicenseGroup.any_instance.should_receive(:supply_default).exactly(1)
\r
48 it 'ページテンプレートnewを描画する' do
50 response.should render_template("new")
54 it '部分テンプレートnew.jsを描画する' do
56 response.should render_template("new")
60 context '作家権限がないとき' do
63 @attr = {:original_picture_id => @op.id}
64 @attrj = @attr.merge({:format => :js})
67 it 'ステータスコード302 Foundを返す' do
69 response.status.should eq 302
73 response.body.should redirect_to '/users/sign_in'
77 it 'ステータスコード401 Unauthorizedを返す' do
79 response.status.should eq 401
81 it '応答メッセージにUnauthorizedを返す' do
83 response.message.should match(/Unauthorized/)
87 context '作家が絵師でないとき' do
89 @attr = {:original_picture_id => @op.id}
90 @attrj = @attr.merge({:format => :js})
91 Author.any_instance.stub(:artist?).and_return(false)
94 it 'ステータスコード302 Foundを返す' do
96 response.status.should eq 302
100 response.should redirect_to new_artist_path
104 it 'ステータスコード200 Okを返す' do
106 response.status.should eq 200
108 it '絵師登録部分テンプレートartists/new.jsを描画する' do
110 response.should render_template("artists/new")
116 describe '新規作成に於いて' do
120 context '事前チェックしておく' 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})
126 it '原画モデルに単体取得を問い合わせている' do
127 OriginalPicture.stub(:show).with(any_args()).and_return(@op)
128 OriginalPicture.should_receive(:show).exactly(1)
\r
131 it '@original_pictureにデータを用意している' do
133 assigns(:original_picture).should eq @op
135 it 'ライセンスグループモデルに単体取得を問い合わせている' do
136 LicenseGroup.stub(:show).with(any_args()).and_return(@lg)
137 LicenseGroup.should_receive(:show).exactly(1)
\r
140 it '@license_groupにデータを用意している' do
142 assigns(:license_group).should eq @lg
144 it '@ctlにコントローラを用意している' do
146 assigns(:ctl).should eq 'original_pictures'
149 OriginalPictureLicenseGroup.any_instance.stub(:valid?).with(any_args()).and_return(true)
150 OriginalPictureLicenseGroup.any_instance.should_receive(:valid?).exactly(1)
154 context 'つつがなく終わるとき' 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})
161 assigns(:original_picture_license_group).valid?.should eq true
166 }.should_not change OriginalPictureLicenseGroup, :count
169 it 'ステータスコード200 OKを返す' do
171 response.should be_success
173 it 'ライセンスクラスの新規作成テンプレートnewを描画する' do
175 response.should render_template("original_pictures/new")
179 it 'ステータスコード200 OKを返す' do
181 response.should be_success
183 it 'ライセンスクラスの新規作成部分テンプレートnew.jsを描画する' do
185 response.should render_template("original_pictures/new")
189 context '作家権限がないとき' do
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})
196 it 'ステータスコード302 Foundを返す' do
198 response.status.should eq 302
200 it 'サインインページへ遷移する' do
202 response.body.should redirect_to '/users/sign_in'
206 it 'ステータスコード401 Unauthorizedを返す' do
208 response.status.should eq 401
210 it '応答メッセージにUnauthorizedを返す' do
212 response.message.should match(/Unauthorized/)
216 context '作家が絵師でないとき' 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})
223 it 'ステータスコード302 Foundを返す' do
225 response.status.should eq 302
229 response.should redirect_to new_artist_path
233 it 'ステータスコード200 OKを返す' do
235 response.status.should eq 200
239 response.should render_template("artists/new")
243 context '検証、保存に失敗した' 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})
249 it "未保存の原画ライセンスグループを保持している" do
251 assigns(:original_picture_license_group).should be_a_new(OriginalPictureLicenseGroup)
254 it 'ステータスコード200 OKを返す' do
256 response.status.should eq 200
260 response.should render_template("new")
264 it 'ステータスコード200 OKを返す' do
266 response.status.should eq 200
270 response.should render_template("new")