-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Constructors validations #948
base: calculators-constructor
Are you sure you want to change the base?
Conversation
app/validators/field_validator.rb
Outdated
|
||
return if used_in_any_formula | ||
|
||
record.errors.add(:var_name, "field isn't used in any formula") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
юзай локалізацію, думаю передай тут символ та додай переклад ключа в локалях
app/validators/field_validator.rb
Outdated
|
||
def field_is_part_of_any_formula(record) | ||
used_in_any_formula = record.calculator.formulas.any? do |formula| | ||
formula.expression.scan(/\b[a-zA-Z_]\w*\b/).uniq.include?(record.var_name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
винеси регексп в константу
app/validators/formula_validator.rb
Outdated
|
||
def fields_are_included_in_formulas(record) | ||
field_names = record.calculator.fields.map(&:var_name) | ||
formula_variables = record.expression.scan(/\b[a-zA-Z_]\w*\b/).uniq |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
теж в константу
app/validators/formula_validator.rb
Outdated
|
||
return if unused_fields.blank? | ||
|
||
record.errors.add(:expression, "requires fields #{unused_fields.join(', ')} to be initialized") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
теж локалізація
spec/models/formula_spec.rb
Outdated
calculator.fields.build(var_name: "a") | ||
calculator.fields.build(var_name: "b") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
before do end
spec/models/field_spec.rb
Outdated
@@ -52,6 +45,19 @@ | |||
is_expected.to define_enum_for(:unit) | |||
.with_values([:day, :week, :month, :year, :date, :times, :money, :items]) | |||
} | |||
|
|||
it "is valid when field is used in any of calculators formulas" do | |||
calculator.formulas.build(expression: "a + b") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
before
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## calculators-constructor #948 +/- ##
===========================================================
- Coverage 83.98% 80.57% -3.42%
===========================================================
Files 65 65
Lines 974 978 +4
===========================================================
- Hits 818 788 -30
- Misses 156 190 +34 ☔ View full report in Codecov by Sentry. 🚨 Try these New Features:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- темплейт не заповнений
- перший левел - ревʼю тіми (не проведений)
- евіденсів нема
@@ -6,6 +6,7 @@ | |||
|
|||
<!-- formula input--> | |||
<div id="formulas" class="space-y-4"> | |||
<%= f.error_notification message: f.object.errors[:formulas].to_sentence if f.object.errors[:formulas].present? %> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
навіщо це? точно потрібно? також де скріншот, як це виглядає?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
коменти написав вище
part of: #359
Code reviewers
Second Level Review
Summary of issue
There is no validations for constructors models
Summary of change
Created new validations for formula and field models
CHECK LIST