OSDN Git Service

t#29678:test broken.fix op model
[pettanr/pettanr.git] / spec / models / license_spec.rb
index 5f7f4d0..b6b2ccb 100644 (file)
@@ -12,15 +12,22 @@ describe License do
       @l = FactoryGirl.build :license, :license_group_id => @lg.id, :system_picture_id => @sp.id
     end
     
-    it 'オーソドックスなデータなら通る' do
-      @l.should be_valid
+    context 'オーソドックスなデータのとき' do
+      it '下限データが通る' do
+        @l.name = 'a'
+        @l.caption = 'a'
+        @l.url = 'http://test.jp/'
+        @l.should be_valid
+      end
+      it '上限データが通る' do
+        @l.name = 'a'*50
+        @l.caption = 'a'*30
+        @l.url = 'http://test.jp/aaaaa' + 'a' * 180
+        @l.should be_valid
+      end
     end
     
     context 'license_group_idを検証するとき' do
-      it 'テストデータの確認' do\r
-        @l.license_group_id = @lg.id\r
-        @l.should be_valid\r
-      end\r
       it 'nullなら失敗する' do
         @l.license_group_id = ''
         @l.should_not be_valid
@@ -35,10 +42,6 @@ describe License do
       end\r
     end
     context 'nameを検証するとき' do
-      it 'テストデータの確認' do\r
-        @l.name = 'a'*50\r
-        @l.should be_valid\r
-      end\r
       it 'nullなら失敗する' do
         @l.name = ''
         @l.should_not be_valid
@@ -53,10 +56,6 @@ describe License do
       end
     end
     context 'captionを検証するとき' do
-      it 'テストデータの確認' do\r
-        @l.caption = 'a'*30\r
-        @l.should be_valid\r
-      end\r
       it 'nullなら失敗する' do
         @l.caption = ''
         @l.should_not be_valid
@@ -67,11 +66,6 @@ describe License do
       end
     end
     context 'urlを検証するとき' do
-      it 'テストデータの確認' do\r
-        @l.url = 'http://test.jp/aaaaa' + 'a' * 180
-        @l.save!\r
-        @l.should be_valid\r
-      end\r
       it 'nullなら失敗する' do
         @l.url = ''
         @l.should_not be_valid
@@ -80,16 +74,12 @@ describe License do
         @l.url = 'http://test.jp/aaaaa' + 'a' * 181
         @l.should_not be_valid
       end
-      it 'url形式でなら失敗する' do
+      it 'urlå½¢å¼\8fã\81§ã\81ªã\81\84ã\81ªã\82\89失æ\95\97ã\81\99ã\82\8b' do
         @l.url = 'a'*200\r
         @l.should_not be_valid\r
       end
     end
     context 'system_picture_idを検証するとき' do
-      it 'テストデータの確認' do\r
-        @l.system_picture_id = @sp.id\r
-        @l.should be_valid\r
-      end\r
       it 'nullなら失敗する' do
         @l.system_picture_id = ''
         @l.should_not be_valid
@@ -105,6 +95,136 @@ describe License do
     end
   end
   
