OSDN Git Service

t#29312:any update
[pettanr/pettanr.git] / spec / models / artist_spec.rb
index b1b088b..f7797cf 100644 (file)
@@ -17,17 +17,17 @@ describe Artist do
     end
     
     it 'オーソドックスなデータなら通る' do
-      @artist = FactoryGirl.build :artist, :author_id => @author.id, :default_license_id => @license.id
+      @artist = FactoryGirl.build :artist, :author_id => @author.id
       @artist.should be_valid
     end
     
     context 'nameを検証するとき' do
       it 'nullなら失敗する' do
-        @artist = FactoryGirl.build :artist, :author_id => @author.id, :default_license_id => @license.id, :name => nil
+        @artist = FactoryGirl.build :artist, :author_id => @author.id, :name => nil
         @artist.should_not be_valid
       end
       it '30文字以上なら失敗する' do
-        @artist = FactoryGirl.build :artist, :author_id => @author.id, :default_license_id => @license.id, :name => 'a'*31
+        @artist = FactoryGirl.build :artist, :author_id => @author.id, :name => 'a'*31
         @artist.should_not be_valid
       end
     end
@@ -43,7 +43,7 @@ describe Artist do
   
   describe '単体取得に於いて' do
     before do
-      @artist = FactoryGirl.create :artist, :author_id => @author.id, :default_license_id => @license.id
+      @artist = FactoryGirl.create :artist, :author_id => @author.id
     end
     it '指定の絵師を返す' do
       a = Artist.show @artist.id
@@ -62,9 +62,34 @@ describe Artist do
       end
     end
   end
+  describe '編集取得に於いて' do
+    before do
+      @artist = FactoryGirl.create :artist, :author_id => @author.id
+    end
+    it '指定の絵師を返す' do
+      Artist.any_instance.stub(:own?).and_return(true)
+      r = Artist.edit @artist.id, @author.id
+      r.should eq @artist
+    end
+    context '他人の絵師を開こうとしたとき' do
+      it '403Forbidden例外を返す' do
+        Artist.any_instance.stub(:own?).and_return(false)
+        lambda{
+          Artist.edit @artist.id, @author
+        }.should raise_error(ActiveRecord::Forbidden)
+      end
+    end
+    context '存在しない絵師を開こうとしたとき' do
+      it '404RecordNotFound例外を返す' do
+        lambda{
+          Artist.edit 110, @author
+        }.should raise_error(ActiveRecord::RecordNotFound)
+      end
+    end
+  end
   describe '一覧取得に於いて' do
     before do
-      @artist = FactoryGirl.create :artist, :author_id => @author.id, :default_license_id => @license.id
+      @artist = FactoryGirl.create :artist, :author_id => @author.id
     end
     context 'page補正について' do
       it '文字列から数値に変換される' do