Skip to content

Commit

Permalink
rename method to match others that have similar pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
epugh committed Dec 12, 2023
1 parent a38b731 commit ccfb038
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 29 deletions.
4 changes: 2 additions & 2 deletions app/controllers/api/v1/scorers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class ScorersController < Api::ApiController

def index
unless Rails.application.config.communal_scorers_only
@user_scorers = current_user.scorers.all.reject(&:communal?)
@user_scorers = current_user.scorers_involved_with.all.reject(&:communal?)
end
@communal_scorers = Scorer.communal

Expand Down Expand Up @@ -189,7 +189,7 @@ def scorer_params

def set_scorer
# This block of logic should all be in user_scorer_finder.rb
@scorer = current_user.scorers.where(id: params[:id]).first
@scorer = current_user.scorers_involved_with.where(id: params[:id]).first

if @scorer.nil? # Check if communal scorers has the scorer. This logic should be in the .scorers. method!
@scorer = Scorer.communal.where(id: params[:id]).first
Expand Down
6 changes: 3 additions & 3 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,8 @@ def num_queries
queries.count
end

# All the scorers that you have access to, either as communal or as owner or team.
def scorers
# All the scorers that you have access to, either as communal or as owner or via a team.
def scorers_involved_with
Scorer.for_user(self)
end

Expand All @@ -206,7 +206,7 @@ def books_involved_with
Book.for_user(self)
end

# This method rpeturns all the search_endpoints that the user has access to via it's teams.
# This method rpeturns all the search_endpoints that the user has access as owner or via a team.
def search_endpoints_involved_with
SearchEndpoint.for_user(self)
end
Expand Down
2 changes: 1 addition & 1 deletion app/views/books/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

<div class="mb-3">
<%= form.label :scorer_id, class: 'form-label' %>
<%= form.collection_select(:scorer_id, current_user.scorers, :id, :name, { prompt: true }, required: true, class: 'form-control') %>
<%= form.collection_select(:scorer_id, current_user.scorers_involved_with, :id, :name, { prompt: true }, required: true, class: 'form-control') %>
<div class="form-text">The scorer you pick drives the options for rating. So AP@10 would give you relevant and irrelevant, whereas NDCG would give your a four point scale.</div>
</div>

Expand Down
2 changes: 1 addition & 1 deletion test/controllers/api/v1/scorers_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ class ScorersControllerTest < ActionController::TestCase

user.reload

assert_not_includes user.scorers, shared_scorer
assert_not_includes user.scorers_involved_with, shared_scorer
end

test 'removes scorer successfully and disassociates it from owner' do
Expand Down
44 changes: 22 additions & 22 deletions test/services/user_scorer_finder_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,19 @@ class UserScorerFinderTest < ActiveSupport::TestCase

describe 'Find all scorers' do
test 'returns an array of scorers' do
result = user.scorers.all
result = user.scorers_involved_with.all

assert_equal 'Scorer::ActiveRecord_Relation', result.class.to_s
end

test 'includes scorers owned by user' do
result = user.scorers.all
result = user.scorers_involved_with.all

assert_includes result, owned_scorer
end

test 'includes scorers shared with user' do
result = user.scorers.all
result = user.scorers_involved_with.all

assert_includes result, shared_scorer
end
Expand All @@ -49,30 +49,30 @@ class UserScorerFinderTest < ActiveSupport::TestCase

describe 'Find all scorers that match params' do
test 'returns an empty array if no results match' do
result = user.scorers.where(id: 123).all
result = user.scorers_involved_with.where(id: 123).all

assert_equal 'Scorer::ActiveRecord_Relation', result.class.to_s
assert_equal 0, result.length
end

test 'works when filtering by id' do
result = user.scorers.where(id: owned_scorer.id).all
result = user.scorers_involved_with.where(id: owned_scorer.id).all

assert_equal 'Scorer::ActiveRecord_Relation', result.class.to_s
assert_equal 1, result.length
assert_includes result, owned_scorer
end

test 'works with complex where clause for owned scorers' do
result = user.scorers.where('`scorers`.`name` LIKE ?', '%Owned%').all
result = user.scorers_involved_with.where('`scorers`.`name` LIKE ?', '%Owned%').all

assert_equal 'Scorer::ActiveRecord_Relation', result.class.to_s
assert_equal 3, result.length
assert_includes result, owned_scorer
end

test 'works with complex where clause for shared scorers' do
result = user.scorers.where('`scorers`.`name` LIKE ?', '%Shared%').all
result = user.scorers_involved_with.where('`scorers`.`name` LIKE ?', '%Shared%').all

assert_equal 'Scorer::ActiveRecord_Relation', result.class.to_s
assert_equal 3, result.length
Expand All @@ -81,15 +81,15 @@ class UserScorerFinderTest < ActiveSupport::TestCase
end

