OSDN Git Service

t#30200:update i18n devise
[pettanr/pettanr.git] / spec / controllers / original_pictures_controller_spec.rb
index d020400..4a325ef 100644 (file)
@@ -4,20 +4,20 @@ require 'spec_helper'
 
 describe OriginalPicturesController do
   before do
-    Factory :admin
-    @user = Factory( :user_yas)
-    @author = @user.author
-    @artist = Factory :artist_yas, :author_id => @author.id
-    @sp = Factory :system_picture
-    @lg = Factory :license_group
-    @license = Factory :license, :license_group_id => @lg.id, :system_picture_id => @sp.id
+    @admin = FactoryGirl.create :admin
+    @user = FactoryGirl.create( :user_yas)
+    @author = FactoryGirl.create :author, :user_id => @user.id
+    @artist = FactoryGirl.create :artist_yas, :author_id => @author.id
+    @sp = FactoryGirl.create :system_picture
+    @lg = FactoryGirl.create :license_group
+    @license = FactoryGirl.create :license, :license_group_id => @lg.id, :system_picture_id => @sp.id
   end
 
   describe '一覧表示に於いて' do
     before do
-      @op = Factory :original_picture, :artist_id => @artist.id
+      @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
       sign_in @user
-      OriginalPicture.stub(:list).and_return([@op, @op, @op])
+      OriginalPicture.stub(:mylist).and_return([@op, @op, @op])
     end
     context 'パラメータpageについて' do
       it '@pageに値が入る' do
@@ -34,7 +34,7 @@ describe OriginalPicturesController do
       end
       it '省略されると@page_sizeにデフォルト値が入る' do
         get :index
-        assigns(:page_size).should eq OriginalPicture.default_page_size\r
+        assigns(:page_size).should eq OriginalPicture.default_page_size
       end
       it '最大を超えると@page_sizeにデフォルト最大値が入る' do
         get :index, :page_size => 1500
@@ -50,8 +50,8 @@ describe OriginalPicturesController do
         get :index
         response.should be_success 
       end
-      it '原画モデルに一覧を問い合わせている' do
-        OriginalPicture.should_receive(:list).exactly(1)\r
+      it '原画モデルにマイリストを問い合わせている' do
+        OriginalPicture.should_receive(:mylist).exactly(1)
         get :index
       end
       it '@original_picturesにリストを取得している' do
@@ -69,6 +69,10 @@ describe OriginalPicturesController do
           get :index, :format => :json
           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
         end
+        it '原画モデルにjson一覧出力オプションを問い合わせている' do
+          OriginalPicture.should_receive(:list_json_opt).exactly(1)
+          get :index, :format => :json
+        end
         it 'データがリスト構造になっている' do
           get :index, :format => :json
           json = JSON.parse response.body
@@ -78,6 +82,9 @@ describe OriginalPicturesController do
           get :index, :format => :json
           json = JSON.parse response.body
           json.first.has_key?("ext").should be_true
+          json.first.has_key?("md5").should be_true
+          json.first.has_key?("artist_id").should be_true
+          json.first.has_key?("width").should be_true
         end
       end
     end
@@ -132,7 +139,7 @@ describe OriginalPicturesController do
   
   describe '単体表示に於いて' do
     before do
-      @pic = Factory :original_picture, :artist_id => @artist.id
+      @pic = FactoryGirl.create :original_picture, :artist_id => @artist.id
       sign_in @user
       OriginalPicture.stub(:show).and_return(@pic)
     end
@@ -142,7 +149,7 @@ describe OriginalPicturesController do
         response.should be_success
       end
       it '原画モデルに単体取得を問い合わせている' do
-        OriginalPicture.should_receive(:show).exactly(1)\r
+        OriginalPicture.should_receive(:show).exactly(1)
         get :show
       end
       it '@original_pictureにアレを取得している' do
@@ -160,44 +167,72 @@ describe OriginalPicturesController do
           get :show, :id => @pic.id, :format => :json
           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
         end
