Re: [rspec-users] id getting overwritten with 0 when testing
On Jan 25, 2012, at 12:43 AM, Guyren G Howe wrote: On Jan 24, 2012, at 11:27 PM, Julian Leviston wrote: On 25/01/2012, at 5:24 PM, Guyren G Howe wrote: My code that saves a record works fine in development or production, or from the console. I can take the code in my test and run it in the console, and it works fine. But when I run it under a model rspec, the ids are getting set to 0. I’ve traced it through to where I do: Model.create params where I can see that the id is what I want to set it to in params. Same problem with rspec 2.6 and 2.8. Don’t make me switch to Test::Unit. Anyone? It'd be nice to have a bit of context for this issue. It's most likely an issue with your model's validation… Not sure what else to tell you. I’ve a complex bit of logic I want to exercise that’s accepting a hierarchy of objects submitted to the application as JSON. The controller pulls it apart into a hierarchical key-value hash. I’ve a recursive operation that walks this structure, pulling out individual objects and saving them. Everything works fine when I test it manually (e.g. in console). When I run the same sequence of operations with the same values in console (i.e. I tested it by copying the values and operations out of the spec into the console), it all works fine. But it all fails horribly in rspec because the ids are getting overwritten with 0s. I can get to the point in my code where I hand things over to ActiveRecord, and the hash I’m giving to create is exactly what I’m after including the id value. FWIW, the ids I’m trying to use are UUIDs. Since I’m entirely sure the hash I’m handing to create is correct, I’m left with trying to grub around inside ActiveRecord, which I don’t look forward to. So: in what way does RSpec modify the behavior of ActiveRecord that might bear on this? ___ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users http://ariejan.net/2008/08/12/ruby-on-rails-uuid-as-your-activerecord-primary-key Make sure the column is 16-byte binary ___ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users
Re: [rspec-users] id getting overwritten with 0 when testing
It'd be nice to have a bit of context for this issue. It's most likely an issue with your model's validation... Julian On 25/01/2012, at 5:24 PM, Guyren G Howe wrote: My code that saves a record works fine in development or production, or from the console. I can take the code in my test and run it in the console, and it works fine. But when I run it under a model rspec, the ids are getting set to 0. I’ve traced it through to where I do: Model.create params where I can see that the id is what I want to set it to in params. Same problem with rspec 2.6 and 2.8. Don’t make me switch to Test::Unit. Anyone? ___ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users ___ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users
Re: [rspec-users] id getting overwritten with 0 when testing
On Wed, 25 Jan 2012, Justin Ko wrote: http://ariejan.net/2008/08/12/ruby-on-rails-uuid-as-your-activerecord-primary-key Make sure the column is 16-byte binary And be sure to update your test database's schema so that it behaves the same as your other environments: rake db:test:clone_structure Patrick J. Collins http://collinatorstudios.com ___ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users
Re: [rspec-users] id getting overwritten with 0 when testing
On Jan 25, 2012, at 1:42 AM, Patrick J. Collins wrote: On Wed, 25 Jan 2012, Justin Ko wrote: http://ariejan.net/2008/08/12/ruby-on-rails-uuid-as-your-activerecord-primary-key Make sure the column is 16-byte binary And be sure to update your test database's schema so that it behaves the same as your other environments: rake db:test:clone_structure You actually want to use rake db:test:prepare. It does the same thing as clone_structure but doesn't create the nasty structure.sql file. http://stackoverflow.com/questions/7693365/whats-the-difference-between-dbtestclone-dbtestclone-structure-dbtestlo Patrick J. Collins http://collinatorstudios.com ___ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users ___ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users
Re: [rspec-users] id getting overwritten with 0 when testing
See that's HEAPS better! More information. Pffft ... not sure what else to tell us! Okay so NOW to me it sounds a lot like you're using a non-integer as a primary key which I wouldn't do... And also, could it not be a string coersion issue? (ie params coersion) Julian On 25/01/2012, at 6:43 PM, Guyren G Howe wrote: On Jan 24, 2012, at 11:27 PM, Julian Leviston wrote: On 25/01/2012, at 5:24 PM, Guyren G Howe wrote: My code that saves a record works fine in development or production, or from the console. I can take the code in my test and run it in the console, and it works fine. But when I run it under a model rspec, the ids are getting set to 0. I’ve traced it through to where I do: Model.create params where I can see that the id is what I want to set it to in params. Same problem with rspec 2.6 and 2.8. Don’t make me switch to Test::Unit. Anyone? It'd be nice to have a bit of context for this issue. It's most likely an issue with your model's validation… Not sure what else to tell you. I’ve a complex bit of logic I want to exercise that’s accepting a hierarchy of objects submitted to the application as JSON. The controller pulls it apart into a hierarchical key-value hash. I’ve a recursive operation that walks this structure, pulling out individual objects and saving them. Everything works fine when I test it manually (e.g. in console). When I run the same sequence of operations with the same values in console (i.e. I tested it by copying the values and operations out of the spec into the console), it all works fine. But it all fails horribly in rspec because the ids are getting overwritten with 0s. I can get to the point in my code where I hand things over to ActiveRecord, and the hash I’m giving to create is exactly what I’m after including the id value. FWIW, the ids I’m trying to use are UUIDs. Since I’m entirely sure the hash I’m handing to create is correct, I’m left with trying to grub around inside ActiveRecord, which I don’t look forward to. So: in what way does RSpec modify the behavior of ActiveRecord that might bear on this? ___ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users ___ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users
Re: [rspec-users] id getting overwritten with 0 when testing
On Wed, Jan 25, 2012 at 3:29 PM, Guyren G Howe gisbo...@emailuser.net wrote: On Jan 25, 2012, at 3:44 AM, Julian Leviston wrote: Okay so NOW to me it sounds a lot like you're using a non-integer as a primary key which I wouldn't do... I don’t think you’ve tried to write a server app that synchronizes with handheld apps over an unreliable internet connection. UUIDs make things *so* much easier. The decision about the pks is made. Am I understanding from folks here that rspec *won’t work* without integer primary keys? That is a major design flaw, if true. RSpec provides a thin wrapper around the testing framework that ships with Rails and extends T/U. I'm not sure I understand the problem yet, but I'd be really surprised if it's anything RSpec is doing or failing to do. What versions of RSpec and Rails are you using? ___ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users
Re: [rspec-users] id getting overwritten with 0 when testing
On Jan 25, 2012, at 1:45 PM, David Chelimsky wrote: Just looked back at your initial email and see you cited rspec-2.8, but the way Rails handles incoming params in tests changed in either 3.1 or 3.2 (I have to check). Which rails version specifically? 3.1. Since I was *always* going to be providing a UUID for the pk, I didn’t even bother changing the default value for the pk in the schema. I’m going to try fixing that and see if it’s any better. ___ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users
Re: [rspec-users] id getting overwritten with 0 when testing
On Wed, Jan 25, 2012 at 3:37 PM, David Chelimsky dchelim...@gmail.com wrote: On Wed, Jan 25, 2012 at 3:29 PM, Guyren G Howe gisbo...@emailuser.net wrote: On Jan 25, 2012, at 3:44 AM, Julian Leviston wrote: Okay so NOW to me it sounds a lot like you're using a non-integer as a primary key which I wouldn't do... I don’t think you’ve tried to write a server app that synchronizes with handheld apps over an unreliable internet connection. UUIDs make things *so* much easier. The decision about the pks is made. Am I understanding from folks here that rspec *won’t work* without integer primary keys? That is a major design flaw, if true. RSpec provides a thin wrapper around the testing framework that ships with Rails and extends T/U. I'm not sure I understand the problem yet, but I'd be really surprised if it's anything RSpec is doing or failing to do. What versions of RSpec and Rails are you using? Just looked back at your initial email and see you cited rspec-2.8, but the way Rails handles incoming params in tests changed in either 3.1 or 3.2 (I have to check). Which rails version specifically? ___ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users
Re: [rspec-users] id getting overwritten with 0 when testing
On Wed, Jan 25, 2012 at 3:49 PM, Guyren G Howe gisbo...@emailuser.net wrote: On Jan 25, 2012, at 1:45 PM, David Chelimsky wrote: Just looked back at your initial email and see you cited rspec-2.8, but the way Rails handles incoming params in tests changed in either 3.1 or 3.2 (I have to check). Which rails version specifically? 3.1. Since I was *always* going to be providing a UUID for the pk, I didn’t even bother changing the default value for the pk in the schema. I’m going to try fixing that and see if it’s any better. I'd start by debugging to see where the wheels fall off. Are you familiar/comfortable with Ruby's debugger? ___ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users
Re: [rspec-users] id getting overwritten with 0 when testing
On Jan 25, 2012, at 1:56 PM, David Chelimsky wrote: I'd start by debugging to see where the wheels fall off. Are you familiar/comfortable with Ruby's debugger? Sure. What’s happening is that during the save process, I get to field_changed? in dirty.rb, which does value = column.type_cast(value) when I look at column here, it believes @sql_type = “integer”. Which seems weird. So at this point, it occurs to me to check this against my test database, and the columns in the test database are indeed integers! How does this come to be? ___ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users
Re: [rspec-users] id getting overwritten with 0 when testing
On Jan 25, 2012, at 4:50 PM, Guyren G Howe wrote: On Jan 25, 2012, at 1:56 PM, David Chelimsky wrote: I'd start by debugging to see where the wheels fall off. Are you familiar/comfortable with Ruby's debugger? Sure. What’s happening is that during the save process, I get to field_changed? in dirty.rb, which does value = column.type_cast(value) when I look at column here, it believes @sql_type = “integer”. Which seems weird. So at this point, it occurs to me to check this against my test database, and the columns in the test database are indeed integers! How does this come to be? And note that rake db:test:load doesn’t change anything. ___ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users
Re: [rspec-users] id getting overwritten with 0 when testing
On Wed, Jan 25, 2012 at 7:20 PM, Guyren Howe guy...@mac.com wrote: On Jan 25, 2012, at 4:50 PM, Guyren G Howe wrote: On Jan 25, 2012, at 1:56 PM, David Chelimsky wrote: I'd start by debugging to see where the wheels fall off. Are you familiar/comfortable with Ruby's debugger? Sure. What’s happening is that during the save process, I get to field_changed? in dirty.rb, which does value = column.type_cast(value) when I look at column here, it believes @sql_type = “integer”. Which seems weird. So at this point, it occurs to me to check this against my test database, and the columns in the test database are indeed integers! How does this come to be? And note that rake db:test:load doesn’t change anything. I'm not sure what rake db:test:load actually does, but `RAILS_ENV=test rake db:reset` should probably do the trick. What db are you using, btw? ___ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users
Re: [rspec-users] id getting overwritten with 0 when testing
On Jan 25, 2012, at 6:20 PM, Guyren Howe wrote: On Jan 25, 2012, at 4:50 PM, Guyren G Howe wrote: On Jan 25, 2012, at 1:56 PM, David Chelimsky wrote: I'd start by debugging to see where the wheels fall off. Are you familiar/comfortable with Ruby's debugger? Sure. What’s happening is that during the save process, I get to field_changed? in dirty.rb, which does value = column.type_cast(value) when I look at column here, it believes @sql_type = “integer”. Which seems weird. So at this point, it occurs to me to check this against my test database, and the columns in the test database are indeed integers! How does this come to be? And note that rake db:test:load doesn’t change anything. ___ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users Please paste the table from your schema.rb file. ___ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users
Re: [rspec-users] id getting overwritten with 0 when testing
On Jan 24, 2012, at 11:27 PM, Julian Leviston wrote: On 25/01/2012, at 5:24 PM, Guyren G Howe wrote: My code that saves a record works fine in development or production, or from the console. I can take the code in my test and run it in the console, and it works fine. But when I run it under a model rspec, the ids are getting set to 0. I’ve traced it through to where I do: Model.create params where I can see that the id is what I want to set it to in params. Same problem with rspec 2.6 and 2.8. Don’t make me switch to Test::Unit. Anyone? It'd be nice to have a bit of context for this issue. It's most likely an issue with your model's validation… Not sure what else to tell you. I’ve a complex bit of logic I want to exercise that’s accepting a hierarchy of objects submitted to the application as JSON. The controller pulls it apart into a hierarchical key-value hash. I’ve a recursive operation that walks this structure, pulling out individual objects and saving them. Everything works fine when I test it manually (e.g. in console). When I run the same sequence of operations with the same values in console (i.e. I tested it by copying the values and operations out of the spec into the console), it all works fine. But it all fails horribly in rspec because the ids are getting overwritten with 0s. I can get to the point in my code where I hand things over to ActiveRecord, and the hash I’m giving to create is exactly what I’m after including the id value. FWIW, the ids I’m trying to use are UUIDs. Since I’m entirely sure the hash I’m handing to create is correct, I’m left with trying to grub around inside ActiveRecord, which I don’t look forward to. So: in what way does RSpec modify the behavior of ActiveRecord that might bear on this? ___ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users