> describe VideosController, " requesting /videos/1 using GET" do
> include UserSpecHelpers
>
> before(:each) do
> login_as mock_user
> mock_user.stub!(:access_video?).and_return true
> @mock_video = mock_model(Video)
> Video.stub!(:find).and_return @mock_video
> end
>
> def do_get
> get :show, :id => "1"
> end
>
> it "should find the video" do
> Video.should_receive(:find).with("1").and_return @mock_video
> do_get
> end
>
> it "should check to see if user is authorized" do
> mock_user.should_receive(:access_video?).with(@mock_video).and_return true
> do_get
> end
>
> it "should render show.rhtml" do
> do_get
> response.should render_template("show")
> end
> end
>
> describe VideosController, " requesting /videos/1 using GET, not logged in" do
> it "should redirect to the login page" do
> get :show, :id => "1"
> response.should redirect_to(login_url)
> end
> end
>
> describe VideosController, " requesting /videos/1 using GET, not authorized"
> do
> include UserSpecHelpers
>
> before(:each) do
> login_as mock_user
> mock_user.stub!(:access_video?).and_return false
> @mock_video = mock_model(Video)
> Video.stub!(:find).and_return @mock_video
> end
>
> it "should redirect to the login page" do
> get :show, :id => "1"
> response.should redirect_to(login_url)
> end
> end
>
>
>
> Pat
> _______________________________________________
> rspec-users mailing list
> [email protected]
> http://rubyforge.org/mailman/listinfo/rspec-users
>
Hi Pat and Mike,
I have login with role base authority and somehow didn't want to make
new describe blocks for every role.
My current practice is using 'with role' like this:
describe PostsController, '/posts POST' do
it 'should redirect to login path'
it 'with user should redirect to posts path'
it 'with admin should redirect to admin favorite place etc'
end
I don't like 'when role is etc' style at the end of spec because it
makes specs very blurry to overview. My project has still a few
behaviors still, perhaps later separation is a better way to go for
handle role stuff cleanly.
Priit
_______________________________________________
rspec-users mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/rspec-users