Skip to content

Commit

Permalink
Use positional arguments for user in viible methods
Browse files Browse the repository at this point in the history
  • Loading branch information
klaustopher committed May 23, 2024
1 parent 60b3ec6 commit d47fccb
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion app/controllers/projects/queries_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,6 @@ def render_result(service_call, success_i18n_key:, error_i18n_key:) # rubocop:di
end

def find_query
@query = Queries::Projects::ProjectQuery.visible(user: current_user).find(params[:id])
@query = Queries::Projects::ProjectQuery.visible(current_user).find(params[:id])
end
end
2 changes: 1 addition & 1 deletion app/models/queries/projects/factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ def find_static_query_and_set_attributes(id, params, user, duplicate:)
end

def find_persisted_query_and_set_attributes(id, params, user, duplicate:)
query = Queries::Projects::ProjectQuery.visible(user:).find_by(id:)
query = Queries::Projects::ProjectQuery.visible(user).find_by(id:)

return unless query

Expand Down
4 changes: 2 additions & 2 deletions app/models/queries/projects/project_query.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ class Queries::Projects::ProjectQuery < ApplicationRecord
scope :public_lists, -> { where(public: true) }
scope :private_lists, ->(user: User.current) { where(public: false, user:) }

scope :visible, ->(user: User.current) {
scope :visible, ->(user = User.current) {
public_lists.or(private_lists(user:))
}

def visible?(user: User.current)
def visible?(user = User.current)
public? || user == self.user
end

Expand Down
10 changes: 5 additions & 5 deletions spec/models/queries/projects/project_query_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -416,8 +416,8 @@
private_query = create(:project_query, public: false)
create(:project_query, public: false)

expect(described_class.visible(user: private_query.user)).to contain_exactly(public_query, public_query_other_user,
private_query)
expect(described_class.visible(private_query.user)).to contain_exactly(public_query, public_query_other_user,
private_query)
end
end
end
Expand All @@ -430,7 +430,7 @@
context "when the user is the owner" do
let(:owner) { user }

it { is_expected.to be_visible(user:) }
it { is_expected.to be_visible(user) }
end

context "when the user is not the owner" do
Expand All @@ -439,13 +439,13 @@
context "and the query is public" do
let(:public) { true }

it { is_expected.to be_visible(user:) }
it { is_expected.to be_visible(user) }
end

context "and the query is private" do
let(:public) { false }

it { is_expected.not_to be_visible(user:) }
it { is_expected.not_to be_visible(user) }
end
end
end
Expand Down

0 comments on commit d47fccb

Please sign in to comment.