2011-10-22 7 views
5

मेरे rspec परीक्षण मुझेrspec उपयोगकर्ता परीक्षण "अपरिभाषित स्थानीय चर या विधि` confirmed_at ' "

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

मेरे उपयोगकर्ता कल्पना दे रहा है देता है:

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 

मैं के लिए किसी भी संदर्भ नहीं मिल सकता है

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 
: confirmed_at

मैं वसीयत 1.4.8 मेरे उपयोगकर्ता माइग्रेशन था

मेरे उपयोगकर्ता तालिका है:

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

क्या देवता को आपके उपयोगकर्ता में 'confirm_at' की आवश्यकता है? मैंने कभी इसका इस्तेमाल नहीं किया है, यह सिर्फ एक जंगली अनुमान है। –

+0

धन्यवाद एमयू! हाँ ऐसा लगता है लेकिन ऐसा लगता है कि यह जनरेटर इसमें शामिल नहीं है और इससे पहले कि मैं जाउंगा और इसे मैन्युअल रूप से जोड़ूं, मैं देखना चाहता था कि किसी और ने इसे देखा है या नहीं। –

+0

शायद माइग्रेशन माइग्रेशन? http://groups.google.com/group/plataformatec-devise/browse_thread/thread/f7d79b0cdada6992 –

उत्तर

7

ऐसा लगता है कि कहीं न कहीं रास्ते में वसीयत के लिए "confirmable" विन्यास याद किया। आप तीन लापता कॉलम अपने आप को जोड़ या कुछ इस तरह की कोशिश (this thread के तल के पास Reza.Hashemi के संदेश देख सकते हैं:

$ rails g migration addconfirmable 

फिर इस के लिए प्रवास संपादित:

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

और अंत में, हमेशा की तरह:

$ rake db:migrate 

मुझे लगता है कि इसके बाद के संस्करण की प्रक्रिया अपने तीन कॉलम जोड़ना चाहिए:

  • confirmed_at :datetime
  • confirmation_token :string
  • confirmation_sent_at :datetime
आप के लिए

। या आप इसे हाथ से कर सकते हैं।

+0

ग्रेट एमयू, थक्स, आप सबसे अच्छे हैं! –

+0

क्या इस उत्तर को Devise v3 में अपडेट करने का कोई मौका है ??? : डी – Jeff

+0

@ जेफ: क्षमा करें, मैं अभी डेविस का उपयोग नहीं कर रहा हूं इसलिए मुझे नहीं पता कि v3 की क्या आवश्यकता होगी। –

0

Mongoid के लिए, उपयोगकर्ता मॉडल में देखें - आवश्यक फ़ील्ड पर टिप्पणी की जा सकती है। मेरे लिए, वे थे:

## 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