everydayrails / rails-4-1-rspec-3-0

Code samples for Everyday Rails Testing with RSpec, Rails 4.1/RSpec 3.0 edition
272 stars 229 forks source link

Active Record Relation query returns Relation Object not an Array #54

Open rabinprithvi opened 9 years ago

rabinprithvi commented 9 years ago

Chapter 3 : Model specs - Testing class methods and scopes

File - spec/models/contact_spec.rb

Test case : Context - context "matching letters" do it "returns a sorted array of results that match" do expect(Contact.by_letter("J")).to eq [@johnson, @jones] end end

Contact.by_letter("J") returns Active record relation object and not an array. Hence we have to change Contact.by_letter("J") to Contact.by_letter("J") .pluck(:lastname) in the test case or change the model code.

ruralocity commented 9 years ago

I can't reproduce this. What version of Rails are you using?