OSDN Git Service

t#29688:change owner permission
[pettanr/pettanr.git] / spec / models / original_picture_spec.rb
index 7c82cbf..15995fc 100644 (file)
@@ -155,14 +155,28 @@ describe OriginalPicture do
   
   describe '作者判定に於いて' do
     before do
+      @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
+    end
+    context 'パラメータが作家のとき' do
+      it '自作の原画ならyes' do
+        @op.own?(@author).should == true
+      end
+      it '他人のならno' do
+        @op.own?(@other_author).should == false
+      end
     end
-    it '自作の原画ならyes' do
-      op = FactoryGirl.create :original_picture, :artist_id => @artist.id
-      op.own?(@artist).should == true
+    context 'パラメータが絵師のとき' do
+      it '自作の原画ならyes' do
+        @op.own?(@artist).should == true
+      end
+      it '他人のならno' do
+        @op.own?(@other_artist).should == false
+      end
     end
-    it '他人のならno' do
-      op = FactoryGirl.create :original_picture, :artist_id => @other_artist.id
-      op.own?(@artist).should == false
+    context 'それ以外のとき' do
+      it 'no' do
+        @op.own?(nil).should == false
+      end
     end
   end
   
@@ -221,10 +235,10 @@ describe OriginalPicture do
     before do
       @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
       OriginalPicture.any_instance.stub(:url).and_return('/original_pictures/3.gif')
-      ResourcePicture.stub(:fix_size_both).with(any_args).and_return([40, 30])
+      PettanImager.stub(:thumbnail_size).with(any_args).and_return([40, 30])
     end
     it 'サムネイル画像の幅高さ取得を依頼している' do
-      ResourcePicture.should_receive(:fix_size_both).with(any_args).exactly(1)
+      PettanImager.should_receive(:thumbnail_size).with(any_args).exactly(1)
       @op.opt_img_tag
     end
     it '戻り値はHashで返す' do
@@ -278,7 +292,7 @@ describe OriginalPicture do
       end
     end
   end
-  describe 'list関連テーブルプションに於いて' do
+  describe '一覧取得オプションに於いて' do
     it 'includeキーを含んでいる' do
       r = OriginalPicture.list_opt
       r.has_key?(:include).should be_true
@@ -297,21 +311,26 @@ describe OriginalPicture do
     end
   end
   describe 'json一覧出力オプションに於いて' do
-    it 'includeキーを含んでいる' do
-      r = OriginalPicture.list_json_opt
-      r.has_key?(:include).should be_true
-    end
-    it '2つの項目を含んでいる' do
-      r = OriginalPicture.list_json_opt[:include]
-      r.should have(2).items
+    before do
+      @op = FactoryGirl.create :original_picture, :artist_id => @artist.id\r
+      @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id\r
+      @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id\r
+      @sbt = FactoryGirl.create :speech_balloon_template\r
+      @comic = FactoryGirl.create :comic, :author_id => @author.id, :visible => 1
+      @panel = FactoryGirl.create :panel, :author_id => @author.id, :publish => 1
+      @story = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id
     end
     it '素材を含んでいる' do
-      r = OriginalPicture.list_json_opt[:include]
-      r.has_key?(:resource_picture).should be_true
+      r = OriginalPicture.mylist(@artist).to_json OriginalPicture.list_json_opt
+      j = JSON.parse r
+      i = j.first
+      i.has_key?('resource_picture').should be_true
     end
     it '実素材を含んでいる' do
-      r = OriginalPicture.list_json_opt[:include]
-      r.has_key?(:pictures).should be_true
+      r = OriginalPicture.mylist(@artist).to_json OriginalPicture.list_json_opt
+      j = JSON.parse r
+      i = j.first
+      i.has_key?('pictures').should be_true
     end
   end
   
@@ -376,6 +395,7 @@ describe OriginalPicture do
         @op3 = FactoryGirl.create :original_picture, :artist_id => @artist.id, :updated_at => Time.now + 200
         @op4 = FactoryGirl.create :original_picture, :artist_id => @artist.id, :updated_at => Time.now + 300
         @op5 = FactoryGirl.create :original_picture, :artist_id => @artist.id, :updated_at => Time.now + 400
+        OriginalPicture.stub(:default_page_size).and_return(2)\r
       end
       it '通常は全件(5件)を返す' do
         r = OriginalPicture.mylist @artist, 5, 0
@@ -481,7 +501,7 @@ describe OriginalPicture do
       end
     end
   end
-  describe 'å\8d\98ä½\93å\87ºå\8a\9bオプションに於いて' do
+  describe 'å\8d\98ä½\93å\8f\96å¾\97オプションに於いて' do
     it 'includeキーを含んでいる' do
       r = OriginalPicture.show_opt
       r.has_key?(:include).should be_true
@@ -500,21 +520,26 @@ describe OriginalPicture do
     end
   end
   describe 'json単体出力オプションに於いて' do
-    it 'includeキーを含んでいる' do
-      r = OriginalPicture.show_json_opt
-      r.has_key?(:include).should be_true
-    end
-    it '2つの項目を含んでいる' do
-      r = OriginalPicture.show_json_opt[:include]
-      r.should have(2).items
+    before do
+      @op = FactoryGirl.create :original_picture, :artist_id => @artist.id\r
+      @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id\r
+      @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id\r
+      @sbt = FactoryGirl.create :speech_balloon_template\r
+      @comic = FactoryGirl.create :comic, :author_id => @author.id, :visible => 1
+      @panel = FactoryGirl.create :panel, :author_id => @author.id, :publish => 1
+      @story = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id
     end
     it '素材を含んでいる' do
-      r = OriginalPicture.show_json_opt[:include]
-      r.has_key?(:resource_picture).should be_true
+      r = OriginalPicture.show(@op.id, @artist).to_json OriginalPicture.show_json_opt
+      j = JSON.parse r
+      i = j
+      i.has_key?('resource_picture').should be_true
     end
     it '実素材を含んでいる' do
-      r = OriginalPicture.show_json_opt[:include]
-      r.has_key?(:pictures).should be_true
+      r = OriginalPicture.show(@op.id, @artist).to_json OriginalPicture.show_json_opt
+      j = JSON.parse r
+      i = j
+      i.has_key?('pictures').should be_true
     end
   end
   describe '作成・更新に於いて' do