From 479631aafc525efef151309ac257e60c73230ac0 Mon Sep 17 00:00:00 2001 From: Boyan Tabakov Date: Wed, 31 Jul 2013 13:52:23 +0300 Subject: Extended User API to expose admin and can_create_group for user creation/updating. Also, is_admin and can_create_group are exposed in the user information. Fixed attributes_for_keys to process properly keys with boolean values (since false.present? is false). --- spec/requests/api/users_spec.rb | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) (limited to 'spec/requests') diff --git a/spec/requests/api/users_spec.rb b/spec/requests/api/users_spec.rb index 2fced3ec945..4a299d3d958 100644 --- a/spec/requests/api/users_spec.rb +++ b/spec/requests/api/users_spec.rb @@ -52,6 +52,16 @@ describe API::API do }.to change { User.count }.by(1) end + it "should create user with correct attributes" do + post api('/users', admin), attributes_for(:user, admin: true, can_create_group: true) + response.status.should == 201 + user_id = json_response['id'] + new_user = User.find(user_id) + new_user.should_not == nil + new_user.admin.should == true + new_user.can_create_group.should == true + end + it "should return 201 Created on success" do post api("/users", admin), attributes_for(:user, projects_limit: 3) response.status.should == 201 @@ -135,6 +145,8 @@ describe API::API do end describe "PUT /users/:id" do + let!(:admin_user) { create(:admin) } + before { admin } it "should update user with new bio" do @@ -144,6 +156,21 @@ describe API::API do user.reload.bio.should == 'new test bio' end + it "should update admin status" do + put api("/users/#{user.id}", admin), {admin: true} + response.status.should == 200 + json_response['is_admin'].should == true + user.reload.admin.should == true + end + + it "should not update admin status" do + put api("/users/#{admin_user.id}", admin), {can_create_group: false} + response.status.should == 200 + json_response['is_admin'].should == true + admin_user.reload.admin.should == true + admin_user.can_create_group.should == false + end + it "should not allow invalid update" do put api("/users/#{user.id}", admin), {email: 'invalid email'} response.status.should == 404 @@ -228,7 +255,6 @@ describe API::API do response.status.should == 200 json_response['email'].should == user.email json_response['is_admin'].should == user.is_admin? - json_response['can_create_team'].should == user.can_create_team? json_response['can_create_project'].should == user.can_create_project? json_response['can_create_group'].should == user.can_create_group? end -- cgit v1.2.3