Reputation: 2847
When running my specs I get the following error:
Failures: 1) UserMailer account_activation renders the headers Failure/Error: mail.subject.should eq("Bazleyapp account activation") ArgumentError: wrong number of arguments (0 for 1)
I can't solve the wrong number of arguments problem. What is it referring to? The error message isn't very helpful.
user_mailer_spec.rb:
require "spec_helper"
describe UserMailer do
describe "account_activation" do
let(:mail) { UserMailer.account_activation }
it "renders the headers" do
mail.subject.should eq("Bazleyapp account activation")
end
end
end
user_mailer.rb:
class UserMailer < ActionMailer::Base
default from: "[email protected]"
def account_activation(user)
@user = user
mail to: user.email, subject: "Bazleyapp account activation"
end
end
config/environments/test.rb:
config.action_mailer.delivery_method = :test
config.action_mailer.default_url_options = { host: 'localhost:3000' }
EDIT:
I made the change that BroiSatse suggested and I now get this error:
UserMailer account_activation renders the headers Failure/Error: let(:user) { FactoryGirl.create(:user) } ArgumentError: wrong number of arguments (1 for 0)
In fact I have just noticed that this error is appearing throughout my whole test suite wherever
let(:user) { FactoryGirl.create(:user) }
appears. So the problem has shifted to FactoryGirl?
My factories.rb file is:
FactoryGirl.define do
factory :user do
sequence(:name) { |n| "User #{n}" }
sequence(:email) { |n| "user_#{n}@example.com" }
sequence(:callsign) { |n| "user_#{n}" }
password "foobar"
password_confirmation "foobar"
activated true
factory :admin do
admin true
end
end
end
User.rb:
class User < ActiveRecord::Base
attr_accessor :remember_token, :activation_token, :reset_token
has_one :ghost, dependent: :destroy
has_many :personas, dependent: :destroy
has_secure_password
before_save do
self.email.downcase!
self.callsign.downcase!
end
before_create :create_activation_digest
after_save do
self.create_ghost unless ghost
end
validates :name, presence: true,
length: { maximum: 50 }
VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-]+(?:\.[a-z\d\-]+)*\.[a-z]+\z/i
validates :email, presence: true,
format: { with: VALID_EMAIL_REGEX },
uniqueness: { case_sensitive: false }
VALID_CALLSIGN_REGEX = /\A[a-z\d\-.\_]+\z/i
validates :callsign, presence: true,
length: { maximum: 20 },
format: { with: VALID_CALLSIGN_REGEX },
uniqueness: { case_sensitive: false }
validates :password, length: { minimum: 6 }
def to_param
callsign
end
def self.digest(string)
cost = ActiveModel::SecurePassword.min_cost ? BCrypt::Engine::MIN_COST :
BCrypt::Engine.cost
BCrypt::Password.create(string, cost: cost)
end
def self.new_token
SecureRandom.urlsafe_base64
end
def remember
self.remember_token = User.new_token
update_attribute(:remember_digest, User.digest(remember_token))
end
def forget
update_attribute(:remember_digest, nil)
end
def authenticated?(attribute, token)
digest = send("#{attribute}_digest")
return false if digest.nil?
BCrypt::Password.new(digest).is_password?(token)
end
def activate
update_columns(activated: true, activated_at: Time.zone.now)
end
def send_activation_email
UserMailer.account_activation(self).deliver_now
end
def create_reset_digest
self.reset_token = User.new_token
update_columns(reset_digest: User.digest(reset_token),
reset_sent_at: Time.zone.now)
end
def send_password_reset_email
UserMailer.password_reset(self).deliver_now
end
def password_reset_expired?
reset_sent_at < 2.hours.ago
end
private
def create_activation_digest
self.activation_token = User.new_token
self.activation_digest = User.digest(activation_token)
end
end
Upvotes: 1
Views: 1459
Reputation: 29419
This is due to an incompatibility between ActiveRecord 4.2 Beta 4 and the newly released Arel and is addressed in https://stackoverflow.com/a/27140014/1008891
When I went through Michael Hartl's tutorial he was pretty adamant that his tutorial is only guaranteed to work with the specific versions of the gems he identified.
Upvotes: 1