@license = FactoryGirl.create :license, :license_group_id => @lg.id, :system_picture_id => @sp.id
end
+if MagicNumber['run_mode'] == 1
describe '一覧表示に於いて' do
before do
@op = FactoryGirl.create :original_picture, :artist_id => @artist.id
end
end
end
+
+else
+ describe '一覧表示に於いて' do
+ before do
+ @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
+ sign_in @user
+ OriginalPicture.stub(:mylist).and_return([@op, @op, @op])
+ end
+ context 'つつがなく終わるとき' do
+ it 'ステータスコード200 OKを返す' do
+ get :index
+ response.should be_success
+ end
+ context 'html形式' do
+ it 'indexテンプレートを描画する' do
+ get :index
+ response.should render_template("index")
+ end
+ end
+ context 'json形式' do
+ it 'jsonデータを返す' do
+ get :index, :format => :json
+ lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
+ end
+ end
+ end
+ context '作家権限がないとき' do
+ before do
+ sign_out @user
+ end
+ context 'html形式' do
+ it 'ステータスコード302 Foundを返す' do
+ get :index
+ response.status.should eq 302
+ end
+ it 'サインインページへ遷移する' do
+ get :index
+ response.should redirect_to '/users/sign_in'
+ end
+ end
+ context 'json形式' do
+ it 'ステータスコード401 Unauthorizedを返す' do
+ get :index, :format => :json
+ response.status.should eq 401
+ end
+ it '応答メッセージにUnauthorizedを返す' do
+ get :index, :format => :json
+ response.message.should match(/Unauthorized/)
+ end
+ end
+ end
+ end
+
+ describe '単体表示に於いて' do
+ before do
+ @pic = FactoryGirl.create :original_picture, :artist_id => @artist.id
+ sign_in @user
+ OriginalPicture.stub(:show).and_return(@pic)
+ end
+ context 'つつがなく終わるとき' do
+ it 'ステータスコード200 OKを返す' do
+ get :show, :id => @pic.id
+ response.should be_success
+ end
+ context 'html形式' do
+ it 'showテンプレートを描画する' do
+ get :show, :id => @pic.id
+ response.should render_template("show")
+ end
+ end
+ context 'json形式' do
+ it 'jsonデータを返す' do
+ get :show, :id => @pic.id, :format => :json
+ lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
+ end
+ end
+ end
+ context '作家権限がないとき' do
+ before do
+ sign_out @user
+ end
+ context 'html形式' do
+ it 'ステータスコード302 Foundを返す' do
+ get :show, :id => @pic.id
+ response.status.should eq 302
+ end
+ it 'サインインページへ遷移する' do
+ get :show, :id => @pic.id
+ response.body.should redirect_to '/users/sign_in'
+ end
+ end
+ context 'json形式' do
+ it 'ステータスコード401 Unauthorizedを返す' do
+ get :show, :id => @pic.id, :format => :json
+ response.status.should eq 401
+ end
+ it '応答メッセージにUnauthorizedを返す' do
+ get :show, :id => @pic.id, :format => :json
+ response.message.should match(/Unauthorized/)
+ end
+ end
+ end
+ end
+
+ describe '履歴一覧表示に於いて' do
+ before do
+ @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
+ @p = FactoryGirl.create :picture, :artist_id => @artist.id, :license_id => @license.id, :revision => 0,
+ :original_picture_id => @op.id
+ sign_in @user
+ OriginalPicture.stub(:show).and_return(@op)
+ OriginalPicture.any_instance.stub(:history).and_return([@p, @p, @p])
+ end
+ context 'つつがなく終わるとき' do
+ it 'ステータスコード200 OKを返す' do
+ get :history, :id => @op.id
+ response.should be_success
+ end
+ context 'html形式' do
+ it 'historyテンプレートを描画する' do
+ get :history, :id => @op.id
+ response.should render_template("history")
+ end
+ end
+ context 'json形式' do
+ it 'jsonデータを返す' do
+ get :history, :id => @op.id, :format => :json
+ lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
+ end
+ end
+ end
+ context '作家権限がないとき' do
+ before do
+ sign_out @user
+ end
+ context 'html形式' do
+ it 'ステータスコード302 Foundを返す' do
+ get :history, :id => @op.id
+ response.status.should eq 302
+ end
+ it 'サインインページへ遷移する' do
+ get :history, :id => @op.id
+ response.should redirect_to '/users/sign_in'
+ end
+ end
+ context 'json形式' do
+ it 'ステータスコード401 Unauthorizedを返す' do
+ get :history, :id => @op.id, :format => :json
+ response.status.should eq 401
+ end
+ it '応答メッセージにUnauthorizedを返す' do
+ get :history, :id => @op.id, :format => :json
+ response.message.should match(/Unauthorized/)
+ end
+ end
+ end
+ end
+
+ describe '新規作成フォーム表示に於いて' do
+ before do
+ sign_in @user
+ end
+ context 'つつがなく終わるとき' do
+ context 'html形式' do
+ it 'ステータスコード200 OKを返す' do
+ get :new
+ response.should be_success
+ end
+ it 'ページテンプレートnewを描画する' do
+ get :new
+ response.should render_template("new")
+ end
+ end
+ context 'js形式' do
+ it 'ステータスコード200 OKを返す' do
+ get :new, :format => :js
+ response.should be_success
+ end
+ it '部分テンプレートnew.jsを描画する' do
+ get :new, :format => :js
+ response.should render_template("new")
+ end
+ end
+ context 'json形式' do
+ it 'jsonデータを返す' do
+ get :new, :format => :json
+ lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
+ end
+ end
+ end
+ context '作家権限がないとき' do
+ before do
+ sign_out @user
+ end
+ context 'html形式' do
+ it 'ステータスコード302 Foundを返す' do
+ get :new
+ response.status.should eq 302
+ end
+ it 'サインインページへ遷移する' do
+ get :new
+ response.body.should redirect_to '/users/sign_in'
+ end
+ end
+ context 'js形式' do
+ it 'ステータスコード401 Unauthorizedを返す' do
+ get :new, :format => :js
+ response.status.should eq 401
+ end
+ it '応答メッセージにUnauthorizedを返す' do
+ get :new, :format => :js
+ response.message.should match(/Unauthorized/)
+ end
+ end
+ end
+ end
+
+ describe '新規作成に於いて' do
+ before do
+ sign_in @user
+ @attr = {:original_picture => {:file => "abc\ndef\nghi"}}
+ @imager = ImagerTest.load("abc\ndef\nghi")
+ OriginalPicturesController.any_instance.stub(:set_image).with(any_args()).and_return("abc\ndef\nghi")
+ end
+ context 'つつがなく終わるとき' do
+ before do
+ PettanImager.stub(:load).with("abc\ndef\nghi").and_return(@imager)
+ end
+ context 'html形式' do
+ it 'ステータスコード302 Foundを返す' do
+ post :create, @attr
+ response.status.should eq 302
+ end
+ it '作成された原画の表示ページへ遷移する' do
+ post :create, @attr
+ response.should redirect_to(OriginalPicture.last)
+ end
+ end
+ context 'json形式' do
+ before do
+ @attr.merge!({:format => :json})
+ end
+ it 'ステータスコード200 OKを返す' do
+ post :create, @attr
+ response.should be_success
+ end
+ it '作成された原画をjsonデータで返す' do
+ post :create, @attr
+ lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
+ end
+ end
+ end
+ context '作家権限がないとき' do
+ before do
+ sign_out @user
+ end
+ context 'html形式' do
+ it 'ステータスコード302 Foundを返す' do
+ post :create, @attr
+ response.status.should eq 302
+ end
+ it 'サインインページへ遷移する' do
+ post :create, @attr
+ response.body.should redirect_to '/users/sign_in'
+ end
+ end
+ context 'json形式' do
+ before do
+ @attr.merge!({:format => :json})
+ end
+ it 'ステータスコード401 Unauthorizedを返す' do
+ post :create, @attr
+ response.status.should eq 401
+ end
+ it '応答メッセージにUnauthorizedを返す' do
+ post :create, @attr
+ response.message.should match(/Unauthorized/)
+ end
+ end
+ end
+ end
+
+ describe '編集フォーム表示に於いて' do
+ before do
+ @pic = FactoryGirl.create :original_picture, :artist_id => @artist.id
+ sign_in @user
+ OriginalPicture.stub(:show).and_return(@pic)
+ end
+ context 'つつがなく終わるとき' do
+ it 'ステータスコード200 OKを返す' do
+ get :edit, :id => @pic.id
+ response.should be_success
+ end
+ context 'html形式' do
+ it 'ページテンプレートeditを描画する' do
+ get :edit, :id => @pic.id
+ response.should render_template("edit")
+ end
+ end
+ context 'js形式' do
+ it '部分テンプレートedit.jsを描画する' do
+ get :edit, :id => @pic.id, :format => :js
+ response.should render_template("edit")
+ end
+ end
+ end
+ context '作家権限がないとき' do
+ before do
+ sign_out @user
+ end
+ context 'html形式' do
+ it 'ステータスコード302 Foundを返す' do
+ get :edit, :id => @pic.id
+ response.status.should eq 302
+ end
+ it 'サインインページへ遷移する' do
+ get :edit, :id => @pic.id
+ response.body.should redirect_to '/users/sign_in'
+ end
+ end
+ context 'js形式' do
+ it 'ステータスコード401 Unauthorizedを返す' do
+ get :edit, :id => @pic.id, :format => :js
+ response.status.should eq 401
+ end
+ it '応答メッセージにUnauthorizedを返す' do
+ get :edit, :id => @pic.id, :format => :js
+ response.message.should match(/Unauthorized/)
+ end
+ end
+ end
+ end
+
+ describe '更新に於いて' do
+ before do
+ @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
+ OriginalPicture.stub(:edit).with(@op.id.to_s, @artist).and_return(@op)
+ OriginalPicturesController.any_instance.stub(:set_image).with(any_args()).and_return("abc\ndef\nghi")
+ sign_in @user
+ @attr = {:file => "abc\ndef\nghi"}
+ @imager = ImagerTest.load("abc\ndef\nghi")
+ end
+ context 'つつがなく終わるとき' do
+ before do
+ PettanImager.stub(:load).with("abc\ndef\nghi").and_return(@imager)
+ end
+ context 'html形式' do
+ it 'ステータスコード302 Foundを返す' do
+ put :update, :id => @op.id, :original_picture => @attr
+ response.status.should eq 302
+ end
+ it '更新された原画の表示ページへ遷移する' do
+ put :update, :id => @op.id, :original_picture => @attr
+ response.should redirect_to(@pic)
+ end
+ end
+ context 'json形式' do
+ it 'ステータスコード200 OKを返す' do
+ put :update, :id => @op.id, :original_picture => @attr, :format => :json
+ response.should be_success
+ end
+ it 'ページ本体は特に返さない' do
+ put :update, :id => @op.id, :original_picture => @attr, :format => :json
+ response.body.should match /./
+ end
+ end
+ end
+ context '作家権限がないとき' do
+ before do
+ sign_out @user
+ end
+ context 'html形式' do
+ it 'ステータスコード302 Foundを返す' do
+ put :update, :id => @op.id, :original_picture => @attr
+ response.status.should eq 302
+ end
+ it 'サインインページへ遷移する' do
+ put :update, :id => @op.id, :original_picture => @attr
+ response.body.should redirect_to '/users/sign_in'
+ end
+ end
+ context 'json形式' do
+ it 'ステータスコード401 Unauthorizedを返す' do
+ put :update, :id => @op.id, :original_picture => @attr, :format => :json
+ response.status.should eq 401
+ end
+ it '応答メッセージにUnauthorizedを返す' do
+ put :update, :id => @op.id, :original_picture => @attr, :format => :json
+ response.message.should match(/Unauthorized/)
+ end
+ end
+ end
+ context '作家が絵師でないとき' do
+ before do
+ Author.any_instance.stub(:artist?).and_return(false)
+ end
+ context 'html形式' do
+ it 'ステータスコード302 Foundを返す' do
+ put :update, :id => @op.id, :original_picture => @attr
+ response.status.should eq 302
+ end
+ it '絵師登録ページへ遷移する' do
+ put :update, :id => @op.id, :original_picture => @attr
+ response.should redirect_to new_artist_path
+ end
+ end
+ context 'json形式' do
+ it '例外403 forbiddenを返す' do
+ lambda{
+ put :update, :id => @op.id, :original_picture => @attr, :format => :json
+ }.should raise_error(ActiveRecord::Forbidden)
+ end
+ end
+ end
+ context '検証、保存に失敗した' do
+ before do
+ PettanImager.stub(:load).with("abc\ndef\nghi").and_return(@imager)
+ OriginalPicture.any_instance.stub(:store).with(@imager).and_return(false)
+ end
+ context 'html形式' do
+ it 'ステータスコード200 Okを返す' do
+ put :update, :id => @op.id, :original_picture => @attr
+ response.status.should eq 200
+ end
+ it '編集ページを描画する' do
+ put :update, :id => @op.id, :original_picture => @attr
+ response.should render_template("edit")
+ end
+ end
+ context 'json形式' do
+ it 'ステータスコード422 unprocessable_entity を返す' do
+ put :update, :id => @op.id, :original_picture => @attr, :format => :json
+ response.status.should eq 422
+ end
+ it '応答メッセージUnprocessable Entityを返す' do
+ put :update, :id => @op.id, :original_picture => @attr, :format => :json
+ response.message.should match(/Unprocessable/)
+ end
+ end
+ end
+ end
+
+ describe '削除に於いて' do
+ before do
+ @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
+ sign_in @user
+ end
+ context '事前チェックしておく' do
+ before do
+ OriginalPicture.stub(:edit).with(any_args()).and_return @op
+ OriginalPicture.any_instance.stub(:destroy_with_resource_picture).with(any_args()).and_return(true)
+ end
+ it '原画モデルに編集取得を問い合わせている' do
+ OriginalPicture.should_receive(:edit).exactly(1)
+ delete :destroy, :id => @op.id
+ end
+ it 'モデルに削除を依頼する' do
+ OriginalPicture.any_instance.should_receive(:destroy_with_resource_picture).exactly(1)
+ delete :destroy, :id => @op.id
+ end
+ it '@original_pictureにアレを取得している' do
+ delete :destroy, :id => @op.id
+ assigns(:original_picture).id.should eq(@op.id)
+ end
+ end
+ context 'つつがなく終わるとき' do
+ before do
+ OriginalPicture.any_instance.stub(:destroy_with_resource_picture).with(any_args()).and_return(true)
+ end
+ context 'html形式' do
+ it 'ステータスコード302 Foundを返す' do
+ delete :destroy, :id => @op.id
+ response.status.should eq 302
+ end
+ it '原画の一覧ページへ遷移する' do
+ delete :destroy, :id => @op.id
+ response.should redirect_to(original_pictures_path)
+ end
+ end
+ context 'json形式' do
+ it 'ステータスコード200 OKを返す' do
+ delete :destroy, :id => @op.id, :format => :json
+ response.should be_success
+ end
+ it 'ページ本体は特に返さない' do
+ delete :destroy, :id => @op.id, :format => :json
+ response.body.should match /./
+ end
+ end
+ end
+ context '作家権限がないとき' do
+ before do
+ sign_out @user
+ end
+ it 'ステータスコード302 Foundを返す' do
+ delete :destroy, :id => @op.id
+ response.status.should eq 302
+ end
+ context 'html形式' do
+ it 'サインインページへ遷移する' do
+ delete :destroy, :id => @op.id
+ response.body.should redirect_to '/users/sign_in'
+ end
+ end
+ context 'json形式' do
+ it '応答メッセージにUnauthorizedを返す' do
+ delete :destroy, :id => @op.id, :format => :json
+ response.message.should match(/Unauthorized/)
+ end
+ end
+ end
+ context '削除に失敗したとき' do
+ before do
+ OriginalPicture.any_instance.stub(:destroy_with_resource_picture).and_return(false)
+ end
+ context 'html形式' do
+ it 'ステータスコード302 Foundを返す' do
+ delete :destroy, :id => @op.id
+ response.status.should eq 302
+ end
+ it 'その原画の詳細ページへ遷移する' do
+ delete :destroy, :id => @op.id
+ response.should redirect_to(original_picture_path(@op))
+ end
+ end
+ context 'json形式' do
+ it 'ステータスコード422 unprocessable_entity を返す' do
+ delete :destroy, :id => @op.id, :format => :json
+ response.status.should eq 422
+ end
+ it '応答メッセージUnprocessable Entityを返す' do
+ delete :destroy, :id => @op.id, :format => :json
+ response.message.should match(/Unprocessable/)
+ end
+ end
+ end
+ end
+end
+
end