« Back to channel list

#RubyOnRails - 18 December 2017

« Back 1 day Forward 1 day »
[00:07:17] jrabe: has joined #RubyOnRails
[00:12:11] one_zero: has joined #RubyOnRails
[00:16:08] SteenJobs: has joined #RubyOnRails
[00:16:48] SteenJobs: has joined #RubyOnRails
[00:19:55] Exhiled: has joined #RubyOnRails
[00:31:31] amperry: has joined #RubyOnRails
[00:33:39] blackmesa: has joined #RubyOnRails
[00:34:08] amperry: having trouble running FactoryBot. I tried setting up a test app with one model, User, and one factory, ':user', in a spec/factories.rb file. I also tried moving it to a spec/factories/user.rb file. No matter what I do, I get the error: "Factory not registered: user". I'm at my wits end.
[00:34:14] sevenseacat: has joined #RubyOnRails
[00:36:47] quazimodo: has joined #RubyOnRails
[00:41:18] blackmesa1: has joined #RubyOnRails
[00:41:41] Vashy: has joined #RubyOnRails
[00:42:27] Jameser: has joined #RubyOnRails
[00:42:31] Vashy: <Vashy> hi all, I'm a beginner rubyist; I'm wondering how to lay out part of my project
[00:42:31] Vashy: <Vashy> I just started a rails project that uses a library to create an api client to make calls with
[00:42:31] Vashy: <Vashy> and I'm using the same client in a bunch of different files so I know i want to move it into it's own module and have these classes extend it... so for example: in my `app/jobs/` dir, I have two classes: `job1.rb` and `job2.rb`, where should I create the new module?
[00:42:31] Vashy: <Vashy> do I do something like: `app/jobs/new_module/api_client.rb`
[00:42:49] Vashy: sorry about the crappy copy paste, I posted it in the #ruby channel
[00:45:51] meesles: has joined #RubyOnRails
[00:58:13] blackmesa1: has joined #RubyOnRails
[01:05:44] guardianx: has joined #RubyOnRails
[01:11:51] blackmesa: has joined #RubyOnRails
[01:11:57] jnollette: has joined #RubyOnRails
[01:16:37] amperry: question: after you've added the 'factory_bot_rails' gem to your Gemfile and run 'bundle install', what is the very next command you need to run in order to set up the directories and notify rails of the paths for the factories?
[01:17:44] guardianx: has left #RubyOnRails: ()
[01:21:27] blackmesa: has joined #RubyOnRails
[01:22:34] meesles: It just the /factories folder under test or spec
[01:22:43] meesles: Then it's up to you to organize
[01:23:53] meesles: At least, that's what I can remember.find
[01:25:31] mtkd: has joined #RubyOnRails
[01:27:49] amperry: meesles: no matter where I place it, I get a "Factory not registered" error.
[01:28:04] amperry: I've tried both test/factories and spec/factories
[01:29:06] amperry: I'm wondering if I need to manually require everything in those directories in the spec_helper.rb file?
[01:29:25] blackmesa1: has joined #RubyOnRails
[01:31:07] sevenseacat: nope. you might have to share what you have
[01:31:27] meesles: Yeah, should work on its own...
[01:31:45] sevenseacat: what factory isnt registered? where is it defined? how is it defined?
[01:31:48] amperry: sevenseacat: https://gist.github.com/amp108/3336ee7ee5f6646ad0bb172ef38f1e45
[01:32:17] amperry: and I've tried placing it several places under both /spec and /test to get it to register
[01:32:43] amperry: tried both a 'factories.rb' file and a single 'user.rb' file.
[01:33:10] sevenseacat: where is this factories.rb file?
[01:33:12] meesles: yeah, filename doesn't matter in this instance
[01:33:34] amperry: right now, directly under /spec
[01:34:07] sevenseacat: you might also need to change your spec to require rails_helper instead of spec_helper
[01:34:29] amperry: do you mean the .rspec file?
[01:34:42] sevenseacat: the home_sepc
[01:34:43] meesles: idk his spec helper has the factorybot stuff
[01:34:45] meesles: so I think that's ok
[01:35:23] sevenseacat: cant hurt to try.
[01:35:41] amperry: sevenseacat: in other words, put
[01:35:57] amperry: '--require rails_helper' in the .rspec file?
[01:36:22] sevenseacat: change your home_spec to require rails_helper instead of spec_helper
[01:37:23] meesles: And you do have ` config.include FactoryBot::Syntax::Methods` in your factory_bot support file?
[01:37:32] meesles: Was just reading through the docs... not much more than that
[01:37:47] amperry: now I get "FactoryBot::DuplicateDefinitionError: Factory already registered: user"
[01:37:47] sevenseacat: thats not necesary unless you want to use the short syntax (create instead of FactoryBot.create)
[01:38:07] meesles: well that makes sense
[01:38:08] amperry: although I do have that
[01:38:32] meesles: i guess just last thing for us to double check is a screenshot of the folder structure
[01:38:39] meesles: that's the only reason I can think that factory isn't being loaded
[01:38:46] meesles: but you're reading the same docs as me so idk
[01:40:00] amperry: the gist has been updated. I do see that I have both factories.rb and user.rb, because I've been slinging files around back and forth trying to get this to work.
[01:40:09] amperry: but look at 'tree.txt'
[01:40:14] meesles: i have an idea
[01:40:21] meesles: in your factory for user
[01:40:30] meesles: anything not a string, put curly brackets around it
[01:40:41] sevenseacat: well if you have both, remove one
[01:40:52] sevenseacat: otherwise you are indeed defining your factories twice
[01:41:04] meesles: saw something on GH about factory eval failing and then that class isn't loaded
[01:41:22] meesles: Although yours is just ints and bools...
[01:41:50] amperry: nope, just moved 'user.rb' into the rails root directory, get the same error.
[01:42:21] meesles: you should delete one of those factories now, definining user twice
[01:42:25] amperry: meesles: anything "not a string"....
[01:42:29] meesles: 1 and bool
[01:43:20] meesles: Once you clear your extra file, if it doesn't work, I'd say there's an error in the factory causing it not to load. file structure looks correct
[01:46:13] amperry: extra file taken out. Spring killed, just to be sure. New error (+ old one): "Failure/Error: require File.expand_path('../../config/environment', __FILE__)" (in spec/features/home_spec.rb)
[01:46:43] amperry: I see no /config directory at all there
[01:47:15] sevenseacat: in the root of your rails app?
[01:48:07] amperry: '../..' from spec/features/home_spec.rb would be spec, unless I'm counting wrong.
[01:49:09] sevenseacat: you are. its moving up two folders, not one
[01:50:33] amperry: gaah. counting up from the file, not the dir
[01:50:40] amperry: well yes, there's a config there
[01:51:32] amperry: but not an 'environment' dir... there's an 'environments' (plural) dir, and environment.rb
[01:51:49] sevenseacat: thats the file its loading, environment.rb.
[01:52:14] alfiemax: has joined #RubyOnRails
[01:53:27] amperry: I'm running this from the rails root directory... should I be in /spec instead?
[01:54:26] meesles: doesn't matter
[01:54:33] meesles: from my experience
[01:57:42] amperry: yep, so if I "require 'spec_helper'" from spec/features/home_spec.rb, I get the 'Factory not registered' error, but if I change that to "require 'rails_helper'", I get the "require File.expand_path" and "Factory already registered" errors.
[01:57:46] Technodrome: has joined #RubyOnRails
[01:58:14] meesles: well you call your spec helper from your rails helper
[01:58:32] meesles: so that can explain that
[01:59:38] amperry: so it *should* be "require 'spec_helper'"?
[02:00:06] sevenseacat: no, it means you shouldnt be loading factory bot stuff in both
[02:03:36] Cache_Money: has joined #RubyOnRails
[02:05:03] moei: has joined #RubyOnRails
[02:05:06] amperry: rails_helper.rb has "require 'support/factory_bot'" and spec_helper.rb has "require 'factory_bot_rails'"... which one is the bad one? (I probably added the one in rails_helper.rb after looking at a stackexchange answer, if memory serves.)
[02:05:26] sevenseacat: the spec_helper one.
[02:06:01] sevenseacat: spec_helper is for tests that don't require rails, so loading rails support files in there won't work.
[02:06:23] meesles: for the record this is why i hate rspec XD
[02:06:33] sevenseacat: good for you.
[02:06:53] meesles: sour sally over here
[02:07:04] meesles: who types sigh with a period
[02:07:33] amperry: okay, so commenting out 'factory_bot_rails' from spec_helper gets me an 'uninitialized constant FactoryBot'
[02:09:21] amperry: I would rant about how poorly documented all of this seems, but I don't want to be That Guy.
[02:09:33] alexertech: has joined #RubyOnRails
[02:09:39] meesles: lol it's ok it's some js setup level library
[02:09:48] meesles: Um well you need both those lines I think
[02:09:54] meesles: Since they're different gems
[02:10:20] meesles: I just don't know about calling one helper from the other, and then if you aren't missing parts if you only call one helper
[02:10:25] amperry: Both which lines, and where should I put them?
[02:10:39] sevenseacat: https://github.com/thoughtbot/factory_bot_rails#configuration is the entire configuration youneed
[02:10:49] sevenseacat: the rest you've done extra.
[02:11:03] meesles: that's a good way to look at it :P
[02:11:13] meesles: yeah maybe start from scratch, seems like it's been overthought
[02:13:30] amperry: the spec_helper.rb and rails_helper.rb files were autogenerated (I think... I've been banging my head against this for so long it's hard to recall) by the command "rails g rspec:install"
[02:14:18] amperry: so I could tuck the spec directory away and run it again, if that's what you're getting at
[02:15:42] amperry: *is* that what you're getting at?
[02:16:30] meesles: brother, go for it
[02:16:35] meesles: worst case you reset lol
[02:17:11] meesles: And then see if you can use a generator or something for your first factory?
[02:17:19] meesles: Then you can copy
[02:17:21] amperry: mmmkay....
[02:17:38] amperry: here goes "rails g rspec:install"...
[02:18:30] amperry: and tell me if this sounds right:
[02:18:43] sevenseacat: if it works, its likely right.
[02:18:53] meesles: if it doesn't, it likely isn't.
[02:18:54] amperry: rails g factory_bot:model user first_name:string last_name:string email:string
[02:19:07] amperry: eff all if I know
[02:19:08] meesles: i've never used a factory for factorybot
[02:21:28] jnollette: has joined #RubyOnRails
[02:22:32] amperry: well, I've done mkdir 'spec/factories' and put 'user.rb' there.
[02:23:11] amperry: and a 'spec/features' and put 'home_spec.rb' there
[02:23:21] amperry: now I pull the switch...
[02:24:59] amperry: didn't like that, tells me I have to tell rails to use the test environment. Because of course, tests don't, by default, use the test environment.
[02:25:48] meesles: they.... should...
[02:26:18] sevenseacat: thats right at the top of spec_helper
[02:27:05] alfiemax: has joined #RubyOnRails
[02:27:32] amperry: I see no string 'env' or 'ENV' anywhere in spec_helper, and I haven't touched it since it was generated ten minutes ago.
[02:27:56] amperry: but whatever, running rails db:environment:set fixed it
[02:28:54] meesles: you shouldn't set your env to test locally though...
[02:29:50] sevenseacat: sorry, at the top of rails_helper is "ENV['RAILS_ENV'] ||= 'test'"
[02:30:04] sevenseacat: ACTION just spun up a new app to test
[02:30:37] amperry: ah yes, see that there
[02:31:44] amperry: okay, ran rails db:environment:set back to development
[02:32:29] amperry: well, now I have a different error so... progress?
[02:33:07] sevenseacat: the code you've posted works with the most basic config, as long as your spec loads rails_helper as it is a spec for rails
[02:35:06] amperry: when you say spec, you mean spec_helper.rb?
[02:35:22] sevenseacat: no. the actual test you've written in home_spec.
[02:36:13] amperry: which right now says "require 'rails_helper'"
[02:36:25] sevenseacat: which is good. now what error do you have?
[02:36:39] sevenseacat: as I just tested with that code and didnt get any
[02:37:45] amperry: well, it complained about a gecko driver, so I downloaded that and put it in /usr/local/bin... now I get "uninitialized constant FactoryBot" again.
[02:38:26] sevenseacat: ok. how did you install factory bot exactly?
[02:39:02] amperry: "gem 'factory_bot_rails', '~> 4.0', require: false", then 'bundle install'
[02:39:29] sevenseacat: can you please follow the installation instructions here https://github.com/thoughtbot/factory_bot_rails#configuration
[02:39:36] amperry: the 'require: false' was an attempted solution, again, based on something I read on stackexchange.
[02:39:45] sevenseacat: and not make your own things up
[02:40:42] amperry: after doing it that way, but I'll switch it back
[02:42:33] orbyt_: has joined #RubyOnRails
[02:44:52] amperry: okay, with "gem 'factory_bot_rails'" and bundle install, based on what I read there, I don't need any more configuration. I do want generators for factories to automatically substitute fixture, if by this sentence they mean "substitute factories for fixtures":
[02:45:03] amperry: Generators for factories will automatically substitute fixture (and maybe any other fixture_replacement you set).
[02:45:23] ebsen: has joined #RubyOnRails
[02:45:30] sevenseacat: yep, thats all you need to do.
[02:46:13] amperry: should I blow out spec again, or should this work as is?
[02:46:34] sevenseacat: it will be fine.
[02:47:17] amperry: "An error occurred while loading ./spec/features/home_spec.rb. Failure/Error: require File.expand_path('../../config/environment', __FILE__)"
[02:49:20] amperry: and then "FactoryBot::DuplicateDefinitionError: Factory already registered: user"
[02:52:22] amperry: also, please don't assume I just made my own things up. I had the original line in my Gemfile the first time. I can guarantee that every line I've changed or addded was an attempt to fix an error that was there after attempting a vanilla installation.
[02:52:46] amperry: because I don't like adding or changing things if they work
[02:54:20] sevenseacat: is this app public? can we see it and tinker with it to see whats going on?
[02:54:44] amperry: it's not, but I can create a simple app that (on my machine) also fails.
[02:57:04] EXCHGR: has joined #RubyOnRails
[03:03:38] ebsen: has joined #RubyOnRails
[03:07:10] amperry: don't tell me the fscking file name has to be "users.rb" and not "user.rb"
[03:08:05] KeyJoo: has joined #RubyOnRails
[03:08:24] amperry: because it just created a "users.rb" file in /spec/factories. Using 'user.rb' fails, but 'users.rb' works, in my new test app.
[03:10:00] amperry: nope, maybe it's the file itself. renaming it didn't do anything.
[03:17:55] alfiemax: has joined #RubyOnRails
[03:17:57] amperry: sevenseacat: of course, the third time I created a test app, it worked.
[03:18:11] sevenseacat: now whats different in your test app to your real app?
[03:18:27] amperry: I have a bunch fewer gems, for one thing.
[03:18:40] sevenseacat: in terms of rspec and factory bot config
[03:19:00] amperry: specifically, what files am I looking at?
[03:19:18] sevenseacat: all of the ones your test app has created in the process of making it work.
[03:20:54] amperry: hmmm... for one thing, there's a spec/models directory in the test app, and not in my working directory.
[03:22:01] amperry: so, in the interest of science, I'll copy spec/models and the one file there into it.
[03:25:26] jnollette: has joined #RubyOnRails
[03:27:00] amperry: nope, that didn't seem to do it. Now I can't even get 'rails s' to run because I'm getting "Factory already registered: user"
[03:27:27] Radar: [13:54:44] <amperry> it's not, but I can create a simple app that (on my machine) also fails.
[03:27:35] Radar: amperry: Did I miss the GitHub link for this?
[03:28:01] amperry: Radar: https://gist.github.com/amp108/3336ee7ee5f6646ad0bb172ef38f1e45
[03:28:10] Radar: I meant more the simple app.
[03:28:27] Radar: My guess is that something is requiring the factory file twice.
[03:28:32] amperry: oh. Not yet. I started going down a different path once that started to work.
[03:28:51] Radar: Ok. Let me know when you get that app together and I can help you figure it out. Do it in the next 20mins or so because I'm busy for the rest of the day after that.
[03:29:15] sevenseacat: this has been going on all morning
[03:32:42] amperry: Radar: https://github.com/amp108/test_factory
[03:32:49] amperry: that one works
[03:34:28] amperry: unfortunately, I don't know how to add information from the existing repository that wouldn't be giving away sensitive information.
[03:34:45] amperry: of course, the most sensitive information is what a lousy coder I am, but still...
[03:38:01] DmitryBochkarev: has joined #RubyOnRails
[03:41:42] amperry: so I was getting a "Factory already registered: user" error when I tried to run "rails s"; I hid both the spec/ and test/ directories and that error went away. Going to try to regenerate spec and see what happens.
[03:46:08] amperry: that's fine. It's when I do "rails g factory_bot:model user first_name last_name email" that the server starts tripping up.
[03:46:30] amperry: that creates the directory and file spec/factories/users.rb
[03:47:06] sevenseacat: i think your 20min are just about up
[03:50:34] Radar: amperry: So that app _doesn't_ have the problem?
[03:51:44] Radar: amperry: https://github.com/amp108/test_factory/blob/master/spec/rails_helper.rb
[03:51:55] Radar: Note here how you're _not_ requiring your factories file
[03:51:57] Radar: but it's still working
[03:52:09] Radar: Note also in your Gist that you _are_ manually requiring your factories file, and it's broken
[03:52:19] Radar: So maybe stop requiring the file? That's probably what's happening. It's being loaded twice.
[03:52:55] amperry: which file, which line?
[03:53:11] amperry: oh, I think I see.
[03:53:55] amperry: except I blew that one away and have the generic rails_helper.rb file in there now.
[03:56:35] amperry: well, I do appreciate the help. I'll see if I can't track down where I'm requiring something twice.
[04:00:19] sandstrom: has joined #RubyOnRails
[04:05:49] amperry: ah well, back to fixtures it is. Thanks, all.
[04:11:29] Saukk: has joined #RubyOnRails
[04:19:15] alfiemax: has joined #RubyOnRails
[04:20:12] ur5us: has joined #RubyOnRails
[04:40:19] Technodrome: has joined #RubyOnRails
[04:44:30] Technodrome: has left #RubyOnRails: ()
[04:47:40] jnollette: has joined #RubyOnRails
[04:49:47] Cache_Money: has joined #RubyOnRails
[04:51:09] jnollette: has joined #RubyOnRails
[05:14:13] _aeris_: has joined #RubyOnRails
[05:18:03] fcser_: has joined #RubyOnRails
[05:20:09] Cache_Money: has joined #RubyOnRails
[05:20:15] drale2k_: has joined #RubyOnRails
[05:32:08] srinidhi: has joined #RubyOnRails
[05:40:05] meesles: has joined #RubyOnRails
[05:47:03] quazimodo: has joined #RubyOnRails
[05:58:05] iamarun: has joined #RubyOnRails
[06:10:37] alfiemax: has joined #RubyOnRails
[06:13:44] reber: has joined #RubyOnRails
[06:17:06] ur5us: has joined #RubyOnRails
[06:20:22] Cache_Money: has joined #RubyOnRails
[06:24:47] desnudopenguino: has joined #RubyOnRails
[06:36:52] MrCrackPotBuilde: has joined #RubyOnRails
[06:49:52] apeiros: has joined #RubyOnRails
[06:49:59] desnudopenguino: is there a way to view a complete Net:HTTP request string?
[06:50:38] kapil___: has joined #RubyOnRails
[06:57:14] hive-mind: has joined #RubyOnRails
[07:01:53] apeiros: has joined #RubyOnRails
[07:07:53] fcser_: has joined #RubyOnRails
[07:08:37] srinidhi: has joined #RubyOnRails
[07:09:13] roshanavand: has joined #RubyOnRails
[07:11:11] Dimik: has joined #RubyOnRails
[07:24:51] moei: has joined #RubyOnRails
[07:27:52] moei: has joined #RubyOnRails
[07:33:15] morfin60: has joined #RubyOnRails
[07:33:46] morfin60: i forgot how define route for single record in resource?
[07:35:46] morfin60: member do\n get 'show'\n end something like that?
[07:48:19] dionysus69: has joined #RubyOnRails
[08:12:52] srinidhi: has joined #RubyOnRails
[08:27:41] Jameser: has joined #RubyOnRails
[08:29:55] acosonic: has joined #RubyOnRails
[08:30:53] s2013: has joined #RubyOnRails
[08:35:45] mappuji: has joined #RubyOnRails
[08:40:29] marr: has joined #RubyOnRails
[08:43:52] mappuji_: has joined #RubyOnRails
[08:58:34] defsdoor: has joined #RubyOnRails
[09:01:49] defsdoor: has joined #RubyOnRails
[09:03:07] morfin60: if i have entity called SeoPage which load SEO information by URL(it's required to show meta tags for all pages) and specific entities(News, Article etc) with metatag fields too how would you load first local fields(for Article as example) then from SeoPage?
[09:03:44] sandstrom: has joined #RubyOnRails
[09:10:33] srinidhi: has joined #RubyOnRails
[09:12:42] alfiemax: has joined #RubyOnRails
[09:28:10] alfiemax: has joined #RubyOnRails
[09:34:03] sevenseacat: has joined #RubyOnRails
[09:34:15] srinidhi: has joined #RubyOnRails
[09:49:05] arBmind: has joined #RubyOnRails
[09:49:36] drale2k_: has joined #RubyOnRails
[09:54:27] gregf_: has joined #RubyOnRails
[09:54:34] mtkd: has joined #RubyOnRails
[09:55:00] pikislabis: has joined #RubyOnRails
[09:59:00] cschneid_: has joined #RubyOnRails
[10:01:59] Cavallari: has joined #RubyOnRails
[10:09:41] quazimodo: has joined #RubyOnRails
[10:13:00] srinidhi: has joined #RubyOnRails
[10:39:54] cschneid_: has joined #RubyOnRails
[10:52:58] arBmind: has joined #RubyOnRails
[11:19:09] ahrs: has joined #RubyOnRails
[11:23:58] Ergo: has joined #RubyOnRails
[11:33:39] sameerynho: has joined #RubyOnRails
[11:39:31] pikislabis: has joined #RubyOnRails
[12:00:43] uksio: has joined #RubyOnRails
[12:02:29] cschneid_: has joined #RubyOnRails
[12:15:50] _ritchie_: has joined #RubyOnRails
[12:26:42] pikislabis: has joined #RubyOnRails
[12:28:05] _aeris_: has joined #RubyOnRails
[12:32:04] noob_on_rails: has joined #RubyOnRails
[12:33:28] noob_on_rails: hey all , i have 2 models Parent and Child , Parent has an attr: minimum_interval , child has an attr live_interval that shouldn't be lower than the Parent.minimum_interval
[12:34:31] noob_on_rails: now , if i update the parent attribute minimum_interval , and use : parent.children.update_all() to avoid N+1 , how can i be able to say , change the childrens live interval , if it's less than your minimum interval?
[12:37:00] cschneid_: has joined #RubyOnRails
[12:42:39] desperek: has joined #RubyOnRails
[12:51:29] truenito: has joined #RubyOnRails
[12:53:06] KeyJoo: has joined #RubyOnRails
[12:55:04] truenito: has joined #RubyOnRails
[13:21:09] gheegh: has joined #RubyOnRails
[13:21:14] mostlybadfly: has joined #RubyOnRails
[13:22:02] za1b1tsu: has joined #RubyOnRails
[13:22:07] mtkd: has joined #RubyOnRails
[13:23:41] alfiemax: has joined #RubyOnRails
[13:28:25] cschneid_: has joined #RubyOnRails
[13:29:35] za1b1tsu: I have a service object called Feedback, when I instantiate the class it should create a new object. When I test this in rspec, it { expect{Feedback.new(order.id, client.id)}.to change{Session.count}.by(1) } it says undefined method `create!' for nil:NilClass https://gist.github.com/bbtdev/56f3d9a9eb54475cb9570c4dba5da8d3
[13:29:59] za1b1tsu: Is there something I'm missing regarding rspec? the assocations work
[13:31:25] Jameser: has joined #RubyOnRails
[13:32:42] tcopeland: has joined #RubyOnRails
[13:32:55] jrabe: has joined #RubyOnRails
[13:34:52] tbuehlmann: za1b1tsu: looks like Order.find(order_id).session is nil in your example
[13:35:54] za1b1tsu: yes, but why? since I've created them the order_id is proper
[13:36:10] za1b1tsu: *by them I mean, order and client
[13:36:41] za1b1tsu: Order with that particular id should exist
[13:37:01] za1b1tsu: client = Client.create! order = client.orders.create!
[13:38:16] tbuehlmann: what is session?
[13:39:08] za1b1tsu: a session is an active model, that belongs to order, and order has one session
[13:40:40] drale2k_: has joined #RubyOnRails
[13:40:44] za1b1tsu: If I type Order.find(order_id).sessionS for example it says undefined method `sessions' for #<Order:0x5642298> Did you mean? session. So associations work, I also tested them with reflect_on_association
[13:41:24] tbuehlmann: have you setup a session for you example?
[13:41:49] tbuehlmann: oh, ha, you want to, right?
[13:42:24] tbuehlmann: try Order.find(order_id).create_session!
[13:42:33] za1b1tsu: yeap, but not like the classic sessions, this does something else
[13:43:25] za1b1tsu: wow, it works... can you tell me why?
[13:44:18] tbuehlmann: order.session returns the associated session. if there is none, it returns nil. so calling order.session.create! is like calling nil.create!, which doesn't make sense
[13:44:41] tbuehlmann: when you want to create the session, that can be done by calling order.create_session!, that's it
[13:45:04] tbuehlmann: you can check up on http://guides.rubyonrails.org/association_basics.html
[13:45:50] za1b1tsu: So why did this work order = client.orders.create! ?
[13:46:30] za1b1tsu: client = Client.create! client is just created
[13:46:54] marahin: Hello! https://gist.github.com/Marahin/d1e062840916bdb69d2ec663f418cd0c - having this, I want to make sure that global_tag_id is unique ALSO between two contexts: 'hq_tag' and 'office_tag'. Is there a way to achieve that?
[13:47:30] marahin: (also with previous definition remaining - so it's overall unique in scope of taggable and context)
[13:47:51] marahin: (and I should say: what IS the best way to achieve that, as it's for sure achievable one way, or another :D)
[13:48:16] tbuehlmann: za1b1tsu, client.orders returns a relation which responds to .create!, this also works for Client
[13:48:24] za1b1tsu: tbuehlmann: I understand
[13:49:35] za1b1tsu: oh, another question if you can, I see a of things about mocks and stubs, I didnt have time to learn about them. In tests like these I should use mocks and stubs only because of speed?
[13:53:09] noob_on_rails: if i includes a child model to the parent , how can i afterwards filter some of the children , and user .update_all on them ?
[13:54:30] noob_on_rails: for example , @parent = Parent.includes(:children).first , taller = parent.children.map { |c| c if c.height > p.height } , taller.update_all({height: parent.height})
[13:54:42] noob_on_rails: this wont work , cause it's just an array of objects
[13:55:39] noob_on_rails: any way i can use a single query style update in a filtered collection?
[14:02:17] jrabe: has joined #RubyOnRails
[14:03:32] gheegh: has joined #RubyOnRails
[14:04:26] truenito: has joined #RubyOnRails
[14:37:05] truenito: has joined #RubyOnRails
[14:43:55] rikkipitt: has joined #RubyOnRails
[14:44:51] rikkipitt: hey folks, suppose I'm allowing users to select a date range (start, end). What would be a programatic way of logically grouping the range by a time period?
[14:45:27] rikkipitt: e.g. the select a day, group by hour. a week, group by day. a year, group by month.
[15:05:29] Saukk: has joined #RubyOnRails
[15:06:25] gheegh: has joined #RubyOnRails
[15:08:52] truenito: has joined #RubyOnRails
[15:11:06] helpa: has joined #RubyOnRails
[15:11:17] LateralOctober: has joined #RubyOnRails
[15:11:20] noob_on_rails: rikkipitt: you'd have to do the math i suppose
[15:13:52] waseem_: has joined #RubyOnRails
[15:14:08] cschneid_: has joined #RubyOnRails
[15:15:21] npgm: has joined #RubyOnRails
[15:23:53] gheegh: has joined #RubyOnRails
[15:26:25] mtkd: has joined #RubyOnRails
[15:29:13] dionysus69: has joined #RubyOnRails
[15:33:29] troys: has joined #RubyOnRails
[15:33:39] yebyen: has joined #RubyOnRails
[15:34:40] yebyen: does anyone know if there's a way to trap a server error during a (feature) test with capybara? I have this condition that my design spec has promised will never happen, and I want to make sure the right error shows up in the server log when it inevitably happens anyway
[15:35:07] yebyen: i'm using expect { bad_button.click }.to raise_error err_class.constantize
[15:35:28] yebyen: but that does not work because the error is not raised out of the user side
[15:36:42] yebyen: The output from cucumber just tells me that the error was simultaneously not encountered and not handled (it was raised, it wasn't raised...)
[15:36:58] yebyen: this is with Capybara.run_server=true
[15:40:13] yebyen: I mean, I guess I could reconfigure the app to display the error instead of just logging it
[15:40:37] yebyen: but it seems like a lot of trouble for something that was promised not to ever happen, by the admin users, in the specs
[15:41:04] yebyen: i'd rather just display the "something went horribly wrong" page
[15:44:42] workmad3_: has joined #RubyOnRails
[15:44:57] ebsen: has joined #RubyOnRails
[15:51:06] waseem_: yebyen: If your design spec has promised it will never happen, why test for it? Or write any code for it?
[15:53:19] _ritchie_: has joined #RubyOnRails
[15:54:51] yebyen: waseem_: coverage?
[15:55:01] yebyen: it's potentially really bad if that is allowed to pass
[15:55:08] safetypin: has joined #RubyOnRails
[15:55:15] yebyen: (it's a Budget Change object, and there are no budget changes allowed without an approver...)
[15:55:35] yebyen: If this error does not come at this particular time, then a budget change may be allowed through the workflow with no approver :D
[15:56:32] waseem_: yebyen: Could you stub out the condition that raises the exception?
[15:57:05] yebyen: I think I'm just going to catch the exception and display it on the "new" page
[15:57:28] yebyen: there's a pretty obvious place to rescue and render 'new'
[15:58:39] Sirecote: has joined #RubyOnRails
[16:03:08] safetypin: has joined #RubyOnRails
[16:11:40] yebyen: which of course means I have to make it look pretty... :\
[16:18:16] Exhiled: has joined #RubyOnRails
[16:26:22] dblessing: has joined #RubyOnRails
[16:32:20] kapil___: has joined #RubyOnRails
[16:36:14] joshsmith: has joined #RubyOnRails
[16:40:51] Cavallari: has joined #RubyOnRails
[16:42:22] DrYockel: has joined #RubyOnRails
[16:46:54] cagomez: has joined #RubyOnRails
[16:47:58] SteenJobs: has joined #RubyOnRails
[16:48:33] cagomez: has joined #RubyOnRails
[16:49:49] dblessing: has joined #RubyOnRails
[16:53:02] dachinat: has joined #RubyOnRails
[16:53:35] yehowyada: has joined #RubyOnRails
[16:54:33] safetypin: has joined #RubyOnRails
[16:54:39] dachinat: Hello. Can you help? When updating a record with nested attributes @record.nested.first.id differs when debugged form 'edit' action. After unsuccessful update @record.nested.first.id is different.
[16:55:12] dachinat: I'm using Rails 5.1.4
[16:55:45] mikecmpbll: has joined #RubyOnRails
[16:59:10] lupine: dachinat: ensure you pass the id along in the update
[16:59:18] lupine: the id of the nested item, I mean
[16:59:40] lupine: if it's nil, it'll just go and create a new one for you
[17:01:21] dachinat: lupine: I have checked and there's correct value for id, same that is debugged on 'edit' action.
[17:02:31] dachinat: I have f.simple_fields_for :support_threads, @support_ticket.support_threads.first do |thread| and on unsuccessful update it gets different value
[17:03:11] drale2k_: has joined #RubyOnRails
[17:03:15] dachinat: i can't get why this happens..
[17:04:17] alfiemax: has joined #RubyOnRails
[17:04:55] dviola: has joined #RubyOnRails
[17:09:11] one_zero: has joined #RubyOnRails
[17:10:14] helpa: has joined #RubyOnRails
[17:17:07] one_zero: has joined #RubyOnRails
[17:18:12] Exhiled: has joined #RubyOnRails
[17:22:28] [Butch]: has joined #RubyOnRails
[17:24:33] srinidhi: has joined #RubyOnRails
[17:27:50] Cache_Money: has joined #RubyOnRails
[17:29:08] amperry: has joined #RubyOnRails
[17:30:16] Exhiled: has joined #RubyOnRails
[17:30:38] amperry: has joined #RubyOnRails
[17:31:45] mtkd: has joined #RubyOnRails
[17:32:31] mrbubbles: has joined #RubyOnRails
[17:32:50] mrbubbles: Has anyone used Pundit?
[17:33:06] amperry: I have, but I wouldn't say I'm an expert by any means.
[17:34:01] amperry: I've got users who have access to different properties, and use it (among other things) to restrict which property a particular user might have access to.
[17:34:23] mrbubbles: Oh amperry - I was going to say... what version of factoryBot do you have in your Gemfile.lock?
[17:34:59] amperry: mrbubbles: 4.8.2
[17:35:09] mrbubbles: https://github.com/thoughtbot/factory_bot/issues/1055
[17:35:18] mrbubbles: I saw this earlier... someone else was discussing the same issue you had
[17:35:34] mrbubbles: See https://github.com/thoughtbot/factory_bot/issues/1055#issuecomment-338425454
[17:36:47] orbyt_: has joined #RubyOnRails
[17:37:18] Cavallari: has joined #RubyOnRails
[17:37:31] amperry: mrbubbles: it seems like, following this logic, I should also add 'factory_bot' to my Gemfile? I'll give that a try.
[17:37:41] mrbubbles: Hmm, I'd go the other way
[17:37:51] mrbubbles: Try updating your Gemfile to include the latest Github version of factory_bot_rails
[17:37:53] mrbubbles: e.g. gem 'factory_bot_rails', github: 'thoughtbot/factory_bot', branch: '4-9-0-stable'
[17:37:59] mrbubbles: That will hopefully sort it
[17:39:12] cagomez: has joined #RubyOnRails
[17:39:18] amperry: Fingers crossed.
[17:40:24] amperry: hrm... that wasn't the exact invocation: "Source does not contain any versions of 'factory_bot_rails'"
[17:44:54] gheegh: has joined #RubyOnRails
[17:46:54] FrostCandy: has joined #RubyOnRails
[17:48:02] amperry: mrbubbles: what I'd resorted to was wrapping "if :factory_name.nil?" blocks around all of my definitions, but that's tedious. I tried using an "#ifndef"-style global variable like "if $my_factories_defined.nil?", but that didn't have any effect.
[17:49:18] amperry: Interesting that the factory_bot 4.9.0 page still refers to itself as 'factory_girl_rails' in the docs.
[17:50:36] xibalba: has joined #RubyOnRails
[17:50:58] alfiemax: has joined #RubyOnRails
[17:51:15] drale2k_: has joined #RubyOnRails
[17:51:59] mrbubbles: amperry is the error you're getting: NameError: uninitialized constant User ?
[17:52:05] za1b1tsu: has joined #RubyOnRails
[17:52:15] amperry: which time?
[17:52:26] workmad3: has joined #RubyOnRails
[17:53:10] mrbubbles: Ah no sorry my bad
[17:53:30] mrbubbles: Okay so I've just scaffolded up a new project and done the barebones to have FactoryBot be able to build a new object
[17:54:00] za1b1tsu: Regarding a has_many/belongs_to association, if I want also the viceversa I need a foreign key in the other table as well?
[17:54:21] mrbubbles: Things to check: 1) in your gemfile you need rspec-rails and factory_bot_rails and these should be wrapped in group :development, :test do
[17:54:59] amperry: mrbubbles: check
[17:55:33] mrbubbles: Next, if you're creating a factory for :user then you need to have a User model and a users table created. You should have this already though
[17:55:56] mrbubbles: Next, in spec/factories/users.rb (plural) you should have the following:
[17:56:11] mrbubbles: https://gist.github.com/joeczucha/c698019c8a840fd10bbed1dbf4a5f783
[17:56:19] mrbubbles: Note factory name is singular, but in a plural filename
[17:58:04] amperry: I have more fields because my actual user model does, but otherwise, check.
[17:58:48] mrbubbles: No I haven't needed to
[17:59:14] mrbubbles: Okay, and it's named plural? Not sure if it makes a difference but just in case
[17:59:31] amperry: it is, although I've tried that both ways.
[18:00:44] mrbubbles: Hmm. How far along is the project? Would it be a huge job to remove anything confidential and git a copy so that I can have a play? This is annoying me now :)
[18:01:56] amperry: I'll be honest. About two lines are confidential. I am so embarrassed by my code I can't bear to put it up.
[18:03:33] amperry: I was going to ask a different question because I have a workaround, clumsy though it is.
[18:04:38] mrbubbles: Haha mate don't worry my code is hardly amazing
[18:07:19] Sirecote: has joined #RubyOnRails
[18:07:55] amperry: I can add you as a collaborator. (Come to think of it, I think the confidential stuff was .gitignored anyhow.)
[18:08:07] amperry: mrbubbles: that is, on github
[18:15:24] dachinat: (fyi) lupine and others who have seen my issue with nested attributes and invalid first record id, there was some kind of issue with database, I've remigrated and all went fine.
[18:22:05] Dimik: has joined #RubyOnRails
[18:28:27] cagomez: has joined #RubyOnRails
[18:32:14] orbyt_: has joined #RubyOnRails
[18:33:02] mikecmpbll: has joined #RubyOnRails
[18:38:08] mikecmpbll: has joined #RubyOnRails
[18:43:42] SteenJobs: has joined #RubyOnRails
[18:50:06] _ritchie_: has joined #RubyOnRails
[18:55:48] mikecmpbll: has joined #RubyOnRails
[19:06:44] mikecmpb_: has joined #RubyOnRails
[19:07:59] dionysus69: has joined #RubyOnRails
[19:09:55] reber: has joined #RubyOnRails
[19:11:09] reber: how to rake with some data in the database please ?
[19:32:38] desnudopenguino: reber: what do you mean?
[19:33:23] reber: ok found seeds :)
[19:38:01] dminuoso: reber: Rake is not special..
[19:38:15] dminuoso: Rake is just a way of invoking tasks. Inside its just plain ruby code.
[19:38:46] reber: as i said, it's found thanks discussion closed :)
[19:41:12] NoGodDamnIdea: has joined #RubyOnRails
[19:47:24] romeoh: has joined #RubyOnRails
[19:53:22] SteenJobs_: has joined #RubyOnRails
[19:59:43] cagomez: has joined #RubyOnRails
[20:01:17] marr: has joined #RubyOnRails
[20:03:00] amperry: ongoing trying-to-create-tests saga: can't login using Warden and Capybara. Gist: https://gist.github.com/amp108/171232957ba9d1307a28dca476f7887f
[20:04:11] mrbubbles: has joined #RubyOnRails
[20:15:26] cagomez: has joined #RubyOnRails
[20:17:49] dminuoso: amperry: The way the helper is rigged, login_as hooks into the _next_ request.
[20:17:57] dminuoso: amperry: So you have to call login_as before `visit`
[20:19:03] dminuoso: iow: login_as doesn't perform any site interaction. so just visit some page.
[20:19:54] dminuoso: amperry: Incidentally that makes this a rather useless test, because login_as skips almost everything you probably might be interested in testing.
[20:20:16] amperry: I have no doubt.
[20:20:25] superscott: has joined #RubyOnRails
[20:21:44] mrbubbles: Where is the best place to test URL params? As in, I have a few dropdowns on the page which each add a sorting param to the URL. I want to check that clicking one sets the URL param correctly
[20:22:22] dminuoso: mrbubbles: Just run it through capybara
[20:22:53] amperry: dminuoso: I'm trying to do two things, and any documentation (other than https://github.com/teamcapybara/capybara or https://github.com/plataformatec/devise/wiki/How-To:-Test-with-Capybara, which I'm perusing now) you know of would help:
[20:23:01] romeoh: has joined #RubyOnRails
[20:23:15] dminuoso: amperry: I just read the source.
[20:23:20] mrbubbles: Thanks dminuoso - so i'm sorting using scopes. Probably capybara to test that the url params are set and then test that the scopes work as expected in the model spec?
[20:23:54] amperry: 1) just test logging in itself, and 2) have a logged in user for all tests that require one (which is all of them).
[20:24:43] mtkd: has joined #RubyOnRails
[20:25:11] amperry: all capybara tests, anyhow. It seems like my situation would be so common that the first google hit of 'capybara login' would do it, but no such luck.
[20:26:43] mtkd: has joined #RubyOnRails
[20:28:24] _aeris_: has joined #RubyOnRails
[20:30:46] dminuoso: amperry: 1) you just fill out the login form and submit it
[20:30:50] dminuoso: amperry: 2) you use the login_as helper.
[20:31:05] cagomez: has joined #RubyOnRails
[20:32:54] dminuoso: amperry: You can avoid boilerplate by using shared examples in rspec for example.
[20:35:19] amperry: dminuoso: thanks
[20:35:30] dminuoso: (Or shared contexts rather)
[20:40:41] ur5us: has joined #RubyOnRails
[20:41:03] ebsen: has joined #RubyOnRails
[20:41:51] amperry: dminuoso: could I trouble you to take a look again? I think I've misunderstood your instructions, which I am wont to do.
[20:42:11] orbyt_: has joined #RubyOnRails
[20:42:54] dminuoso: amperry: https://github.com/hassox/warden/blob/master/lib/warden/test/helpers.rb#L19-L21
[20:42:57] dminuoso: This is what the helper does.
[20:43:07] dminuoso: Based on this, is it obvious why your first attempt didn't work?
[20:44:18] amperry: my first attempt, I think so. But I don't know why the second attempt didn't.
[20:45:29] mrbubbles: Is there any way to get URL params with Capybara? I'm using expect(page).to have_current_path at the moment but that matches the entire URL
[20:46:39] dminuoso: mrbubbles: Since you have Rack available (boon of a rails app) you can use Rack::Utils
[20:48:20] Radanisk: has joined #RubyOnRails
[20:48:44] dminuoso: amperry: Without seeing your new code I cant say.
[20:49:37] amperry: dminuoso: I included it at the top of the gist: https://gist.github.com/amp108/171232957ba9d1307a28dca476f7887f#file-_error-txt
[20:55:44] dminuoso: amperry: https://github.com/plataformatec/devise/wiki/How-To:-Test-with-Capybara#if-your-login-works-using-capybararacktest-but-not-in-capybaraselenium
[20:56:06] dminuoso: amperry: This is a result of you using `js: true`
[20:56:11] dminuoso: You can't have both.
[20:56:51] dminuoso: (You'll probably want some truncation logic after each test)
[21:03:05] amperry: has joined #RubyOnRails
[21:03:34] amperry: cursed network
[21:04:30] amperry: dminuoso: I asked a question then got disconnected. But it seems like setting use_transactional_fixtures to true means there'll be a db write?
[21:05:35] dminuoso: amperry: The problem is just how transactions work.
[21:06:25] dminuoso: amperry: You can juryrig AR to allow this to work if you want: https://github.com/teamcapybara/capybara/blob/2.4.4/README.md#transactions-and-database-setup
[21:06:53] truenito: has joined #RubyOnRails
[21:11:58] romeoh: has joined #RubyOnRails
[21:14:39] sameerynho: has joined #RubyOnRails
[21:15:59] amperry: dminuoso: I'm fine with setting it to true and emptying out the db afterwards. It's only test, after all. That page recommends cucumber or database_cleaner; any opinions?
[21:16:57] cagomez: has joined #RubyOnRails
[21:18:10] dminuoso: amperry: You cant set it to true.
[21:19:21] ramfjord: has joined #RubyOnRails
[21:23:03] amperry: erm, I meant false.
[21:23:11] Exhiled: has joined #RubyOnRails
[21:34:54] mostlybadfly: has joined #RubyOnRails
[22:05:50] quazimodo: has joined #RubyOnRails
[22:07:46] mrbubbles: dminuoso - sorry I'm struggling to work out how to use Rack::Utils to grab the URL params... can you point me in the right direction? Should I be using unescape?
[22:08:13] dminuoso: mrbubbles: parse_query/parse_nested_query
[22:12:12] justicef_: has joined #RubyOnRails
[22:25:39] romeoh: has joined #RubyOnRails
[22:32:12] desperek: has joined #RubyOnRails
[22:49:15] desperek: has joined #RubyOnRails
[23:08:36] Dimik: has joined #RubyOnRails
[23:08:38] Radar: GOOD MRONING
[23:08:41] Radar: MORNING ALSO
[23:16:03] helpa: MAYBE I CAN GET THEIR ATTENTION WITH LARGE, CAPITAL LETTERS
[23:16:13] dminuoso: ACTION waves at Radar
[23:23:49] baweaver: ACTION waves at dminuoso and Radar 
[23:35:43] s2013: has joined #RubyOnRails
[23:46:25] romeoh: has joined #RubyOnRails
[23:46:58] nogic: has joined #RubyOnRails
[23:48:11] mikecmpbll: has joined #RubyOnRails
[23:59:18] tamouse__: has joined #RubyOnRails