|
Smol posted:Model attributes that are not marked as serializable (stuff that is saved as json or yaml strings in the database, usually arrays) are only saved when they are marked to be dirty, i.e. when you use the setter methods. If you mutate the values directly, Rails doesn't know about that. necrotic posted:While I wouldn't recommend it for this use case, you can force an attribute to dirty by calling foo.prop_will_change!. See the API Docs for more on dirty attributes. Awesome, thanks folks! I don't mind going through the setter, I just wanted to understand what's going on.
|
# ? Dec 12, 2014 19:08 |
|
|
# ? Apr 29, 2024 18:46 |
|
Last night and this morning are why I hate tests. I have spent more time trying to figure out why this test isn't working than I did writing the drat feature in the first place. I have 2 nearly identical tests. In one, it works 100% of the time. In the other it fails 100% of the time. The difference is that the failing test has a second user that has been created in the system. "That's easy, figure out why the other user is causing the test to fail!" If only. It's failing because in the 2nd test, the controller isn't getting the params that are being passed in the body of the AJAX call. How does this make any sense: Ruby code:
I hate you testing. e: And it winds up being a bug with qt webkit where PATCH requests aren't always interpreted properly? So very strange. Workaround is to switch to a PUT instead as shown here: https://github.com/thoughtbot/capybara-webkit/issues/553 kayakyakr fucked around with this message at 19:47 on Dec 17, 2014 |
# ? Dec 17, 2014 17:35 |
|
I have a question for folks who work professionally in a Ruby environment. What type of testing do you use? Reading a lot it seems like Test::Unit, Minitest and RSpec are the most popular but I can't really decide which way I should go that I would benefit the most in the field.
|
# ? Dec 19, 2014 18:06 |
xenilk posted:I have a question for folks who work professionally in a Ruby environment. What type of testing do you use? Reading a lot it seems like Test::Unit, Minitest and RSpec are the most popular but I can't really decide which way I should go that I would benefit the most in the field. RSpec, and then some chromedriver wrapper I forget the name of for browser integration tests. I just write API stuff now so I never have to do frontend
|
|
# ? Dec 19, 2014 18:13 |
|
xenilk posted:I have a question for folks who work professionally in a Ruby environment. What type of testing do you use? Reading a lot it seems like Test::Unit, Minitest and RSpec are the most popular but I can't really decide which way I should go that I would benefit the most in the field.
|
# ? Dec 19, 2014 18:21 |
|
xenilk posted:I have a question for folks who work professionally in a Ruby environment. What type of testing do you use? Reading a lot it seems like Test::Unit, Minitest and RSpec are the most popular but I can't really decide which way I should go that I would benefit the most in the field. There's no "right" way to go about testing. RSpec is definitely popular, but I think Test::Unit holds its own in a large part of the field. I have heard less about minitest, but I know its also a relatively new player on the block.
|
# ? Dec 19, 2014 18:21 |
|
I hate testing (as I've attested to many times in this thread), but I've settled on RSpec + capybara as the testing that I hate the least.
|
# ? Dec 19, 2014 18:52 |
|
Yeah, RSpec + Capybara, with FactoryGirl and Timecop as the situation calls for. Simplecov generates a nice coverage report if you need to care about that. Coincidentally, I just learned Rails 4 Test Prescriptions came out and have a copy on the way, though it's through work and we have the holiday weeks off so it'll be awhile before I can dig into it myself. https://pragprog.com/book/nrtest2/rails-4-test-prescriptions
|
# ? Dec 19, 2014 19:14 |
|
kayakyakr posted:I hate testing (as I've attested to many times in this thread), but I've settled on RSpec + capybara as the testing that I hate the least.
|
# ? Dec 19, 2014 19:26 |
|
Gmaz posted:May I ask why? Personally coming from a project that was pretty big and had no tests to a smaller one but with good test coverage is a night and day difference. Yes they can be boring to write, but they certainly save a lot of time in the end. It's just a struggle for me. Bad testing habits piled against bad luck getting test suites to work. My normal testing experience is what I posted about halfway up the page. Spend 6 hours implementing a feature, spend 12 hours figuring out why the hell the tests aren't working for said feature. It also combines with the way I code: pre-writing tests means I can't stream-of-thought program which essentially kills my 2 hour bursts of extreme productivity and afterwards I move on to the next task rather than going back and filling out the test. I don't argue with the value of a good test suite, though. We're having to build integration tests into one startup because it's gotten large enough that changes are causing cascading issues.
|
# ? Dec 19, 2014 20:28 |
|
kayakyakr posted:It also combines with the way I code: pre-writing tests means I can't stream-of-thought program which essentially kills my 2 hour bursts of extreme productivity and afterwards I move on to the next task rather than going back and filling out the test. This has been one of the hardest things for me with testing is getting in to the "TDD mindset", instead of using coding as both exploratory and implementation, then just kind of moving on once things are done. I am starting to realize thought that I think the whole idea of writing your tests before your code is a bit misleading, since there is a completely valid need to have some of a coding spike first to get things going.
|
# ? Dec 19, 2014 20:52 |
|
kayakyakr posted:It's just a struggle for me. Bad testing habits piled against bad luck getting test suites to work. I'm a noob but feel the same way, except it's just about tests that require javascript. They. Never. loving. Just. Run. There's always a little corner case where the change event on an input isn't triggering properly or you need to exec a script cos of a known bug or whatever the gently caress. And in the absolute best case scenario they are SLLLLLLOoooooOOoOOOOOWwwwww. I'm basically solo dev for a company with a few legacy PHP/Python/Rails 3 apps and in the middle of porting them to Rails 4. I REALLY want good integration test coverage. REALLY want it. Especially since I end up doubling as QA as well. But gently caress me if it can't take literally 4-5 hours to (fail to) figure out why my jQuery change() event that's meant to show a div with a few extra form fields when you click a certain radio button NEVER gets triggered by clicking a radio button. But switch from using radio buttons to using a select and it's all fine. Welp, I got angry all over again remembering that Conversely I love unit testing. Works, always helps me design methods and features, saves my bacon when I'm refactoring dumb 800 line models from 7 years ago. Fortunately our apps are very JS light and I can just click about when it gets to that stage.
|
# ? Dec 19, 2014 20:55 |
|
I have hit a brick wall and I would love some help. I'm building out some widgets for Twitch.TV users so they have interactive thingies that make it easier to do things like show donations on their live feed, choose a random user from the chat room to win a prize, etc. I hit a road block with the prize wheel thingy. In order to get the list of all users in the chat room, I'm connecting to Twitch's chat room with the Cinch gem. Twitch chat is modeled after, but isn't quite IRC. Anyway, to use Cinch which is really an IRC bot tool, you need to configure a bot and then start it up so it can begin monitoring the chat. Soooo... I'm putting the code to configure and start a bot in one of my Rails controllers - and at this point I'd like to point out that I'm most definitely misusing Cinch, which is a chat bot. The command that starts the bot: bot.start blocks the main thread, so I spin it off as a separate thread. Here's where I show how I know just enough to be dangerous: After I start the thread, because bot.start is a long-running command, I'm calling sleep(n) so I can access the bot's properties after it's had some time to get going. And so I'm blocking anyway because sleep and sometimes the bot's properties haven't fully set up even after sleeping so I have to refresh the page and retry. So you can see this is starting to get really ugly. Then, I'm grabbing what I need from the bot and sending it to the view. So this all works™ and the wheel spins with all the names on it and lands on a winner. However, I'm unable to kill the bot thread after I get what I need, even if I call thr.kill. The bot remains connected -- I can see it's connected because the chat log is still scrolling in the server logs. And then if I refresh the page, a NEW bot is created/configured and connects. So now I have two identical bots connected to the chat and the server log is doubling everything. And if I refresh again... you get the point. This is all kinds of terrible. But I don't know what I don't know. Can someone give me a gentle push in the right direction? I would like to start the bot, get what I need without calling sleep, and kill the bot on every page refresh. OR, I'd like to have the bot run once and only once, and maybe even stay connected/persist across multiple page refreshes and I can ask the canonical bot for its properties. What hole in my knowledge do I have here? I am a clueless and dangerous idiot.
|
# ? Dec 20, 2014 05:44 |
|
xenilk posted:I have a question for folks who work professionally in a Ruby environment. What type of testing do you use? Reading a lot it seems like Test::Unit, Minitest and RSpec are the most popular but I can't really decide which way I should go that I would benefit the most in the field. We use Test::Unit. The only thing that makes unit testing at all tolerable for me is mocking/stubbing. Otherwise I just try to do end to end stuff.
|
# ? Dec 20, 2014 22:30 |
|
Seems like a lot of us don't enjoy testing, huh! I find it very difficult - I'm still at the stage where integration tests are natural, but unit tests are very difficult somehow - and often wonder why so many developers outwardly dislike testing but put up with it. It's saved my rear end so many times, though. gently caress it. (Also, Cucumber is pretty amazing once you get used to it)
|
# ? Dec 21, 2014 02:51 |
|
My personal approach, just to keep me sane, is to only kill myself testing if: a) I'm developing a feature, and writing tests is faster than testing manually b) A failure in the system I'm working on involves money, or some sort of serious obligation Otherwise, I just do the best I can with the time available. Some legacy systems are just too broken to test in a meaningful way. I can write tests for those things, and I'll be sure that my 'unit' will work, but I wont actually be ensuring that my unit isn't going to be breaking something.
|
# ? Dec 21, 2014 03:02 |
|
We use rspec mostly because my team prefers the syntax and the plugins available. It's not bad, but we never do test first. We end up writing tests at the end to hit about 80% coverage and go from there.
|
# ? Dec 21, 2014 03:29 |
|
MALE SHOEGAZE posted:My personal approach, just to keep me sane, is to only kill myself testing if: RSpec here, and I take pretty much the same approach. Anything in my customer portal that can destroy/mess with servers, or deals with billing in any way has 100% test coverage. The stuff that's less critical like admin notes on an account or simple reports? Nah, not worth testing those. Overall I have about 95% test coverage, which is nice, but I don't have much intention to shoot for 100%.
|
# ? Dec 21, 2014 05:36 |
|
EVGA Longoria posted:We use rspec mostly because my team prefers the syntax and the plugins available. As much as I would like to try the test first mindset I think coding as exploration is far too ingrained in my brain. Lately I have been at least switching over to specs once I have a rough outline of things and bouncing back and forth from there. I think that's probably the way to go in practice, for me at least. At least it feels better than the write everything and fart out some tests after I'm 99% sure it's working method.
|
# ? Dec 21, 2014 22:11 |
|
MrDoDo posted:This has been one of the hardest things for me with testing is getting in to the "TDD mindset", instead of using coding as both exploratory and implementation, then just kind of moving on once things are done. I am starting to realize thought that I think the whole idea of writing your tests before your code is a bit misleading, since there is a completely valid need to have some of a coding spike first to get things going. I'm reading Eloquent Ruby by Russ Olsen (which is great so far) and he tackles that issues in the Test chapter. quote:I have to say that I like the idea of test-first development, and I frequently practice it. But not-and here is the rub-always. There are times when I can be more productive by simply writing the code and then going back and adding the tests. When I hit those times I leave the tests for the end. Test-first development is a great idea, but we in the software industry have a habit of messing up really good ideas by deciding they are not just good but absolutely universal. And required. The take-away here is that you are not finished until you have both the software and the tests or specs to go with it. Write the tests first, or second, or third. But write the darned tests.
|
# ? Dec 22, 2014 19:22 |
|
My first two years of Ruby was at a place which insisted on 100% BDD. That was good discipline which has served me well in terms of knowing when I should test first and when I shouldn't. Personally I write the tests first because I find keeping the success criteria in my head while writing the code too much of a cognitive burden, even if I just sketch the tests out first.
|
# ? Dec 23, 2014 12:16 |
|
plasticbugs posted:However, I'm unable to kill the bot thread after I get what I need, even if I call thr.kill. The bot remains connected -- I can see it's connected because the chat log is still scrolling in the server logs. And then if I refresh the page, a NEW bot is created/configured and connects. So now I have two identical bots connected to the chat and the server log is doubling everything. And if I refresh again... you get the point. Welcome to threading. What thr.kill? You don't have access to the thread Cinch is starting, as it's done internally in the bot here: https://github.com/cinchrb/cinch/blob/master/lib/cinch/irc.rb#L217-L223 plasticbugs posted:I would like to start the bot, get what I need without calling sleep, and kill the bot on every page refresh. You're going to have trouble not sleeping as Cinch doesn't seem to have a synchronous mode. If you want to kill the bot once you have what you want, looks like you need bot.quit. plasticbugs posted:OR, I'd like to have the bot run once and only once, and maybe even stay connected/persist across multiple page refreshes and I can ask the canonical bot for its properties. Yeah, do this instead. The key to unlock this is the difference between storing your bot within the controller (which is transient and torn down each request) and storing it somewhere more permanent, like a class attr accessor on your Rails app's main module or a persistent services repository.
|
# ? Dec 23, 2014 12:28 |
|
Arachnamus posted:Welcome to threading. What thr.kill? You don't have access to the thread Cinch is starting, as it's done internally in the bot here: https://github.com/cinchrb/cinch/blob/master/lib/cinch/irc.rb#L217-L223 Thanks for your advice! I'm working on an implementation that creates a canonical bot that I can access across multiple requests. I've been putting the bot code in the controller for no good reason.
|
# ? Dec 31, 2014 01:23 |
|
Not a Rails question, but I'm trying to do something a little weird in Middleman. I have a blog page, blog/index.html.haml, and several article pages, blog/article-1.html.md blog/article-2.html.md etc. What I want to do is to have the contents of each article pages rendered into the blog index page, like basically iterate through an array of article.html.mds and add their HTML to a list on the page. I tried using layouts for that, but all I could figure out how to do was to simply display the link to the page - not get the HTML for the page itself. Is there a way to just stick the contents of a page inside another page?
|
# ? Jan 4, 2015 21:11 |
|
Er, are you using the middleman-blog gem? From what I can tell, it does everything you're looking for. I hate to send a link to docs, sorry, so please correct me if I misunderstood
hmm yes fucked around with this message at 06:34 on Jan 5, 2015 |
# ? Jan 5, 2015 06:24 |
|
I'll second that you want to be using middleman-blog. They have example code for a blog index: code:
The article.body is what you're looking for.
|
# ? Jan 5, 2015 08:42 |
|
Anyone have an idiomatic example of reading rc files for configuration? Specifically, I'm looking to read bowerrc files, which can be in the global root, the user's home, or any directory in the tree up from current working directory. Easy enough to do, but I'd rather not reinvent the wheel if it's already been done in a pretty manner.
|
# ? Jan 5, 2015 20:32 |
|
EVGA Longoria posted:Anyone have an idiomatic example of reading rc files for configuration? Specifically, I'm looking to read bowerrc files, which can be in the global root, the user's home, or any directory in the tree up from current working directory. I don't think that you need a library for something like that. I don't know of any. It's pretty easy to whip up in an ad-hoc fashion. This function uses recursion to traverse from the current directory to the root in search of filename. Ruby code:
xtal fucked around with this message at 20:42 on Jan 6, 2015 |
# ? Jan 6, 2015 17:15 |
|
xtal posted:I don't think that you need a library for something like that. I don't know of any. It's pretty easy to whip up in an ad-hoc fashion. This function uses recursion to traverse from the current directory to the root in search of filename. For rc files, you have to merge and override. I.e. settings in /etc are overridden by settings in ~/, which are overridden by files in the local folder. It's not too difficult to do (since it's a json file), was just curious if someone had something pre-built to handle that kind of thing.
|
# ? Jan 6, 2015 21:18 |
|
I want to add :touch => true functionality to my has_many associations. How do I upgrade has_many to accept touch (like how belong_to behaves). I've find the relevant files in active_record/associations, but its all cryptic and wanted to see if any of you have done this before or have suggestions.
|
# ? Jan 12, 2015 20:09 |
|
KoRMaK posted:I want to add :touch => true functionality to my has_many associations. How do I upgrade has_many to accept touch (like how belong_to behaves). I've find the relevant files in active_record/associations, but its all cryptic and wanted to see if any of you have done this before or have suggestions. (in some file that gets included.) Ruby code:
KoRMaK fucked around with this message at 05:44 on Jan 13, 2015 |
# ? Jan 13, 2015 05:29 |
|
I've got a best practices question about Ajax stuff: I have a model Article, and I want to be able to update particular attributes of that article through an AJAX form on the Article's Show page. These attributes could be Title, Status, and Footnote. Right now, I am placing the forms for updating these attributes in their own partials, and placing those onto the show page inside hidden div tags. The forms target the Update action of the ArticleController. I'm manually handling the Ajax calls by binding the ajax:whatever events in articles.js, and this feels a little smelly. Would I be better off having dedicated update_title action, with its own update_title.js.erb file to handle the Ajax call? I'm a little afraid of overloading the controller. Edit: Maybe in update.js.erb I could do something like JavaScript code:
MasterSlowPoke fucked around with this message at 16:14 on Jan 16, 2015 |
# ? Jan 15, 2015 21:24 |
|
Is there a way to modify the default ActionMailer::DeliveryJob class to have a callback before it where it waits five minutes before actually sending the email? I just changed something from using deliver_now to deliver_later and I want to see what happens if I tell the job to wait five minutes before sending the email, cause it's hard for me to tell if the email is actually asynchronous or not.
|
# ? Jan 19, 2015 00:45 |
|
What's everyone using for provisioning and deploys these days? We're an agency that has about 150 Rails apps and we use a mix of Capistrano for older stuff, git-based deploys for some stuff, and Chef for a few things. I hate Chef because deploys take almost 90 seconds. Looking for something that makes provisioning a new server fairly easy and also supports lightning fast deploys... we're down to ~2 seconds for git deploys if bundle install doesn't need to run and no assets have changed but git deploys aren't ideal for provisioning or scaling.
|
# ? Jan 19, 2015 16:48 |
|
Is there a fast .xls reader for Ruby? I don't want to write anything or look at fonts or whatever, I'm just interested in the data. I've tried out Roo, but it's taking 3-4 minutes to load a very small (33x10) spreadsheet.
|
# ? Jan 19, 2015 17:55 |
|
MasterSlowPoke posted:Is there a fast .xls reader for Ruby? I don't want to write anything or look at fonts or whatever, I'm just interested in the data. I've tried out Roo, but it's taking 3-4 minutes to load a very small (33x10) spreadsheet. Roo isn't the speediest but that's a still few orders of magnitude off. How are you parsing it?
|
# ? Jan 19, 2015 18:22 |
|
I've tried bothcode:
|
# ? Jan 19, 2015 19:30 |
|
prom candy posted:What's everyone using for provisioning and deploys these days? We're an agency that has about 150 Rails apps and we use a mix of Capistrano for older stuff, git-based deploys for some stuff, and Chef for a few things. I hate Chef because deploys take almost 90 seconds. Looking for something that makes provisioning a new server fairly easy and also supports lightning fast deploys... we're down to ~2 seconds for git deploys if bundle install doesn't need to run and no assets have changed but git deploys aren't ideal for provisioning or scaling. I deploy with capistrano. Provisioning is tougher. A lot of people like Ansible.
|
# ? Jan 19, 2015 20:06 |
|
Ansible and Docker seem to be the new hotness.
|
# ? Jan 19, 2015 21:43 |
|
|
# ? Apr 29, 2024 18:46 |
|
MasterSlowPoke posted:Is there a fast .xls reader for Ruby? I don't want to write anything or look at fonts or whatever, I'm just interested in the data. I've tried out Roo, but it's taking 3-4 minutes to load a very small (33x10) spreadsheet. There was a problem with a recent version of roo where it was rear end slow. The fix was a pull request maybe even merged but no semantic release yet. I'll check when I get home.
|
# ? Jan 20, 2015 03:55 |