I have a basic user class and doing rspec validations. When I do a factory
create to produce validations it blows up before I can get to the second
line to check for errors. Ideas how to get this to perform like AR
Validations?
MongoMapper::DocumentNotValid:
Validation failed: Password can''t be blank, Email can''t
be blank,
Password digest can''t be blank
class User
include MongoMapper::Document
include ActiveModel::SecurePassword
attr_accessible :email, :password
key :password_digest, String
key :password, String, :required => true
key :email, String, :required => true
has_secure_password
end
it "should not authenticate with incorrect password" do
user = Factory(:user, :email=> '''', :password =>
'''').should
have(2).errors
#user.should have(2).errors #_on(:name)
end
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://rubyforge.org/pipermail/rspec-users/attachments/20110903/9c7b9378/attachment.html>
Hey Chris. Could you be more specific than "it blows up"? If there''s a stack trace, that''d be helpful. -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20110903/6f3ac167/attachment.html>
Sorry, it fails validation which it should but it errors out in the cli as
opposed to going along and checking, it does not get past the inital factory
new line:
Failure/Error: user = Factory(:user, :email=> '''', :password
=> '''')
MongoMapper::DocumentNotValid:
Validation failed: Password can''t be blank, Email can''t
be blank,
Password digest can''t be blank
On Sat, Sep 3, 2011 at 20:41, Nick <nick at deadorange.com> wrote:
> Hey Chris. Could you be more specific than "it blows up"? If
there''s a
> stack trace, that''d be helpful.
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
>
--
*"In matters of style, swim with the current; in matters of principle,
stand
like a rock."
Thomas Jefferson
*
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://rubyforge.org/pipermail/rspec-users/attachments/20110904/08819244/attachment.html>
What does the backtrace say? -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20110904/51408e3e/attachment.html>
MongoMapper::DocumentNotValid:
Validation failed: Password can''t be blank, Email can''t
be blank,
Password digest can''t be blank
On Sun, Sep 4, 2011 at 19:06, Nick <nick at deadorange.com> wrote:
> What does the backtrace say?
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
>
--
*"In matters of style, swim with the current; in matters of principle,
stand
like a rock."
Thomas Jefferson
*
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://rubyforge.org/pipermail/rspec-users/attachments/20110904/bceb24ce/attachment.html>
I seem to have the same problem. DId you guys find out what the problem was? Thanks On Sep 5, 3:11?am, Chris Habgood <chabg... at gmail.com> wrote:> MongoMapper::DocumentNotValid: > ? ? ? ?Validation failed: Password can''t be blank, Email can''t be blank, > Password digest can''t be blank > > On Sun, Sep 4, 2011 at 19:06, Nick <n... at deadorange.com> wrote: > > What does the backtrace say? > > _______________________________________________ > > rspec-users mailing list > > rspec-us... at rubyforge.org > >http://rubyforge.org/mailman/listinfo/rspec-users > > -- > *"In matters of style, swim with the current; in matters of principle, stand > like a rock." > Thomas Jefferson > * > > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users
On Sep 3, 2011, at 4:17 PM, Chris Habgood wrote:> I have a basic user class and doing rspec validations. When I do a factory create to produce validations it blows up before I can get to the second line to check for errors. Ideas how to get this to perform like AR Validations? > > MongoMapper::DocumentNotValid: > Validation failed: Password can''t be blank, Email can''t be blank, Password digest can''t be blank > > class User > include MongoMapper::Document > include ActiveModel::SecurePassword > > attr_accessible :email, :password > > key :password_digest, String > key :password, String, :required => true > key :email, String, :required => true > > has_secure_password > end > > it "should not authenticate with incorrect password" do > user = Factory(:user, :email=> '''', :password => '''').should have(2).errorsTry Factory.build instead of Factory (which is an alias for Factory.create): user = Factory.build(:user, :email => '''', :password => '''') user.should_not be_valid # this triggers the validation user.should have(1).error_on(:email) user.should have(1).error_on(: password) HTH, David> #user.should have(2).errors #_on(:name) > end
Hi
I sort of fixed the issue. Let me first describe it some more.
My tests kept generating the following failed test:
1) Portfolio require a valid e-mail address
Failure/Error: port = Factory :portfolio, :email => email
MongoMapper::DocumentNotValid:
Validation failed: Email is invalid
# ./spec/models/portfolio_spec.rb:44:in `block (3 levels) in <top
(required)>''
# ./spec/models/portfolio_spec.rb:43:in `each''
# ./spec/models/portfolio_spec.rb:43:in `block (2 levels) in <top
(required)>''
This tells me my validation is working as it should be. But although
the code in production reacts normally on ''update_attributes''
or
''save'' by returning a ''false'', in my test
the
MongoMapper::DocumentNotValid: is raised.
I fixed it by using the following test code:
lambda { port = Factory :portfolio, :email => '''' }.should
raise_error(MongoMapper::DocumentNotValid)
This way I test for a working validation.
I believe I have some setting that is causing this behaviour. I also
tested it out in Rails console where it works as expected:
port = Portfolio.find_by_name(''test'')
port.name = ''new_name''
port.save
=> false
port.update_attributes(:name => ''new_name'')
=> false
Any ideas?
regards
On Oct 5, 3:15?pm, David Chelimsky <dchelim... at gmail.com>
wrote:> On Sep 3, 2011, at 4:17 PM, Chris Habgood wrote:
>
>
> > I have a basic user class and doing rspec validations. ?When I do a
factory create to produce validations it blows up before I can get to the second
line to check for errors. ?Ideas how to get this to perform like AR Validations?
>
> > MongoMapper::DocumentNotValid:
> > ? ? ? ?Validation failed: Password can''t be blank, Email
can''t be blank, Password digest can''t be blank
>
> > class User
> > ? include MongoMapper::Document
> > ? include ActiveModel::SecurePassword
>
> > ? attr_accessible :email, :password
>
> > ? key :password_digest, String
> > ? key :password, String, :required => true
> > ? key :email, String, :required => true
>
> > ? has_secure_password
> > end
>
> > it "should not authenticate with incorrect password" do
> > ? ? ? user = Factory(:user, :email=> '''',
:password => '''').should have(2).errors
>
> Try Factory.build instead of Factory (which is an alias for
Factory.create):
>
> ? user = Factory.build(:user, :email => '''', :password
=> '''')
> ? user.should_not be_valid # this triggers the validation
> ? user.should have(1).error_on(:email)
> ? user.should have(1).error_on(: password)
>
> HTH,
> David
>
> > ? ? ? #user.should have(2).errors #_on(:name)
> > ? end
>
> _______________________________________________
> rspec-users mailing list
> rspec-us... at
rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users