Skip to content

Commit

Permalink
Merge branch 'api'
Browse files Browse the repository at this point in the history
  • Loading branch information
dzaporozhets committed Sep 20, 2012
2 parents a605943 + d12579a commit 49fe8fe
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 10 deletions.
12 changes: 12 additions & 0 deletions app/views/help/api.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
%a{href: "#snippets"} Snippets
%li
%a{href: "#users"} Users
%li
%a{href: "#session"} Session
%li
%a{href: "#issues"} Issues
%li
Expand Down Expand Up @@ -58,6 +60,16 @@

%br

.file_holder#session
.file_title
%i.icon-file
Session
.file_content.wiki
= preserve do
= markdown File.read(Rails.root.join("doc", "api", "session.md"))

%br

.file_holder#issues
.file_title
%i.icon-file
Expand Down
8 changes: 3 additions & 5 deletions lib/api/entities.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ class UserBasic < Grape::Entity
expose :id, :email, :name, :blocked, :created_at
end

class UserLogin < Grape::Entity
expose :id, :email, :name, :private_token, :blocked, :created_at
class UserLogin < UserBasic
expose :private_token
end

class Hook < Grape::Entity
Expand Down Expand Up @@ -56,9 +56,7 @@ class Issue < Grape::Entity
end

class Key < Grape::Entity
expose :id,
:title,
:key
expose :id, :title, :key
end
end
end
5 changes: 2 additions & 3 deletions lib/api/session.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,13 @@ class Session < Grape::API
post "/session" do
resource = User.find_for_database_authentication(email: params[:email])

return forbidden! unless resource
return unauthorized! unless resource

if resource.valid_password?(params[:password])
present resource, with: Entities::UserLogin
else
forbidden!
unauthorized!
end
end
end
end

4 changes: 2 additions & 2 deletions spec/requests/api/session_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
context "when invalid password" do
it "should return authentication error" do
post api("/session"), email: user.email, password: '123'
response.status.should == 403
response.status.should == 401

json_response['email'].should be_nil
json_response['private_token'].should be_nil
Expand All @@ -29,7 +29,7 @@
context "when empty password" do
it "should return authentication error" do
post api("/session"), email: user.email
response.status.should == 403
response.status.should == 401

json_response['email'].should be_nil
json_response['private_token'].should be_nil
Expand Down

0 comments on commit 49fe8fe

Please sign in to comment.