1

I'm currently having a very weird issue at the moment. I have an ExportFile model. Within a byebug console inside the tests, if I call .all, I see:

>>> ExportFile.all
#<ActiveRecord::Relation [#<ExportFile id: 189, sequence_number: 1, filename: "DB_EXPORT_20151106173840.zip", status: 3, content: 2, created_at: "2015-12-09 12:54:56", updated_at: "2015-12-09 12:54:56", first_transfer_date: nil, failed_transfer_count: 0, successful_transfer_date: "2015-12-01 12:54:56">, #<ExportFile id: 190, sequence_number: 2, filename: "DB_EXPORT_20151106173840.zip", status: 3, content: 2, created_at: "2015-12-09 12:54:56", updated_at: "2015-12-09 12:54:56", first_transfer_date: nil, failed_transfer_count: 0, successful_transfer_date: "2015-12-01 12:54:56">, #<ExportFile id: 191, sequence_number: 3, filename: "DB_EXPORT_20151106173840.zip", status: 3, content: 2, created_at: "2015-12-09 12:54:56", updated_at: "2015-12-09 12:54:56", first_transfer_date: nil, failed_transfer_count: 0, successful_transfer_date: "2015-12-01 12:54:56">, #<ExportFile id: 192, sequence_number: 4, filename: "DB_EXPORT_20151106173840.zip", status: 3, content: 2, created_at: "2015-12-09 12:54:56", updated_at: "2015-12-09 12:54:56", first_transfer_date: nil, failed_transfer_count: 0, successful_transfer_date: "2015-12-01 12:54:56">, #<ExportFile id: 193, sequence_number: 5, filename: "DB_EXPORT_20151106173840.zip", status: 3, content: 2, created_at: "2015-12-09 12:54:56", updated_at: "2015-12-09 12:54:56", first_transfer_date: nil, failed_transfer_count: 0, successful_transfer_date: "2015-12-01 12:54:56">]>

But if I try .count, or .all.to_a, I get nothing:

>>> ExportFile.count
0
>>> ExportFile.all.to_a
[]

Why is this happening and what am I doing wrong? Before running the above snippets I use FactoryGirl.create_list(:export_file, 5), if it does make a difference.

linkyndy
  • 17,038
  • 20
  • 114
  • 194

2 Answers2

1

I assume the thing is that you are in console in development mode, but FactoryGirl creates records in test database, thus you do not have access to them.

I think, that if you seed the development database with ExportData records, they'd be there for you.

Andrey Deineko
  • 51,333
  • 10
  • 112
  • 145
1

It seemed that upgrading byebug solved this issue. I've upgraded from 8.1.0 to 8.2.1. Very strange...

linkyndy
  • 17,038
  • 20
  • 114
  • 194
  • hm. This is indeed strange, but happens to very rarely, that updating the gem solves the issue – Andrey Deineko Dec 09 '15 at 14:10
  • The problem was that if I dropped `byebug` inside an example, it caused the above behaviour. If i removed it and used `puts` to output `.count`, it worked as expected. Therefore, it must've been something with `byebug`, although these kind of bugs are **very** hard to spot. – linkyndy Dec 09 '15 at 14:13