Skip to content

Commit

Permalink
got system tests working
Browse files Browse the repository at this point in the history
  • Loading branch information
GBH committed Dec 23, 2017
1 parent b2583eb commit d6d936e
Show file tree
Hide file tree
Showing 11 changed files with 54 additions and 34 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ db/test.sqlite3-journal
pkg
rdoc
/tmp
public/*
public/system/
Gemfile.lock
.rvmrc
.ruby-version
Expand Down
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Binary file added public/favicon.ico
Binary file not shown.
2 changes: 1 addition & 1 deletion test/controllers/comfy/admin/cms/sites_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/comfy/cms/sites.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
default:
label: Default Site
identifier: default-site
hostname: test.host
hostname: www.example.com
path:
2 changes: 1 addition & 1 deletion test/integration/seeds_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
<html>
<body>
Expand Down
12 changes: 6 additions & 6 deletions test/integration/sites_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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")
Expand Down
12 changes: 6 additions & 6 deletions test/models/page_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -487,17 +487,17 @@ 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)
end

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)
Expand Down
24 changes: 12 additions & 12 deletions test/models/site_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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")
Expand All @@ -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")
Expand All @@ -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
Expand Down
11 changes: 11 additions & 0 deletions test/system/sites_test.rb
Original file line number Diff line number Diff line change
@@ -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
20 changes: 14 additions & 6 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {})
Expand Down Expand Up @@ -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

0 comments on commit d6d936e

Please sign in to comment.