mumuki / mumuki-domain

💡 Mumuki's domain model
GNU Affero General Public License v3.0
1 stars 0 forks source link

Feature add uppercase mode #174

Closed felipecalvo closed 3 years ago

felipecalvo commented 3 years ago

:dart: Goal

Add a Preferences object to store user preferences and add the first setting, uppercase_mode. Needed for https://github.com/mumuki/mumuki-laboratory/pull/1532.

:spiral_notepad: Note for reviewers

This is very similar as to how submissions are embedded in assignments, still, please let me know if this is what you were expecting @flbulgarelli as we talked on that other pull request. I'll write some tests in the meantime.

Here is how this design works

user = User.last
=> #<User:0x0000557776f0a878
 id: 5,
 uppercase_mode: false>

user.preferences
=> #<Preferences:0x000055d33ece4d20 @uppercase_mode=false>
user = User.last
=> #<User:0x0000557776f0a878
 id: 5,
 uppercase_mode: false>

user.uppercase_mode=true
=> true

user.preferences
=> #<Preferences:0x000055d33ebe3d60 @uppercase_mode=true>
user = User.last
=> #<User:0x0000557776f0a878
 id: 5,
 uppercase_mode: false>

preferences = Preferences.new
=> #<Preferences:0x00005606976672d8>

preferences.uppercase_mode = true
=> true

user.preferences = preferences
=> #<Preferences:0x00005606976672d8 @uppercase_mode=true>

user
=> #<User:0x0000557776f0a878
 id: 5,
 uppercase_mode: true>
user = User.last
=> #<User:0x0000557776f0a878
 id: 5,
 uppercase_mode: true>

user.preferences.uppercase?
=> true
felipecalvo commented 3 years ago

We decided to keep this as-is but consider that each setting must be added three times right now - one on the list of attributes and two on the mapping. Through a similar solution to the one in Assignment composed_of submission, we can zip the list of attributes with itself, making it so we only have to write each setting once.

This will be implemented once a second setting is added