« Back to channel list

#RubyOnRails - 29 November 2017

« Back 1 day Forward 1 day »
[00:02:15] jrabe: has joined #RubyOnRails
[00:07:04] milesmatthias: has joined #RubyOnRails
[00:07:06] xcesariox: has joined #RubyOnRails
[00:21:34] Vircung: has joined #RubyOnRails
[00:27:56] orbyt_: has joined #RubyOnRails
[00:36:40] macxim: has joined #RubyOnRails
[00:45:52] mcr1: has joined #RubyOnRails
[00:50:27] fryguy: has joined #RubyOnRails
[01:11:06] easzero: has joined #RubyOnRails
[01:21:33] orbyt_: has joined #RubyOnRails
[01:25:49] dviola: has joined #RubyOnRails
[01:26:46] Vircung: has joined #RubyOnRails
[01:35:23] easzero: has joined #RubyOnRails
[01:39:26] cagomez: has joined #RubyOnRails
[01:41:44] Vircung: has joined #RubyOnRails
[01:42:10] krawchyk: has joined #RubyOnRails
[01:45:54] mostlybadfly: has joined #RubyOnRails
[01:49:57] easzero: has joined #RubyOnRails
[01:56:24] helpa: has joined #RubyOnRails
[02:01:33] quazimodo: has joined #RubyOnRails
[02:03:05] Vircung: has joined #RubyOnRails
[02:16:33] mtkd: has joined #RubyOnRails
[02:18:23] Vircung: has joined #RubyOnRails
[02:18:35] xlegoman: has joined #RubyOnRails
[02:20:00] dviola: has joined #RubyOnRails
[02:23:48] cagomez: has joined #RubyOnRails
[02:32:07] Technodrome: has joined #RubyOnRails
[02:32:47] Technodrome: i am getting a JQuery not defined , but i am loading jquery gem and my application.js is requiring it
[02:35:17] ornerymoose: has joined #RubyOnRails
[02:35:20] conta: has joined #RubyOnRails
[02:35:47] Technodrome: jquery 3.2.1 is being loaded via the network tab i see it
[02:37:21] Technodrome: $(document).ready(function() { console.log("hey there"); } ) this works though in my console , JQuery is not defined though
[02:38:25] Technodrome: nvim fixed it, thanks
[02:38:32] Jameser: has joined #RubyOnRails
[02:39:10] Vircung: has joined #RubyOnRails
[02:43:29] fragamus: has joined #RubyOnRails
[02:52:02] Vircung: has joined #RubyOnRails
[03:35:22] easzero: has joined #RubyOnRails
[03:40:29] Barrt: has joined #RubyOnRails
[03:59:45] Jameser: has joined #RubyOnRails
[04:01:35] Vircung: has joined #RubyOnRails
[04:15:32] fragamus: has joined #RubyOnRails
[04:17:08] Barrt: has joined #RubyOnRails
[04:22:22] ornerymoose: has joined #RubyOnRails
[04:23:04] Vircung: has joined #RubyOnRails
[04:32:49] Ropeney: has joined #RubyOnRails
[04:33:54] Vircung: has joined #RubyOnRails
[04:36:56] conta: has joined #RubyOnRails
[04:40:02] Exhiled: has joined #RubyOnRails
[04:48:14] Jameser: has joined #RubyOnRails
[05:00:49] Ropeney: has joined #RubyOnRails
[05:05:03] Vircung: has joined #RubyOnRails
[05:21:46] safetypin: has joined #RubyOnRails
[05:24:19] blindMoe: has joined #RubyOnRails
[05:24:33] blindMoe: Is is possible to manually set a model instance to invalid?
[05:24:41] fragamus: has joined #RubyOnRails
[05:26:25] Vircung: has joined #RubyOnRails
[05:34:59] iamarun: has joined #RubyOnRails
[05:48:54] Exhiled: has joined #RubyOnRails
[06:00:07] Vircung: has joined #RubyOnRails
[06:11:07] Vircung: has joined #RubyOnRails
[06:23:11] cschneid_: has joined #RubyOnRails
[06:31:18] Jameser: has joined #RubyOnRails
[06:32:23] havenwood: blindmoe: You want it to be valid but respond that it isn't?
[06:32:32] havenwood: blindmoe: def instance_of_model.valid?; false end
[06:32:38] Vircung: has joined #RubyOnRails
[06:35:45] Axsuul: has joined #RubyOnRails
[06:38:18] cschneid_: has joined #RubyOnRails
[06:38:31] conta: has joined #RubyOnRails
[06:38:51] boshhead: has joined #RubyOnRails
[07:02:30] Vircung: has joined #RubyOnRails
[07:14:30] Vircung: has joined #RubyOnRails
[07:20:29] cschneid_: has joined #RubyOnRails
[07:22:38] DoubleMalt: has joined #RubyOnRails
[07:31:23] Jameser: has joined #RubyOnRails
[07:33:17] conta: has joined #RubyOnRails
[07:35:54] Vircung: has joined #RubyOnRails
[07:39:43] DrYockel: has joined #RubyOnRails
[07:43:02] kies: has joined #RubyOnRails
[07:43:45] dionysus70: has joined #RubyOnRails
[07:51:17] Dimik: has joined #RubyOnRails
[07:55:38] cschneid_: has joined #RubyOnRails
[08:10:18] arBmind: has joined #RubyOnRails
[08:38:49] yottanami: has joined #RubyOnRails
[08:39:21] yottanami: I am using Monoid as ORM
[08:39:42] yottanami: Now how should I create my collection in DB?
[08:40:14] yottanami: when I try to create I got this error http://dpaste.com/3M5T898
[08:40:44] yottanami: should I include Mongoid::Attributes::Dynamic ?
[08:41:29] yottanami: Sorry the error is here http://dpaste.com/1H446CC
[08:42:00] cschneid_: has joined #RubyOnRails
[08:44:50] quazimodo: has joined #RubyOnRails
[08:50:26] srinidhi: has joined #RubyOnRails
[08:55:06] DoubleMalt: has joined #RubyOnRails
[08:58:52] marr: has joined #RubyOnRails
[09:08:33] simmerz: has joined #RubyOnRails
[09:11:31] n88: has joined #RubyOnRails
[09:16:07] cschneid_: has joined #RubyOnRails
[09:17:54] defsdoor: has joined #RubyOnRails
[09:29:05] Ergo: has joined #RubyOnRails
[09:39:07] fourcolors: has joined #RubyOnRails
[09:45:16] kitsuneyo: has joined #RubyOnRails
[09:47:36] Arkentias: has joined #RubyOnRails
[09:50:17] arBmind: has joined #RubyOnRails
[09:55:16] guardianx: has joined #RubyOnRails
[09:59:15] gregf_: has joined #RubyOnRails
[10:01:43] cgfbee: has joined #RubyOnRails
[10:04:16] blackmesa: has joined #RubyOnRails
[10:36:55] oquidave: has joined #RubyOnRails
[10:38:22] oquidave: Hello, how can i take a domain name as a paramter in my route. Here's what I have done https://dpaste.de/5ze4#L . /v1/domains/i3c.ug/available doesn't work, but /v1/domains/i3c/available works. How can I make it work? thanks
[10:45:01] cschneid_: has joined #RubyOnRails
[10:51:04] Vircung: has joined #RubyOnRails
[10:57:26] quazimodo: has joined #RubyOnRails
[11:10:59] Terens: has joined #RubyOnRails
[11:17:07] cschneid_: has joined #RubyOnRails
[11:28:20] Barrt: has joined #RubyOnRails
[11:39:46] lupine: has joined #RubyOnRails
[11:46:46] gheegh: has joined #RubyOnRails
[11:48:12] Barrt: has joined #RubyOnRails
[11:50:05] Jameser: has joined #RubyOnRails
[11:50:27] apparition: has joined #RubyOnRails
[11:54:02] Jameser: has joined #RubyOnRails
[11:56:09] cschneid_: has joined #RubyOnRails
[11:59:49] uksio: has joined #RubyOnRails
[12:08:05] Vircung: has joined #RubyOnRails
[12:10:42] mcr1: has joined #RubyOnRails
[12:16:09] apeiros_: has joined #RubyOnRails
[12:18:50] simmerz: has joined #RubyOnRails
[12:34:55] Technodrome: has joined #RubyOnRails
[12:46:03] Vircung: has joined #RubyOnRails
[12:54:13] workmad3: has joined #RubyOnRails
[12:59:24] simmerz: has joined #RubyOnRails
[13:06:58] lupine: has joined #RubyOnRails
[13:10:45] argoneus: (Can I ask about rspec/factorygirl here or is this strictly for rails?)
[13:17:29] ornerymoose: has joined #RubyOnRails
[13:18:59] truenito: has joined #RubyOnRails
[13:21:49] dminuoso: argoneus: This place is strictly for all things related to rails.
[13:22:13] dminuoso: This includes but is not limited to rails, rspec, factorygirl, or why Matz may not be as nice as you think.
[13:23:05] dionysus70: Matz seems super nice :P
[13:23:30] argoneus: so, I'm using rails and factorygirl+rspec for testing, but I'm getting this error: DETAIL: Key (char_as_id)=(0) is not present in table "characters".
[13:23:36] argoneus: actually this'll be better to put in a paste, 1 sec
[13:24:47] dminuoso: argoneus: Please include your rails_helper.rb
[13:24:53] dminuoso: In the same gist, separate file.
[13:26:54] argoneus: https://gist.github.com/argoneuscze/d6f5cd433b4b71636deee63ca7737638
[13:27:07] argoneus: oh, okay, 1 sec
[13:27:38] dminuoso: argoneus: Next time, please use multiple files to denote content from different files.
[13:27:41] dminuoso: It's easier to read.
[13:27:58] argoneus: you can add multiple files to gist, I had no idea, I apologize!
[13:28:01] argoneus: should I re-do it?
[13:28:04] dminuoso: No issue. No need.
[13:28:21] dminuoso: But you can edit gists, so you can include your rails_helper.rb as an additional file without trouble
[13:28:25] argoneus: doing that atm
[13:29:11] argoneus: I updated it
[13:30:06] rfoust: has joined #RubyOnRails
[13:30:09] dminuoso: argoneus: Can you include the entirety of your spec file?
[13:30:32] argoneus: I'll just split it properly into files, 1 sec
[13:30:42] dminuoso: argoneus: Also note that you shouldnt use both database_cleaner and transactional fixtures.
[13:31:01] dminuoso: Either one is fine, and transactional fixtures are probably faster.
[13:31:16] argoneus: the problem I assumed was happening was that my Characters were somehow getting removed before the Matchup was created
[13:31:26] argoneus: but I had/have no idea how, 1 sec let me update the spec
[13:32:22] argoneus: updated https://gist.github.com/argoneuscze/d6f5cd433b4b71636deee63ca7737638#file-matchup_spec-rb
[13:33:42] argoneus: as for the fixtures, so I can remove that entire block in rails_helper?
[13:34:03] dminuoso: argoneus: You can remove require 'support/database_cleaner' and the required file
[13:34:26] argoneus: oh, I see, I'm new to rails and I saw most reference projects/tutorials using it
[13:34:35] argoneus: thought it was a must have
[13:34:48] argoneus: (I assume its functionality was added into Rails?)
[13:34:53] dminuoso: Although.. well the database cleaner *can* be fine
[13:34:55] dminuoso: It depends really
[13:35:36] dminuoso: argoneus: So ideally I would now like to see the output of rspec (right now I want to make sure that we're looking at the correct spec) if thats okay
[13:35:58] dminuoso: (And then we'd have the gist containing all important files and output so we can start debugging)
[13:36:29] silvermine: has joined #RubyOnRails
[13:36:31] argoneus: https://gist.github.com/argoneuscze/d6f5cd433b4b71636deee63ca7737638#file-rspec_output-txt
[13:36:52] dminuoso: And I think..
[13:37:04] MrCrackPotBuilde: has joined #RubyOnRails
[13:37:57] argoneus: also, reading some stuff, it seems Rails does what database_cleaner does out of the box, interesting, I didn't know that, thanks! (but the problem persists :()
[13:38:00] dminuoso: argoneus: Can you please include the entire output? Im not convinced the line of code is correct.
[13:38:55] argoneus: hm, that is the entire input
[13:39:02] argoneus: but when I comment out the line "it { is_expected.to validate_uniqueness_of(:char_as_id).scoped_to(:char_against_id) }", it doesn't break anymore
[13:39:07] dminuoso: argoneus: There's no rspec output about what test is failing?
[13:39:36] dminuoso: Okay that information is enough, thanks.
[13:39:36] argoneus: I'm using RubyMine, let me try from console
[13:39:52] dminuoso: Yeah try running it locally, and you'll see what should come
[13:40:17] dminuoso: argoneus: Okay its quite simple.
[13:40:28] argoneus: oh, you're right, when I run it from console I get another message
[13:40:36] argoneus: "1) Matchup validations should validate that :char_as_id is case-sensitively unique within the scope of :char_against_id"
[13:41:01] dminuoso: argoneus: Can you run `rspec -b` and attach the output?
[13:41:10] dminuoso: Id like to know what's happening
[13:41:51] apeiros: is there a configuration setting which makes rails to crash with an exception when I do `image_tag("foo")` instead of `image_tag("foo.png")`? I ask because the former either causes recompiling all assets (since "foo" isn't in the manifest, only "foo.png"), or is ignored silently (with config.assets.compile = false)
[13:41:55] dminuoso: argoneus: The one thing I do notice, is that you never construct your subject
[13:42:03] apeiros: and neither of those two options seem compelling to me
[13:42:03] argoneus: https://gist.github.com/argoneuscze/d6f5cd433b4b71636deee63ca7737638#file-rspec_output_large-txt
[13:42:58] argoneus: I'd assumed that was some FactoryBot magic, because in another model it seems to work just fine with the foreign key (ie. it creates the foreign object)
[13:43:12] argoneus: Rails in general seems to be very harry potter to me at the moment
[13:44:10] dminuoso: argoneus: I'd like someone else to confirm this, but I'd say it could be a bug in shoudla-matchers
[13:44:21] apeiros: argoneus: and you're the muggle in the story? :)
[13:44:53] argoneus: I'm not even sure if I'm approaching this correctly
[13:45:04] dminuoso: argoneus: I would just do it by hand really and stop using this magic.
[13:45:10] argoneus: I just want to make sure that no two matchups are in the database twice, but at the same time char X vs char Y is distinct from char Y vs char X
[13:45:19] dminuoso: argoneus: Just use rspec manually to construct the scenario you want to test.
[13:45:20] argoneus: thought that's what the scoped uniqueness is for
[13:46:16] argoneus: do you think I should drop the shoulda matchers entirely or just that one statement?
[13:46:26] dminuoso: argoneus: I dropped shoulda matchers entirely. It's up to you really.
[13:46:37] dminuoso: Some people like it, Im a strong opponent.
[13:46:57] argoneus: sorry for this stupid question, but could you somehow tl;dr me on what this bug is / what's causing it?
[13:47:16] argoneus: since I thought it meant the object wasn't being created, but suddenly it is being created because it works in the other statements
[13:47:25] argoneus: so I have no idea what the error message means
[13:47:58] dminuoso: argoneus: https://github.com/thoughtbot/shoulda-matchers/issues/745
[13:48:43] dminuoso: http://matchers.shoulda.io/docs/v2.8.0/Shoulda/Matchers/ActiveRecord.html#validate_uniqueness_of-instance_method
[13:48:58] dminuoso: So it's even documented *shrugs*
[13:50:15] argoneus: hm, that error seems different from mine, though
[13:50:42] dminuoso: argoneus: *shrugs* shoulda-matchers.
[13:50:52] dminuoso: Construct the scenario from hand.
[13:51:09] argoneus: can I ask what's wrong with it? because I've been kind of relying on it until now and rewriting everything into normal rspec would probably take me a bit
[13:51:22] argoneus: and I'm willing to do it to learn more things about rspec, but... yeah
[13:52:03] dminuoso: Perhaps a bug, perhaps something else - like I said, it's shoulda-matchers.
[13:52:11] dminuoso: argoneus: Not everything, just start here.
[13:52:15] argoneus: no, no, I meant shoulda-matchers in general
[13:52:20] dminuoso: It just costs maybe 3-4 lines to do this test by hand.
[13:52:21] argoneus: you mentioned you prefer not to use it at all
[13:52:47] dminuoso: Yes. The thing is "validate_uniqueness_of(:char_as_id).scoped_to(:char_against_id)" I know what this is supposed to check.
[13:52:52] dminuoso: But I dont know what it does.
[13:53:03] dminuoso: Which makes it really frustrating if for some reason you need to control things.
[13:53:26] argoneus: ah, I always thought it was a Ruby philosophy to abstract things ad infinitum
[13:53:43] cschneid_: has joined #RubyOnRails
[13:54:21] argoneus: truth be told, I haven't really used raw rspec yet, so this might be a good opportunity - I assume I need to create a Matchup object, two distinct Character objects and then try to create a duplicate record?
[13:54:25] argoneus: and that's it
[13:55:51] dminuoso: argoneus: I like abstractions that are representative of what they do.
[13:56:07] dminuoso: argoneus: Yes, and then you just assert that one has an error on that attribute.
[13:58:57] argoneus: hmm... I assume that means FactoryBot is not needed either
[13:59:09] argoneus: since that should only give me records that are acceptable
[13:59:18] silvermine: has joined #RubyOnRails
[13:59:45] argoneus: now that I think about it, I don't really know how FactoryBot works either, I hate myself for using this magic stuff now :(
[14:00:00] dminuoso: argoneus: You dont need factory_bot either.
[14:00:03] dminuoso: https://gist.github.com/anonymous/a373b95d274bb253789d38a259ac6091
[14:00:15] dminuoso: That gives you two assertions to check for. :-)
[14:00:39] dminuoso: argoneus: Perhaps you should just do this by hand, and then look into factory_bot later to see what it does, and whether it helps you
[14:00:39] argoneus: oh, like that
[14:00:52] argoneus: I don't even need a DB to run these tests
[14:01:02] dminuoso: Well you do strictly speaking.
[14:01:46] argoneus: I just don't confirm any transactions, then
[14:02:17] argoneus: but thanks for the help, I'm going to re-write all my tests by hand for now
[14:04:54] dminuoso: argoneus: Or you can actually shorten that by using .create rather than .new/.validate
[14:05:17] argoneus: since I'm using the transactional approach
[14:05:23] argoneus: any and all items I create during a test will be rolled back after it?
[14:06:05] dminuoso: (With database cleaner you were additionally doing the same thing, except with explicit truncate statements *ontop* of also transactions rolling back)
[14:06:26] argoneus: and instead of FactoryBot
[14:06:31] argoneus: I can just make my own fixtures in spec/fixtures?
[14:07:00] argoneus: since it's essentially sample data
[14:07:20] dminuoso: argoneus: In this particular case you don't care at all.
[14:07:32] argoneus: right, I meant when I'm e.g. writing Controller tests
[14:07:36] argoneus: I should probably try to write those by hand too
[14:07:38] argoneus: at first at least
[14:07:56] dminuoso: argoneus: Controller tests have been deprecated. Use acceptance tests instead.
[14:08:02] dminuoso: *Integration
[14:08:22] argoneus: (is it just me or are most popular tutorials garbage?)
[14:08:25] argoneus: (apparently)
[14:08:29] dminuoso: You can still test your controllers if you really want, but if there's complex behavior to be tested, somehow move it out of the action and test it separately
[14:08:39] dminuoso: argoneus: There's lots of popular garbage.
[14:08:53] dminuoso: Also keep in mind that frequently learning material is not updated.
[14:08:55] argoneus: well, I've been trying to make a REST API for a website frontend
[14:09:05] argoneus: and I decided to do it "properly" with tests etc.
[14:09:06] dminuoso: Lets see if we have a decent factoid
[14:09:07] helpa: What book should you get? - http://is.gd/hYWq
[14:09:18] dminuoso: Mmm no. Thats quite old.
[14:09:39] argoneus: (btw, do you use FactoryGir-- FactoryBot?)
[14:10:05] dminuoso: I do, but the original reason I picked up has disappeared. It remains mostly because its not worth the effort to remove i.
[14:10:09] Vircung: has joined #RubyOnRails
[14:10:20] argoneus: so I can get by without all these things, just rspec and fixtures, huh
[14:10:22] dminuoso: So right now it just serves as a tool to quickly construct hierachial data
[14:10:31] dminuoso: argoneus: Yes.
[14:11:01] argoneus: that's good then, using magic wand libraries was daunting
[14:11:06] argoneus: I like doing things myself
[14:11:32] Vircung: has joined #RubyOnRails
[14:12:00] dminuoso: argoneus: Note there's nothing inherently wrong in using shoulda-matchers for convenience. But it is my belief, that you should only do this if you understand how this would be done yourself.
[14:12:12] argoneus: I'm not saying I'll never use any of these
[14:12:20] argoneus: but for now I'll try to write the project from ground up myself
[14:12:20] dminuoso: So that it becomes a vessel to reduce your work, not solve magical problems.
[14:12:40] argoneus: (well I'm already using Rails, so it's not very ground-up)
[14:13:54] argoneus: anyway, could you give me a quick overview on what you meant by controller tests being deprecated?
[14:14:12] argoneus: e.g. if I want to test that an endpoint /character/:id responds correctly and verifies auth, how would you test it?
[14:15:11] dminuoso: argoneus: https://github.com/rails/rails/issues/18950
[14:15:33] dminuoso: argoneus: So if you look at this.. they have just become integration tests in effect.
[14:15:55] dminuoso: But feel free to give the whole thread a read
[14:16:04] argoneus: so I still test the controller, but not the innards, just as a black box
[14:16:09] argoneus: I'll skim through it
[14:16:45] dminuoso: argoneus: If you have special behavior in your controller you need to test, move it into a separate method. There's then ruby tricks to test those methods in isolation (so then your tests become pure ruby tests "does this method do what I think it does?"_)
[14:18:07] argoneus: this is making my head hurt
[14:19:02] Terens: There is a gem that will be generating messages. I suggest to put the messages in a Queue so that I can consume them. However other dev regards queue as overcomplexity so he will use a simple array
[14:19:11] SteenJobs: has joined #RubyOnRails
[14:19:17] Terens: so I think a timer with polling would be ok ?
[14:19:45] dminuoso: terens: Since you mentioned Queue, do you intend to share this data structure across threads?
[14:20:25] Terens: it should not block
[14:20:35] Terens: I guess yes
[14:20:54] dminuoso: terens: Then fire those other devs.
[14:21:48] dminuoso: Arrays are not thread safe, queues are thread safe FIFO, designed to synchronize communication across multiple threads.
[14:21:54] argoneus: also dminuoso thanks a lot for all the tips, you've been a great help
[14:23:14] dminuoso: terens: There's nothing overly or even complex about Queues. Consider pointing them towards ri.
[14:23:50] Terens: He tells me that array has pop and queue has pop too . I cant explain him the difference
[14:25:44] dminuoso: terens: Array is not thread safe.
[14:25:55] rikkipitt: has joined #RubyOnRails
[14:27:00] dminuoso: terens: But if they are arguing about this without either knowing this or having looked at the documentation (which would state this at the top), Im not convinced a discussion is fruitful.
[14:27:01] Terens: I will try to convice him
[14:27:11] dminuoso: terens: Don't convince him, just explain to him the concept of thread safety.
[14:28:45] safetypin: has joined #RubyOnRails
[14:29:08] krawchyk: has joined #RubyOnRails
[14:30:52] cschneid_: has joined #RubyOnRails
[14:32:56] rikkipitt: has joined #RubyOnRails
[14:40:29] rikkipitt: has joined #RubyOnRails
[14:42:30] Vircung: has joined #RubyOnRails
[14:44:31] fragamus: has joined #RubyOnRails
[14:44:39] mcr1: has joined #RubyOnRails
[14:53:34] spastorino: has joined #RubyOnRails
[14:53:41] fourcolors: has joined #RubyOnRails
[14:58:41] lupine: has joined #RubyOnRails
[15:00:23] Terens: has joined #RubyOnRails
[15:00:30] SteenJobs: has joined #RubyOnRails
[15:06:04] cschneid_: has joined #RubyOnRails
[15:11:29] dviola: has joined #RubyOnRails
[15:22:11] tcopeland: has joined #RubyOnRails
[15:28:40] urk187: has joined #RubyOnRails
[15:32:04] duderonomy: has joined #RubyOnRails
[15:34:53] kus_ubuntui686a: has joined #RubyOnRails
[15:39:12] simmerz: has joined #RubyOnRails
[15:43:41] DoubleMalt: has joined #RubyOnRails
[15:49:28] gheegh: has joined #RubyOnRails
[16:01:19] hfp_work: has joined #RubyOnRails
[16:03:40] silvermine: has joined #RubyOnRails
[16:04:19] simmerz: has joined #RubyOnRails
[16:05:22] apeiros: has joined #RubyOnRails
[16:06:44] troys: has joined #RubyOnRails
[16:07:51] Papierkorb: has joined #RubyOnRails
[16:11:35] Vircung: has joined #RubyOnRails
[16:26:52] conta: has joined #RubyOnRails
[16:28:29] ornerymoose: has joined #RubyOnRails
[16:31:36] lxnr: has joined #RubyOnRails
[16:32:47] cschneid_: has joined #RubyOnRails
[16:32:53] argoneus: I'm trying to figure out how to use RSpec to write request specs, but... once again it seems like pure magic to me
[16:33:02] argoneus: e.g. the first code example from this site: http://matthewlehner.net/rails-api-testing-guidelines/
[16:33:08] argoneus: I have no clue where "response" came from
[16:33:11] Technodrome: has joined #RubyOnRails
[16:33:30] argoneus: what am I missing here?
[16:33:54] argoneus: and how are the FactoryGirl messages even propagated to the request/response?
[16:34:04] dminuoso: argoneus: So..
[16:34:04] argoneus: it just creates a list and that's it
[16:34:09] dminuoso: argoneus: Do you have pry?
[16:34:32] dminuoso: argoneus: Im gonna equip you with the basic swiss army knife to figure out things.
[16:34:53] dminuoso: argoneus: add 'pry-rails' to your Gemfile and update your bundle.
[16:35:29] dminuoso: Once that's done, you can use the ruby code `binding.pry` in *any* ruby code, when execution hits that line of code it will stop and start an interactive ruby shell right in that context.
[16:35:52] dminuoso: Even in rspec code (since its still just ruby code)
[16:36:02] srinidhi: has joined #RubyOnRails
[16:36:42] dminuoso: argoneus: Ultimately this wont help here much but you will want it anyway.
[16:36:59] dminuoso: argoneus: So check the top of your spec file. What do you always blindly do?
[16:37:09] argoneus: oki, I added it to the gemfile
[16:37:15] argoneus: hmm, I require rails_helper to get access to some things
[16:37:21] dminuoso: So open that file.
[16:37:27] dminuoso: See what it does.
[16:38:02] argoneus: requires a bunch of other rails files, and configures rspec
[16:38:30] argoneus: rspec/rails seems relevant
[16:38:51] dminuoso: argoneus: Yes. That comes from rspec-rails with is somewhere in your Gemfile
[16:39:08] argoneus: and rspec/rails .... includes like 15 other files again
[16:39:13] dminuoso: argoneus: Ignore that.
[16:39:26] dminuoso: argoneus: You just need to know that its rspec-rails, so check out the github page: https://github.com/rspec/rspec-rails
[16:39:47] dminuoso: There's a scarce rundown of all the things it provides.
[16:40:26] dminuoso: argoneus: Also do take note of the require "spec_helper". The thing that's happening, is that there's just a raw rspec config file "spec_helper" that any spec testing pure ruby code would use.
[16:40:50] dminuoso: And if you want to test rails specific magic, then rails_helper first loads up the regular rspec config, and adds all its rails bells and whistles.
[16:41:04] dminuoso: which is why you have spec_helper and rails_helper
[16:43:15] argoneus: so every file that wants to test using rspec-rails has to require rails_helper
[16:43:31] argoneus: otherwise I get just "vanilla" rspec
[16:43:41] dminuoso: argoneus: right, you get vanilla rspec with "spec_helper"
[16:44:27] dminuoso: so for example get() obviously does not make sense in vanilla. there needs to be some special code that knows what to do with get (it has to somehow push this into your rails router, through the controller and do something meaningful with the render output)
[16:45:01] dminuoso: so rspec-rails somewhere defines this magical get method, and response method to do the things that read nicely.
[16:45:41] dminuoso: argoneus: Also take good note of this line of code: require File.expand_path('../../config/environment', __FILE__)
[16:46:01] dminuoso: That is your config/environment.rb and its an interesting file. If you require that file. you have loaded the rails application.
[16:46:40] dminuoso: This is the reason why you can just write Post.create(...) for example, even though you have not required the file for that model or configured anything for autoloading.
[16:47:34] dminuoso: Which also means: If you ever want to run a script "in the context of your rails application", you just require that file and write your code. You can just use `ruby script.rb` and it will work.
[16:47:46] argoneus: that's pretty clever
[16:48:15] dminuoso: argoneus: And even more to the point! the actual rails application, does the same thing!
[16:48:29] dminuoso: argoneus: config.ru in your base directory is the actual rails application. :-)
[16:49:20] dminuoso: when you type `rails s` it essentially just executes config.ru in a slightly special fashion with ruby.
[16:49:45] argoneus: so basically
[16:49:49] argoneus: my tests have access
[16:49:58] argoneus: to pretty much the entire application, so I can seemingly pull magic keywords out of nowhere
[16:51:03] argoneus: so what's happening in that code snippet
[16:51:40] argoneus: is that FactoryGirl creates a bunch of messages and populates the test database with it, then I do a get request, which does <internal rails magic> and then I can use helper functions like "response" to get access to the most recent response object
[16:51:44] argoneus: http://matthewlehner.net/rails-api-testing-guidelines/
[16:51:54] argoneus: and test it
[16:51:57] dminuoso: argoneus: Yes basically.
[16:52:05] argoneus: and this internal rails magic
[16:52:15] dminuoso: Its not exactly internal rails, its internal rspec-rails.
[16:52:15] argoneus: includes going through my controllers, in context of the test database
[16:52:26] dminuoso: Do you know why the test database?
[16:52:31] dminuoso: Just since we're on the demystification path
[16:52:42] dminuoso: Check out your rails_helper.rb again
[16:52:48] Exhiled: has joined #RubyOnRails
[16:53:03] dminuoso: This is the sole reason why it works on the test database rather than development. It also shows how you can override it for some tests should you want it.
[16:53:16] argoneus: it sets an env var
[16:53:21] dminuoso: It defaults it rather.
[16:53:29] argoneus: sets it unless it exists ye
[16:53:34] drowze: has joined #RubyOnRails
[16:53:51] dminuoso: You have to do this before loading config/environment
[16:53:56] argoneus: this is making a lot more sense now
[16:54:03] argoneus: right, because those also work with the env var
[16:54:27] argoneus: on one hand I'm happy I understand it a bit more now
[16:54:30] dminuoso: Exactly. config/environment will load the bundle in the Gemfile, it will run your config/initializers and then initialize the actual rails app
[16:54:34] argoneus: but on the other now there's probably 281461824 functions I have no idea about
[16:54:43] jtperreault: nice rundown dminuoso
[16:56:09] argoneus: thanks a lot! this explained a ton
[16:56:23] argoneus: now the last step of my master plan is actually understanding how let/let!/before work
[16:56:33] dminuoso: argoneus: I wouldn't worry about "how rspec works"
[16:56:40] dminuoso: Because rspec is a thick DSL implemented in Ruby.
[16:57:00] dminuoso: argoneus: https://relishapp.com/
[16:57:13] dminuoso: argoneus: this is the official website, they have absolutely amazing resources, manuals and reference documentation
[16:57:32] dminuoso: https://relishapp.com/rspec
[16:58:46] argoneus: I never actually found this exact site when googling for rspec related issues
[16:58:49] argoneus: but it seems to have a lot of info
[16:59:51] one_zero: has joined #RubyOnRails
[17:01:58] argoneus: thanks once again!
[17:03:23] dminuoso: argoneus: While you're on that path, be sure to look at the basics how autoloading works in rails soon.
[17:04:04] dminuoso: On the one side its good to know why you never have to require files in rails, on the other sooner or later you will run into troubles. If you understand how autoloading works you usually can identify and fix them trivially.
[17:04:50] Exhiled: has joined #RubyOnRails
[17:08:43] mtkd: has joined #RubyOnRails
[17:11:10] one_zero: has joined #RubyOnRails
[17:13:24] fragamus: has joined #RubyOnRails
[17:14:43] mrbubbles: has joined #RubyOnRails
[17:15:17] mrbubbles: Don't seem to be able to set Rails.cache.write in a sidekiq job... the exact same code works in console, I can quit console and reload and it still retains it... but in the sidekiq job it doesn't seem to carry thoguh
[17:15:23] mrbubbles: Am I overlooking something obvious?
[17:16:06] dminuoso: mrbubbles: Spring perhaps? ;-)
[17:16:27] dminuoso: argoneus: ^- this is something you ought to know about too.
[17:17:51] mrbubbles: I don't know about that
[17:18:03] brent__: has joined #RubyOnRails
[17:18:45] dminuoso: Nobody ever does.
[17:19:01] mrbubbles: Oh I think I know, it's because the app is on heroku, it's using filestore caching and the file systems between the worker and the app processes are different
[17:20:01] brent__: I'm getting a " TypeError Exception: no implicit conversion of nil into Hash " when trying to call a route inside a model
[17:20:47] brent__: https://gist.github.com/brentluna/381fe6770f9ef1fe904b64d34630c7b1
[17:21:57] dminuoso: Stack trace please.
[17:21:59] brent__: it comes from line 12, i've tried puttin ga debugger inside the #stat_path and when invoking the path, it throws that type error
[17:23:11] brent__: dminuoso: updated the gist w/ the trace in additional file
[17:23:42] dminuoso: brent__: You ought to update your rails application.
[17:24:07] brent__: i spent almost a month a couple months ago updating from 3.1 to 4
[17:24:14] Exhiled: has joined #RubyOnRails
[17:24:26] brent__: we have storys for further updates when time is available
[17:24:52] brent__: also updating ruby from 2.0 to 2.3
[17:25:02] brent__: I never knew so much could be broken with an update
[17:25:36] Technodrome: has joined #RubyOnRails
[17:25:44] dminuoso: brent__: Your opts is nil.
[17:26:29] brent__: dminuoso: It's not. I can put a debugger right above line 12, and invoke the method and get the same error
[17:26:32] KeyJoo: has joined #RubyOnRails
[17:26:33] dminuoso: brent__: Its like mommy all over again. If you dont clean your room every day with just 5 minutes, cleaning it once a year is much more work.§
[17:26:35] brent__: with a hash or without
[17:27:30] brent__: oh I know, i came onto this job w/ rails 3.1, and ruby 2.0 and was able to get some time to update
[17:27:50] brent__: hoping the next updates up to 5.0 won't be as bad
[17:30:18] brent__: dminuoso: i'm pretty sure it's not part of opts... in byebug i can invoke 'retrieve_stat_admin_dashboard_path' w/ no argument and get the same error
[17:30:54] dminuoso: brent__: can you show me the line for "retrieve_stat_admin_dashboard_path" in your rails routes?
[17:31:00] dminuoso: or it might be `rake routes` on your version
[17:31:18] dminuoso: Should be named retrieve_stat_admin_dashboard in that
[17:31:34] brent__: correct, which it is
[17:31:38] brent__: i can invoke it elsehwere
[17:31:54] brent__: for instance I have 2 other models with this method
[17:31:56] brent__: #stat_path
[17:31:59] brent__: and those 2 work fine
[17:32:20] brent__: this is the only one throwing the error
[17:32:32] dminuoso: Id just like to see what the route looks like
[17:32:57] dminuoso: brent__: maybe show me a model that works (as well as with the route from that output)
[17:32:57] brent__: retrieve_stat_admin_dashboard GET /admin/dashboard/retrieve_stat(.:format) admin/dashboards#retrieve_stat
[17:33:32] dminuoso: brent__: what is `opts` ?
[17:33:58] kies: has joined #RubyOnRails
[17:34:01] brent__: statable.stat_path(stat_type: 'PublishedContent')
[17:34:06] brent__: that's the origin where it's called
[17:35:41] brent__: https://gist.github.com/brentluna/381fe6770f9ef1fe904b64d34630c7b1
[17:36:08] brent__: dminuoso: i included the methods from the other 2 models in the first file
[17:36:29] brent__: the paths called are slightly different as they belong to a competition or channel
[17:37:09] dminuoso: brent__: The controller seems faulty
[17:37:15] dminuoso: brent__: Did you override url_options?
[17:37:31] orbyt_: has joined #RubyOnRails
[17:38:07] brent__: Rails.application.routes.default_url_options = { host: 'localhost', port: '3000' }
[17:38:23] brent__: thats id development.rb
[17:38:30] dminuoso: brent__: and what environment are you in?
[17:39:05] dminuoso: brent__: So Ive looked at rails source code using that version, and it seems the only way this would error out, is if the default_url_options was nil
[17:39:12] brent__: that line i showed you where the method is called "statable.stat_path"
[17:39:16] dminuoso: you could use pry-debugger or anything else to step into those frames and confirm
[17:39:25] brent__: if i put a debugger there, i can invoke that path and it works fine
[17:39:44] brent__: it just doens't seem to want to work inside that model
[17:40:48] dminuoso: brent__: No I mean beneath your model.
[17:41:01] dminuoso: brent__: Let me show you.
[17:42:37] dminuoso: brent__: https://github.com/rails/rails/blob/v4.0.13/actionpack/lib/action_dispatch/routing/url_for.rb#L155
[17:43:19] dminuoso: brent__: This call goes into: https://github.com/rails/rails/blob/v4.0.13/activesupport/lib/active_support/core_ext/hash/reverse_merge.rb#L19
[17:43:34] dminuoso: And that would fail exactly if you tried {}.merge nil
[17:43:43] dminuoso: Leading us to conclude that url_options must be nil
[17:43:58] dminuoso: https://github.com/rails/rails/blob/v4.0.13/actionpack/lib/action_dispatch/routing/url_for.rb#L110-L112
[17:44:01] dminuoso: So this produces nil.
[17:44:03] SteenJobs: has joined #RubyOnRails
[17:45:34] brent__: https://gist.github.com/brentluna/381fe6770f9ef1fe904b64d34630c7b1
[17:46:00] brent__: dminuoso: at this point 't' is the nullstatable instance
[17:46:12] brent__: and t.url_options == nil
[17:46:26] dminuoso: brent__: You're in the wrong code visually.
[17:46:42] dminuoso: brent__: You're on line 181. Now step one in.
[17:46:50] dminuoso: And that's where things go wrong.
[17:48:27] fragamus: has joined #RubyOnRails
[17:48:49] dminuoso: Or two frames in actually.
[17:49:16] brent__: just about to be at the when Hash
[17:50:12] brent__: dminuoso: at that case, url_options is nil
[17:51:37] dminuoso: brent__: Yup, like I said.
[17:51:46] dminuoso: And that's the issue. It shouldn't be.
[17:52:12] brent__: i noticed a difference. the NullStatable doesn't inherit from ActiveRecord::Base
[17:52:15] brent__: while the 2 working do
[17:52:24] brent__: would that exclude url_options from NullStatable
[17:54:31] dminuoso: Im not sure honestly.
[18:06:28] DoubleMalt: has joined #RubyOnRails
[18:09:48] truenito: has joined #RubyOnRails
[18:12:40] mcr1: has joined #RubyOnRails
[18:14:53] brent__: dminuoso: FYI, it was that defined class method inside the model that was breaking it
[18:15:16] brent__: somoene put a method def class; OpenStruct.new(base_class: nil);end
[18:15:22] brent__: that lost the default_url_options
[18:15:43] brent__: just defining def self.base_class and removing the openstruct fixed it
[18:25:10] Exhiled: has joined #RubyOnRails
[18:26:03] [Butch]: has joined #RubyOnRails
[18:27:20] Dimik: has joined #RubyOnRails
[18:28:22] conta2: has joined #RubyOnRails
[18:37:24] arBmind: has joined #RubyOnRails
[18:38:46] dminuoso: brent__: Interesting.
[18:49:52] Cache_Money: has joined #RubyOnRails
[19:00:37] ninja247: has joined #RubyOnRails
[19:01:14] ninja247: hi all. new to Ruby. just completed a coding bootcamp and wanted to connect with the community
[19:01:42] Uranio: has joined #RubyOnRails
[19:03:41] Uranio: has left #RubyOnRails: ()
[19:05:23] orbyt_: has joined #RubyOnRails
[19:07:46] [Butch]: has joined #RubyOnRails
[19:11:10] havenwood: ninja247: hi!
[19:11:19] havenwood: ninja247: welcome
[19:11:40] Barrt: has joined #RubyOnRails
[19:14:41] quirkycoders: has joined #RubyOnRails
[19:19:09] Uranio: has joined #RubyOnRails
[19:19:29] Uranio: has left #RubyOnRails: ()
[19:22:20] ninja247: @havenwood thanks!!!
[19:22:50] ninja247: this channel seems rather technical. is there a JV version? on slack or IRC perhaps for learners
[19:27:28] havenwood: ninja247: There is a Rails Slack channel. Do feel free to ask beginner questions here as well.
[19:27:39] havenwood: ninja247: Or the Ruby channel is friendly to beginner Ruby questions.
[19:28:27] ninja247: @havenwood what’s the slack channel called? i registered for this one, but nothing happened http://www.rubyonrails.link/
[19:28:38] ninja247: maybe it takes a day or so to get approved
[19:32:26] Vircung: has joined #RubyOnRails
[19:33:14] havenwood: ninja247: Yes, it's that one. I'm sure someone here can give you an invite if you don't get one shortly.
[19:40:08] fragamus: has joined #RubyOnRails
[19:42:29] quarters: has joined #RubyOnRails
[19:46:28] Vircung: has joined #RubyOnRails
[19:51:36] Exhiled: has joined #RubyOnRails
[19:52:23] mcr1: has joined #RubyOnRails
[19:55:24] Vircung: has joined #RubyOnRails
[20:01:45] alexertech: has joined #RubyOnRails
[20:08:25] Technodrome: has joined #RubyOnRails
[20:08:29] agent_white: has joined #RubyOnRails
[20:27:13] alexertech: has joined #RubyOnRails
[20:30:35] orbyt_: has joined #RubyOnRails
[20:31:54] marr: has joined #RubyOnRails
[20:33:47] ninja247: has left #RubyOnRails: ()
[20:34:47] Vircung: has joined #RubyOnRails
[20:37:25] Barrt: has joined #RubyOnRails
[20:42:11] conta2: has joined #RubyOnRails
[20:50:49] orbyt_: has joined #RubyOnRails
[21:06:41] quazimodo: has joined #RubyOnRails
[21:11:45] sagax: has joined #RubyOnRails
[21:46:33] roshanavand: has joined #RubyOnRails
[21:48:10] kus_ubuntui686a: has joined #RubyOnRails
[21:54:32] rfoust: has joined #RubyOnRails
[21:59:28] amperry: has joined #RubyOnRails
[22:04:30] rfoust: has joined #RubyOnRails
[22:04:56] fragamus: has joined #RubyOnRails
[22:06:29] amperry: hi folks; I'm trying to create a spreadsheet using the 'spreadsheet' gem (https://github.com/zdavatz/spreadsheet). I need a link that downloads some data, and I don't know (at least) three things: (1) what kind of link_to invocation would I need, (2) what (if anything) to put in the controller 'respond_to' block, and (3) what kind of view I need to create (given that this will download from in-memory data, and not create a temp file)?
[22:06:29] amperry: Documentation seems sparse.
[22:09:07] amperry: also, I'm not married (or even engaged) to spreadsheet if there's a better gem.
[22:10:25] workmad3: has joined #RubyOnRails
[22:13:58] amperry: although I think creating a controller method and route might work... hrm...
[22:29:19] kapil___: has joined #RubyOnRails
[22:36:24] Vircung: has joined #RubyOnRails
[22:50:12] SteenJobs: has joined #RubyOnRails
[22:55:27] easzero: has joined #RubyOnRails
[22:55:49] dviola: has joined #RubyOnRails
[22:57:37] armyriad: has joined #RubyOnRails
[23:10:59] xlegoman: has joined #RubyOnRails
[23:29:32] orbyt_: has joined #RubyOnRails
[23:40:39] apeiros_: has joined #RubyOnRails
[23:43:02] macxim: has joined #RubyOnRails
[23:43:48] macxim: Does this test for PUT request make sense?
[23:43:50] macxim: https://gist.github.com/Macxim/2df431ee64efae290a7cd33643b35942
[23:51:50] quazimodo: has joined #RubyOnRails
[23:57:27] hervie: has joined #RubyOnRails