+        it '原画モデルにjson単体出力オプションを問い合わせている' do
+          OriginalPicture.should_receive(:show_json_opt).exactly(1)
+          get :show, :id => @pic.id, :format => :json
+        end
         it 'データがアレになっている' do
           get :show, :id => @pic.id, :format => :json
           json = JSON.parse response.body
           json["ext"].should match(/png/)
+          json["md5"].should be_true
+          json["artist_id"].should be_true
+          json["width"].should be_true
         end
       end
       #画像送信では、send_dataにスタブをおいてテストしたいが、ここに噛ませると
       #renderが働かず、エラーとなってしまう。そこで、原画のファイル取得部分に
       #スタブをおいてsend_dataがデータを返す体裁でテストする。
       context 'png形式' do
+        before do
+          OriginalPicture.any_instance.stub(:mime_type).and_return('image/png')
+          OriginalPicture.any_instance.stub(:restore).and_return('aaa')
+        end
         it '画像モデルに画像データを問い合わせる' do
-          OriginalPicture.any_instance.should_receive(:restore).exactly(1)\r
+          OriginalPicture.any_instance.should_receive(:restore).exactly(1)
+          get :show, :id => @pic.id, :format => :png
+        end
+        it '画像モデルにMimeTypeを問い合わせる' do
+          OriginalPicture.any_instance.should_receive(:mime_type).exactly(1)
           get :show, :id => @pic.id, :format => :png
         end
         it '画像を送信する' do
-          OriginalPicture.any_instance.stub(:restore).and_return('aaa')\r
           get :show, :id => @pic.id, :format => :png
           response.body.should eq 'aaa'
         end
       end
       context 'gif形式' do
+        before do
+          OriginalPicture.any_instance.stub(:mime_type).and_return('image/gif')
+          OriginalPicture.any_instance.stub(:restore).and_return('bbb')
+        end
         it '画像モデルに画像データを問い合わせる' do
-          OriginalPicture.any_instance.should_receive(:restore).exactly(1)\r
+          OriginalPicture.any_instance.should_receive(:restore).exactly(1)
+          get :show, :id => @pic.id, :format => :gif
+        end
+        it '画像モデルにMimeTypeを問い合わせる' do
+          OriginalPicture.any_instance.should_receive(:mime_type).exactly(1)
           get :show, :id => @pic.id, :format => :gif
         end
         it '画像を送信する' do
-          OriginalPicture.any_instance.stub(:restore).and_return('bbb')\r
           get :show, :id => @pic.id, :format => :gif
           response.body.should eq 'bbb'
         end
       end
       context 'jpeg形式' do
+        before do
+          OriginalPicture.any_instance.stub(:mime_type).and_return('image/jpeg')
+          OriginalPicture.any_instance.stub(:restore).and_return('ccc')
+        end
         it '画像モデルに画像データを問い合わせる' do
-          OriginalPicture.any_instance.should_receive(:restore).exactly(1)\r
+          OriginalPicture.any_instance.should_receive(:restore).exactly(1)
+          get :show, :id => @pic.id, :format => :jpeg
+        end
+        it '画像モデルにMimeTypeを問い合わせる' do
+          OriginalPicture.any_instance.should_receive(:mime_type).exactly(1)
           get :show, :id => @pic.id, :format => :jpeg
         end
         it '画像を送信する' do
-          OriginalPicture.any_instance.stub(:restore).and_return('ccc')\r
           get :show, :id => @pic.id, :format => :jpeg
           response.body.should eq 'ccc'
         end
@@ -293,35 +328,147 @@ describe OriginalPicturesController do
 =end
   end
 
-  describe '新規作成フォーム表示に於いて' do
+  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 :new
+        get :history, :id => @op.id
         response.should be_success 
       end
