I’m trying to do a simple assert of the value of a column returned from
MySQL
using the sequel gem. However, the type is an Array, rather than a
String.
I found that cur_user.map(:phone).to_s works, but I don’t understand why
the
default type of a varchar column comes back as an Array. Any insight
would
be appreciated.
nabblee wrote:
puts "not equal" if cur_user.map(:phone) != '9995551212'
Why is the content of the phone column considered an Array? What is the
proper syntax to make the assert succeed?
I’ve never used the sequel gem, I think your problem here is that
this:@db[:users].where(:username
=> ‘test1’, :password => ‘test1’)
returns an array of users, not just a single user object. Also, calling
the
map method on an array will return another array, not a single value.
So
you are trying to compare of values to a single value. Here’s my hunch
how
you want your test to look:
This way you are getting the first record from the original query, so
now
cur_user is a single object, not an array. And if I read the sequel
documentation right, you can reference individual columns like a hash or
something. So you use cur_user[:phone] to get the phone column from the
record. Good luck.
I’m with you, Joe. My first inclination was cur_user[:phone], but that
doesn’t work at all. You have to use the map method to gain access to
the
columns.
The first line fails, but the second one succeeds: