#RubyOnRails - 19 May 2017
« Back 1 day Forward 1 day »
[00:12:36] Nicmavr: Hey ovaltine, thanks :) So basically I have a text field in which I input an email address, and I have a validation which checks that the field is not blank and that it's in the correct format. The problem is that the test passes even if I don't specify a value to put into the field (ie. the validation doesn't work)
[00:12:52] Nicmavr: What are common reasons that text field validations don't work during Rspec testing?
[00:13:10] Nicmavr: The funny thing is I have another 2 fields with validations and they work just fine as they should.
[00:13:46] Nicmavr: Should also add, the validation works fine when I try the app out manually. It only fails in Rspec when it allows the test to pass when it should fail.
[01:00:52] mwlang: trying to debug an odd issue with old browsers. be nice, I’m in enough pain as it is. ;-) Here’s the deal, IE7 appears to be making valid requests to my Rails 4.1 app, but Rails is randomly failing to find perfectly valid routes. Here’s a log snapshot of back-to-back requests of same route. The first one fails, the second one succeeds and all I did was hit F5 in IE7. https://gist.github.com/mwlang/10a5c205d3befde0b383097fd296c15a
[01:02:09] mwlang: any thoughts on how to try to snuff this one out (other than obviously telling a few thousand users to upgrade their browsers…)?
[01:11:15] mwlang: there’s lots of gems out there for that so you might try those before rolling your own.
[01:12:14] mwlang: amperry: http://stackoverflow.com/questions/21102324/the-rails-way-of-doing-client-side-validation-rails-4-with-simple-form
[03:44:29] hahuang65: but `wait` usually requires you to specify the subject you are waiting for, so at least there's a sanity check there of "we should be waiting"
[04:06:57] Scriptonaut: our full test suite went from taking 6 minutes to 45 minutes, because one of the developers litered the specs with sleeps
[04:07:58] Scriptonaut: I've heard that capybara methods wait for you now? But only about half of them?
[04:08:21] Scriptonaut: so the best way to do things would be to just use those methods that wait implicitly?
[04:09:05] hahuang65: Scriptonaut: probably. I'm unfamiliar with the newer versions of Capybara, but I've never been satisfied with the facilities it provided for waiting.
[04:14:47] Scriptonaut: hahuang65: ya, that's the issue I'm having, there doesn't seem to be a decent/easy/correct way to wait
[04:16:38] Scriptonaut: capybara is what everybody uses, I just don't understand how there isn't a correct way to do this
[04:17:07] hahuang65: maybe they just sleep. maybe they don't have as big a problem with sleep as we do :p
[04:17:34] Scriptonaut: it gets especially hairy when you have a bunch of asynchronous server calls going on
[04:18:11] Scriptonaut: because with turbolinks being default in rails 4, every time a user clicks a link, it's loaded async
[04:18:51] Scriptonaut: I mostly wanted to come here and ask what other devs did to solve this problem, because the other dev on my team is adamant that sleeping all over the place is a completely appropriate way to deal with this
[04:20:39] Scriptonaut: they take forever on there, though we just got the parallel/pipe system setup
[04:20:44] hahuang65: Scriptonaut: honestly, if it's good enough for the team, I wouldn't worry about
[04:22:09] hahuang65: i mean the easy thing is, put the suite on CI and block merging until suite passes
[04:22:12] Scriptonaut: but that is an issue because now everytime we release a feature, it introduces 2 to 3 to 5+ bugs
[04:22:33] Scriptonaut: ya, management would be like "dafuq you mean the test doesn't passes, it looks good to me"
[04:22:57] Scriptonaut: it's a constant power struggle between the devs and management on these types of things
[04:29:48] Scriptonaut: I dunno, only problem is, we have people opening PRs probably like once an hour
[08:56:59] shilon: Hello everyone, I’m seeding an array of Categories. And I’m using faker to create companies, each company has a category_id. I’m trying to add a random category_id to each company.
[10:00:12] dminuoso: sevenseacat: Interesting. Can you explain why? Here we avoid it because since the data is unpredictable it's totally annoying to get randomly breaking builds in our gitlab pipeline.
[10:00:57] dminuoso: (I mean you can get *some* predictability back with seeding faker, but reordering things or inserting code in the middle has some really annoying side effects)
[10:01:05] sevenseacat: thats kind of the point, it exposes assumptions you make about the shape of your data
[10:01:37] dminuoso: sevenseacat: Even if you can't reproduce it? Or do you then pull the failed docker container and analyze it?
[10:07:10] workmad3: dminuoso: no need to if you've not got anything in that's monkeying with it in your app or test code
[10:07:46] workmad3: if you have it seeded to the same value at the start of the test run, the entire sequence is deterministic
[10:08:15] workmad3: which means faker gives you the same values each run (as long as it is the same run)
[10:09:32] workmad3: dminuoso: the rspec side of it is just a cli option to specify the seed... you then pass that to seed the generator in spec/spec_helper.rb
[10:10:45] sevenseacat: i wasnt aware of that the seeding would carry through to faker-generated data
[10:10:47] workmad3: and tbh, you don't need rspec for it... you just need a way to specify the seed
[10:11:06] workmad3: sevenseacat: it seeds the internal random number generator, so it hits anything that uses that
[10:11:43] workmad3: so unless faker uses SecureRandom or directly pulls from something like /dev/random (which I kinda doubt :) ) it'll get seeded by the same value :)
[10:13:26] dminuoso: workmad3: Mmm. I should probably look at it again, for now Im just using factory_girl left and right with sequences.
[10:13:47] workmad3: yeah, I change my mind at different points and for different projects on using fake data
[10:14:58] workmad3: but it's a useful tool to have available, and if the primary reason you're not using it is because you can't repeat the builds to investigate, then it's worth knowing that you can solve that problem :)
[10:16:05] workmad3: sevenseacat: I wrote up some sample data for an acceptance test yesterday that was spongebob references
[10:16:28] workmad3: and then did an example in another spec where I named something "Boaty McBoatface" :)
[10:17:13] workmad3: A member of my team then said he could guess my current level of cynicism from how fun my test data is at any point :D
[10:17:38] sevenseacat: yeah if I stop referencing the word 'awesome' a million times in tests, probably a sign I'm not having a good day
[10:19:10] workmad3: personally, I find it easier to spot the discrepancies in test data if I'm looking for something more obvious than a change of "user 1" to "user 2"... which is how I justify it :)
[10:23:46] agent_white: Fun to attempt to be 'that guy'. Get him through L1-3 first. Your _bad test_ will be your own if you do shit right.
[10:24:00] workmad3: it's just getting out of the assumption that your users will be sensible and nice and know what you meant to do
[10:26:11] workmad3: it wouldn't be too bad... but I need to build a mechanism to transition transparently too, as it's integrated into invoice payments :(
[10:46:57] shilon: Hello everyone, I’m seeding an array of Categories. And I’m using faker to create companies, each company has a category_id. I’m trying to add a random category_id to each company.
[10:49:43] sevenseacat: not sure you can call that a noob error, seeing as thats something you had to do deliberately
[10:52:53] sevenseacat: even if it was public, how many categories do you have in your test database?
[10:58:36] sevenseacat: http://stackoverflow.com/questions/17372886/whats-the-rails-4-way-of-finding-some-number-of-random-records
[11:04:40] sevenseacat: yeah if youre having problems with specific code, it helps when you show it.
[11:06:08] sevenseacat: sure you can. i have no idea what you're trying to do, but you can write whatever code you want.
[11:06:43] sevenseacat: i dont know why you're trying to assign 17 categories to the category_id fued
[11:07:09] sevenseacat: but if what you have works and has the effect you want, its good enough for now.
[11:08:18] sevenseacat: in that case, it probably helps to check the documentation of any method you don't know.
[11:08:22] shilon: since I’ve added Category.order("RANDOM()").limit(1) the seed only creates the static company
[11:09:12] sevenseacat: use create! instead of create to get an exception when it fails, so you can see why
[11:13:24] sevenseacat: wait, are you working in test or development? faker is usually for test data
[11:52:05] Terens: Hello. I have several devices running a ruby daemon. Which tools are appropriate to use to send them notifications from a central server?
[12:35:12] Papierkorb: Terens: If the messaging server is a rails app, or if all target apps are rails apps, you could use WebSockets through the ActiveCable stuff (Rails 5.0+). Haven't used it myself, but it's built-in
[12:58:35] jarr0dsz: hello everyone, anyone could help me with this ActiveRecord::Base.establish_connection DB_ROUTER creating a db connection works
[12:59:06] jarr0dsz: Assuming this changes the db connection and one could do regular AR stuff but this is not true
[13:00:26] durango: undefined method `each_with_index' for #<ImageUploader::..> anyone have success with multiple image uploads using carrierwave?
[13:04:10] dminuoso: durango: However, "anyone have..." is a really bad way of asking about a problem.
[13:06:21] durango: dminuoso https://gist.github.com/durango/60c6118ebe31f7b6cdfa5432f7c3271d heres my gist
[13:08:55] durango: dminuoso so I tried using mount_uploaders and it says undefined method `mount_uploaders' fo
[13:11:07] dminuoso: durango: https://github.com/carrierwaveuploader/carrierwave/commit/62eee426ff0b012082fdb433b7cf07af0414e56e
[13:11:47] durango: ok, i was onboarded to this project so im not exactly sure why CW is such an old version o-o
[13:21:20] durango: dminuoso https://gist.github.com/durango/fcaa97f52c549ed0a72703ab18bf8e2c wondering if any o fthese other gems are causing issues
[13:23:13] dminuoso: durango: Use a version constraint. That will force bundler to either error or install the desired version.
[13:23:35] dminuoso: durango: This makes sense becauase whenever you start using features that requires a certain version to work, you should specify that constraint in Gemfile.
[13:24:37] dminuoso: durango: carrierwave consists of the entire uploader backend and a very trivial helper that you can just implement yourself
[13:25:32] dminuoso: durango: https://github.com/carrierwaveuploader/carrierwave/blob/87c37b706c560de6d01816f9ebaa15ce1c51ed58/lib/carrierwave/mount.rb#L134-L198
[13:25:41] dminuoso: durango: https://github.com/carrierwaveuploader/carrierwave/blob/c45699c318ca895f89fa3304204e48b5f1c411f1/lib/carrierwave/orm/activerecord.rb#L12-L22
[13:45:08] durango: ok new issue when I try to upload an image now https://gist.github.com/durango/ce400cc6b5f9e35cd90e6ef4fb4d2f7d I checked the input[name] value and that seems to be correct not exactly sure why Rails is trying to initialize MediaPhoto at all
[13:55:00] jarr0dsz: hello everyone i see the ActiveRecord::Base.establish_connection DB_ROUTER changes systemwide
[13:55:15] jarr0dsz: i require a change of connection on a per user base.. how would I approach this?
[13:58:10] jarr0dsz: preventing multiline spam? i have implemented this almost totally the only problem is when im switching to the router db and then this is systemwide so everything breaks for other users
[13:58:30] helpa: ¯\_(ツ)_/¯ Sorry, sevenseacat is not able to help you any further as they do not know.
[13:58:33] dminuoso: jarr0dsz: You accidentally gave us the link to gist.github.com in general, not some specific ode.
[13:59:07] schuylr: dminuoso: Back to haunt you with my AR troubles. I’m writing my test case but I don’t want to have ActiveRecord::Mysql2TestCase create a bunch of other schema that I don’t want. Any suggestions?
[13:59:16] schuylr: ARCONN=mysql2 bundle exec ruby -Itest test/cases/adapters/mysql2/enum_gem_test.rb -n test_valid_column
[13:59:41] jarr0dsz: i have multiple databases for each user, im only using the "router" db to lookup the corrosponding database id for that email of the user
[14:00:24] jarr0dsz: multitennant solution having seperate databases for users, and no way for the codebase to get access to other's database
[14:00:36] schuylr: First thing that comes to mind with multitenancy: https://github.com/influitive/apartment
[14:00:43] helpa: Multitenancy With Rails - https://leanpub.com/multi-tenancy-rails-2 - An excellent book that teaches you about building a Multitenanted Rails application. Written by Ryan Bigg.
[14:00:50] jarr0dsz: it works quite nice is lean yes i have looked at those and the book its overkill for our solution
[14:04:03] mrbubbles: I'm reading a file that is arriving via FTP. It's working most of the time, but sometimes silently failing. Doesn't seem able to read the contents of the file. I suspect that the FTP is not "releasing" the file when it's finished uploading, does that sound plausible? Any way I can check that?
[14:04:04] jarr0dsz: but is there a way to do a db connection and not make it system wide? just temporarily
[14:05:38] schuylr: dminuoso: The unit test loads the helper.rb which in turn loads a whole schema.rb and mysql2_specific_schema.rb
[14:06:53] schuylr: Sorry - I’m doing a unit test against a gem that broke with an activerecord update that you recommended I git-bisect to figure out the breaking commit
[14:06:59] jarr0dsz: like so https://github.com/rails/rails/blob/801b33a4812c937a7e726d4060e2e3e9361c56fa/activerecord/test/support/connection_helper.rb#L2-L7
[14:07:29] jarr0dsz: it is possible only problem this is still systemwide, i would require a seperate connection beside the existing one assuming this is possible
[14:07:40] schuylr: dminuoso: I wrote my own test as you suggested yesterday but there’s no need for the rest of the schema (which breaks in my utf8mb4 encoded database)
[14:09:02] richardjohn: happy friday everyone - have a timezone question, hopefully quite simple. I want to display/input dates in the local timezone, but store them in UTC. I’ve set ‘config.time_zone = 'London’’ and ‘config.active_record.default_timezone = :utc’
[14:10:01] sevenseacat: you dont need to specify the default_timezone line - thats what Rails does by default
[14:11:26] richardjohn: sevenseacat: it seems to deal with DST fine, it knows London is currently +01 and takes the hour off when saving
[14:11:39] workmad3: richardjohn: I think it's because you should have 'config.active_record.default_timezone = :local'
[14:14:13] shilon: sevenseacat: hey, based on what we talked before, do you think this could be an option? http://sebastien.saunier.me/blog/2015/11/04/retrieve-a-random-record-in-a-rails-application.html
[14:14:48] richardjohn: sevenseacat: err I am listening, but if :utc is the default then setting it to :utc explicitly isn’t going to cause this issue...
[14:16:32] workmad3: richardjohn: start by removing it, and then try it set to :local if that doesn't work... and look at what ends up in the DB at each point
[14:17:23] richardjohn: sorry but there are two options for that config setting, removing it will just default it to one of the two
[14:17:48] richardjohn: “remove it” is stupid advice which implies Rails is a magic box that people have no idea of the default behaviour
[14:18:14] workmad3: richardjohn: given that `config.time_zone = "blah"` will mess with ActiveRecord, it's not a stupid suggestion
[14:18:38] workmad3: (it states in the docs for that config directive that it enables timezone awareness in AR...)
[14:21:16] richardjohn: setting it to :local just returns the UTC date but with +0100 appended rather than UTC
[14:30:04] ponzii: I'm about to take a job with a company who want their in-house CodeIgniter 2 CMS rewriting in a more modern language. They're particularly proud of the performance of the sites they've built with the CMS so I'm wondering if Rails can match what they already have given the right approach to caching, turbolinks etc.
[14:31:53] schuylr: Well I haven’t been in the PHP game for a few years now so I don’t know how PHP7’s speed is compared to Ruby. Rumour is it’s a tad bit better?
[14:31:59] ponzii: schuylr: Just don't want them firing me for producing something more elegant but slower :(
[14:32:52] schuylr: Well that’s perceptive. The framework can be slightly slower but if there’s fancy fragment caching and nice use of turbolinks, that ultimately makes the overall experience faster
[14:34:56] ponzii: sevenseacat: Guess I should just download a copy of CI2 and setup a demo for ab testing and compare with `rails new ci2replacement`
[14:35:46] schuylr: maybe try adding some cases for database calls to ensure that you factor in hydration speeds and whatnot
[14:36:56] sevenseacat: rails is an entirely different beast to any PHP framework, that rebuilds your whole stack on every page load
[14:37:57] ponzii: sevenseacat: Yeah, I get that and that's why I'm wondering. If they've been good at optimising CI2, which is a much lighter framework than Rails, Rails might be a hard sell.
[14:38:02] schuylr: Rebuilds the WHOLE stack? What about autoloaders and initializers? I can wipe a lot of those away and they’re still in memory
[14:38:18] richardjohn: if they’re not using one, you’ve got no chance matching the performance with Rails
[14:39:32] sevenseacat: I'd argue that there's no benefit to using a 'modern language' if you're still going to use the same shitty practices
[14:41:50] ponzii: sevenseacat: When you're taking-on an existing database with complex JOINs AR isn't the answer to everything.
[14:44:41] richardjohn: if someone gave you a complex search strategy, you’d try it and do it in AR because “it’s the right way”?
[14:44:57] richardjohn: then spend the extra money on hardware trying to get it to return in < 5 minutes...
[16:28:56] bennyzr: Hi, how do I get rails to run an update or validation callback when only an attr_accessor field is submitted to the server?
[16:40:45] schuylr: dminuoso: If I run register_type on the same key as before, will it override the existing register_type for a column? i.e. register_type(%r(enum)i) to override the original one in AbstractMysqlAdapter
[17:31:37] hobodave: forgive me if this is phrased stupidly, but how do I figure out what class is referred to by this error message? NoMethodError: undefined method `default_scope_override' for #<Class:0xc414eb3>
[17:34:20] hobodave: Thanks fryguy. That helps. How do I figure out what Class it refers to? Or, even simpler, if I have a candidate Class, how do I get its memory address?
[17:35:42] hobodave: I've been trying to debug a bizarre concurrency bug in Rails for the better part of a month and I'm getting close :D
[17:36:30] hobodave: I've been avoiding that. I'm on JRuby, so I have to explicitly enable that. I'm afraid of Heisenberg. :D
[17:37:52] hobodave: fryguy just found this: http://stackoverflow.com/questions/2402228/accessing-objects-memory-address-in-ruby
[17:55:37] woods: does anyone in here have experience with the has_friendship gem? I am working on a small social networking project
[19:20:16] sunya7a: is it possible to direct a controller to load a view with a specific anchor? for example i know you can do something like edit_project_path(@project, anchor: "start-here")
[20:09:21] squaregoldfish: Linux/Bash: I have .ruby-version and .ruby-gemset. If I cd into the directory and run rails s, everything is happy. But if I do the same in a shell script, it doesn’t work (rails: command not found). Running gem env in the script shows that it’s not setting up the paths etc for the gemset. Any idea why it doesn’t work?
[20:10:17] amperry: hey folks, I've got a problem with an attribute that won't save. Gist: https://gist.github.com/amp108/b7178aa7a0f0acdbef4e2c74ac062e10
[20:16:42] squaregoldfish: fryguy: You genius. Never saw that as it’s in my bash_profile, not .bashrc. D’oh.
[20:24:47] amperry: Is it possible to do an AR query on one model, include an association, and call a scope on the associated model? If so, how does that look?
[21:02:12] amperry: With STI, if you were to reclassify the type of something, does that change how Rails thinks of it as a model? IOW, if I had the model 'class Chicken < ActiveRecord' and models 'Egg < Chicken' and 'CordonBleu < Chicken', can I change an Egg model to a CordonBleu model simply by altering the type? I have two models that are all-but-identical, and one literally does replace the other if instantiated.
[21:09:22] cnk: I would guess you would need to requery the changed thing so that rails builds a new object with the new type - but guessing