ruby - RSpec 2 speccing a static ActiveRecord method -


i've got pretty basic static method on activerecord model:

#./app/models/comic.rb class comic < activerecord::base   class << self     def furthest       comic.maximum(:comic_id) || 0     end   end end 

when executing comic.furthest in rails console returns 0 expect. problem trying spec behavior both presence , absence of records:

#./spec/app/models/comic_spec.rb require 'spec_helper'  describe comic   describe "#furthest"     subject { comic.furthest }      context "when there no rows in database"       { should == 0 }     end      context "when there rows in database"       before         factory.create(:comic, :comic_id => 100)         factory.create(:comic, :comic_id => 99)       end        { should == 100 }     end   end end 

all of appears basic , straightforward, specs failing message:

1) comic#furthest when there no rows in database   failure/error: { should == 0 }    expected: 0         got: nil (using ==)  # ./spec/models/comic_spec.rb:8:in `block (4 levels) in <top (required)>' 

even if change furthest simply:

def furthest   0 end 

i still nil (using ==).

the second spec, it { should == 100 } passes original comic.maximum(:comic_id) || 0 definition, if factory.create invocations required #furthest not return nil.

what doing wrong?

i confident problem me using p180 release of ruby 1.9.2 custom patches improve require performance. after upgrading p290 problem gone.


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -