Skip to content

Commit

Permalink
Merge pull request #589 from ualbertalib/add-cms-admin-tests
Browse files Browse the repository at this point in the history
Add basic smoke tests to verify cms admin pages are being rendered
  • Loading branch information
murny authored Jun 21, 2024
2 parents e42ded9 + d14f732 commit 8a21070
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 8 deletions.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,19 @@ Pagination is handled by either Kaminari or WillPaginate. Make sure you have one
7. visit [http://localhost:3000](http://localhost:3000) and you will see the library homepage.
8. If you need to visit the admin section ([http://localhost:3000/admin](http://localhost:3000/admin)) - You'll be prompted to enter username and password (use the ones in your `config/secrets.yml`, which by default are 'admin' and 'mysecretpassword')


## Testing
To run the tests for the library-cms application, you can use the following command once your application has been setup from above:

```
bundle exec rails test
```

This will execute all the test cases and provide you with the test results.

NOTE: We preload the test database with all the seed CMS data (pages/layouts/etc) before tests are ran. This happens only once.
So if you make a change to the CMS seed data, you must drop the test DB for your changes to be reflected in the test database.

## Features

![image](https://user-images.githubusercontent.com/1220762/173146961-b8430fca-4d41-4c8c-a413-8bd0ac6cc929.png)
Expand Down
Empty file removed test/integration/.keep
Empty file.
53 changes: 53 additions & 0 deletions test/integration/cms_admin_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# frozen_string_literal: true

require "test_helper"

class CmsAdminTest < ActionDispatch::IntegrationTest
test "unauthorized access to admin gets unauthorized response" do
get comfy_admin_cms_path

assert_response :unauthorized
end

test "/admin redirects to first site's pages index" do
get comfy_admin_cms_path, headers: admin_authorization_headers

assert_response :redirect
assert_redirected_to comfy_admin_cms_site_pages_path(site_id: Comfy::Cms::Site.first)
end

test "admin sites index" do
get comfy_admin_cms_sites_path, headers: admin_authorization_headers

assert_response :success
assert_select "h2", "Sites"
end

test "admin site pages index" do
get comfy_admin_cms_site_pages_path(site_id: Comfy::Cms::Site.first), headers: admin_authorization_headers

assert_response :success
assert_select "h2", "Pages"
end

test "admin site layouts index" do
get comfy_admin_cms_site_layouts_path(site_id: Comfy::Cms::Site.first), headers: admin_authorization_headers

assert_response :success
assert_select "h2", "Layouts"
end

test "admin site snippets index" do
get comfy_admin_cms_site_snippets_path(site_id: Comfy::Cms::Site.first), headers: admin_authorization_headers

assert_response :success
assert_select "h2", "Snippets"
end

test "admin site files index" do
get comfy_admin_cms_site_files_path(site_id: Comfy::Cms::Site.first), headers: admin_authorization_headers

assert_response :success
assert_select "h2", "Files"
end
end
13 changes: 5 additions & 8 deletions test/integration/profiles_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,13 @@ class ProfilesTest < ActionDispatch::IntegrationTest
end

test "should get new" do
get new_profile_url,
headers: {Authorization: ActionController::HttpAuthentication::Basic.encode_credentials(Rails.application.secrets.cms_user, Rails.application.secrets.cms_password)}
get new_profile_url, headers: admin_authorization_headers

assert_response :success
end

test "should get edit" do
get edit_profile_url(profiles(:one)),
headers: {Authorization: ActionController::HttpAuthentication::Basic.encode_credentials(Rails.application.secrets.cms_user, Rails.application.secrets.cms_password)}
get edit_profile_url(profiles(:one)), headers: admin_authorization_headers

assert_response :success
end
Expand All @@ -37,7 +35,7 @@ class ProfilesTest < ActionDispatch::IntegrationTest
assert_difference("Profile.count") do
post profiles_url,
params: {profile: {first_name: "John", last_name: "Doe", email: "[email protected]"}},
headers: {Authorization: ActionController::HttpAuthentication::Basic.encode_credentials(Rails.application.secrets.cms_user, Rails.application.secrets.cms_password)}
headers: admin_authorization_headers
end

assert_redirected_to profile_url(Profile.last)
Expand All @@ -46,7 +44,7 @@ class ProfilesTest < ActionDispatch::IntegrationTest
test "should update profile" do
patch profile_url(@profile),
params: {profile: {first_name: "John"}},
headers: {Authorization: ActionController::HttpAuthentication::Basic.encode_credentials(Rails.application.secrets.cms_user, Rails.application.secrets.cms_password)}
headers: admin_authorization_headers

@profile.reload

Expand All @@ -56,8 +54,7 @@ class ProfilesTest < ActionDispatch::IntegrationTest

test "should destroy profile" do
assert_difference("Profile.count", -1) do
delete profile_url(@profile),
headers: {Authorization: ActionController::HttpAuthentication::Basic.encode_credentials(Rails.application.secrets.cms_user, Rails.application.secrets.cms_password)}
delete profile_url(@profile), headers: admin_authorization_headers
end

assert_redirected_to profiles_url
Expand Down
4 changes: 4 additions & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,8 @@ class ActiveSupport::TestCase
fixtures :all

# Add more helper methods to be used by all tests here...

def admin_authorization_headers
{Authorization: ActionController::HttpAuthentication::Basic.encode_credentials(Rails.application.secrets.cms_user, Rails.application.secrets.cms_password)}
end
end

0 comments on commit 8a21070

Please sign in to comment.