Fix branch matching logic

Based on Jim's feedback, change the branch matching logic to always
have priority over ref matching. And v3 will always have refs, so no
need to check if that attribute exists. Also adds a test that checks the
current breakage of branch matching logic.

Change-Id: Iba148b73a77b3300ad84db1c05c083d2c82cd950
diff --git a/tests/base.py b/tests/base.py
index 2e3d682..c240a1b 100755
--- a/tests/base.py
+++ b/tests/base.py
@@ -2620,6 +2620,13 @@
                 return build
         raise Exception("Unable to find build %s" % name)
 
+    def assertJobNotInHistory(self, name, project=None):
+        for job in self.history:
+            if (project is None or
+                job.parameters['zuul']['project']['name'] == project):
+                self.assertNotEqual(job.name, name,
+                                    'Job %s found in history' % name)
+
     def getJobFromHistory(self, name, project=None):
         for job in self.history:
             if (job.name == name and