+      it '原画モデルに単体取得を問い合わせている' do
+        OriginalPicture.should_receive(:show).exactly(1)
+        get :history, :id => @op.id
+      end
+      it '自身に履歴一覧を問い合わせている' do
+        OriginalPicture.any_instance.should_receive(:history).exactly(1)
+        get :history, :id => @op.id
+      end
+      it '@historyにリストを取得している' do
+        get :history, :id => @op.id
+        assigns(:history).should have_at_least(3).items
+      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
+        it 'データがリスト構造になっている' do
+          get :history, :id => @op.id, :format => :json
+          json = JSON.parse response.body
+          json.should have_at_least(3).items
+        end
+        it 'リストの先頭くらいは原画っぽいものであって欲しい' do
+          get :history, :id => @op.id, :format => :json
+          json = JSON.parse response.body
+          json.first.has_key?("ext").should be_true
+        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
+    context '作家が絵師でないとき' do
+      before do
+        Author.any_instance.stub(:artist?).and_return(false)
+      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 new_artist_path
+        end
+      end
+      context 'json形式' do
+        it '例外403 forbiddenを返す' do
+          lambda{
+            get :history, :id => @op.id, :format => :json
+          }.should raise_error(ActiveRecord::Forbidden)
+        end
+      end
+    end
+  end
+  
+  describe '新規作成フォーム表示に於いて' do
+    before do
+      sign_in @user
+    end
+    context 'つつがなく終わるとき' do
       it '@original_pictureに新規データを用意している' do
         get :new
         assigns(:original_picture).should be_a_new(OriginalPicture)
       end
       it '原画モデルにデフォルト値補充を依頼している' do
-        OriginalPicture.any_instance.should_receive(:supply_default).exactly(1)\r
+        OriginalPicture.any_instance.should_receive(:supply_default).exactly(1)
         get :new
       end
       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
+        it '原画モデルにjson単体出力オプションを問い合わせている' do
+          OriginalPicture.should_receive(:show_json_opt).exactly(1)
+          get :new, :format => :json
+        end
+      end
     end
     context '作家権限がないとき' do
       before do
@@ -372,61 +519,86 @@ describe OriginalPicturesController do
           response.should render_template("artists/new")
         end
       end
+      context 'json形式' do
+        it '例外403 forbiddenを返す' do
+          lambda{
+          get :new, :format => :json
+          }.should raise_error(ActiveRecord::Forbidden)
+        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
-        OriginalPicture.any_instance.stub(:store).with(any_args()).and_return(true)
+        PettanImager.stub(:load).with("abc\ndef\nghi").and_return(@imager)
+        OriginalPicture.any_instance.stub(:store).with(@imager).and_return(true)
       end
-      it 'モデルに保存依頼する' do
-        OriginalPicture.any_instance.should_receive(:store).exactly(1)
-        post :create, :original_picture => Factory.attributes_for(:original_picture)
+      it '画像ライブラリをロードする' do
+        PettanImager.should_receive(:load).with(any_args()).exactly(1)
+        post :create, @attr
       end
-      it "@original_pictureに作成された原画を保持している" do
-        post :create, :original_picture => Factory.attributes_for(:original_picture)
-        assigns(:original_picture).should be_a(OriginalPicture)
+      it '原画モデルにデフォルト値補充を依頼している' do
+        OriginalPicture.any_instance.should_receive(:supply_default).with(any_args()).exactly(1)
+        post :create, @attr
+      end
+      it '原画モデルに上書き補充を依頼している' do
+        OriginalPicture.any_instance.should_receive(:overwrite).with(@artist).exactly(1)
+        post :create, @attr
+      end
+      it 'モデルに保存依頼する' do
+        OriginalPicture.any_instance.should_receive(:store).with(@imager).exactly(1)
+        post :create, @attr
       end
     end
     context 'つつがなく終わるとき' do
       before do
-        OriginalPicture.any_instance.stub(:store).with(any_args()).and_return {
-          assigns(:original_picture).attributes = Factory.attributes_for(:original_picture, :artist_id => @artist.id, :ext => 'jpeg')
-          assigns(:original_picture).save
-          true
-        }
+        PettanImager.stub(:load).with("abc\ndef\nghi").and_return(@imager)
       end
