Add API for App Index

- Add tests for unauthorised response for APIs which require authentication
This commit is contained in:
leenasn
2015-11-23 12:05:45 +05:30
parent b881726a25
commit 879a0f49e1
6 changed files with 59 additions and 26 deletions

View File

@@ -0,0 +1,26 @@
require 'rails_helper'
RSpec.describe AppsController, type: :controller do
context "With Authentication" do
let(:device){create(:device)}
before(:each) do
request.env['HTTP_AUTHORIZATION'] = ActionController::HttpAuthentication::Token.encode_credentials(device.access_token)
end
it "#index" do
expect(App).to receive(:all)
get :index, format: :json
expect(response).to have_http_status(:ok)
end
end
context "Without Authentication" do
it "#index" do
get :index, format: :json
expect(response).to have_http_status(:unauthorized)
end
end
end

View File

@@ -1,13 +1,14 @@
require 'rails_helper'
RSpec.describe HeartbeatsController, type: :controller do
let(:heartbeat) {FactoryGirl.create(:heartbeat)}
before(:each) do
request.env['HTTP_AUTHORIZATION'] = ActionController::HttpAuthentication::Token.encode_credentials(heartbeat.device.access_token)
end
describe "POST #create" do
context "POST #create" do
let(:heartbeat) {FactoryGirl.create(:heartbeat)}
before(:each) do
request.env['HTTP_AUTHORIZATION'] = ActionController::HttpAuthentication::Token.encode_credentials(heartbeat.device.access_token)
end
it "Respond with next heartbeat time" do
post :create, format: :json
expect(response).to have_http_status(:created)
@@ -15,5 +16,12 @@ RSpec.describe HeartbeatsController, type: :controller do
end
end
context "Require Authentication" do
it "#create" do
post :create, format: :json
expect(response).to have_http_status(:unauthorized)
end
end
end

View File

@@ -3,25 +3,22 @@ require 'rails_helper'
RSpec.describe InstallationsController, type: :controller do
let(:installation) {FactoryGirl.create(:installation)}
let(:device){installation.device}
before(:each)do
request.env['HTTP_AUTHORIZATION'] = ActionController::HttpAuthentication::Token.encode_credentials(device.access_token)
end
describe "POST #downloaded" do
it "upate installation with download status" do
post :downloaded, :id => installation.id , format: :json
expect(response).to have_http_status(:ok)
expect(Installation.last.downloaded?).to be true
context "With Authentication" do
before(:each)do
request.env['HTTP_AUTHORIZATION'] = ActionController::HttpAuthentication::Token.encode_credentials(device.access_token)
end
end
describe "POST #installed" do
it "update installation with installed status" do
it "POST #installed" do
post :installed, :id => installation.id , format: :json
expect(response).to have_http_status(:ok)
expect(Installation.last.installed?).to be true
end
end
context "Require Authentication" do
it "POST #installed" do
post :installed, :id => installation.id , format: :json
expect(response).to have_http_status(:unauthorized)
end
end
end