Skip to content
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

Updated COLUMN_PATTERN to handle optional metadata (e.g., constraints or descriptions) enclosed in parentheses. #170

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

hatsu38
Copy link

@hatsu38 hatsu38 commented Dec 1, 2024

Before: Try fail Regex Link https://rubular.com/r/fMCSHSUICtyUIN
After: Try pass Regex LInk https://rubular.com/r/nwANf5UyNf7OhB

ISSUE

close #169

Summary

AnnotateRb was not working when column comments included characters like / or non-English characters such as Japanese.

This PR resolves the issue by extending the regular expression to support a wider range of characters in the metadata inside parentheses.

Before

COLUMN_PATTERN = /^#[\t ]+[\w*.`\[\]():]+(?:\(.*?\))?[\t ]+.+$/

With this regular expression, the test cases added in this pull request fail.

 be rspec spec/lib/annotate_rb/model_annotator/annotation_diff_generator_spec.rb:146
Run options: include {:locations=>{"./spec/lib/annotate_rb/model_annotator/annotation_diff_generator_spec.rb"=>[146]}}

Randomized with seed 43894

AnnotateRb::ModelAnnotator::AnnotationDiffGenerator
  .call
    when a new column with metadata in parentheses is added
      returns an AnnotationDiff object with the expected old and new columns (FAILED - 1)

Failures:

  1) AnnotateRb::ModelAnnotator::AnnotationDiffGenerator.call when a new column with metadata in parentheses is added returns an AnnotationDiff object with the expected old and new columns
     Failure/Error: expect(resulting_new_columns_data).to eq(expected_new_columns_data)
     
       expected: ["#id:bigintnotnull,primarykey", "#name([sensitivity:medium]):string(50)notnull", "#status(active/pending/inactive):stringnotnull", "#Tablename:users"]
            got: ["#id:bigintnotnull,primarykey", "#name([sensitivity:medium]):string(50)notnull", "#Tablename:users"]
     
       (compared using ==)
     # ./spec/lib/annotate_rb/model_annotator/annotation_diff_generator_spec.rb:13:in `test_columns_match_expected'
     # ./spec/lib/annotate_rb/model_annotator/annotation_diff_generator_spec.rb:190:in `block (4 levels) in <top (required)>'
     # ./vendor/bundle/ruby/3.3.0/gems/aruba-2.1.0/lib/aruba/rspec.rb:38:in `block (2 levels) in <top (required)>'
     # ./vendor/bundle/ruby/3.3.0/gems/aruba-2.1.0/lib/aruba/rspec.rb:25:in `block (2 levels) in <top (required)>'

Finished in 0.00954 seconds (files took 0.38138 seconds to load)
1 example, 1 failure

Failed examples:

rspec ./spec/lib/annotate_rb/model_annotator/annotation_diff_generator_spec.rb:189 # AnnotateRb::ModelAnnotator::AnnotationDiffGenerator.call when a new column with metadata in parentheses is added returns an AnnotationDiff object with the expected old and new columns

Randomized with seed 43894

After

COLUMN_PATTERN = /^#[\t ]+[\w*.`\[\]():]+(?:\(.*?\))?[\t ]+.+$/

With this updated regular expression, the test cases added in this pull request pass.

 be rspec spec/lib/annotate_rb/model_annotator/annotation_diff_generator_spec.rb:146
Run options: include {:locations=>{"./spec/lib/annotate_rb/model_annotator/annotation_diff_generator_spec.rb"=>[146]}}

Randomized with seed 57719

AnnotateRb::ModelAnnotator::AnnotationDiffGenerator
  .call
    when a new column with metadata in parentheses is added
      returns an AnnotationDiff object with the expected old and new columns

Finished in 0.00285 seconds (files took 0.65977 seconds to load)
1 example, 0 failures

Randomized with seed 57719

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Model Annotation Not Updated When Modifying Table Columns Using change_table.
1 participant