test/functional/users_controller_test.rb in zena-0.15.2 vs test/functional/users_controller_test.rb in zena-0.16.0

- old
+ new

@@ -1,28 +1,90 @@ require 'test_helper' class UsersControllerTest < Zena::Controller::TestCase - def test_update_preferences - login(:lion) - put 'update', 'id' => users_id(:lion), 'user'=>{'name'=>'Leo Verneyi', 'lang'=>'en', 'time_zone'=>'Africa/Algiers', 'first_name'=>'Panthera', 'login'=>'lion', 'email'=>'lion@zenadmin.info'} - assert_response :success - user = assigns['user'] - assert_equal 'Africa/Algiers', user[:time_zone] + context "on GET index" do + context " if visitor is admin" do + setup do + login(:su) + get :index + end + + should_assign_to :users + should_render_with_layout :_main + should_respond_with :success + end + + context " if visitor is not admin" do + setup do + login(:ant) + get :index + end + + should_not_assign_to :users + should_render_without_layout + should_respond_with 404 + end + + context " if layout is invalid" do + setup do + login(:lion) + Version.connection.execute "UPDATE #{Version.table_name} SET text = 'empty' WHERE id = #{versions_id(:Node_admin_layout_zafu_en)}" + without_files('test.host/zafu') do + get 'index' + end + end + + should_respond_with :success + should_render_with_layout :_main + end + end - def test_render_invalid_adminLayout - login(:lion) - Version.connection.execute "UPDATE #{Version.table_name} SET text = 'empty' WHERE id = #{versions_id(:Node_admin_layout_zafu_en)}" - without_files('test.host/zafu') do - get 'index' - assert_response :success - assert_no_match %r{empty}, @response.body - # The assertion below passes alone but fails when we pass all tests. - # Tracked the problem all the way to default rendering and all seems ok: - # Maybe the problem is related to ruby not evaluating the erb. No idea. - # We'll make it a pending for the safety of our minds. - # assert_match %r{Using default '\+adminLayout' template}, @response.body - print 'P' + context "on GET show" do + setup do + login(:su) + get(:show, {'id'=>visitor.id}) end + + should_respond_with :success + should_render_without_layout end + + context 'on GET preferences' do + setup do + login(:su) + get(:preferences, {'id'=>visitor.id}) + end + + should_respond_with :success + should_render_with_layout :_main + end + + context 'on GET swap_dev' do + setup do + login(:su) + get(:swap_dev, {'id'=> visitor.id}) + end + + should_set_session(:dev) {true} + should_redirect_to("the user profile") { user_url(visitor.id) } + end + + + + context "on PUT" do + context "in order to update parameters" do + setup do + login(:lion) + put 'update', 'id' => users_id(:lion), 'user'=>{'name'=>'Leo Verneyi', 'lang'=>'en', 'time_zone'=>'Africa/Algiers', 'first_name'=>'Panthera', 'login'=>'lion', 'email'=>'lion@zenadmin.info'} + end + should_assign_to :user + should_respond_with :success + should "be able to set timezone" do + assert_equal 'Africa/Algiers', assigns(:user)[:time_zone] + end + end + end + + end \ No newline at end of file