diff --git a/test/cassettes/Communication_Website_GitFileTest_test_should_update__an_existing_file.yml b/test/cassettes/Communication_Website_GitFileTest_test_should_update__an_existing_file.yml new file mode 100644 index 0000000000000000000000000000000000000000..b7406006135848c560f62b5e83390fe6fa06ea92 --- /dev/null +++ b/test/cassettes/Communication_Website_GitFileTest_test_should_update__an_existing_file.yml @@ -0,0 +1,85 @@ +--- +http_interactions: +- request: + method: get + uri: https://api.github.com/repos/<TEST_GITHUB_REPOSITORY>/contents/content/posts/2010/2010-11-28-test-2.html + body: + encoding: US-ASCII + string: '' + headers: + Accept: + - application/vnd.github.v3+json + User-Agent: + - Octokit Ruby Gem 4.22.0 + Content-Type: + - application/json + Authorization: + - token <TEST_GITHUB_TOKEN> + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + response: + status: + code: 200 + message: OK + headers: + Server: + - GitHub.com + Date: + - Wed, 23 Feb 2022 18:49:12 GMT + Content-Type: + - application/json; charset=utf-8 + Transfer-Encoding: + - chunked + Cache-Control: + - private, max-age=60, s-maxage=60 + Vary: + - Accept, Authorization, Cookie, X-GitHub-OTP + - Accept-Encoding, Accept, X-Requested-With + Etag: + - W/"8b58a401710ed6560d7d06353c0fdf46f587128f" + Last-Modified: + - Wed, 23 Feb 2022 18:16:13 GMT + X-Oauth-Scopes: + - repo + X-Accepted-Oauth-Scopes: + - '' + Github-Authentication-Token-Expiration: + - 2022-03-02 10:41:25 UTC + X-Github-Media-Type: + - github.v3; format=json + X-Ratelimit-Limit: + - '5000' + X-Ratelimit-Remaining: + - '4956' + X-Ratelimit-Reset: + - '1645643208' + X-Ratelimit-Used: + - '44' + X-Ratelimit-Resource: + - core + Access-Control-Expose-Headers: + - ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, + X-RateLimit-Used, X-RateLimit-Resource, X-RateLimit-Reset, X-OAuth-Scopes, + X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type, X-GitHub-SSO, + X-GitHub-Request-Id, Deprecation, Sunset + Access-Control-Allow-Origin: + - "*" + Strict-Transport-Security: + - max-age=31536000; includeSubdomains; preload + X-Frame-Options: + - deny + X-Content-Type-Options: + - nosniff + X-Xss-Protection: + - '0' + Referrer-Policy: + - origin-when-cross-origin, strict-origin-when-cross-origin + Content-Security-Policy: + - default-src 'none' + X-Github-Request-Id: + - C988:DD33:741334:7734EF:621681A8 + body: + encoding: ASCII-8BIT + string: '{"name":"2010-11-28-test-2.html","path":"content/posts/2010/2010-11-28-test-2.html","sha":"8b58a401710ed6560d7d06353c0fdf46f587128f","size":92,"url":"https://api.github.com/repos/<TEST_GITHUB_REPOSITORY>/contents/content/posts/2010/2010-11-28-test-2.html?ref=main","html_url":"https://github.com/<TEST_GITHUB_REPOSITORY>/blob/main/content/posts/2010/2010-11-28-test-2.html","git_url":"https://api.github.com/repos/<TEST_GITHUB_REPOSITORY>/git/blobs/8b58a401710ed6560d7d06353c0fdf46f587128f","download_url":"https://raw.githubusercontent.com/<TEST_GITHUB_REPOSITORY>/main/content/posts/2010/2010-11-28-test-2.html","type":"file","content":"LS0tCnRpdGxlOiAiVGVzdCAyIgpkYXRlOiAiMjAxMC0xMS0yOFQwMTowMDow\nMCswMTowMCIKc2x1ZzogInRlc3QtMiIKZGVzY3JpcHRpb246ID4KICAKLS0t\nCgo=\n","encoding":"base64","_links":{"self":"https://api.github.com/repos/<TEST_GITHUB_REPOSITORY>/contents/content/posts/2010/2010-11-28-test-2.html?ref=main","git":"https://api.github.com/repos/<TEST_GITHUB_REPOSITORY>/git/blobs/8b58a401710ed6560d7d06353c0fdf46f587128f","html":"https://github.com/<TEST_GITHUB_REPOSITORY>/blob/main/content/posts/2010/2010-11-28-test-2.html"}}' + recorded_at: Wed, 23 Feb 2022 18:49:12 GMT +recorded_with: VCR 6.0.0 diff --git a/test/fixtures/communication/website/git_files.yml b/test/fixtures/communication/website/git_files.yml index 953b550527c2514df3a20355d1af0826e88849c0..21a1d16a6c596ec57810e8cf1363d5885ec20579 100644 --- a/test/fixtures/communication/website/git_files.yml +++ b/test/fixtures/communication/website/git_files.yml @@ -23,3 +23,8 @@ git_file_1: about: test_post (Communication::Website::Post) website: website_with_github +git_file_2: + about: test_post_2 (Communication::Website::Post) + website: website_with_github + previous_sha: 8b58a401710ed6560d7d06353c0fdf46f587128f + previous_path: content/posts/2010/2010-11-28-test-2.html diff --git a/test/fixtures/communication/website/posts.yml b/test/fixtures/communication/website/posts.yml index c2154ce20abbe871edfe13965a4d0f83f08efe5f..aa5498d02486b6145071853198c254c3eaeca95c 100644 --- a/test/fixtures/communication/website/posts.yml +++ b/test/fixtures/communication/website/posts.yml @@ -38,3 +38,11 @@ test_post: slug: test published: true published_at: 2010-11-28 00:00:00 +test_post_2: + university: default_university + website: website_with_github + title: Test 2 + slug: test-2 + published: true + published_at: 2010-11-28 00:00:00 + text: new content diff --git a/test/models/communication/website/git_file_test.rb b/test/models/communication/website/git_file_test.rb index 8509604b66fad91ce9713dc02005a1ab40247110..9bfc4adce11026e10cbe754aaa93fe3093beffc9 100644 --- a/test/models/communication/website/git_file_test.rb +++ b/test/models/communication/website/git_file_test.rb @@ -23,10 +23,24 @@ require "test_helper" class Communication::Website::GitFileTest < ActiveSupport::TestCase - test "should_create? for a new file" do + test "should_create? a new file" do VCR.use_cassette(location) do file = communication_website_git_files(:git_file_1) assert file.should_create? end end + + test "should_update? an existing file" do + VCR.use_cassette(location) do + # To create the file, i first did that: + # file = communication_website_git_files(:git_file_2) + # file.website.git_repository.add_git_file file + # file.website.git_repository.sync! + # byebug + # Then i got the sha and path, pasted it in the fixtures, + # changed the text so the content would need an update. + file = communication_website_git_files(:git_file_2) + assert file.should_update? + end + end end