OSDN Git Service

miss edit
[pettanr/pettanr.git] / spec / models / license_group_spec.rb
index ebf426e..fbf9f0f 100644 (file)
@@ -96,4 +96,97 @@ describe LicenseGroup do
     end
   end
   
+  describe 'インポートに於いて' do
+    before do
+    end
+    context 'つつがなく終わるとき' do
+      it 'テキストインポートを依頼する' do
+        CommonLicense.should_receive(:parse).with(any_args).exactly(1)
+        CommonLicense.stub(:parse).with(any_args).and_return(@j)
+        CommonLicense.import(@t)
+      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)
+      end
+      it 'ライセンスグループが追加される' do
+        lambda {
+          CommonLicense.import(@t)
+        }.should change CommonLicense, :count
+      end
+      it '[]を返す' do
+        CommonLicense.import(@t).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)
+      end
+      it 'ライセンスグループが二個追加される' do
+        lambda {
+          CommonLicense.import(@ts)
+        }.should change(CommonLicense, :count).by 2
+      end
+      it '[]を返す' do
+        CommonLicense.import(@ts).should eq []
+      end
+    end
+    context 'コモンライセンス作成に失敗したとき' 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)
+      end
+      it 'コモンライセンスの数に変化がない' do
+        lambda {
+          CommonLicense.import(@t)
+        }.should_not change CommonLicense, :count
+      end
+      it '配列を返す' do
+        r = CommonLicense.import(@t)
+        r.is_a?(Array).should be_true
+      end
+      it '配列の中身は一件' do
+        r = CommonLicense.import(@t)
+        r.should have(1).items
+      end
+      it 'コモンライセンスオブジェクトが入っている' do
+        r = CommonLicense.import(@t)
+        r.first.is_a?(CommonLicense).should be_true
+      end
+    end
+    context '複数のコモンライセンス作成に失敗したとき' do
+      #三件中、二件の失敗、一件を成功させ、成功データは戻り値に含まないことを確認する
+      it 'コモンライセンスの数に変化がない' do
+        lambda {
+          CommonLicense.import(@tes)
+        }.should_not change CommonLicense, :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)
+      end
+      it '配列を返す' do
+        r = CommonLicense.import(@tes)
+        r.is_a?(Array).should be_true
+      end
+      it '配列の中身は2件' do
+        r = CommonLicense.import(@tes)
+        r.should have(2).items
+      end
+      it '配列の中身は失敗したコモンライセンスオブジェクトが入っている' 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'
+      end
+    end
+  end
+  
 end