Machinist/Authlogic problem -- Validation failed: User is invalid (password "can't be blank")

99 views
Skip to first unread message

Mitch

unread,
Aug 19, 2009, 5:26:54 PM8/19/09
to Machinist Users
Hi, all

I've recently started using Machinist to clean up my company's
cucumber and rspec test code, which had massive duplication,
particularly between the two sides. This was going great until I hit
this snag with User...

We have Users, with a many-to-many relationship to Group through
Membership.
User is the user for AuthLogic, and the models look like this:

class User < ActiveRecord::Base
has_many :memberships
has_many :groups, :through => :memberships
end
class Group < ActiveRecord::Base
has_many :memberships
has_many :users, :through => :memberships
end
class Membership < ActiveRecord::Base
belongs_to :group, :validate=>true
belongs_to :user, :validate=>true
end

With blueprints as obvious:

User.blueprint do
email
password { "asdf" }
password_confirmation { password }
end
Group.blueprint do
end
Membership.blueprint do
group
user
end

The problem arises in our membership_spec, specifically in the test to
prevent duplicate memberships:
describe Membership do
it "should not be able to create an instance with duplicated
group_id and user_id combination" do
membership = Membership.make
duplicate_membership = Membership.make(:group_id =>
membership.group.id, :user_id => membership.user.id)
lambda{duplicate_membership.save!}.should raise_error() {|error| p
error.backtrace}
end
This fails with "ActiveRecord::RecordInvalid: Validation failed: User
is invalid", and checking membership.user.valid indicates that errors
just contains {"password"=>["can't be blank"]}
This does not occur when we create the user explicitly:

describe Membership do
it "should not be able to create an instance with duplicated
group_id and uer_id combination" do
user = User.make
membership = Membership.make(:user => user)
duplicate_membership = Membership.make(:group_id =>
membership.group.id, :user_id => user.id)
lambda{duplicate_membership.save!}.should raise_error() {|error| p
error.backtrace}
end

Did I make some obvious mistake? Please say yes :-)
Thanks in advance,
--Mitch

Pete Yandell

unread,
Aug 23, 2009, 9:27:42 PM8/23/09
to Machinist Users
Hi Mitch,

That all looks ok to me, although I don't know what AuthLogic does
with the password field. I'm guessing there's some magic around
password hashing, etc.

No easy answer, I'm afraid! You'll have to keep digging.

- Pete
Reply all
Reply to author
Forward
0 new messages