Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does "assigns" do in Ruby on Rails?

I am currently attempt to learn Ruby on Rails, and the testing framework RSpec. What does assigns do in this RSpec test?

 describe "GET index" do
    it "assigns all mymodel as @mymodel" do
      mymodel = Factory(:mymodel)
      get :index
      assigns(:mymodels).should eq([mymodel])
    end
  end
like image 537
bulleric Avatar asked Dec 23 '11 13:12

bulleric


1 Answers

assigns simply checks the value of the instance variables you set in your controller.

Here it checks @mymodels.

like image 87
apneadiving Avatar answered Nov 14 '22 23:11

apneadiving