Permalink
Browse files

Tests for edit/update of controller.

  • Loading branch information...
1 parent 149d756 commit 85d217902da014e23b2d5dc04c128520a426f808 @Loremaster committed May 6, 2012
Showing with 80 additions and 0 deletions.
  1. +80 −0 spec/controllers/timetables_controller_spec.rb
@@ -99,4 +99,84 @@
end
end
end
+
+ describe "GET 'edit'" do
+ describe "for non-signed users" do
+ it "should deny access" do
+ get :edit, :id => @timetable
+ response.should redirect_to( signin_path )
+ flash[:notice].should =~ /войдите в систему как завуч/i
+ end
+ end
+
+ describe "for signin-in admins" do
+ before(:each) do
+ test_sign_in( @adm )
+ end
+
+ it "should deny access" do
+ get :edit, :id => @timetable
+ response.should redirect_to( pages_wrong_page_path )
+ flash[:error].should =~ /вы не можете увидеть эту страницу/i
+ end
+ end
+
+ describe "for sign-in school-heads" do
+ before(:each) do
+ test_sign_in( @sh )
+ end
+
+ it "should allow to edit timetables" do
+ get :edit, :id => @timetable
+ response.should be_success
+ flash[:error].should be_nil
+ end
+ end
+ end
+
+ describe "PUT 'update" do
+ describe "for non-signed users" do
+ it "should deny access" do
+ put :update, :id => @timetable,
+ :timetable => @timetable.attributes.merge( :tt_room => "333" )
+ response.should redirect_to( signin_path )
+ flash[:notice].should =~ /войдите в систему как завуч/i
+ end
+ end
+
+ describe "for signed-in admins" do
+ before(:each) do
+ test_sign_in( @adm )
+ end
+
+ it "should deny access" do
+ put :update, :id => @timetable,
+ :timetable => @timetable.attributes.merge( :tt_room => "333" )
+ response.should redirect_to( pages_wrong_page_path )
+ flash[:error].should =~ /вы не можете увидеть эту страницу/i
+ end
+ end
+
+ describe "for signed-in school-heads" do
+ before(:each) do
+ test_sign_in( @sh )
+ end
+
+ it "should reject to update timetable with wrong params" do
+ text = " "
+ put :update, :id => @timetable,
+ :order => @timetable.attributes.merge(:tt_number_of_lesson => text )
+ @timetable.reload
+ @timetable.tt_number_of_lesson.should_not == text
+ end
+
+ it "should update timetable with correct params" do
+ text = "333"
+ put :update, :id => @timetable,
+ :timetable => @timetable.attributes.merge( :tt_room => text )
+ @timetable.reload
+ @timetable.tt_room.should == text
+ end
+ end
+ end
end

0 comments on commit 85d2179

Please sign in to comment.