Skip to content

Commit

Permalink
Merge branch 'master' into ozfortress
Browse files Browse the repository at this point in the history
  • Loading branch information
BenjaminSchaaf committed Aug 27, 2024
2 parents 8d3b560 + 7e11e1a commit 21ade8c
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 5 deletions.
3 changes: 3 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ group :test do
# Use rspec for tests
gem 'rspec-rails', '~> 6'

# Extra functionality for rspec-rails
gem 'rails-controller-testing'

# Parallelize tests
gem 'parallel_tests'

Expand Down
5 changes: 5 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,10 @@ GEM
activesupport (= 7.1.3.3)
bundler (>= 1.15.0)
railties (= 7.1.3.3)
rails-controller-testing (1.0.5)
actionpack (>= 5.0.1.rc1)
actionview (>= 5.0.1.rc1)
activesupport (>= 5.0.1.rc1)
rails-dom-testing (2.2.0)
activesupport (>= 5.0.0)
minitest
Expand Down Expand Up @@ -527,6 +531,7 @@ DEPENDENCIES
parallel_tests
pg (~> 1.0)
rails (~> 7.1.0)
rails-controller-testing
rails_best_practices
rake (~> 12.0)
redcarpet
Expand Down
6 changes: 1 addition & 5 deletions lib/auth/permissions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,7 @@ def instance_map
end

def get_actions_relation(action_model, subject)
if subject.is_a? ActiveRecord::Base
action_model.where(actor_name => @instances, action_model.subject => subject.id)
else
action_model.where(actor_name => @instances)
end
action_model.where(actor_name => @instances).for(subject)
end
end
end
50 changes: 50 additions & 0 deletions spec/controllers/forums/topics_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,56 @@
expect(response).to redirect_to(forums_path)
end
end

context 'hidden thread' do
let(:user2) { create(:user) }

let!(:hidden_thread) do
create(:forums_thread, topic: topic, title: 'Hidden Title', hidden: true, created_by: user2)
end
let!(:visible_thread) { create(:forums_thread, topic: topic, title: 'Visible Title') }

it 'is visible for managing user' do
user.grant(:manage, topic)
sign_in user

get :show, params: { id: topic.id }

expect(assigns(:threads)).to contain_exactly(hidden_thread, visible_thread)
end

it 'is visible for creating user' do
sign_in user2

get :show, params: { id: topic.id }

expect(assigns(:threads)).to contain_exactly(hidden_thread, visible_thread)
end

it 'is hidden for user with permissions to other topic' do
topic2 = create(:forums_topic)
user.grant(:manage, topic2)
sign_in user

get :show, params: { id: topic.id }

expect(assigns(:threads)).to eq([visible_thread])
end

it 'is hidden for other user' do
sign_in user

get :show, params: { id: topic.id }

expect(assigns(:threads)).to eq([visible_thread])
end

it 'is hidden for unauthenticated user' do
get :show, params: { id: topic.id }

expect(assigns(:threads)).to eq([visible_thread])
end
end
end

describe 'PATCH #toggle_subscription' do
Expand Down

0 comments on commit 21ade8c

Please sign in to comment.