Kasper Timm Hansen
Gem walkthrough: active_record-associated_object & Oaken

Summarized using AI

Gem walkthrough: active_record-associated_object & Oaken

Kasper Timm Hansen • June 22, 2022 • online

In the video titled "Gem walkthrough: activerecord-associatedobject & Oaken," seasoned Ruby developer Kasper Timm Hansen presents a detailed exploration of his two Ruby on Rails gems: activerecord-associatedobject and Oaken. This session, aimed at Ruby developers, provides valuable insights into managing complex data relationships and simplifying database interactions within Rails applications.

Key Points Discussed:

  • ActiveRecord Associated Object:

    • This gem helps organize service objects by introducing a way to create collaborator objects associated with ActiveRecord models.
    • It aims to declutter application directories by managing these collaborators more effectively.
    • Developers can define behaviors such as publishing posts through a structured approach, encapsulating logic within dedicated files instead of cluttering the main model.
    • The gem allows for the automatic management of dependencies and supports callback handling, enhancing code organization.
  • Examples of Use:

    • Kasper shares feedback from other developers who successfully implemented this gem in billing and entitlement systems, highlighting its ability to streamline and provide clarity within codebases.
    • He notes that the gem is lightweight, allowing it to coexist with existing service objects and concerns, particularly enhancing code organization without imposing a strict framework.
  • Oaken Gem:

    • Oaken attempts to redefine how developers use fixtures and factories in testing by improving on their limitations.
    • The gem focuses on a seed-based approach for both development and testing datasets, which allows better management of data relationships and structure.
    • Developers can prepare their database using seeds that establish essential relationships while maintaining the ability to write clean, concise test code.
    • This approach promotes better discoverability and organization of data, reducing confusion associated with traditional fixture and factory management.

Conclusion:

Kasper emphasizes the importance of maintaining organization as Rails applications grow, advocating for a structured approach to coding practices with these gems. By utilizing activerecord-associatedobject, developers can enhance the clarity and organization of their code. Meanwhile, Oaken offers a modernized approach to testing that encourages developers to think critically about data relationships within their applications. Both gems provide tools for maintaining manageable, readable, and maintainable code in scalable applications, making them valuable additions to any Ruby on Rails toolkit.

Gem walkthrough: active_record-associated_object & Oaken
Kasper Timm Hansen • June 22, 2022 • online

Kasper Timm Hansen, is a seasoned Ruby developer and a core contributor to the Ruby on Rails framework between 2016-2022. He has made significant contributions to the Ruby community, particularly through his work on various gems that enhance the functionality of Rails.

In this session, Kasper will walk us through some of his popular gems, active_record-associated_object and oaken. He will explore how these tools can help developers manage complex data relationships and simplify database interactions in their Ruby on Rails applications.

Ruby Türkiye Meetup

