survival / donation-system

:gem: Gem containing Survival's donation system logic
https://donation-system-staging.herokuapp.com/
MIT License
2 stars 3 forks source link

Think about moving the Salesforce validator one level up #34

Closed octopusinvitro closed 6 years ago

octopusinvitro commented 6 years ago

See our contributing guides.

In the Salesforce::Database class, the wiring of our business logic is implemented:

However, there is also this:

      def add_donation
        return [:missing_email] unless email_present?
        # ...
      end

      # ...

      def email_present?
        data &&
          data.respond_to?(:request_data) &&
          data.request_data.respond_to?(:email) &&
          data.request_data.email
      end

The reason for this is that the email is explicitly used in the supporter search in that class.

The input data for supporters and donations is the same, so I think this would be totally unnecessary if we merged the supporter and donation validators into one validator to use there:

      def add_donation
        return validation.errors unless validation.okay?
        # ...
      end

      # ...

      def validation
        @validation ||= Validator.execute(data)
      end

We would need to split the validation part from the field generation part and merge only the code that does the validations. Then, the two supporter and donation validators would rather be two fields-generators and be used to produce fields for each.

octopusinvitro commented 6 years ago

Fixed in #39