OSDN Git Service

t#30322:create provider license import func
[pettanr/pettanr.git] / spec / models / license_spec.rb
index a81390f..e0dafd4 100644 (file)
@@ -32,14 +32,14 @@ describe License do
         @l.license_group_id = ''
         @l.should_not be_valid
       end
-      it '数値でなければ失敗する' do\r
-        @l.license_group_id = 'a'\r
-        @l.should_not be_valid\r
-      end\r
-      it '存在するライセンスグループでなければ失敗する' do\r
-        @l.license_group_id = 0\r
-        @l.should_not be_valid\r
-      end\r
+      it '数値でなければ失敗する' do
+        @l.license_group_id = 'a'
+        @l.should_not be_valid
+      end
+      it '存在するライセンスグループでなければ失敗する' do
+        @l.license_group_id = 0
+        @l.should_not be_valid
+      end
     end
     context 'nameを検証するとき' do
       it 'nullなら失敗する' do
@@ -75,8 +75,8 @@ describe License do
         @l.should_not be_valid
       end
       it 'url形式でないなら失敗する' do
-        @l.url = 'a'*200\r
-        @l.should_not be_valid\r
+        @l.url = 'a'*200
+        @l.should_not be_valid
       end
     end
     context 'system_picture_idを検証するとき' do
@@ -84,14 +84,14 @@ describe License do
         @l.system_picture_id = ''
         @l.should_not be_valid
       end
-      it '数値でなければ失敗する' do\r
-        @l.system_picture_id = 'a'\r
-        @l.should_not be_valid\r
-      end\r
-      it '存在するシステム画像でなければ失敗する' do\r
-        @l.system_picture_id = 0\r
-        @l.should_not be_valid\r
-      end\r
+      it '数値でなければ失敗する' do
+        @l.system_picture_id = 'a'
+        @l.should_not be_valid
+      end
+      it '存在するシステム画像でなければ失敗する' do
+        @l.system_picture_id = 0
+        @l.should_not be_valid
+      end
     end
   end
   
@@ -124,13 +124,13 @@ describe License do
       @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
+    context 'つつがなく終わるとき' do
+      it '一覧取得オプションを利用している' do
+        License.stub(:list_opt).with(any_args).and_return({})
+        License.should_receive(:list_opt).with(any_args).exactly(1)
         r = License.list
-      end\r
-    end\r
+      end
+    end
     it 'リストを返す' do
       l = License.list 
       l.should eq [@l]
@@ -176,24 +176,24 @@ describe License do
       @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
+    context 'つつがなく終わるとき' do
+      it '単体取得オプションを利用している' do
+        License.stub(:show_opt).with(any_args).and_return({})
+        License.should_receive(:show_opt).with(any_args).exactly(1)
         r = License.show @l.id
-      end\r
-    end\r
+      end
+    end
     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
+    context '存在しないライセンスを開こうとしたとき' do
+      it '404RecordNotFound例外を返す' do
+        lambda{
+          License.show 110
+        }.should raise_error(ActiveRecord::RecordNotFound)
+      end
+    end
   end
   describe '単体取得オプションに於いて' do
     it 'includeキーを含んでいる' do
@@ -341,4 +341,21 @@ 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
+      @l2 = FactoryGirl.create :license, :name => 'l2[old ls]', :url => @l.url+'2', :license_group_id => @lg.id, :system_picture_id => @sp.id, :updated_at => Time.now - 3000
+    end
+    it '開始日時が省略された場合はすべてのライセンスを返す' do
+      r = License.export 
+      r.should eq [@l, @l2]
+    end
+    it '開始日時以降に更新されたライセンスを返す' do
+      r = License.export @l.updated_at - 100
+      r.should eq [@l]
+    end
+  end
+  
 end