Commit 7b39aaf0 by John Doe

fixed bugs in data view handling

parent 4cff7d2e
...@@ -32,6 +32,7 @@ class DataViewsController < ApplicationController ...@@ -32,6 +32,7 @@ class DataViewsController < ApplicationController
@service = StubService.new @service = StubService.new
@data_view.destroy @data_view.destroy
@service.set_notice('removed data view') @service.set_notice('removed data view')
render 'helpers/empty_response', status: :ok
end end
private private
......
...@@ -79,4 +79,42 @@ RSpec.describe DataViewsController, type: :request do ...@@ -79,4 +79,42 @@ RSpec.describe DataViewsController, type: :request do
end end
end end
end end
describe 'DELETE destroy' do
before do
service = CreateDataView.new
service.run(
{name: 'created'}, viewed_streams.map{|x| x.id}, viewer)
@my_view = service.data_view
end
context 'with view owner' do
it 'removes the data view' do
@auth_headers = viewer.create_new_auth_token
delete "/data_views/#{@my_view.id}.json",
headers: @auth_headers
expect(response).to have_http_status(:ok)
expect(response).to have_notice_message
expect(DataView.exists?(@my_view.id)).to be false
# make sure the associated permissions are destroyed
expect(DataViewsNilm.count).to eq(0)
end
end
context 'with anybody else' do
it 'returns unauthorized' do
other_user = create(:user)
@auth_headers = other_user.create_new_auth_token
delete "/data_views/#{@my_view.id}.json",
headers: @auth_headers
expect(response).to have_http_status(:unauthorized)
expect(DataView.exists?(@my_view.id)).to be true
end
end
context 'without sign-in' do
it 'returns unauthorized' do
delete "/data_views/#{@my_view.id}.json"
expect(response).to have_http_status(:unauthorized)
expect(DataView.exists?(@my_view.id)).to be true
end
end
end
end end
...@@ -9,6 +9,6 @@ FactoryGirl.define do ...@@ -9,6 +9,6 @@ FactoryGirl.define do
end_time { start_time + Faker::Number.number(5) } end_time { start_time + Faker::Number.number(5) }
size_on_disk { Faker::Number.number(6) } size_on_disk { Faker::Number.number(6) }
hidden false hidden false
path { "/root/#{Faker::Lorem.unique.word}" } path { "/root/#{Faker::Lorem.word}/#{Faker::Number.unique.number(4)}" }
end end
end end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment