Change the app_usages API to accept array of data

- Add foreignkey to device for AppUsage
- Rename the route to app_usage from app_usage/create
This commit is contained in:
Leena
2016-02-05 08:24:39 +05:30
parent 45bcc78962
commit abe0b6c083
8 changed files with 22 additions and 15 deletions

View File

@@ -9,12 +9,12 @@ RSpec.describe AppUsagesController, type: :controller do
request.env['HTTP_AUTHORIZATION'] = ActionController::HttpAuthentication::Token.encode_credentials(device.access_token)
end
it "Valid params" do
post :create, app_usage: attributes_for(:app_usage), format: :json
post :create, app_usage: [attributes_for(:app_usage)], format: :json
expect(response).to have_http_status(:success)
end
it "InValid Params" do
post :create, app_usage: attributes_for(:invalid_app_usage), format: :json
post :create, app_usage: [attributes_for(:invalid_app_usage)], format: :json
expect(response).to have_http_status(:unprocessable_entity)
end
end

View File

@@ -6,4 +6,5 @@ RSpec.describe AppUsage, type: :model do
it { should validate_presence_of :package_name }
it { should validate_presence_of :usage_duration_in_seconds }
it { should validate_presence_of :used_on }
it { should belong_to :device }
end