From 7716462c8fec516a5fcf79f284fe467ae747cf98 Mon Sep 17 00:00:00 2001 From: Devin Howard Date: Mon, 14 Mar 2016 11:40:23 +0800 Subject: [PATCH 1/4] fix topics controller test --- spec/controllers/topics_controller_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/controllers/topics_controller_spec.rb b/spec/controllers/topics_controller_spec.rb index 2dd999a1..4cce6851 100644 --- a/spec/controllers/topics_controller_spec.rb +++ b/spec/controllers/topics_controller_spec.rb @@ -95,7 +95,7 @@ RSpec.describe TopicsController, type: :controller do end it 'return 204 NO CONTENT' do - delete :destroy, { id: topic.to_param, format: :json } + delete :destroy, { id: owned_topic.to_param, format: :json } expect(response.status).to eq 204 end end From 32326ff4afc178e1a71ebf75f3757989cb977fb8 Mon Sep 17 00:00:00 2001 From: Devin Howard Date: Mon, 14 Mar 2016 11:46:45 +0800 Subject: [PATCH 2/4] update map/topic delete action test --- spec/controllers/maps_controller_spec.rb | 6 ++++-- spec/controllers/topics_controller_spec.rb | 5 +---- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/spec/controllers/maps_controller_spec.rb b/spec/controllers/maps_controller_spec.rb index 67950d75..35c3ddcc 100644 --- a/spec/controllers/maps_controller_spec.rb +++ b/spec/controllers/maps_controller_spec.rb @@ -89,7 +89,8 @@ RSpec.describe MapsController, type: :controller do expect do delete :destroy, { id: unowned_map.to_param, format: :json } end.to change(Map, :count).by(0) - expect(response.body).to eq("unauthorized") + expect(response.body).to eq '' + expect(response.status).to eq 403 end it 'deletes owned map' do @@ -97,7 +98,8 @@ RSpec.describe MapsController, type: :controller do expect do delete :destroy, { id: owned_map.to_param, format: :json } end.to change(Map, :count).by(-1) - expect(response.body).to eq("success") + expect(response.body).to eq '' + expect(response.status).to eq 204 end end end diff --git a/spec/controllers/topics_controller_spec.rb b/spec/controllers/topics_controller_spec.rb index 4cce6851..2fc99b22 100644 --- a/spec/controllers/topics_controller_spec.rb +++ b/spec/controllers/topics_controller_spec.rb @@ -92,10 +92,7 @@ RSpec.describe TopicsController, type: :controller do expect do delete :destroy, { id: owned_topic.to_param, format: :json } end.to change(Topic, :count).by(-1) - end - - it 'return 204 NO CONTENT' do - delete :destroy, { id: owned_topic.to_param, format: :json } + expect(response.body).to eq '' expect(response.status).to eq 204 end end From d11f3923dd3d047a67b0e2a15e29540b707add30 Mon Sep 17 00:00:00 2001 From: Devin Howard Date: Mon, 14 Mar 2016 14:34:36 +0800 Subject: [PATCH 3/4] remove unused has_viewable_synapses function --- app/models/topic.rb | 11 ---------- spec/models/topic_spec.rb | 42 --------------------------------------- 2 files changed, 53 deletions(-) diff --git a/app/models/topic.rb b/app/models/topic.rb index 0f312823..aef72b74 100644 --- a/app/models/topic.rb +++ b/app/models/topic.rb @@ -83,15 +83,4 @@ class Topic < ActiveRecord::Base def mk_permission Perm.short(permission) end - - # has no viewable synapses helper function - def has_viewable_synapses(current) - result = false - synapses.each do |synapse| - if synapse.authorize_to_show(current) - result = true - end - end - result - end end diff --git a/spec/models/topic_spec.rb b/spec/models/topic_spec.rb index ef8f0b7a..dbaac86d 100644 --- a/spec/models/topic_spec.rb +++ b/spec/models/topic_spec.rb @@ -7,46 +7,4 @@ RSpec.describe Topic, type: :model do it { is_expected.to have_many :mappings } it { is_expected.to validate_presence_of :permission } it { is_expected.to validate_inclusion_of(:permission).in_array Perm::ISSIONS.map(&:to_s) } - - context 'has_viewable_synapses function' do - let (:user) { create(:user) } - let (:other_user) { create(:user) } - - context 'topic with no synapses' do - let (:topic) { create(:topic) } - - it 'returns false' do - expect(topic.has_viewable_synapses(user)).to eq false - end - end - - context 'topic with one unpermitted synapse' do - let (:synapse) { create(:synapse, permission: :private, user: other_user) } - let (:topic) { create(:topic, synapses1: [synapse]) } - - it 'returns false' do - expect(topic.has_viewable_synapses(user)).to eq false - end - end - - context 'topic with one permitted synapse' do - let (:synapse) { create(:synapse, permission: :private, user: user) } - let(:topic) { create(:topic, synapses1: [synapse]) } - - it 'returns true' do - expect(topic.has_viewable_synapses(user)).to eq true - end - end - - context 'topic with one unpermitted, one permitted synapse' do - let (:synapse1) { create(:synapse, permission: :private, user: other_user) } - let (:synapse2) { create(:synapse, permission: :private, user: user) } - let (:topic) { create(:topic, synapses1: [synapse1, synapse2]) } - - it 'returns true' do - expect(topic.synapses.count).to eq 2 - expect(topic.has_viewable_synapses(user)).to eq true - end - end - end end From a05c7dc5fe497ae1f5df2ed860bfdb3ad686b6ea Mon Sep 17 00:00:00 2001 From: Devin Howard Date: Mon, 14 Mar 2016 14:37:01 +0800 Subject: [PATCH 4/4] avoid pundit error if no map specified with a mapping --- app/policies/mapping_policy.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/policies/mapping_policy.rb b/app/policies/mapping_policy.rb index 40b71f61..5826ccd4 100644 --- a/app/policies/mapping_policy.rb +++ b/app/policies/mapping_policy.rb @@ -20,7 +20,7 @@ class MappingPolicy < ApplicationPolicy end def create? - map_policy.update? + record.map.present? && map_policy.update? end def update?