Sto provando ad essere attivo con le chiavi primarie UUID per un modello con Postgres e Rails 4.0 .0.rc2, ma le mie specifiche non riescono a creare e distruggere, tuttavia MyThing.create
o MyThing#destroy
funziona bene dalla console di rotaie (sia in ambiente di sviluppo che di test). ... fino a quando non eseguo le specifiche, nel qual caso una di queste cose smette di funzionare tramite la console. Quindi, sembra qualcosa che accade quando eseguo le mie specifiche che alterano il mio DB e impedisce alle chiavi UUID di continuare a funzionare.RSpec, Rails 4, Postgres, chiavi primarie UUID: id è nullo con Rake + RSpec, ma va bene in RSpec o console
Halp?
ho seguito this blog post per generare la mia migrazione, così il mio schema assomiglia:
ActiveRecord::Schema.define(version: 20130613174601) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
enable_extension "uuid-ossp"
create_table "growers", id: false, force: true do |t|
t.uuid "id", null: false
t.string "name"
t.string "code"
t.datetime "created_at"
t.datetime "updated_at"
end
end
Ecco la progressione delle cose:
Crea: $ rake db:create RAILS_ENV=test
Migrate:
$ rake db:migrate RAILS_ENV=test
== CreateGrowers: migrating ==================================================
-- enable_extension("uuid-ossp")
-> 0.0052s
-- create_table(:growers, {:id=>:uuid})
-> 0.0043s
== CreateGrowers: migrated (0.0096s) =========================================
Crea e modello di oggetto:
$ rails c test
agrian> g = Grower.create name: 'bobo'
(0.3ms) BEGIN
SQL (4.1ms) INSERT INTO "growers" ("created_at", "name", "updated_at") VALUES ($1, $2, $3) RETURNING "id" [["created_at", Tue, 18 Jun 2013 20:22:39 UTC +00:00], ["name", "bobo"], ["updated_at", Tue, 18 Jun 2013 20:22:39 UTC +00:00]]
(0.4ms) COMMIT
=> #<Grower id: "38f84f39-e52e-4664-b776-4fdfcbd60b09", name: "bobo", code: nil, created_at: "2013-06-18 20:22:39", updated_at: "2013-06-18 20:22:39">
(gioia)
Run spec:
$ rake spec
/Users/sloveless/.rbenv/versions/2.0.0-p195/bin/ruby -S rspec ./spec/controllers/api/v1/growers_controller_spec.rb ./spec/helpers/growers_helper_spec.rb ./spec/models/grower_spec.rb ./spec/requests/api/v1/growers_spec.rb ./spec/routing/api/v1/growers_routing_spec.rb
...............FF..........F.*
(other stuff)
Finished in 0.30626 seconds
30 examples, 3 failures, 1 pending
Crea oggetto del modello:
$ rails c test
Loading test environment (Rails 4.0.0.rc2)
agrian> g = Grower.create name: 'bobo'
(0.4ms) BEGIN
SQL (3.5ms) INSERT INTO "growers" ("created_at", "name", "updated_at") VALUES ($1, $2, $3) [["created_at", Tue, 18 Jun 2013 20:29:36 UTC +00:00], ["name", "bobo"], ["updated_at", Tue, 18 Jun 2013 20:29:36 UTC +00:00]]
PG::Error: ERROR: null value in column "id" violates not-null constraint
DETAIL: Failing row contains (null, bobo, null, 2013-06-18 20:29:36.773391, 2013-06-18 20:29:36.773391).
: INSERT INTO "growers" ("created_at", "name", "updated_at") VALUES ($1, $2, $3)
(0.2ms) ROLLBACK
ActiveRecord::StatementInvalid: PG::Error: ERROR: null value in column "id" violates not-null constraint
DETAIL: Failing row contains (null, bobo, null, 2013-06-18 20:29:36.773391, 2013-06-18 20:29:36.773391).
: INSERT INTO "growers" ("created_at", "name", "updated_at") VALUES ($1, $2, $3)
from /Users/sloveless/.rbenv/versions/2.0.0-p195/lib/ruby/gems/2.0.0/gems/activerecord-4.0.0.rc2/lib/active_record/connection_adapters/postgresql_adapter.rb:780:in `get_last_result'
(faccia triste)
Can punto qualcuno io nella giusta direzione domanda su cosa potrebbe fare sciocchezze con il mio db?
Aggiornamento: Sono in grado di eseguire bin/rspec spec
più e più volte con successo (tutte le mie specifiche passano). Se corro rake spec
, ottengo errori, quindi la prossima volta che corro bin/rspec spec
ottengo errori.
Modifica: Titolo aggiornato per riflettere rake + rspec problema, non solo con rspec.
Sembra che essi saranno fissandolo in Rails 4.0.1. Dovrebbero intitolare l'uscita dopo di te. –