mysql - in Rails, database call works in development but stalls in test -


i running test controller method shown below:

it "should assigns instance var @items including item"   @item = factorygirl.create(:item)   :index   response.should include(@item) end 

the controller method is:

def index   @item = item.select_items end  

where select_items scope method in items model:

scope :select_items, where(items.arel_table[:select_field].not_eq(nil)) 

in development, works fine. in test however,

  • a 500 error when test controller method in console
  • no error when test model method in console
  • a permanent hang when run spec

in test.log, hang happens @ last line of following:

connecting database specified database.yml   admin load (0.5ms)  select `admins`.* `admins`     (0.6ms)  release savepoint active_record_1    (0.2ms)  savepoint active_record_1   sql (1.1ms)  insert `items` (`various fields')    (0.1ms)  release savepoint active_record_1 processing admin::itemscontroller#index html   admin load (0.4ms)  select `admins`.* `admins` `admins`.`id` = 1 limit 1   rendered admin/items/index.haml within layouts/tabs (0.2ms) completed 200 ok in 15ms (views: 3.9ms | activerecord: 0.4ms)   item load (1.2ms)  select `items`.* `items` (`item`.`select_field` not null) limit 25 offset 0 

if run test in rspec, spec stops @ point. why?

your test should this:

it "should assigns instance var @items including item"   @item = factorygirl.create(:item)   :index   assigns(:item).should include(@item) end 

your controller assigned instance variable, , how access them. response holds lot of information never need @ in test. exception if returning things json or xml, in case you'd @ response.body.

in addition, considering controller instance variable grabbing possible multiple items, should name variable @items, pluralized. furthermore, never capitalize instance variables, should @items. , lastly nitpicky things, in test, don't need make @item instance variable exists single it.


Comments

Popular posts from this blog

curl - PHP fsockopen help required -

HTTP/1.0 407 Proxy Authentication Required PHP -

c# - Resource not found error -