0a79345d2283 — Alessio Caiazza v0.1.2 13 years ago
Test class migrated from Github to Bitbucket
1 files changed, 33 insertions(+), 52 deletions(-)

M test/functional/github_hook_controller_test.rb => test/functional/bitbucket_hook_controller_test.rb
M test/functional/github_hook_controller_test.rb => test/functional/bitbucket_hook_controller_test.rb +33 -52
@@ 2,56 2,37 @@ require File.dirname(__FILE__) + '/../te
 
 require 'mocha'
 
-class GithubHookControllerTest < ActionController::TestCase
+class BitbucketHookControllerTest < ActionController::TestCase
 
   def setup
-    # Sample JSON post from http://github.com/guides/post-receive-hooks
-    @json = '{ 
-      "before": "5aef35982fb2d34e9d9d4502f6ede1072793222d",
-      "repository": {
-        "url": "http://github.com/defunkt/github",
-        "name": "github",
-        "description": "You\'re lookin\' at it.",
-        "watchers": 5,
-        "forks": 2,
-        "private": 1,
-        "owner": {
-          "email": "chris@ozmm.org",
-          "name": "defunkt"
-        }
-      },
-      "commits": [
-        {
-          "id": "41a212ee83ca127e3c8cf465891ab7216a705f59",
-          "url": "http://github.com/defunkt/github/commit/41a212ee83ca127e3c8cf465891ab7216a705f59",
-          "author": {
-            "email": "chris@ozmm.org",
-            "name": "Chris Wanstrath"
-          },
-          "message": "okay i give in",
-          "timestamp": "2008-02-15T14:57:17-08:00",
-          "added": ["filepath.rb"]
-        },
-        {
-          "id": "de8251ff97ee194a289832576287d6f8ad74e3d0",
-          "url": "http://github.com/defunkt/github/commit/de8251ff97ee194a289832576287d6f8ad74e3d0",
-          "author": {
-            "email": "chris@ozmm.org",
-            "name": "Chris Wanstrath"
-          },
-          "message": "update pricing a tad",
-          "timestamp": "2008-02-15T14:36:34-08:00"
-        }
-      ],
-      "after": "de8251ff97ee194a289832576287d6f8ad74e3d0",
-      "ref": "refs/heads/master"
-    }'
-    @repository = Repository::Git.new
+    # Sample JSON post from http://confluence.atlassian.com/display/BBDEV/Writing+Brokers+for+Bitbucket#the-payload
+    @json = <<-EOF
+{"broker": "twitter",
+ "commits": [{ "author": "jespern",
+               "files": [{"file": "media/css/layout.css",
+                           "type": "modified"},
+                          {"file": "apps/bb/views.py",
+                           "type": "modified"},
+                          {"file": "templates/issues/issue.html",
+                           "type": "modified"}],
+               "message": "adding bump button, issue #206 fixed",
+               "node": "e71c63bcc05e",
+               "revision": 1650,
+               "size": 684}],
+ "repository": { "absolute_url": "/jespern/bitbucket/",
+                 "name": "bitbucket",
+                 "owner": "jespern",
+                 "slug": "bitbucket",
+                 "website": "http://bitbucket.org/"},
+ "service": {"password": "bar", "username": "foo"}}
+EOF
+    @repository = Repository::Mercurial.new
     @repository.stubs(:fetch_changesets).returns(true)
 
     @project = Project.new
     @project.stubs(:repository).returns(@repository)
-    Project.stubs(:find_by_identifier).with('github').returns(@project)
+    Project.stubs(:find_by_identifier).with('bitbucket').returns(@project)
+    @controller = BitbucketHookController.new
     @controller.stubs(:exec)
 
     Repository.expects(:fetch_changesets).never

          
@@ 64,12 45,12 @@ class GithubHookControllerTest < ActionC
   end
 
   def test_should_use_the_repository_name_as_project_identifier
-    Project.expects(:find_by_identifier).with('github').returns(@project)
+    Project.expects(:find_by_identifier).with('bitbucket').returns(@project)
     do_post
   end
 
-  def test_should_update_the_repository_using_git_on_the_commandline
-    Project.expects(:find_by_identifier).with('github').returns(@project)
+  def test_should_update_the_repository_using_hg_on_the_commandline
+    Project.expects(:find_by_identifier).with('bitbucket').returns(@project)
     @controller.expects(:exec).returns(true)
     do_post
   end

          
@@ 98,18 79,18 @@ class GithubHookControllerTest < ActionC
     assert_raises TypeError do
       project = mock('project')
       project.expects(:repository).returns(nil)
-      Project.expects(:find_by_identifier).with('github').returns(project)
-      do_post :repository => {:name => 'github'}
+      Project.expects(:find_by_identifier).with('bitbucket').returns(project)
+      do_post :repository => {:name => 'bitbucket'}
     end
   end
 
-  def test_should_return_500_if_repository_is_not_git
+  def test_should_return_500_if_repository_is_not_mercurial
     assert_raises TypeError do
       project = mock('project')
       repository = Repository::Subversion.new
       project.expects(:repository).at_least(1).returns(repository)
-      Project.expects(:find_by_identifier).with('github').returns(project)
-      do_post :repository => {:name => 'github'}
+      Project.expects(:find_by_identifier).with('bitbucket').returns(project)
+      do_post :repository => {:name => 'bitbucket'}
     end
   end