The quesion is not about the dificulty level, I knew that. I asked about the way to test the above sope method. So when calling it in the console, of course I'm getting an array, here is:
ruby-1.9.3-p0 :001 > operations = Account.operations_by_client
Account Load (26.8ms) SELECT clients.firstname, clients.lastname, sum(operations.total) as total FROM "accounts" INNER JOIN "clients" ON "clients"."id" = "accounts"."client_id" INNER JOIN "operations" ON "operations"."account_id" = "accounts"."id" GROUP BY
clients.id, clients.firstname, clients.lastname ORDER BY clients.lastname
=> [#<Account >, #<Account >, #<Account >, #<Account >, #<Account >, #<Account >, #<Account >, #<Account >, #<Account >, #<Account >, #<Account >, #<Account >, #<Account >, #<Account >, #<Account >, #<Account >, #<Account >, #<Account >, #<Account >, #<Account >, #<Account >, #<Account >, #<Account >, #<Account >, #<Account >, #<Account >, #<Account >, #<Account >, #<Account >, #<Account >, #<Account >, #<Account >, #<Account >, #<Account >, #<Account >]
ruby-1.9.3-p0 :002 >
As you see, it is not a 'normal' array which we usually could test like that:
describe 'GET #index' do
it "displays an array of all the operations by client" do
account = create(:operation) #will NOT work because the scope method result is not an array of Account objects
get :index
assigns(:operations).should == [account]
end
it "renders the :index view" do
get :index
response.should render_template :index
end
end
end
Regards