OSDN Git Service

pass model import test
[pettanr/pettanr.git] / spec / models / license_group_spec.rb
index fbf9f0f..96431fa 100644 (file)
@@ -8,6 +8,8 @@ describe LicenseGroup do
     @f = Rails.root + 'spec/json/license_group.json'
     @t = File.open(@f, 'r').read
     @j = JSON.parse @t
+    @fs = Rails.root + 'spec/json/license_groups.json'
+    @fes = Rails.root + 'spec/json/invalid_license_groups.json'
   end
   describe '検証に於いて' do
     before do
@@ -96,95 +98,122 @@ describe LicenseGroup do
     end
   end
   
+  describe '更新に於いて' do
+    before do
+      @n = @j.keys.first
+      @a = @j.values.first
+    end
+    context 'つつがなく終わるとき' do
+      it 'データ更新準備を依頼する' do
+        LicenseGroup.stub(:modify_object).with(any_args).and_return(LicenseGroup.new)
+        LicenseGroup.should_receive(:modify_object).with(any_args).exactly(1)
+        LicenseGroup.any_instance.stub(:save).with(any_args).and_return(true)
+        r = LicenseGroup.store(@n, @a)
+      end
+      it '保存を依頼する' do
+        LicenseGroup.stub(:modify_object).with(any_args).and_return(LicenseGroup.new)
+        LicenseGroup.any_instance.stub(:save).with(any_args).and_return(true)
+        LicenseGroup.any_instance.should_receive(:save).with(any_args).exactly(1)
+        r = LicenseGroup.store(@n, @a)
+      end
+      it 'オブジェクトを返す' do
+        r = LicenseGroup.store(@n, @a)
+        r.is_a?(LicenseGroup).should be_true
+        r.name.should eq @n
+        r.url.should eq @a["url"]
+      end
+    end
+  end
+  
   describe 'インポートに於いて' do
     before do
     end
     context 'つつがなく終わるとき' do
-      it 'ã\83\86ã\82­ã\82¹ã\83\88インポートを依頼する' do
-        CommonLicense.should_receive(:parse).with(any_args).exactly(1)
-        CommonLicense.stub(:parse).with(any_args).and_return(@j)
-        CommonLicense.import(@t)
+      it 'ã\83\95ã\82¡ã\82¤ã\83«インポートを依頼する' do
+        LicenseGroup.should_receive(:import_file).with(any_args).exactly(1)
+        LicenseGroup.stub(:import_file).with(any_args).and_return([])
+        LicenseGroup.import(@f)
       end
       it 'ライセンスグループ更新を一回依頼する' do
-        CommonLicense.stub(:store).with(any_args).and_return(CommonLicense.new)
-        CommonLicense.any_instance.stub(:valid?).with(any_args).and_return(true)
-        CommonLicense.should_receive(:store).with(any_args).exactly(1)
-        CommonLicense.import(@t)
+        LicenseGroup.stub(:store).with(any_args).and_return(LicenseGroup.new)
+        LicenseGroup.should_receive(:store).with(any_args).exactly(1)
+        LicenseGroup.import(@f)
       end
       it 'ライセンスグループが追加される' do
         lambda {
-          CommonLicense.import(@t)
-        }.should change CommonLicense, :count
+          LicenseGroup.import(@f)
+        }.should change LicenseGroup, :count
       end
       it '[]を返す' do
-        CommonLicense.import(@t).should eq []
+        r = LicenseGroup.import(@f)
+        r.should eq []
       end
     end
     context '複数データがつつがなく終わるとき' do
       it 'ライセンスグループ更新を二回依頼する' do
-        CommonLicense.stub(:store).with(any_args).and_return(CommonLicense.new)
-        CommonLicense.any_instance.stub(:valid?).with(any_args).and_return(true)
-        CommonLicense.should_receive(:store).with(any_args).exactly(2)
-        CommonLicense.import(@ts)
+        LicenseGroup.stub(:store).with(any_args).and_return(LicenseGroup.new)
+        LicenseGroup.should_receive(:store).with(any_args).exactly(2)
+        LicenseGroup.import(@fs)
       end
       it 'ライセンスグループが二個追加される' do
         lambda {
-          CommonLicense.import(@ts)
-        }.should change(CommonLicense, :count).by 2
+          r = LicenseGroup.import(@fs)
+        }.should change(LicenseGroup, :count).by 2
       end
       it '[]を返す' do
-        CommonLicense.import(@ts).should eq []
+        r = LicenseGroup.import(@fs)
+        r.should eq []
       end
     end
-    context 'ã\82³ã\83¢ã\83³ã\83©ã\82¤ã\82»ã\83³ã\82¹作成に失敗したとき' do
+    context 'ã\83©ã\82¤ã\82»ã\83³ã\82¹ã\82°ã\83«ã\83¼ã\83\97作成に失敗したとき' do
       before do
