As in title, I try to fabricate hash into hstore type column.
I have seen question fabricator with hstore attribute, but the solution there does not work for me.
My hstore column name is "status", there I want to set three flags: "processed", "duplicate", "eol". I'm using sequel (4.14.0) as ORM, fabrication (2.8.1), Ruby 2.1.2 and Postgresql of course ;)
case 1:
status {eol: true, duplicate: false, processed: true}
result:
syntax error
case 2:
status {"heol"=>"true", "hduplicate"=>"false", "hprocessed"=>"true"}
result:
syntax error
case 3:
status do
{"heol"=>"true", "hduplicate"=>"false", "hprocessed"=>"true"}
end
result:
Sequel::DatabaseError: PG::DatatypeMismatch: ERROR: column "status" is of type hstore but expression is of type boolean LINE 1: ...23.0, '2000-01-01', (('heol' = '... HINT: You will need to rewrite or cast the expression.
case 4:
status do
{status: "heol:true"}
end
result:
Failure/Error: Fabricate(:entry) Sequel::DatabaseError: PG::UndefinedColumn: ERROR: column "status" does not exist LINE 1: ...123.0, '2000-01-01', ("status" =... HINT: There is a column named "status" in table "entries", but it cannot be referenced from this part of the query.
case 5:
status do {'status' => "heol:true"} end
result:
Failure/Error: Fabricate(:entry) Sequel::DatabaseError: PG::DatatypeMismatch: ERROR: column "status" is of type hstore but expression is of type boolean LINE 1: ...123.0, '2000-01-01', ('status' =... HINT: You will need to rewrite or cast the expression.
case 6: gave up ;) result: this question
With FactoryGirl everything works as expected, and syntax is straightforward:
FactoryGirl.define do
factory :entry do
status {{ flag_processed: true, flag_duplicate: false }}
end
Promise to make good use of the correct syntax in Fabrication =) Thanks!
Lucas.
Case 1 and 2 are definitely not what you want. The Hash needs to be specified within a block, which is the same as what FactoryGirl is doing with your example containing double braces. Case 3, 4, and 5 would normally work but don't because Sequel has a special syntax for assigning hstore columns and Fabrication is not automatically translating it for you (because before you brought it up I had no idea this was a thing).
If you change it to this, I think you'll find success:
status do
Sequel.hstore("heol"=>"true", "hduplicate"=>"false", "hprocessed"=>"true")
end