I ran into a "gotcha" on Rails Perf Testing that no Docs or 'Casts seem to mention. I couldn't figure out why my tests were being run 4 times, no matter what I passed in the runs: arg to self.profile_options. For example, if you place a puts in your test_ method, you'll see it output 4 times.
The Perf-Test code runs your test once for each "metric" it is measuring. So by constraining it to only :process_time, you can force the test to only run once.
Is this a little dangerous even with receiving a default param from routes table? Is it possible for end user to set ?commentable='arbitrary_class' in a request to create object of any class?
I think I see what he's saying. Completely remove the polymorphic association, User and MemberProfile have a simple has_one/belongs_to association, guests are stored in Users table as well, but they have no MemberProfile so the profile_id foreign key in Users is null for guests and we conditionally build a PORO for guests when a null profile_id is found.
Yes, sorry I meant GuestProfile as a PORO, not MemberProfile, as Ryan states at around 13:40 in the railscast.
It sounds like he's suggesting there would be no AR association between GuestProfile and User, that there would be a null check on profile_id in the users table and if the value was null then the app would generate a PORO in memory to handle Guest related behaviors (validations, methods, etc). But how would that PORO be bound to the relevant User record?
Curious what the MemberProfile model would look like if it were a PORO and not inheriting from AR as suggested. It could not make use of AR associations in the model, so what would that look like? Thanks for a great episode!
I ran into a "gotcha" on Rails Perf Testing that no Docs or 'Casts seem to mention. I couldn't figure out why my tests were being run 4 times, no matter what I passed in the
runs:
arg toself.profile_options
. For example, if you place aputs
in yourtest_
method, you'll see it output 4 times.The Perf-Test code runs your test once for each "metric" it is measuring. So by constraining it to only
:process_time
, you can force the test to only run once.(Process Time only applies to a Profile Test. For a Benchmark, you would do
[:wait_time]
.)Is this a little dangerous even with receiving a default param from routes table? Is it possible for end user to set ?commentable='arbitrary_class' in a request to create object of any class?
I think I see what he's saying. Completely remove the polymorphic association, User and MemberProfile have a simple has_one/belongs_to association, guests are stored in Users table as well, but they have no MemberProfile so the profile_id foreign key in Users is null for guests and we conditionally build a PORO for guests when a null profile_id is found.
Yes, sorry I meant GuestProfile as a PORO, not MemberProfile, as Ryan states at around 13:40 in the railscast.
It sounds like he's suggesting there would be no AR association between GuestProfile and User, that there would be a null check on profile_id in the users table and if the value was null then the app would generate a PORO in memory to handle Guest related behaviors (validations, methods, etc). But how would that PORO be bound to the relevant User record?
Curious what the MemberProfile model would look like if it were a PORO and not inheriting from AR as suggested. It could not make use of AR associations in the model, so what would that look like? Thanks for a great episode!