1 # -*- encoding: utf-8 -*-
5 describe OriginalPictureLicenseGroupsController 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
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)
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)
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)
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)
140 it '@license_groupにデータを用意している' do
142 assigns(:license_group).should eq @lg
144 it '@ctlにコントローラを用意している' do
146 assigns(:ctl).should eq 'pettanr_unknown_v01_licenses'
148 it '@original_picture_license_groupにデータを用意している' do
150 assigns(:original_picture_license_group).should be_a_new OriginalPictureLicenseGroup
153 OriginalPictureLicenseGroup.any_instance.stub(:valid?).with(any_args()).and_return(true)
154 OriginalPictureLicenseGroup.any_instance.should_receive(:valid?).exactly(1)
158 context 'つつがなく終わるとき' 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})
165 assigns(:original_picture_license_group).valid?.should eq true
170 }.should_not change OriginalPictureLicenseGroup, :count
173 it 'ステータスコード200 OKを返す' do
175 response.should be_success
177 it 'ライセンスクラスの新規作成テンプレートnewを描画する' do
179 response.should render_template("pettanr_unknown_v01_licenses/attributes/new")
183 it 'ステータスコード200 OKを返す' do
185 response.should be_success
187 it 'ライセンスクラスの新規作成部分テンプレートnew.jsを描画する' do
189 response.should render_template("pettanr_unknown_v01_licenses/attributes/new")
193 context '作家権限がないとき' do
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})
200 it 'ステータスコード302 Foundを返す' do
202 response.status.should eq 302
204 it 'サインインページへ遷移する' do
206 response.body.should redirect_to '/users/sign_in'
210 it 'ステータスコード401 Unauthorizedを返す' do
212 response.status.should eq 401
214 it '応答メッセージにUnauthorizedを返す' do
216 response.message.should match(/Unauthorized/)
220 context '作家が絵師でないとき' 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})
227 it 'ステータスコード302 Foundを返す' do
229 response.status.should eq 302
233 response.should redirect_to new_artist_path
237 it 'ステータスコード200 OKを返す' do
239 response.status.should eq 200
243 response.should render_template("artists/new")
247 context '検証、保存に失敗した' 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})
253 it "未保存の原画ライセンスグループを保持している" do
255 assigns(:original_picture_license_group).should be_a_new(OriginalPictureLicenseGroup)
258 it 'ステータスコード200 OKを返す' do
260 response.status.should eq 200
264 response.should render_template("new")
268 it 'ステータスコード200 OKを返す' do
270 response.status.should eq 200
274 response.should render_template("new")