2013-02-26 2 views
0

У меня есть этот тест adminuser модели, и я получил эти результаты и error.What проблемы и как я могу это исправить admin_user_spec.rbрельсов спецификация с Shoulda жемчужиной

require 'spec_helper' 

describe AdminUser do 

    it { should allow_mass_assignment_of(:email) } 
    it { should allow_mass_assignment_of(:password) } 
    it { should allow_mass_assignment_of(:password_confirmation) } 
    it { should allow_mass_assignment_of(:remember_me) } 

end 

Результат:

1) AdminUser 
    Failure/Error: it { should allow_mass_assignment_of(:password) } 
    NoMethodError: 
     undefined method `allow_mass_assignment_of' for #<RSpec::Core::ExampleGroup::Nested_1:0x007f8d58d5d3a0> 
    # ./spec/models/admin_user_spec.rb:6:in `block (2 levels) in <top (required)>' 

AdminUser.rb

class AdminUser < ActiveRecord::Base 
    # Include default devise modules. Others available are: 
    # :token_authenticatable, :confirmable, :lockable and :timeoutable 
    devise :database_authenticatable, :trackable 

    # :timeoutable, :lockable 

    # Setup accessible (or protected) attributes for your model 
    attr_accessible :email, :password, :password_confirmation, :remember_me 

# after_create { |admin| admin.send_reset_password_instructions } 

    # def password_required? 
    # new_record? ? false : super 
    # end 

end 
+0

может у показать ур модель здесь? –

+0

Я добавил AdminUser.rb –

+0

уверены, что 'должен разрешить' или' should_not allow' для пароля? – Learner

ответ

0

Дайте попробовать ...

require 'spec_helper' 

describe AdminUser do 

    it { should allow_mass_assignment_of(:email) } 
    it { should allow_mass_assignment_of(:password).as(:admin) } 
    it { should allow_mass_assignment_of(:password_confirmation) } 
    it { should allow_mass_assignment_of(:remember_me) } 

end 
+0

Я пробовал, он не работает –

+0

Вы проверили, что 'должен разрешить' для' password' является правильным? или 'should allow_not'? – Learner

0

Попробуйте добавить

require 'shoulda-matchers' 
require 'shoulda/matchers/integrations/rspec' 

в верхней части spec_helper.rb

+0

Не работает –

0

я добавил

require 'shoulda/integrations/rspec2' 

это выше

require 'rspec/rails' 

в spec_helper.rb и проблема решена

Смежные вопросы