test 'works when querying on the name for owned scorers' do
result = user.scorers.where(name: 'Owned Scorer').all
result = user.scorers_involved_with.where(name: 'Owned Scorer').all

assert_equal 'Scorer::ActiveRecord_Relation', result.class.to_s
assert_equal 1, result.length
assert_includes result, owned_scorer
end

test 'works when querying on the name for shared scorers' do
result = user.scorers.where(name: 'Shared Scorer').all
result = user.scorers_involved_with.where(name: 'Shared Scorer').all

assert_equal 'Scorer::ActiveRecord_Relation', result.class.to_s
assert_equal 1, result.length
Expand All @@ -100,13 +100,13 @@ class UserScorerFinderTest < ActiveSupport::TestCase

describe 'Find first scorer that matches params' do
test 'returns nil if no results match' do
result = user.scorers.where(id: 123).first
result = user.scorers_involved_with.where(id: 123).first

assert_nil result
end

test 'works when filtering by id' do
result = user.scorers.where(id: owned_scorer.id)
result = user.scorers_involved_with.where(id: owned_scorer.id)
.order(name: :asc)
.first

Expand All @@ -115,7 +115,7 @@ class UserScorerFinderTest < ActiveSupport::TestCase
end

test 'works with complex where clause for owned scorers' do
result = user.scorers.where('`scorers`.`name` LIKE ?', '%Owned%')
result = user.scorers_involved_with.where('`scorers`.`name` LIKE ?', '%Owned%')
.order(name: :asc)
.first

Expand All @@ -124,7 +124,7 @@ class UserScorerFinderTest < ActiveSupport::TestCase
end

test 'works with complex where clause for shared scorers' do
result = user.scorers.where('`scorers`.`name` LIKE ?', '%Shared%')
result = user.scorers_involved_with.where('`scorers`.`name` LIKE ?', '%Shared%')
.order(name: :asc)
.first

Expand All @@ -134,7 +134,7 @@ class UserScorerFinderTest < ActiveSupport::TestCase
end

test 'works when querying on the name for owned scorers' do
result = user.scorers.where(name: 'Owned Scorer')
result = user.scorers_involved_with.where(name: 'Owned Scorer')
.order(name: :asc)
.first

Expand All @@ -143,7 +143,7 @@ class UserScorerFinderTest < ActiveSupport::TestCase
end

test 'works when querying on the name for shared scorers' do
result = user.scorers.where(name: 'Shared Scorer')
result = user.scorers_involved_with.where(name: 'Shared Scorer')
.order(name: :asc)
.first

Expand All @@ -155,13 +155,13 @@ class UserScorerFinderTest < ActiveSupport::TestCase

describe 'Find last scorer that matches params' do
test 'returns nil if no results match' do
result = user.scorers.where(id: 123).last
result = user.scorers_involved_with.where(id: 123).last

assert_nil result
end

test 'works when filtering by id' do
result = user.scorers.where(id: owned_scorer.id)
result = user.scorers_involved_with.where(id: owned_scorer.id)
.order(name: :desc)
.last

Expand All @@ -170,7 +170,7 @@ class UserScorerFinderTest < ActiveSupport::TestCase
end

test 'works with complex where clause for owned scorers' do
result = user.scorers.where('`scorers`.`name` LIKE ?', '%Owned%')
result = user.scorers_involved_with.where('`scorers`.`name` LIKE ?', '%Owned%')
.order(name: :desc)
.last

Expand All @@ -179,7 +179,7 @@ class UserScorerFinderTest < ActiveSupport::TestCase
end

test 'works with complex where clause for shared scorers' do
result = user.scorers.where('`scorers`.`name` LIKE ?', '%Shared%')
result = user.scorers_involved_with.where('`scorers`.`name` LIKE ?', '%Shared%')
.order(name: :desc)
.last

Expand All @@ -189,7 +189,7 @@ class UserScorerFinderTest < ActiveSupport::TestCase
end

test 'works when querying on the name for owned scorers' do
result = user.scorers.where(name: 'Owned Scorer')
result = user.scorers_involved_with.where(name: 'Owned Scorer')
.order(name: :desc)
.last

Expand All @@ -198,7 +198,7 @@ class UserScorerFinderTest < ActiveSupport::TestCase
end

test 'works when querying on the name for shared scorers' do
result = user.scorers.where(name: 'Shared Scorer')
result = user.scorers_involved_with.where(name: 'Shared Scorer')
.order(name: :desc)
.last

Expand All @@ -208,7 +208,7 @@ class UserScorerFinderTest < ActiveSupport::TestCase
end

test 'includes the default communal scorer' do
result = user.scorers.all
result = user.scorers_involved_with.all

assert_includes result, quepid_default_scorer
end
Expand Down

0 comments on commit ccfb038

Please sign in to comment.