diff --git a/.gitignore b/.gitignore index 2b355a0c0..02d89952c 100644 --- a/.gitignore +++ b/.gitignore @@ -9,7 +9,7 @@ db/test.sqlite3-journal pkg rdoc /tmp -public/* +public/system/ Gemfile.lock .rvmrc .ruby-version diff --git a/Gemfile b/Gemfile index cdc017cc1..92fb9c914 100644 --- a/Gemfile +++ b/Gemfile @@ -6,6 +6,7 @@ group :development, :test do gem "byebug", platforms: %i[mri mingw x64_mingw] gem "capybara" gem "kaminari" + gem "puma" gem "rubocop", require: false gem "selenium-webdriver" gem "sqlite3" diff --git a/public/favicon.ico b/public/favicon.ico new file mode 100644 index 000000000..6cc01676d Binary files /dev/null and b/public/favicon.ico differ diff --git a/test/controllers/comfy/admin/cms/sites_controller_test.rb b/test/controllers/comfy/admin/cms/sites_controller_test.rb index 56d1ddc60..90da7979a 100644 --- a/test/controllers/comfy/admin/cms/sites_controller_test.rb +++ b/test/controllers/comfy/admin/cms/sites_controller_test.rb @@ -22,7 +22,7 @@ def test_get_new r :get, new_comfy_admin_cms_site_path assert_response :success assert assigns(:site) - assert_equal "test.host", assigns(:site).hostname + assert_equal "www.example.com", assigns(:site).hostname assert_template :new assert_select "form[action='/admin/sites']" end diff --git a/test/fixtures/comfy/cms/sites.yml b/test/fixtures/comfy/cms/sites.yml index 70fbcf3a6..f4496bc1b 100644 --- a/test/fixtures/comfy/cms/sites.yml +++ b/test/fixtures/comfy/cms/sites.yml @@ -1,5 +1,5 @@ default: label: Default Site identifier: default-site - hostname: test.host + hostname: www.example.com path: diff --git a/test/integration/seeds_test.rb b/test/integration/seeds_test.rb index 4dd835333..b0fe066c5 100644 --- a/test/integration/seeds_test.rb +++ b/test/integration/seeds_test.rb @@ -35,7 +35,7 @@ def test_seeds_enabled assert_equal "Default Seed Snippet", Comfy::Cms::Snippet.find_by_identifier("default").label file_path = url_for(ActiveStorage::Blob.find_by(filename: "header.png")) - file_path = file_path.sub("http://test.host", "") + file_path = file_path.sub("http://www.example.com", "") out = <<-HTML.strip_heredoc diff --git a/test/integration/sites_test.rb b/test/integration/sites_test.rb index 79189b62c..e311f4421 100644 --- a/test/integration/sites_test.rb +++ b/test/integration/sites_test.rb @@ -23,14 +23,14 @@ def test_get_public_page_with_single_site get "/" assert_response :success assert assigns(:cms_site) - assert_equal "test.host", assigns(:cms_site).hostname + assert_equal "www.example.com", assigns(:cms_site).hostname end def test_get_public_page_with_sites_with_different_paths Comfy::Cms::Site.delete_all - site_a = Comfy::Cms::Site.create!(identifier: "site-a", hostname: "test.host", path: "") - site_b = Comfy::Cms::Site.create!(identifier: "site-b", hostname: "test.host", path: "path-b") - site_c = Comfy::Cms::Site.create!(identifier: "site-c", hostname: "test.host", path: "path-c/child") + site_a = Comfy::Cms::Site.create!(identifier: "site-a", hostname: "www.example.com", path: "") + site_b = Comfy::Cms::Site.create!(identifier: "site-b", hostname: "www.example.com", path: "path-b") + site_c = Comfy::Cms::Site.create!(identifier: "site-c", hostname: "www.example.com", path: "path-c/child") [site_a, site_b, site_c].each do |site| layout = site.layouts.create!(identifier: "test") @@ -62,8 +62,8 @@ def test_get_public_page_with_sites_with_different_paths def test_get_public_page_with_host_with_port Comfy::Cms::Site.delete_all - site_a = Comfy::Cms::Site.create!(identifier: "site-a", hostname: "test.host:3000") - site_b = Comfy::Cms::Site.create!(identifier: "site-b", hostname: "test.host") + site_a = Comfy::Cms::Site.create!(identifier: "site-a", hostname: "www.example.com:3000") + site_b = Comfy::Cms::Site.create!(identifier: "site-b", hostname: "www.example.com") [site_a, site_b].each do |site| layout = site.layouts.create!(identifier: "test") diff --git a/test/models/page_test.rb b/test/models/page_test.rb index 958828cb8..1cfd04d02 100644 --- a/test/models/page_test.rb +++ b/test/models/page_test.rb @@ -477,8 +477,8 @@ def test_root? end def test_url - assert_equal "//test.host/", @page.url - assert_equal "//test.host/child-page", comfy_cms_pages(:child).url + assert_equal "//www.example.com/", @page.url + assert_equal "//www.example.com/child-page", comfy_cms_pages(:child).url assert_equal "/", @page.url(relative: true) assert_equal "/child-page", comfy_cms_pages(:child).url(relative: true) @@ -487,8 +487,8 @@ def test_url @page.reload comfy_cms_pages(:child).reload - assert_equal "//test.host/en/site/", @page.url - assert_equal "//test.host/en/site/child-page", comfy_cms_pages(:child).url + assert_equal "//www.example.com/en/site/", @page.url + assert_equal "//www.example.com/en/site/child-page", comfy_cms_pages(:child).url assert_equal "/en/site/", @page.url(relative: true) assert_equal "/en/site/child-page", comfy_cms_pages(:child).url(relative: true) @@ -496,8 +496,8 @@ def test_url def test_url_with_public_cms_path ComfortableMexicanSofa.config.public_cms_path = "/custom" - assert_equal "//test.host/custom/", @page.url - assert_equal "//test.host/custom/child-page", comfy_cms_pages(:child).url + assert_equal "//www.example.com/custom/", @page.url + assert_equal "//www.example.com/custom/child-page", comfy_cms_pages(:child).url assert_equal "/custom/", @page.url(relative: true) assert_equal "/custom/child-page", comfy_cms_pages(:child).url(relative: true) diff --git a/test/models/site_test.rb b/test/models/site_test.rb index 14f2041d8..4d87c301d 100644 --- a/test/models/site_test.rb +++ b/test/models/site_test.rb @@ -110,19 +110,19 @@ def test_cascading_destroy def test_find_site site_a = @site - assert_equal "test.host", site_a.hostname + assert_equal "www.example.com", site_a.hostname assert_nil site_a.path - assert_equal site_a, Comfy::Cms::Site.find_site("test.host") - assert_equal site_a, Comfy::Cms::Site.find_site("test.host", "/some/path") + assert_equal site_a, Comfy::Cms::Site.find_site("www.example.com") + assert_equal site_a, Comfy::Cms::Site.find_site("www.example.com", "/some/path") assert_equal site_a, Comfy::Cms::Site.find_site("test99.host", "/some/path") site_b = Comfy::Cms::Site.create!(identifier: "test_a", hostname: "test2.host", path: "en") site_c = Comfy::Cms::Site.create!(identifier: "test_b", hostname: "test2.host", path: "fr") - assert_equal site_a, Comfy::Cms::Site.find_site("test.host") - assert_equal site_a, Comfy::Cms::Site.find_site("test.host", "/some/path") - assert_equal site_a, Comfy::Cms::Site.find_site("test.host", "/some/path") + assert_equal site_a, Comfy::Cms::Site.find_site("www.example.com") + assert_equal site_a, Comfy::Cms::Site.find_site("www.example.com", "/some/path") + assert_equal site_a, Comfy::Cms::Site.find_site("www.example.com", "/some/path") assert_nil Comfy::Cms::Site.find_site("test99.host", "/some/path") assert_nil Comfy::Cms::Site.find_site("test2.host") @@ -141,7 +141,7 @@ def test_find_site def test_find_site_with_public_cms_path ComfortableMexicanSofa.config.public_cms_path = "/custom" - assert_equal "//test.host/custom", comfy_cms_sites(:default).url + assert_equal "//www.example.com/custom", @site.url site_a = Comfy::Cms::Site.create!(identifier: "test_a", hostname: "test2.host", path: "en") site_b = Comfy::Cms::Site.create!(identifier: "test_b", hostname: "test2.host", path: "fr") @@ -165,8 +165,8 @@ def test_find_site_with_site_alias site_b = Comfy::Cms::Site.create!(identifier: "site_b", hostname: "test2.host") ComfortableMexicanSofa.config.hostname_aliases = { - "test.host" => "alias_a.host", - "test2.host" => %w[alias_b.host alias_c.host] + "www.example.com" => "alias_a.host", + "test2.host" => %w[alias_b.host alias_c.host] } assert_equal site_a, Comfy::Cms::Site.find_site("alias_a.host") @@ -175,14 +175,14 @@ def test_find_site_with_site_alias end def test_url - assert_equal "//test.host", @site.url + assert_equal "//www.example.com", @site.url assert_nil @site.url(relative: true) @site.update_column(:path, "/site-path") - assert_equal "//test.host/site-path", @site.url + assert_equal "//www.example.com/site-path", @site.url ComfortableMexicanSofa.config.public_cms_path = "cms" - assert_equal "//test.host/cms/site-path", @site.url + assert_equal "//www.example.com/cms/site-path", @site.url assert_equal "/cms/site-path", @site.url(relative: true) end diff --git a/test/system/sites_test.rb b/test/system/sites_test.rb new file mode 100644 index 000000000..2861f6034 --- /dev/null +++ b/test/system/sites_test.rb @@ -0,0 +1,11 @@ +require_relative "../test_helper" + +class SitesFrontendTest < ApplicationSystemTestCase + + def test_new + visit_p new_comfy_admin_cms_site_path + fill_in("Label", with: "Test Site") + assert_equal "test-site", find_field("Identifier").value + end + +end diff --git a/test/test_helper.rb b/test/test_helper.rb index e9c5d538b..bb5f04457 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -121,12 +121,6 @@ def with_captured_stout class ActionDispatch::IntegrationTest - setup :setup_host - - def setup_host - host! "test.host" - end - # Attaching http_auth stuff with request. Example use: # r :get, '/cms-admin/pages' def r(method, path, options = {}) @@ -186,3 +180,17 @@ def read_file(filename) end end + +class ApplicationSystemTestCase < ActionDispatch::SystemTestCase + + driven_by :selenium, using: :headless_chrome, screen_size: [1400, 1400] + + # Visiting path and passing in BasicAuth credentials at the same time + # I have no idea how to set headers here. + def visit_p(path) + username = ComfortableMexicanSofa::AccessControl::AdminAuthentication.username + password = ComfortableMexicanSofa::AccessControl::AdminAuthentication.password + visit("http://#{username}:#{password}@#{Capybara.server_host}:#{Capybara.server_port}#{path}") + end + +end