OSDN Git Service

t#30322:create provider license import func
[pettanr/pettanr.git] / spec / models / license_spec.rb
index b6b2ccb..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]
@@ -142,7 +142,7 @@ describe License do
       l.should eq [@l3, @l, @l2]
     end
   end
-  describe 'list関連テーブルプションに於いて' do
+  describe '一覧取得オプションに於いて' do
     it 'includeキーを含んでいる' do
       r = License.list_opt
       r.has_key?(:include).should be_true
@@ -157,17 +157,16 @@ describe License do
     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
+    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
-      r = License.list_json_opt[:include]
-      r.has_key?(:license_group).should be_true
+      r = License.list.to_json License.list_json_opt
+      j = JSON.parse r
+      i = j.first
+      i.has_key?('license_group').should be_true
     end
   end
   
@@ -177,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
@@ -211,17 +210,16 @@ describe License do
     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
+    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
-      r = License.show_json_opt[:include]
-      r.has_key?(:license_group).should be_true
+      r = License.show(@l.id).to_json License.show_json_opt
+      j = JSON.parse r
+      i = j
+      i.has_key?('license_group').should be_true
     end
   end
   
@@ -265,6 +263,9 @@ describe License do
         r.is_a?(License).should be_true
         r.name.should eq @ln
         r.url.should eq @la["url"]
+        cp = JSON.parse r.credit_pictures
+        cp['a_picture_id'].should_not be_nil
+        cp['b_picture_id'].should_not be_nil
       end
       it 'ライセンスが作成されている' do
         lambda {
@@ -340,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