[logaling-commit] logaling/logaling-server [master] Add spec about validation for GithubProject

Back to archive index

SHIMADA Koji null+****@clear*****
Thu Aug 23 09:51:44 JST 2012


SHIMADA Koji	2012-08-23 09:51:44 +0900 (Thu, 23 Aug 2012)

  New Revision: 4153bc973481f0692a21391fb2bc9e1a51921984
  https://github.com/logaling/logaling-server/commit/4153bc973481f0692a21391fb2bc9e1a51921984

  Log:
    Add spec about validation for GithubProject

  Modified files:
    app/models/git_backended.rb
    spec/models/github_project_spec.rb

  Modified: app/models/git_backended.rb (+5 -1)
===================================================================
--- app/models/git_backended.rb    2012-08-23 09:20:33 +0900 (6ecc177)
+++ app/models/git_backended.rb    2012-08-23 09:51:44 +0900 (0b7f86b)
@@ -4,7 +4,7 @@ module GitBackended
   end
 
   def checkout!
-    if File.directory?(repository_path)
+    if cloned?
       Dir.chdir(repository_path) do
         unless system "git", "reset", "--hard"
           raise "reset failed"
@@ -22,4 +22,8 @@ module GitBackended
       end
     end
   end
+
+  def cloned?
+    File.directory?(repository_path)
+  end
 end

  Modified: spec/models/github_project_spec.rb (+43 -13)
===================================================================
--- spec/models/github_project_spec.rb    2012-08-23 09:20:33 +0900 (d0d8cd8)
+++ spec/models/github_project_spec.rb    2012-08-23 09:51:44 +0900 (7ef5c8f)
@@ -1,33 +1,63 @@
 require 'spec_helper'
 
-describe GithubProject, 'using logaling' do
-  subject do
-    GithubProject.create(:owner => 'logaling', :name => 'logaling-server')
-  end
-
+describe GithubProject do
   before do
     subject.stub!(:remote_repository_url)
            .and_return(File.join(Rails.root, '.git'))
   end
 
-  context 'synchronizing with the repository for the first time' do
-    before do
-      subject.sync!
+  describe 'using logaling' do
+    subject do
+      GithubProject.new(:owner => 'logaling', :name => 'logaling-server')
     end
 
     it do
-      subject.should be_with_logaling
+      subject.should be_valid
+    end
+
+    it 'should have local repository after validation' do
+      subject.valid?
+      subject.should be_cloned
+    end
+
+    context 'synchronizing with the repository for the first time' do
+      before do
+        subject.sync!
+      end
+
+      it do
+        subject.should be_with_logaling
+      end
+    end
+
+    context 'synchronizing with the repository twice' do
+      before do
+        subject.sync!
+        subject.sync!
+      end
+
+      it do
+        subject.should be_with_logaling
+      end
     end
   end
 
-  context 'synchronizing with the repository twice' do
+  describe 'not using logaling' do
+    subject do
+      GithubProject.new(:owner => 'logaling', :name => 'logaling-server')
+    end
+
     before do
-      subject.sync!
-      subject.sync!
+      subject.stub!(:with_logaling?).and_return(false)
     end
 
     it do
-      subject.should be_with_logaling
+      subject.should_not be_valid
+    end
+
+    it 'should not have local repository after validation' do
+      subject.valid?
+      subject.should_not be_cloned
     end
   end
 end
-------------- next part --------------
An HTML attachment was scrubbed...
下载 



More information about the logaling-commit mailing list
Back to archive index