Skip to content

Commit c10c0e8

Browse files
Add application_form_class method to Flex::Case (#188)
## Changes - Added `application_form_class` class method to `Flex::Case` that returns the application form class name using string substitution - Updated `start_on_application_form_created` in `business_process_builder.rb` to use the new method instead of hardcoded string manipulation - Allows subclasses to override the method for custom application form naming conventions This changes allows us to have application form subclasses that aren't suffixed with ApplicationForm, such as PaidLeaveRequest or ActivityReport ## Context This change refactors hardcoded string substitution logic into a reusable class method. Previously, the business process builder was directly performing `case_class.name.sub("Case", "ApplicationFormCreated")` to generate event names. Now it calls `case_class.application_form_class` which returns the application form class name that can be customized by subclasses. The implementation maintains backward compatibility by using the same string substitution logic (`name.sub("Case", "ApplicationForm")`) as the default behavior. **Key areas for review:** - Verify the string substitution logic works correctly for all Case subclasses - Confirm that event name generation still matches what ApplicationForm classes publish - Check that the method allows appropriate subclass customization ## Testing - **Full test suite**: All 787 tests pass with 0 failures - **Linting**: All style checks pass with no offenses detected - **Event name verification**: Confirmed in Rails console that event names match correctly: - `PassportCase.application_form_class` → `"PassportApplicationForm"` - `TestCase.application_form_class` → `"TestApplicationForm"` - **Business process functionality**: PassportBusinessProcess acceptance test passes, confirming cases are created correctly when application forms are submitted The existing test suite provides good coverage for this change since it exercises the business process event handling that relies on the modified code. --- **Link to Devin run**: https://app.devin.ai/sessions/353c6623acf94683970eea40c0e23270 **Requested by**: @lorenyu Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-authored-by: Loren Yu <yuloren@gmail.com>
1 parent 9103eb0 commit c10c0e8

2 files changed

Lines changed: 11 additions & 1 deletion

File tree

app/models/flex/business_process_builder.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def start(step_name, on: nil, &handler)
5353
end
5454

5555
def start_on_application_form_created(step_name)
56-
event_name = case_class.name.sub("Case", "ApplicationFormCreated")
56+
event_name = "#{case_class.application_form_class}Created"
5757
start(step_name, on: event_name) do |event|
5858
case_class.new(application_form_id: event[:payload][:application_form_id])
5959
end

app/models/flex/case.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,16 @@ def self.base_attributes_for_generator
3030
"facts:jsonb"
3131
]
3232
end
33+
34+
# Returns the application form class name for this case class.
35+
# Subclasses can override this method to customize the application form class naming.
36+
#
37+
# @return [String] The application form class name
38+
# @example
39+
# PassportCase.application_form_class #=> "PassportApplicationForm"
40+
def self.application_form_class
41+
name.sub("Case", "ApplicationForm")
42+
end
3343
attribute :application_form_id, :uuid
3444

3545
attribute :status, :integer, default: 0

0 commit comments

Comments
 (0)