-
Notifications
You must be signed in to change notification settings - Fork 0
Validate LogEntry metadata; increase flash z-index #257
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
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
4c460c1
Validate LogEntry metadata; increase flash z-index
rashusharda 74add0e
Improve validation check
rashusharda cc67f20
Fix validation error
rashusharda d263f5f
Update log_entries_controller.rb
rashusharda dc234d6
Internationalized error; simplify method name.
rashusharda fc1f095
Fix i18n healthcheck
rashusharda 2affc2d
Add i18n comment to LogEntry validator
rashusharda 10c80df
log entry: add test for model not empty and fix z-index
pranavrao145 107840e
fix date casting error
pranavrao145 72d1a73
log entry and schema: add handling for explicit false and more tests
pranavrao145 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,15 @@ | ||
| class LogEntry < ApplicationRecord | ||
| belongs_to :subproject | ||
| belongs_to :user | ||
|
|
||
| validate :not_empty | ||
|
|
||
| private | ||
|
|
||
| def not_empty | ||
| return if metadata.is_a?(Hash) && metadata.values.any? { |v| v.present? || v == false } | ||
|
|
||
| # i18n-tasks-use t('activerecord.errors.models.log_entry.attributes.base.not_empty') | ||
| errors.add(:base, :not_empty) | ||
| end | ||
| end | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,28 @@ | ||
| require "test_helper" | ||
|
|
||
| class LogEntryTest < ActiveSupport::TestCase | ||
| setup do | ||
| @project = create(:project, log_schema: { "content" => "text", "verified" => "boolean", "notes" => "text" }) | ||
| @subproject = create(:subproject, project: @project) | ||
| end | ||
|
|
||
| test "log entry is not valid if metadata is empty" do | ||
| log_entry = build(:log_entry, subproject: @subproject, metadata: {}) | ||
|
|
||
| assert_not log_entry.valid? | ||
| assert_includes log_entry.errors.full_messages, | ||
| I18n.t("activerecord.errors.models.log_entry.attributes.base.not_empty") | ||
| end | ||
pranavrao145 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| test "log entry is not valid if metadata contains only nil values" do | ||
| log_entry = build(:log_entry, subproject: @subproject, metadata: { "content" => nil, "verified" => nil }) | ||
| assert_not log_entry.valid? | ||
| assert_includes log_entry.errors.full_messages, | ||
| I18n.t("activerecord.errors.models.log_entry.attributes.base.not_empty") | ||
| end | ||
|
|
||
| test "log entry is valid if metadata contains a boolean false" do | ||
| log_entry = build(:log_entry, subproject: @subproject, metadata: { "verified" => false }) | ||
| assert log_entry.valid? | ||
| end | ||
| end | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.