forked from fixin.me/fixin.me
Compare commits
2 Commits
feature/ex
...
feature/qu
| Author | SHA1 | Date | |
|---|---|---|---|
| 862430e586 | |||
| 3702e24153 |
84
CLAUDE.md
Normal file
84
CLAUDE.md
Normal file
@@ -0,0 +1,84 @@
|
||||
# CLAUDE.md
|
||||
|
||||
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
|
||||
|
||||
## Project Overview
|
||||
|
||||
Fixin.me is a "quantified self" Rails 7.2.3 application for personal data tracking. Users define hierarchical **quantities** (metrics to track), **units** (with optional conversion hierarchies), and **readouts** (individual measurements). There is also a non-persistent **measurement** model used as a form wrapper.
|
||||
|
||||
## Setup
|
||||
|
||||
Configuration files are distributed as `.dist` templates — copy and customize before use:
|
||||
|
||||
```bash
|
||||
cp config/application.rb.dist config/application.rb
|
||||
cp config/database.yml.dist config/database.yml
|
||||
cp config/puma.rb.dist config/puma.rb
|
||||
```
|
||||
|
||||
```bash
|
||||
bundle config --local frozen true
|
||||
bundle config --local path .gem
|
||||
bundle config --local with mysql development test # or: pg, sqlite
|
||||
bundle install
|
||||
RAILS_ENV=development bundle exec rails db:create db:migrate db:seed
|
||||
```
|
||||
|
||||
## Common Commands
|
||||
|
||||
```bash
|
||||
bundle exec rails s # start server
|
||||
bundle exec rails test # all unit/model/controller tests
|
||||
bundle exec rails test:system # all system tests (Capybara + Selenium)
|
||||
bundle exec rails test test/system/units_test.rb # single test file
|
||||
bundle exec rails test --seed 64690 --name test_add_unit # single test by name
|
||||
bundle exec rails db:seed:export # export default settings as seed file
|
||||
```
|
||||
|
||||
## Architecture
|
||||
|
||||
### Data Model
|
||||
|
||||
- **Quantity** — hierarchical tree (self-referential `parent_id`). Cached `depth` and `pathname` fields are recomputed via recursive CTEs on write. Direct assignment to cached fields is blocked.
|
||||
- **Unit** — optional hierarchy via `base_id` and `multiplier` for unit conversion. Multiplier precision/scale is validated by a custom validator.
|
||||
- **Readout** — single measurement: `value` (IEEE 754 float), `quantity`, `unit`, `category`.
|
||||
- **Measurement** — `ActiveModel::Model` form wrapper (not database-backed); bridges the readout creation form.
|
||||
- **User** — Devise-managed with a status enum: `admin`, `active`, `restricted`, `locked`, `disabled`. Admins can disguise as other users.
|
||||
|
||||
### Hierarchical Queries
|
||||
|
||||
Both `Quantity` and `Unit` use recursive CTEs for tree traversal (ordered traversal, ancestors, progenies, common ancestors). `lib/core_ext/arel/` patches Arel to support CTE with `UPDATE`/`DELETE` statements, working around Rails issue #54658.
|
||||
|
||||
### Custom Extensions (`lib/core_ext/`)
|
||||
|
||||
- **arel/** — CTE support for UPDATE/DELETE
|
||||
- **active_model/** — precision/scale validator used by `Unit#multiplier`
|
||||
- **active_record/** — `attr_cached` mechanism (see `ApplicationRecord`)
|
||||
- **action_view/** — record identifier suffixes
|
||||
- Miscellaneous: `Array#delete_bang`, `BigDecimal` scientific notation
|
||||
|
||||
### Response Handling
|
||||
|
||||
Controllers respond to both HTML and Turbo Stream formats. Errors during Turbo Stream requests trigger a redirect with flash rather than rendering inline, handled in `ApplicationController`.
|
||||
|
||||
### Numeric Precision
|
||||
|
||||
Readout values are stored as IEEE 754 double-precision floats (not fixed-point decimals). Rationale in `DESIGN.md`: biological values span many orders of magnitude; 15-digit float precision is sufficient and avoids conversion overhead.
|
||||
|
||||
### Routes
|
||||
|
||||
```
|
||||
measurements GET/POST /measurements
|
||||
readouts GET/POST /readouts, DELETE /readouts/:id/discard
|
||||
quantities CRUD + POST /quantities/:id/reparent
|
||||
units CRUD + POST /units/:id/rebase
|
||||
users CRUD + POST /users/:id/disguise, POST /users/revert
|
||||
default/ namespace for default units import/export and admin panel
|
||||
root → /units (authenticated), /sign_in (unauthenticated)
|
||||
```
|
||||
|
||||
## Database Requirements
|
||||
|
||||
The database must support:
|
||||
- Recursive CTEs with `UPDATE`/`DELETE` (MySQL ≥ 8.0, PostgreSQL, or SQLite3)
|
||||
- Decimal precision of 30+ digits
|
||||
@@ -8,6 +8,10 @@ class QuantitiesController < ApplicationController
|
||||
raise AccessForbidden unless current_user.at_least(:active)
|
||||
end
|
||||
|
||||
before_action only: [:new, :edit, :create, :update] do
|
||||
@user_units = current_user.units.ordered
|
||||
end
|
||||
|
||||
def index
|
||||
@quantities = current_user.quantities.ordered.includes(:parent, :subquantities)
|
||||
end
|
||||
|
||||
@@ -86,6 +86,7 @@ module ApplicationHelper
|
||||
def initialize(...)
|
||||
super(...)
|
||||
@default_options.merge!(@options.slice(:form))
|
||||
@default_html_options.merge!(@options.slice(:form))
|
||||
end
|
||||
|
||||
[:text_field, :password_field, :text_area].each do |selector|
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
class Quantity < ApplicationRecord
|
||||
ATTRIBUTES = [:name, :description, :parent_id]
|
||||
ATTRIBUTES = [:name, :description, :parent_id, :default_unit_id]
|
||||
attr_cached :depth, :pathname
|
||||
|
||||
belongs_to :user, optional: true
|
||||
belongs_to :parent, optional: true, class_name: "Quantity"
|
||||
belongs_to :default_unit, optional: true, class_name: "Unit"
|
||||
has_many :subquantities, ->{ order(:name) }, class_name: "Quantity",
|
||||
inverse_of: :parent, dependent: :restrict_with_error
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
class Readout < ApplicationRecord
|
||||
ATTRIBUTES = [:quantity_id, :value, :unit_id]
|
||||
ATTRIBUTES = [:quantity_id, :value, :unit_id, :taken_at]
|
||||
|
||||
belongs_to :user
|
||||
belongs_to :quantity
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
<tr class="italic">
|
||||
<td class="hexpand hmin50"><%= t '.taken_at_html' %></td>
|
||||
<td colspan="3" class="ralign">
|
||||
<%= form.datetime_field :taken_at, required: true %>
|
||||
<%= form.datetime_field :taken_at, required: true, value: Time.current.strftime('%Y-%m-%dT%H:%M') %>
|
||||
</td>
|
||||
</tr>
|
||||
<% end %>
|
||||
|
||||
@@ -8,6 +8,11 @@
|
||||
<td>
|
||||
<%= form.text_area :description, cols: 30, rows: 1, escape: false %>
|
||||
</td>
|
||||
<td>
|
||||
<%= form.collection_select :default_unit_id, @user_units, :id,
|
||||
->(u){ sanitize(' ' * (u.base_id? ? 1 : 0) + u.symbol) },
|
||||
{include_blank: true}, onchange: "this.dataset.changed = ''" %>
|
||||
</td>
|
||||
|
||||
<td class="flex">
|
||||
<%= form.button %>
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
onclick: 'this.blur();', data: {turbo_stream: true} %>
|
||||
</td>
|
||||
<td><%= quantity.description %></td>
|
||||
<td><%= quantity.default_unit&.symbol %></td>
|
||||
|
||||
<% if current_user.at_least(:active) %>
|
||||
<td class="flex">
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
<tr>
|
||||
<th><%= Quantity.human_attribute_name(:name) %></th>
|
||||
<th class="hexpand"><%= Quantity.human_attribute_name(:description) %></th>
|
||||
<th><%= Quantity.human_attribute_name(:default_unit) %></th>
|
||||
<% if current_user.at_least(:active) %>
|
||||
<th><%= t :actions %></th>
|
||||
<th></th>
|
||||
@@ -25,7 +26,7 @@
|
||||
ondragover: "dragOver(event)", ondrop: "drop(event)",
|
||||
ondragenter: "dragEnter(event)", ondragleave: "dragLeave(event)",
|
||||
data: {drop_id: "quantity_", drop_id_param: "quantity[parent_id]"} do %>
|
||||
<th colspan="4"><%= t '.top_level_drop' %></th>
|
||||
<th colspan="5"><%= t '.top_level_drop' %></th>
|
||||
<% end %>
|
||||
</thead>
|
||||
<tbody id="quantities">
|
||||
|
||||
@@ -12,10 +12,17 @@
|
||||
<td>
|
||||
<%= form.collection_select :unit_id, @user_units, :id,
|
||||
->(u){ sanitize(' ' * (u.base_id ? 1 : 0) + u.symbol) },
|
||||
{prompt: '', disabled: '', selected: ''}, required: true %>
|
||||
{prompt: '', disabled: '', selected: readout.quantity.default_unit_id || ''}, required: true,
|
||||
data: {default_unit_id: readout.quantity.default_unit_id || ''},
|
||||
onchange: "readoutUnitChanged(this)" %>
|
||||
</td>
|
||||
<td class="flex">
|
||||
<%# TODO: change to _link_ after giving up displaying relative paths %>
|
||||
<%= image_button_tag '', 'check-circle-outline',
|
||||
class: 'set-default-unit', name: nil, type: 'button', disabled: true,
|
||||
title: t('readouts.form.set_default_unit'),
|
||||
data: {path: quantity_path(readout.quantity)},
|
||||
onclick: 'setDefaultUnit(this)' %>
|
||||
<%= image_button_tag '', 'delete-outline', class: 'dangerous', name: nil,
|
||||
formaction: discard_readouts_path(readout.quantity),
|
||||
formmethod: :get, formnovalidate: true, data: {turbo_stream: true} %>
|
||||
|
||||
@@ -20,10 +20,6 @@ Bundler.require(*Rails.groups)
|
||||
|
||||
module FixinMe
|
||||
class Application < Rails::Application
|
||||
# Allow RAILS_DATABASE_YML to override the database config file path.
|
||||
# Used by the multi-database test runner (lib/tasks/test_databases.rake).
|
||||
config.paths['config/database'] = [ENV['RAILS_DATABASE_YML']] if ENV['RAILS_DATABASE_YML']
|
||||
|
||||
# Initialize configuration defaults for originally generated Rails version.
|
||||
config.load_defaults 7.0
|
||||
|
||||
|
||||
@@ -48,24 +48,3 @@ production:
|
||||
#test:
|
||||
# <<: *default
|
||||
# database: fixinme_test
|
||||
|
||||
# Multi-database testing
|
||||
# ----------------------
|
||||
# Any key starting with "test" is treated as a test database.
|
||||
# When more than one is present, EVERY test task (rails test, rails test:models,
|
||||
# rails test:system, …) automatically runs against all of them.
|
||||
#
|
||||
# The adapter gem must be available:
|
||||
# bundle config --local with "mysql sqlite" # mysql + sqlite
|
||||
# bundle config --local with "mysql pg" # mysql + postgresql
|
||||
#
|
||||
#test_sqlite:
|
||||
# adapter: sqlite3
|
||||
# database: db/fixinme_test.sqlite3
|
||||
#
|
||||
#test_pg:
|
||||
# adapter: postgresql
|
||||
# database: fixinme_test
|
||||
# username: fixinme
|
||||
# password: Some-password1%
|
||||
# host: localhost
|
||||
|
||||
@@ -58,4 +58,7 @@ 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
|
||||
|
||||
@@ -11,8 +11,13 @@ en:
|
||||
activerecord:
|
||||
attributes:
|
||||
quantity:
|
||||
default_unit: Default unit
|
||||
description: Description
|
||||
name: Name
|
||||
readout:
|
||||
created_at: Recorded at
|
||||
taken_at: Taken at
|
||||
value: Value
|
||||
unit:
|
||||
base: Base unit
|
||||
description: Description
|
||||
@@ -81,6 +86,9 @@ en:
|
||||
revert: Revert
|
||||
sign_out: Sign out
|
||||
source_code: Get code
|
||||
readouts:
|
||||
form:
|
||||
set_default_unit: Set as default unit
|
||||
measurements:
|
||||
navigation: Measurements
|
||||
no_items: There are no measurements taken. You can Add some now.
|
||||
@@ -89,6 +97,15 @@ en:
|
||||
taken_at_html: Measurement taken at 
|
||||
index:
|
||||
new_measurement: Add measurement
|
||||
readout:
|
||||
destroy: Delete
|
||||
create:
|
||||
success:
|
||||
one: Recorded 1 measurement.
|
||||
other: Recorded %{count} measurements.
|
||||
no_readouts: No readouts selected.
|
||||
destroy:
|
||||
success: Measurement deleted.
|
||||
quantities:
|
||||
navigation: Quantities
|
||||
no_items: There are no configured quantities. You can Add some or Import from defaults.
|
||||
|
||||
6
db/migrate/20260402000000_add_taken_at_to_readouts.rb
Normal file
6
db/migrate/20260402000000_add_taken_at_to_readouts.rb
Normal file
@@ -0,0 +1,6 @@
|
||||
class AddTakenAtToReadouts < ActiveRecord::Migration[7.2]
|
||||
def change
|
||||
add_column :readouts, :taken_at, :datetime
|
||||
add_index :readouts, [:user_id, :taken_at]
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,5 @@
|
||||
class AddDefaultUnitToQuantities < ActiveRecord::Migration[7.2]
|
||||
def change
|
||||
add_reference :quantities, :default_unit, foreign_key: {to_table: :units}, null: true
|
||||
end
|
||||
end
|
||||
@@ -10,7 +10,7 @@
|
||||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema[7.2].define(version: 2025_01_21_230456) do
|
||||
ActiveRecord::Schema[7.2].define(version: 2026_04_03_000000) do
|
||||
create_table "quantities", charset: "utf8mb4", collation: "utf8mb4_0900_as_ci", force: :cascade do |t|
|
||||
t.bigint "user_id"
|
||||
t.string "name", limit: 31, null: false
|
||||
@@ -20,6 +20,8 @@ ActiveRecord::Schema[7.2].define(version: 2025_01_21_230456) do
|
||||
t.datetime "updated_at", null: false
|
||||
t.integer "depth", default: 0, null: false
|
||||
t.string "pathname", limit: 511, null: false
|
||||
t.bigint "default_unit_id"
|
||||
t.index ["default_unit_id"], name: "index_quantities_on_default_unit_id"
|
||||
t.index ["parent_id"], name: "index_quantities_on_parent_id"
|
||||
t.index ["user_id", "parent_id", "name"], name: "index_quantities_on_user_id_and_parent_id_and_name", unique: true
|
||||
t.index ["user_id"], name: "index_quantities_on_user_id"
|
||||
@@ -32,10 +34,12 @@ ActiveRecord::Schema[7.2].define(version: 2025_01_21_230456) do
|
||||
t.decimal "value", precision: 30, scale: 15, null: false
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.datetime "taken_at"
|
||||
t.index ["quantity_id", "created_at"], name: "index_readouts_on_quantity_id_and_created_at", unique: true
|
||||
t.index ["quantity_id"], name: "index_readouts_on_quantity_id"
|
||||
t.index ["unit_id"], name: "index_readouts_on_unit_id"
|
||||
t.index ["user_id"], name: "index_readouts_on_user_id"
|
||||
t.index ["user_id", "taken_at"], name: "index_readouts_on_user_id_and_taken_at"
|
||||
end
|
||||
|
||||
create_table "units", charset: "utf8mb4", collation: "utf8mb4_0900_as_ci", force: :cascade do |t|
|
||||
@@ -70,6 +74,7 @@ ActiveRecord::Schema[7.2].define(version: 2025_01_21_230456) do
|
||||
end
|
||||
|
||||
add_foreign_key "quantities", "quantities", column: "parent_id", on_delete: :cascade
|
||||
add_foreign_key "quantities", "units", column: "default_unit_id"
|
||||
add_foreign_key "quantities", "users"
|
||||
add_foreign_key "readouts", "quantities"
|
||||
add_foreign_key "readouts", "units"
|
||||
|
||||
@@ -1,158 +0,0 @@
|
||||
require 'yaml'
|
||||
require 'erb'
|
||||
require 'tmpdir'
|
||||
|
||||
# Multi-database test runner
|
||||
# ==========================
|
||||
# When database.yml contains more than one `test*` configuration, every
|
||||
# standard test task (test, test:models, test:system, …) is automatically
|
||||
# rewritten to run the full suite against EACH configured database in turn.
|
||||
#
|
||||
# Convention — any top-level key that starts with "test" and holds a Hash:
|
||||
#
|
||||
# test: ← required primary database
|
||||
# adapter: mysql2
|
||||
# database: fixinme_test
|
||||
# ...
|
||||
#
|
||||
# test_sqlite: ← optional additional databases
|
||||
# adapter: sqlite3
|
||||
# database: db/fixinme_test.sqlite3
|
||||
#
|
||||
# test_pg:
|
||||
# adapter: postgresql
|
||||
# ...
|
||||
#
|
||||
# A single-database setup is unchanged: every task behaves exactly as before.
|
||||
#
|
||||
# The mechanism uses RAILS_DATABASE_YML — an env var read by
|
||||
# config/application.rb(.dist) to override Rails' database config path before
|
||||
# initialisation, giving each subprocess a clean, isolated database config.
|
||||
|
||||
module MultiDbTests
|
||||
ADAPTER_GEMS = {
|
||||
'mysql2' => 'mysql2',
|
||||
'sqlite3' => 'sqlite3',
|
||||
'postgresql' => 'pg',
|
||||
'pg' => 'pg',
|
||||
}.freeze
|
||||
|
||||
ADAPTER_BUNDLE_GROUPS = {
|
||||
'mysql2' => 'mysql',
|
||||
'sqlite3' => 'sqlite',
|
||||
'postgresql' => 'postgresql',
|
||||
'pg' => 'postgresql',
|
||||
}.freeze
|
||||
|
||||
# Rake task names generated by railties/lib/rails/test_unit/testing.rake
|
||||
# that use run_from_rake — these are the ones we rewrite.
|
||||
WRAPPED_TASKS = (
|
||||
['test'] +
|
||||
Rails::TestUnit::Runner::TEST_FOLDERS.map { |f| "test:#{f}" } +
|
||||
%w[test:all test:system test:generators test:units test:functionals]
|
||||
).freeze
|
||||
|
||||
class << self
|
||||
# Returns {name => config_hash} for every key starting with "test".
|
||||
def test_configs
|
||||
@test_configs ||= begin
|
||||
db_file = Rails.root.join('config', 'database.yml')
|
||||
all = YAML.safe_load(ERB.new(db_file.read).result, aliases: true) || {}
|
||||
all.select { |k, v| k.to_s.start_with?('test') && v.is_a?(Hash) }
|
||||
end
|
||||
end
|
||||
|
||||
def non_test_configs
|
||||
@non_test_configs ||= begin
|
||||
db_file = Rails.root.join('config', 'database.yml')
|
||||
all = YAML.safe_load(ERB.new(db_file.read).result, aliases: true) || {}
|
||||
all.reject { |k, _| k.to_s.start_with?('test') }
|
||||
end
|
||||
end
|
||||
|
||||
# Run rails +task_name+ for every configured test database.
|
||||
# Called from the rewritten rake task actions.
|
||||
def run(task_name)
|
||||
cfgs = test_configs
|
||||
results = {}
|
||||
|
||||
cfgs.each do |db_name, config|
|
||||
adapter = config['adapter'].to_s
|
||||
puts "\n#{'─' * 64}"
|
||||
puts " #{task_name} · #{db_name} (#{adapter})"
|
||||
puts '─' * 64
|
||||
|
||||
unless adapter_available?(adapter)
|
||||
warn " SKIPPED — '#{adapter}' gem not in bundle.\n" \
|
||||
" Run: bundle config --local with \"#{current_with} #{adapter_group(adapter)}\""
|
||||
results[db_name] = :skipped
|
||||
next
|
||||
end
|
||||
|
||||
Dir.mktmpdir('rails_test_') do |tmpdir|
|
||||
tmp_yml = File.join(tmpdir, 'database.yml')
|
||||
File.write(tmp_yml, non_test_configs.merge('test' => config).to_yaml)
|
||||
env = { 'RAILS_DATABASE_YML' => tmp_yml }
|
||||
|
||||
if system(env, 'bundle exec rails db:test:prepare')
|
||||
results[db_name] = system(env, 'rails', task_name) ? :pass : :fail
|
||||
else
|
||||
results[db_name] = :prepare_failed
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
print_summary(cfgs, results)
|
||||
|
||||
failed = results.count { |_, s| [:fail, :prepare_failed].include?(s) }
|
||||
exit(false) if failed > 0
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def adapter_available?(adapter)
|
||||
require ADAPTER_GEMS.fetch(adapter, adapter)
|
||||
true
|
||||
rescue LoadError
|
||||
false
|
||||
end
|
||||
|
||||
def adapter_group(adapter)
|
||||
ADAPTER_BUNDLE_GROUPS.fetch(adapter, adapter)
|
||||
end
|
||||
|
||||
def current_with
|
||||
(Bundler.settings[:with] || '').split(':').join(' ')
|
||||
end
|
||||
|
||||
def print_summary(cfgs, results)
|
||||
return if results.size <= 1 # no summary for single-DB runs
|
||||
|
||||
puts "\n#{'═' * 64}"
|
||||
puts ' SUMMARY'
|
||||
puts '═' * 64
|
||||
results.each do |db_name, status|
|
||||
adapter = cfgs.dig(db_name, 'adapter') || '?'
|
||||
icon = status == :pass ? '✓' : (status == :skipped ? '–' : '✗')
|
||||
label = { pass: 'PASS', fail: 'FAIL',
|
||||
prepare_failed: 'PREPARE FAILED', skipped: 'SKIPPED' }[status]
|
||||
puts " #{icon} #{db_name.ljust(26)} (#{adapter.ljust(12)}) #{label}"
|
||||
end
|
||||
puts '═' * 64
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Rewrite every standard test task to run against all configured databases.
|
||||
# This file loads after railties/testing.rake, so all tasks already exist.
|
||||
# Single-database setups are completely unaffected.
|
||||
if MultiDbTests.test_configs.size > 1
|
||||
MultiDbTests::WRAPPED_TASKS.each do |task_name|
|
||||
next unless Rake::Task.task_defined?(task_name)
|
||||
|
||||
Rake::Task[task_name].clear_actions
|
||||
Rake::Task[task_name].enhance do
|
||||
MultiDbTests.run(task_name)
|
||||
end
|
||||
end
|
||||
end
|
||||
45
test/system/quantities_test.rb
Normal file
45
test/system/quantities_test.rb
Normal file
@@ -0,0 +1,45 @@
|
||||
require "application_system_test_case"
|
||||
|
||||
class QuantitiesTest < ApplicationSystemTestCase
|
||||
setup do
|
||||
@user = sign_in(user: users(:alice))
|
||||
@unit = @user.units.create!(symbol: 'kg')
|
||||
@quantity = @user.quantities.create!(name: 'Weight')
|
||||
visit quantities_path
|
||||
end
|
||||
|
||||
test "update button turns red when default unit changes" do
|
||||
click_on 'Weight'
|
||||
|
||||
button = find('button[name=button]')
|
||||
initial_color = evaluate_script("getComputedStyle(arguments[0]).backgroundColor", button)
|
||||
|
||||
select 'kg', from: 'quantity[default_unit_id]'
|
||||
|
||||
changed_color = evaluate_script("getComputedStyle(arguments[0]).backgroundColor", button)
|
||||
refute_equal initial_color, changed_color, "Button color should change when default unit is altered"
|
||||
end
|
||||
|
||||
test "saving default unit pre-selects it in measurements form" do
|
||||
click_on 'Weight'
|
||||
select 'kg', from: 'quantity[default_unit_id]'
|
||||
click_on t('helpers.submit.update')
|
||||
assert_selector '.flash.notice'
|
||||
|
||||
@quantity.reload
|
||||
assert_equal @unit.id, @quantity.default_unit_id
|
||||
|
||||
visit measurements_path
|
||||
find(:link_or_button, t('measurements.index.new_measurement')).click
|
||||
assert_selector '#measurement_form'
|
||||
|
||||
within '#quantity_select' do
|
||||
check 'Weight'
|
||||
end
|
||||
find('button[formaction]').click
|
||||
|
||||
within 'tbody#readouts' do
|
||||
assert_selector "option[value='#{@unit.id}'][selected]"
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -229,7 +229,7 @@ class UsersTest < ApplicationSystemTestCase
|
||||
user = User.find_by_email!(first(:link).text)
|
||||
inject_button_to first('td:not(.link)'), "update status", user_path(user), method: :patch,
|
||||
params: {user: {status: User.statuses.keys.sample}}, data: {turbo: false}
|
||||
click_on "update status"
|
||||
execute_script("arguments[0].click()", find_button("update status"))
|
||||
end
|
||||
assert_title 'The change you wanted was rejected (422)'
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user