#1881 Fix traceback when trying to edit file online
Merged 7 years ago by cep. Opened 7 years ago by cep.

@@ -21,11 +21,7 @@ 

              identifier=branchname)

        }}"><span class="oi" data-glyph="random"></span>&nbsp; {{ branchname }}</a></li>{%

      for file in filename.split('/') %}

-       {% if loop.first %}

-       {% set path = file %}

-       {% else %}

-       {% set path = path + '/' + file %}

-       {% endif %}

+       {% set path = '/'.join(filename.split('/')[:loop.index]) %}

neat :)

        {% if loop.index != loop.length %}<li><a

        href="{{ url_for('view_file',

              repo=repo.name,

@@ -74,6 +74,7 @@ 

              </a>

            </li>

          {% for file in filename.split('/') %}

+           {% set path = '/'.join(filename.split('/')[:loop.index]) %}

            {% if loop.index != loop.length

          %}<li><a href="{{ url_for('view_file',

                  repo=repo.name,

@@ -1683,6 +1683,15 @@ 

          self.assertIn(

              '<a href="/test/blob/master/f/folder1/folder2">', output.data)

  

+         # Verify the nav links correctly when viewing a nested folder/file.

+         output = self.app.get('/test/blob/master/f/folder1/folder2/file')

+         self.assertEqual(output.status_code, 200)

+         self.assertIn(

+             '<li><a href="/test/blob/master/f/folder1/folder2">\n'

+             '            <span class="oi" data-glyph="folder">'

+             '</span>&nbsp; folder2</a>\n'

+             '          </li>', output.data)

+ 

          # View by image name -- with a non-existant file

          output = self.app.get('/test/blob/sources/f/testfoo.jpg')

          self.assertEqual(output.status_code, 404)
@@ -1729,6 +1738,16 @@ 

              os.path.join(self.path, 'forks', 'pingou', 'test3.git'),

              ncommits=10)

  

+         # Verify the nav links correctly when viewing a file/folder in a fork.

+         output = self.app.get(

+             '/fork/pingou/test3/blob/master/f/folder1/folder2/file')

+         self.assertEqual(output.status_code, 200)

+         self.assertIn(

+             '<li><a href="/fork/pingou/test3/blob/master/f/folder1/folder2">\n'

+             '            <span class="oi" data-glyph="folder"></span>&nbsp; '

+             'folder2</a>\n          </li>', output.data)

+ 

+ 

          output = self.app.get('/fork/pingou/test3/blob/master/f/sources')

          self.assertEqual(output.status_code, 200)

          self.assertIn('<table class="code_table">', output.data)
@@ -3033,6 +3052,15 @@ 

                  '<textarea id="textareaCode" name="content">foo\n bar</textarea>',

                  output.data)

  

+             # Verify the nav links correctly when editing a file.

+             output = self.app.get('/test/blob/master/f/folder1/folder2/file')

+             self.assertEqual(output.status_code, 200)

+             self.assertIn(

+                 '<li><a href="/test/blob/master/f/folder1/folder2">\n'

+                 '            <span class="oi" data-glyph="folder">'

+                 '</span>&nbsp; folder2</a>\n'

+                 '          </li>', output.data)

+ 

              csrf_token = output.data.split(

                  'name="csrf_token" type="hidden" value="')[1].split('">')[0]

  
@@ -3113,6 +3141,16 @@ 

                  os.path.join(self.path, 'forks', 'pingou', 'test3.git'),

                  ncommits=10)

  

+             # Verify the nav links correctly when editing a file in a fork.

+             output = self.app.get(

+                 '/fork/pingou/test3/edit/master/f/folder1/folder2/file')

+             self.assertEqual(output.status_code, 200)

+             self.assertIn(

+                 '<li><a\n      '

+                 'href="/fork/pingou/test3/blob/master/f/folder1/folder2"\n'

+                 '        ><span class="oi" data-glyph="folder"></span>&nbsp; '

+                 'folder2</a>\n        </li>', output.data)

+ 

              output = self.app.get('/fork/pingou/test3/edit/master/f/sources')

              self.assertEqual(output.status_code, 200)

              self.assertIn(

It broke only when the file was not in the root of the repo. i.e when the file was inside a directory.

Check if the path is actually used anywhere :)

1 new commit added

  • Fix path not defined in file.html
7 years ago

1 new commit added

  • Fix incorrect value for variable 'path'
7 years ago

1 new commit added

  • Add tests for nav links when viewing or editing a file online
7 years ago

@pingou: The tests are up, but they only test for cases where the links are correct. I'm not sure how to mock the previous (incorrect) behaviour. Searching didn't turn up any relevant results, so can you please point me to some docs, or examples for the same? Thanks :)

@cep, it's easy, remove your fix and see if the test still pass, if it does then we're not checking that this won't break in the future :)

rebased

7 years ago

@pingou, done! Please see if this'll do it.

Looks great, let's rebase and merge :)

(btw, if you grant me commit to your fork I could do the rebase while you're afk and merge directly :))

Going to apply this one manually as I'd like to have it in 2.12.1

thanks :)

Commit 0294d15 fixes this pull-request

Pull-Request has been merged by breathingcode@gmail.com

7 years ago