Compare commits

..

3 Commits

9 changed files with 93 additions and 30 deletions

View File

@@ -231,12 +231,17 @@ textarea:invalid {
text-decoration: underline 1px var(--color-border-gray);
text-underline-offset: 0.25em;
}
[name=cancel],
.auxiliary {
border-color: var(--color-border-gray);
border-color: var(--color-nav-gray);
color: var(--color-nav-gray);
fill: var(--color-nav-gray);
}
table .button {
border-color: var(--color-border-gray);
font-weight: normal;
height: 100%;
padding: 0.4em;
}
.button:focus-visible,
.tab:focus-visible,
.tab:hover {
@@ -259,13 +264,6 @@ textarea:invalid {
color: var(--color-blue);
text-decoration-color: var(--color-blue);
}
table .button {
border-color: var(--color-border-gray);
color: var(--color-table-gray);
font-weight: normal;
height: 100%;
padding: 0.4em;
}
/* NOTE: collapse gaps around empty rows (`topside`) once possible with
@@ -360,20 +358,20 @@ header {
line-height: 2.2em;
pointer-events: auto;
}
.flash:before {
filter: invert();
.flash::before {
filter: invert(1);
height: 1.4em;
margin: 0 0.5em;
width: 1.4em;
}
.flash.alert:before {
.flash.alert::before {
content: url('pictograms/alert-outline.svg');
}
.flash.alert {
border-color: var(--color-red);
background-color: var(--color-red);
}
.flash.notice:before {
.flash.notice::before {
content: url('pictograms/check-circle-outline.svg');
}
.flash.notice {
@@ -437,15 +435,18 @@ header {
.tabular-form table {
border: none;
border-spacing: 0.4em 0;
margin-inline: -0.4em;
border-spacing: 0;
}
.tabular-form table td {
border: none;
padding-inline-start: 0.4em;
vertical-align: middle;
}
.tabular-form table td {
padding-inline: 0;
.tabular-form table td:first-child {
padding-inline-start: 0;
}
.tabular-form table td:last-child {
padding-inline-end: 0;
}
.tabular-form table :is(form, input, select, textarea):only-child {
margin-inline-start: 0;

View File

@@ -33,7 +33,7 @@
<div class="flex reverse">
<%= form.button id: :create_measurement_button, disabled: true -%>
<%= image_link_to t(:cancel), "close-outline", measurements_path, name: :cancel,
class: 'dangerous', onclick: render_turbo_stream('form_close') %>
class: 'auxiliary dangerous', onclick: render_turbo_stream('form_close') %>
</div>
<% end %>

View File

@@ -1,4 +1,5 @@
#!/usr/bin/env ruby
APP_PATH = File.expand_path("../config/application", __dir__)
require_relative "../config/boot"
require_relative "../lib/core_ext/test_multiple_adapters.rb"
require "rails/commands"

View File

@@ -42,9 +42,24 @@ production:
# <<: *default
# database: fixinme_dev
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
# Warning: Test databases will be erased and re-generated from your development
# database when you run "rake". Do not set these dbs to the same as development
# or production.
#
# Multiple test databases can be provided. When more than one test db is
# present, every test task (test, test:models, test:system, etc.) automatically
# runs against all of them.
#
# In additional test databases only "adapter", "database", "host", "port" and
# "socket" settings are used. All settings default to values specified in
# "test" - which is required in all test setups.
#test:
# <<: *default
# database: fixinme_test
#
#test_sqlite3:
# adapter: sqlite3
# database: db/fixinme_test.sqlite3
#
#test_postgresql:
# adapter: postgresql

View File

@@ -58,7 +58,4 @@ Rails.application.configure do
# config.action_view.annotate_rendered_view_with_filenames = true
config.log_level = :info
# Allow Capybara's dynamic test server host (127.0.0.1:<random_port>)
config.hosts << '127.0.0.1'
end

View File

@@ -0,0 +1,42 @@
require "byebug"
module CoreExt
module TestMultipleAdapters
def perform(...)
#require APP_PATH
$LOAD_PATH << Rails::Command.root.join("test").to_s
require "test_helper"
Rails.application.config.database_configuration.each_pair do |name, config|
next unless name.start_with?('test_')
puts config['adapter']
ENV['DATABASE_URL'] = dbconfig_to_url(config)
byebug
super
end
end
alias_method :test, :perform
private
def dbconfig_to_url(cfg)
return cfg['url'] if cfg.has_key?("url")
config = cfg.transform_values { |v| URI.encode_www_form_component(v) }
username, password = config.delete('username'), config.delete('password')
auth = username ? "#{username}:#{password}" : ''
host, port = config.delete('host'), config.delete('port')
server = port ? "#{host}:#{port}" : host
url = "#{config.delete('adapter')}:"
url += "//#{auth}@#{server}" if auth || server
url += "/#{config.delete('database')}"
url += "?#{config.map { |k,v| "#{k}=#{v}" }.join('&')}" unless config.empty?
end
end
end
#require "rails/commands/test/test_command"
#Rails::Command::TestCommand.prepend CoreExt::TestMultipleAdapters

View File

@@ -25,9 +25,10 @@ class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
user
end
def inject_button_to(after, *button_options)
def inject_button_to(inside, *button_options)
button = button_to *button_options
evaluate_script("arguments[0].insertAdjacentHTML('beforeend', '#{button.html_safe}');", after)
inside.evaluate_script("this.insertAdjacentHTML('beforeend', arguments[0]);",
button.html_safe)
end
# Allow skipping interpolations when translating for testing purposes
@@ -55,4 +56,8 @@ class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
# find('a[disabled]').click
# end
#end
# TODO: override #test, creating per-adapter test methods running within
# #with_connection?
# define shards for test database
end

View File

@@ -2,7 +2,7 @@ require "test_helper"
class UsersControllerTest < ActionDispatch::IntegrationTest
setup do
@user = users(:one)
@user = users(:admin)
end
test "should get index" do

View File

@@ -6,6 +6,7 @@ class UsersTest < ApplicationSystemTestCase
end
test 'sign in' do
byebug
visit root_url
assert find_link(href: new_user_session_path)[:disabled]
@@ -227,7 +228,8 @@ class UsersTest < ApplicationSystemTestCase
within all(:xpath, "//tbody//tr[not(descendant::select)]").sample do |tr|
user = User.find_by_email!(first(:link).text)
inject_button_to first('td:not(.link)'), "update status", user_path(user), method: :patch,
inject_button_to find('td', exact_text: user.status), "update status",
user_path(user), method: :patch,
params: {user: {status: User.statuses.keys.sample}}, data: {turbo: false}
click_on "update status"
end
@@ -237,8 +239,8 @@ class UsersTest < ApplicationSystemTestCase
test 'update status forbidden for non admin' do
sign_in user: users.reject(&:admin?).select(&:confirmed?).sample
visit units_path
inject_button_to find('body'), "update status", user_path(User.all.sample), method: :patch,
params: {user: {status: User.statuses.keys.sample}}
inject_button_to find('body'), "update status", user_path(User.all.sample),
method: :patch, params: {user: {status: User.statuses.keys.sample}}
click_on "update status"
assert_text t('actioncontroller.exceptions.status.forbidden')
end