-        CommonLicense.any_instance.stub(:save).with(any_args).and_return(false)
-        CommonLicense.any_instance.stub(:valid?).with(any_args).and_return(false)
+        LicenseGroup.any_instance.stub(:save).with(any_args).and_return(false)
+        LicenseGroup.any_instance.stub(:valid?).with(any_args).and_return(false)
       end
-      it 'ã\82³ã\83¢ã\83³ã\83©ã\82¤ã\82»ã\83³ã\82¹の数に変化がない' do
+      it 'ã\83©ã\82¤ã\82»ã\83³ã\82¹ã\82°ã\83«ã\83¼ã\83\97の数に変化がない' do
         lambda {
-          CommonLicense.import(@t)
-        }.should_not change CommonLicense, :count
+          LicenseGroup.import(@f)
+        }.should_not change LicenseGroup, :count
       end
       it '配列を返す' do
-        r = CommonLicense.import(@t)
+        r = LicenseGroup.import(@f)
         r.is_a?(Array).should be_true
       end
       it '配列の中身は一件' do
-        r = CommonLicense.import(@t)
+        r = LicenseGroup.import(@f)
         r.should have(1).items
       end
-      it 'ã\82³ã\83¢ã\83³ã\83©ã\82¤ã\82»ã\83³ã\82¹オブジェクトが入っている' do
-        r = CommonLicense.import(@t)
-        r.first.is_a?(CommonLicense).should be_true
+      it 'ã\83©ã\82¤ã\82»ã\83³ã\82¹ã\82°ã\83«ã\83¼ã\83\97オブジェクトが入っている' do
+        r = LicenseGroup.import(@f)
+        r.first.is_a?(LicenseGroup).should be_true
       end
     end
-    context 'è¤\87æ\95°ã\81®ã\82³ã\83¢ã\83³ã\83©ã\82¤ã\82»ã\83³ã\82¹作成に失敗したとき' do
+    context 'è¤\87æ\95°ã\81®ã\83©ã\82¤ã\82»ã\83³ã\82¹ã\82°ã\83«ã\83¼ã\83\97作成に失敗したとき' do
       #三件中、二件の失敗、一件を成功させ、成功データは戻り値に含まないことを確認する
-      it 'ã\82³ã\83¢ã\83³ã\83©ã\82¤ã\82»ã\83³ã\82¹の数に変化がない' do
+      it 'ã\83©ã\82¤ã\82»ã\83³ã\82¹ã\82°ã\83«ã\83¼ã\83\97の数に変化がない' do
         lambda {
-          CommonLicense.import(@tes)
-        }.should_not change CommonLicense, :count
+          LicenseGroup.import(@fes)
+        }.should_not change LicenseGroup, :count
       end
       it '途中で保存に失敗しても全件更新依頼する' do
-        CommonLicense.stub(:store).with(any_args).and_return(CommonLicense.new)
-        CommonLicense.should_receive(:store).with(any_args).exactly(3)
-        CommonLicense.import(@tes)
+        LicenseGroup.stub(:store).with(any_args).and_return(LicenseGroup.new)
+        LicenseGroup.should_receive(:store).with(any_args).exactly(3)
+        LicenseGroup.import(@fes)
       end
       it '配列を返す' do
-        r = CommonLicense.import(@tes)
+        r = LicenseGroup.import(@fes)
         r.is_a?(Array).should be_true
       end
       it '配列の中身は2件' do
-        r = CommonLicense.import(@tes)
+        r = LicenseGroup.import(@fes)
         r.should have(2).items
       end
-      it 'é\85\8då\88\97ã\81®ä¸­èº«ã\81¯å¤±æ\95\97ã\81\97ã\81\9fã\82³ã\83¢ã\83³ã\83©ã\82¤ã\82»ã\83³ã\82¹オブジェクトが入っている' do
-        r = CommonLicense.import(@tes)
-        r[0].is_a?(CommonLicense).should be_true
-        r[0]["name"].should eq 'fail1'
-        r[1].is_a?(CommonLicense).should be_true
-        r[1]["name"].should eq 'fail2'
+      it 'é\85\8då\88\97ã\81®ä¸­èº«ã\81¯å¤±æ\95\97ã\81\97ã\81\9fã\83©ã\82¤ã\82»ã\83³ã\82¹ã\82°ã\83«ã\83¼ã\83\97オブジェクトが入っている' do
+        r = LicenseGroup.import(@fes)
+        r[0].is_a?(LicenseGroup).should be_true
+        r[0]["name"].should eq 'UnknownUrl'
+        r[1].is_a?(LicenseGroup).should be_true
+        r[1]["name"].should eq 'UnknownClassname'
       end
     end
   end