-      it "作成された原画がDBにある" do
-        post :create, :original_picture => Factory.attributes_for(:original_picture)
-        assigns(:original_picture).should_not be_a_new OriginalPicture
+      it "@original_pictureに作成された原画を保持している" do
+        post :create, @attr
+        assigns(:original_picture).should be_a(OriginalPicture)
       end
       context 'html形式' do
         it 'ステータスコード302 Foundを返す' do
-          post :create, :original_picture => Factory.attributes_for(:original_picture)
+          post :create, @attr
           response.status.should eq 302
         end
         it '作成された原画の表示ページへ遷移する' do
-          post :create, :original_picture => Factory.attributes_for(:original_picture)
+          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, :original_picture => Factory.attributes_for(:original_picture), :format => :json
+          post :create, @attr
           response.should be_success 
         end
         it '作成された原画をjsonデータで返す' do
-          post :create, :original_picture => Factory.attributes_for(:original_picture), :format => :json
+          post :create, @attr
           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
         end
+        it '原画モデルにjson単体出力オプションを問い合わせている' do
+          OriginalPicture.should_receive(:show_json_opt).exactly(1)
+          post :create, @attr
+        end
         it 'データがアレになっている' do
-          post :create, :original_picture => Factory.attributes_for(:original_picture, :ext => 'jpeg'), :format => :json
+          post :create, @attr
           json = JSON.parse response.body
-          json["ext"].should match(/jpeg/)
+          json["ext"].should match(/png/)
+          json["md5"].should be_true
+          json["artist_id"].should be_true
+          json["width"].should be_true
         end
       end
     end
@@ -436,21 +608,24 @@ describe OriginalPicturesController do
       end
       context 'html形式' do
         it 'ステータスコード302 Foundを返す' do
-          post :create, :original_picture => Factory.attributes_for(:original_picture)
+          post :create, @attr
           response.status.should eq 302
         end
         it 'サインインページへ遷移する' do
-          post :create, :original_picture => Factory.attributes_for(:original_picture)
+          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, :original_picture => Factory.attributes_for(:original_picture), :format => :json
+          post :create, @attr
           response.status.should eq 401
         end
         it '応答メッセージにUnauthorizedを返す' do
-          post :create, :original_picture => Factory.attributes_for(:original_picture), :format => :json
+          post :create, @attr
           response.message.should match(/Unauthorized/)
         end
       end
@@ -461,47 +636,54 @@ describe OriginalPicturesController do
       end
       context 'html形式' do
         it 'ステータスコード302 Foundを返す' do
-          post :create, :original_picture => Factory.attributes_for(:original_picture)
+          post :create, @attr
           response.status.should eq 302
         end
         it '絵師登録ページへ遷移する' do
-          post :create, :original_picture => Factory.attributes_for(:original_picture)
+          post :create, @attr
           response.should redirect_to new_artist_path
         end
       end
       context 'json形式' do
+        before do
+          @attr.merge!({:format => :json})
+        end
         it '例外403 forbiddenを返す' do
           lambda{
-            post :create, :original_picture => Factory.attributes_for(:original_picture), :format => :json
+            post :create, @attr
           }.should raise_error(ActiveRecord::Forbidden)
         end
       end
     end
     context '検証、保存に失敗した' do
       before do
-        OriginalPicture.any_instance.stub(:store).and_return(false)
+        PettanImager.stub(:load).with("abc\ndef\nghi").and_return(@imager)
+        OriginalPicture.any_instance.stub(:store).with(@imager).and_return(false)
       end
-      it "未保存のコミックを保持している" do
-        post :create, :original_picture => Factory.attributes_for(:original_picture)
+      it "未保存の原画を保持している" do
+        post :create, @attr
         assigns(:original_picture).should be_a_new(OriginalPicture)
       end
       context 'html形式' do
         it 'ステータスコード200 OKを返す' do
-          post :create, :original_picture => Factory.attributes_for(:original_picture)
+          post :create, @attr
           response.status.should eq 200
         end
         it '新規ページを描画する' do