00:00:02.679 okay this stage is yours perfect yeah okay well hey
00:00:08.040 everybody I'm Casper uh us be realore team and today I'm going to talk about a few gems I've written and been working
00:00:14.000 on for a while and just showing them off for a bit and then I probably taking some questions if there's anybody that
00:00:19.600 wants to ask anything so um let's see and then I got to find a share screen button oh host disabl participant screen
00:00:28.199 sharing wait a minute wait wait wait a minute the the zoom zoom change whole Ur
00:00:33.760 and yes holy okay
00:00:39.480 um yes advanc options well yeah I guess you have the L now okay yeah this looks
00:00:47.000 like let's see think we probably start with this one can we
00:00:52.399 share shift like multiple windows let's it's probably just good from now okay
00:00:57.520 see that one so this is the let's start here okay thens just took out my screen with a bunch of UI can
00:01:03.600 you let's see here we go yeah you can see it I just need to move some stuff around so I can also read what's going
00:01:10.320 on so that's good okay let's see if we do this actually that might be easier for me okay I think that's good cool so
00:01:17.320 the first thing I've working on is called act regular Associated object um the idea is well let's scroll down so
00:01:24.079 the idea is that as R applications grow it becomes a little bit difficult to figure out where you want to put things and so one of the responses has been to
00:01:30.400 use service objects where you get like an app Services directory and start Turing things in there but then
00:01:35.640 sometimes what can happen is that it can kind of just like an app models directory with actual records and other
00:01:42.280 POR in there can kind of get a little bit junky sometimes that can also become a junk drawer so what I'm trying to do
00:01:48.520 is kind of take that head on in a way and try to do something a little bit different but not in a way that's so
00:01:54.520 overt that you need to convert your whole app to use and always use this or whatever it's just one thing to help you
00:02:01.880 tease out these collaborator objects as I call them um for your active record models so they're for the most part
00:02:08.039 playing old Ruby objects but then you just sort of require that you associate with active record model so here for
00:02:13.680 instance you have a post haris from application record and then what you can do with that is then within the post
00:02:21.519 namespace have an extra file in here that you then inherit from this act recular Associated object for it and
00:02:27.400 then part of what that gives you is namespace automatically so you are starting to hopefully be a little bit
00:02:33.080 more organized and then you contr control any dependent logic in here and this publisher has access to the post
00:02:38.920 and then what you want to do after you've done that is hop back into the post and declare that it's there and I'll just give you a post. publisher
00:02:45.599 let's see and then this is a little bit of explainer for that what it works behind the scenes simpy but we don't
00:02:51.280 really need to get into that for right now uh and there's some more stuff about what we can do with how to name things
00:02:57.800 and uh pluralization there I think what else is valid let's look more
00:03:03.400 what it actually does So within this now it can rely on the post itself so for instance you could take and then Define
00:03:10.200 you have a publisher maybe it makes sense to then that it defines handling how to publish this post and like a blogging system so you have access to
00:03:17.720 just calling transaction which delegates to the post essentially uh and then you can do other of stuff the way you want
00:03:23.080 to muck with the post itself the idea being that now you're encapsulating a slightly more tightly scoped name to
00:03:30.799 just a part of the app as opposed to also littering it in with the post itself um I think I can say this
00:03:38.560 depending on when this goes out on YouTube someone else has been trying to use this for um I heard from a few people that have been using this for
00:03:44.760 their billing and entitlements and so forth and how to split those things up and they've been using thism to essentially help them carve out and give
00:03:51.519 it a slightly nicer namespace API for some of the things they're doing to organize the code itself it's not
00:03:57.280 required for the work that we're doing but it was a kind of EAS fit so um let's
00:04:03.159 see there's a generator we ship with as well to help set them up correctly kind of let's see there's something else I
00:04:10.120 feel like I wanted to show but it's kind of where is it running from uh
00:04:17.079 see what is there's something else I feel like I'm missing here but maybe I just read me let's start okay let's just
00:04:22.800 take it from the next part so the other thing I wanted to try to experiment with is like I know you know there's mixed
00:04:30.080 feelings on callbacks or whatever I just thought it was interesting once having this declaration that you could then do more stuff with that because one of the
00:04:36.639 things I like about this is to try to have I want more bang for my buck
00:04:42.320 essentially so when a gem comes in sets up a little bit of an extra convention on top of rails I want to get more out
00:04:47.880 of following that essentially which here means you could also pass these callbacks along for instance so we want
00:04:53.759 to make sure that this after prate commit just calls published and we want to make sure we always do that on the post something you could do that for
00:04:59.199 instance is what it would look like you could also from within uh one of these delegated callbacks to throw abort so
00:05:06.199 you can you know abort if you need to based on I guess you know whatever business rules you want
00:05:12.000 um let's see uh yeah you could also extend so
00:05:18.080 part is this also springing out of what some people have been doing which is a Convention of let's see if I I'm
00:05:23.360 actually showing it here where you take some sort of name and wrap it in a concern and then you all this included
00:05:30.560 stuff you do these class methods and then you can also add your instance methods there and then you include this within the post up here
00:05:38.560 um but then with Associated object what you could do is instead have this one so
00:05:45.759 what people are trying to do with these concerns is they're wrapping a bunch of methods to help them make the
00:05:51.479 integration layer between you know um some Behavior they have and then the the
00:05:56.800 hosting object which in this case is the post and that can be fine but then when
00:06:01.880 you're mixing in another plal essentially suddenly we have two different files to find a behavior and so what we're trying to do with this
00:06:07.599 extension method is kind of it's mostly just syntactic suker essentially for this um but now it means you only have
00:06:15.440 to look in one file and so has object basically this declaration just eally loads the class which means that then
00:06:21.880 will be executing this block and then the post itself is extended with all these methods so you have one less file
00:06:28.400 to look into in instead of also wrapping with a concern I hope that makes sense it's kind of doing a lot of different
00:06:34.199 things so part of the benefits here is that you don't need to have a naming convention for concerns and where to
00:06:40.120 place them look up to two files to read the feature you know the concern and Associated object or wrap integrating
00:06:45.880 code in like the whole included block you kind of spare doing that into just one block ex setly uh same thing with
00:06:52.720 class Mage you don't need to wrap that either so you kind of need to know a little bit less about Ruby's module
00:06:58.280 hierarchy same thing with the act support concern you don't need that either so it saves you a little bit of of boiler plate essentially um and the
00:07:06.280 primary goal we're trying to do with this is adding this kind of soft convention in a way to give you more
00:07:13.160 organization that's primarily the the the main benefit kind of and trying to
00:07:19.039 enforce people to use names spacing to see what that would do for their app and like their optic hierarchy essentially
00:07:24.840 um let's see and then Nate here is a person who's been using this GM and
00:07:30.639 and they also talking about another thing I don't think we'll be covering that gym today but this is what they've been been running into is they are
00:07:36.440 running Associated object uh in three spots in production so far I mastered improved how was architecting a new
00:07:41.919 feature I put a PR for review and I coworker locked how organized and easy to follow the large PR was because of those two gems I'm now working on
00:07:48.440 another PR App where I'm using them again I using them again I keep seeing use cases for them now I love it thank
00:07:54.280 you for D GMS blah blah blah so recommend checking it out um and then I follow up with them later and it was
00:08:00.159 still holding up for them and they've added four more Associated Optics this is this was a while back so they must
00:08:06.159 have been doing more because I think they're still using it uh it's like a one point one two point superpower I'm a
00:08:11.360 bit surprised this rails core to be honest I want to mic some some more code over to this feels more organized and
00:08:16.479 samee for them uh oh there's the stuff with the the jobs folder but we won't be covering that right now um let's see
00:08:23.560 other quote let's skip that over you test it kind of similar to what you do with anything else you sort of borrow an
00:08:29.199 act record and then you call this method on it that's the concession you're making that it's kind of tied to the rec
00:08:34.919 record but then the next part you can get is we're we're essentially implementing a global ID identification
00:08:42.320 that's called which is what actual record implements which is how if you use active job that you don't need to do
00:08:49.240 post. find because it's serial liens it's Global ID active job will know how to
00:08:54.959 like serialize the object and then pull it back out um and and and through that
00:09:00.959 you can you know you can basically pass these por of jobs so the way that this works is let's see here I'm explaining
00:09:07.480 here so basically because you can do post. find
00:09:13.000 one you could basically do Post publisher. find one so we're using the same post ID and the same post class to
00:09:19.800 use that as like the lookup um but then we're extending with an extra constant in there which means that we can then
00:09:25.279 find that object so we're I hope that makes sense so we're reusing yeah here yeah post. find orp publisher we're
00:09:31.360 using that lookup capability essentially um and then I'm explaining this other G
00:09:38.120 I've been working on to act job performs I don't think we'll go too much into this but the idea is basically that since you can since we have Global ad
00:09:45.079 support you can then generate these jobs based on that because we just pass this
00:09:50.240 poral into a job and so you could generate methods like these essentially and have these be generating jobs you
00:09:57.880 can see this is all the stuff that it ends up generating so because we have this extra convention we can generate a little bit more essentially and remove
00:10:04.160 some more boil plate if you want to um and then there's a whole more about what the D Json there the second part that's
00:10:11.000 relying on the same idea uh because of this post ID and the post namespace and then we just Stitch
00:10:18.279 the extra name space in here is we can also have automatic credit support um
00:10:26.200 so uh let's see what my fought here but but the idea is basically that now we have this convention for the namespace
00:10:33.120 and borrowing the post ID we can have uniqueness so we can do this kind of stuff and know we'll find the right P
00:10:39.160 essentially and and and give some of this like built-in features to you know
00:10:44.279 uh things like credits or like Global ID so it's so we get more again more Bay for your buck when you're writing code
00:10:49.800 and following this pattern if you want to you know it's it's optional to use something like this or the job support
00:10:55.440 it's just kind of there so that you know you're following like the right thing in terms of if you're following this pattern um yeah it's the same it's the
00:11:03.600 same feature set we are borrowing the post and the ID for that uh and here's the showing that we also work with like
00:11:09.519 namespace models if you have an optic rating here and then post comment rating descend
00:11:17.040 down into that same name convention let's see same way of testing it as well uh we do support custom composite
00:11:24.440 primary Keys actually it's a new feature where primary keys can now be like an array so it's a a little bit different
00:11:29.680 to work with it but um but it's it's the same same deal essenti we also support
00:11:34.839 that uh cool I think that's sort of the all walk through of the read me I was wondering if we should jump into some of
00:11:40.880 the code but I'm curious if anybody has any questions or something this is kind of like a high level overview yeah
00:12:00.240 oh let's jump into the code so uh maybe we should actually start and say so this
00:12:05.839 is just a regular gem there's nothing particularly special in here most gems just have like a gems speack we just
00:12:11.040 declare a few things and give it us you know Ruby version all that stuff and in most gems have a lip and test directory
00:12:18.000 that's it just if people have if people aren't used to jumping into gems and so forth I'll just explain a little bit as we go and then hopping to lip and it'll
00:12:25.720 just be loading in here actor recer ass object and this is pretty much it so
00:12:34.600 this is for the most part most of the code kind of so it's fairly meta programming heavy but I'm just hooking
00:12:39.760 into inherited which is a ruby hook so when you inherit from this optic we're we're declaring a few things onto the
00:12:47.320 like post publisher for instance so this is a rails method module parent which means means that from the post publish
00:12:53.800 we can get the post class itself and here we can get the post name and we can underscore so we could do like generate
00:13:00.720 the post method on this thing uh so you can do publisher. post and that's what how we get like bidirectional so you can
00:13:07.320 go back and forth if you wanted to um and then we're using some somewhat I
00:13:13.320 guess simple methods I guess um here's the extension block I was showing earlier where we just have this record
00:13:19.760 class was again refers back to the post doing a class Evol there and here's where we're
00:13:24.800 doing uh let's see we're doing respond to there yep and then we're doing a
00:13:30.240 method missing here as well let's see some of these things was just for convenience essentially I don't quite
00:13:36.360 remember method missing is kind of a little bit obtuse here but this is how we're implementing the wear method to
00:13:44.440 support glob ID that's kind of it um and
00:13:49.800 we're just yanking them out uh so this is like post. map publisher and then we
00:13:56.480 extract all of those or if it's a single one we just extract that from the one so that's kind of what we're doing um see
00:14:05.639 and yeah we take the record so this would be the post itself that's kind of it uh let's
00:14:12.680 see yeah that's that's sort of it for that this stuff let's see the other
00:14:18.120 thing you might want to do let's go back actually so this is typical what You' see in like a gem that extends rails is
00:14:24.880 this line where you're taking whether or not we've defined as rails rail TI and you look an optional class essentially
00:14:31.399 and what this rail tie does is then instructing how we want to tie into rails itself so you inherit from
00:14:38.680 this rail tie Define your own and then you can do some extra stuff if you want to so this is how we're adding in the
00:14:44.920 automatic credits and Global ID support we've already declared the the pillars you saw with the method missing Hook and
00:14:50.759 the other one with the ID um and this is just where we're automatically inserting
00:14:56.160 so people don't have to do it in their apps it's like hey we know that we support support these things um same thing with how we're extending this
00:15:01.759 active support active job performs rather um and then it's the other thing we haven't looked at it this object
00:15:07.720 Association this is where that has object method comes from we can look at that now
00:15:13.519 see so this is also kind of a little bit tricky but H up here I'm using an inline
00:15:20.160 anybody used refinements before so part of what I do when I do these gems is also experiment with a bunch of Ruby
00:15:26.560 syntax and I kind of have a little bit fun with it since it's not production app so it's kind of exploring seeing
00:15:31.759 what is I wouldn't get to use a refinement at my day job and you kind of maybe shouldn't but here it makes more sense so the fact that we're
00:15:39.079 using here if we're using these like braces to define the block it means that I don't need to wrap like paren around
00:15:45.240 the module. new call and the block will go to module. new as opposed to the using call that's how that works and
00:15:51.680 then within this call we can then do a refine on module itself to add this
00:15:57.319 method here and that's how we can within the has optic method use this method to then help us extend the source a little
00:16:03.880 bit EAS more easily in a way um yeah and we're using it again here to we're kind
00:16:09.680 of composing a method that we're adding onto your optic based on these like
00:16:15.000 strings we're passing back essentially um yeah I hope that makes sense but that's kind of what we're doing you can
00:16:20.079 see it up here class EV all passing through Source chunk so we're passing through this block which is the block that that we're passing here and then
00:16:26.560 also here so that's kind of how it work Works uh and making sure we're declaring the right files line number so if you do
00:16:32.680 like uh post. method publisher it will point back to that has object called that you had um hope that makes sense
00:16:39.399 but it's a little bit most people don't need to do this sort of stuff with call locations and so forth what we're doing
00:16:44.519 here is we're plucking out a frame on the stack that's just above us so we know where it's called from um yeah
00:16:52.399 that's kind of that's kind of what's going on here uh if you haven't seen met a program before maybe it's a little difficult I'm not sure but um that's
00:16:58.160 that's kind of the the G of it essentially uh yeah any questions so
00:17:04.559 far or like confusions or you can type it out in chat too if that's easier I can try to how do I see that actually
00:17:11.000 let's see okay I could find it there yeah makes sense but it does
00:17:17.679 cool otherwise I think we might should we hop on to open or there
00:17:22.720 something else I want to show in here let me check the test director is anything I need to show
00:17:29.280 uh let's see see fairly simple here we're just
00:17:34.360 doing some setup to make some of these things work setting up the APC job as well
00:17:40.960 clearing out all the stuff we put into creds if anything doing a bunch of Dent inte gra test yeah uh let's
00:17:48.280 see boot uh oh yeah oh if you never seen
00:17:53.520 this before by the way here's how you can set up active record like in an inline script
00:17:59.360 so you can use this if you want to test something out as well where you can connect to a SQL twe adapter and then pass it in a memory database so you
00:18:05.880 don't have to worry about creating a whatever like you can define a schema in line which is what we're doing here and
00:18:12.480 you can set up the logger as well if you want to and then you just have the whole schema logs put out when you run the test as well um that's kind of that's
00:18:20.880 kind of it in a way so you can Define this and then you can inherit from these things down below I'm setting up an application here here just to make it a
00:18:26.240 little bit more like an app and then that's what we're doing here but where this is all in memory like
00:18:31.400 it's a database in memory essentially but um it's really helpful with these kind of scripts so you don't have to mck
00:18:36.760 around with like an extra like DB schema file or something like that or have to migrate or anything like that you could
00:18:43.039 just Define it in line it'll be loaded up in memory but you can still do all the updates creates and finds and so
00:18:48.559 forth um but this is what that looks like it's in the test boot actual record if you end up going to the gym kind of
00:18:55.039 so let's see is there anything else I want to show in test maybe we have the
00:19:00.400 generator still as well but I kind of don't care about that right now uh yeah
00:19:05.559 and then we're just testing a bunch of stuff that uh method passing and all that stuff works and we will end up finding the same object that we CED uh
00:19:13.960 up here I guess through this method that they all return the same thing so yeah that's kind of uh some of that suction
00:19:22.039 pass through uh oh okay there's an old comment here I don't remember that part
00:19:27.600 to do uh it's always like that let's see global ID yeah this is what it looks
00:19:33.159 like when you pass to Global ID so if you have an active record you could do the same thing you do post. 2G ID and
00:19:38.520 it'll look I mean you won't have to publish in there but it'll look the same pretty much and that's how active job Works it'll find those and it'll locate
00:19:45.200 locate based on this g string essentially um let's
00:19:51.120 see anything else just Tak the methods for as well yeah I feel like it's fairly
00:19:58.760 standard so far anything else I need to look at source location yeah we're just taking that it points to the right file
00:20:05.520 Essen I don't want to bother with the line if anybody changes it that's a little bit too much but there point the right file I'm just checking okay
00:20:11.240 hopefully that means to we're also on the right line but uh yeah um
00:20:16.919 cool cool maybe we look at the generator real quick as
00:20:22.440 well uh generators so I think this is pretty
00:20:29.200 much just built into rails that the way that it loads generator so look in lip
00:20:34.919 SL generator SL Associated so you could do bin SL rails generate Associated and
00:20:41.679 then you can pass it some an argument I think yeah an argument for a name and it will help generate some of these files
00:20:47.640 for you so you can sort of or you can also uh also generate that has object so you don't need to worry about that
00:20:54.880 see uh I think that's kind of it anything else want to see the templates
00:21:01.440 directory yeah just fairly simple stuff just to help set set it up a little bit
00:21:07.640 so a test yeah just simple things kind of um
00:21:14.039 cool that's kind of I think this is kind of that G and how it works so uh it's
00:21:19.360 not a ton not a ton of code to kind of set this stuff up I guess the generator is almost half of it in a way um but
00:21:25.919 yeah kind of metap programming and so forth but because it's set up with these conventions in place it's not
00:21:31.400 necessarily so difficult and it's not super difficult to maintain either I haven't had to do a ton of versions and
00:21:37.360 most of the changes have been the core of it has stayed the same I've just added a few extra things I don't remember what it was but but yeah um 47
00:21:45.120 lines of cod to some of the stuff so so uh yeah fairly Dependable in that sense
00:21:51.360 cool any questions or we can I ask can I ask a question Casper yeah um can we use
00:21:57.960 it uh uh on other Frameworks like
00:22:04.120 Sinatra probably if you're using active record yeah yeah but I saw the gener generator
00:22:12.120 it start with been rails generator Associated or yeah have we have we have we add to
00:22:21.799 uh rails to our Sinatra project as well I don't think so because I think the
00:22:26.960 generator itself is just loaded by rails I'm not loading it in here and I don't
00:22:32.400 think I'm loading it anywhere else so it means you can't use the generator but uh because that's exclusive to rails but I
00:22:37.919 think if you're just using active record that's kind of what I require but to know the interface is the same but um
00:22:46.200 yeah yeah I see so if you're using active record in your in your catop I think it should work I haven't tried it
00:22:51.799 but um it should be fairly easy to to try out actually bundle bundle act
00:22:57.000 Associated opting it'll find out pretty quick not work or not I think I think everything should work yeah if you're
00:23:02.279 using active record I got that set up in there so MH thanks so yeah
00:23:09.520 cool I have one like um have you seen an
00:23:14.760 example like a live example that which makes you know say like oh this is like
00:23:19.919 a misusage of this uh pattern basically and you should use you know stick with the services or stick with the concerns
00:23:26.960 that have you ever seen like you know too much for this gem to handle itself uh not yet no it's kind of still
00:23:34.640 early days in a way um I think and then and the other thing too is this is not
00:23:41.159 meant to be the only way so if people still want to use services or con or whatever this is just like an extra tool
00:23:46.960 in the toolbox essentially that I think can help show up some things and know where to place them but it's not in
00:23:52.360 compatible with Services if people still want to use it for like the things that touch multiple models or things like that that's also totally fine um because
00:24:00.000 I think it's still fairly lightweight so it's sort of easy enough to see where you it kind of transgresses or things
00:24:05.640 like that um but yeah for sure uh it could possibly go very very wrong I'm not not sure I haven't heard about that
00:24:11.960 yet but um you know um depends on more people using it I think um so yeah if anybody wants to try it and just like
00:24:18.320 completely like overdo it by all means um I didn't hear from somebody else that was using it I was using it for quite a
00:24:24.039 bit where there was another developer that was originally kind of hesitant about adop it was like couldn't this
00:24:29.120 just be a poral or concern but then they ended up trying it out and then being completely converted because it added a
00:24:34.720 few extra things for them and putting that convention in place as opposed to uh doing the manual poral boiler plate
00:24:41.279 was kind of simpler because part of it is also again there's not so much code here the main point is almost like just
00:24:47.919 having this concept name of knowing what an Associated optic is because then you can when you're writing new features it
00:24:54.440 becomes a little bit EAS oh this could be where an Associated object lives or something like so you have extra tool in your in your like mind or whatever to
00:25:02.120 decompose features or other code you have essentially um as opposed to just like a por or something because that
00:25:08.120 could be kind of a lot of different things or just a service OB could also be a ton of different things but this is kind of trying to be a little bit more
00:25:14.600 scoped in that sense uh but yeah see uh I've got to sneeze hold
00:25:23.880 on almost there I guess okay cool see I think let's hop on to the other one then
00:25:30.480 where am I at uh let's see okay so the other GM I've been working on is called
00:25:35.760 o uh which is a little bit more ambitious so Soo is a little bit more scoped in a way uh o tries to kind of
00:25:42.799 see what if there was something different than fixtures and factories and trying to take like a new approach so all this stuff both for the
00:25:49.120 development scenes that we have but then also for the test data we're using in like you know testing essentially um so
00:25:55.640 I think a lot of people are kind of familiar with um pictures and factories maybe I don't
00:26:01.960 know if should explain any of them just like giving a rough like uh sense of what they are see is there anything I
00:26:08.919 actually want to show in the scrolling through because GitHub RS to read me a little bit nicer than my of
00:26:15.919 my own window let's see I'm just GNA switch to my editor instead here it is share this instead
00:26:23.120 Okay cool so go away Zoom I need my I need the rest of my screen please
00:26:29.039 I want to laugh up here there we go okay uh let's see open something up here
00:26:34.080 maybe B this a little bit cool and let's what's all this stuff oh that's some oh
00:26:40.640 that's like paralyzation okay cool do not our way here cool H yeah yeah yeah
00:26:46.399 yeah cool what else do I want to look at so what I wanted to show was in here
00:26:53.919 actually yeah we got our test fixtures so I have a test setup here with fix pies in them just to sort of we also
00:27:01.200 have a generator here that will actually convert fixtures into what o does so let's start with what fixtures are here
00:27:06.799 just to give a basic case so typically what fixtures look like is kind of like this where you have a file that looks
00:27:13.120 it's just in test fixtures ignore a test D you think that's just rails Indians and how you test them but test fixures
00:27:18.880 last account study anal for instance would have how many accounts you have and then whatever attributes they have they look like this next Association uh
00:27:26.840 probably the useless thing you have a few in there as well and then to connect back to the account somehow and give it a name or some more attributes as well
00:27:33.919 and probably like 20 30 lines for all the gamble to do that c another Association let's see actually one this
00:27:41.880 one in menus now we just have a Donuts one on this account cool okay let's go to the next one in here we have a menu
00:27:48.480 item I have a few items in there and they belong to this menu That's The Donut menu we just saw okay fair enough
00:27:54.200 let's Hub over to uh anything else I added in here I think that's kind of what I added for right now so what
00:28:01.919 happens with fixtures is you have these files that and they're kind of in this like in between space where there
00:28:07.799 there's this yaml that gets converted and this like set straight to the database so one of the issues that
00:28:12.960 people sometimes have with fixtures is that there's no call backs so if they're actually writing callbacks or whatever interactive records and you know there's
00:28:18.919 advice they're not used to on but if people are then fixtures don't help them with that because you have to rewrite it manually and put it into the S so
00:28:26.360 sometimes that mismatch gets a little bit difficult to work with and the other part is also we just saw here there's
00:28:31.600 like four or five associations but then there's four or five files with not a lot of content in them like most of the
00:28:36.880 fs right now is kind of simple and of course in a real laap it'll grow a little bit more and so forth and it'll be kind come on wieldy because you might
00:28:42.760 you have maybe have like several accounts where you have multiple different things so it's all
00:28:47.799 intermingled into one file so it becomes really difficult to figure out how where we organize these or how do we deal with
00:28:52.880 all this like complexities see as things grow so but one thing that is nice about fixtures is they're kind of fast because
00:28:58.760 they they're pre-loaded before a test so they're just like grouped up and just sent to the database like as few queries
00:29:05.600 as possible kind of so that's kind of nice in that sense and in that initial cost you kind of recoup that because you have a staple data set that you're
00:29:13.000 working with through your test so it kind of makes sense that so you kind of like
00:29:18.279 um use the app or learn the the main model a bit more it makes oh we have this Casper Donuts account and it has
00:29:24.279 this Casper user on it that I know how to use and access to and that's kind of what I need for most of my tests I just
00:29:29.799 need to sign in as this Casper person whatever and then that's kind of what I'm doing because the alternative I
00:29:35.840 tried with is also with factories I worked on a system used pictures and I worked on a system used factories as well and my difficulty with factories
00:29:43.799 was that they were kind of optimized for isolation whereas like fixures are kind of about the storytelling thing but
00:29:49.840 they're kind of ironically a little bit bad at it like we just seene where it's just like jumping to all these files and I have to reconstruct everything for
00:29:56.440 myself and it's like what are we doing but at the best case they can kind of give you some names to some of these
00:30:01.720 things that help you understand how your optic graph works oh this is actually my railp and
00:30:07.880 it connects in these ways and it has oh it has accounts and there's a little Mom and Pop shop or whatever it runs a donut
00:30:13.039 store whatever it is um that's the nice case about but then with factories they're kind of on the other side of
00:30:18.960 things where they're trying to be almost really Anonymous where all the data is kind of generated of you know
00:30:24.880 everything's like these like fake names or none of is really tight get or it's all like generated on the Fly which is
00:30:30.360 kind of nice in some ways because of some of the uses you can run into fixtures that you want something that's more ad hoc but then a difficulty there
00:30:37.159 and what I found was yeah I could get a test to pass but I had to kind of wire up four or five different factories
00:30:43.799 together and I don't know if I did it correctly and then both factories and
00:30:49.080 fixes have this discoverability problem where as things grow it becomes more difficult to figure out do I need to add
00:30:54.960 anything new to this this place or do I need to like do I need to update something or do I need to add something
00:31:01.159 in a different place like where do I go with this stuff does this belong to the existing Factory or do I need something
00:31:06.240 new or is this how do I actually work with this stuff over time so there's a lot here that's kind of and I think you
00:31:12.960 know fixtures was kind of has been rails as default since forever and I don't know how many people kind of use it some
00:31:18.919 people kind of use it in a little bit and then factories have also been kind of around since forever they're kind of
00:31:24.000 a Mainstay idea but so not a ton of stuff has been happening on these fronts I think um for a while so let me hop
00:31:31.600 back to the browse is it renders a little bit nicer let's see uh here
00:31:38.960 yeah so my take is kind of based on having worked on systems that use both factories and fixures and trying to see
00:31:44.519 is there something else we could kind of do here um this the other thing that we're also doing in apps a lot of time
00:31:50.840 is like working with datab Bas needs for development and setting that up and so sometimes what I've experienced is wait
00:31:57.200 there's both seeds and also these fixtures that are kind of a little bit similar and
00:32:02.559 sometimes you want to almost use some of the fixture data you have to also seed your database that's been my experience at Le words it's like you're doing
00:32:08.080 something that's kind of similar but you can't really share them it's like compers some to do that um so let's see
00:32:16.039 uh guess run through some of this stuff
00:32:21.240 uh uh see I don't really think so let's just start up here so what we're trying to do instead is kind of start from the
00:32:27.360 seeds case and then leveling those up and then using them for test as well so what it looks like is you'd head into DB
00:32:33.960 seats therapy and then You' do this you'd say open up prepare and then here you could do seing the accounts and then
00:32:40.799 also just data we get back to that so now we'll look for for deeply nested
00:32:46.360 files to load in this DB seats directory and then also within the current environment so you could for instance
00:32:51.720 have uh right now let's look at this file so just a file name so right now
00:32:57.880 now if we when we call seed accounts we're going to be looking for everything beneath this accounts directory or
00:33:04.120 everything beneath the the current environments accounts directory so you could also split this
00:33:10.360 up for just development or just test if you didn't want to share anything right now this is sort of in the the C
00:33:15.480 directory so this would be loaded in both development and test um so here's what it looks like instead
00:33:22.840 so those files that we just had to go through four or five different files to look at they're kind of all bundle in
00:33:28.960 here um like this where you could set up the account first and then when you give
00:33:34.000 it a name like the symbol here you can then use that in test you can say accounts. Casper Donuts to access this
00:33:39.919 or users. Casper to access it in in your test essentially and we're doing kind of the same thing where we're setting it up
00:33:46.360 and because we're not in yaml anymore we could also do things on like one line which I kind of like doing because like you know I just want to see the
00:33:51.399 statement and I just want to see how this Compares like this user Compares with the next user so it's easy to spot
00:33:57.279 the difference oh we're sharing the accounts the same thing the different name so for okay
00:34:02.440 makes sense to me um we're setting up the menu now we don't need to give it a name because we're we're kind of we're
00:34:08.520 creating actual records here so which also means we're running call back so it helps with that as well um and then the
00:34:15.839 menu here we could could pass it in directly we don't have to give it like a Donut's name like we did in the fixtures call um set up an extra like user here
00:34:23.639 for how to access the system generate some orders here some bogus ones and
00:34:29.040 that's kind of that's kind of it in a way um and then we're also doing this like trying to add a few more
00:34:35.119 conventions here as well where we both have this sier directory that's kind of I actually completely forgot to talk
00:34:40.800 about this is kind of a major thing where and N of fixtures or factories kind of have this but what we're trying
00:34:47.159 to do is group around this root level model where everything else kind of stems from so it's usually like an
00:34:53.639 account or a team or an organization where it's like the system can't exist what this model in there and everything
00:34:59.200 else like starts hooking on to that like you can see here we're setting up the account first and then we're setting up all the users on this account that's it
00:35:06.079 and then from there we can then go further and then add now we can add the menu and now we can add another user
00:35:11.880 that's then going to buy purchase some of these um that's kind of the way to look at it so so these files are kind of
00:35:19.320 more like like your config routes file where it's going to be a little bit longer vertically but everything's kind
00:35:25.320 of grouped together and you have a sense of where things start and like oh this is what's needed for my optic graph to
00:35:31.480 actually work it's it goes in this order where with fixtures and factories that could be kind of tough to trace around
00:35:37.400 and figure out how do this actually connect and what's to what and you can't really do it uh because you have to keep
00:35:42.920 a lot in your head and here you can kind of see it in the file similar to what you do in the route file so next up
00:35:49.200 we're trying to add this extra conation with this data director as well where there's these tables that aren't really
00:35:54.240 connected to anything else necess I mean it is but but they're kind of more to straight up like data tables like a
00:36:00.480 plans for instance where you just want to have a title and maybe give it a pricing for something you're just
00:36:05.960 offering this plan in your system but it's not quite connected to anything else we just want the data to be there um and also also we haven't done this
00:36:12.599 quite yet but we're still looking at it where this kind of data stuff could also be the thing that you maybe you want to
00:36:18.040 have in production so you could run this and make sure that the same data is like perforated and updated in production as
00:36:24.400 well to is like upsurt nothing it's still early for that figure out whether not this a good idea or not because it's
00:36:29.880 you know po a little bit risky so see cool and then we're just following
00:36:36.319 the conventions here so now you can do bin rails DB seed and Bin rails DB seed replant a replant will just truncate the
00:36:43.079 whole database and wipe everything and you start from scratch and add it again that's kind of it
00:36:48.960 so let's see we're also there's actually a type over here there should be no s here but part of what we're doing here
00:36:55.920 is also you do DB SE SL test SL cases if you have a specific case File that you
00:37:01.400 want for just a few tests or whatnot and then you can use them later on I think we're showing that um another thing
00:37:07.800 we're looking at is also adding defaults you can assign these broad Global defaults so if any if any column has a
00:37:14.200 name they will automatically use this so if you don't care about adding every
00:37:19.720 like default through hierarchy was like I don't really care about this it just needs to be there I don't want to give
00:37:25.240 it a specific value and it kind of ruins what it is I'm trying to say within my C file well now you can set a default here
00:37:30.880 or on a specific thing like if you know that you know an account is really a more specific name so it needs more of a
00:37:38.200 business name than a person name so you could kind of tweak it like this if you want to that's kind of part of it as well where we're trying to give a place
00:37:45.480 where we can set some of these things people have been doing this kind of stuff with fixtures as well where they have like there's this whole yaml syntax
00:37:51.079 you can use to capture something and then you can like extend something and it's just with these defaults and it's
00:37:56.640 also a little bit difficult too so um yeah and then we've integrated we also
00:38:02.960 have an rspec yeah okay it's here this OK rspec setup um and then for a mini
00:38:09.520 test we got this and it works with uh Ra's test parallelization as well we checked that so see and then test have
00:38:17.680 access to the accounts the Casper doners and uses the Casper frences that were set up into Data scripts
00:38:23.960 uh there's a little bit of recommendation for using like oneoff test is where it loads that cases for
00:38:29.240 instance the one single case for like a paty a test where you may be you're loading more records or whatnot but um
00:38:35.760 ship with a fixes converter it see development as well
00:38:41.839 well that's kind of just all okay that's just you supported by some people that was nice to support that's
00:38:47.240 cool okay any questions should we jump into the
00:38:52.560 code sounds good okay let's see and again similar gems spec all the standard files here change SL codee of conduct
00:38:59.200 gem file license uh MIT license they're both MIT license gems the test dummy is
00:39:05.079 kind of a rails so this is a rails engine I think maybe it is or maybe it is and I don't remember actually we'll
00:39:11.119 find out pretty soon let's see maybe it's just a rail tie yeah it's just a rail so it's not quite an engine so there's a difference
00:39:17.760 between if you just add a gym that wants to do something rails typically you ship these rail ties but you can also ship an
00:39:23.200 entire rails engine where you can have your own where your engine can then have an app directory and controllers mod
00:39:28.800 like device is an engine which is why it can stand up like extra routes like sign you know whatever has these or Shi these
00:39:35.280 like sess control or like the password reset flow device can ship all that stuff because it's that's what engin let
00:39:41.079 you do for instance let's see jump back so this is the main loading part we'll do it's a bunch of stuff in here again
00:39:47.960 not super much in here it's just setting some things up let's see seats the test
00:39:53.400 setup we talked about before the seats themselves there something we're looking at here let's see look a pass here's where we're doing
00:40:00.880 I think it's in the rail TI where we're putting the rails environment onto this thing so basically we're just having
00:40:08.000 these uh let's see we're not doing in here where's that being used in let's see I don't remember it's been a I
00:40:14.640 looked at some of the stuff uh okay we're seing all these we're loading all these files with our transactions if anything happens we can like revert or
00:40:21.040 whatnot which might be a little helpful for other things let's see uh cool again similar to what we did
00:40:28.520 in the associated optic gem we're loading the rail tie if there is defined one I guess it's a little bit silly here
00:40:33.720 because this doesn't work outside of rail so it's kind of I guess I don't I guess I should just require it um yeah
00:40:41.000 okay cool let's see maybe start with a rail tight end yeah so we're setting up
00:40:46.680 these lookup paths and here's where we're passing in that that part with the extra rail environment for how to find
00:40:51.839 all the extra files based on the environment so you both find the global ones in DB seats and then the per environment one
00:41:00.880 cool uh let's see what do we want to look at seeds probably is the best place here's where we set up the the thing
00:41:07.000 with the defaults it's a little bit wonky I kind of like this Ruby syntax with these endless methods people kind
00:41:13.920 of don't like it as well but I again for me since this is just my personal product I'm kind of trying to go a
00:41:19.599 little bit nuts with some of the syntax and see how that feels just to see what it looks like and and maybe even to make
00:41:25.560 myself oh I don't know if I like that but then just for fun see what it feels like um another method missing hook
00:41:33.200 here's how we Define the accounts and so forth it's a little complex because we're doing some more stuff in here um
00:41:40.079 but yeah so this is how we Define these accounts and the reason I wanted do these some people ask me why not just do
00:41:46.119 straight up active record calls in the seed P which you can totally do it's just more I like having it look a little
00:41:52.920 bit different so it's so you're aware you're not quite Within the whole actor
00:41:58.000 record thing and that's also how you can do things like the defaults and and setting them up as well so you get some
00:42:03.280 of those again more Bank fore Buck asense if you follow these conventions you get a little bit more out of it as opposed to soon our back to record in a
00:42:09.720 way where we don't have as much control so see the reg thing you kind of it's all auto registered these days so you
00:42:15.839 don't really need to worry about that that's this is more how it works with the registering like the account
00:42:21.160 internally and mapping it to an actual record model um he have load a specific seed file
00:42:29.000 here's where those look a passs come in where you just uh I guess you can pass multiple different directories kind of
00:42:34.359 and then for each of those who try to load from that so a little bit difficult here uh load from adding a new loader
00:42:41.280 and loading it onto this self here assistance module so that's how we're defining all these methods uh like uh
00:42:49.000 accounts for instance that's a specific thing uh we haven't talked about this at
00:42:54.119 all here's this is an experiment I've been trying where you know a lot of Rubik code bases where people are doing
00:43:00.559 comments for things like oh here's here's where the association start or whatever or like here's a new thing and
00:43:06.040 the old one ends um but I'm kind of like well rues is an expressive language that I think is a little bit of a shame if
00:43:11.119 we're just doing everything within comments because it's kind of tough to work with so I've been exploring just having this section method that that
00:43:17.319 kind of just it just leverages what ruby can do like Ruby's method syntax and all
00:43:23.000 the stuff you can do with methods um method signatures and then also yielding
00:43:28.359 a block So What it lets you do is set up things like these where you can do this stuff that's a little bit more
00:43:33.599 self-documenting to carve up your file into specific sections so here's the one we just call roots for instance um but
00:43:40.800 then we can also just pass a block because we just set this we just yield but you could also do it deeply nested if you wanted to so it lets you try to
00:43:48.680 carve up a file in a way that's hopefully makes a little bit more sense to either indent a little bit more if
00:43:54.280 you want to or something but but trying to make it a little bit since they're running a little bit longer trying to make it easier to figure out what's
00:44:00.680 going on but it's up to people to figure out how to use that but it's just you know the codo is so simple and just it's
00:44:06.400 just leting all the stuff that Ruby can do in their method signature so you know you could give it key values as well we
00:44:12.160 like give it a hash for something just something specific I think I'm doing that in one of the test to see what that would look like
00:44:19.760 see cool maybe we should jump into that so I'll show what it looks
00:44:24.880 like again test on me here let's see DB
00:44:31.000 seats yeah so we're setting some things up get some Global default some of this
00:44:36.359 is just for testing so it looks a little bit more gnarly than it maybe needs to um I know a lot of people in their Factory Bots they set up things like
00:44:43.119 calendar so I was trying to see what that would look like here I don't know if I like it exactly but just trying to
00:44:48.280 play around with it um another thing we got which is also kind of long is uh
00:44:53.880 anybody know about Ruby Singleton methods well you're you're actually seeing them here let me jump back to the
00:44:59.200 code base to show you what they are here here okay let's jump back into
00:45:06.760 where was I was that before oh oh oh the other one let's see DBC is there okay BR
00:45:12.520 to this TC here so here we are in here let's see so what is actually going on
00:45:18.720 with these methods here is uh you can do
00:45:23.800 this oh I nailed this a typo uh and then so rubby lets you add
00:45:31.200 methods to like an individual instance of an object uh and they're called Singleton methods so we're kind of using
00:45:37.760 those here so users here as an instance of a class uh we can look at that too
00:45:44.359 and then we can override its create method and because single methods you can actually call Super to get the
00:45:50.640 actual method as well so that's kind of what we're doing to just assign this like unique by default here get into
00:45:56.520 that as well um so it's a little bit uncommon but it's a way to get um access to some
00:46:04.559 Factory like helpers if you need to set up some more things but kind of doing it a little bit in line so a lot of us is still experimental and figure out how
00:46:10.839 does it actually feel and so forth I kind of like how Wild this is in a way that it kind of just works and it's just
00:46:17.040 sort of Ruby that lets you do these kind of things so again that's my take on on trying to explore these things and seeing what comes out of it and then let
00:46:23.359 people decide whether or not they like it or what not you know um so yeah let's see anything else I want to look at or
00:46:31.440 show right now uh yeah here's the one again trying to play with these like sections and
00:46:38.720 because this is the the free method signature we could do kind of whatever if you want to uh see there's a few more
00:46:45.960 things in here that wasn't the read me but I think that's just for testing trying to set up an extra account to see
00:46:51.280 what that looks like one of the things I want to add at some point is this is why there's a demo account in here as well it's just
00:46:57.760 trying to make it easier for people to set up some demo data for like marketing so that they could even sign in in
00:47:03.319 production want to play around with something or you could have a like a c
00:47:08.480 bar based Suite that could run based on this demo account and then take automatic screenshots that you could
00:47:14.079 then do stuff with or send to like a publishing Pipeline and then have it like Auto updated or something like that
00:47:19.880 um so that's that's some of the other things we're looking at I haven't gotten any of that yet but this is but the the
00:47:25.800 stuff is kind of mostly there to be able to start setting some of that up and and playing around with that and seeing how that would look like so that's like next
00:47:33.119 steps essentially but just trying to take doing this reconceptualization and
00:47:38.280 then trying to take it further essentially and seeing what else that gives us because both fixtures and
00:47:43.440 factures are kind of like they're kind of at their end stage and they've kind of done everything they can they they
00:47:49.680 they set up with a certain path which is cool but they're kind of at the most of what they can be I think uh which is
00:47:55.200 which is totally fine it's just like but this is kind of where the the end of the station is for them because they're kind
00:48:00.680 of scope so this trying to do something different here can give us some new ideas tly and then see how we feel about
00:48:07.800 them that's kind of my take cool uh what's all this stuff
00:48:13.200 here I don't know what these are okay huh that's just for testing I think cool
00:48:18.880 let's see o parallel testing that's what they are fake cool uh leaset test
00:48:25.200 pictures cool we need to look at the test helper thing pretty simple here
00:48:31.319 we're just I'm using the parallel test result to test if if we support both
00:48:36.359 parallel testing or not for our CI setup just so we test both modes um and this
00:48:42.040 is it we're just including o test setup um that's kind of it for for the test
00:48:48.200 setup cool anything else I need to look at oh
00:48:54.640 maybe we should look at the other hold on let find that this is a test we don't want
00:49:00.400 anymore I we look at the generator too but it's kind of complex we're trying to trace because we're giving this root
00:49:06.960 model in the fixtures like the account we can actually trace the rest of the optic graph based on that so this is
00:49:12.040 what this does but it's kind of there's a lot of stuff to figure that out so uh yeah this is kind of some of
00:49:19.599 the conflict stuff in here to figure this stuff out but this is the way to help people like I just used it the other day I'm trying to look at this
00:49:25.839 Ruby video if anybody heard of it uh somebody else let me know about it like an open source app for Ruby videos I
00:49:31.680 guess um and one of the people who wrote me was like hey I've been hacking on thing but it's using pictures and it
00:49:38.319 kind of a compass them in a way so I'm looking at trying to see what it would looked like to Port that to Oak and so far it's going sort of well but I use
00:49:44.440 this as a starting place to help uh make it a little bit faster to upgrade some of and kind of did some of the work um
00:49:51.960 but yeah I need some moreen in there anyway let's see here
00:49:57.799 o so when you add a new like the accounts for instance it's one of these
00:50:02.920 we're creating and so when you add those Singleton methods on Def users. create or something it's one of these instances
00:50:09.680 we're actually mutating um and here's what we're doing those like defaults just like so
00:50:15.920 anything that you have a a column name for essentially we're just grabbing from these like Global
00:50:21.920 defaults and seeing if you have any of those and then we'll just use them let's see
00:50:27.640 and some delegation here as well uh those are the like prototype defaults here here's where you do the create
00:50:34.119 stuff we're also exploring doing something where you can set these unique Buy on create calls which usually in act
00:50:40.799 workor you can only do that on like the upsert call but the idea here being if you have a user where what they're
00:50:46.960 unique by is actually their email um so we're trying to see well if the person exists in the system with that email
00:50:53.200 when you're seing uh we can actually go in and just update that person instead if you have those that data so that's
00:50:58.799 kind of what we're doing here uh we're trying to let me close the pain here
00:51:04.079 we're trying to to see if we have unique B here and if you pass any of those like the email address for instance we'll
00:51:10.240 actually find it first based on those and then try to update with the rest of the attributes again may have seen what or
00:51:16.680 not this is a good idea whatnot but it's still a little bit exploring and then the label here is just taking the the
00:51:23.079 name here we gave to expose it on the op so you can actually refer to them in tests and things like that uh upsert
00:51:30.559 kind of works a little bit similarly uh label here I can do some of this call location stuff to find the actual place
00:51:36.280 within the seeds file where you generated the method um yeah so that's
00:51:41.520 kind of the gist of it I guess uh and not too bad I think in
00:51:47.079 terms of code it's a lot of setup and so forth but um yeah
00:51:53.799 cool uh let's see
00:52:03.119 cool any questions I know this is like a ton of stuff or whatever and I like going kind of fast for some of these
00:52:08.400 demos just because I think it's kind of fun to just like trip through it and see what happens and hopefully we can follow along or whatnot it's just mostly just
00:52:15.359 for fun in a way so yeah
00:52:21.799 cool so I have one like it doesn't trigger the ACT record callbacks
00:52:28.319 right yeah it does okay yeah yeah so but is there
00:52:33.480 a is way you can get like a circular somehow maybe I guess suppose maybe yeah
00:52:40.880 but you can see here we're using so type here is just the actual record so we're calling create here so we'll end up
00:52:46.720 executing that thing but we'll also end up executing the I guess the update call back there um if calling update but you
00:52:53.720 can use obser as well to sidestep that um we're trying to do something a little bit beyond just what like upsert on an
00:53:00.799 acord these days tries to skip a whole bunch of stuff both callbacks and I think validations as well because it's
00:53:05.880 trying to be very close to a database but we're so we're mostly doing that but then we're also trying to be like okay
00:53:10.920 but let's also validate the record you passed and just to help you set it up correctly so you don't run into some of
00:53:16.000 those like weird bugs down the line or whatever um that's kind of you but yeah so you could Sid step callx with this
00:53:22.280 but it's kind of I don't know it's it's it's not the easiest thing to figure out what everybody wants for these things
00:53:28.319 because they domain so different in everything and obviously that's not what you're saying but um I mean in terms of uh that it should solve everything but
00:53:34.520 it's just kind of yeah so I'm trying to set up some defaults that hopefully make it easier to work with and then people
00:53:41.720 are going to make what they're going to make of it but and then also just looking for more uses in a way to see
00:53:47.240 what they find with it because I can't fake my way to all the different situations so it's just let's see what
00:53:52.319 happens and then you know it's going to be need to be used by more people in a way so I've been working with a friend of mine
00:53:58.160 he's the one that's quoted quoted in the read me as well he said this today actually I don't know if you can see it here but it's kind of anyway you can
00:54:04.960 find it read me as well as Thomas Canon he's been a big proponent of this and be using it up in two different apps as
00:54:10.359 well and been really happy with it so I'm really happy that it it's working for the some people um I still think it
00:54:16.680 remains to be seen how it's going to work for like larger apps for instance but at least where I'm at right now well
00:54:22.160 I think this is better than the two Alternatives we have right now at least for small and we could always figure out
00:54:27.480 what we could do later on down the line so that's kind of my take right now but
00:54:32.720 yeah definitely makes it I think easier to keep in the mind like how the data flows compared to fixures that
00:54:39.359 especially for me yes yes exactly yeah that's what I'm hoping for and then and and by the way this could also be you
00:54:45.200 could still use this with factories if you wanted to I think Factory but has a
00:54:50.280 I think it has like a I don't quite remember was Factory about a create no wait I think it's like called for or
00:54:57.000 something so if you had an an account fix an account Factory I think if you do this and then wait hold on I'm typing
00:55:04.960 what people are looking but something like this where you could like combine the two of them or something you could
00:55:11.040 probably even do what is it do you do include Factory bot or how do you do the because it has like Shand so maybe you
00:55:16.240 can factory syntax something like that I think right oh Sy text okay cool but
00:55:21.799 then maybe you could even get it down to like this or something and then you could combine the two of them if you wanted to so you still could use the
00:55:27.079 factory B uh stuff that you set up but then you could still get some of this like stuff preceded in a way um and then
00:55:35.559 that line between what's in a factory and what's in like seeds is also like difficult because I think what people
00:55:41.240 are running into with fixures is to try to make to try to add every X case to fixtures which is kind of not what
00:55:46.520 they're there for um what you want is do something where you have the base case and then you can always mutate like an
00:55:52.640 object in the test because they're wrapped in trans accents so anything you add create or update gets rolled back
00:55:58.920 right after the test so it's safer in that way um and also faster yeah
00:56:05.760 cool any other questions make sense so far I hope it's hope it makes sort of sense it's like I just sent it like oh
00:56:12.520 here's all the context and there these things and we used to and all this stuff so I hope it makes sense but uh
00:56:22.720 yeah cool I think that's kind of what I had uh
00:56:30.520 just here they do anything what's the I see
00:56:41.400 okay no I can actually ask one more like do you use the riing technique for these
00:56:47.280 ones too or do you keep it more like a domain modeling uh I actually did for the
00:56:52.559 associated optic one I think I have the original commit let's see if we hop back back to GitHub let's see here wait is
00:57:00.520 that the one yeah it is the one back to here and then H back to here and then
00:57:05.880 into the see yeah what what you're mening is I've been doing we can also look at that
00:57:12.039 actually let's look at that let's see oh wait that's gonna take a while to get the last one hold on maybe not too much
00:57:20.480 uh so this is like two years ago I did a lot of stuff uh let's see okay
00:57:26.760 so what I've been doing is let's maybe find that as well I don't think I have it on my Roofing on Rails so what I've
00:57:33.119 been also doing is I don't think that was mentioned in the let me put this in the chat as well I don't think this was
00:57:39.160 mentioned in yeah I know we didn't yeah no but we
00:57:44.480 didn't talk about that either but but what I've been doing working on as well as this like technique for uh domain
00:57:50.720 modeling essentially and you can see a bunch of examples in here and there's also a YouTube video down some YouTube videos down below with some sessions as
00:57:56.400 well um and there's also a rails comp talk I don't think I've even updated this with where the rails comp talk is I
00:58:02.119 was on the bike set as well and talk about some of the stuff you curious about all that stuff um so but the idea
00:58:08.839 is that you're essentially opening up a blank Ruby file and tossing in some some Ruby code into that so this is just what
00:58:15.079 it looks like again you don't necessarily need to write class user inherits from application to know that
00:58:20.240 it's an acur record you can kind of use the same DSL to sort of build up oh this usually has many playlist and it has one
00:58:25.760 history and so forth and you can start building out your autograph kind of like that um so there's a YouTube video for
00:58:31.480 this frame for instance so you can see in the repo for how we actually did this and it takes us like 40 minutes and I
00:58:36.520 think we talk about it for 15 minutes afterwards me and me and Jeremy Smith a friend of mine um so I've been doing
00:58:43.079 this sort of technique for a while where I'm just tossing things around and have sort of an idea for something and seeing what it looks like and sketching some
00:58:49.680 code out because Ruby is really great at that looking this is kind of pretty close to standard Ruby you know it would
00:58:55.119 need some extra stuff to break on a syntax ER here but you know get you get the idea across so that's what I did
00:59:02.359 with this original uh sketch in here I think that was yeah in April in 2022 so
00:59:07.799 I was working on coming up with the idea and trying to prove it out and added some things in the console or whatnot
00:59:13.160 and then I just took the sketch and then committed it straight in here and then started working on it some more to iterate on it um you see this is kind of
00:59:20.280 what looked like At first I guess I just implemented a wear directly and I was like oh wait maybe you could simplify but but yeah
00:59:27.319 um yeah the base of the idea was there essentially um what is this stuff oh oh I was trying
00:59:35.200 to oh yeah oh I've completely forgotten about this this was something else did not work so I had to yank this out but
00:59:41.480 uh where was I going for there oh yeah while we're loading oh okay it was actually trying to do
00:59:46.880 something similar to what I'm doing in Oaken but it did not work um trying to use those Singleton methods to also be
00:59:52.319 able to add stuff to the record as we're loading the associated object but it kind of didn't work so maybe we should
00:59:58.599 actually picked that up again I'm not sure that's maybe that be interesting I'm not sure anyway um
01:00:05.240 cool cool cool cool uh yeah I I think I could actually make this work now that's
01:00:10.839 okay I need to look at that okay that okay cool uh but yeah I did I used the
01:00:16.559 riffing thing for this just to try to play swap things around and see what it looks like and oh can this work because I had the idea for doing the credits in
01:00:24.599 the the global integration because then we could work with jobs and so forth so that was the core of it um I think
01:00:33.039 yeah cool so that's kind of a lot a lot of stuff to throw everybody so I hope it
01:00:39.039 makes sense uh again if there's any questions we could deal them and talk about them and so forth
01:01:07.799 I think then we are done I guess like if no one has any
01:01:13.559 additional questions or okay then well thank you cish for
01:01:20.520 joining us like so much yeah really great to have you yeah this is cool
01:01:27.599 yeah hopefully like we can do it maybe some other time like when you have another talk or like try to get ready I
01:01:34.400 think yeah yeah yeah yeah great way to learn
01:01:40.240 too yeah I T just uh toss people into the deep end and be like well see it's not that deep but sometimes people can
01:01:46.520 be a little bit like wait wait but at least I feel like it's because I think sometimes what people do when like
01:01:52.760 looking at rails code itself on Rails something like oh I don't know what do and just click stuff and then you'll
01:01:57.960 figure it out kind of and just if you can only we 5% of the file well then you can only we 5% of the file but at least
01:02:03.079 you read those 5% and you can start building up from there that's kind of what I did um otherwise it just becomes
01:02:09.119 like oh I'm not good enough for doing that okay but then when when are you going to be that way it's just so it's just clicking stuff and it's looking at
01:02:15.160 stuff it's it's all good essentially um yeah but yeah I can sometimes be a
01:02:20.640 little bit like yeah here's this stuff and here's this stuff and what has its charm I think but uh
01:02:27.880 yeah yeah cool yeah and that do you have anything to
01:02:33.799 say or should we wrap it up yeah uh thank you thank you Casper
01:02:39.279 for everything and it was a great talk so uh I guess I can stop the
01:02:44.760 recording yeah for sure cool yeah
Explore all talks recorded at Ruby Türkiye Meetup
+3