Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/mongodb/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Rspec无法与mongodb正常工作_Mongodb_Rspec_Ruby On Rails 4_Mongomapper - Fatal编程技术网

Rspec无法与mongodb正常工作

Rspec无法与mongodb正常工作,mongodb,rspec,ruby-on-rails-4,mongomapper,Mongodb,Rspec,Ruby On Rails 4,Mongomapper,我有以下用户类 class User include MongoMapper::Document key :email, String, :unique => true end 还有我的rspec代码 before do @user = FactoryGirl.create(:user) end describe "when email address is already taken" do before do user_with_same_ema

我有以下用户类

class User
  include MongoMapper::Document 
  key :email, String, :unique => true
end
还有我的rspec代码

before do
  @user = FactoryGirl.create(:user)
end

 describe "when email address is already taken" do
    before do
      user_with_same_email = @user.dup
      user_with_same_email.email = @user.email
      user_with_same_email.save
    end
    it { should_not be_valid }
  end
引发以下错误

1) User when email address is already taken 
      Failure/Error: it { should_not be_valid }
       expected #<User _id: BSON::ObjectId('5236bec5ebe8660fcb00001a'), accepted_tender_ids: [], avatar: #<Avatar _id: BSON::ObjectId('5236bec3ebe8660fcb000001'), digest: "c7358a60a79905a7d4e3383ba905f1baaab278b06a6f751971344cb91763068f", image: "c7358a60a79905a7d4e3383ba905f1baaab278b06a6f751971344cb91763068f">, busy: false, completed_count: 0, completed_tender_ids: [], confirmed: true, dialogs: [], dislikes: 0, email: "maurice_langworth@treutel.com", role: "customer", subspecializations: [], type: "personal"> not to be valid
预期用户无效,但它是有效的

具有相同电子邮件的用户将无法保存,因此数据库中不会有第二个用户具有您的电子邮件;假设subject是@user,则不会有冲突,用户将是有效的


您是否忘了将主题定义为具有相同电子邮件的用户

不,为什么我需要主题作为用户使用相同的电子邮件?我的代码类似于M.Hartl的代码,因为当你没有特别指定一个主题时,它就是指这个代码。