+  describe 'デフォルト値補充に於いて' do
+    it 'defined' do
+      @sp = FactoryGirl.create :system_picture
+      @lg = FactoryGirl.create :license_group
+      @l = FactoryGirl.build :license, :name => 'peta2.0', :license_group_id => @lg.id, :system_picture_id => @sp.id
+      @l.supply_default
+    end
+  end
+  
+  describe '上書き補充に於いて' do
+    it 'defined' do
+      @sp = FactoryGirl.create :system_picture
+      @lg = FactoryGirl.create :license_group
+      @l = FactoryGirl.build :license, :name => 'peta2.0', :license_group_id => @lg.id, :system_picture_id => @sp.id
+      @l.overwrite
+    end
+  end
+  
+  describe '閲覧許可に於いて' do
+    #ライセンスは作家作成する前から存在するので、閲覧制限の意味がない
+  end
+  
+  describe '一覧取得に於いて' do
+    before do
+      @sp = FactoryGirl.create :system_picture
+      @lg = FactoryGirl.create :license_group
+      @l = FactoryGirl.create :license, :name => 'peta2.0', :license_group_id => @lg.id, :system_picture_id => @sp.id
+      @lg2 = FactoryGirl.create :license_group, :name => 'pubdm'
+    end
+    context 'つつがなく終わるとき' do\r
+      it '一覧取得オプションを利用している' do\r
+        License.stub(:list_opt).with(any_args).and_return({})\r
+        License.should_receive(:list_opt).with(any_args).exactly(1)\r
+        r = License.list
+      end\r
+    end\r
+    it 'リストを返す' do
+      l = License.list 
+      l.should eq [@l]
+    end
+    it '名前順で並んでいる' do
+      @l2 = FactoryGirl.create :license, :name => 'peta3.0', :url => 'http://pe.ta/3.0', :license_group_id => @lg.id, :system_picture_id => @sp.id
+      @l3 = FactoryGirl.create :license, :name => 'pd1.0', :url => 'http://pb.dm/1.0', :license_group_id => @lg2.id, :system_picture_id => @sp.id
+      l = License.list
+      l.should eq [@l3, @l, @l2]
+    end
+  end
+  describe 'list関連テーブルプションに於いて' do
+    it 'includeキーを含んでいる' do
+      r = License.list_opt
+      r.has_key?(:include).should be_true
+    end
+    it '1つの項目を含んでいる' do
+      r = License.list_opt[:include]
+      r.should have(1).items
+    end
+    it 'ライセンスグループを含んでいる' do
+      r = License.list_opt[:include]
+      r.has_key?(:license_group).should be_true
+    end
+  end
+  describe 'json一覧出力オプションに於いて' do
+    it 'includeキーを含んでいる' do
+      r = License.list_json_opt
+      r.has_key?(:include).should be_true
+    end
+    it '1つの項目を含んでいる' do
+      r = License.list_json_opt[:include]
+      r.should have(1).items
+    end
+    it 'ライセンスグループを含んでいる' do
+      r = License.list_json_opt[:include]
+      r.has_key?(:license_group).should be_true
+    end
+  end
+  
+  describe '単体取得に於いて' do
+    before do
+      @sp = FactoryGirl.create :system_picture
+      @lg = FactoryGirl.create :license_group
+      @l = FactoryGirl.create :license, :license_group_id => @lg.id, :system_picture_id => @sp.id
+    end
+    context 'つつがなく終わるとき' do\r
+      it '単体取得オプションを利用している' do\r
+        License.stub(:show_opt).with(any_args).and_return({})\r
+        License.should_receive(:show_opt).with(any_args).exactly(1)\r
+        r = License.show @l.id
+      end\r
+    end\r
+    it '指定のライセンスを返す' do
+      l = License.show @l.id
+      l.should eq @l
+    end
+    context '存在しないライセンスを開こうとしたとき' do\r
+      it '404RecordNotFound例外を返す' do\r
+        lambda{\r
+          License.show 110\r
+        }.should raise_error(ActiveRecord::RecordNotFound)\r
+      end\r
+    end\r
+  end
+  describe '単体取得オプションに於いて' do
+    it 'includeキーを含んでいる' do
+      r = License.show_opt
+      r.has_key?(:include).should be_true
+    end
+    it '1つの項目を含んでいる' do
+      r = License.show_opt[:include]
+      r.should have(1).items
+    end
+    it 'ライセンスグループを含んでいる' do
+      r = License.show_opt[:include]
+      r.has_key?(:license_group).should be_true
+    end
+  end
+  describe 'json単体出力オプションに於いて' do
+    it 'includeキーを含んでいる' do
+      r = License.show_json_opt
+      r.has_key?(:include).should be_true
+    end
+    it '1つの項目を含んでいる' do
+      r = License.show_json_opt[:include]
+      r.should have(1).items
+    end
+    it 'ライセンスグループを含んでいる' do
+      r = License.show_json_opt[:include]
+      r.has_key?(:license_group).should be_true
+    end
+  end
+  
   describe '更新に於いて' do
     before do
       @lg = FactoryGirl.create :license_group
