OSDN Git Service

t#28985:add credit
[pettanr/pettanr.git] / spec / controllers / resource_pictures_controller_spec.rb
index f5f7547..fa42389 100644 (file)
@@ -276,4 +276,89 @@ describe ResourcePicturesController do
     end
   end
 
+  describe 'クレジット表示に於いて' do\r
+    before do\r
+      @p = Factory :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
+      @pic = Factory :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id
+      sign_in @user
+      ResourcePicture.stub(:show).and_return(@pic)
+    end\r
+    context 'つつがなく終わるとき' do\r
+      it 'ステータスコード200 OKを返す' do\r
+        get :credit, :id => @pic.id\r
+        response.should be_success\r
+      end\r
+      it '素材モデルに単体取得を問い合わせている' do\r
+        ResourcePicture.should_receive(:show).exactly(1)\r
+        get :credit, :id => @pic.id\r
+      end\r
+      it '@resource_pictureにアレを取得している' do\r
+        get :credit, :id => @pic.id\r
+        assigns(:resource_picture).id.should eq(@pic.id)\r
+      end\r
+      context 'html形式' do\r
+        it 'creditテンプレートを描画する' do\r
+          get :credit, :id => @pic.id\r
+          response.should render_template("credit")\r
+        end\r
+      end\r
+      context 'json形式' do\r
+        it 'jsonデータを返す' do\r
+          get :credit, :id => @pic.id, :format => :json\r
+          lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)\r
+        end\r
+        it 'データがアレになっている' do\r
+          get :credit, :id => @pic.id, :format => :json\r
+          json = JSON.parse response.body\r
+          json["ext"].should match(/png/)\r
+        end\r
+      end\r
+    end\r
+    context '作家権限がないとき' do\r
+      before do\r
+        sign_out @user\r
+      end\r
+      context 'html形式' do\r
+        it 'ステータスコード302 Foundを返す' do\r
+          get :credit, :id => @pic.id\r
+          response.status.should eq 302\r
+        end\r
+        it 'サインインページへ遷移する' do\r
+          get :credit, :id => @pic.id\r
+          response.body.should redirect_to '/users/sign_in'\r
+        end\r
+      end\r
+      context 'json形式' do\r
+        it 'ステータスコード401 Unauthorizedを返す' do\r
+          get :credit, :id => @pic.id, :format => :json\r
+          response.status.should eq 401\r
+        end\r
+        it '応答メッセージにUnauthorizedを返す' do\r
+          get :credit, :id => @pic.id, :format => :json\r
+          response.message.should match(/Unauthorized/)\r
+        end\r
+      end\r
+    end\r
+=begin\r
+    context '対象素材がないとき' do\r
+      before do\r
+        ResourcePicture.unstub(:show)\r
+      end\r
+      context 'html形式' do\r
+        it '例外404 not_foundを返す' do\r
+          lambda{\r
+            get :show, :id => 0\r
+          }.should raise_error(ActiveRecord::RecordNotFound)\r
+        end\r
+      end\r
+      context 'json形式' do\r
+        it '例外404 not_foundを返す' do\r
+          lambda{ \r
+            get :show, :id => 0, :format => :json\r
+          }.should raise_error(ActiveRecord::RecordNotFound)\r
+        end\r
+      end\r
+    end\r
+=end\r
+  end\r
 end