0

I'm attempting to write out some unit tests for my Rails application using RSpec. I'm using Rails 4.0.0 and Rspec-Rails 2.14.6. My User model:

class User < ActiveRecord::Base
  devise :database_authenticatable, :registerable,
    :recoverable, :rememberable, :trackable, :validatable,
    :omniauthable, :omniauth_providers => Settings.authentication.providers.map { |i| i.to_sym }

  validates :password, presence: true, allow_nil: true,
    allow_blank: true, if: :password_required?
  validates :email, presence: true

  def password_required?
    self.providers.empty?
  end

  has_many :providers
  has_one :profile
end

And my (magical) spec:

require 'spec_helper'

describe User do
  describe '.new' do
    it 'can create a valid user with no providers'  do
      params = ActionController::Parameters.new(FactoryGirl.attributes_for :user)
      u = User.create params.permit!
      expect(u).to be_new_record
    end
  end

  describe '.build_with_provider' do
    it 'can create a valid user with a provider' do
      puts ap(User)
      provider   = FactoryGirl.create :provider
      oauth_data = FactoryGirl.attributes_for :oauth_data
      u = User.build_from_provider_and_oauth_data provider, oauth_data
      expect(u).to_not be_nil
      expect(u).to be_new_record
      expect(u).to be_valid
      u.save
      expect(u).to be_persisted
    end
  end
end

If I'm missing something, please let me know. As far as I know, using ActionController::Parameters is the new way of (white|black)listing parameters in Rails 4.

jackyalcine
  • 469
  • 1
  • 8
  • 21
  • 1
    It seems like you're asking for a code review. If so, that's not something StackOverflow is intended for, but there is http://codereview.stackexchange.com/ – Peter Alfvin Oct 31 '13 at 20:56
  • If you're getting results you don't expect/understand, please describe the results and what you're expecting to get. – Peter Alfvin Oct 31 '13 at 20:57

0 Answers0