-
Notifications
You must be signed in to change notification settings - Fork 5.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
API fixes #1735
API fixes #1735
Changes from all commits
770ec33
c610206
2dc0f09
0369c74
00325a7
cf70439
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,24 +23,23 @@ class Users < Grape::API | |
@user = User.find(params[:id]) | ||
present @user, with: Entities::User | ||
end | ||
|
||
# Create user. Available only for admin | ||
# | ||
# Parameters: | ||
# email (required) - Email | ||
# name (required) - Name | ||
# password (required) - Password | ||
# password_confirmation (required) - Password confirmation | ||
# name - Name | ||
# skype - Skype ID | ||
# linkedin - Linkedin | ||
# twitter - Twitter account | ||
# projects_limit - Limit projects wich user can create | ||
# projects_limit - Number of projects user can create | ||
# Example Request: | ||
# POST /users | ||
post do | ||
authenticated_as_admin! | ||
attrs = attributes_for_keys [:email, :name, :password, :password_confirmation, :skype, :linkedin, :twitter, :projects_limit] | ||
user = User.new attrs | ||
attrs = attributes_for_keys [:email, :name, :password, :skype, :linkedin, :twitter, :projects_limit] | ||
user = User.new attrs, as: :admin | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why as :admin ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
if user.save | ||
present user, with: Entities::User | ||
else | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,7 +46,7 @@ | |
response.status.should == 201 | ||
end | ||
|
||
it "should repsond with 404 on failure" do | ||
it "should respond with 404 on failure" do | ||
post api("/projects", user) | ||
response.status.should == 404 | ||
end | ||
|
@@ -188,16 +188,16 @@ | |
}.to change {project.hooks.count}.by(1) | ||
end | ||
end | ||
|
||
describe "PUT /projects/:id/hooks/:hook_id" do | ||
it "should update an existing project hook" do | ||
put api("/projects/#{project.code}/hooks/#{hook.id}", user), | ||
url: 'http://example.com' | ||
url: 'http://example.org' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what's the point? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. to test the changes. |
||
response.status.should == 200 | ||
json_response['url'].should == 'http://example.com' | ||
json_response['url'].should == 'http://example.org' | ||
end | ||
end | ||
|
||
|
||
describe "DELETE /projects/:id/hooks" do | ||
it "should delete hook from project" do | ||
|
@@ -239,7 +239,7 @@ | |
end | ||
|
||
describe "GET /projects/:id/snippets" do | ||
it "should return a project snippet" do | ||
it "should return an array of project snippets" do | ||
get api("/projects/#{project.code}/snippets", user) | ||
response.status.should == 200 | ||
json_response.should be_an Array | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ | |
include ApiHelpers | ||
|
||
let(:user) { Factory :user } | ||
let(:admin) {Factory :admin} | ||
let(:admin) { Factory :admin } | ||
let(:key) { Factory :key, user: user } | ||
|
||
describe "GET /users" do | ||
|
@@ -42,9 +42,9 @@ | |
end | ||
|
||
it "should create user" do | ||
expect{ | ||
post api("/users", admin), Factory.attributes(:user) | ||
}.to change{User.count}.by(1) | ||
expect { | ||
post api("/users", admin), Factory.attributes(:user, projects_limit: 3) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why projects_limit: 3 ?? |
||
}.to change { User.count }.by(1) | ||
end | ||
|
||
it "shouldn't available for non admin users" do | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea :)