I''m using
restful-authentication from
http://github.com/technoweenie/restful-authentication/tree/master
RSPEC 1.1.4 from http://github.com/dchelimsky/rspec-rails/wikis/home
(downloaded this week)
The spec for loging in work
I even have it working checking for authentication on the teachers
controller.
What I want to do is find students that belong to a teacher
So if I''m the teacher and I log in I want to see only my students.
----------------------------------------------
Models
class Students < ActiveRecord::Base
belongs_to :teacher
end
class Teacher < ActiveRecord::Base
has_many :students
end
----------------------------------------------
controller
class TeachersController < ApplicationController
# GET /teachers
# GET /teachers.xml
def index
@teachers = current_user.projects
respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @teachers }
end
end
end
----------------------------------------------
controler_spec
require File.expand_path(File.dirname(__FILE__) +
''/../spec_helper'')
describe StudentsController do
describe "handling GET /students" do
before(:each) do
@student = mock_model(Student)
student.stub!(:find).and_return([@student])
@User = user_login # logs user in
end
def do_get
controller.logged_in?().should == true
get :index
end
it "should be successful" do
do_get
response.should be_success
end
it "should render index template" do
do_get
response.should render_template(''index'')
end
it "should find all students" do
Student.should_receive(:find).with(:all).and_return([@student])
do_get
end
it "should assign the found projects for the view" do
do_get
assigns[:student].should == [@student]
end
end
end
----------------------------------------------
errors I get
Spec::Mocks::MockExpectationError in ''StudentsController handling GET /
students should assign the found students for the
view''
Mock ''Person_1155'' received unexpected message :students with
(no
args)
C:/InstantRails-2.0-win/rails_apps/ztemp/app/controllers/
students_controller.rb:5:in `index''
./spec/controllers/students_controller_spec.rb:14:in `do_get''
./spec/controllers/students_controller_spec.rb:35:
NoMethodError in ''StudentsController handling GET /students should
find all students''
undefined method `authenticate_with_http_basic'' for
#<Spec::Rails::Example::ControllerExampleGroup::Subclass_1::Subclass
_1:0x43914b8>
C:/InstantRails-2.0-win/rails_apps/ztemp/lib/authenticated_system.rb:
111:in `login_from_basic_auth''
C:/InstantRails-2.0-win/rails_apps/ztemp/lib/authenticated_system.rb:
12:in `current_person''
./spec/controllers/students_controller_spec.rb:29:
Spec::Mocks::MockExpectationError in ''StudentsController handling GET /
students should render index template''
Mock ''Person_1159'' received unexpected message :students with
(no
args)
C:/InstantRails-2.0-win/rails_apps/ztemp/app/controllers/
students_controller.rb:5:in `index''
./spec/controllers/students_controller_spec.rb:14:in `do_get''
./spec/controllers/students_controller_spec.rb:23:
Spec::Mocks::MockExpectationError in ''StudentsController handling GET /
students should be successful''
Mock ''Person_1161'' received unexpected message :students with
(no
args)
C:/InstantRails-2.0-win/rails_apps/ztemp/app/controllers/
students_controller.rb:5:in `index''
./spec/controllers/students_controller_spec.rb:14:in `do_get''
./spec/controllers/students_controller_spec.rb:18:
----------------------------------------------
I think this is what is giving me grief
Student.should_receive(:find).with(:all).and_return([@student])
but I don''t know how to get it to work
Any help will be appreciated
John I
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---