summaryrefslogtreecommitdiff
path: root/spec/support
diff options
context:
space:
mode:
authorRobert Speicher <rspeicher@gmail.com>2012-08-28 01:42:28 -0400
committerRobert Speicher <rspeicher@gmail.com>2012-08-28 21:22:49 -0400
commitc9c1f76e002d899dd6765c4c1630697cc5068f27 (patch)
tree0ab18369aa5df80c89b1618e4de75eaa33da174b /spec/support
parent4805c64f2a96e8a9ea5a0e94a820d840fa1675e0 (diff)
downloadgitlab-ce-c9c1f76e002d899dd6765c4c1630697cc5068f27.tar.gz
All specs and features currently passing with FactoryGirl
Diffstat (limited to 'spec/support')
-rw-r--r--spec/support/monkeypatch.rb21
-rw-r--r--spec/support/stubbed_repository.rb60
2 files changed, 60 insertions, 21 deletions
diff --git a/spec/support/monkeypatch.rb b/spec/support/monkeypatch.rb
deleted file mode 100644
index 04bbb6fb680..00000000000
--- a/spec/support/monkeypatch.rb
+++ /dev/null
@@ -1,21 +0,0 @@
-# Stubbing Project <-> git host path
-# create project using Factory only
-class Project
- def path_to_repo
- File.join(Rails.root, "tmp", "tests", path)
- end
-
- def satellite
- @satellite ||= FakeSatellite.new
- end
-end
-
-class FakeSatellite
- def exists?
- true
- end
-
- def create
- true
- end
-end
diff --git a/spec/support/stubbed_repository.rb b/spec/support/stubbed_repository.rb
new file mode 100644
index 00000000000..fa6c4c9a9b6
--- /dev/null
+++ b/spec/support/stubbed_repository.rb
@@ -0,0 +1,60 @@
+# Stubs out all Git repository access done by models so that specs can run
+# against fake repositories without Grit complaining that they don't exist.
+module StubbedRepository
+ extend ActiveSupport::Concern
+
+ included do
+ # If a class defines the method we want to stub directly, rather than
+ # inheriting it from a module (as is the case in UsersProject), that method
+ # will overwrite our stub, so use alias_method to ensure it's our stub
+ # getting called.
+
+ alias_method :update_repository, :fake_update_repository
+ alias_method :destroy_repository, :fake_destroy_repository
+ alias_method :repository_delete_key, :fake_repository_delete_key
+ alias_method :path_to_repo, :fake_path_to_repo
+ alias_method :satellite, :fake_satellite
+ end
+
+ def fake_update_repository
+ true
+ end
+
+ def fake_destroy_repository
+ true
+ end
+
+ def fake_repository_delete_key
+ true
+ end
+
+ def fake_path_to_repo
+ if new_record?
+ # There are a couple Project specs that expect the Project's path to be
+ # in the returned path, so let's patronize them.
+ File.join(Rails.root, 'tmp', 'tests', path)
+ else
+ # For everything else, just give it the path to one of our real seeded
+ # repos.
+ File.join(Rails.root, 'tmp', 'tests', 'gitlabhq_1')
+ end
+ end
+
+ def fake_satellite
+ FakeSatellite.new
+ end
+
+ class FakeSatellite
+ def exists?
+ true
+ end
+
+ def create
+ true
+ end
+ end
+end
+
+[Project, Key, ProtectedBranch, UsersProject].each do |c|
+ c.send(:include, StubbedRepository)
+end