-          post :create, :original_picture => Factory.attributes_for(:original_picture)
+          post :create, @attr
           response.should render_template("new")
         end
       end
       context 'json形式' do
+        before do
+          @attr.merge!({:format => :json})
+        end
         it 'ステータスコード422 unprocessable_entity を返す' do
-          post :create, :original_picture => Factory.attributes_for(:original_picture), :format => :json
+          post :create, @attr
           response.status.should eq 422
         end
         it '応答メッセージUnprocessable Entityを返す' do
-          post :create, :original_picture => Factory.attributes_for(:original_picture), :format => :json
+          post :create, @attr
           response.message.should match(/Unprocessable/)
         end
       end
@@ -510,7 +692,7 @@ describe OriginalPicturesController do
 
   describe '編集フォーム表示に於いて' do
     before do
-      @pic = Factory :original_picture, :artist_id => @artist.id
+      @pic = FactoryGirl.create :original_picture, :artist_id => @artist.id
       sign_in @user
       OriginalPicture.stub(:show).and_return(@pic)
     end
@@ -519,8 +701,8 @@ describe OriginalPicturesController do
         get :edit, :id => @pic.id
         response.should be_success 
       end
-      it '原画モデルに単体取得を問い合わせている' do
-        OriginalPicture.should_receive(:show).exactly(1)\r
+      it '原画モデルに編集取得を問い合わせている' do
+        OriginalPicture.should_receive(:edit).exactly(1)
         get :edit, :id => @pic.id
       end
       it '@original_pictureにデータを用意している' do
@@ -594,56 +776,60 @@ describe OriginalPicturesController do
 
   describe '更新に於いて' do
     before do
-      @pic = Factory :original_picture, :artist_id => @artist.id
-      OriginalPicture.stub(:edit).with(any_args()).and_return(@pic)
+      @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
-        OriginalPicture.any_instance.stub(:store).with(any_args()).and_return(true)
+        PettanImager.stub(:load).with("abc\ndef\nghi").and_return(@imager)
+        OriginalPicture.any_instance.stub(:store).with(@imager).and_return(true)
       end
-      it '原画モデルに単体取得を問い合わせている' do
-        OriginalPicture.should_receive(:edit).exactly(1)\r
-        put :update, :id => @pic.id, :original_picture => Factory.attributes_for(:original_picture)
+      it '画像ライブラリをロードする' do
+        PettanImager.should_receive(:load).with(any_args()).exactly(1)
+        put :update, :id => @op.id, :original_picture => @attr
       end
-      it 'モデルに更新を依頼する' do
-        OriginalPicture.any_instance.should_receive(:store).exactly(1)
-        put :update, :id => @pic.id, :original_picture => Factory.attributes_for(:original_picture)
+      it '原画モデルに編集取得を問い合わせている' do
+        OriginalPicture.should_receive(:edit).with(@op.id.to_s, @artist).exactly(1)
+        put :update, :id => @op.id, :original_picture => @attr
       end
-      it '@original_pictureにアレを取得している' do
-        put :update, :id => @pic.id, :original_picture => Factory.attributes_for(:original_picture)
-        assigns(:original_picture).should eq(@pic)
+      it '原画モデルに上書き補充を依頼している' do
+        OriginalPicture.any_instance.should_receive(:overwrite).with(@artist).exactly(1)
+        put :update, :id => @op.id, :original_picture => @attr
+      end
+      it 'モデルに更新を依頼する' do
+        OriginalPicture.any_instance.should_receive(:store).with(@imager).exactly(1)
+        put :update, :id => @op.id, :original_picture => @attr
       end
     end
     context 'つつがなく終わるとき' do
       before do
-        OriginalPicture.any_instance.stub(:store).with(any_args()).and_return {
-          assigns(:original_picture).attributes = Factory.attributes_for(:original_picture, :artist_id => @artist.id, :ext => 'jpeg')
-          assigns(:original_picture).save
-          true
-        }
+        PettanImager.stub(:load).with("abc\ndef\nghi").and_return(@imager)
       end
