Rails: default controller spec fails -



Rails: default controller spec fails -

i'm new rails , i'm trying specs pass. however, 1 of default specs fails next error:

failures: 1) ratingscontroller index assigns ratings @ratings failure/error: expect(assigns(:ratings)).to eq([rating]) expected: [#<rating id: 1, rottentomatoes_id: 1, rater_id: 1, rating: 10, created_at: "2014-06-17 22:58:53", updated_at: "2014-06-17 22:58:53">] got: nil (compared using ==) # ./spec/controllers/ratings_controller_spec.rb:34:in `block (3 levels) in <top (required)>' finished in 1 min 34.34 seconds (files took 4.55 seconds load) 61 examples, 1 failure failed examples: rspec ./spec/controllers/ratings_controller_spec.rb:30 # ratingscontroller index assigns ratings @ratings

here's spec (it's default controller spec generated bundle exec rails generate scaffold ...):

rspec.describe ratingscontroller, :type => :controller include_context 'shared context' describe "get index" "assigns ratings @ratings" rating = rating.create! valid_attributes :index, {}, valid_session expect(assigns(:ratings)).to eq([rating]) end end end

the shared_context:

rspec.shared_context 'shared context' include devise::testhelpers include warden::test::helpers warden.test_mode! let(:user1) { user.find_by(id: 1) || factorygirl.create(:user1) } let(:user2) { user.find_by(id: 2) || factorygirl.create(:user2) } let(:user3) { user.find_by(id: 3) || factorygirl.create(:user3) } let(:user4) { user.find_by(id: 4) || factorygirl.create(:user4) } let(:admin) { admin.find_by(id: 1) || factorygirl.create(:admin) } before @admin = admin.find_by(id: 1) || factorygirl.create(:admin) login_as(@admin, scope: :admin) end end

i should add together i'm using devise in conjunction controller:

class ratingscontroller < applicationcontroller before_action :set_rating, only: [:show, :edit, :update, :destroy] before_action :authenticate_admin! # /ratings # /ratings.json def index @ratings = rating.all end end

i figured things out using link: https://github.com/plataformatec/devise/wiki/how-to:-controllers-tests-with-rails-3-(and-rspec)

the document states rails 3, find works fine rails 4.

ruby-on-rails ruby-on-rails-4 devise

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -