2011-10-22 9 views
5

mio test rspec mi sta dandoprova di utente rspec dà "indefinito variabile locale o metodo` confirmed_at'"

NameError: 
    undefined local variable or method `confirmed_at' for #<User:0xca6ff98> 

mio spec utente è:

require 'spec_helper' 

describe User do 

    before(:each) do 
     @user = Factory(:user) 
    end 
    # Factory will make sure that in the future if attributes are added the tests below don't break 
    # Just as long as the Factory is updated for the new attributes as appropriate. 

    context "email is null" do 
     it "record is invalid " do 
     @user.name = nil 
     @user.should_not be_valid 
     end 
    end 

    context "email is unique" do 
     it "record is valid " do 
     @user2 = Factory(:user) 
     @user2 = @user.email 
     @user2.should_not be_valid 
     end 
    end 

end 

non riesco a trovare alcun riferimento a confirmed_at

devo elaborare 1.4.8 La mia migrazione degli utenti è stato:

class DeviseCreateUsers < ActiveRecord::Migration 
    def self.up 
    create_table(:users) do |t| 
     t.database_authenticatable :null => false 
     t.recoverable 
     t.rememberable 
     t.trackable 

     # t.encryptable 
     # t.confirmable 
     # t.lockable :lock_strategy => :failed_attempts, :unlock_strategy => :both 
     # t.token_authenticatable 


     t.timestamps 
    end 

    add_index :users, :email,    :unique => true 
    add_index :users, :reset_password_token, :unique => true 
    # add_index :users, :confirmation_token, :unique => true 
    # add_index :users, :unlock_token,   :unique => true 
    # add_index :users, :authentication_token, :unique => true 
    end 

    def self.down 
    drop_table :users 
    end 
end 

mia tabella utente è:

mysql> describe users; 
+------------------------+--------------+------+-----+---------+----------------+ 
| Field     | Type   | Null | Key | Default | Extra   | 
+------------------------+--------------+------+-----+---------+----------------+ 
| id      | int(11)  | NO | PRI | NULL | auto_increment | 
| email     | varchar(255) | NO | UNI |   |    | 
| encrypted_password  | varchar(128) | NO |  |   |    | 
| reset_password_token | varchar(255) | YES | UNI | NULL |    | 
| reset_password_sent_at | datetime  | YES |  | NULL |    | 
| remember_created_at | datetime  | YES |  | NULL |    | 
| sign_in_count   | int(11)  | YES |  | 0  |    | 
| current_sign_in_at  | datetime  | YES |  | NULL |    | 
| last_sign_in_at  | datetime  | YES |  | NULL |    | 
| current_sign_in_ip  | varchar(255) | YES |  | NULL |    | 
| last_sign_in_ip  | varchar(255) | YES |  | NULL |    | 
| created_at    | datetime  | YES |  | NULL |    | 
| updated_at    | datetime  | YES |  | NULL |    | 
| last_name    | varchar(255) | YES |  | NULL |    | 
| first_name    | varchar(255) | YES |  | NULL |    | 
+------------------------+--------------+------+-----+---------+----------------+ 
+1

Devise richiede un 'confirmed_at' nel tuo utente? Non l'ho mai usato quindi è solo un'ipotesi. –

+0

Grazie mu! Sì, sembra così ma sembra strano che il generatore non lo includa e prima di andare ad aggiungerlo manualmente volevo vedere se qualcun altro l'avesse visto. –

+0

Migrazione mancante forse? http://groups.google.com/group/plataformatec-devise/browse_thread/thread/f7d79b0cdada6992 –

risposta

7

Sembra che vi siete persi la configurazione "confirmable" per Devise da qualche parte lungo la strada. È possibile aggiungere le tre colonne mancanti da soli o provare qualcosa di simile (vedi il messaggio di Reza.Hashemi vicino al fondo della this thread:

$ rails g migration addconfirmable 

quindi modificare la migrazione a questo:

def self.up 
    change_table(:users) do |t| 
    t.confirmable 
    end 
end 

e, infine, il solito:

$ rake db:migrate 

penso che il processo di cui sopra dovrebbe aggiungere le tre colonne:

  • confirmed_at :datetime
  • confirmation_token :string
  • confirmation_sent_at :datetime

per voi. O puoi farlo a mano.

+0

Great mu, thx, sei il migliore! –

+0

C'è qualche possibilità di ottenere questa risposta aggiornata a Devise v3 ??? : D – Jeff

+0

@Jeff: Scusa, non sto utilizzando Devise in questo momento, quindi non so che cosa v3 avrebbe bisogno. –

0

Per Mongoid, cercare nel modello utente - i campi necessari possono essere commentati. Per me erano:

## Confirmable 
field :confirmation_token, :type => String 
field :confirmed_at,   :type => Time 
field :confirmation_sent_at, :type => Time 
field :unconfirmed_email, :type => String # Only if using reconfirmable 
Problemi correlati