@@ -220,90 +340,4 @@ describe License do
     end
   end
   
-  describe '単体取得に於いて' do
-    before do
-      @sp = FactoryGirl.create :system_picture
-      @lg = FactoryGirl.create :license_group
-      @l = FactoryGirl.create :license, :license_group_id => @lg.id, :system_picture_id => @sp.id
-    end
-    it '指定のコマを返す' do
-      l = License.show @l.id
-      l.should eq @l
-    end
-  end
-  describe '関連テーブルプションに於いて' do
-    context 'オプションがないとき' do
-      it 'ライセンスグループを含んでいる' do
-        r = License.show_include_opt
-        r.should eq [:license_group]
-      end
-    end
-    context 'オプションで素材ライセンスを含ませたとき' do
-      it 'ライセンスグループと素材ライセンスを含んでいる' do
-        r = License.show_include_opt(:include => :resource_picture_license)
-        r.should eq [:license_group, :resource_picture_license]
-      end
-    end
-  end
-  describe 'json単体出力オプションに於いて' do
-    it 'includeキーを含んでいる' do
-      r = License.show_json_include_opt
-      r.has_key?(:include).should be_true
-    end
-    it '1つの項目を含んでいる' do
-      r = License.show_json_include_opt[:include]
-      r.should have(1).items
-    end
-    it 'ライセンスグループを含んでいる' do
-      r = License.show_json_include_opt[:include]
-      r.has_key?(:license_group).should be_true
-    end
-  end
-  describe '一覧取得に於いて' do
-    before do
-      @sp = FactoryGirl.create :system_picture
-      @lg = FactoryGirl.create :license_group
-      @l = FactoryGirl.create :license, :name => 'peta2.0', :license_group_id => @lg.id, :system_picture_id => @sp.id
-      @lg2 = FactoryGirl.create :license_group, :name => 'pubdm'
-    end
-    it 'リストを返す' do
-      l = License.list 
-      l.should eq [@l]
-    end
-    it '名前順で並んでいる' do
-      @l2 = FactoryGirl.create :license, :name => 'peta3.0', :url => 'http://pe.ta/3.0', :license_group_id => @lg.id, :system_picture_id => @sp.id
-      @l3 = FactoryGirl.create :license, :name => 'pd1.0', :url => 'http://pb.dm/1.0', :license_group_id => @lg2.id, :system_picture_id => @sp.id
-      l = License.list
-      l.should eq [@l3, @l, @l2]
-    end
-  end
-  describe 'list関連テーブルプションに於いて' do
-    it 'includeキーを含んでいる' do
-      r = License.list_opt
-      r.has_key?(:include).should be_true
-    end
-    it '1つの項目を含んでいる' do
-      r = License.list_opt[:include]
-      r.should have(1).items
-    end
-    it 'ライセンスグループを含んでいる' do
-      r = License.list_opt[:include]
-      r.has_key?(:license_group).should be_true
-    end
-  end
-  describe 'json一覧出力オプションに於いて' do
-    it 'includeキーを含んでいる' do
-      r = License.list_json_opt
-      r.has_key?(:include).should be_true
-    end
-    it '1つの項目を含んでいる' do
-      r = License.list_json_opt[:include]
-      r.should have(1).items
-    end
-    it 'ライセンスグループを含んでいる' do
-      r = License.list_json_opt[:include]
-      r.has_key?(:license_group).should be_true
-    end
-  end
-  
 end