-      it '更新される' do
-        put :update, :id => @pic.id, :original_picture => Factory.attributes_for(:original_picture, :ext => 'jpeg')
-        OriginalPicture.find(@pic.id).ext.should eq 'jpeg'
+      it '@original_pictureにアレを取得している' do
+        put :update, :id => @op.id, :original_picture => @attr
+        assigns(:original_picture).should eq(@op)
       end
       context 'html形式' do
         it 'ステータスコード302 Foundを返す' do
-          put :update, :id => @pic.id, :original_picture => Factory.attributes_for(:original_picture)
+          put :update, :id => @op.id, :original_picture => @attr
           response.status.should eq 302
         end
         it '更新された原画の表示ページへ遷移する' do
-          put :update, :id => @pic.id, :original_picture => Factory.attributes_for(:original_picture)
+          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 => @pic.id, :original_picture => Factory.attributes_for(:original_picture), :format => :json
+          put :update, :id => @op.id, :original_picture => @attr, :format => :json
           response.should be_success 
         end
         it 'ページ本体は特に返さない' do
-          put :update, :id => @pic.id, :original_picture => Factory.attributes_for(:original_picture), :format => :json
+          put :update, :id => @op.id, :original_picture => @attr, :format => :json
           response.body.should match /./
         end
       end
@@ -654,21 +840,21 @@ describe OriginalPicturesController do
       end
       context 'html形式' do
         it 'ステータスコード302 Foundを返す' do
-          post :create, :original_picture => Factory.attributes_for(:original_picture)
+          put :update, :id => @op.id, :original_picture => @attr
           response.status.should eq 302
         end
         it 'サインインページへ遷移する' do
-          post :create, :original_picture => Factory.attributes_for(:original_picture)
+          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
-          post :create, :original_picture => Factory.attributes_for(:original_picture), :format => :json
+          put :update, :id => @op.id, :original_picture => @attr, :format => :json
           response.status.should eq 401
         end
         it '応答メッセージにUnauthorizedを返す' do
-          post :create, :original_picture => Factory.attributes_for(:original_picture), :format => :json
+          put :update, :id => @op.id, :original_picture => @attr, :format => :json
           response.message.should match(/Unauthorized/)
         end
       end
@@ -679,43 +865,44 @@ describe OriginalPicturesController do
       end
       context 'html形式' do
         it 'ステータスコード302 Foundを返す' do
-          post :create, :original_picture => Factory.attributes_for(:original_picture)
+          put :update, :id => @op.id, :original_picture => @attr
           response.status.should eq 302
         end
         it '絵師登録ページへ遷移する' do
-          post :create, :original_picture => Factory.attributes_for(:original_picture)
+          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{
-            post :create, :original_picture => Factory.attributes_for(:original_picture), :format => :json
+            put :update, :id => @op.id, :original_picture => @attr, :format => :json
           }.should raise_error(ActiveRecord::Forbidden)
         end
       end
     end
     context '検証、保存に失敗した' do
       before do
-        OriginalPicture.any_instance.stub(:store).and_return(false)
+        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 => @pic.id, :original_picture => Factory.attributes_for(:original_picture)
+          put :update, :id => @op.id, :original_picture => @attr
           response.status.should eq 200
         end
         it '編集ページを描画する' do
-          put :update, :id => @pic.id, :original_picture => Factory.attributes_for(:original_picture)
+          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 => @pic.id, :original_picture => Factory.attributes_for(:original_picture), :format => :json
+          put :update, :id => @op.id, :original_picture => @attr, :format => :json
           response.status.should eq 422
         end
         it '応答メッセージUnprocessable Entityを返す' do
-          put :update, :id => @pic.id, :original_picture => Factory.attributes_for(:original_picture), :format => :json
+          put :update, :id => @op.id, :original_picture => @attr, :format => :json
           response.message.should match(/Unprocessable/)
         end
       end