vendredi 2 septembre 2016

RoR - expected nil to be persisted, but was a new record

I'm trying to fix my application but I'm still new to Rails. So I did some tests I receive this error vom Rspec.

Rspec:

  describe 'requests to create' do
    before do
      login(FactoryGirl.create(:admin))
    end
    def valid_user_fields
      {
      :login => 'test',
      'authorized_time_entries_until(1i)' => '2007',
      'authorized_time_entries_until(2i)' => '01',
      'authorized_time_entries_until(3i)' => '01'
    }
  end
  it 'should be successfull for valid user data' do
    post :create, user: valid_user_fields
    response.should redirect_to(admin_users_path)
  end
  it 'should create an activated user' do
    post :create, user: valid_user_fields
    user = assigns(:user)
    user.should_not be_new_record
    user.should be_activated
  end
end

Failure:

1) AdminUsersController requests to create should create an activated user
Failure/Error: user.should_not be_new_record
  expected nil to be persisted, but was a new record
  # ./spec/controllers/admin_users_controller_spec.rb:71:in `block (3 levels) in <top (required)>'

Well. I tried to look for similiar problems and tried to change my controller in a way it would work. ANy ide ahow I can make this work?

Aucun commentaire:

Enregistrer un commentaire